Skip to contentSkip to conversation

am57xx: Implement Android 10 boot flow

PATCH New Sam Protsenko 3 participants 13 messages Jan 24, 2020 – Feb 4, 2020

lore
Share & tools
lore
#0 lore raw

v4 cover am57xx: Implement Android 10 boot flow

Android 10 brings a lot of new requirements for bootloaders: [1]. This patch series attempts to implement such a boot process on BeagleBoard X15 platform. Some common code is added too, which can be reused later for other platforms (see "abootimg" command and associated C API).

Changes in v4:
- fixed broken build due to recent load_addr -> image_load_addr renaming
- added "doc: android: Convert to Sphinx format" patch to series
- addressed pending comments for v3 on mailing list
- rebased series on top of current master

Changes in v3:
- rename command to "abootimg" (requested by Simon Glass)
- rework command interface (as discussed with Eugeniu)
- add command documentation
- address other comments

[1] https://source.android.com/devices/bootloader

Sam Protsenko (10):
image: android: Add functions for handling dtb field
image: android: Add routine to get dtbo params
cmd: abootimg: Add abootimg command
doc: android: Add documentation for Android Boot Image
doc: android: Convert to Sphinx format test/py: android: Add test for abootimg
configs: am57xx_evm: Enable Android commands
env: ti: boot: Respect slot_suffix in AVB commands
env: ti: boot: Boot Android with dynamic partitions
arm: ti: boot: Use correct dtb and dtbo on Android boot

 MAINTAINERS                                   |   4 +-
 cmd/Kconfig                                   |  12 +-
 cmd/Makefile                                  |   1 +
 cmd/abootimg.c                                | 258 ++++++++++++++++
 common/Makefile                               |   2 +-
 common/image-android.c                        | 282 ++++++++++++++++++
 configs/am57xx_evm_defconfig                  |   6 +
 configs/am57xx_hs_evm_defconfig               |   6 +
 configs/am57xx_hs_evm_usb_defconfig           |   6 +
 configs/sandbox_defconfig                     |   1 +
 doc/android/{ab.txt => ab.rst}                |  39 +--
 doc/android/avb2.rst                          | 133 +++++++++
 doc/android/avb2.txt                          | 115 -------
 doc/android/bcb.rst                           | 100 +++++++
 doc/android/bcb.txt                           |  89 ------
 doc/android/boot-image.rst                    | 154 ++++++++++
 ...oot-protocol.txt => fastboot-protocol.rst} |  45 +--
 doc/android/{fastboot.txt => fastboot.rst}    |  92 +++---
 doc/android/index.rst                         |  14 +
 doc/index.rst                                 |  12 +
 include/configs/ti_armv7_common.h             |   7 +
 include/environment/ti/boot.h                 | 154 +++++-----
 include/image.h                               |   6 +
 test/py/tests/test_android/test_abootimg.py   | 159 ++++++++++
 test/py/tests/test_android/test_avb.py        |   2 +-
 25 files changed, 1335 insertions(+), 364 deletions(-)
 create mode 100644 cmd/abootimg.c
 rename doc/android/{ab.txt => ab.rst} (52%)
 create mode 100644 doc/android/avb2.rst
 delete mode 100644 doc/android/avb2.txt
 create mode 100644 doc/android/bcb.rst
 delete mode 100644 doc/android/bcb.txt
 create mode 100644 doc/android/boot-image.rst
 rename doc/android/{fastboot-protocol.txt => fastboot-protocol.rst} (82%)
 rename doc/android/{fastboot.txt => fastboot.rst} (79%)
 create mode 100644 doc/android/index.rst
 create mode 100644 test/py/tests/test_android/test_abootimg.py
Signature · 1 line
2.24.0
#1 lore raw

PATCH v4 1/10 image: android: Add functions for handling dtb field

Android Boot Image v2 adds "DTB" payload (and corresponding field in the image header). Provide functions for its handling:

- android_image_get_dtb_by_index(): Obtain DTB blob from "DTB" part of boot image, by blob's index
- android_image_print_dtb_contents(): Iterate over all DTB blobs in "DTB" part of boot image and print those blobs info

"DTB" payload might be in one of the following formats:
1. concatenated DTB blobs
2. Android DTBO format

The latter requires "android-image-dt.c" functionality, so this commit selects that file for building for CONFIG_ANDROID_BOOT_IMAGE option.

Right now this new functionality isn't used, but it can be used further. As it's required to apply some specific dtbo blob(s) from "dtbo" partition, we can't automate this process inside of "bootm" command. But we can do next:
- come up with some new command like "abootimg" to extract dtb blob from boot image (using functions from this patch)
- extract desired dtbo blobs from "dtbo" partition using "adtimg" command
- merge dtbo blobs into dtb blob using "fdt apply" command
- pass resulting dtb blob into bootm command in order to boot the Android kernel with Android ramdisk from boot image

---
 common/Makefile        |   2 +-
 common/image-android.c | 221 +++++++++++++++++++++++++++++++++++++++++
 include/image.h        |   5 +
 3 files changed, 227 insertions(+), 1 deletion(-)
common/Makefile +1 -1
index 5f62b8d0b1..896e4af91d 100644
@@ -108,7 +108,7 @@ endif
 
 obj-y += image.o
 obj-$(CONFIG_ANDROID_AB) += android_ab.o
-obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o
+obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
 obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o
 obj-$(CONFIG_$(SPL_)MULTI_DTB_FIT) += boot_fit.o common_fit.o
common/image-android.c +221 -0

241 lines not on this page · raw message

include/image.h +5 -0
index 9c6b6d6054..4e36b87f42 100644
@@ -1425,10 +1425,15 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
 			      ulong *rd_data, ulong *rd_len);
 int android_image_get_second(const struct andr_img_hdr *hdr,
 			      ulong *second_data, ulong *second_len);
+bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
+				    u32 *size);
 ulong android_image_get_end(const struct andr_img_hdr *hdr);
 ulong android_image_get_kload(const struct andr_img_hdr *hdr);
 ulong android_image_get_kcomp(const struct andr_img_hdr *hdr);
 void android_print_contents(const struct andr_img_hdr *hdr);
+#if !defined(CONFIG_SPL_BUILD)
+bool android_image_print_dtb_contents(ulong hdr_addr);
+#endif
 
 #endif /* CONFIG_ANDROID_BOOT_IMAGE */
 
Signature · 1 line
2.24.0
#2 lore raw

PATCH v4 2/10 image: android: Add routine to get dtbo params

In reply to Sam Protsenko

Android Boot Image v1 adds "Recovery DTB" field in image header and associate payload in boot image itself [1]. Payload should be in Android DTB/DTBO format [2]. That "Recovery DTB" area should be only populated for non-A/B devices, and only in recovery image.

Add function to get an address and size of that payload. That function can be further used e.g. in 'abootimg' command to provide the user a way to get the address of recovery dtbo from U-Boot shell, which can be further parsed using 'adtimg' command.

[1] https://source.android.com/devices/bootloader/boot-image-header
[2] https://source.android.com/devices/architecture/dto/partitions

---
 common/image-android.c | 61 ++++++++++++++++++++++++++++++++++++++++++
 include/image.h        |  1 +
 2 files changed, 62 insertions(+)
common/image-android.c +61 -0
index 220983655a..6af9baa121 100644
@@ -197,6 +197,67 @@ int android_image_get_second(const struct andr_img_hdr *hdr,
 	return 0;
 }
 
+/**
+ * android_image_get_dtbo() - Get address and size of recovery DTBO image.
+ * @hdr_addr: Boot image header address
+ * @addr: If not NULL, will contain address of recovery DTBO image
+ * @size: If not NULL, will contain size of recovery DTBO image
+ *
+ * Get the address and size of DTBO image in "Recovery DTBO" area of Android
+ * Boot Image in RAM. The format of this image is Android DTBO (see
+ * corresponding "DTB/DTBO Partitions" AOSP documentation for details). Once
+ * the address is obtained from this function, one can use 'adtimg' U-Boot
+ * command or android_dt_*() functions to extract desired DTBO blob.
+ *
+ * This DTBO (included in boot image) is only needed for non-A/B devices, and it
+ * only can be found in recovery image. On A/B devices we can always rely on
+ * "dtbo" partition. See "Including DTBO in Recovery for Non-A/B Devices" in
+ * AOSP documentation for details.
+ *
+ * Return: true on success or false on error.
+ */
+bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size)
+{
+	const struct andr_img_hdr *hdr;
+	ulong dtbo_img_addr;
+	bool ret = true;
+
+	hdr = map_sysmem(hdr_addr, sizeof(*hdr));
+	if (android_image_check_header(hdr)) {
+		printf("Error: Boot Image header is incorrect\n");
+		ret = false;
+		goto exit;
+	}
+
+	if (hdr->header_version < 1) {
+		printf("Error: header_version must be >= 1 to get dtbo\n");
+		ret = false;
+		goto exit;
+	}
+
+	if (hdr->recovery_dtbo_size == 0) {
+		printf("Error: recovery_dtbo_size is 0\n");
+		ret = false;
+		goto exit;
+	}
+
+	/* Calculate the address of DTB area in boot image */
+	dtbo_img_addr = hdr_addr;
+	dtbo_img_addr += hdr->page_size;
+	dtbo_img_addr += ALIGN(hdr->kernel_size, hdr->page_size);
+	dtbo_img_addr += ALIGN(hdr->ramdisk_size, hdr->page_size);
+	dtbo_img_addr += ALIGN(hdr->second_size, hdr->page_size);
+
+	if (addr)
+		*addr = dtbo_img_addr;
+	if (size)
+		*size = hdr->recovery_dtbo_size;
+
+exit:
+	unmap_sysmem(hdr);
+	return ret;
+}
+
 /**
  * android_image_get_dtb_img_addr() - Get the address of DTB area in boot image.
  * @hdr_addr: Boot image header address
include/image.h +1 -0
index 4e36b87f42..b316d167d8 100644
@@ -1425,6 +1425,7 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
 			      ulong *rd_data, ulong *rd_len);
 int android_image_get_second(const struct andr_img_hdr *hdr,
 			      ulong *second_data, ulong *second_len);
+bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size);
 bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
 				    u32 *size);
 ulong android_image_get_end(const struct andr_img_hdr *hdr);
Signature · 1 line
2.24.0
#3 lore raw

PATCH v4 3/10 cmd: abootimg: Add abootimg command

In reply to Sam Protsenko

This command can be used to extract fields and image payloads from Android Boot Image. It can be used for example to implement boot flow where dtb is taken from boot.img (as v2 incorporated dtb inside of boot.img). Using this command, one can obtain needed dtb blob from boot.img in scripting manner, and then apply needed dtbo's (from "dtbo" partition) on top of that, providing then the resulting image to bootm command in order to boot the Android.

Also right now this command has the sub-command to get an address and size of recovery dtbo from recovery image (for non-A/B devices only, see [1,2] for details).

It can be tested like this:

=> mmc dev 1
=> part start mmc 1 boot_a boot_start
=> part size mmc 1 boot_a boot_size
=> mmc read $loadaddr $boot_start $boot_size
=> abootimg get ver
=> abootimg dump dtb

[1] https://source.android.com/devices/bootloader/boot-image-header
[2] https://source.android.com/devices/architecture/dto/partitions

---
 cmd/Kconfig    |   8 ++
 cmd/Makefile   |   1 +
 cmd/abootimg.c | 258 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 267 insertions(+)
 create mode 100644 cmd/abootimg.c
cmd/Kconfig +8 -0
index 6e1efaaf85..4734da17fe 100644
@@ -386,6 +386,14 @@ config CMD_ADTIMG
 	  files should be merged in one dtb further, which needs to be passed to
 	  the kernel, as part of a boot process.
 
+config CMD_ABOOTIMG
+	bool "abootimg"
+	depends on ANDROID_BOOT_IMAGE
+	help
+	  Android Boot Image manipulation commands. Allows one to extract
+	  images contained in boot.img, like kernel, ramdisk, dtb, etc, and
+	  obtain corresponding meta-information from boot.img.
+
 config CMD_ELF
 	bool "bootelf, bootvx"
 	default y
cmd/Makefile +1 -0
index 4f29b72c69..f1dd513a4b 100644
@@ -48,6 +48,7 @@ ifdef CONFIG_POST
 obj-$(CONFIG_CMD_DIAG) += diag.o
 endif
 obj-$(CONFIG_CMD_ADTIMG) += adtimg.o
+obj-$(CONFIG_CMD_ABOOTIMG) += abootimg.o
 obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
cmd/abootimg.c new file +258 -0

258 lines not on this page · raw message

Signature · 1 line
2.24.0
#4 lore raw

PATCH v4 4/10 doc: android: Add documentation for Android Boot Image

In reply to Sam Protsenko

Describe Android Boot Image format, how its support is implemented in U-Boot and associated commands usage.

---
 cmd/Kconfig                |   2 +
 doc/android/boot-image.rst | 154 +++++++++++++++++++++++++++++++++++++
 2 files changed, 156 insertions(+)
 create mode 100644 doc/android/boot-image.rst
cmd/Kconfig +2 -0
index 4734da17fe..6a2f6fb070 100644
@@ -394,6 +394,8 @@ config CMD_ABOOTIMG
 	  images contained in boot.img, like kernel, ramdisk, dtb, etc, and
 	  obtain corresponding meta-information from boot.img.
 
+	  See doc/android/boot-image.rst for details.
+
 config CMD_ELF
 	bool "bootelf, bootvx"
 	default y
doc/android/boot-image.rst new file +154 -0

154 lines not on this page · raw message

Signature · 1 line
2.24.0
#5 lore raw

PATCH v4 5/10 doc: android: Convert to Sphinx format

In reply to Sam Protsenko

Convert Android documentation from regular txt format to Sphinx (RST). Also add Android index.rst file and reference it in root index.rst, so that Android documentation is visible.

Test:

    $ make htmldocs
    $ xdg-open doc/output/index.html
---
 MAINTAINERS                                   |   4 +-
 cmd/Kconfig                                   |   2 +-
 doc/android/{ab.txt => ab.rst}                |  39 ++---
 doc/android/avb2.rst                          | 133 ++++++++++++++++++
 doc/android/avb2.txt                          | 115 ---------------
 doc/android/bcb.rst                           | 100 +++++++++++++
 doc/android/bcb.txt                           |  89 ------------
 ...oot-protocol.txt => fastboot-protocol.rst} |  45 +++---
 doc/android/{fastboot.txt => fastboot.rst}    |  92 ++++++------
 doc/android/index.rst                         |  14 ++
 doc/index.rst                                 |  12 ++
 test/py/tests/test_android/test_avb.py        |   2 +-
 12 files changed, 351 insertions(+), 296 deletions(-)
 rename doc/android/{ab.txt => ab.rst} (52%)
 create mode 100644 doc/android/avb2.rst
 delete mode 100644 doc/android/avb2.txt
 create mode 100644 doc/android/bcb.rst
 delete mode 100644 doc/android/bcb.txt
 rename doc/android/{fastboot-protocol.txt => fastboot-protocol.rst} (82%)
 rename doc/android/{fastboot.txt => fastboot.rst} (79%)
 create mode 100644 doc/android/index.rst
MAINTAINERS +2 -2
index b0634b23bc..9dce9f10f2 100644
@@ -56,7 +56,7 @@ R:	Sam Protsenko <[email protected]>
 S:	Maintained
 F:	cmd/ab_select.c
 F:	common/android_ab.c
-F:	doc/android/ab.txt
+F:	doc/android/ab.rst
 F:	include/android_ab.h
 F:	test/py/tests/test_android/test_ab.py
 
@@ -65,7 +65,7 @@ M:	Igor Opaniuk <[email protected]>
 S:	Maintained
 F:	cmd/avb.c
 F:	common/avb_verify.c
-F:	doc/android/avb2.txt
+F:	doc/android/avb2.rst
 F:	include/avb_verify.h
 F:	lib/libavb/
 F:	test/py/tests/test_android/test_avb.py
cmd/Kconfig +1 -1
index 6a2f6fb070..e6ba57035e 100644
@@ -880,7 +880,7 @@ config CMD_FASTBOOT
 	  Android devices. Fastboot requires either the network stack
 	  enabled or support for acting as a USB device.
 
-	  See doc/android/fastboot.txt for more information.
+	  See doc/android/fastboot.rst for more information.
 
 config CMD_FLASH
 	bool "flinfo, erase, protect"
doc/android/ab.rst renamed from doc/android/ab.txt +22 -17
similarity index 52%
rename from doc/android/ab.txt
rename to doc/android/ab.rst
index 9f37ed5c58..961895c32e 100644
@@ -1,3 +1,5 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
 Android A/B updates
 ===================
 
@@ -7,41 +9,44 @@ Overview
 A/B system updates ensures modern approach for system update. This feature
 allows one to use two sets (or more) of partitions referred to as slots
 (normally slot A and slot B). The system runs from the current slot while the
-partitions in the unused slot can be updated [1].
+partitions in the unused slot can be updated [1]_.
 
 A/B enablement
 --------------
 
 The A/B updates support can be activated by specifying next options in
-your board configuration file:
+your board configuration file::
 
     CONFIG_ANDROID_AB=y
     CONFIG_CMD_AB_SELECT=y
 
 The disk space on target device must be partitioned in a way so that each
 partition which needs to be updated has two or more instances. The name of
-each instance must be formed by adding suffixes: _a, _b, _c, etc.
-For example: boot_a, boot_b, system_a, system_b, vendor_a, vendor_b.
+each instance must be formed by adding suffixes: ``_a``, ``_b``, ``_c``, etc.
+For example: ``boot_a``, ``boot_b``, ``system_a``, ``system_b``, ``vendor_a``,
+``vendor_b``.
 
-As a result you can use 'ab_select' command to ensure A/B boot process in your
+As a result you can use ``ab_select`` command to ensure A/B boot process in your
 boot script. This command analyzes and processes A/B metadata stored on a
-special partition (e.g. "misc") and determines which slot should be used for
+special partition (e.g. ``misc``) and determines which slot should be used for
 booting up.
 
 Command usage
 -------------
 
+.. code-block:: none
+
     ab_select <slot_var_name> <interface> <dev[:part_number|#part_name]>
 
-for example:
+for example::
 
     => ab_select slot_name mmc 1:4
 
-or
+or::
 
     => ab_select slot_name mmc 1#misc
 
-Result:
+Result::
 
     => printenv slot_name
     slot_name=a
@@ -49,19 +54,19 @@ Result:
 Based on this slot information, the current boot partition should be defined,
 and next kernel command line parameters should be generated:
 
- - androidboot.slot_suffix=
- - root=
+* ``androidboot.slot_suffix=``
+* ``root=``
 
-For example:
+For example::
 
     androidboot.slot_suffix=_a root=/dev/mmcblk1p12
 
-A/B metadata is organized according to AOSP reference [2]. On the first system
-start with A/B enabled, when 'misc' partition doesn't contain required data,
-the default A/B metadata will be created and written to 'misc' partition.
+A/B metadata is organized according to AOSP reference [2]_. On the first system
+start with A/B enabled, when ``misc`` partition doesn't contain required data,
+the default A/B metadata will be created and written to ``misc`` partition.
 
 References
 ----------
 
-[1] https://source.android.com/devices/tech/ota/ab
-[2] bootable/recovery/bootloader_message/include/bootloader_message/bootloader_message.h
+.. [1] https://source.android.com/devices/tech/ota/ab
+.. [2] https://android.googlesource.com/platform/bootable/recovery/+/refs/tags/android-10.0.0_r25/bootloader_message/include/bootloader_message/bootloader_message.h
doc/android/avb2.rst new file +133 -0

133 lines not on this page · raw message

doc/android/avb2.txt deleted +0 -115

115 lines not on this page · raw message

doc/android/bcb.rst new file +100 -0

100 lines not on this page · raw message

doc/android/bcb.txt deleted +0 -89

89 lines not on this page · raw message

doc/android/fastboot-protocol.rst renamed from doc/android/fastboot-protocol.txt +24 -21

89 lines not on this page · raw message

doc/android/fastboot.rst renamed from doc/android/fastboot.txt +42 -50

205 lines not on this page · raw message

doc/android/index.rst new file +14 -0
new file mode 100644
index 0000000000..225d6f125a
@@ -0,0 +1,14 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Android-specific doc
+====================
+
+.. toctree::
+   :maxdepth: 2
+
+   ab
+   avb2
+   bcb
+   boot-image
+   fastboot-protocol
+   fastboot
doc/index.rst +12 -0
index 206a04590f..cd98be6cc5 100644
@@ -86,6 +86,18 @@ organized in a vendor subdirectory.
 
    board/index
 
+Android-specific doc
+--------------------
+
+These books provide information about booting the Android OS from U-Boot,
+manipulating Android images from U-Boot shell and discusses other
+Android-specific features available in U-Boot.
+
+.. toctree::
+   :maxdepth: 2
+
+   android/index
+
 Indices and tables
 ==================
 
test/py/tests/test_android/test_avb.py +1 -1
index 20ccaf6712..a04a7ff264 100644
@@ -8,7 +8,7 @@
 This tests Android Verified Boot 2.0 support in U-boot:
 
 For additional details about how to build proper vbmeta partition
-check doc/android/avb2.txt
+check doc/android/avb2.rst
 
 For configuration verification:
 - Corrupt boot partition and check for failure
Signature · 1 line
2.24.0
#6 lore raw

PATCH v4 6/10 test/py: android: Add test for abootimg

In reply to Sam Protsenko

Unit test for 'abootimg' command. Right now it covers dtb/dtbo functionality in Android Boot Image v2, which was added recently.

Running test:

    $ ./test/py/test.py --bd sandbox --build -k test_abootimg

shows that 1/1 tests passes successfully.

---
 configs/sandbox_defconfig                   |   1 +
 test/py/tests/test_android/test_abootimg.py | 159 ++++++++++++++++++++
 2 files changed, 160 insertions(+)
 create mode 100644 test/py/tests/test_android/test_abootimg.py
configs/sandbox_defconfig +1 -0
index fc018bdd2c..790dcb0592 100644
@@ -25,6 +25,7 @@ CONFIG_ANDROID_AB=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_BOOTZ=y
+CONFIG_CMD_ABOOTIMG=y
 # CONFIG_CMD_ELF is not set
 CONFIG_CMD_ASKENV=y
 CONFIG_CMD_GREPENV=y
test/py/tests/test_android/test_abootimg.py new file +159 -0

159 lines not on this page · raw message

Signature · 1 line
2.24.0
#7 lore raw

PATCH v4 7/10 configs: am57xx_evm: Enable Android commands

In reply to Sam Protsenko

Enable Android commands that will be needed for Android 10 boot flow implementation, for all AM57x variants. Commands enabled:

1. 'abootimg':
- CONFIG_CMD_ABOOTIMG=y
2. 'ab_select':
- CONFIG_ANDROID_AB=y
- CONFIG_CMD_AB_SELECT=y
3. 'avb':
- CONFIG_LIBAVB=y
- CONFIG_AVB_VERIFY=y
- CONFIG_CMD_AVB=y

While at it, resync defconfig files with "make savedefconfig".

---
 configs/am57xx_evm_defconfig        | 6 ++++++
 configs/am57xx_hs_evm_defconfig     | 6 ++++++
 configs/am57xx_hs_evm_usb_defconfig | 6 ++++++
 3 files changed, 18 insertions(+)
configs/am57xx_evm_defconfig +6 -0
index e429d0e200..f39f553afb 100644
@@ -22,6 +22,8 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_MISC_INIT_R is not set
 CONFIG_VERSION_VARIABLE=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_AVB_VERIFY=y
+CONFIG_ANDROID_AB=y
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SPL_DMA=y
@@ -31,11 +33,14 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_SPI_U_BOOT_OFFS=0x40000
 CONFIG_SPL_YMODEM_SUPPORT=y
 CONFIG_CMD_ADTIMG=y
+CONFIG_CMD_ABOOTIMG=y
 CONFIG_CMD_SPL=y
 CONFIG_CMD_BCB=y
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
+CONFIG_CMD_AB_SELECT=y
 # CONFIG_CMD_PMIC is not set
+CONFIG_CMD_AVB=y
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="am572x-idk"
@@ -102,3 +107,4 @@ CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_MANUFACTURER="Texas Instruments"
 CONFIG_USB_GADGET_VENDOR_NUM=0x0451
 CONFIG_USB_GADGET_PRODUCT_NUM=0xd022
+CONFIG_LIBAVB=y
configs/am57xx_hs_evm_defconfig +6 -0
index bebaae8743..4480f1c84d 100644
@@ -27,6 +27,8 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_MISC_INIT_R is not set
 CONFIG_VERSION_VARIABLE=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_AVB_VERIFY=y
+CONFIG_ANDROID_AB=y
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SPL_DMA=y
@@ -34,10 +36,13 @@ CONFIG_SPL_DMA=y
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_SPI_U_BOOT_OFFS=0x40000
 CONFIG_CMD_ADTIMG=y
+CONFIG_CMD_ABOOTIMG=y
 CONFIG_CMD_BCB=y
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
+CONFIG_CMD_AB_SELECT=y
 # CONFIG_CMD_PMIC is not set
+CONFIG_CMD_AVB=y
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="am57xx-beagle-x15"
@@ -98,3 +103,4 @@ CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_MANUFACTURER="Texas Instruments"
 CONFIG_USB_GADGET_VENDOR_NUM=0x0451
 CONFIG_USB_GADGET_PRODUCT_NUM=0xd022
+CONFIG_LIBAVB=y
configs/am57xx_hs_evm_usb_defconfig +6 -0
index d96640d44f..1e9268f68d 100644
@@ -28,6 +28,8 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_MISC_INIT_R is not set
 CONFIG_VERSION_VARIABLE=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_AVB_VERIFY=y
+CONFIG_ANDROID_AB=y
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SPL_DMA=y
@@ -39,10 +41,13 @@ CONFIG_SPL_USB_GADGET=y
 CONFIG_SPL_DFU=y
 CONFIG_SPL_YMODEM_SUPPORT=y
 CONFIG_CMD_ADTIMG=y
+CONFIG_CMD_ABOOTIMG=y
 CONFIG_CMD_BCB=y
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
+CONFIG_CMD_AB_SELECT=y
 # CONFIG_CMD_PMIC is not set
+CONFIG_CMD_AVB=y
 CONFIG_OF_CONTROL=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="am57xx-beagle-x15"
@@ -105,3 +110,4 @@ CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_MANUFACTURER="Texas Instruments"
 CONFIG_USB_GADGET_VENDOR_NUM=0x0451
 CONFIG_USB_GADGET_PRODUCT_NUM=0xd022
+CONFIG_LIBAVB=y
Signature · 1 line
2.24.0
#8 lore raw

PATCH v4 8/10 env: ti: boot: Respect slot_suffix in AVB commands

In reply to Sam Protsenko
---
 include/environment/ti/boot.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/environment/ti/boot.h +1 -1
index 6313f3e328..bfbd76c3af 100644
@@ -63,7 +63,7 @@
 			"else " \
 				"echo AVB verification failed.;" \
 			"exit; fi;"
-#define AVB_VERIFY_CMD "avb_verify=avb init 1; avb verify;\0"
+#define AVB_VERIFY_CMD "avb_verify=avb init 1; avb verify $slot_suffix;\0"
 #else
 #define AVB_VERIFY_CHECK ""
 #define AVB_VERIFY_CMD ""
Signature · 1 line
2.24.0
#9 lore raw

PATCH v4 9/10 env: ti: boot: Boot Android with dynamic partitions

In reply to Sam Protsenko

Changes:
- use boot.img instead of boot_fit.img
- use .dtb from boot.img v2
- implement recovery boot
- always boot ramdisk from boot.img, we can't mount system as root now, as system is a logical partition inside of super partition
- don't add "skip_initramfs" to cmdline anymore
- to boot into recovery, use boot image from recovery partition
- prepare partition table:
- A/B scheme
- use 'super' partition instead of 'system' and 'vendor'
- add dtbo partitions
- introduce metadata partition

Not implemented: reading and applying dtbo blobs from dtbo partition.

---
 include/environment/ti/boot.h | 115 +++++++++++++++-------------------
 1 file changed, 49 insertions(+), 66 deletions(-)
include/environment/ti/boot.h +49 -66
index bfbd76c3af..5a0fc1dc5d 100644
@@ -13,30 +13,14 @@
 #define CONSOLEDEV "ttyS2"
 #endif
 
-#define VBMETA_PART_SIZE		(64 * 1024)
-
-#if defined(CONFIG_LIBAVB)
-#define VBMETA_PART \
-	"name=vbmeta,size=" __stringify(VBMETA_PART_SIZE) \
-	",uuid=${uuid_gpt_vbmeta};"
-#else
-#define VBMETA_PART			""
-#endif
-
-#if defined(CONFIG_CMD_AB_SELECT)
-#define COMMON_PARTS \
-	"name=boot_a,size=20M,uuid=${uuid_gpt_boot_a};" \
-	"name=boot_b,size=20M,uuid=${uuid_gpt_boot_b};" \
-	"name=system_a,size=1024M,uuid=${uuid_gpt_system_a};" \
-	"name=system_b,size=1024M,uuid=${uuid_gpt_system_b};"
-#else
-#define COMMON_PARTS \
-	"name=boot,size=20M,uuid=${uuid_gpt_boot};" \
-	"name=system,size=1024M,uuid=${uuid_gpt_system};"
-#endif
-
 #ifndef PARTS_DEFAULT
-/* Define the default GPT table for eMMC */
+/*
+ * Default GPT tables for eMMC (Linux and Android). Notes:
+ *   1. Keep partitions aligned to erase group size (512 KiB) when possible
+ *   2. Keep partitions in sync with DFU_ALT_INFO_EMMC (see dfu.h)
+ *   3. Keep 'bootloader' partition (U-Boot proper) start address in sync with
+ *      CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR (see common/spl/Kconfig)
+ */
 #define PARTS_DEFAULT \
 	/* Linux partitions */ \
 	"uuid_disk=${uuid_gpt_disk};" \
@@ -49,10 +33,15 @@
 	"name=bootloader,size=2048K,uuid=${uuid_gpt_bootloader};" \
 	"name=uboot-env,start=2432K,size=256K,uuid=${uuid_gpt_reserved};" \
 	"name=misc,size=128K,uuid=${uuid_gpt_misc};" \
-	"name=recovery,size=40M,uuid=${uuid_gpt_recovery};" \
-	COMMON_PARTS \
-	"name=vendor,size=256M,uuid=${uuid_gpt_vendor};" \
-	VBMETA_PART \
+	"name=boot_a,size=20M,uuid=${uuid_gpt_boot_a};" \
+	"name=boot_b,size=20M,uuid=${uuid_gpt_boot_b};" \
+	"name=dtbo_a,size=8M,uuid=${uuid_gpt_dtbo_a};" \
+	"name=dtbo_b,size=8M,uuid=${uuid_gpt_dtbo_b};" \
+	"name=vbmeta_a,size=64K,uuid=${uuid_gpt_vbmeta_a};" \
+	"name=vbmeta_b,size=64K,uuid=${uuid_gpt_vbmeta_b};" \
+	"name=recovery,size=64M,uuid=${uuid_gpt_recovery};" \
+	"name=super,size=2560M,uuid=${uuid_gpt_super};" \
+	"name=metadata,size=16M,uuid=${uuid_gpt_metadata};" \
 	"name=userdata,size=-,uuid=${uuid_gpt_userdata}"
 #endif /* PARTS_DEFAULT */
 
@@ -72,7 +61,7 @@
 #define CONTROL_PARTITION "misc"
 
 #if defined(CONFIG_CMD_AB_SELECT)
-#define AB_SELECT \
+#define AB_SELECT_SLOT \
 	"if part number mmc 1 " CONTROL_PARTITION " control_part_number; " \
 	"then " \
 		"echo " CONTROL_PARTITION \
@@ -82,20 +71,14 @@
 		"echo " CONTROL_PARTITION " partition not found;" \
 		"exit;" \
 	"fi;" \
-	"setenv slot_suffix _${slot_name};" \
-	"if part number mmc ${mmcdev} system${slot_suffix} " \
-	"system_part_number; then " \
-		"setenv bootargs_ab " \
-		"ro root=/dev/mmcblk${mmcdev}p${system_part_number} " \
-		"rootwait init=/init skip_initramfs " \
-		"androidboot.slot_suffix=${slot_suffix};" \
-		"echo A/B cmdline addition: ${bootargs_ab};" \
-		"setenv bootargs ${bootargs} ${bootargs_ab};" \
-	"else " \
-		"echo system${slot_suffix} partition not found;" \
-	"fi;"
+	"setenv slot_suffix _${slot_name};"
+#define AB_SELECT_ARGS \
+	"setenv bootargs_ab androidboot.slot_suffix=${slot_suffix}; " \
+	"echo A/B cmdline addition: ${bootargs_ab};" \
+	"setenv bootargs ${bootargs} ${bootargs_ab};"
 #else
-#define AB_SELECT ""
+#define AB_SELECT_SLOT ""
+#define AB_SELECT_ARGS ""
 #endif
 
 #define FASTBOOT_CMD \
@@ -121,46 +104,46 @@
 		"setenv mmcroot /dev/mmcblk0p2 rw; " \
 		"run mmcboot;\0" \
 	"emmc_android_boot=" \
+		"setenv mmcdev 1; " \
+		"mmc dev $mmcdev; " \
+		"mmc rescan; " \
+		AB_SELECT_SLOT \
 		"if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
 		CONTROL_PARTITION "; then " \
+			"setenv ardaddr -; " \
 			"if bcb test command = bootonce-bootloader; then " \
-				"echo BCB: Bootloader boot...; " \
+				"echo Android: Bootloader boot...; " \
 				"bcb clear command; bcb store; " \
 				FASTBOOT_CMD \
+				"exit; " \
 			"elif bcb test command = boot-recovery; then " \
-				"echo BCB: Recovery boot...; " \
-				"echo Warning: recovery is not implemented; " \
-				"echo Performing normal boot for now...; " \
-				"bcb clear command; bcb store; " \
-				"run emmc_android_normal_boot; " \
+				"echo Android: Recovery boot...; " \
+				"setenv ardaddr $loadaddr;" \
+				"setenv apart recovery; " \
 			"else " \
-				"echo BCB: Normal boot requested...; " \
-				"run emmc_android_normal_boot; " \
+				"echo Android: Normal boot...; " \
+				"setenv ardaddr $loadaddr; " \
+				"setenv apart boot${slot_suffix}; " \
 			"fi; " \
 		"else " \
 			"echo Warning: BCB is corrupted or does not exist; " \
-			"echo Performing normal boot...; " \
-			"run emmc_android_normal_boot; " \
-		"fi;\0" \
-	"emmc_android_normal_boot=" \
-		"echo Trying to boot Android from eMMC ...; " \
-		"run update_to_fit; " \
+			"echo Android: Normal boot...; " \
+		"fi; " \
 		"setenv eval_bootargs setenv bootargs $bootargs; " \
 		"run eval_bootargs; " \
-		"setenv mmcdev 1; " \
 		"setenv machid fe6; " \
-		"mmc dev $mmcdev; " \
-		"mmc rescan; " \
 		AVB_VERIFY_CHECK \
-		AB_SELECT \
-		"if part start mmc ${mmcdev} boot${slot_suffix} boot_start; " \
-		"then " \
-			"part size mmc ${mmcdev} boot${slot_suffix} " \
-				"boot_size; " \
-			"mmc read ${loadaddr} ${boot_start} ${boot_size}; " \
-			"bootm ${loadaddr}#${fdtfile}; " \
+		AB_SELECT_ARGS \
+		"if part start mmc $mmcdev $apart boot_start; then " \
+			"part size mmc $mmcdev $apart boot_size; " \
+			"mmc read $loadaddr $boot_start $boot_size; " \
+			"abootimg get dtb --index=0 dtb_start dtb_size; " \
+			"cp.b $dtb_start $fdtaddr $dtb_size; " \
+			"fdt addr $fdtaddr; " \
+			"bootm $loadaddr $ardaddr $fdtaddr; " \
 		"else " \
-			"echo boot${slot_suffix} partition not found; " \
+			"echo $apart partition not found; " \
+			"exit; " \
 		"fi;\0"
 
 #ifdef CONFIG_OMAP54XX
Signature · 1 line
2.24.0
#10 lore raw

PATCH v4 10/10 arm: ti: boot: Use correct dtb and dtbo on Android boot

In reply to Sam Protsenko

Read correct dtb blob from boot.img/recovery.img and apply correct dtbo blobs from dtbo partition.

---
 include/configs/ti_armv7_common.h |  7 +++++
 include/environment/ti/boot.h     | 43 ++++++++++++++++++++++++++++---
 2 files changed, 47 insertions(+), 3 deletions(-)
include/configs/ti_armv7_common.h +7 -0
index a1a053e675..a612bb5b4a 100644
@@ -37,11 +37,18 @@
  * seen large trees).  We say all of this must be within the first 256MB
  * as that will normally be within the kernel lowmem and thus visible via
  * bootm_size and we only run on platforms with 256MB or more of memory.
+ *
+ * As a temporary storage for DTBO blobs (which should be applied into DTB
+ * blob), we use the location 15.5 MB above the ramdisk. If someone wants to
+ * use ramdisk bigger than 15.5 MB, then DTBO can be loaded and applied to DTB
+ * blob before loading the ramdisk, as DTBO location is only used as a temporary
+ * storage, and can be re-used after 'fdt apply' command is done.
  */
 #define DEFAULT_LINUX_BOOT_ENV \
 	"loadaddr=0x82000000\0" \
 	"kernel_addr_r=0x82000000\0" \
 	"fdtaddr=0x88000000\0" \
+	"dtboaddr=0x89000000\0" \
 	"fdt_addr_r=0x88000000\0" \
 	"rdaddr=0x88080000\0" \
 	"ramdisk_addr_r=0x88080000\0" \
include/environment/ti/boot.h +40 -3

55 lines not on this page · raw message

Signature · 1 line
2.24.0
#11 lore raw

v4 cover am57xx: Implement Android 10 boot flow

In reply to Sam Protsenko
Quoted 12 lines · Sam Protsenko

Android 10 brings a lot of new requirements for bootloaders: [1]. This patch series attempts to implement such a boot process on BeagleBoard X15 platform. Some common code is added too, which can be reused later for other platforms (see "abootimg" command and associated C API).

Changes in v4:
- fixed broken build due to recent load_addr -> image_load_addr renaming
- added "doc: android: Convert to Sphinx format" patch to series
- addressed pending comments for v3 on mailing list
- rebased series on top of current master

Quoted 7 lines

Changes in v3:
- rename command to "abootimg" (requested by Simon Glass)
- rework command interface (as discussed with Eugeniu)
- add command documentation
- address other comments

[1] https://source.android.com/devices/bootloader

Verified Key functionality as mentioned in [1] on AM57x X15 A/B , AVB , fastbootd, super image ( vendor + system), recovery mode on AOSP master

For the series

Quoted 51 lines

Sam Protsenko (10):
image: android: Add functions for handling dtb field
image: android: Add routine to get dtbo params
cmd: abootimg: Add abootimg command
doc: android: Add documentation for Android Boot Image
doc: android: Convert to Sphinx format test/py: android: Add test for abootimg
configs: am57xx_evm: Enable Android commands
env: ti: boot: Respect slot_suffix in AVB commands
env: ti: boot: Boot Android with dynamic partitions
arm: ti: boot: Use correct dtb and dtbo on Android boot

  MAINTAINERS                                   |   4 +-
  cmd/Kconfig                                   |  12 +-
  cmd/Makefile                                  |   1 +
  cmd/abootimg.c                                | 258 ++++++++++++++++
  common/Makefile                               |   2 +-
  common/image-android.c                        | 282 ++++++++++++++++++
  configs/am57xx_evm_defconfig                  |   6 +
  configs/am57xx_hs_evm_defconfig               |   6 +
  configs/am57xx_hs_evm_usb_defconfig           |   6 +
  configs/sandbox_defconfig                     |   1 +
  doc/android/{ab.txt => ab.rst}                |  39 +--
  doc/android/avb2.rst                          | 133 +++++++++
  doc/android/avb2.txt                          | 115 -------
  doc/android/bcb.rst                           | 100 +++++++
  doc/android/bcb.txt                           |  89 ------
  doc/android/boot-image.rst                    | 154 ++++++++++
  ...oot-protocol.txt => fastboot-protocol.rst} |  45 +--
  doc/android/{fastboot.txt => fastboot.rst}    |  92 +++---
  doc/android/index.rst                         |  14 +
  doc/index.rst                                 |  12 +
  include/configs/ti_armv7_common.h             |   7 +
  include/environment/ti/boot.h                 | 154 +++++-----
  include/image.h                               |   6 +
  test/py/tests/test_android/test_abootimg.py   | 159 ++++++++++
  test/py/tests/test_android/test_avb.py        |   2 +-
  25 files changed, 1335 insertions(+), 364 deletions(-)

create mode 100644 cmd/abootimg.c
rename doc/android/{ab.txt => ab.rst} (52%)
create mode 100644 doc/android/avb2.rst
delete mode 100644 doc/android/avb2.txt
create mode 100644 doc/android/bcb.rst
delete mode 100644 doc/android/bcb.txt
create mode 100644 doc/android/boot-image.rst
rename doc/android/{fastboot-protocol.txt => fastboot-protocol.rst} (82%) rename doc/android/{fastboot.txt => fastboot.rst} (79%) create mode 100644 doc/android/index.rst
create mode 100644 test/py/tests/test_android/test_abootimg.py

#12 lore raw

v4 cover am57xx: Implement Android 10 boot flow

In reply to Sam Protsenko
Quoted 12 lines · Sam Protsenko

Android 10 brings a lot of new requirements for bootloaders: [1]. This patch series attempts to implement such a boot process on BeagleBoard X15 platform. Some common code is added too, which can be reused later for other platforms (see "abootimg" command and associated C API).

Changes in v4:
- fixed broken build due to recent load_addr -> image_load_addr renaming
- added "doc: android: Convert to Sphinx format" patch to series
- addressed pending comments for v3 on mailing list
- rebased series on top of current master

Quoted 7 lines

Changes in v3:
- rename command to "abootimg" (requested by Simon Glass)
- rework command interface (as discussed with Eugeniu)
- add command documentation
- address other comments

[1] https://source.android.com/devices/bootloader

Series pulled into u-boot-ti tree.

Thanks and regards,
Lokesh