Mar 19, 2012

Parody of Android Kernel

Well we have reference how to set our PC up for android kernel development AT DELL VENUE PAGE and How to prepare kernel compilation at BUILDING ANDROID KERNEL FROM SOURCE in LINUX .
Question ?
How to obtain kernel config file and named into .config [read : DOTconfig]. On the previous page, we obtain config file by pulling from a live device. If you don't have live device and wanna to leran how to compile an android kernel, we can use available prebuilt configuration located at folder ~/kernel/arch/arm/configs let us see what are available for msmgit kernel source . On terminla in the folder where you store kernel tree, execute >
[x@ThinkPad msm-kernel]$ ls arch/arm/configs
acs5k_defconfig
iop13xx_defconfig
omap_innovator_1610_defconfig
ezx_defconfig
omap3_defconfig
surf7x30_defconfig
footbridge_defconfig
omap3_evm_defconfig
swordfish_defconfig
..... AND MANY MORE defconfig file you can utilized


Let say you wanna to build a android kernel for swordfish board, then on terminal just execute a command >
$armmake swordfish_defconfig

You will have DOTconfig file among kernel tree. To compile the kernel then just execute >
$armmake swordfish_defconfig
Output will be
#
# configuration written to .config
#
Then execute another command >
$time armmake -j5

... and wait long phyton process ... average to compile a android kernel about 15-35 minutes


For lucks and No Error ... kernel will be available at folder [KERNER_TREE_STORED_FOLDER]/arch/arm/boot .. named zImage
If you read any warning .. just ignore, warning is No Problem. They are normally just unresolved BUGS from kernel hackers. But once you face ERROR and build process STOP ... the disaster is coming. We probably DO NOT KNOW anything the cause of error. It's time to do GOOGLING, joining kernel-dev mailling list or forum.

Flashing kernel to a Device
From above process, let say we have dell-venue. Connect dell venue live device to PC with adb obtain kernel config file, by execute >
$ sudo adb start-server
$adb pull /proc/config.gz
$gunzip config.gz > .config
$armmake menuconfig

...EDIT WHAT YOU WANT OR JUST LET AS DEFAULT...
...save cnfig file
$time armmake -j5

Presumed, we can tackle all error and successfully build a kernel image. The pain is not over :D .... since we need to do something to flash the kernel into the device. Now we are in the kernel tree folder with success build of an android kernel image. store somewhere the kernel image for further use. Execute a comman >
$mkdir ~/dell-kernel
we create a folder to store built kernel
$ cp arch/arm/boot/zImage_SPACE_~/dell-kernel/
Clean the kernel tree for further use
$armmake distclean
Start working with kernel image
$cd ~/dell-kernel

Now we are in dell-kernel folder. Theoritically we can TEST our kernel build, it will bootable into device or not :D ... turn your dell venue device into boot loader mode (fastboot). Your dell venue device is connected to PC with adb alive. Execute >
$adb reboot bootloader
... dell venue device should turn into bootloader mode

To turn dell venue into bootloader mode without adb we can set in the device > set vibrate button > press power button + volume down button simultaneously


Dell Venue on Fastboot mode >


Theoritically .. we can flash kernel image (zImage in this case) into device to see the image bootable or not. Execute >
$sudo fastboot boot zImage

zImage is the file name of kernel image
device should be reboot (if everything goes well) and new kernel alive booting on the device
. In real life, the thing never so easy. If you test by that way kernel not booting, or something wrong happened. let us do test, that our kernel build is in proper and bootbale kernel. To enable flash the kernel into a device, we need to turn the image into flashable image and packed with RAMDISK. What is ramdisk ... just googling to learn. How to create ramdisk? this page will not guide how to create ramdisk. This guid is specific we will use available ramdisk to test our kernel build for dell venue.
In short wen are going to "borrow" ramdisk from live bootable image and packed with our build kernel and flashed to dell venue to test. Our build is correct
. Let us find boot image which is proved bootable into dell venue. I toke 408-frimware of dell venue and toke the boot image (usually named boot.img. If you don't have download 408 VENUE BOOT IMAGE FILE save into you home folder you can put in the dell-kernel forlder we create previously.
We need to split this boot.img file to have kernel and ramdisk, edit the ramdisk (if we wish), repacked with our own kernel and flash into device. Some additional tools is required. Nevermind ... I provide for you. Download tools IMAGE TOOLS . Extract somewhere in the forlder and The important file for our operations are :
- split_bootimg.pl
- unpack_bootimg.pl
- repack_bootimg.pl
- mkbootfs
- mkbootimg
We have two options to store these executable files.
1. Store in the folder ~/bin and export the PATH to enable ~/bin functining globally. Presumed we are in the folder where we store above files and wanna to copy to ~/bin folder. Execute >
$cp split_bootimg.pl unpack_bootimg.pl repack_bootimg.pl mkbootfs mkbootimg_SPACE_~/bin
$chmod +x ~/bin/*
NOTE : if you set up properly the development environment as DECRIBED HERE you ~/bin folder is in your path. Otherwise you need to export the PATH


2. Store above five files into /usr/bin. You need cp command like above and the destination folder is /usr/bin.Execute >
$cp split_bootimg.pl unpack_bootimg.pl repack_bootimg.pl mkbootfs mkbootimg_SPACE_/usr/bin
$sudo chmod +x /usr/bin/*
NOTE : We need SUDO, due to /usr/bin is not accessible by our regular user. We need root previllege to modify files there

We have all required tools for this action. Navigate to > $ cd ~/dell-kernel in this folder we have boot408.img and zImage file. We are going to have fun with these TWO files.
We need to split boot408.img to have "kernel" and "ramdisk" and we going to "borrow" ramdisk file repack with our own kernel and flash into device. Execute >
$split_bootimg.pl_SPACE_boot408.img
WATCH THE OUTPUT DURING EXCUTE THIS COMMAND SINCE YOU WILL SEE VERY IMPORTANT INFORMATION
Page size: 2048 (0x00000800)
Kernel size: 3092536 (0x002f3038)
Ramdisk size: 168270 (0x0002914e)
Second size: 0 (0x00000000)
Board name:
Command line: androidboot.hardware=venue
Writing boot408.img-kernel ... complete.
Writing boot408.img-ramdisk.gz ... complete.
I SUGGESTED YOU COPY ALL OUTPUT TEXT AND PASTE INTO TEXT EDITOR AND SAVE WITH file name dell-venue-kernel-detils.txt SAVE ANYWHERE YOU LIKE

Now in folder ~/dell-kernel we have files>
boot408.img
boot408.img-kernel
boot408.img-ramdisk.gz
zImage

We are going to make it simple. Test our kernel. We need to create bootable image consisted of our kernel (zImage) and ramdisk (boot408.img-ramdisk.gz). Execute the following command >
$mkbootimg --kernel zImage --ramdisk boot408.img-ramdisk.gz --pageszie 2048 --cmdline "androidboot.hardware=venue" --base 0x20000000 -o venueboot.img

The bootable image NAMED venueboot.img should be there, and flashable to device via fastboot
$sudo fastboot flash boot venueboot.img
THREE minimum option : --pagesize --cmdline --base (ARE MANDATORY) otherwise our bootimage will NOT BOOTABLE. Check the mkbootimg usage here>
[x@ThinkPad test]$ mkbootimg -h
usage: mkbootimg
--kernel [filename]
--ramdisk [filename]
[ --second [2ndbootloader-filename] ]
[ --cmdline [kernel-commandline] ]
[ --board [boardname>] ]
[ --base [address] ]
[ --pagesize [pagesize] ]
[ --ramdiskaddr [address] ]
-o|--output [filename]

Parody ...? Yess .. to just a build and make a kernel booting into our device. we need to collect so many informations, which is sometimes DID NOT available on the Internet......
Have Fun

Real Multilib Userland on Linux

Read multilib requirement on Android rom building and other stuff. About two years absent from getting rid with android rom. I have time to...