You are viewing outdated content for BUG. If you have a BUG Y.T. edition or 2.0 series device, please visit our updated wiki: http://wiki.buglabs.net



Hand Compile the Kernel

From BUG Wiki

Jump to: navigation, search

Contents

Overview

This tutorial will show you how to hand-compile your kernel. Why would you want to do this? You probably want to connect a peripheral to the BUG and need additional driver support to get it to work. The example below shows you how to modify the bug kernel to support USB Video Class Linux devices (UVC).

Assumptions

If you're using Hiro P BUG (1.2) you should have a handylink cable for debugging purposes. If you're using the new BUGwifi (1.3A), you should have a dock. If you don't, email support@buglabs.net and tell them the nature of your project to determine your elegibility for receiving the dock. You should be using linux. The instructions below have only been tested on Ubuntu 9.04 but should work on most linux distros. You should also be acquainted with the Bug Labs Kernel and Rootfs Build System, especially if you want to build the armv6 toolchain from sources.

Cross-compiler set up

Toolchain

What's a toolchain? It's gcc, g++, ld, as etc, but in this case you'll be cross-compiling. In other words, you're building for a host platform (BUG) on your build system (x86?). To do this, you need a special form of gcc which is built to run on the build system, but compile for the host system.

x86_64

We've put the toolchain up for download, as built by the Bug Labs build machine. The Bug Labs build machine is of architecture x86_64, so the instructions below should only be followed if your architecture is the same.

wget http://repo.buglabs.net/x86_64-armv6-sdk-extras/binutils-cross-sdk_2.18-r4_x86_64-armv6-sdk.ipk
ar x binutils-cross-sdk_2.18-r4_x86_64-armv6-sdk.ipk 
sudo tar xzvf data.tar.gz -C /
wget http://repo.buglabs.net/x86_64-armv6-sdk-extras/gcc-cross-sdk_4.1.2-r3_x86_64-armv6-sdk.ipk
ar x gcc-cross-sdk_4.1.2-r3_x86_64-armv6-sdk.ipk
sudo tar xzvf data.tar.gz -C /

x86

wget http://bugcommunity.com/downloads/files/arm-poky-BUG-x86-cross.tar.gz
tar xzvf arm-poky-BUG-x86-cross.tar.gz

From source

The preferred method of getting the toolchain is building it yourself! Follow the instructions on our Kernel and Rootfs Build System to build the linux kernel and uboot yourself via the bitbake/oe methodology. I recommend using the R1.4/qa branch as mentioned in the wiki's Source Branch Section. To do this, you simply follow the instructions in the Kernel and Rootfs Build System, check out the R1.4/qa branch, cd into the build directory and:

svn up
source reinstate-build-env
bitbake linux-bug
bitbake uboot

The first will give you all the tools you need to cross-compile the linux kernel, the second will give you "mkimage", which is required to generate a uboot-compatible uImage, which is the image of your kernel.

Path

After getting the toolchain, you'll need to add the cross-compiler to your path.

x86_64

Add the resulting bin directory to your path in your .bashrc or whatever you use to export PATH.

export PATH=$PATH:/usr/local/poky/eabi-glibc/arm/bin/

x86 binaries

Add the cross/bin directory

export PATH=$PATH:/path/to/untarred/cross/bin

Built from source

Add the cross/bin directory

export PATH=$PATH:/path/to/kernelandrootfs/com.buglabs.build.oe/build/tmp/cross/bin

NOTE: If you are using OpenEmbedded rather than Poky the path will be slightly different:

export PATH=$PATH:/path/to/kernelandrootfs/com.buglabs.build.oe/build/tmp/cross/armv7a/bin/

Make sure you see mkimage in that dir. If you don't have it, you can try "sudo apt-get install uboot-mkimage" but only the Bug Labs built one is supported at the moment (this needs verification).

Configuring

Menuconfig/xconfig

It's recommended to stay as close as possible to the production kernel, which is built out of a branch in SVN. Check out the branch below and we'll modify just some configuration options, ensuring that the underlying bug-specific code should be identical to the production branch.

svn co svn://bugcamp.net/bug/branches/R1.4/qa/bug-linux-2.6.27.2
cd bug-linux-2.6.27.2

Check out (or export) the config we use to build the production BUG kernel:

svn export svn://bugcamp.net/bug/branches/R1.4/qa/com.buglabs.build.oe/meta-bug/packages/linux/linux-bug-2.6.27.2/defconfig-bug .config

(You'll probably already find a .config in the bug-linux-2.6.26.2 directory prior to copying defconfig-bug; just overwrite it with defconfig-bug as defconfig-bug is the one that is actually used when the kernel is built for official releases.)

Now let's get into menuconfig which is a curses GUI simplifying the process of selecting optional features and drivers for the linux kernel. If you see an error message like Install ncurses (ncurses-devel) and try again. then you don't have the ncurses libraries installed; on Ubuntu do an apt-get install libncurses5-dev to get them.

make ARCH=arm menuconfig

You should see something like:

 HOSTCC  scripts/basic/fixdep
 HOSTCC  scripts/basic/docproc
 HOSTCC  scripts/kconfig/mconf.o
 HOSTCC  scripts/kconfig/zconf.tab.o
 HOSTLD  scripts/kconfig/mconf
 scripts/kconfig/mconf arch/arm/Kconfig

Then a curses menu:

 .config - Linux Kernel v2.6.27.2 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  --->                                                                                           │ │  
  │ │                                              Floating point emulation  --->                                                                               │ │  
  │ │                                              Userspace binary formats  --->                                                                               │ │  
  │ │                                              Power management options  --->                                                                               │ │  
  │ │                                          [*] Networking support  --->                                                                                     │ │  
  │ │                                              Device Drivers  --->                                                                                         │ │  
  │ │                                              File systems  --->                                                                                           │ │  
  │ │                                              Kernel hacking  --->                                                                                         │ │  
  │ │                                              Security options  --->                                                                                       │ │  
  │ │                                          -*- Cryptographic API  --->                                                                                      │ │  
  │ │                                              Library routines  --->                                                                                       │ │  
  │ │                                          ---                                                                                                              │ │  
  │ │                                              Load an Alternate Configuration File                                                                         │ │  
  │ │                                              Save an Alternate Configuration File                                                                         │ │  
  │ │                                                                                                                                                           │ │  
  │ │                                                                                                                                                           │ │  
  │ │                                                                                                                                                           │ │  
  │ │                                                                                                                                                           │ │  
  │ │                                                                                                                                                           │ │  
  │ │                                                                                                                                                           │ │  
  │ │                                                                                                                                                           │ │  
  │ │                                                                                                                                                           │ │  
  │ │                                                                                                                                                           │ │  
  │ │                                                                                                                                                           │ │  
  │ │                                                                                                                                                           │ │  
  │ │                                                                                                                                                           │ │  
  │ └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ │  
  ├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤  
  │                                                               <Select>    < Exit >    < Help >                                                                │  
  └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘  

In this case we're interested in UVC camera support. Where to navigate? Hit the "/" key to open up a search:


                                             ┌──────────────────── Search Configuration Parameter ─────────────────────┐
                                             │  Enter CONFIG_ (sub)string to search for (with or without "CONFIG")     │  
                                             │ ┌─────────────────────────────────────────────────────────────────────┐ │  
                                             │ │UVC                                                                  │ │  
                                             │ └─────────────────────────────────────────────────────────────────────┘ │  
                                             │                                                                         │  
                                             │                                                                         │  
                                             ├─────────────────────────────────────────────────────────────────────────┤  
                                             │                         <  Ok  >      < Help >                          │  
                                             └─────────────────────────────────────────────────────────────────────────┘  
                                                                                                                          

Ok, no dice on UVC:

 .config - Linux Kernel v2.6.27.2 Configuration
 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  ┌─────────────────────────────────────────────────────────────────────── Search Results ────────────────────────────────────────────────────────────────────────┐
  │ No matches found.    
...

It's probably using the full name: USB_VIDEO_CLASS:


                                             ┌──────────────────── Search Configuration Parameter ─────────────────────┐
                                             │  Enter CONFIG_ (sub)string to search for (with or without "CONFIG")     │  
                                             │ ┌─────────────────────────────────────────────────────────────────────┐ │  
                                             │ │USB_VIDEO_CLASS                                                      │ │  
                                             │ └─────────────────────────────────────────────────────────────────────┘ │  
                                             │                                                                         │  
                                             │                                                                         │  
                                             ├─────────────────────────────────────────────────────────────────────────┤  
                                             │                         <  Ok  >      < Help >                          │  
                                             └─────────────────────────────────────────────────────────────────────────┘  
                                                                                                                          

Hit enter and you should see:

.config - Linux Kernel v2.6.27.2 Configuration
 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  ┌─────────────────────────────────────────────────────────────────────── Search Results ────────────────────────────────────────────────────────────────────────┐
  │ Symbol: USB_VIDEO_CLASS_INPUT_EVDEV [=n]                                                                                                                      │  
  │ Prompt: UVC input events device support                                                                                                                       │  
  │   Defined at drivers/media/video/uvc/Kconfig:9                                                                                                                │  
  │   Depends on: HAS_IOMEM && VIDEO_CAPTURE_DRIVERS && VIDEO_V4L2 && V4L_USB_DRIVERS && USB && USB_VIDEO_CLASS && INPUT                                          │  
  │   Location:                                                                                                                                                   │  
  │     -> Device Drivers                                                                                                                                         │  
  │       -> Multimedia devices                                                                                                                                   │  
  │         -> Video capture adapters (VIDEO_CAPTURE_DRIVERS [=y])                                                                                                │  
  │           -> V4L USB devices (V4L_USB_DRIVERS [=n])                                                                                                           │  
  │             -> USB Video Class (UVC) (USB_VIDEO_CLASS [=n])                                                                                                   │  
  │                                                                                                                                                               │  
  │                                                                                                                                                               │  
  │ Symbol: USB_VIDEO_CLASS [=n]                                                                                                                                  │  
  │ Prompt: USB Video Class (UVC)                                                                                                                                 │  
  │   Defined at drivers/media/video/uvc/Kconfig:1                                                                                                                │  
  │   Depends on: HAS_IOMEM && VIDEO_CAPTURE_DRIVERS && VIDEO_V4L2 && V4L_USB_DRIVERS && USB                                                                      │  
  │   Location:                                                                                                                                                   │  
  │     -> Device Drivers                                                                                                                                         │  
  │       -> Multimedia devices                                                                                                                                   │  
  │         -> Video capture adapters (VIDEO_CAPTURE_DRIVERS [=y])                                                                                                │  
  │           -> V4L USB devices (V4L_USB_DRIVERS [=n])                                                                                                           │  
  │                                                                                                                                                               │  
  │                                                                                                                                                               │  
...

That's what we're looking for. So we should look in "Device Drivers->Multimedia->Video capture adapters->V4L USB devices" and "Device Drivers-> Multimedia devices->Video capture adapters->V4L USB devices->USB Video Class (UVC). So back out (esc esc) and navigate to it: Toplevel:

...
 │ │                                              Floating point emulation   --->                                                                               │ │  
 │ │                                              Userspace binary formats  --->                                                                               │ │  
 │ │                                              Power management options  --->                                                                               │ │  
 │ │                                          [*] Networking support  --->                                                                                     │ │  
 │ │                                              Device Drivers  --->                                                                                         │ │  
 │ │                                              File systems  --->                                                                                           │ │  
 │ │                                              Kernel hacking  --->                                                                                         │ │  
 │ │                                              Security options  --->                                                                                       │ │  
 │ │                                          -*- Cryptographic API  --->                  
...

Then:

...
 │ │                                          < > Hardware Monitoring support  --->                                                                            │ │  
 │ │                                          [*] Watchdog Timer Support  --->                                                                                 │ │  
 │ │                                              Sonics Silicon Backplane  --->                                                                               │ │  
 │ │                                              Multifunction device drivers  --->                                                                           │ │  
 │ │                                              Multimedia devices  --->                                                                                     │ │  
 │ │                                              Graphics support  --->                                                                                       │ │  
 │ │                                          <*> Sound card support  --->                                                                                     │ │  
 │ │                                          [*] HID Devices  --->                                                                                            │ │  
 │ │                                          [*] USB support  --->                                                                                            │ │ 

...

Then:

...
 │ │                                              *** Multimedia core support ***                                                                              │ │  
 │ │                                          <*> Video For Linux                                                                                              │ │  
 │ │                                          [*]   Enable Video For Linux API 1 (DEPRECATED)                                                                  │ │  
 │ │                                          < > DVB for Linux                                                                                                │ │  
 │ │                                              *** Multimedia drivers ***                                                                                   │ │  
 │ │                                          [ ] Load and attach frontend and tuner driver modules as needed                                                  │ │  
 │ │                                          [ ] Customize analog and hybrid tuner modules to build  --->                                                     │ │  
 │ │                                          [*] Video capture adapters  --->                                                                                 │ │  
 │ │                                          [ ] Radio Adapters  --->                                                                                         │ │  
 │ │                                          [ ] DAB adapters         
...

Then:

 │ ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │  
 │ │                                          --- Video capture adapters                                                                                       │ │  
 │ │                                          [ ]   Enable advanced debug functionality                                                                        │ │  
 │ │                                          [*]   Autoselect pertinent encoders/decoders and other helper chips                                              │ │  
 │ │                                          < >   Virtual Video Driver                                                                                       │ │  
 │ │                                          < >   MXC Video For Linux Camera                                                                                 │ │  
 │ │                                          <M>   MXC Video For Linux Video Output                                                                           │ │  
 │ │                                          < >   CPiA Video For Linux                                                                                       │ │  
 │ │                                          < >   CPiA2 Video For Linux                                                                                      │ │  
 │ │                                          < >   SAA5246A, SAA5281 Teletext processor                                                                       │ │  
 │ │                                          < >   SAA5249 Teletext processor                                                                                 │ │  
 │ │                                          < >   SAB3036 tuner                                                                                              │ │  
 │ │                                          [ ]   V4L USB devices  --->                                                                                      │ │  
 │ │                                          < >   SoC camera support                                                                                         │ │  
 │ │                                          < >   SuperH Mobile CEU Interface driver    
...

Navigate down to V4L USB Devices and hit spacebar to enable:

 │ │                                          < >   SAB3036 tuner                                                                                              │ │  
 │ │                                          [*]   V4L USB devices  --->                                                                                      │ │  
 │ │                                          < >   SoC camera support                                                     
...

Then hit enter to drop into the particular devices you'd like to support. In my case I'm using a Logitech Quickcam Communicate Deluxe/S7500 (046d:09a2), so I'll select only the relevant drivers I need.

...
 │ │                                          --- V4L USB devices                                                                                              │ │  
 │ │                                          <M>   USB Video Class (UVC)                                                                                      │ │  
 │ │                                          [*]     UVC input events device support (NEW)     
...

That's it really. Now we just back out and save our changes.


                                                    ┌──────────────────────────────────────────────────────────┐
                                                    │  Do you wish to save your new kernel configuration?      │  
                                                    │  <ESC><ESC> to continue.                                 │  
                                                    ├──────────────────────────────────────────────────────────┤  
                                                    │                   < Yes >      <  No  >                  │  
                                                    └──────────────────────────────────────────────────────────┘

Compiling

Now you need to actually build your kernel. If you've followed the steps above, you should have the cross-compiler toolchain and mkimage in your path. All you need to do to compile is:

make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi-
make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- uImage
make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- modules
make INSTALL_MOD_PATH=install ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- modules_install

You should see something like:

jconnolly@jconnolly-linux:~/buglabs/dev/misc/bug-linux-2.6.27.2-qa$  make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi-
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf -s arch/arm/Kconfig
  CHK     include/linux/version.h
make[1]: `include/asm-arm/mach-types.h' is up to date.
...
  CC      drivers/video/fbcvt.o
  LD      drivers/video/fb.o
  LD      drivers/video/backlight/built-in.o
  CC      drivers/video/console/dummycon.o
...
  CC      net/wireless/cfg80211.mod.o
  LD [M]  net/wireless/cfg80211.ko
...

After uImage: ...

Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    1735764 Bytes = 1695.08 kB = 1.66 MB
Load Address: 80008000
Entry Point:  80008000
  Image arch/arm/boot/uImage is ready

... After modules:

  ...
  Building modules, stage 2.
  MODPOST 144 modules
  ...

After modules_install:

...
  INSTALL net/netfilter/xt_u32.ko
  INSTALL net/sunrpc/sunrpc.ko
  INSTALL net/wireless/cfg80211.ko
  DEPMOD  2.6.27.2
...

That's it. It's built. Now you need to put it into the right places on your SD card:

ls -haltr arch/arm/boot/
...
-rw-r--r--  1 jconnolly jconnolly  237 2009-12-09 12:53 .uImage.cmd
-rw-r--r--  1 jconnolly jconnolly 1.7M 2009-12-09 12:53 uImage
drwxr-xr-x  5 jconnolly jconnolly 4.0K 2009-12-09 12:53 .
...

Deploying

Directly mounted SD card

Mount your SD card as you would any other piece of ext3 media.

uImage

The uImage you see in the build dir above should go into /boot/ on your BUG's SD card. I usually move the old one and stick the newly built one in its place (there's a symlink at /boot/uImage and I replace the file it points to). Assuming your SD card is mounted and you're at / on it:

mv boot/uImage-2.6.27.2 boot/uImage-2.6.27.2.old
cp /path/to/kernel-build/bug-linux-2.6.27.2/arch/arm/boot/uImage boot/uImage-2.6.27.2

Kernel Modules

The modules were installed into bug-linux-2.6.27.2/install, where you built them before. I usually tar/gzip them up for handy packaging.

cd install
tar czvf ../modules.tar.gz lib
cp ../modules.tar.gz /media/SD/

I just copied all the modules into the root dir of the SD card. Now I want to move the old ones and untar/ungzip them into the rootfs:

cd /media/SD/
mv -f lib/modules/2.6.27.2 lib/modules/2.6.27.2.old
tar xzvf modules.tar.gz\
...
lib/
lib/modules/
lib/modules/2.6.27.2/
lib/modules/2.6.27.2/modules.seriomap
lib/modules/2.6.27.2/modules.symbols
lib/modules/2.6.27.2/modules.inputmap
lib/modules/2.6.27.2/modules.symbols.bin
...

Depmod

That's it--well, almost. If you have a dock, this is easy, simply pop the SD card into your BUG and boot it. When you get to the command line:

root@BUG:~# depmod

After you've done that, the meta information about each kernel module and your kernel image will be renewed and you should be good to reboot again and see all the usual messages and kernel modules loaded. If you don't have a dock, you can force the BUG to do this upon first boot by adding an init script (assuming your SD is mounted at /media/SD):

cd /media/SD
vi etc/init.d/depmod.sh

add:

#!/bin/sh
depmod -a

chmod it:

chmod 775 etc/init.d/depmod.sh

link it:

ln -s etc/init.d/depmod.sh etc/rc5.d/S99depmod.sh

And just boot it, then reboot it. After that you should be good to go. You may want to remove the depmod script (though it's not really harmful if it runs) to reduce the slight boot time increase.