Difference between revisions of "Step-by-step Cross-compiling a Kernel"
(Created page with "THIS IS IN PROGRESS: PLEASE DO NOT EDIT wget https://launchpadlibrarian.net/129963014/gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux.tar.xz xz -d gcc-linaro-arm-...") |
|||
Line 1: | Line 1: | ||
THIS IS IN PROGRESS: PLEASE DO NOT EDIT | THIS IS IN PROGRESS: PLEASE DO NOT EDIT | ||
+ | === Introduction === | ||
+ | This tutorial is for developers | ||
+ | These procedures assume you have an Debian-based distribution loaded on your host and your odroid. The kernel building is not different between the distros, but getting ready to build is. | ||
+ | Debian/Ubuntu/Mint and others use "Debian packages", .deb files. They use tools like dpkg, apt, synaptic and so on to manage a package database. | ||
+ | |||
+ | RedHat, Centos, Fedora and Gentoo would not know about apt-get and friends -- so these instructions will not be of much use. | ||
+ | |||
+ | |||
+ | |||
+ | === Setting up the Toolchain === | ||
+ | If you are happy with your arm cross-compiler, you can skip this step. Some people prefer the CodeSourcery toolchains, but the free version does not support hard floating point. | ||
+ | |||
+ | The kernel is much easier to build than a whole root file system because there are few dependencies. We need a compiler that can generate code for the cortex-a9. We prefer hard-float (armhf rather than armel in Debian lingo) | ||
+ | |||
+ | On your Linux host, setup a shared work area | ||
+ | <pre> | ||
+ | sudo mkdir -p /usr/local/arm >/dev/null | ||
+ | sudo chmod 777 /usr/local/arm | ||
+ | cd /usr/local/arm | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | On your Linux host, get the toolchain and expand it. | ||
+ | <pre> | ||
+ | cd /usr/local/arm | ||
wget https://launchpadlibrarian.net/129963014/gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux.tar.xz | wget https://launchpadlibrarian.net/129963014/gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux.tar.xz | ||
xz -d gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux.tar.xz | xz -d gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux.tar.xz | ||
tar -xvf gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux.tar | tar -xvf gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux.tar | ||
+ | </pre> | ||
− | + | I need to change compilers depending on the project I'm working on, so I prefer to use a symlink to select the 'active' version. | |
+ | <pre> | ||
ln -s gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux /usr/local/arm/toolchain | ln -s gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux /usr/local/arm/toolchain | ||
+ | </pre> | ||
− | Setup the c-compiler cache | + | Setup the c-compiler cache (optional) |
<pre> | <pre> | ||
cd /usr/local/arm/toolchain | cd /usr/local/arm/toolchain | ||
mkdir bin-ccache | mkdir bin-ccache | ||
+ | # you may already have ccache installed, but for the sake of illustration... | ||
+ | sudo apt-get install ccache | ||
ln -s $(which ccache) arm-linux-gnueabihf-gcc | ln -s $(which ccache) arm-linux-gnueabihf-gcc | ||
ln -s $(which ccache) arm-linux-gnueabihf-g++ | ln -s $(which ccache) arm-linux-gnueabihf-g++ | ||
Line 20: | Line 50: | ||
</pre> | </pre> | ||
+ | Check your PATH and update it as shown. It is convenient to edit your ~/.bashrc file and re-launch a shell rather than just export. | ||
+ | <pre> | ||
export PATH=/usr/local/arm/toolchain/bin-ccache:/usr/local/arm/toolchain/bin:$PATH | export PATH=/usr/local/arm/toolchain/bin-ccache:/usr/local/arm/toolchain/bin:$PATH | ||
+ | </pre> | ||
+ | === Grabbing the source === | ||
+ | Go to a convenient work area, here I show $HOME/work | ||
+ | <pre> | ||
+ | cd $HOME | ||
+ | mkdir work | ||
+ | cd work | ||
+ | </pre> | ||
Get the kernel snapshot, and unzip it | Get the kernel snapshot, and unzip it | ||
Line 30: | Line 70: | ||
− | Move into the kernel source directory and set up | + | Move into the kernel source directory and set up. You could edit your .bashrc and add the ARCH and CROSS_COMPILE variables -- but remember that you did it. Some x86 packages will fail to build with CROSS_COMPILE and/or ARCH set... (vmware is the worst offender I know) |
<pre> | <pre> | ||
cd linux-odroid-3.0.y/ | cd linux-odroid-3.0.y/ | ||
Line 37: | Line 77: | ||
</pre> | </pre> | ||
− | Select the configuration you want, and build it | + | Select the configuration you want, and build it (you can see the alternatives in ./arch/arm/configs/odroid*) |
<pre> | <pre> | ||
make odroidu2_ubuntu_defconfig | make odroidu2_ubuntu_defconfig | ||
Line 43: | Line 83: | ||
</pre> | </pre> | ||
− | Make a directory for the kernel modules and let the kernel make system strip and copy them out. | + | Make a directory for the kernel modules and let the kernel make system strip and copy them out. Create a tarball for quick copy/transfer. |
<pre> | <pre> | ||
mkdir ../rfs | mkdir ../rfs | ||
Line 57: | Line 97: | ||
</pre> | </pre> | ||
− | Copy our new kernel and modules to the target. This method copies over the network. The thing to remember is that the kernel goes on the boot partition and the kernel modules go on the rootfs partition | + | Copy our new kernel and modules to the target. This method copies over the network. The thing to remember is that the kernel goes on the boot partition and the kernel modules go on the rootfs partition. Here odroidu2 is the name of my odroid target, defined in /etc/hosts. You can do ifconfig on your odroid to see what IP Address it is using and then use it explicitly instead of the technique I show here (the dotted quad instead of odroidu2) |
<pre> | <pre> | ||
scp modules.tgz root@odroidu2:/ | scp modules.tgz root@odroidu2:/ | ||
Line 63: | Line 103: | ||
</pre> | </pre> | ||
− | Now go to the odroid Linux console | + | Now go to the odroid Linux console, expand the kernel modules tarball and reboot |
<pre> | <pre> | ||
tar -xvzf modules.tgz | tar -xvzf modules.tgz |
Revision as of 20:45, 2 February 2013
THIS IS IN PROGRESS: PLEASE DO NOT EDIT
Introduction
This tutorial is for developers
These procedures assume you have an Debian-based distribution loaded on your host and your odroid. The kernel building is not different between the distros, but getting ready to build is.
Debian/Ubuntu/Mint and others use "Debian packages", .deb files. They use tools like dpkg, apt, synaptic and so on to manage a package database.
RedHat, Centos, Fedora and Gentoo would not know about apt-get and friends -- so these instructions will not be of much use.
Setting up the Toolchain
If you are happy with your arm cross-compiler, you can skip this step. Some people prefer the CodeSourcery toolchains, but the free version does not support hard floating point.
The kernel is much easier to build than a whole root file system because there are few dependencies. We need a compiler that can generate code for the cortex-a9. We prefer hard-float (armhf rather than armel in Debian lingo)
On your Linux host, setup a shared work area
sudo mkdir -p /usr/local/arm >/dev/null sudo chmod 777 /usr/local/arm cd /usr/local/arm
On your Linux host, get the toolchain and expand it.
cd /usr/local/arm wget https://launchpadlibrarian.net/129963014/gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux.tar.xz xz -d gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux.tar.xz tar -xvf gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux.tar
I need to change compilers depending on the project I'm working on, so I prefer to use a symlink to select the 'active' version.
ln -s gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux /usr/local/arm/toolchain
Setup the c-compiler cache (optional)
cd /usr/local/arm/toolchain mkdir bin-ccache # you may already have ccache installed, but for the sake of illustration... sudo apt-get install ccache ln -s $(which ccache) arm-linux-gnueabihf-gcc ln -s $(which ccache) arm-linux-gnueabihf-g++ ln -s $(which ccache) arm-linux-gnueabihf-cpp ln -s $(which ccache) arm-linux-gnueabihf-c++
Check your PATH and update it as shown. It is convenient to edit your ~/.bashrc file and re-launch a shell rather than just export.
export PATH=/usr/local/arm/toolchain/bin-ccache:/usr/local/arm/toolchain/bin:$PATH
Grabbing the source
Go to a convenient work area, here I show $HOME/work
cd $HOME mkdir work cd work
Get the kernel snapshot, and unzip it
wget --no-check-certificate https://github.com/hardkernel/linux/archive/odroid-3.0.y.zip unzip odroid-3.0.y.zip
Move into the kernel source directory and set up. You could edit your .bashrc and add the ARCH and CROSS_COMPILE variables -- but remember that you did it. Some x86 packages will fail to build with CROSS_COMPILE and/or ARCH set... (vmware is the worst offender I know)
cd linux-odroid-3.0.y/ export CROSS_COMPILE=arm-linux-gnueabihf- export ARCH=arm
Select the configuration you want, and build it (you can see the alternatives in ./arch/arm/configs/odroid*)
make odroidu2_ubuntu_defconfig make -j8 zImage
Make a directory for the kernel modules and let the kernel make system strip and copy them out. Create a tarball for quick copy/transfer.
mkdir ../rfs export INSTALL_MOD_PATH=$PWD/../rfs make modules_install cd ../rfs # remove symlinks that point to files we do not need in root file system find . -name source | xargs rm find . -name build | xargs rm # Compress sudo tar -cvzf ../modules.tgz . cd ../
Copy our new kernel and modules to the target. This method copies over the network. The thing to remember is that the kernel goes on the boot partition and the kernel modules go on the rootfs partition. Here odroidu2 is the name of my odroid target, defined in /etc/hosts. You can do ifconfig on your odroid to see what IP Address it is using and then use it explicitly instead of the technique I show here (the dotted quad instead of odroidu2)
scp modules.tgz root@odroidu2:/ scp linux-odroid-3.0.y/arch/arm/boot/zImage root@odroidu2:/boot
Now go to the odroid Linux console, expand the kernel modules tarball and reboot
tar -xvzf modules.tgz rm modules.tgz sync reboot
Check the kernel version, with uname -a
Linux odroidu2-1 3.0.61 #1 SMP Sat Feb 2 15:28:35 PST 2013 armv7l GNU/Linux