Step-by-step Native Compiling a Kernel

From odroid US
Revision as of 20:09, 18 February 2013 by Osterluk (Talk | contribs)

Jump to: navigation, search

WATCH THE SIZE OF YOUR BOOT PARTITION, MAYBE YOU HAVE TO DELETE SOME OF THE BACKUP FILES!

DO THIS ON YOUR ODROID, NOT ON YOUR PC!

These procedures assume you have an Debian-based distribution loaded on 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.


Grabbing the source

you can easily build the kernel on your own.

You can get the latest kernel snapshot or get a source for a specific Hardkernel released build. This link shows how to get a specific release: Use git and commit tag . If a snapshot is acceptable, use the wget step as shown next.

  1. browse to https://github.com/hardkernel/linux
  2. choose your branch (as of today -2013-01-12- it's odroid-3.0.y)
wget --no-check-certificate https://github.com/hardkernel/linux/archive/odroid-3.0.y.zip

Unpacking the source

mv odroid-3.0.y.zip /usr/src/linux.zip
cd /usr/src
7z x -y linux.zip > /dev/null
# add a symlink to the source tree
ln -s  linux-odroid-3.0.y linux 

Configuring the kernel

Now is the time to consider whether you want to work as root user or to logout and proceed as a normal user. Usually file permissions trip up users new to Linux. Working as root can make things easier, but there is a risk of wrecking your system. On the plus side, with odroid, we can just re-flash it and get back to work.

You might want to install the sudo package if you don't have it already. This next section is optional

sudo apt-get install
# You need to add yourself to the "sudoers list", and how exactly that is done depends on the distribution.
# This hack works for Debian Wheezy
# as root, add normal user (named user) to adm group
adduser user adm
# configure the adm group to have no restrictions
echo "%adm ALL=(ALL) ALL" >> /etc/sudoers
# sudo will complain if it cannot resolve the hostname
echo "127.0.0.1  $(hostname )" >> /etc/hosts

Move to the linux source tree and change ownership to the normal user named user. Substitute your own username.

cd /usr/src
chown -R user:user linux
cd linux

Make sure to select the correct config for your device in the next step. execute the following to get a list of odroid kernel configs:

ls /usr/src/linux/arch/arm/configs/ | grep odroid

now choose your config and copy it to /usr/src/linux/.config (I chose odroidu2_ubuntu_defconfig)

# This step prepares for building and copies the configuration from arch/arm/configs to .config
make odroidu2_ubuntu_defconfig

Now you can build the kernel according to the configuration you chose, or you and make configuration changes.

You can configure the kernel using either text mode or GUI. The results are the same. The search functions in the GUI are nice. If you only have the serial console, you will need to use text mode.

Text mode:

apt-get install libncurses5-dev
make menuconfig

Graphical mode:

apt-get install qt4-dev-tools
make xconfig

change everything to your needs (use / for searching)

Building the kernel

make -j8
# If you are building as root:
make modules_install
# If you are building as user:
sudo make modules_install
make zImage


Mounting the Boot Partition

The boot partition is the section on the media, either SD-Card or eMMC, that holds the kernel image and the initial root filesystem. For the Hardkernel Ubuntu systems, the boot partition would be mounted at /media/boot. For other distros, the boot partition may not be mounted automatically and by default if might like to be mounted to a different location. For example, the Debian Wheezy distro does not currently mount it, and this and other tutorials mount it at /boot when necessary.

You can work the tutorial and substitute /boot/media for /boot if you like, although it will not cause a problem if you just use /boot. Create the /boot directory to use as a mount point if you need to.

This code snippet shows one way to mount the boot partition

    if [ ! -d /boot ]; then
        mkdir -p /boot || exit 1
    fi
    mountpoint /boot >/dev/null
    if [ $? -ne 0 ]; then
        mount -o rw /dev/mmcblk0p1 /boot || exit 1
    fi

Building the initial ram filesystem

This is not always needed -- unless you need changes in phase 1 of the Linux boot, it is best to leave this alone.

If you need a custom filesystem driver, or you want to directly mount your root file system on a thumb drive or NAS drive, this would be the area to work in. You would need to know that this is a busybox-based system completely separate from the eventual distro you intend to boot.

kernelversion=`cat ./include/config/kernel.release`
mkinitramfs -c gzip -o ./initramfs-$kernelversion $kernelversion
mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n initramfs -d ./initramfs-$kernelversion ./uInitrd
cp uInitrd /boot

Copying the kernel and initramfs to the boot partition

kernelversion=`cat ./include/config/kernel.release`
cp /boot/zImage /boot/zImage.prev
cp /boot/uInitrd /boot/uInitrd.prev
cp arch/arm/boot/zImage /boot
cp .config /boot/config-$kernelversion

optionally:

cp System.map /boot/System.map-$kernelversion

halt:

shutdown -h 0

power cycle after that.

The new kernel will show something like this:

uname -a

Linux odroidu2-1 3.0.57 #1 SMP Sun Jan 13 21:53:37 UTC 2013 armv7l GNU/Linux

The #1 came from the file: /usr/src/linux/.version. Each time you build, this number will be incremented.

warnings

Your new kernel built kernel modules that may not be compatible with other builds.

Please don't post a private kernel without giving a warning. If could break another system. If you make small changes, like select an additional module, the result will probably not segfault other systems. On the other hand, if you select some networking options (especially) you may find that structs don't quite line up and eventually someone will segfault.