Android: Boot image
Contents
Overview
Android boot image (boot.img file) packs
- boot header containing, among others, kernel command line
- kernel binary image
- ramdisk serving as the root of Android file system
- optionally, a 2-nd stage bootloader
The boot image format is not limited to Android only - it can pack any OS kernel including, but not limited to, Linux, whereas ramdisk is optional.
Two tools are available for boot image manipulation:
- mkbootimg - an official utility used to pack boot images. It is a part of Android project.
- abootimg - an alternative utility used to both pack and unpack boot images.
Getting mkbootimg
mkbootimg is a part of Android project, and is built within Android build process.
Upon build completion, mkbootimg binary file is located at out/host/linux-x86/bin/mkbootimg.
Getting abootimg
abootimg can be obtained in either source code form or via Linux distribution repositories. For example, on Ubuntu platform, abootimg may be obtained via abootimg package.
Sample boot image manipulations
Unpacking boot image
$ abootimg -x boot.img $ ls bootimg.cfg # boot header zImage # kernel initrd.img # ramdisk
Unpacking ramdisk
$ mkdir ramdisk $ cd ramdisk $ gunzip -c ../initrd.img | cpio -i $ ls data dev proc ...
Packing ramdisk
$ cd ramdisk $ find . | cpio -o -H newc | gzip > ../newramdisk.img
Packing boot image
$ abootimg --create boot.img -k zImage -r newramdisk.img -c "pagesize=2048" -c "kerneladdr=0x80208000" -c "ramdiskaddr=0x82200000" -c "tagsaddr=0x80200100" -c "cmdline=console=ttyHSL0,115200n8 ..."
Packing boot image with no ramdisk
Due to its Android-oriented assumptions, abootimg does not allow creating ramdisk-less boot image. However, ramdisk-less boot image is quite appropriate for booting Linux. This is possible falling back to mkbootimg utility:
$ mkbootimg --kernel zImage --ramdisk NONE --pagesize 2048 --base 0x80200100 --cmdline "console=ttyHSL0,115200n8 ..." --output boot.img