Skip to contentSkip to conversation

am57xx: Implement Android 10 boot flow

PATCH Superseded Sam Protsenko 4 participants 18 messages Sep 19, 2019 – Oct 24, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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.

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

Sam Protsenko (7):
image: android: Add functions for handling dtb field
image: android: Add routine to get dtbo params
cmd: bootimg: Add bootimg command
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

 cmd/Kconfig                         |   8 +
 cmd/Makefile                        |   1 +
 cmd/bootimg.c                       | 177 ++++++++++++++++++++
 common/Makefile                     |   2 +-
 common/image-android.c              | 245 ++++++++++++++++++++++++++++
 configs/am57xx_evm_defconfig        |   8 +-
 configs/am57xx_hs_evm_defconfig     |   6 +
 configs/am57xx_hs_evm_usb_defconfig |   8 +-
 include/configs/ti_armv7_common.h   |   7 +
 include/environment/ti/boot.h       | 145 ++++++++--------
 include/image.h                     |   7 +
 11 files changed, 546 insertions(+), 68 deletions(-)
 create mode 100644 cmd/bootimg.c
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/7 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 file from "DTB" part of boot image, by file index
- android_image_print_dtb_contents(): Iterate over all DTB files in "DTB" part of boot image and print those files info

"DTB" payload might be in one of the following formats:
1. concatenated DTB files
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 file(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 "bootimg" to extract dtb file from boot image (using functions from this patch)
- extract desired dtbo files from "dtbo" partition using "dtimg" command
- merge dtbo files into dtb file using "fdt apply" command
- pass resulting dtb file into bootm command in order to boot the Android kernel with Android ramdisk from boot image

---
 common/Makefile        |   2 +-
 common/image-android.c | 191 +++++++++++++++++++++++++++++++++++++++++
 include/image.h        |   5 ++
 3 files changed, 197 insertions(+), 1 deletion(-)
common/Makefile +1 -1
index 302d8beaf3..7e5f5058b3 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 +191 -0

207 lines not on this page · raw message

include/image.h +5 -0
index c1065c06f9..08eda41961 100644
@@ -1333,10 +1333,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(const struct andr_img_hdr *hdr, 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(const struct andr_img_hdr *hdr);
+#endif
 
 #endif /* CONFIG_ANDROID_BOOT_IMAGE */
 
Signature · 1 line
2.23.0
#2 lore raw

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

Hi Sam,

Quoted 28 lines · Sam Protsenko

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 file from "DTB" part of boot image, by file index
- android_image_print_dtb_contents(): Iterate over all DTB files in "DTB" part of boot image and print those files info

"DTB" payload might be in one of the following formats:
1. concatenated DTB files
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 file(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 "bootimg" to extract dtb file from boot image (using functions from this patch)
- extract desired dtbo files from "dtbo" partition using "dtimg" command
- merge dtbo files into dtb file using "fdt apply" command
- pass resulting dtb file into bootm command in order to boot the Android kernel with Android ramdisk from boot image

Quoted 7 lines
---
 common/Makefile        |   2 +-
 common/image-android.c | 191 +++++++++++++++++++++++++++++++++++++++++
 include/image.h        |   5 ++
 3 files changed, 197 insertions(+), 1 deletion(-)

Please rememeber to add tests for new functionality.

Regards,
Simon

#3 lore raw

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

Hi Simon,

Quoted 40 lines · Simon Glass

Hi Sam,

Quoted 28 lines · Sam Protsenko

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 file from "DTB" part of boot image, by file index
- android_image_print_dtb_contents(): Iterate over all DTB files in "DTB" part of boot image and print those files info

"DTB" payload might be in one of the following formats:
1. concatenated DTB files
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 file(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 "bootimg" to extract dtb file from boot image (using functions from this patch)
- extract desired dtbo files from "dtbo" partition using "dtimg" command
- merge dtbo files into dtb file using "fdt apply" command
- pass resulting dtb file into bootm command in order to boot the Android kernel with Android ramdisk from boot image

Quoted 7 lines
---
 common/Makefile        |   2 +-
 common/image-android.c | 191 +++++++++++++++++++++++++++++++++++++++++
 include/image.h        |   5 ++
 3 files changed, 197 insertions(+), 1 deletion(-)
Quoted 2 lines

Please rememeber to add tests for new functionality.

Will send v2 with added unit test soon, thanks!

Quoted 2 lines

Regards,
Simon

#4 lore raw

PATCH 2/7 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 'bootimg' command to provide the user a way to get the address of recovery dtbo from U-Boot shell, which can be further parsed using 'dtimg' command.

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

---
 common/image-android.c | 54 ++++++++++++++++++++++++++++++++++++++++++
 include/image.h        |  2 ++
 2 files changed, 56 insertions(+)
common/image-android.c +54 -0
index 63e41ea5f1..5ecd75dcfc 100644
@@ -196,6 +196,60 @@ 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: 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 'dtimg' U-Boot
+ * command or android_dt_*() functions to extract desired DTBO file.
+ *
+ * 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(const struct andr_img_hdr *hdr, ulong *addr,
+			    u32 *size)
+{
+	ulong dtbo_img_addr;
+
+	if (android_image_check_header(hdr)) {
+		printf("Error: Boot Image header is incorrect\n");
+		return false;
+	}
+
+	if (hdr->header_version < 1) {
+		printf("Error: header_version must be >= 1 to get dtbo\n");
+		return false;
+	}
+
+	if (hdr->recovery_dtbo_size == 0) {
+		printf("Error: recovery_dtbo_size is 0\n");
+		return false;
+	}
+
+	/* Calculate the address of DTB area in boot image */
+	dtbo_img_addr = (ulong)hdr;
+	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;
+
+	return true;
+}
+
 /**
  * android_image_get_dtb_img_addr() - Get the address of DTB area in boot image.
  * @hdr: Boot image header address
include/image.h +2 -0
index 08eda41961..c8a3088acb 100644
@@ -1333,6 +1333,8 @@ 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(const struct andr_img_hdr *hdr, ulong *addr,
+			    u32 *size);
 bool android_image_get_dtb_by_index(const struct andr_img_hdr *hdr, u32 index,
 				    ulong *addr, u32 *size);
 ulong android_image_get_end(const struct andr_img_hdr *hdr);
Signature · 1 line
2.23.0
#5 lore raw

PATCH 3/7 cmd: bootimg: Add bootimg 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 file 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. It can be further parsed using 'dtimg' command and merged into dtb file (for non-A/B devices only, see [1,2] for details).

[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/bootimg.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 cmd/bootimg.c
cmd/Kconfig +8 -0
index 98647f58b7..37f3003c2b 100644
@@ -305,6 +305,14 @@ config CMD_DTIMG
 	  files should be merged in one dtb further, which needs to be passed to
 	  the kernel, as part of a boot process.
 
+config CMD_BOOTIMG
+	bool "bootimg"
+	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 ac843b4b16..bf15e38f41 100644
@@ -48,6 +48,7 @@ ifdef CONFIG_POST
 obj-$(CONFIG_CMD_DIAG) += diag.o
 endif
 obj-$(CONFIG_CMD_DTIMG) += dtimg.o
+obj-$(CONFIG_CMD_BOOTIMG) += bootimg.o
 obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
cmd/bootimg.c new file +177 -0

177 lines not on this page · raw message

Signature · 1 line
2.23.0
#6 lore raw

PATCH 3/7 cmd: bootimg: Add bootimg command

Hi,

Quoted 17 lines · 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 file 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. It can be further parsed using 'dtimg' command and merged into dtb file (for non-A/B devices only, see [1,2] for details).

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

Quoted 7 lines
---
 cmd/Kconfig   |   8 +++
 cmd/Makefile  |   1 +
 cmd/bootimg.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 cmd/bootimg.c

Shouldn't this be a subcommand of avb?

Regards,
Simon

#7 lore raw

PATCH 3/7 cmd: bootimg: Add bootimg command

Hi Simon,

Quoted 30 lines · Simon Glass

Hi,

Quoted 17 lines · 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 file 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. It can be further parsed using 'dtimg' command and merged into dtb file (for non-A/B devices only, see [1,2] for details).

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

Quoted 7 lines
---
 cmd/Kconfig   |   8 +++
 cmd/Makefile  |   1 +
 cmd/bootimg.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 cmd/bootimg.c
Quoted 1 line

Shouldn't this be a subcommand of avb?

I think there is some misunderstanding here, as avb
is used only for signature verification/roll-back protection, other aspects of booting Android (parsing android boot image) are handled by other commands (for instance, bootm).

Howewer, I think (IMHO) that bootimg isn't a good choice for the command name , which major functionality is manipulating dtb/dtbos.

Quoted 3 lines

Regards,
Simon

Signature · 8 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk
#8 lore raw

PATCH 3/7 cmd: bootimg: Add bootimg command

Hi Igor,

Quoted 36 lines · Igor Opaniuk

Hi Simon,

Quoted 30 lines · Simon Glass

Hi,

Quoted 17 lines · 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 file 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. It can be further parsed using 'dtimg' command and merged into dtb file (for non-A/B devices only, see [1,2] for details).

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

Quoted 7 lines
---
 cmd/Kconfig   |   8 +++
 cmd/Makefile  |   1 +
 cmd/bootimg.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 cmd/bootimg.c
Quoted 1 line

Shouldn't this be a subcommand of avb?

Quoted 9 lines

I think there is some misunderstanding here, as avb
is used only for signature verification/roll-back protection, other aspects of booting Android (parsing android boot image) are handled by other commands (for instance, bootm).

Howewer, I think (IMHO) that bootimg isn't a good choice for the command name , which major functionality is manipulating dtb/dtbos.

Actually, 'bootimg' manipulates only Android boot image, but new Android Boot Image v2 happen to have DTB field. For DTBO files in Android we already have 'dtimg' command.

Simon,

This command is not connected with AVB. It's only needed to obtain Android Boot Image payloads. We can't integrate its functionality in 'bootm' command, because we would need to merge some DTBO files (from 'dtbo' partition) into DTB file obtained from boot image. And bootm command can't possibly know which DTBO files vendor would like to use (e.g. different DTBOs for different boards). That's why I came up with 'bootimg' command.

Actually I think that we should think about implementing 'boot_android' next. Because the boot script is becoming quite cluttered. But we should have those tiny commands anyway, as it's convenient for development and provides a more flexible way to boot Android.

I'm having presentation today at Linaro Connect, highlighting new Android boot scheme. Slides will be available at [1]. The Android boot flow becomes more and more extensive, so I think it's time to start discussion between community, Google and vendors w.r.t. this topic. One point we should bring up is the possibility to use FIT image instead of bunch of Android images. I hope this is discussable.

But for now I think we should stick to established Android boot architecture, as it was published at [2] and mandatory for new devices launching with Android 10.

Thanks!

[1] https://connect.linaro.org/resources/san19/san19-217/
[2] https://source.android.com/devices/bootloader

Quoted 15 lines
Quoted 3 lines

Regards,
Simon

--
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk

#9 lore raw

PATCH 3/7 cmd: bootimg: Add bootimg command

Hi Sam,

Quoted 56 lines · Sam Protsenko

Hi Igor,

Quoted 36 lines · Igor Opaniuk

Hi Simon,

Quoted 30 lines · Simon Glass

Hi,

Quoted 17 lines · 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 file 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. It can be further parsed using 'dtimg' command and merged into dtb file (for non-A/B devices only, see [1,2] for details).

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

Quoted 7 lines
---
 cmd/Kconfig   |   8 +++
 cmd/Makefile  |   1 +
 cmd/bootimg.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 cmd/bootimg.c
Quoted 1 line

Shouldn't this be a subcommand of avb?

Quoted 9 lines

I think there is some misunderstanding here, as avb
is used only for signature verification/roll-back protection, other aspects of booting Android (parsing android boot image) are handled by other commands (for instance, bootm).

Howewer, I think (IMHO) that bootimg isn't a good choice for the command name , which major functionality is manipulating dtb/dtbos.

Actually, 'bootimg' manipulates only Android boot image, but new Android Boot Image v2 happen to have DTB field. For DTBO files in Android we already have 'dtimg' command.

Simon,

Quoted 7 lines

This command is not connected with AVB. It's only needed to obtain Android Boot Image payloads. We can't integrate its functionality in 'bootm' command, because we would need to merge some DTBO files (from 'dtbo' partition) into DTB file obtained from boot image. And bootm command can't possibly know which DTBO files vendor would like to use (e.g. different DTBOs for different boards). That's why I came up with 'bootimg' command.

OK, so can we say this is specific to Android. So perhaps 'boota' ?

Minor point - boom allows passing an image address rather than requiring loadaddr to be set.

Quoted 6 lines

Actually I think that we should think about implementing 'boot_android' next. Because the boot script is becoming quite cluttered. But we should have those tiny commands anyway, as it's convenient for development and provides a more flexible way to boot Android.

Agreed on both counts.

Quoted 7 lines

I'm having presentation today at Linaro Connect, highlighting new Android boot scheme. Slides will be available at [1]. The Android boot flow becomes more and more extensive, so I think it's time to start discussion between community, Google and vendors w.r.t. this topic. One point we should bring up is the possibility to use FIT image instead of bunch of Android images. I hope this is discussable.

That sounds like a good idea.

Quoted 4 lines

But for now I think we should stick to established Android boot architecture, as it was published at [2] and mandatory for new devices launching with Android 10.

OK. Let's make sure to add sandbox tests for new functionality too.

- SImon

Quoted 21 lines

Thanks!

[1] https://connect.linaro.org/resources/san19/san19-217/
[2] https://source.android.com/devices/bootloader

Quoted 15 lines
Quoted 3 lines

Regards,
Simon

--
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk

#10 lore raw

PATCH 3/7 cmd: bootimg: Add bootimg command

Hi Simon,

Quoted 68 lines · Simon Glass

Hi Sam,

Quoted 56 lines · Sam Protsenko

Hi Igor,

Quoted 36 lines · Igor Opaniuk

Hi Simon,

Quoted 30 lines · Simon Glass

Hi,

Quoted 17 lines · 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 file 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. It can be further parsed using 'dtimg' command and merged into dtb file (for non-A/B devices only, see [1,2] for details).

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

Quoted 7 lines
---
 cmd/Kconfig   |   8 +++
 cmd/Makefile  |   1 +
 cmd/bootimg.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 cmd/bootimg.c
Quoted 1 line

Shouldn't this be a subcommand of avb?

Quoted 9 lines

I think there is some misunderstanding here, as avb
is used only for signature verification/roll-back protection, other aspects of booting Android (parsing android boot image) are handled by other commands (for instance, bootm).

Howewer, I think (IMHO) that bootimg isn't a good choice for the command name , which major functionality is manipulating dtb/dtbos.

Actually, 'bootimg' manipulates only Android boot image, but new Android Boot Image v2 happen to have DTB field. For DTBO files in Android we already have 'dtimg' command.

Simon,

Quoted 7 lines

This command is not connected with AVB. It's only needed to obtain Android Boot Image payloads. We can't integrate its functionality in 'bootm' command, because we would need to merge some DTBO files (from 'dtbo' partition) into DTB file obtained from boot image. And bootm command can't possibly know which DTBO files vendor would like to use (e.g. different DTBOs for different boards). That's why I came up with 'bootimg' command.

Quoted 2 lines

OK, so can we say this is specific to Android. So perhaps 'boota' ?

I'd like to keep 'bootimg' name, to not confuse this command with actual boot commands. The 'bootimg' doesn't boot anything, it just provides the means to work with the image which is called "boot image".

Quoted 3 lines

Minor point - boom allows passing an image address rather than requiring loadaddr to be set.

Good point. I have added 'set_addr' sub-command in v2, will send it soon.

Quoted 10 lines
Quoted 6 lines

Actually I think that we should think about implementing 'boot_android' next. Because the boot script is becoming quite cluttered. But we should have those tiny commands anyway, as it's convenient for development and provides a more flexible way to boot Android.

Agreed on both counts.

Quoted 1 line
Quoted 9 lines
Quoted 6 lines

I'm having presentation today at Linaro Connect, highlighting new Android boot scheme. Slides will be available at [1]. The Android boot flow becomes more and more extensive, so I think it's time to start discussion between community, Google and vendors w.r.t. this topic. One point we should bring up is the possibility to use FIT image instead of bunch of Android images. I hope this is discussable.

That sounds like a good idea.

Just in case, slides and video are available here:

    https://connect.linaro.org/resources/san19/san19-217/
Quoted 7 lines
Quoted 4 lines

But for now I think we should stick to established Android boot architecture, as it was published at [2] and mandatory for new devices launching with Android 10.

OK. Let's make sure to add sandbox tests for new functionality too.

Done, will send v2 soon. Thanks!

Quoted 24 lines

- SImon

Quoted 21 lines

Thanks!

[1] https://connect.linaro.org/resources/san19/san19-217/
[2] https://source.android.com/devices/bootloader

Quoted 15 lines
Quoted 3 lines

Regards,
Simon

--
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk at gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk

#11 lore raw

PATCH 4/7 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. 'bootimg':
- CONFIG_CMD_BOOTIMG=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        | 8 +++++++-
 configs/am57xx_hs_evm_defconfig     | 6 ++++++
 configs/am57xx_hs_evm_usb_defconfig | 8 +++++++-
 3 files changed, 20 insertions(+), 2 deletions(-)
configs/am57xx_evm_defconfig +7 -1
index 248c302057..ee7852fd30 100644
@@ -10,6 +10,7 @@ CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI_SUPPORT=y
 CONFIG_ARMV7_LPAE=y
 CONFIG_AHCI=y
+CONFIG_SPL_TEXT_BASE=0x40300000
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_OF_BOARD_SETUP=y
@@ -20,7 +21,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_SPL_TEXT_BASE=0x40300000
+CONFIG_AVB_VERIFY=y
+CONFIG_ANDROID_AB=y
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SPL_DMA_SUPPORT=y
@@ -30,11 +32,14 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_SPI_U_BOOT_OFFS=0x40000
 CONFIG_SPL_YMODEM_SUPPORT=y
 CONFIG_CMD_DTIMG=y
+CONFIG_CMD_BOOTIMG=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"
@@ -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_defconfig +6 -0
index 7b56df8db7..89e5094a74 100644
@@ -26,6 +26,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_SUPPORT=y
@@ -33,10 +35,13 @@ CONFIG_SPL_DMA_SUPPORT=y
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_SPI_U_BOOT_OFFS=0x40000
 CONFIG_CMD_DTIMG=y
+CONFIG_CMD_BOOTIMG=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"
@@ -96,3 +101,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 +7 -1
index c8078e9f4e..04dc402a23 100644
@@ -14,6 +14,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI_SUPPORT=y
 CONFIG_ARMV7_LPAE=y
+CONFIG_SPL_TEXT_BASE=0x40306D50
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_FIT_IMAGE_POST_PROCESS=y
 CONFIG_SPL_LOAD_FIT=y
@@ -26,7 +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_SPL_TEXT_BASE=0x40306D50
+CONFIG_AVB_VERIFY=y
+CONFIG_ANDROID_AB=y
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SPL_DMA_SUPPORT=y
@@ -38,10 +40,13 @@ CONFIG_SPL_USB_GADGET=y
 CONFIG_SPL_DFU=y
 CONFIG_SPL_YMODEM_SUPPORT=y
 CONFIG_CMD_DTIMG=y
+CONFIG_CMD_BOOTIMG=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"
@@ -103,3 +108,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.23.0
#12 lore raw

PATCH 5/7 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 684a744f31..da99215fbd 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.23.0
#13 lore raw

PATCH 6/7 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 files from dtbo partition.

---
 include/environment/ti/boot.h | 105 +++++++++++++---------------------
 1 file changed, 41 insertions(+), 64 deletions(-)
include/environment/ti/boot.h +41 -64
index da99215fbd..a7644a5874 100644
@@ -13,28 +13,6 @@
 #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 */
 #define PARTS_DEFAULT \
@@ -49,10 +27,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 +55,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,18 +65,12 @@
 		"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 ""
 #endif
@@ -121,46 +98,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; " \
+			"bootimg get_dtb_file 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.23.0
#14 lore raw

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

In reply to Sam Protsenko

Read correct dtb file from boot.img/recovery.img and apply correct dtbo files from dtbo partition.

---
 include/configs/ti_armv7_common.h |  7 +++++
 include/environment/ti/boot.h     | 44 ++++++++++++++++++++++++++++---
 2 files changed, 48 insertions(+), 3 deletions(-)
include/configs/ti_armv7_common.h +7 -0
index 2de6bc2390..188171e4c4 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 files (which should be applied into DTB
+ * file), 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
+ * file 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 +41 -3

56 lines not on this page · raw message

Signature · 1 line
2.23.0
#15 lore raw

cover am57xx: Implement Android 10 boot flow

In reply to Sam Protsenko

Hi Sam,

Quoted 6 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.

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

First, many thanks and true appreciation for making the bring-up of the same features easier on other platforms. Big thumbs up.

Since I wanted to include some backtraces, I've posted my review findings (1st round) in https://paste.ubuntu.com/p/jNwYP99kp8/.

Signature · 2 lines
Best Regards,
Eugeniu
#16 lore raw

cover am57xx: Implement Android 10 boot flow

Hi Eugeniu,

Quoted 9 lines · Eugeniu Rosca

Hi Sam,

Quoted 5 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.

Quoted 8 lines
Quoted 1 line

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

First, many thanks and true appreciation for making the bring-up of the same features easier on other platforms. Big thumbs up.

Since I wanted to include some backtraces, I've posted my review findings (1st round) in https://paste.ubuntu.com/p/jNwYP99kp8/.

Thanks for your input. All issues you mentioned should be fixed in v2 I sent recently. Can you please check it out too?

Quoted 3 lines

--
Best Regards,
Eugeniu

#17 lore raw

cover am57xx: Implement Android 10 boot flow

Hi Sam,

On Wed, Oct 23, 2019 at 10:37:23PM +0300, Sam Protsenko wrote:
[..]

Quoted 2 lines

Thanks for your input. All issues you mentioned should be fixed in v2 I sent recently. Can you please check it out too?

Thanks for the notification. I will review v2 in the following days. Congrats with the awesome presentation and slides.

Signature · 2 lines
Best Regards,
Eugeniu