blob: 195da688f47fbee36e01cf951ac0c2db8b052229 [file] [log] [blame]
Sam Protsenkod8efc7c2020-01-24 17:53:43 +02001.. SPDX-License-Identifier: GPL-2.0+
2.. sectionauthor:: Sam Protsenko <joe.skb7@gmail.com>
3
4Android Boot Image
5==================
6
7Overview
8--------
9
10Android Boot Image is used to boot Android OS. It usually contains kernel image
11(like ``zImage`` file) and ramdisk. Sometimes it can contain additional
12binaries. This image is built as a part of AOSP (called ``boot.img``), and being
13flashed 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.
17
18Android Boot Image format is described at [1]_. At the moment it can have one of
19next image headers:
20
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
23 (usually unused)
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
26 details)
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)
30
31v2, v1 and v0 formats are backward compatible.
32
33Android Boot Image format is represented by :c:type:`struct andr_img_hdr` in
34U-Boot, and can be seen in ``include/android_image.h``. U-Boot supports booting
35Android Boot Image and also has associated command
36
37Booting
38-------
39
40U-Boot is able to boot the Android OS from Android Boot Image using ``bootm``
41command. In order to use Android Boot Image format support, next option should
42be enabled::
43
44 CONFIG_ANDROID_BOOT_IMAGE=y
45
46Then one can use next ``bootm`` command call to run Android:
47
48.. code-block:: bash
49
50 => bootm $loadaddr $loadaddr $fdtaddr
51
52where ``$loadaddr`` - address in RAM where boot image was loaded; ``$fdtaddr`` -
53address in RAM where DTB blob was loaded.
54
55And parameters are, correspondingly:
56
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
60
61``bootm`` command will figure out that image located in ``$loadaddr`` has
62Android Boot Image format, will parse that and boot the kernel from it,
63providing DTB blob to kernel (from 3rd parameter), passing info about ramdisk to
64kernel via DTB.
65
66DTB and DTBO blobs
67------------------
68
69``bootm`` command can't just use DTB blob from Android Boot Image (``dtb``
70field), because:
71
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)
76
77So user has to prepare DTB blob manually and provide it in a 3rd parameter
78of ``bootm`` command. Next commands can be used to do so:
79
801. ``abootimg``: manipulates Anroid Boot Image, allows one to extract
81 meta-information and payloads from it
822. ``adtimg``: manipulates Android DTB/DTBO image [3]_, allows one to extract
83 DTB/DTBO blobs from it
84
85In order to use those, please enable next config options::
86
87 CONFIG_CMD_ABOOTIMG=y
88 CONFIG_CMD_ADTIMG=y
89
90For example, let's assume we have next Android partitions on eMMC:
91
92* ``boot``: contains Android Boot Image v2 (including DTB blobs)
93* ``dtbo``: contains DTBO blobs
94
95Then next command sequence can be used to boot Android:
96
97.. code-block:: bash
98
99 => mmc dev 1
100
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
105
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
110
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
114
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
120
121 # Boot Android
122 => bootm $loadaddr $loadaddr $fdtaddr
123
124This sequence should be used for Android 10 boot. Of course, the whole Android
125boot procedure includes much more actions, like:
126
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]_)
132
133But Android Boot Image booting is the most crucial part in Android boot scheme.
134
135All Android bootloader requirements documentation is available at [7]_. Some
136overview on the whole Android 10 boot process can be found at [8]_.
137
138C API for working with Android Boot Image format
139------------------------------------------------
140
141.. kernel-doc:: common/image-android.c
142 :internal:
143
144References
145----------
146
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
150.. [4] :doc:`bcb`
151.. [5] :doc:`ab`
152.. [6] :doc:`avb2`
153.. [7] https://source.android.com/devices/bootloader
154.. [8] https://connect.linaro.org/resources/san19/san19-217/