Difference between revisions of "Cross-compiling Linux kernel on x86 64"

From Linux Driver Project
Jump to: navigation, search
(Cross-compiling Linux kernel on x86_64)
(Cross-compile script)
Line 259: Line 259:
  
 
echo "Grepping for warnings in build logs" >> cross_compile_results
 
echo "Grepping for warnings in build logs" >> cross_compile_results
grep -i error *.log >> cross_compile_results
+
grep -i warn *.log >> cross_compile_results
  
 
echo "========================================================="
 
echo "========================================================="
  
 
</pre>
 
</pre>
 +
 
=== Work in progress ===
 
=== Work in progress ===
 
* Add support for defconfig on architectures that don't support.
 
* Add support for defconfig on architectures that don't support.

Revision as of 19:00, 27 August 2013

mediawiki

Contents

Cross-compiling Linux kernel on x86_64

I recently installed several cross-compilers on my x86_64 test system running Ubuntu 12.10 or 13.04. It took some work finding the repositories and correct cross-compiler packages, then figuring out how to install and compile kernels. I am sharing my notes on where to find cross-compilers, how to install them, and how to compile on each of these architectures. This is by no means new information, just a compilation of all my sources and my own discoveries along the way on how to compile.

Installation Preparation

Get your system ready for installation and find packages.

Test/Build System Configuration

First of all, make sure the target test system has essetinal packages to compile x86_64 or x83_32 Linux kernel in native mode, in which case it already has the build-essential package installed. If not, the following is needed to get the test system ready:

   sudo apt-get install build-essential

I am going to cover, how to install and compile for alpha, arm, arm64, c6x, mips, mipsel, powerpc, sh, sparc, and tile. I tried installing microblaze, and couldn not find the correct cross-compiler for this architecture.

Let's start with common packages all cross-compilers need.

Installing common packages

   sudo apt-get install binutils-multiarch
   sudo apt-get install ncurses-dev (Note - required package to run make menuconfig)
   sudo apt-get install alien

Configure apt for arm64 repo (skip this step for 13.04

   wget -O - http://people.debian.org/~wookey/bootstrap/bootstrap-archive.key | sudo apt-key add -
   sudo apt-add-repository 'deb http://people.debian.org/~wookey/bootstrap/ubunturepo/ quantal-bootstrap main'
   sudo apt-get update

Configure apt for emdebian repo

I found alpha, mips, mipsel, powerpc, sh, and sparc cross-compilers on www.emdebian.org repository. Configure the package manager first:

   sudo apt-get install emdebian-archive-keyring
   Create /etc/apt/sources.list.d/emdebian.list file with the following line:
   deb http://www.emdebian.org/debian/ sid main

Download rpms from fedora repo

The following fedora repo is a great source for several cross-compilers and binutils rpms. In my case, since my test system is debian based, I downloaded the rpms and used alien to comver them .deb format, and installed them using dpkg. If your test system is rpm based, you could simply add the repo to yum configuration and install these using yum.

http://dl.fedoraproject.org/pub/fedora/linux/updates/17/x86_64/

I downloaded blackfin, tile, and c6x binutils and gcc from this repo. In the case of tile, make sure you have the latest compiler, gcc-tile-linux-gnu-4.7.2-2.aa.20121114svn.fc17.x86_64.rpm. The older version is missing feedback.h that tilegx needs.

blackfin rpms:

  • binutils-bfin-linux-gnu-2.23.51.0.3-1.fc17.x86_64.rpm
  • gcc-bfin-linux-gnu-4.7.1-0.1.20120606.fc17.x86_64.rpm

c6x rpms:

  • binutils-c6x-linux-gnu-2.23.51.0.3-1.fc17.x86_64.rpm
  • gcc-c6x-linux-gnu-4.7.2-2.aa.20121114svn.fc17.x86_64.rpm

tile rpms:

  • binutils-tile-linux-gnu-2.23.51.0.3-1.fc17.x86_64.rpm
  • gcc-tile-linux-gnu-4.7.2-2.aa.20121114svn.fc17.x86_64.rpm

Now convert rpms to .debs: (you will have to install alien if you don't have it on your system)

   sudo alien -d binutils-bfin-linux-gnu-2.23.51.0.3-1.fc17.x86_64.rpm
   sudo alien -d gcc-bfin-linux-gnu-4.7.1-0.1.20120606.fc17.x86_64.rpm
   sudo alien -d binutils-c6x-linux-gnu-2.23.51.0.3-1.fc17.x86_64.rpm
   sudo alien -d gcc-c6x-linux-gnu-4.7.2-2.aa.20121114svn.fc17.x86_64.rpm
   sudo alien -d binutils-tile-linux-gnu-2.23.51.0.3-1.fc17.x86_64.rpm
   sudo alien -d gcc-tile-linux-gnu-4.7.2-2.aa.20121114svn.fc17.x86_64.rpm

You will see warnings about missing keys like the one below and you can safely ignore them.

warning: gcc-tile-linux-gnu-4.7.2-2.aa.20121114svn.fc17.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 1aca3465: NOKEY

You will end up with the following .debs:

  • binutils-bfin-linux-gnu_2.23.51.0.3-2_amd64.deb
  • gcc-bfin-linux-gnu_4.7.1-1.1_amd64.deb
  • binutils-c6x-linux-gnu_2.23.51.0.3-2_amd64.deb
  • gcc-c6x-linux-gnu_4.7.2-3_amd64.deb
  • binutils-tile-linux-gnu_2.23.51.0.3-2_amd64.deb
  • gcc-tile-linux-gnu_4.7.2-3_amd64.deb

Installation Steps

Note: Creating link to *arch*-linux-gnu-gcc is required to use CROSS_COMPILE directive. For example creating link to aarch64-linux-gnu-gcc is required to use CROSS_COMPILE directive. This step is not needed when installing compilers from .deb packages.

Installing alpha cross-compiler

   sudo apt-get install --install-recommends gcc-4.7-alpha-linux-gnu
   sudo ln -s /usr/bin/alpha-linux-gnu-gcc-4.7 /usr/bin/alpha-linux-gnu-gcc

Installing arm cross-compiler

Please note that arm doesn't need link creation.

   sudo apt-get install gcc-arm-linux-gnueabi

Installing arm64 cross-compiler

Note that arm64 cross-compile works on Linux 3.7 and later kernels.

   sudo apt-get install --install-recommends gcc-4.7-aarch64-linux-gnu
   sudo ln -s /usr/bin/aarch64-linux-gnu-gcc-4.7 /usr/bin/aarch64-linux-gnu-gcc

Installing mips cross-compiler

   sudo apt-get install --install-recommends gcc-4.7-mips-linux-gnu
   sudo ln -s /usr/bin/mips-linux-gnu-gcc-4.7 /usr/bin/mips-linux-gnu-gcc

Installing mipsel cross-compiler

   sudo apt-get install --install-recommends gcc-4.7-mipsel-linux-gnu
   sudo ln -s /usr/bin/mipsel-linux-gnu-gcc-4.7 /usr/bin/mipsel-linux-gnu-gcc

Installing powerpc cross-compiler

   sudo apt-get install --install-recommends gcc-4.7-powerpc-linux-gnu
   sudo ln -s /usr/bin/powerpc-linux-gnu-gcc-4.7 /usr/bin/powerpc-linux-gnu-gcc

Installing sh cross-compiler

   sudo apt-get install --install-recommends gcc-4.7-sh4-linux-gnu
   sudo ln -s /usr/bin/sh4-linux-gnu-gcc-4.7 /usr/bin/sh4-linux-gnu-gcc

Installing sparc cross-compiler

   sudo apt-get install --install-recommends gcc-4.7-sparc-linux-gnu
   sudo ln -s /usr/bin/sparc-linux-gnu-gcc-4.7 /usr/bin/sparc-linux-gnu-gcc

Install the converted .debs

   sudo dpkg -i binutils-bfin-linux-gnu_2.23.51.0.3-2_amd64.deb
   sudo dpkg -i gcc-bfin-linux-gnu_4.7.1-1.1_amd64.deb
   sudo dpkg -i binutils-c6x-linux-gnu_2.23.51.0.3-2_amd64.deb
   sudo dpkg -i gcc-c6x-linux-gnu_4.7.2-3_amd64.deb
   sudo dpkg -i binutils-tile-linux-gnu_2.23.51.0.3-2_amd64.deb
   sudo dpkg -i gcc-tile-linux-gnu_4.7.2-3_amd64.deb

Compilation

Please note that some architectures don't have good support for make ARCH=arch defconfig. In those cases, I end up picking a configuration file from configs. In some cases, you might see errors in LD phase, and please keep in mind these are just compile tests.

alpha cross-compile

   make distclean
   make ARCH=alpha defconfig
   ARCH=alpha CROSS_COMPILE=alpha-linux-gnu- make all

arm cross-compile

   make distclean
   make ARCH=arm defconfig
   ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make all

arm64 cross-compile

Note: works on Linux 3.7 and later releases.

   make distclean
   make ARCH=arm64 defconfig
   ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make all

blackfin cross-compile

   make distclean
   make ARCH=blackfin defconfig
   ARCH=blackfin CROSS_COMPILE=bfin-linux-gnu- make all

c6x cross-compile

Note: works on 3.4 and later releases.

   make distclean
   cp arch/c6x/configs/dsk6455_defconfig .config
   ARCH=c6x CROSS_COMPILE=c6x-linux-gnu- make all

mips cross-compile

   make distclean
   make ARCH=mips defconfig
   ARCH=mips CROSS_COMPILE=mips-linux-gnu- make all

mipsel cross-compile

   make distclean
   make ARCH=mips defconfig
   ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- make all

powerpc cross-compile

Note: defconfig is not supported. It will generate native x86_64 config when make ARCH=powerpc defconfig is run.

   make distclean
   cp arch/powerpc/configs/wii_defconfig .config
   ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu- make all

sh cross-compile

   make distclean
   make ARCH=sh defconfig
   ARCH=sh CROSS_COMPILE=sh4-linux-gnu- make all

sparc cross-compile

   make distclean
   make ARCH=sparc defconfig
   ARCH=sparc CROSS_COMPILE=sparc-linux-gnu- make all

tile cross-compile

   make distclean
   make ARCH=tile defconfig
   ARCH=tile CROSS_COMPILE=tile-linux-gnu- make all

Cross-compile script

    #!/bin/bash -x
    
    echo "Start Cross Compiling in" $PWD > cross_compile_results
    
    ls $PWD/arch >> cross_compile_results
    rm vmlinux* vmlinux.*
    
    echo "alpha cross-compile" >> cross_compile_results
    make distclean
    make ARCH=alpha defconfig
    ARCH=alpha CROSS_COMPILE=alpha-linux-gnu- make -j2 all > alpha.log 2>&1
    ls -l vmlinux* >> cross_compile_results
    
    echo "arm cross-compile" >> cross_compile_results
    make distclean
    make ARCH=arm defconfig
    ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make -j2 all > arm.log 2>&1
    ls -l vmlinux* >> cross_compile_results
    
    echo "arm64 cross-compile" >> cross_compile_results
    make distclean
    make ARCH=arm64 defconfig
    ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j2 all > arm64.log 2>&1
    ls -l vmlinux* >> cross_compile_results

    echo "blackfin cross-compile" >> cross_compile_results
    make distclean
    make ARCH=blackfin defconfig
    ARCH=blackfin CROSS_COMPILE=bfin-linux-gnu- make -j2 all > blackfin.log 2>&1
    ls -l vmlinux* >> cross_compile_results

    # make runs through config options and prompts for choices. Redirecting logs won't work even when methods to pipe yes '' to make    
    echo "c6x cross-compile" >> cross_compile_results
    make distclean
    make ARCH=c6x defconfig
    ARCH=c6x CROSS_COMPILE=c6x-linux-gnu- make -j2 all
    ls -l vmlinux* >> cross_compile_results
    
    echo "mips cross-compile" >> cross_compile_results
    make distclean
    make ARCH=mips defconfig
    ARCH=mips CROSS_COMPILE=mips-linux-gnu- make -j2 all > mips.log 2>&1
    ls -l vmlinux* >> cross_compile_results
    
    echo "mipsel cross-compile" >> cross_compile_results
    make distclean
    make ARCH=mips defconfig
    ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- make -j2 all > mipsel.log 2>&1
    ls -l vmlinux* >> cross_compile_results

    # make runs through config options and prompts for choices. Redirecting logs won't work even when methods to pipe yes '' to make    
    echo "powerpc cross-compile" >> cross_compile_results
    make distclean
    cp arch/powerpc/configs/wii_defconfig .config
    ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu- make -j2 all
    ls -l vmlinux* >> cross_compile_results
    
    echo "sh cross-compile" >> cross_compile_results
    make distclean
    make ARCH=sh defconfig
    ARCH=sh CROSS_COMPILE=sh4-linux-gnu- make -j2 all > sh.log 2>&1
    ls -l vmlinux* >> cross_compile_results
    
    # make runs through config options and prompts for choices. Redirecting
    # logs won't work even when methods to pipe yes '' to make to auto-select
    # default config options.
    echo "sparc cross-compile" >> cross_compile_results
    make distclean
    make ARCH=sparc defconfig
    ARCH=sparc CROSS_COMPILE=sparc-linux-gnu- make -j2 all
    ls -l vmlinux* >> cross_compile_results
    
    # make runs through config options and prompts for choices. Redirecting
    # logs won't work even when methods to pipe yes '' to make to auto-select
    # default config options.
    echo "tile cross-compile" >> cross_compile_results
    make distclean
    make ARCH=tile defconfig
    ARCH=tile CROSS_COMPILE=tile-linux-gnu- make -j2 all
    ls -l vmlinux* >> cross_compile_results

echo "========================================================="

echo "Grepping for errors in build logs" >> cross_compile_results
grep -i error *.log >> cross_compile_results

echo "Grepping for warnings in build logs" >> cross_compile_results
grep -i warn *.log >> cross_compile_results

echo "========================================================="

Work in progress

  • Add support for defconfig on architectures that don't support.

References and Package repositories

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox