From: Matthias Zoechmann <[email protected]>

If an image is loaded by serial download protocol with DCD_WRITE ROM
command on closed i.mx6 devices, the DCD table block loaded into the
OCRAM must be signed.
This patch adds the option '-a' to apply the additional authentication
block for the OCRAM section into the CSF.
The load address for the block is fixed to '0x00910000' which is the
default address configured in mfg-tools of NXP.

Signed-off-by: Matthias Zoechmann <[email protected]>
---
 include/mach/imx/imx-header.h |  2 ++
 scripts/imx/imx-image.c       | 19 ++++++++++++++++++-
 scripts/imx/imx.c             | 22 ++++++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/include/mach/imx/imx-header.h b/include/mach/imx/imx-header.h
index 
08329e3d056171ff1b4b5d9399f68fb8e0387f77..e8ead33a9ead4024da63574a71afc96923d54671
 100644
--- a/include/mach/imx/imx-header.h
+++ b/include/mach/imx/imx-header.h
@@ -115,6 +115,7 @@ struct config_data {
        int (*write_mem)(const struct config_data *data, uint32_t addr,
                         uint32_t val, int width, int set_bits, int clear_bits);
        int (*nop)(const struct config_data *data);
+       int (*get_dcd_length)(void);
        char *csf;
        char *flexspi_csf;
        int sign_image;
@@ -122,6 +123,7 @@ struct config_data {
        int encrypt_image;
        size_t dek_size;
        bool hab_qspi_support;
+       bool dcd_usb_image;
 };
 
 #define MAX_RECORDS_DCD_V2 1024
diff --git a/scripts/imx/imx-image.c b/scripts/imx/imx-image.c
index 
a8ac34091fc0811ad76064b178416056a02ea2c9..c08857a6157e92ae7cb4a395a618b3eaeaedae9f
 100644
--- a/scripts/imx/imx-image.c
+++ b/scripts/imx/imx-image.c
@@ -495,6 +495,9 @@ static void usage(const char *prgname)
                "             variable 'CST'\n"
                "-u           create USB image suitable for imx-usb-loader\n"
                "             necessary for signed images (-s) only\n"
+               "-a           authenticate additionaly the DCD block loaded 
via\n"
+               "             'SDP: DCD_WRITE' to the internal RAM on i.mx6 
devices\n"
+               "             necessary for usb images (-u) only\n"
                "-h           this help\n", prgname);
        exit(1);
 }
@@ -662,6 +665,11 @@ static int nop(const struct config_data *data)
        }
 }
 
+static int get_dcd_length(void)
+{
+       return sizeof(uint32_t) + (curdcd * sizeof(uint32_t));
+}
+
 /*
  * This uses the Freescale Code Signing Tool (CST) to sign the image.
  * The cst is expected to be executable as 'cst' or if exists, the content
@@ -875,6 +883,7 @@ int main(int argc, char *argv[])
                .write_mem = write_mem,
                .check = check,
                .nop = nop,
+               .get_dcd_length = get_dcd_length
        };
        uint32_t *bb_header;
        size_t sizeof_bb_header;
@@ -883,7 +892,7 @@ int main(int argc, char *argv[])
 
        prgname = argv[0];
 
-       while ((opt = getopt(argc, argv, "c:hf:o:p:bduse")) != -1) {
+       while ((opt = getopt(argc, argv, "c:hf:o:p:bduase")) != -1) {
                switch (opt) {
                case 'c':
                        configfile = optarg;
@@ -909,6 +918,9 @@ int main(int argc, char *argv[])
                case 'u':
                        create_usb_image = true;
                        break;
+               case 'a':
+                       data.dcd_usb_image = true;
+                       break;
                case 'e':
                        data.encrypt_image = 1;
                        break;
@@ -969,6 +981,11 @@ int main(int argc, char *argv[])
                create_usb_image = 0;
        }
 
+       if (data.dcd_usb_image && !create_usb_image) {
+               fprintf(stderr, "Warning: the -a option only has effect with 
usb images\n");
+               data.dcd_usb_image = false;
+       }
+
        if (data.image_ivt_offset == 0xffffffff) {
                if (create_usb_image)
                        data.image_ivt_offset = 0x0;
diff --git a/scripts/imx/imx.c b/scripts/imx/imx.c
index 
6dabaf59c159b582dfe84eff81cec039c4863b77..26efe6d813dca5ecc7b2a06459df2b2f26673e0f
 100644
--- a/scripts/imx/imx.c
+++ b/scripts/imx/imx.c
@@ -430,6 +430,28 @@ static int do_hab_blocks(struct config_data *data, int 
argc, char *argv[])
                ret = asprintf(&str, "Blocks = 0x%08x 0x%08x 0x%08x \"%s\"",
                        data->image_load_addr + data->image_ivt_offset, offset,
                        signed_size - data->image_ivt_offset, data->outfile);
+
+               if (data->dcd_usb_image && (data->cpu_type == IMX_CPU_IMX6)) {
+                       char *str_dcd_blk;
+                       uint32_t dcd_offset = offset + offsetof(struct 
imx_flash_header_v2, dcd_header);
+                       uint32_t dcd_length = data->get_dcd_length();
+
+                       if(!dcd_length) {
+                               fprintf(stderr, "failed to get dcd length\n");
+                               return -EINVAL;
+                       }
+
+                       ret |= asprintf(&str_dcd_blk, ", \\\n 0x00910000 0x%08x 
0x%08x \"%s\"",
+                               dcd_offset, dcd_length, data->outfile);
+
+                       str = strcata(str, str_dcd_blk);
+                       free(str_dcd_blk);
+
+                       if(!str) {
+                               return -ENOMEM;
+                       }
+               }
+
                if (data->flexspi_csf)
                        ret |= asprintf(&flexspi_str,
                                        "Blocks = 0x%08x 0x%08x 0x%08x \"%s\"",

-- 
2.47.2


Reply via email to