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

Signed-off-by: Sam Protsenko <semen.protse...@linaro.org>
---
 common/image-android.c | 54 ++++++++++++++++++++++++++++++++++++++++++
 include/image.h        |  2 ++
 2 files changed, 56 insertions(+)

diff --git a/common/image-android.c b/common/image-android.c
index 63e41ea5f1..5ecd75dcfc 100644
--- a/common/image-android.c
+++ b/common/image-android.c
@@ -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
diff --git a/include/image.h b/include/image.h
index 08eda41961..c8a3088acb 100644
--- a/include/image.h
+++ b/include/image.h
@@ -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);
-- 
2.23.0

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to