Software:Manually Compile the Kernel

From BUGwiki

Jump to: navigation, search

Contents

Overview

This page describes steps necessary for manually building the Linux kernel for the OMAP3-based BUG Y.T.

Who

Developers who are interested in getting acquainted with customizing the software for their prototype device will often find the kernel to be the starting point for optimization and new device integration. Developers that want bleeding-edge features or defect fixes but cannot wait for a full-on release.

Assumptions

If you find yourself wanting to compile and modify the stock linux kernel, you should definitely consider purchasing the BUG Stinger, which provides a fail-safe serial console. If you've done something wrong, serial console will give you the bootloader and kernel loading output.

You'll also want to install ncurses to menuconfig, as well as mkimage to package the kernel as a u-boot loadable image:

sudo apt-get install ncurses-dev uboot-mkimage

BUG Toolchain

See the Software:Toolchain page for links to pre-built toolchains for BUG.

Sources

Clone the bug20 kernel git tree:

git clone git://github.com/buglabs/bug20-2.6.35-linaro.git
Initialized empty Git repository in /path/bug20-2.6.35-omap/.git/
remote: Counting objects: 1314642, done.
remote: Compressing objects: 100% (221725/221725), done.
remote: Total 1314642 (delta 1084792), reused 1314347 (delta 1084572)
Receiving objects: 100% (1314642/1314642), 319.84 MiB | 1.10 MiB/s, done.
Resolving deltas: 100% (1084792/1084792), done.

Building

Initialize your build environment for angstrom cross compilation:

. /usr/local/angstrom/arm/environment-setup
export ARCH=arm
export CROSS_COMPILE=arm-angstrom-linux-gnueabi-
unset CPATH

(The CPATH environment variable is set by angstroms environment setup script, but it confuses the Linux build system when building host tools). Assuming you're using the armv7a toolchain:

cd bug20-2.6.35-linaro

Copy the buglabs default config into the right place:

make omap3_buglabs_defconfig

Begin building:

make menuconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/basic/docproc
  HOSTCC  scripts/basic/hash
  HOSTCC  scripts/kconfig/conf.o
scripts/kconfig/conf.c: In function ‘conf_askvalue’:

... You'll come up with a menu like that below. In this case, we won't be covering modifying the kernel. For that, see

.config - Linux Kernel v2.6.35.10 Configuration
─────────────────────────────────────────────────────────────────────────────────────────────────────────────
 ┌────────────────────────────────────── Linux Kernel Configuration ──────────────────────────────────────┐
 │  Arrow keys navigate the menu.  <Enter> selects submenus --->.  Highlighted letters are hotkeys.       │  
 │  Pressing <Y> includes, <N> excludes, <M> modularizes features.  Press <Esc><Esc> to exit, <?> for     │  
 │  Help, </> for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < > module capable             │  
 │                                                                                                        │  
 │ ┌────────────────────────────────────────────────────────────────────────────────────────────────────┐ │  
 │ │                   General setup  --->                                                              │ │  
 │ │               [*] Enable loadable module support  --->                                             │ │  
 │ │               [*] Enable the block layer  --->                                                     │ │  
 │ │                   System Type  --->                                                                │ │  
 │ │                   Bus support  --->                                                                │ │  
 │ │                   Kernel Features  --->                                                            │ │  
 │ │                   Boot options  --->                                                               │ │  
 │ │                   CPU Power Management  --->                                                       │ │  
 │ │                   Floating point emulation  --->                                                   │ │  
 │ │                   Userspace binary formats  --->                                                   │ │  
 │ │                   Power management options  --->                                                   │ │  
 │ │               [*] Networking support  --->                                                         │ │  
 │ │                   Device Drivers  --->                                                             │ │  
 │ │               <*> BMI  --->                                                                        │ │  
 │ │                   File systems  --->                                                               │ │  
 │ │                   Kernel hacking  --->                                                             │ │  
 │ │                   Security options  --->                                                           │ │  
 │ │               -*- Cryptographic API  --->                                                          │ │  
 │ │                   Library routines  --->                                                           │ │  
 │ │               ---                                                                                  │ │  
 │ │                   Load an Alternate Configuration File                                             │ │  
 │ │                   Save an Alternate Configuration File                                             │ │  
 │ │                                                                                                    │ │  
 │ │                                                                                                    │ │  
 │ └────────────────────────────────────────────────────────────────────────────────────────────────────┘ │  
 ├────────────────────────────────────────────────────────────────────────────────────────────────────────┤  
 │                                    <Select>    < Exit >    < Help >                                    │  
 └────────────────────────────────────────────────────────────────────────────────────────────────────────┘  
   


Hit esc twice to close it out.

Now, make the kernel image and the kernel modules.

make -j 2 uImage modules
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf -s arch/arm/Kconfig
  CHK     include/linux/version.h
  UPD     include/linux/version.h
  SYMLINK include/asm -> include/asm-arm
  Generating include/asm-arm/mach-types.h
  CHK     include/linux/utsrelease.h
  UPD     include/linux/utsrelease.h
  HOSTCC  scripts/genksyms/genksyms.o
  CC      kernel/bounds.s
...
  LD [M]  net/netfilter/x_tables.ko
  LD [M]  net/netfilter/xt_tcpudp.ko

Now you're ready to deploy.

Deploying

The uImage will be in arch/arm/boot/uImage.

To deploy, it's a good habit (to reduce uncertainty) to remove the old modules and uImage entirely, then put the new ones in their place. Mount the SD card you have with the rootfs under /mnt/rootfs, then clean the old kernel and copy over the new uImage:

rm -fr /mnt/rootfs/boot/uImage-2.6.35.10-r100
cp ./arch/arm/boot/uImage /mnt/rootfs/boot/uImage-2.6.35-linaro

You'll also need to update the symlink to our new uImage:

rm /mnt/rootfs/boot/uImage
ln -s uImage-2.6.35-linaro uImage

Same for modules:

rm -fr /mnt/rootfs/lib/modules/

Install modules:

make INSTALL_MOD_PATH=/mnt/rootfs modules_install

When that is done, unmount the SD card, and put it back into the bug.

Now you can reboot the bug with new kernel powers.

If you want to install the new kernel and modules through the network to a running BUG, copy the uImage as above. For the modules, it is convenient to first use make modules_install with INSTALL_MOD_PATH pointing to an empty directory an copying the modules from that directory to the BUG. Note that you'll first have to boot the new kernel and run depmod on the target machine before you can use any of the modules, so make sure that you have a working console connection.

Handy Scripts

Simple build and install, helpful for repetitive build / debug / edit / build cycles. Label (using e2label) your sd card R2.1.0. This script uses the Ubuntu normal mounting point convention of /media/VOLNAME, you may have to adapt to your mount points. If any step runs into errors, it will stop at that point:

#!/bin/bash
export RELHASH=R2.1.0
. /usr/local/angstrom/arm/environment-setup
make distclean && 
make omap3_buglabs_defconfig && 
make uImage -j2 && 
make modules -j2 && 
rm /media/${RELHASH}/boot/uImage && 
cp arch/arm/boot/uImage /media/${RELHASH}/boot/uImage && 
make INSTALL_MOD_PATH=/media/${RELHASH} modules_install

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox
Print/export