kernel build environment

時間が取れたため、以前からチェックしていたcreams@nexusさんの記事を参考にkernel buildを行いました。基本的には記事のとおりに実行するだけなのですが、躓いた箇所があったため、備忘録として残しておきます。Android open source projectも参考になります。

VMware Player

普段はWindows環境を使用しているため、ここではVMware Playerを使った仮想マシンにbuild環境を導入します。Ubuntuの10.04以降が必要です。先日リリースされた11.04を触ってみたかったこともあり、11.04をダウンロードしました(32bit)。
最近のVMware Playerは、仮想マシンの新規作成も可能となっており、インストールディスクイメージとしてダウンロードしたisoファイルを指定すると、簡易インストールまで行ってくれます。ちなみに、ハードウェアの構成をイジり、メモリは1024MB、プロセッサ数は2、としました。
インストールが終わると、ログイン画面となります。ここで、keyboardをJapaneseに、shellをClassicに切り替えておきます。
ログイン後はとりあえず、System→Administration→Update ManagerからUpdateを行います。一段落ついたところで、一度シャットダウンして仮想マシンのバックアップ(単なるコピー)を行っておくと、失敗したときのリカバリーが楽になるかもしれません。

Setting up a Linux build environment

Installing the JDK
$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk
Installing required packages
$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev g++ valgrind libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline5-dev libz-dev libwxgtk2.6-dev libsdl-dev libesd0-dev zlib1g-dev

Downloading the Source Tree

Installing Repo
$ mkdir ~/bin
$ PATH=~/bin:$PATH

$ curl http://android.git.kernel.org/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
Initializing a Repo client
$ mkdir mydroid
$ cd mydroid

$ repo init -u git://android.git.kernel.org/platform/manifest.git
$ repo init -u git://android.git.kernel.org/platform/manifest.git -b gingerbread
Getting the files

1〜2時間ほど待つ必要があります。

$ repo sync

その他のツールを準備

mkbootfsとmkbootimgのコンパイル

MEDIA STREETさんの記事を参考にコンパイルします。海外のフォーラムを探すとバイナリが落ちていることもありますが、古いためかpagesizeオプションがありません。

$ cd ~/mydroid/system/core/cpio
$ gcc -I../include -o mkbootfs mkbootfs.c
$ mv mkbootfs ~/bin
$ cd ~/mydroid/system/core/mkbootimg
$ gcc -I../include -o mkbootimg mkbootimg.c ../libmincrypt/rsa.c ../libmincrypt/sha.c
$ mv mkbootimg ~/bin
$ cd ~/bin
$ ls -l

-rwxr-xr-x 1 norite norite 13598 2011-05-07 12:26 mkbootfs
-rwxr-xr-x 1 norite norite 16496 2011-05-07 12:25 mkbootimg
-rwxr-xr-x 1 norite norite 17451 2011-05-06 12:34 repo
-rwxrw-rw- 1 norite norite  6121 2011-05-07 00:35 split_bootimg.pl
split_bootimg.plの入手

zen-droidから入手できます。~/binにコピーしておきます。

build kernel

Get kernel
$ git clone git://android.git.kernel.org/kernel/samsung.git
make
$ cd samsung
$ make ARCH=arm herring_defconfig
$ make -j2 ARCH=arm CROSS_COMPILE=/home/norite/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-

  CHK     include/linux/version.h
  CHK     include/generated/utsrelease.h
make[1]: `include/generated/mach-types.h' is up to date.
  CALL    scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  Kernel: arch/arm/boot/Image is ready
  Building modules, stage 2.
  MODPOST 3 modules
  SHIPPED arch/arm/boot/compressed/lib1funcs.S
  AS      arch/arm/boot/compressed/lib1funcs.o
  LD      arch/arm/boot/compressed/vmlinux
  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready
zImageの確認
$ cd ~/mydroid/samsung/arch/arm/boot/
$ ls -l | grep zImage

-rwxr-xr-x 1 norite norite 2828616 2011-05-07 13:59 zImage
split_bootimg

boot.imgはclockworkmodのbackupから持ってきました

$ split_bootimg.pl boot.img

Page size: 4096 (0x00001000)
Kernel size: 2825092 (0x002b1b84)
Ramdisk size: 142677 (0x00022d55)
Second size: 0 (0x00000000)
Board name: 
Command line: console=ttyFIQ0 no_console_suspend
Writing boot.img-kernel ... complete.
Writing boot.img-ramdisk.gz ... complete.

$ ls -l | grep boot.img

-rwxrw-rw- 1 norite norite 8388608 2011-04-30 01:40 boot.img
-rw-r--r-- 1 norite norite 2825092 2011-05-07 14:05 boot.img-kernel
-rw-r--r-- 1 norite norite  142677 2011-05-07 14:05 boot.img-ramdisk.gz
mkbootimg
$ mkbootimg --cmdline 'console=ttyFIQ0 no_console_suspend' --kernel zImage --base 0x30000000 --pagesize 4096 --ramdisk boot.img-ramdisk.gz -o myboot.img
$ ls -l | grep myboot.img

-rw-r--r-- 1 norite norite 2977792 2011-05-07 14:06 myboot.img
myboot.imgの適用

端末をfastbootモードにしてから

$ fastboot boot myboot.img

とし、起動することを確認する。また、ホーム画面のメニューから設定→端末情報→カーネルバージョンを見ることで

2.6.35.7-ge382d80
norite@ubuntu #1

自前のkernelになっていることが確認できます。