1 .. SPDX-License-Identifier: GPL-2.0+
2 .. sectionauthor:: Sam Protsenko <joe.skb7@gmail.com>
10 Android Boot Image is used to boot Android OS. It usually contains kernel image
11 (like ``zImage`` file) and ramdisk. Sometimes it can contain additional
12 binaries. This image is built as a part of AOSP (called ``boot.img``), and being
13 flashed into ``boot`` partition on eMMC. Bootloader then reads that image from
14 ``boot`` partition to RAM and boots the kernel from it. Kernel than starts
15 ``init`` process from the ramdisk. It should be mentioned that recovery image
16 (``recovery.img``) also has Android Boot Image format.
18 Android Boot Image format is described at [1]_. At the moment it can have one of
21 * v0: it's called *legacy* boot image header; used in devices launched before
22 Android 9; contains kernel image, ramdisk and second stage bootloader
24 * v1: used in devices launched with Android 9; adds ``recovery_dtbo`` field,
25 which should be used for non-A/B devices in ``recovery.img`` (see [2]_ for
27 * v2: used in devices launched with Android 10; adds ``dtb`` field, which
28 references payload containing DTB blobs (either concatenated one after the
29 other, or in Android DTBO image format)
31 v2, v1 and v0 formats are backward compatible.
33 Android Boot Image format is represented by :c:type:`struct andr_img_hdr` in
34 U-Boot, and can be seen in ``include/android_image.h``. U-Boot supports booting
35 Android Boot Image and also has associated command
40 U-Boot is able to boot the Android OS from Android Boot Image using ``bootm``
41 command. In order to use Android Boot Image format support, next option should
44 CONFIG_ANDROID_BOOT_IMAGE=y
46 Then one can use next ``bootm`` command call to run Android:
50 => bootm $loadaddr $loadaddr $fdtaddr
52 where ``$loadaddr`` - address in RAM where boot image was loaded; ``$fdtaddr`` -
53 address in RAM where DTB blob was loaded.
55 And parameters are, correspondingly:
57 1. Where kernel image is located in RAM
58 2. Where ramdisk is located in RAM (can be ``"-"`` if not applicable)
59 3. Where DTB blob is located in RAM
61 ``bootm`` command will figure out that image located in ``$loadaddr`` has
62 Android Boot Image format, will parse that and boot the kernel from it,
63 providing DTB blob to kernel (from 3rd parameter), passing info about ramdisk to
69 ``bootm`` command can't just use DTB blob from Android Boot Image (``dtb``
72 * there is no DTB area in Android Boot Image before v2
73 * there may be several DTB blobs in DTB area (e.g. for different SoCs)
74 * some DTBO blobs may have to be merged in DTB blobs before booting
75 (e.g. for different boards)
77 So user has to prepare DTB blob manually and provide it in a 3rd parameter
78 of ``bootm`` command. Next commands can be used to do so:
80 1. ``abootimg``: manipulates Anroid Boot Image, allows one to extract
81 meta-information and payloads from it
82 2. ``adtimg``: manipulates Android DTB/DTBO image [3]_, allows one to extract
83 DTB/DTBO blobs from it
85 In order to use those, please enable next config options::
90 For example, let's assume we have next Android partitions on eMMC:
92 * ``boot``: contains Android Boot Image v2 (including DTB blobs)
93 * ``dtbo``: contains DTBO blobs
95 Then next command sequence can be used to boot Android:
101 # Read boot image to RAM (into $loadaddr)
102 => part start mmc 1 boot boot_start
103 => part size mmc 1 boot boot_size
104 => mmc read $loadaddr $boot_start $boot_size
106 # Read DTBO image to RAM (into $dtboaddr)
107 => part start mmc 1 dtbo dtbo_start
108 => part size mmc 1 dtbo dtbo_size
109 => mmc read $dtboaddr $dtbo_start $dtbo_size
111 # Copy required DTB blob (into $fdtaddr)
112 => abootimg get dtb --index=0 dtb0_start dtb0_size
113 => cp.b $dtb0_start $fdtaddr $dtb0_size
115 # Merge required DTBO blobs into DTB blob
116 => fdt addr $fdtaddr 0x100000
117 => adtimg addr $dtboaddr
118 => adtimg get dt --index=0 $dtbo0_addr
119 => fdt apply $dtbo0_addr
122 => bootm $loadaddr $loadaddr $fdtaddr
124 This sequence should be used for Android 10 boot. Of course, the whole Android
125 boot procedure includes much more actions, like:
127 * obtaining reboot reason from BCB (see [4]_)
128 * implementing recovery boot
129 * implementing fastboot boot
130 * implementing A/B slotting (see [5]_)
131 * implementing AVB2.0 (see [6]_)
133 But Android Boot Image booting is the most crucial part in Android boot scheme.
135 All Android bootloader requirements documentation is available at [7]_. Some
136 overview on the whole Android 10 boot process can be found at [8]_.
138 C API for working with Android Boot Image format
139 ------------------------------------------------
141 .. kernel-doc:: common/image-android.c
147 .. [1] https://source.android.com/devices/bootloader/boot-image-header
148 .. [2] https://source.android.com/devices/bootloader/recovery-image
149 .. [3] https://source.android.com/devices/architecture/dto/partitions
153 .. [7] https://source.android.com/devices/bootloader
154 .. [8] https://connect.linaro.org/resources/san19/san19-217/