tools/imximage: get HAB information from header
authorHolger Dengler <dengler@linutronix.de>
Fri, 6 Jul 2018 14:10:00 +0000 (16:10 +0200)
committerStefano Babic <sbabic@denx.de>
Mon, 23 Jul 2018 09:04:22 +0000 (11:04 +0200)
Signing parts of a u-boot imximage for image verification in High
Assurance Boot (HAB) in a post-build process, requires some
information from the imximage header. Currently, this information is
only provided during the image build, which makes the transfer of this
information to the post-build process harder than necessary.

The i.MX HAB information (start and length) can be calculated either
by using information from the image-configuration file, or from the
information in the flash header of the imximage.
The advantage of using information from flash header is, that they are
not only available during image creation, but also available if
existing images are processed.

Example:
$ tools/mkimage -l u-boot.imx
Image Type:   Freescale IMX Boot Image
Image Ver:    2 (i.MX53/6/7 compatible)
Mode:         DCD
Data Size:    483328 Bytes = 472.00 KiB = 0.46 MiB
Load Address: 877ff420
Entry Point:  87800000
HAB Blocks:   0x877ff400 0x00000000 0x00071c00
DCD Blocks:   0x00910000 0x0000002c 0x00000208

Signed-off-by: Holger Dengler <dengler@linutronix.de>
Tested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
tools/imximage.c

index 5f63bf875945b9b8ddc850a6cb0736cbe1413165..d7c0b6e883f7c8e3d5449227d77da5f0e325e035 100644 (file)
@@ -506,8 +506,7 @@ static void print_hdr_v2(struct imx_header *imx_hdr)
                genimg_print_size(hdr_v2->boot_data.size);
                printf("Load Address: %08x\n", (uint32_t)fhdr_v2->boot_data_ptr);
                printf("Entry Point:  %08x\n", (uint32_t)fhdr_v2->entry);
-               if (fhdr_v2->csf && (imximage_ivt_offset != UNDEFINED) &&
-                   (imximage_csf_size != UNDEFINED)) {
+               if (fhdr_v2->csf) {
                        uint16_t dcdlen;
                        int offs;
 
@@ -515,10 +514,16 @@ static void print_hdr_v2(struct imx_header *imx_hdr)
                        offs = (char *)&hdr_v2->data.dcd_table
                                - (char *)hdr_v2;
 
+                       /*
+                        * The HAB block is the first part of the image, from
+                        * start of IVT header (fhdr_v2->self) to the start of
+                        * the CSF block (fhdr_v2->csf). So HAB size is
+                        * calculated as:
+                        * HAB_size = fhdr_v2->csf - fhdr_v2->self
+                        */
                        printf("HAB Blocks:   0x%08x 0x%08x 0x%08x\n",
                               (uint32_t)fhdr_v2->self, 0,
-                              hdr_v2->boot_data.size - imximage_ivt_offset -
-                              imximage_csf_size);
+                              (uint32_t)(fhdr_v2->csf - fhdr_v2->self));
                        printf("DCD Blocks:   0x00910000 0x%08x 0x%08x\n",
                               offs, be16_to_cpu(dcdlen));
                }