
So far the tool could only assemble imx8 images but not show anything about the content Signed-off-by: Ludwig Nussel <ludwig.nussel@siemens.com> --- tools/imx8image.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/tools/imx8image.c b/tools/imx8image.c index 5a76643c06e..758bd570455 100644 --- a/tools/imx8image.c +++ b/tools/imx8image.c @@ -33,8 +33,97 @@ static void imx8image_set_header(void *ptr, struct stat *sbuf, int ifd, { } +static int imx8image_verify_header(unsigned char *ptr, int image_size, + struct image_tool_params *params) +{ + flash_header_v3_t *header = (flash_header_v3_t *) ptr; + + if (header->tag == IVT_HEADER_TAG_B0 && + header->version == IVT_VERSION_B0 && + header->num_images) + return 0; + + return 1; +} + +static void imx8image_print_flash_header_v3(const flash_header_v3_t *header, + struct image_tool_params *params) +{ + static const char * const img_type_table[8] = { + "?", "CSF", "SCD", "EXEC", "DATA", "DCD_DDR", "SECO", "SENTINEL" }; + static const char * const core_table[8] = { + "?", "SC", "CM4_0", "CM4_1", "CA35/CA53", "CA72", "SECO", "?" }; + + printf(" Version: 0x%02x\n" + " Length: 0x%04x\n" + " Tag: 0x%02x\n" + " Flags: 0x%08x\n" + " SW Version: 0x%04x\n" + " Fuse Version 0x%02x\n" + " Num Images: %4u\n" + " Sig Blk Offset: %4u\n", + header->version, + le16_to_cpu(header->length), + header->tag, + header->flags, + header->sw_version, + header->fuse_version, + header->num_images, + header->sig_blk_offset + ); + + for (int i = 0; i < header->num_images; ++i) { + const boot_img_t* h = &header->img[i]; + printf(" Image #%d\n" + " Offset: 0x%08x\n" + " Size: 0x%08x\n" + " Dst: 0x%016" PRIx64 "\n" + " Entry: 0x%016" PRIx64 "\n" + " HAB Flags: 0x%08x\n" + " Image Type: %10s\n" + " Core: %10s\n" + " Meta: 0x%08x\n" + " Hash: 0x%02x%02x%02x..\n" + " IV: 0x%02x%02x%02x..\n", + i, + le32_to_cpu(h->offset), + le32_to_cpu(h->size), + le64_to_cpu(h->dst), + le64_to_cpu(h->entry), + le32_to_cpu(h->hab_flags), + img_type_table[h->hab_flags & 0x7], + core_table[(h->hab_flags >> BOOT_IMG_FLAGS_CORE_SHIFT) & BOOT_IMG_FLAGS_CORE_MASK], + le32_to_cpu(h->meta), + h->hash[0], h->hash[1], h->hash[2], + h->iv[0], h->iv[1], h->iv[2] + ); + } + printf(" Signature\n" + " Version: 0x%02x\n" + " Length: 0x%04x\n" + " Tag: 0x%02x\n" + " SRK Offset: 0x%04x\n" + " Cert Offset: 0x%04x\n" + " Blob Offset: 0x%04x\n" + " Sig Offset: 0x%04x\n", + header->sig_blk_hdr.version, + header->sig_blk_hdr.length, + header->sig_blk_hdr.tag, + header->sig_blk_hdr.srk_table_offset, + header->sig_blk_hdr.cert_offset, + header->sig_blk_hdr.blob_offset, + header->sig_blk_hdr.signature_offset + ); +} + static void imx8image_print_header(const void *ptr, struct image_tool_params *params) { + printf("Container #0:\n"); + imx8image_print_flash_header_v3(ptr, params); + if (imx8image_verify_header((void *)ptr + 0x400, 0, 0) == 0) { + printf("Container #1:\n"); + imx8image_print_flash_header_v3(ptr + 0x400, params); + } } static int imx8image_check_image_types(uint8_t type) @@ -571,7 +660,7 @@ static void set_image_hash(boot_img_t *img, char *filename, uint32_t hash_type) } for (i = 0; i < strlen(hash) / 2; i++) { - ret = sscanf(hash + 2 * i, "%02hhx", &img->hash[i]); + ret = sscanf(hash + 2 * i, "%02x", &img->hash[i]); if (ret < 0) { fprintf(stderr, "Failed sscanf hash: %d\n", ret); exit(EXIT_FAILURE); @@ -1191,7 +1280,7 @@ U_BOOT_IMAGE_TYPE( 0, NULL, imx8image_check_params, - NULL, + imx8image_verify_header, imx8image_print_header, imx8image_set_header, NULL, -- 2.34.1