am57xx: Implement Android 10 boot flow
v3 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).
This patch series must be applied on top of these recently sent patches by Eugeniu:
[PATCH 0/3] cmd: dtimg: Rename to adtimg and refactor usage style
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 (9):
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 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
cmd/Kconfig | 10 + cmd/Makefile | 1 + cmd/abootimg.c | 242 +++++++++++++++++ common/Makefile | 2 +- common/image-android.c | 275 ++++++++++++++++++++ configs/am57xx_evm_defconfig | 6 + configs/am57xx_hs_evm_defconfig | 6 + configs/am57xx_hs_evm_usb_defconfig | 6 + configs/sandbox_defconfig | 1 + doc/android/boot-image.rst | 154 +++++++++++ include/configs/ti_armv7_common.h | 7 + include/environment/ti/boot.h | 146 ++++++----- include/image.h | 6 + test/py/tests/test_android/test_abootimg.py | 159 +++++++++++ 14 files changed, 954 insertions(+), 67 deletions(-) create mode 100644 cmd/abootimg.c create mode 100644 doc/android/boot-image.rst create mode 100644 test/py/tests/test_android/test_abootimg.py
Signature · 1 line
2.24.0
PATCH v3 1/9 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 | 214 +++++++++++++++++++++++++++++++++++++++++ include/image.h | 5 + 3 files changed, 220 insertions(+), 1 deletion(-)
common/Makefile +1 -1
@@ -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 +214 -0
234 lines not on this page · raw message
include/image.h +5 -0
@@ -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 (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
PATCH v3 1/9 image: android: Add functions for handling dtb field
Hi Sam,
Quoted 53 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 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 formatThe latter requires "
android-image-dt.c" functionality, so this commit selects that file for building forCONFIG_ANDROID_BOOT_IMAGEoption.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 imageSigned-off-by Sam Protsenko <[email protected]>--- common/Makefile | 2 +- common/image-android.c | 214 +++++++++++++++++++++++++++++++++++++++++ include/image.h | 5 + 3 files changed, 220 insertions(+), 1 deletion(-)common/Makefile +1
-1@@ -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.ocommon/image-android.c +0
-0
common/image-android.c line 9
Quoted 4 lines
common/image-android.c +1
-0@@ -6,10 +6,12 @@#include <common.h> #include <env.h> #include <image.h> +#include <image-android-dt.h>
Prefer underscores if possible.
Quoted 14 lines
common/image-android.c +3
-0#include <android_image.h> #include <malloc.h> #include <errno.h> #include <asm/unaligned.h> +#include <mapmem.h> #define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR 0x10008000@@ -195,6 +197,121 @@ int android_image_get_second(const struct andr_img_hdr *hdr,return 0 ; } +/** +* android_image_get_dtb_img_addr() - Get the address of DTB area in boot image.
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 211
Quoted 10 lines
common/image-android.c +10
-0+* @hdr_addr: Boot image header address +* @addr: Will contain the address of DTB area in boot image +* +* Return: true on success or false on fail. +*/ +static bool android_image_get_dtb_img_addr (ulong hdr_addr,ulong *addr) +{ +const struct andr_img_hdr *hdr; +ulong dtb_img_addr; +bool res = true;
Perhaps this isn't universal but at least with DM we use 'ret' for return code instead of 'res' for result.
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 216
Quoted 5 lines
common/image-android.c +5
-0+ + hdr =map_sysmem (hdr_addr,sizeof (*hdr)); +if (android_image_check_header (hdr)) { +printf ("Error: Boot Image header is incorrect\n" ); + res = false;
Could this function return an error code?
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 226
Quoted 10 lines
common/image-android.c +10
-0+ goto exit; + } + +if (hdr->header_version <2 ) { +printf ("Error: header_version must be >= 2 to get dtb\n" ); + res = false; + goto exit; + } + +if (hdr->dtb_size ==0 ) {
if (!hdr...)
Quoted 21 lines
common/image-android.c +21
-0+printf ("Error: dtb_size is 0\n" ); + res = false; + goto exit; + } + +/* Calculate the address of DTB area in boot image */ + dtb_img_addr = hdr_addr; + dtb_img_addr += hdr->page_size; + dtb_img_addr +=ALIGN (hdr->kernel_size, hdr->page_size); + dtb_img_addr +=ALIGN (hdr->ramdisk_size, hdr->page_size); + dtb_img_addr +=ALIGN (hdr->second_size, hdr->page_size); + dtb_img_addr +=ALIGN (hdr->recovery_dtbo_size, hdr->page_size); + + *addr = dtb_img_addr; + +exit: +unmap_sysmem (hdr); +return res; +} + +/**
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 257
Quoted 10 lines
common/image-android.c +10
-0+* android_image_get_dtb_by_index() - Get address and size of blob in DTB area. +* @hdr_addr: Boot image header address +* @index: Index of desired DTB in DTB area (starting from 0) +* @addr: If not NULL, will contain address to specified DTB +* @size: If not NULL, will contain size of specified DTB +* +* Get the address and size of DTB blob by its index in DTB area of Android +* Boot Image in RAM. +* +* Return: true on success or false on error.
Let's return an error code.
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 260
Quoted 3 lines
common/image-android.c +3
-0+*/ +bool android_image_get_dtb_by_index (ulong hdr_addr,u32 index,ulong *addr, +u32 *size)
Suggest adding a 'p' suffix to return values, i.e. addrp and sizep.
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 267
Quoted 7 lines
common/image-android.c +7
-0+{ +const struct andr_img_hdr *hdr; +bool res; +ulong dtb_img_addr;/* address of DTB part in boot image */ +u32 dtb_img_size;/* size of DTB payload in boot image */ +ulong dtb_addr;/* address of DTB blob with specified index */ +u32 i;/* index iterator */
Why use u32 for these variables? Natural types should be used where possible, i.e. uint or int.
Quoted 51 lines
common/image-android.c +47
-0+ + res =android_image_get_dtb_img_addr (hdr_addr, &dtb_img_addr); +if (!res) +return false; + +/* Check if DTB area of boot image is in DTBO format */ +if (android_dt_check_header (dtb_img_addr)) { +return android_dt_get_fdt_by_index (dtb_img_addr, index, addr, + size); + } + +/* Find out the address of DTB with specified index in concat blobs */ + hdr =map_sysmem (hdr_addr,sizeof (*hdr)); + dtb_img_size = hdr->dtb_size; +unmap_sysmem (hdr); + i =0 ; + dtb_addr = dtb_img_addr; +while (dtb_addr < dtb_img_addr + dtb_img_size) { +const struct fdt_header *fdt; +u32 dtb_size; + + fdt =map_sysmem (dtb_addr,sizeof (*fdt)); +if (fdt_check_header (fdt) !=0 ) { +unmap_sysmem (fdt); +printf ("Error: Invalid FDT header for index %u\n" , i); +return false; + } + + dtb_size =fdt_totalsize (fdt); +unmap_sysmem (fdt); + +if (i == index) { +if (size) + *size = dtb_size; +if (addr) + *addr = dtb_addr; +return true; + } + + dtb_addr += dtb_size; + ++i;are these are these are these + } + +printf ("Error: Index is out of bounds (%u/%u)\n" , index, i); +return false; +} +#if !defined(CONFIG_SPL_BUILD )/** * android_print_contents - prints out the contents of the Android format image
common/image-android.c void android_print_contents(const struct andr_img_hdr *hdr) · line 366
Quoted 4 lines
common/image-android.c +1
-0@@ -246,4 +363,101 @@ void android_print_contents(const struct andr_img_hdr *hdr)printf ("%sdtb addr: %llx\n" , p, hdr->dtb_addr); } } +
Function comment...what is index?
Quoted 32 lines
common/image-android.c +32
-0+static bool android_image_print_dtb_info (const struct fdt_header *fdt, +u32 index) +{ +int root_node_off; +u32 fdt_size; +const char *model; +const char *compatible; + + root_node_off =fdt_path_offset (fdt,"/" ); +if (root_node_off <0 ) { +printf ("Error: Root node not found\n" ); +return false; + } + + fdt_size =fdt_totalsize (fdt); + compatible =fdt_getprop (fdt, root_node_off,"compatible" , +NULL ); + model =fdt_getprop (fdt, root_node_off,"model" ,NULL ); + +printf (" - DTB #%u:\n" , index); +printf (" (DTB)size = %d\n" , fdt_size); +printf (" (DTB)model = %s\n" , model ? model :"(unknown)" ); +printf (" (DTB)compatible = %s\n" , + compatible ? compatible :"(unknown)" ); + +return true; +} + +/** +* android_image_print_dtb_contents() - Print info for DTB blobs in DTB area. +* @hdr_addr: Boot image header address +*
common/image-android.c void android_print_contents(const struct andr_img_hdr *hdr) · line 408
Quoted 10 lines
common/image-android.c +10
-0+* DTB payload in Android Boot Image v2+ can be in one of following formats: +* 1. Concatenated DTB blobs +* 2. Android DTBO format (see CONFIG_CMD_ADTIMG for details) +* +* This function does next: +* 1. Prints out the format used in DTB area +* 2. Iterates over all DTB blobs in DTB area and prints out the info for +* each blob. +* +* Return: true on success or false on error.
Again I think an error code is better.
Quoted 60 lines
common/image-android.c +54
-0+*/ +bool android_image_print_dtb_contents (ulong hdr_addr) +{ +const struct andr_img_hdr *hdr; +bool res; +ulong dtb_img_addr;/* address of DTB part in boot image */ +u32 dtb_img_size;/* size of DTB payload in boot image */ +ulong dtb_addr;/* address of DTB blob with specified index */ +u32 i;/* index iterator */ + + res =android_image_get_dtb_img_addr (hdr_addr, &dtb_img_addr); +if (!res) +return false; + +/* Check if DTB area of boot image is in DTBO format */ +if (android_dt_check_header (dtb_img_addr)) { +printf ("## DTB area contents (DTBO format):\n" ); +android_dt_print_contents (dtb_img_addr); +return true; + } + +printf ("## DTB area contents (concat format):\n" ); + +/* Iterate over concatenated DTB blobs */ + hdr =map_sysmem (hdr_addr,sizeof (*hdr)); + dtb_img_size = hdr->dtb_size; +unmap_sysmem (hdr); + i =0 ; + dtb_addr = dtb_img_addr; +while (dtb_addr < dtb_img_addr + dtb_img_size) { +const struct fdt_header *fdt; +u32 dtb_size; + + fdt =map_sysmem (dtb_addr,sizeof (*fdt)); +if (fdt_check_header (fdt) !=0 ) { +unmap_sysmem (fdt); +printf ("Error: Invalid FDT header for index %u\n" , i); +return false; + } + + res =android_image_print_dtb_info (fdt, i); +if (!res) { +unmap_sysmem (fdt); +return false; + } + + dtb_size =fdt_totalsize (fdt); +unmap_sysmem (fdt); + dtb_addr += dtb_size; + ++i; + } + +return true; +}#endif include/image.h +0
-0
include/image.h int android_image_get_ramdisk(const struct andr_img_hdr *hdr, · line 1337
Quoted 5 lines
include/image.h +2
-0@@ -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 (ulong hdr_addr,u32 index,ulong *addr, +u32 *size);
Function comment
Quoted 11 lines
include/image.h +3
-1ulong 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 */ --
Quoted 2 lines
2.24.0
Regards,
SImon
PATCH v3 1/9 image: android: Add functions for handling dtb field
Hi Simon,
Quoted 55 lines · Simon Glass
Hi Sam,
Quoted 51 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 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 formatThe latter requires "
android-image-dt.c" functionality, so this commit selects that file for building forCONFIG_ANDROID_BOOT_IMAGEoption.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 imageSigned-off-by Sam Protsenko <[email protected]>--- common/Makefile | 2 +- common/image-android.c | 214 +++++++++++++++++++++++++++++++++++++++++ include/image.h | 5 + 3 files changed, 220 insertions(+), 1 deletion(-)common/Makefile +1
-1@@ -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.ocommon/image-android.c +0
-1--- a/common/image-android.c
Quoted 9 lines
common/image-android.c line 9
Quoted 6 lines
+++
b/common/image-android.ccommon/image-android.c +1
-0@@ -6,10 +6,12 @@#include <common.h> #include <env.h> #include <image.h> +#include <image-android-dt.h> Prefer underscores if possible.
It's existing header file, related to another feature. So it can be renamed in some separate patch outside of this patch series. Btw, is there any background on why we should stick to underscore in file names?
Quoted 12 lines
Quoted 12 lines
common/image-android.c +1
-0#include <android_image.h> #include <malloc.h> #include <errno.h> #include <asm/unaligned.h> +#include <mapmem.h> #define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR 0x10008000@@ -195,6 +197,121 @@ int android_image_get_second(const struct andr_img_hdr *hdr,return 0 ; }
Quoted 16 lines
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 211
Quoted 12 lines
common/image-android.c +12
-0+/** +* android_image_get_dtb_img_addr() - Get the address of DTB area in boot image. +* @hdr_addr: Boot image header address +* @addr: Will contain the address of DTB area in boot image +* +* Return: true on success or false on fail. +*/ +static bool android_image_get_dtb_img_addr (ulong hdr_addr,ulong *addr) +{ +const struct andr_img_hdr *hdr; +ulong dtb_img_addr; +bool res = true;Perhaps this isn't universal but at least with DM we use 'ret' for return code instead of 'res' for result.
I think it's just a matter of taste. Not a major one, right?
Quoted 8 lines
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 216
Quoted 5 lines
common/image-android.c +5
-0+ + hdr =map_sysmem (hdr_addr,sizeof (*hdr)); +if (android_image_check_header (hdr)) { +printf ("Error: Boot Image header is incorrect\n" ); + res = false;Could this function return an error code?
Frankly, don't see much value in error code in this particular case. All we can do to handle any error in this function further is just to print corresponding error message, which I do in this function already (sticking to principle to print error messages where we actually know what happened). So I'd stick to just bool, if you don't mind, to not over-complicate this without actual reason.
Quoted 4 lines
Quoted 4 lines
common/image-android.c +4
-0+ goto exit; + } + +if (hdr->header_version <2 ) {
Quoted 9 lines
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 226
Quoted 6 lines
common/image-android.c +6
-0+printf ("Error: header_version must be >= 2 to get dtb\n" ); + res = false; + goto exit; + } + +if (hdr->dtb_size ==0 ) {if (!hdr...)
Actually I really wanted to emphasize here that we test if size is 0, so I'd keep that as is, if you don't mind.
Quoted 25 lines
Quoted 25 lines
common/image-android.c +25
-0+printf ("Error: dtb_size is 0\n" ); + res = false; + goto exit; + } + +/* Calculate the address of DTB area in boot image */ + dtb_img_addr = hdr_addr; + dtb_img_addr += hdr->page_size; + dtb_img_addr +=ALIGN (hdr->kernel_size, hdr->page_size); + dtb_img_addr +=ALIGN (hdr->ramdisk_size, hdr->page_size); + dtb_img_addr +=ALIGN (hdr->second_size, hdr->page_size); + dtb_img_addr +=ALIGN (hdr->recovery_dtbo_size, hdr->page_size); + + *addr = dtb_img_addr; + +exit: +unmap_sysmem (hdr); +return res; +} + +/** +* android_image_get_dtb_by_index() - Get address and size of blob in DTB area. +* @hdr_addr: Boot image header address +* @index: Index of desired DTB in DTB area (starting from 0) +* @addr: If not NULL, will contain address to specified DTB
Quoted 9 lines
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 257
Quoted 6 lines
common/image-android.c +6
-0+* @size: If not NULL, will contain size of specified DTB +* +* Get the address and size of DTB blob by its index in DTB area of Android +* Boot Image in RAM. +* +* Return: true on success or false on error. Let's return an error code.
Sorry, I don't agree. Just by looking how we handle (or can handle in future) error cases when executing this function, I can't see any value in error code. Error message is already printed on each particular error case in this function. So if you don't mind, I'd keep "bool" here (because I don't see some really good reason why not to).
Quoted 6 lines
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 260
Quoted 3 lines
common/image-android.c +3
-0+*/ +bool android_image_get_dtb_by_index (ulong hdr_addr,u32 index,ulong *addr, +u32 *size)Suggest adding a 'p' suffix to return values, i.e. addrp and sizep.
Sorry, I really don't like cluttering variable names with suffixes. We already know that those are pointers, just by looking at function signature. I'd better stay away from stuff like Hungarian notation, but maybe it's just my Windows development induced trauma is talking ;)
Quoted 11 lines
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 267
Quoted 7 lines
common/image-android.c +7
-0+{ +const struct andr_img_hdr *hdr; +bool res; +ulong dtb_img_addr;/* address of DTB part in boot image */ +u32 dtb_img_size;/* size of DTB payload in boot image */ +ulong dtb_addr;/* address of DTB blob with specified index */ +u32 i;/* index iterator */ Why use u32 for these variables? Natural types should be used where possible, i.e. uint or int.
'dtb_img_size' should be u32, because struct andr_img_hdr::dtb_size is u32, and it's being assigned to 'dtb_img_size'.
As for 'i', it's used to check the 'index', which in turn is used to check struct dt_table_header::dt_entry_count, in android_dt_get_fdt_by_index() function.
Although I agree that in common case we should stick to int/ulong, in this particular case I guess u32 choice is valid.
Quoted 49 lines
Quoted 49 lines
common/image-android.c +47
-0+ + res =android_image_get_dtb_img_addr (hdr_addr, &dtb_img_addr); +if (!res) +return false; + +/* Check if DTB area of boot image is in DTBO format */ +if (android_dt_check_header (dtb_img_addr)) { +return android_dt_get_fdt_by_index (dtb_img_addr, index, addr, + size); + } + +/* Find out the address of DTB with specified index in concat blobs */ + hdr =map_sysmem (hdr_addr,sizeof (*hdr)); + dtb_img_size = hdr->dtb_size; +unmap_sysmem (hdr); + i =0 ; + dtb_addr = dtb_img_addr; +while (dtb_addr < dtb_img_addr + dtb_img_size) { +const struct fdt_header *fdt; +u32 dtb_size; + + fdt =map_sysmem (dtb_addr,sizeof (*fdt)); +if (fdt_check_header (fdt) !=0 ) { +unmap_sysmem (fdt); +printf ("Error: Invalid FDT header for index %u\n" , i); +return false; + } + + dtb_size =fdt_totalsize (fdt); +unmap_sysmem (fdt); + +if (i == index) { +if (size) + *size = dtb_size; +if (addr) + *addr = dtb_addr; +return true; + } + + dtb_addr += dtb_size; + ++i;are these are these are these + } + +printf ("Error: Index is out of bounds (%u/%u)\n" , index, i); +return false; +} +#if !defined(CONFIG_SPL_BUILD )/**
Quoted 9 lines
common/image-android.c void android_print_contents(const struct andr_img_hdr *hdr) · line 366
Quoted 6 lines
common/image-android.c +1
-0* android_print_contents - prints out the contents of the Android format image @@ -246,4 +363,101 @@ void android_print_contents(const struct andr_img_hdr *hdr)printf ("%sdtb addr: %llx\n" , p, hdr->dtb_addr); } } +Function comment...what is index?
It's static, so I decided the comment can be ommited in this case. But ok, I'll add it in v4, for consistency.
Quoted 36 lines
Quoted 36 lines
common/image-android.c +36
-0+static bool android_image_print_dtb_info (const struct fdt_header *fdt, +u32 index) +{ +int root_node_off; +u32 fdt_size; +const char *model; +const char *compatible; + + root_node_off =fdt_path_offset (fdt,"/" ); +if (root_node_off <0 ) { +printf ("Error: Root node not found\n" ); +return false; + } + + fdt_size =fdt_totalsize (fdt); + compatible =fdt_getprop (fdt, root_node_off,"compatible" , +NULL ); + model =fdt_getprop (fdt, root_node_off,"model" ,NULL ); + +printf (" - DTB #%u:\n" , index); +printf (" (DTB)size = %d\n" , fdt_size); +printf (" (DTB)model = %s\n" , model ? model :"(unknown)" ); +printf (" (DTB)compatible = %s\n" , + compatible ? compatible :"(unknown)" ); + +return true; +} + +/** +* android_image_print_dtb_contents() - Print info for DTB blobs in DTB area. +* @hdr_addr: Boot image header address +* +* DTB payload in Android Boot Image v2+ can be in one of following formats: +* 1. Concatenated DTB blobs +* 2. Android DTBO format (see CONFIG_CMD_ADTIMG for details) +*
Quoted 9 lines
common/image-android.c void android_print_contents(const struct andr_img_hdr *hdr) · line 408
Quoted 6 lines
common/image-android.c +6
-0+* This function does next: +* 1. Prints out the format used in DTB area +* 2. Iterates over all DTB blobs in DTB area and prints out the info for +* each blob. +* +* Return: true on success or false on error. Again I think an error code is better.
As stated above, I don't see any actual usages of error code value... So I'd stick to bool as more simplistic choice, if it's not critical with you.
Quoted 59 lines
Quoted 59 lines
common/image-android.c +54
-0+*/ +bool android_image_print_dtb_contents (ulong hdr_addr) +{ +const struct andr_img_hdr *hdr; +bool res; +ulong dtb_img_addr;/* address of DTB part in boot image */ +u32 dtb_img_size;/* size of DTB payload in boot image */ +ulong dtb_addr;/* address of DTB blob with specified index */ +u32 i;/* index iterator */ + + res =android_image_get_dtb_img_addr (hdr_addr, &dtb_img_addr); +if (!res) +return false; + +/* Check if DTB area of boot image is in DTBO format */ +if (android_dt_check_header (dtb_img_addr)) { +printf ("## DTB area contents (DTBO format):\n" ); +android_dt_print_contents (dtb_img_addr); +return true; + } + +printf ("## DTB area contents (concat format):\n" ); + +/* Iterate over concatenated DTB blobs */ + hdr =map_sysmem (hdr_addr,sizeof (*hdr)); + dtb_img_size = hdr->dtb_size; +unmap_sysmem (hdr); + i =0 ; + dtb_addr = dtb_img_addr; +while (dtb_addr < dtb_img_addr + dtb_img_size) { +const struct fdt_header *fdt; +u32 dtb_size; + + fdt =map_sysmem (dtb_addr,sizeof (*fdt)); +if (fdt_check_header (fdt) !=0 ) { +unmap_sysmem (fdt); +printf ("Error: Invalid FDT header for index %u\n" , i); +return false; + } + + res =android_image_print_dtb_info (fdt, i); +if (!res) { +unmap_sysmem (fdt); +return false; + } + + dtb_size =fdt_totalsize (fdt); +unmap_sysmem (fdt); + dtb_addr += dtb_size; + ++i; + } + +return true; +}#endif include/image.h +0
-0
Quoted 9 lines
include/image.h int android_image_get_ramdisk(const struct andr_img_hdr *hdr, · line 1337
Quoted 6 lines
include/image.h +2
-0@@ -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 (ulong hdr_addr,u32 index,ulong *addr, +u32 *size);Function comment
It's present next to function implementation, in common/image-android.c (like it's usually done in Linux kernel).
Quoted 16 lines
Quoted 11 lines
include/image.h +3
-1ulong 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 */ --Quoted 2 lines
2.24.0
Regards,
SImon
PATCH v3 1/9 image: android: Add functions for handling dtb field
Hi Sam,
Quoted 69 lines · Sam Protsenko
Hi Simon,
Quoted 55 lines · Simon Glass
Hi Sam,
Quoted 51 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 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 formatThe latter requires "
android-image-dt.c" functionality, so this commit selects that file for building forCONFIG_ANDROID_BOOT_IMAGEoption.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 imageSigned-off-by Sam Protsenko <[email protected]>--- common/Makefile | 2 +- common/image-android.c | 214 +++++++++++++++++++++++++++++++++++++++++ include/image.h | 5 + 3 files changed, 220 insertions(+), 1 deletion(-)common/Makefile +1
-1@@ -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.ocommon/image-android.c +0
-1--- a/common/image-android.cQuoted 9 lines
common/image-android.c line 9
Quoted 6 lines
+++
b/common/image-android.ccommon/image-android.c +1
-0@@ -6,10 +6,12 @@#include <common.h> #include <env.h> #include <image.h> +#include <image-android-dt.h> Prefer underscores if possible.
Quoted 4 lines
It's existing header file, related to another feature. So it can be renamed in some separate patch outside of this patch series. Btw, is there any background on why we should stick to underscore in file names?
I added a comment here:
https://www.denx.de/wiki/U-Boot/CodingStyle
Quoted 30 lines
Quoted 13 lines
Quoted 13 lines
common/image-android.c +1
-0#include <android_image.h> #include <malloc.h> #include <errno.h> #include <asm/unaligned.h> +#include <mapmem.h> #define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR 0x10008000@@ -195,6 +197,121 @@ int android_image_get_second(const struct andr_img_hdr *hdr,return 0 ; }Quoted 16 lines
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 211
Quoted 12 lines
common/image-android.c +12
-0+/** +* android_image_get_dtb_img_addr() - Get the address of DTB area in boot image. +* @hdr_addr: Boot image header address +* @addr: Will contain the address of DTB area in boot image +* +* Return: true on success or false on fail. +*/ +static bool android_image_get_dtb_img_addr (ulong hdr_addr,ulong *addr) +{ +const struct andr_img_hdr *hdr; +ulong dtb_img_addr; +bool res = true;Perhaps this isn't universal but at least with DM we use 'ret' for return code instead of 'res' for result.
Quoted 1 line
I think it's just a matter of taste. Not a major one, right?
Not major perhaps, but this sort of consistency makes the code much easier to read, IMO. Using error codes as return values is pretty universal in U-Boot so I think you should do that instead of true/false.
Quoted 10 lines
Quoted 9 lines
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 216
Quoted 6 lines
common/image-android.c +5
-0+ + hdr =map_sysmem (hdr_addr,sizeof (*hdr)); +if (android_image_check_header (hdr)) { +printf ("Error: Boot Image header is incorrect\n" ); + res = false;Could this function return an error code?
Quoted 6 lines
Frankly, don't see much value in error code in this particular case. All we can do to handle any error in this function further is just to print corresponding error message, which I do in this function already (sticking to principle to print error messages where we actually know what happened). So I'd stick to just bool, if you don't mind, to not over-complicate this without actual reason.
It is not a great idea to print an error message in a leaf function. Ideally we would do all of this in the command that calls the function, if it can be determined by the error code.
Also, 'boot image header is incorrect' doesn't help that much. What is incorrect about it? You could print the return code so you know. Following your philosophy you should add lots of printf() calls to android_image_check_header().
Also log_err() is better than printf()
Quoted 15 lines
Quoted 14 lines
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 226
Quoted 11 lines
common/image-android.c +10
-0+ goto exit; + } + +if (hdr->header_version <2 ) { +printf ("Error: header_version must be >= 2 to get dtb\n" ); + res = false; + goto exit; + } + +if (hdr->dtb_size ==0 ) {if (!hdr...)
Quoted 2 lines
Actually I really wanted to emphasize here that we test if size is 0, so I'd keep that as is, if you don't mind.
OK I guess it is just what you are used to.
Quoted 36 lines
Quoted 26 lines
Quoted 26 lines
common/image-android.c +25
-0+printf ("Error: dtb_size is 0\n" ); + res = false; + goto exit; + } + +/* Calculate the address of DTB area in boot image */ + dtb_img_addr = hdr_addr; + dtb_img_addr += hdr->page_size; + dtb_img_addr +=ALIGN (hdr->kernel_size, hdr->page_size); + dtb_img_addr +=ALIGN (hdr->ramdisk_size, hdr->page_size); + dtb_img_addr +=ALIGN (hdr->second_size, hdr->page_size); + dtb_img_addr +=ALIGN (hdr->recovery_dtbo_size, hdr->page_size); + + *addr = dtb_img_addr; + +exit: +unmap_sysmem (hdr); +return res; +} + +/** +* android_image_get_dtb_by_index() - Get address and size of blob in DTB area. +* @hdr_addr: Boot image header address +* @index: Index of desired DTB in DTB area (starting from 0) +* @addr: If not NULL, will contain address to specified DTB Quoted 9 lines
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 257
Quoted 6 lines
common/image-android.c +6
-0+* @size: If not NULL, will contain size of specified DTB +* +* Get the address and size of DTB blob by its index in DTB area of Android +* Boot Image in RAM. +* +* Return: true on success or false on error. Let's return an error code.
Quoted 5 lines
Sorry, I don't agree. Just by looking how we handle (or can handle in future) error cases when executing this function, I can't see any value in error code. Error message is already printed on each particular error case in this function. So if you don't mind, I'd keep "bool" here (because I don't see some really good reason why not to).
See above.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
common/image-android.c +3
-0+*/ +bool android_image_get_dtb_by_index (ulong hdr_addr,u32 index,ulong *addr, +u32 *size)
Quoted 8 lines
Quoted 2 lines
Suggest adding a 'p' suffix to return values, i.e. addrp and sizep.
Sorry, I really don't like cluttering variable names with suffixes. We already know that those are pointers, just by looking at function signature. I'd better stay away from stuff like Hungarian notation, but maybe it's just my Windows development induced trauma is talking ;)
Again this is just a matter of style. Driver model uses 'p' and some of image.h. I like Hungarians but not their notation either, except in this case where is a really good visual indication of what is going on.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
common/image-android.c +7
-0+{ +const struct andr_img_hdr *hdr; +bool res; +ulong dtb_img_addr;/* address of DTB part in boot image */ +u32 dtb_img_size;/* size of DTB payload in boot image */ +ulong dtb_addr;/* address of DTB blob with specified index */ +u32 i;/* index iterator */
Quoted 6 lines
Quoted 3 lines
Why use u32 for these variables? Natural types should be used where possible, i.e. uint or int.
'
dtb_img_size' should be u32, because structandr_img_hdr::dtb_sizeis u32, and it's being assigned to 'dtb_img_size'.
I'm not sure why.
Quoted 7 lines
As for 'i', it's used to check the 'index', which in turn is used to check struct
dt_table_header::dt_entry_count, inandroid_dt_get_fdt_by_index()function.Although I agree that in common case we should stick to int/ulong, in this particular case I guess u32 choice is valid.
In general we should use natural sizes to avoid shifts/masks, etc. on machines with a larger word size. The exception is structures, etc. where you need a certain binary format.
Quoted 60 lines
Quoted 50 lines
Quoted 50 lines
common/image-android.c +47
-0+ + res =android_image_get_dtb_img_addr (hdr_addr, &dtb_img_addr); +if (!res) +return false; + +/* Check if DTB area of boot image is in DTBO format */ +if (android_dt_check_header (dtb_img_addr)) { +return android_dt_get_fdt_by_index (dtb_img_addr, index, addr, + size); + } + +/* Find out the address of DTB with specified index in concat blobs */ + hdr =map_sysmem (hdr_addr,sizeof (*hdr)); + dtb_img_size = hdr->dtb_size; +unmap_sysmem (hdr); + i =0 ; + dtb_addr = dtb_img_addr; +while (dtb_addr < dtb_img_addr + dtb_img_size) { +const struct fdt_header *fdt; +u32 dtb_size; + + fdt =map_sysmem (dtb_addr,sizeof (*fdt)); +if (fdt_check_header (fdt) !=0 ) { +unmap_sysmem (fdt); +printf ("Error: Invalid FDT header for index %u\n" , i); +return false; + } + + dtb_size =fdt_totalsize (fdt); +unmap_sysmem (fdt); + +if (i == index) { +if (size) + *size = dtb_size; +if (addr) + *addr = dtb_addr; +return true; + } + + dtb_addr += dtb_size; + ++i;are these are these are these + } + +printf ("Error: Index is out of bounds (%u/%u)\n" , index, i); +return false; +} +#if !defined(CONFIG_SPL_BUILD )/** Quoted 9 lines
common/image-android.c void android_print_contents(const struct andr_img_hdr *hdr) · line 366
Quoted 6 lines
common/image-android.c +1
-0* android_print_contents - prints out the contents of the Android format image @@ -246,4 +363,101 @@ void android_print_contents(const struct andr_img_hdr *hdr)printf ("%sdtb addr: %llx\n" , p, hdr->dtb_addr); } } +Function comment...what is index?
Quoted 2 lines
It's static, so I decided the comment can be ommited in this case. But ok, I'll add it in v4, for consistency.
Yes please. Function comments should be added for non-trivial functions even if they are static.
Quoted 47 lines
Quoted 37 lines
Quoted 37 lines
common/image-android.c +36
-0+static bool android_image_print_dtb_info (const struct fdt_header *fdt, +u32 index) +{ +int root_node_off; +u32 fdt_size; +const char *model; +const char *compatible; + + root_node_off =fdt_path_offset (fdt,"/" ); +if (root_node_off <0 ) { +printf ("Error: Root node not found\n" ); +return false; + } + + fdt_size =fdt_totalsize (fdt); + compatible =fdt_getprop (fdt, root_node_off,"compatible" , +NULL ); + model =fdt_getprop (fdt, root_node_off,"model" ,NULL ); + +printf (" - DTB #%u:\n" , index); +printf (" (DTB)size = %d\n" , fdt_size); +printf (" (DTB)model = %s\n" , model ? model :"(unknown)" ); +printf (" (DTB)compatible = %s\n" , + compatible ? compatible :"(unknown)" ); + +return true; +} + +/** +* android_image_print_dtb_contents() - Print info for DTB blobs in DTB area. +* @hdr_addr: Boot image header address +* +* DTB payload in Android Boot Image v2+ can be in one of following formats: +* 1. Concatenated DTB blobs +* 2. Android DTBO format (see CONFIG_CMD_ADTIMG for details) +* Quoted 9 lines
common/image-android.c void android_print_contents(const struct andr_img_hdr *hdr) · line 408
Quoted 6 lines
common/image-android.c +6
-0+* This function does next: +* 1. Prints out the format used in DTB area +* 2. Iterates over all DTB blobs in DTB area and prints out the info for +* each blob. +* +* Return: true on success or false on error. Again I think an error code is better.
Quoted 3 lines
As stated above, I don't see any actual usages of error code value... So I'd stick to bool as more simplistic choice, if it's not critical with you.
See above, but I suggest you add some error codes, so the caller can see what went wrong.
Quoted 70 lines
Quoted 60 lines
Quoted 60 lines
common/image-android.c +54
-0+*/ +bool android_image_print_dtb_contents (ulong hdr_addr) +{ +const struct andr_img_hdr *hdr; +bool res; +ulong dtb_img_addr;/* address of DTB part in boot image */ +u32 dtb_img_size;/* size of DTB payload in boot image */ +ulong dtb_addr;/* address of DTB blob with specified index */ +u32 i;/* index iterator */ + + res =android_image_get_dtb_img_addr (hdr_addr, &dtb_img_addr); +if (!res) +return false; + +/* Check if DTB area of boot image is in DTBO format */ +if (android_dt_check_header (dtb_img_addr)) { +printf ("## DTB area contents (DTBO format):\n" ); +android_dt_print_contents (dtb_img_addr); +return true; + } + +printf ("## DTB area contents (concat format):\n" ); + +/* Iterate over concatenated DTB blobs */ + hdr =map_sysmem (hdr_addr,sizeof (*hdr)); + dtb_img_size = hdr->dtb_size; +unmap_sysmem (hdr); + i =0 ; + dtb_addr = dtb_img_addr; +while (dtb_addr < dtb_img_addr + dtb_img_size) { +const struct fdt_header *fdt; +u32 dtb_size; + + fdt =map_sysmem (dtb_addr,sizeof (*fdt)); +if (fdt_check_header (fdt) !=0 ) { +unmap_sysmem (fdt); +printf ("Error: Invalid FDT header for index %u\n" , i); +return false; + } + + res =android_image_print_dtb_info (fdt, i); +if (!res) { +unmap_sysmem (fdt); +return false; + } + + dtb_size =fdt_totalsize (fdt); +unmap_sysmem (fdt); + dtb_addr += dtb_size; + ++i; + } + +return true; +}#endif include/image.h +0
-0Quoted 9 lines
include/image.h int android_image_get_ramdisk(const struct andr_img_hdr *hdr, · line 1337
Quoted 6 lines
include/image.h +2
-0@@ -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 (ulong hdr_addr,u32 index,ulong *addr, +u32 *size);Function comment
Quoted 2 lines
It's present next to function implementation, in
common/image-android.c(like it's usually done in Linux kernel).
OK but please put it in the header, which is where people look and ctags takes you for the definition. The header file describes the API for image.h
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
include/image.h +3
-0ulong 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
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
include/image.h +0
-1#endif /* CONFIG_ANDROID_BOOT_IMAGE */ --2.24.0
Regards,
Simon
PATCH v3 2/9 image: android: Add routine to get dtbo params
In reply to Sam ProtsenkoAndroid 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
@@ -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 res = true; + + hdr =map_sysmem (hdr_addr,sizeof (*hdr)); +if (android_image_check_header (hdr)) { +printf ("Error: Boot Image header is incorrect\n" ); + res = false; + goto exit; + } + +if (hdr->header_version <1 ) { +printf ("Error: header_version must be >= 1 to get dtbo\n" ); + res = false; + goto exit; + } + +if (hdr->recovery_dtbo_size ==0 ) { +printf ("Error: recovery_dtbo_size is 0\n" ); + res = 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 res; +} +/** * 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
@@ -1333,6 +1333,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
PATCH v3 2/9 image: android: Add routine to get dtbo params
Hi Sam,
Quoted 36 lines · 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/partitionsSigned-off-by Sam Protsenko <[email protected]>--- common/image-android.c | 61 ++++++++++++++++++++++++++++++++++++++++++ include/image.h | 1 + 2 files changed, 62 insertions(+)common/image-android.c +8
-0@@ -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
common/image-android.c int android_image_get_second(const struct andr_img_hdr *hdr, · line 217
Quoted 10 lines
common/image-android.c +10
-0+* 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.
Same comments as previous patch on error codes, etc.
Also can we have a test for all this code?
Quoted 51 lines
common/image-android.c +43
-0+*/ +bool android_image_get_dtbo (ulong hdr_addr,ulong *addr,u32 *size) +{ +const struct andr_img_hdr *hdr; +ulong dtbo_img_addr; +bool res = true; + + hdr =map_sysmem (hdr_addr,sizeof (*hdr)); +if (android_image_check_header (hdr)) { +printf ("Error: Boot Image header is incorrect\n" ); + res = false; + goto exit; + } + +if (hdr->header_version <1 ) { +printf ("Error: header_version must be >= 1 to get dtbo\n" ); + res = false; + goto exit; + } + +if (hdr->recovery_dtbo_size ==0 ) { +printf ("Error: recovery_dtbo_size is 0\n" ); + res = 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 res; +} +/** * android_image_get_dtb_img_addr() - Get the address of DTB area in boot image. * @hdr_addr: Boot image header address include/image.h +0
-0
include/image.h int android_image_get_ramdisk(const struct andr_img_hdr *hdr, · line 1336
Quoted 4 lines
include/image.h +1
-0@@ -1333,6 +1333,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);
function comment again
Quoted 6 lines
include/image.h +0
-1bool 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); --2.24.0
Regards,
SImon
PATCH v3 3/9 cmd: abootimg: Add abootimg command
In reply to Sam ProtsenkoThis 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 | 242 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 cmd/abootimg.c
cmd/Kconfig +8 -0
@@ -356,6 +356,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
@@ -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 +242 -0
242 lines not on this page · raw message
Signature · 1 line
2.24.0
PATCH v3 3/9 cmd: abootimg: Add abootimg command
Hi,
With below nits, I have provided the Reviewed-by/Tested-by signatures.
Quoted 5 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 blob from boot.img in scripting manner, and then apply needed dtbo's (from "dtbo"
FWIW, 'scripted manner' is more common, as suggested by Ngram:
https://tinyurl.com/rck3ysj
Quoted 6 lines
cmd/abootimg.c +5
-0+static int abootimg_get_dtb_by_index (int argc,char *const argv[]) +{ +u32 num; +char *endp; +ulong addr;
cmd/abootimg.c line 108
Quoted 10 lines
cmd/abootimg.c +10
-0+u32 size; + +if (argc <1 || argc >3 ) +return CMD_RET_USAGE ; + + num =simple_strtoul (argv[0 ] +strlen ("--index=" ), &endp,0 ); +if (*endp !='\0' ) { +printf ("Error: Wrong num\n" ); +return CMD_RET_FAILURE ; + }
The way '--index=' option is processed right now results in below inconsistencies:
=> abootimg get dtb --index=0
1980
`- expected output
=> abootimg get dtb --index=
1980
`- unexpected output (expected error)
=> abootimg get dtb --index=0 --index=1
=>
`- unexpected output (expected error)
Quoted 11 lines
cmd/abootimg.c +11
-0+U_BOOT_CMD ( + abootimg,CONFIG_SYS_MAXARGS ,0 , do_abootimg, +"manipulate Android Boot Image" , +"addr <addr>\n" +" - set the address in RAM where boot image is located\n" +" ($loadaddr is used by default)\n" +"abootimg dump dtb\n" +" - print info for all DT blobs in DTB area\n" +"abootimg get ver [varname]\n" +" - get header version\n" + "abootimg get recovery_dtbo [addr_var [size_var]]\n"
cmd/abootimg.c line 241
Quoted 10 lines
cmd/abootimg.c +10
-0+" - get address and size (hex) of recovery DTBO area in the image\n" +" [addr_var]: variable name to contain DTBO area address\n" +" [size_var]: variable name to contain DTBO area size\n" +"abootimg get dtb_load_addr [varname]\n" +" - get load address (hex) of DTB, from image header\n" +"abootimg get dtb --index=<num> [addr_var [size_var]]\n" +" - get address and size (hex) of DT blob in the image by index\n" +" <num>: index number of desired DT blob in DTB area\n" +" [addr_var]: variable name to contain DT blob address\n" +" [size_var]: variable name to contain DT blob size\n"
[minor] Superfluous blank line at the end of help.
Apart from the above, testing two Android v2 images containing the DTB in so called "concat" and DTBO formats didn't reveal any issues.
Signature · 2 lines
Best Regards, Eugeniu
PATCH v3 3/9 cmd: abootimg: Add abootimg command
In reply to Sam ProtsenkoQuoted 25 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 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 1boot_aboot_start
=> part size mmc 1boot_aboot_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
Quoted 7 lines
Signed-off-by Sam Protsenko <[email protected]>--- cmd/Kconfig | 8 ++ cmd/Makefile | 1 + cmd/abootimg.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 cmd/abootimg.c
Can we have a test please?
PATCH v3 4/9 doc: android: Add documentation for Android Boot Image
In reply to Sam ProtsenkoDescribe 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
@@ -364,6 +364,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
PATCH v3 4/9 doc: android: Add documentation for Android Boot Image
Quoted 10 lines · Sam Protsenko
Describe Android Boot Image format, how its support is implemented in U-Boot and associated commands usage.
Signed-off-by Sam Protsenko <[email protected]>--- cmd/Kconfig | 2 + doc/android/boot-image.rst | 154 +++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 doc/android/boot-image.rst
PATCH v3 5/9 test/py: android: Add test for abootimg
In reply to Sam ProtsenkoUnit 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
@@ -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
PATCH v3 5/9 test/py: android: Add test for abootimg
Quoted 8 lines · 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
Quoted 8 lines
shows that 1/1 tests passes successfully.
Signed-off-by Sam Protsenko <[email protected]>--- 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
OK here is the test -)
PATCH v3 6/9 configs: am57xx_evm: Enable Android commands
In reply to Sam ProtsenkoEnable 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
@@ -21,6 +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_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_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
@@ -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_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
@@ -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_SUPPORT=y
@@ -38,10 +40,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
PATCH v3 6/9 configs: am57xx_evm: Enable Android commands
Quoted 14 lines · 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
Quoted 8 lines
While at it, resync defconfig files with "make savedefconfig".
Signed-off-by Sam Protsenko <[email protected]>--- configs/am57xx_evm_defconfig | 6 ++++++ configs/am57xx_hs_evm_defconfig | 6 ++++++ configs/am57xx_hs_evm_usb_defconfig | 6 ++++++ 3 files changed, 18 insertions(+)
PATCH v3 7/9 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
@@ -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
PATCH v3 8/9 env: ti: boot: Boot Android with dynamic partitions
In reply to Sam ProtsenkoChanges:
- 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 | 107 +++++++++++++--------------------- 1 file changed, 42 insertions(+), 65 deletions(-)
include/environment/ti/boot.h +42 -65
@@ -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,20 +65,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 +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; " \ +"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
PATCH v3 9/9 arm: ti: boot: Use correct dtb and dtbo on Android boot
In reply to Sam ProtsenkoRead 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
@@ -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
Bajjuri
v3 cover am57xx: Implement Android 10 boot flow
In reply to Sam ProtsenkoTom,
Quoted 8 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).
This patch series must be applied on top of these recently sent patches by Eugeniu:
Quoted 7 lines
[PATCH 0/3] cmd: dtimg: Rename to adtimg and refactor usage style
Changes in v3:
- rename command to "abootimg" (requested by Simon Glass)
- rework command interface (as discussed with Eugeniu)
- add command documentation
- address other comments
Since this series is functionally mature,
can this series be pulled as-is in the next merge window, verified v3 with current aosp master and functionality is working as expected.
the comments on changing to a more suitable names , adding a new test script for the functionality can be done as a incremental update on the top during the next cycle.
Quoted 33 lines
[1] https://source.android.com/devices/bootloader
Sam Protsenko (9):
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 test/py: android: Add test for abootimg
configs:am57xx_evm: Enable Android commands
env: ti: boot: Respectslot_suffixin AVB commands
env: ti: boot: Boot Android with dynamic partitions
arm: ti: boot: Use correct dtb and dtbo on Android bootcmd/Kconfig | 10 + cmd/Makefile | 1 + cmd/abootimg.c | 242 +++++++++++++++++ common/Makefile | 2 +- common/image-android.c | 275 ++++++++++++++++++++ configs/am57xx_evm_defconfig | 6 + configs/am57xx_hs_evm_defconfig | 6 + configs/am57xx_hs_evm_usb_defconfig | 6 + configs/sandbox_defconfig | 1 + doc/android/boot-image.rst | 154 +++++++++++ include/configs/ti_armv7_common.h | 7 + include/environment/ti/boot.h | 146 ++++++----- include/image.h | 6 + test/py/tests/test_android/test_abootimg.py | 159 +++++++++++ 14 files changed, 954 insertions(+), 67 deletions(-)create mode 100644
cmd/abootimg.c
create mode 100644doc/android/boot-image.rst
create mode 100644test/py/tests/test_android/test_abootimg.py
Bajjuri
v3 cover am57xx: Implement Android 10 boot flow
+ Sam Protsenko's current email address
Quoted 63 lines · Praneeth
Tom,
Quoted 8 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).
This patch series must be applied on top of these recently sent patches by Eugeniu:
Quoted 7 lines
[PATCH 0/3] cmd: dtimg: Rename to adtimg and refactor usage style
Changes in v3:
- rename command to "abootimg" (requested by Simon Glass)
- rework command interface (as discussed with Eugeniu)
- add command documentation
- address other commentsSince this series is functionally mature,
can this series be pulled as-is in the next merge window, verified v3 with current aosp master and functionality is working as expected.the comments on changing to a more suitable names , adding a new test script for the functionality can be done as a incremental update on the top during the next cycle.
Quoted 33 lines
[1] https://source.android.com/devices/bootloader
Sam Protsenko (9):
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 test/py: android: Add test for abootimg
configs:am57xx_evm: Enable Android commands
env: ti: boot: Respectslot_suffixin AVB commands
env: ti: boot: Boot Android with dynamic partitions
arm: ti: boot: Use correct dtb and dtbo on Android bootcmd/Kconfig | 10 + cmd/Makefile | 1 + cmd/abootimg.c | 242 +++++++++++++++++ common/Makefile | 2 +- common/image-android.c | 275 ++++++++++++++++++++ configs/am57xx_evm_defconfig | 6 + configs/am57xx_hs_evm_defconfig | 6 + configs/am57xx_hs_evm_usb_defconfig | 6 + configs/sandbox_defconfig | 1 + doc/android/boot-image.rst | 154 +++++++++++ include/configs/ti_armv7_common.h | 7 + include/environment/ti/boot.h | 146 ++++++----- include/image.h | 6 +
test/py/tests/test_android/test_abootimg.py| 159 +++++++++++14 files changed, 954 insertions(+), 67 deletions(-)create mode 100644
cmd/abootimg.c
create mode 100644doc/android/boot-image.rst
create mode 100644test/py/tests/test_android/test_abootimg.py