Booting Android: Bootloaders, Fastboot and Boot Images
Booting Android: Bootloaders, Fastboot and Boot Images
• Share Alike: if you alter, transform, or build upon this work, you may distribute
the resulting work only under a license identical to this one (i.e. include this
page exactly as it is)
• For any reuse or distribution, you must make clear to others the license terms of
this work
https://uk.linkedin.com/in/chrisdsimmonds/
https://google.com/+chrissimmonds
From system/core/mkbootimg/bootimg.h
struct boot_img_hdr {
ramdisk unsigned char magic[8]; // "ANDROID!"
image unsigned kernel_size;
(compressed unsigned kernel_addr;
unsigned ramdisk_size;
cpio) unsigned ramdisk_addr;
unsigned second_size; // 2nd image: not used
unsigned second_addr;
unsigned tags_addr;
unsigned page_size; // typically 2048
unsigned unused[2];
unsigned char name[16]; // product name
unsigned char cmdline[512]; // kernel cmdline
Kernel unsigned id[8]; // timestamp/checksum/etc
image unsigned char extra_cmdline[1024];
(zImage) };
Header
Load normal
kernel and ramdisk
Load recovery
kernel and ramdisk Run /init
Read init*.rc
Mount file systems
Start services
Recovery Normal
mode mode
• Do the following
$ cd some-directory
$ find . | cpio -H newc --owner root:root -ov > ∼/ramdisk.cpio
$ cd ∼
$ gzip ramdisk.cpio
Basic commands
Command Description
devices List devices attached that will accept fast-
boot commands
getvar Get a variable
continue Continue boot process as normal
reboot Reboot device
reboot-bootloader Reboot back into bootloader
Command Description
erase <partition> Erase <partition>
flash <partition> Erase and program <partition>
with <partition>.img of current
product
flash <partition> <filename> Erase and program <partition>
with <filename>
flashall Erase and program boot.img,
recovery.img and system.img of
current product and then reboot
Where
<partition> is one of boot, recovery, system, userdata, cache
current product is $ANDROID_PRODUCT_OUT
Note: the location and size of partitions is hard-coded in the bootloader
Special commands
Command Description
oem Device-specific operations
boot <kernel> <ramdisk> Load and boot kernel and ramdisk
Example:
$ fastboot -c "kernel command line" boot zImage ramdisk.cpio.gz
system.img: read-only
ramdisk.img:
/app built-in Android apps
read-only
/bin native binaries
ramdisk
/framework Java components of framework
/lib native libraries
...