[U-Boot] Issues about u-boot tools (mkimage and dumpimage)

Sun,Mingshen sunmingshen at baidu.com
Fri Aug 4 22:30:57 UTC 2017


Hi all,

I am working on a project related to secure boot. We are using NXP’s iMX7d development board.

I am using `make –j32 V=1` to verbosely print build commands. The last command for making u-boot is `./tools/mkimage -n board/freescale/mx7dsabresd/imximage.cfg.cfgtmp -T imximage -e 0x87800000 -d u-boot-dtb.bin u-boot-dtb.imx`. Then it will print out the image header imformation like this:

```
Image Type:   Freescale IMX Boot Image
Image Ver:    2 (i.MX53/6/7 compatible)
Mode:         DCD
Data Size:    561152 Bytes = 548.00 KiB = 0.54 MiB
Load Address: 877ff420
Entry Point:  87800000
HAB Blocks:   877ff400 00000000 00086c00
DCD Blocks:   00910000 0000002c 000001b4
```

The last two lines about “HAB” and “DCD” are special header fields for this type of board because of secure boot (i.e., high assurance boot).

I’d like to later examine the values of HAB Blocks. I found `dumpimage` tools can print the header of built image.

However, it will report segmentation fault. After spending some time to understand the code. I found it’s caused by `imximage_check_params()` function which requires a non-null `imagename` in `prams`.

I tried to fix this issue. However, the dumpimage tool still cannot dump “HAB Blocks” information in the header. The reason is that the `print_header()` functions of `imximage` type needs a configuration file which located in "board/freescale/mx7dsabresd/imximage.cfg.cfgtmp" for my board. Again, I tried to fix it, but failed. Because the `print_header()` function only accept one parameter which is header and this is a unified function among all types of board. I cannot change the definition of it.

In a nutshell, there are two issues with the code related with imximage type:
  1. The mkimage tool *misuses* “-n” (i.e., image name) flag to pass an image configuration file path.
  2. The dumpimage tool cannot dump the “HAB” header information due to the *lack* of the imx image configuration file.

Here is my temporary workaround patch for imx board:
```
diff --git a/tools/dumpimage.c b/tools/dumpimage.c
index 75a5d47..ad67f22 100644
--- a/tools/dumpimage.c
+++ b/tools/dumpimage.c
@@ -15,6 +15,7 @@ static void usage(void);
/* parameters initialized by core will be used by the image type code */
static struct image_tool_params params = {
        .type = IH_TYPE_KERNEL,
+       .imagename = "board/freescale/mx7dsabresd/imximage.cfg.cfgtmp",
};

/*
diff --git a/tools/imximage.c b/tools/imximage.c
index eb7e682..e495345 100644
--- a/tools/imximage.c
+++ b/tools/imximage.c
@@ -810,6 +810,21 @@ static void imximage_print_header(const void *ptr)
        struct imx_header *imx_hdr = (struct imx_header *) ptr;
        uint32_t version = detect_imximage_version(imx_hdr);

+       memset(&imximage_header, 0, sizeof(imximage_header));
+       /*
+        * In order to not change the old imx cfg file
+        * by adding VERSION command into it, here need
+        * set up function ptr group to V1 by default.
+        */
+       imximage_version = IMXIMAGE_V1;
+       /* Be able to detect if the cfg file has no BOOT_FROM tag */
+       imximage_ivt_offset = FLASH_OFFSET_UNDEFINED;
+       imximage_csf_size = 0;
+       set_hdr_func();
+
+       /* Parse dcd configuration file */
+       parse_cfg_file(&imximage_header, "board/freescale/mx7dsabresd/imximage.cfg.cfgtmp");
+
        switch (version) {
        case IMXIMAGE_V1:
                print_hdr_v1(imx_hdr);
```

Is there any suggestion for me to contribute patches to the mainstream code in order to permanently fix above issues. Thank you.

Best,
Mingshen



More information about the U-Boot mailing list