1 // SPDX-License-Identifier: GPL-2.0+
8 #include <image-android-dt.h>
9 #include <android_image.h>
12 #include <asm/unaligned.h>
14 #include <linux/libfdt.h>
16 #define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR 0x10008000
17 #define ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR 0x11000000
19 static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
21 static ulong checksum(const unsigned char *buffer, ulong size)
25 for (ulong i = 0; i < size; i++)
30 static bool is_trailer_present(ulong bootconfig_end_addr)
32 return !strncmp((char *)(bootconfig_end_addr - BOOTCONFIG_MAGIC_SIZE),
33 BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_SIZE);
36 static ulong add_trailer(ulong bootconfig_start_addr, ulong bootconfig_size)
41 if (!bootconfig_start_addr)
46 end = bootconfig_start_addr + bootconfig_size;
47 if (is_trailer_present(end))
50 memcpy((void *)(end), &bootconfig_size, BOOTCONFIG_SIZE_SIZE);
51 sum = checksum((unsigned char *)bootconfig_start_addr, bootconfig_size);
52 memcpy((void *)(end + BOOTCONFIG_SIZE_SIZE), &sum,
53 BOOTCONFIG_CHECKSUM_SIZE);
54 memcpy((void *)(end + BOOTCONFIG_SIZE_SIZE + BOOTCONFIG_CHECKSUM_SIZE),
55 BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_SIZE);
57 return BOOTCONFIG_TRAILER_SIZE;
60 __weak ulong get_avendor_bootimg_addr(void)
65 static void android_boot_image_v3_v4_parse_hdr(const struct andr_boot_img_hdr_v3 *hdr,
66 struct andr_image_data *data)
70 data->kcmdline = hdr->cmdline;
71 data->header_version = hdr->header_version;
74 * The header takes a full page, the remaining components are aligned
78 end += ANDR_GKI_PAGE_SIZE;
79 data->kernel_ptr = end;
80 data->kernel_size = hdr->kernel_size;
81 end += ALIGN(hdr->kernel_size, ANDR_GKI_PAGE_SIZE);
82 data->ramdisk_ptr = end;
83 data->ramdisk_size = hdr->ramdisk_size;
84 data->boot_ramdisk_size = hdr->ramdisk_size;
85 end += ALIGN(hdr->ramdisk_size, ANDR_GKI_PAGE_SIZE);
87 if (hdr->header_version > 3)
88 end += ALIGN(hdr->signature_size, ANDR_GKI_PAGE_SIZE);
90 data->boot_img_total_size = end - (ulong)hdr;
93 static void android_vendor_boot_image_v3_v4_parse_hdr(const struct andr_vnd_boot_img_hdr
94 *hdr, struct andr_image_data *data)
99 * The header takes a full page, the remaining components are aligned
102 data->kcmdline_extra = hdr->cmdline;
103 data->tags_addr = hdr->tags_addr;
104 data->image_name = hdr->name;
105 data->kernel_addr = hdr->kernel_addr;
106 data->ramdisk_addr = hdr->ramdisk_addr;
107 data->dtb_load_addr = hdr->dtb_addr;
108 data->bootconfig_size = hdr->bootconfig_size;
110 end += hdr->page_size;
111 if (hdr->vendor_ramdisk_size) {
112 data->vendor_ramdisk_ptr = end;
113 data->vendor_ramdisk_size = hdr->vendor_ramdisk_size;
114 data->ramdisk_size += hdr->vendor_ramdisk_size;
115 end += ALIGN(hdr->vendor_ramdisk_size, hdr->page_size);
119 data->dtb_size = hdr->dtb_size;
121 end += ALIGN(hdr->dtb_size, hdr->page_size);
122 end += ALIGN(hdr->vendor_ramdisk_table_size, hdr->page_size);
123 data->bootconfig_addr = end;
124 if (hdr->bootconfig_size) {
125 data->bootconfig_size += add_trailer(data->bootconfig_addr,
126 data->bootconfig_size);
127 data->ramdisk_size += data->bootconfig_size;
129 end += ALIGN(data->bootconfig_size, hdr->page_size);
130 data->vendor_boot_img_total_size = end - (ulong)hdr;
133 static void android_boot_image_v0_v1_v2_parse_hdr(const struct andr_boot_img_hdr_v0 *hdr,
134 struct andr_image_data *data)
138 data->image_name = hdr->name;
139 data->kcmdline = hdr->cmdline;
140 data->kernel_addr = hdr->kernel_addr;
141 data->ramdisk_addr = hdr->ramdisk_addr;
142 data->header_version = hdr->header_version;
143 data->dtb_load_addr = hdr->dtb_addr;
148 * The header takes a full page, the remaining components are aligned
152 end += hdr->page_size;
154 data->kernel_ptr = end;
155 data->kernel_size = hdr->kernel_size;
156 end += ALIGN(hdr->kernel_size, hdr->page_size);
158 data->ramdisk_ptr = end;
159 data->ramdisk_size = hdr->ramdisk_size;
160 end += ALIGN(hdr->ramdisk_size, hdr->page_size);
162 data->second_ptr = end;
163 data->second_size = hdr->second_size;
164 end += ALIGN(hdr->second_size, hdr->page_size);
166 if (hdr->header_version >= 1) {
167 data->recovery_dtbo_ptr = end;
168 data->recovery_dtbo_size = hdr->recovery_dtbo_size;
169 end += ALIGN(hdr->recovery_dtbo_size, hdr->page_size);
172 if (hdr->header_version >= 2) {
174 data->dtb_size = hdr->dtb_size;
175 end += ALIGN(hdr->dtb_size, hdr->page_size);
178 data->boot_img_total_size = end - (ulong)hdr;
181 bool android_image_get_data(const void *boot_hdr, const void *vendor_boot_hdr,
182 struct andr_image_data *data)
184 if (!boot_hdr || !data) {
185 printf("boot_hdr or data params can't be NULL\n");
189 if (!is_android_boot_image_header(boot_hdr)) {
190 printf("Incorrect boot image header\n");
194 if (((struct andr_boot_img_hdr_v0 *)boot_hdr)->header_version > 2) {
195 if (!vendor_boot_hdr) {
196 printf("For boot header v3+ vendor boot image has to be provided\n");
199 if (!is_android_vendor_boot_image_header(vendor_boot_hdr)) {
200 printf("Incorrect vendor boot image header\n");
203 android_boot_image_v3_v4_parse_hdr(boot_hdr, data);
204 android_vendor_boot_image_v3_v4_parse_hdr(vendor_boot_hdr, data);
206 android_boot_image_v0_v1_v2_parse_hdr(boot_hdr, data);
212 static ulong android_image_get_kernel_addr(struct andr_image_data *img_data,
216 * All the Android tools that generate a boot.img use this
217 * address as the default.
219 * Even though it doesn't really make a lot of sense, and it
220 * might be valid on some platforms, we treat that adress as
221 * the default value for this field, and try to execute the
222 * kernel in place in such a case.
224 * Otherwise, we will return the actual value set by the user.
226 if (img_data->kernel_addr == ANDROID_IMAGE_DEFAULT_KERNEL_ADDR) {
227 if (comp == IH_COMP_NONE)
228 return img_data->kernel_ptr;
229 return env_get_ulong("kernel_addr_r", 16, 0);
233 * abootimg creates images where all load addresses are 0
234 * and we need to fix them.
236 if (img_data->kernel_addr == 0 && img_data->ramdisk_addr == 0)
237 return env_get_ulong("kernel_addr_r", 16, 0);
239 return img_data->kernel_addr;
243 * android_image_get_kernel() - processes kernel part of Android boot images
244 * @hdr: Pointer to boot image header, which is at the start
246 * @vendor_boot_img: Pointer to vendor boot image header, which is at the
247 * start of the image.
248 * @verify: Checksum verification flag. Currently unimplemented.
249 * @os_data: Pointer to a ulong variable, will hold os data start
251 * @os_len: Pointer to a ulong variable, will hold os data length.
253 * This function returns the os image's start address and length. Also,
254 * it appends the kernel command line to the bootargs env variable.
256 * Return: Zero, os start address and length on success,
257 * otherwise on failure.
259 int android_image_get_kernel(const void *hdr,
260 const void *vendor_boot_img, int verify,
261 ulong *os_data, ulong *os_len)
263 struct andr_image_data img_data = {0};
265 const struct legacy_img_hdr *ihdr;
268 if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
271 comp = android_image_get_kcomp(hdr, vendor_boot_img);
273 kernel_addr = android_image_get_kernel_addr(&img_data, comp);
274 ihdr = (const struct legacy_img_hdr *)img_data.kernel_ptr;
277 * Not all Android tools use the id field for signing the image with
278 * sha1 (or anything) so we don't check it. It is not obvious that the
279 * string is null terminated so we take care of this.
281 strlcpy(andr_tmp_str, img_data.image_name, ANDR_BOOT_NAME_SIZE);
282 andr_tmp_str[ANDR_BOOT_NAME_SIZE] = '\0';
283 if (strlen(andr_tmp_str))
284 printf("Android's image name: %s\n", andr_tmp_str);
286 printf("Kernel load addr 0x%08lx size %u KiB\n",
287 kernel_addr, DIV_ROUND_UP(img_data.kernel_size, 1024));
290 if (*img_data.kcmdline) {
291 printf("Kernel command line: %s\n", img_data.kcmdline);
292 len += strlen(img_data.kcmdline);
295 if (*img_data.kcmdline_extra) {
296 printf("Kernel extra command line: %s\n", img_data.kcmdline_extra);
297 len += strlen(img_data.kcmdline_extra);
300 char *bootargs = env_get("bootargs");
302 len += strlen(bootargs);
304 char *newbootargs = malloc(len + 2);
306 puts("Error: malloc in android_image_get_kernel failed!\n");
312 strcpy(newbootargs, bootargs);
313 strcat(newbootargs, " ");
316 if (*img_data.kcmdline)
317 strcat(newbootargs, img_data.kcmdline);
319 if (*img_data.kcmdline_extra) {
320 strcat(newbootargs, " ");
321 strcat(newbootargs, img_data.kcmdline_extra);
324 env_set("bootargs", newbootargs);
328 if (image_get_magic(ihdr) == IH_MAGIC) {
329 *os_data = image_get_data(ihdr);
331 *os_data = img_data.kernel_ptr;
335 if (image_get_magic(ihdr) == IH_MAGIC)
336 *os_len = image_get_data_size(ihdr);
338 *os_len = img_data.kernel_size;
343 bool is_android_vendor_boot_image_header(const void *vendor_boot_img)
345 return !memcmp(VENDOR_BOOT_MAGIC, vendor_boot_img, ANDR_VENDOR_BOOT_MAGIC_SIZE);
348 bool is_android_boot_image_header(const void *hdr)
350 return !memcmp(ANDR_BOOT_MAGIC, hdr, ANDR_BOOT_MAGIC_SIZE);
353 ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr,
354 const void *vendor_boot_img)
356 struct andr_image_data img_data;
358 if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
361 if (img_data.header_version > 2)
364 return img_data.boot_img_total_size;
367 ulong android_image_get_kload(const void *hdr,
368 const void *vendor_boot_img)
370 struct andr_image_data img_data;
373 if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
376 comp = android_image_get_kcomp(hdr, vendor_boot_img);
378 return android_image_get_kernel_addr(&img_data, comp);
381 ulong android_image_get_kcomp(const void *hdr,
382 const void *vendor_boot_img)
384 struct andr_image_data img_data;
387 if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
390 p = (const void *)img_data.kernel_ptr;
391 if (image_get_magic((struct legacy_img_hdr *)p) == IH_MAGIC)
392 return image_get_comp((struct legacy_img_hdr *)p);
393 else if (get_unaligned_le32(p) == LZ4F_MAGIC)
396 return image_decomp_type(p, sizeof(u32));
399 int android_image_get_ramdisk(const void *hdr, const void *vendor_boot_img,
400 ulong *rd_data, ulong *rd_len)
402 struct andr_image_data img_data = {0};
405 if (!android_image_get_data(hdr, vendor_boot_img, &img_data))
408 if (!img_data.ramdisk_size)
411 * Android tools can generate a boot.img with default load address
412 * or 0, even though it doesn't really make a lot of sense, and it
413 * might be valid on some platforms, we treat that address as
414 * the default value for this field, and try to pass ramdisk
415 * in place if possible.
417 if (img_data.header_version > 2) {
418 /* Ramdisk can't be used in-place, copy it to ramdisk_addr_r */
419 if (img_data.ramdisk_addr == ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR) {
420 ramdisk_ptr = env_get_ulong("ramdisk_addr_r", 16, 0);
422 printf("Invalid ramdisk_addr_r to copy ramdisk into\n");
426 ramdisk_ptr = img_data.ramdisk_addr;
428 *rd_data = ramdisk_ptr;
429 memcpy((void *)(ramdisk_ptr), (void *)img_data.vendor_ramdisk_ptr,
430 img_data.vendor_ramdisk_size);
431 ramdisk_ptr += img_data.vendor_ramdisk_size;
432 memcpy((void *)(ramdisk_ptr), (void *)img_data.ramdisk_ptr,
433 img_data.boot_ramdisk_size);
434 ramdisk_ptr += img_data.boot_ramdisk_size;
435 if (img_data.bootconfig_size) {
437 (ramdisk_ptr), (void *)img_data.bootconfig_addr,
438 img_data.bootconfig_size);
441 /* Ramdisk can be used in-place, use current ptr */
442 if (img_data.ramdisk_addr == 0 ||
443 img_data.ramdisk_addr == ANDROID_IMAGE_DEFAULT_RAMDISK_ADDR) {
444 *rd_data = img_data.ramdisk_ptr;
446 ramdisk_ptr = img_data.ramdisk_addr;
447 *rd_data = ramdisk_ptr;
448 memcpy((void *)(ramdisk_ptr), (void *)img_data.ramdisk_ptr,
449 img_data.ramdisk_size);
453 printf("RAM disk load addr 0x%08lx size %u KiB\n",
454 *rd_data, DIV_ROUND_UP(img_data.ramdisk_size, 1024));
456 *rd_len = img_data.ramdisk_size;
460 int android_image_get_second(const void *hdr, ulong *second_data, ulong *second_len)
462 struct andr_image_data img_data;
464 if (!android_image_get_data(hdr, NULL, &img_data))
467 if (img_data.header_version > 2) {
468 printf("Second stage bootloader is only supported for boot image version <= 2\n");
472 if (!img_data.second_size) {
473 *second_data = *second_len = 0;
477 *second_data = img_data.second_ptr;
479 printf("second address is 0x%lx\n",*second_data);
481 *second_len = img_data.second_size;
486 * android_image_get_dtbo() - Get address and size of recovery DTBO image.
487 * @hdr_addr: Boot image header address
488 * @addr: If not NULL, will contain address of recovery DTBO image
489 * @size: If not NULL, will contain size of recovery DTBO image
491 * Get the address and size of DTBO image in "Recovery DTBO" area of Android
492 * Boot Image in RAM. The format of this image is Android DTBO (see
493 * corresponding "DTB/DTBO Partitions" AOSP documentation for details). Once
494 * the address is obtained from this function, one can use 'adtimg' U-Boot
495 * command or android_dt_*() functions to extract desired DTBO blob.
497 * This DTBO (included in boot image) is only needed for non-A/B devices, and it
498 * only can be found in recovery image. On A/B devices we can always rely on
499 * "dtbo" partition. See "Including DTBO in Recovery for Non-A/B Devices" in
500 * AOSP documentation for details.
502 * Return: true on success or false on error.
504 bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size)
506 const struct andr_boot_img_hdr_v0 *hdr;
510 hdr = map_sysmem(hdr_addr, sizeof(*hdr));
511 if (!is_android_boot_image_header(hdr)) {
512 printf("Error: Boot Image header is incorrect\n");
517 if (hdr->header_version != 1 && hdr->header_version != 2) {
518 printf("Error: header version must be >= 1 and <= 2 to get dtbo\n");
523 if (hdr->recovery_dtbo_size == 0) {
524 printf("Error: recovery_dtbo_size is 0\n");
529 /* Calculate the address of DTB area in boot image */
530 dtbo_img_addr = hdr_addr;
531 dtbo_img_addr += hdr->page_size;
532 dtbo_img_addr += ALIGN(hdr->kernel_size, hdr->page_size);
533 dtbo_img_addr += ALIGN(hdr->ramdisk_size, hdr->page_size);
534 dtbo_img_addr += ALIGN(hdr->second_size, hdr->page_size);
537 *addr = dtbo_img_addr;
539 *size = hdr->recovery_dtbo_size;
547 * android_image_get_dtb_img_addr() - Get the address of DTB area in boot image.
548 * @hdr_addr: Boot image header address
549 * @vhdr_addr: Vendor Boot image header address
550 * @addr: Will contain the address of DTB area in boot image
552 * Return: true on success or false on fail.
554 static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong vhdr_addr, ulong *addr)
556 const struct andr_boot_img_hdr_v0 *hdr;
557 const struct andr_vnd_boot_img_hdr *v_hdr;
561 hdr = map_sysmem(hdr_addr, sizeof(*hdr));
562 if (!is_android_boot_image_header(hdr)) {
563 printf("Error: Boot Image header is incorrect\n");
568 if (hdr->header_version < 2) {
569 printf("Error: header_version must be >= 2 to get dtb\n");
574 if (hdr->header_version == 2) {
575 if (!hdr->dtb_size) {
576 printf("Error: dtb_size is 0\n");
580 /* Calculate the address of DTB area in boot image */
581 dtb_img_addr = hdr_addr;
582 dtb_img_addr += hdr->page_size;
583 dtb_img_addr += ALIGN(hdr->kernel_size, hdr->page_size);
584 dtb_img_addr += ALIGN(hdr->ramdisk_size, hdr->page_size);
585 dtb_img_addr += ALIGN(hdr->second_size, hdr->page_size);
586 dtb_img_addr += ALIGN(hdr->recovery_dtbo_size, hdr->page_size);
588 *addr = dtb_img_addr;
591 if (hdr->header_version > 2) {
592 v_hdr = map_sysmem(vhdr_addr, sizeof(*v_hdr));
593 if (!v_hdr->dtb_size) {
594 printf("Error: dtb_size is 0\n");
599 /* Calculate the address of DTB area in boot image */
600 dtb_img_addr = vhdr_addr;
601 dtb_img_addr += v_hdr->page_size;
602 if (v_hdr->vendor_ramdisk_size)
603 dtb_img_addr += ALIGN(v_hdr->vendor_ramdisk_size, v_hdr->page_size);
604 *addr = dtb_img_addr;
614 * android_image_get_dtb_by_index() - Get address and size of blob in DTB area.
615 * @hdr_addr: Boot image header address
616 * @vendor_boot_img: Pointer to vendor boot image header, which is at the start of the image.
617 * @index: Index of desired DTB in DTB area (starting from 0)
618 * @addr: If not NULL, will contain address to specified DTB
619 * @size: If not NULL, will contain size of specified DTB
621 * Get the address and size of DTB blob by its index in DTB area of Android
624 * Return: true on success or false on error.
626 bool android_image_get_dtb_by_index(ulong hdr_addr, ulong vendor_boot_img,
627 u32 index, ulong *addr, u32 *size)
629 struct andr_image_data img_data;
630 const struct andr_boot_img_hdr_v0 *hdr;
631 const struct andr_vnd_boot_img_hdr *vhdr;
633 hdr = map_sysmem(hdr_addr, sizeof(*hdr));
634 if (vendor_boot_img != -1)
635 vhdr = map_sysmem(vendor_boot_img, sizeof(*vhdr));
636 if (!android_image_get_data(hdr, vhdr, &img_data)) {
637 if (vendor_boot_img != -1)
642 if (vendor_boot_img != -1)
646 ulong dtb_img_addr; /* address of DTB part in boot image */
647 u32 dtb_img_size; /* size of DTB payload in boot image */
648 ulong dtb_addr; /* address of DTB blob with specified index */
649 u32 i; /* index iterator */
651 android_image_get_dtb_img_addr(hdr_addr, vendor_boot_img, &dtb_img_addr);
652 /* Check if DTB area of boot image is in DTBO format */
653 if (android_dt_check_header(dtb_img_addr)) {
654 return android_dt_get_fdt_by_index(dtb_img_addr, index, addr,
658 /* Find out the address of DTB with specified index in concat blobs */
659 dtb_img_size = img_data.dtb_size;
661 dtb_addr = dtb_img_addr;
662 while (dtb_addr < dtb_img_addr + dtb_img_size) {
663 const struct fdt_header *fdt;
666 fdt = map_sysmem(dtb_addr, sizeof(*fdt));
667 if (fdt_check_header(fdt) != 0) {
669 printf("Error: Invalid FDT header for index %u\n", i);
673 dtb_size = fdt_totalsize(fdt);
684 dtb_addr += dtb_size;
688 printf("Error: Index is out of bounds (%u/%u)\n", index, i);
692 #if !defined(CONFIG_XPL_BUILD)
694 * android_print_contents - prints out the contents of the Android format image
695 * @hdr: pointer to the Android format image header
697 * android_print_contents() formats a multi line Android image contents
699 * The routine prints out Android image properties
702 * no returned results
704 void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr)
706 if (hdr->header_version >= 3) {
707 printf("Content print is not supported for boot image header version > 2");
710 const char * const p = IMAGE_INDENT_STRING;
711 /* os_version = ver << 11 | lvl */
712 u32 os_ver = hdr->os_version >> 11;
713 u32 os_lvl = hdr->os_version & ((1U << 11) - 1);
715 printf("%skernel size: %x\n", p, hdr->kernel_size);
716 printf("%skernel address: %x\n", p, hdr->kernel_addr);
717 printf("%sramdisk size: %x\n", p, hdr->ramdisk_size);
718 printf("%sramdisk address: %x\n", p, hdr->ramdisk_addr);
719 printf("%ssecond size: %x\n", p, hdr->second_size);
720 printf("%ssecond address: %x\n", p, hdr->second_addr);
721 printf("%stags address: %x\n", p, hdr->tags_addr);
722 printf("%spage size: %x\n", p, hdr->page_size);
723 /* ver = A << 14 | B << 7 | C (7 bits for each of A, B, C)
724 * lvl = ((Y - 2000) & 127) << 4 | M (7 bits for Y, 4 bits for M) */
725 printf("%sos_version: %x (ver: %u.%u.%u, level: %u.%u)\n",
727 (os_ver >> 7) & 0x7F, (os_ver >> 14) & 0x7F, os_ver & 0x7F,
728 (os_lvl >> 4) + 2000, os_lvl & 0x0F);
729 printf("%sname: %s\n", p, hdr->name);
730 printf("%scmdline: %s\n", p, hdr->cmdline);
731 printf("%sheader_version: %d\n", p, hdr->header_version);
733 if (hdr->header_version >= 1) {
734 printf("%srecovery dtbo size: %x\n", p,
735 hdr->recovery_dtbo_size);
736 printf("%srecovery dtbo offset: %llx\n", p,
737 hdr->recovery_dtbo_offset);
738 printf("%sheader size: %x\n", p,
742 if (hdr->header_version == 2) {
743 printf("%sdtb size: %x\n", p, hdr->dtb_size);
744 printf("%sdtb addr: %llx\n", p, hdr->dtb_addr);
749 * android_image_print_dtb_info - Print info for one DTB blob in DTB area.
751 * @index: Number of DTB blob in DTB area.
753 * Return: true on success or false on error.
755 static bool android_image_print_dtb_info(const struct fdt_header *fdt,
761 const char *compatible;
763 root_node_off = fdt_path_offset(fdt, "/");
764 if (root_node_off < 0) {
765 printf("Error: Root node not found\n");
769 fdt_size = fdt_totalsize(fdt);
770 compatible = fdt_getprop(fdt, root_node_off, "compatible",
772 model = fdt_getprop(fdt, root_node_off, "model", NULL);
774 printf(" - DTB #%u:\n", index);
775 printf(" (DTB)size = %d\n", fdt_size);
776 printf(" (DTB)model = %s\n", model ? model : "(unknown)");
777 printf(" (DTB)compatible = %s\n",
778 compatible ? compatible : "(unknown)");
784 * android_image_print_dtb_contents() - Print info for DTB blobs in DTB area.
785 * @hdr_addr: Boot image header address
787 * DTB payload in Android Boot Image v2+ can be in one of following formats:
788 * 1. Concatenated DTB blobs
789 * 2. Android DTBO format (see CONFIG_CMD_ADTIMG for details)
791 * This function does next:
792 * 1. Prints out the format used in DTB area
793 * 2. Iterates over all DTB blobs in DTB area and prints out the info for
796 * Return: true on success or false on error.
798 bool android_image_print_dtb_contents(ulong hdr_addr)
800 const struct andr_boot_img_hdr_v0 *hdr;
802 ulong dtb_img_addr; /* address of DTB part in boot image */
803 u32 dtb_img_size; /* size of DTB payload in boot image */
804 ulong dtb_addr; /* address of DTB blob with specified index */
805 u32 i; /* index iterator */
807 res = android_image_get_dtb_img_addr(hdr_addr, 0, &dtb_img_addr);
811 /* Check if DTB area of boot image is in DTBO format */
812 if (android_dt_check_header(dtb_img_addr)) {
813 printf("## DTB area contents (DTBO format):\n");
814 android_dt_print_contents(dtb_img_addr);
818 printf("## DTB area contents (concat format):\n");
820 /* Iterate over concatenated DTB blobs */
821 hdr = map_sysmem(hdr_addr, sizeof(*hdr));
822 dtb_img_size = hdr->dtb_size;
825 dtb_addr = dtb_img_addr;
826 while (dtb_addr < dtb_img_addr + dtb_img_size) {
827 const struct fdt_header *fdt;
830 fdt = map_sysmem(dtb_addr, sizeof(*fdt));
831 if (fdt_check_header(fdt) != 0) {
833 printf("Error: Invalid FDT header for index %u\n", i);
837 res = android_image_print_dtb_info(fdt, i);
843 dtb_size = fdt_totalsize(fdt);
845 dtb_addr += dtb_size;