]> Git Repo - J-u-boot.git/blobdiff - tools/fit_image.c
configs: stm32mp1: Restore boot SPL from sdcard for Engicam i.Core STM32MP1 EDIMM2.2
[J-u-boot.git] / tools / fit_image.c
index 9fe69ea0d9f8e682be6980b7a8dacf03d07f8238..0fccfbb4ebda47f6a43f21b6a4e4064797597d13 100644 (file)
@@ -61,7 +61,7 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc,
                ret = fit_set_timestamp(ptr, 0, time);
        }
 
-       if (!ret)
+       if (CONFIG_IS_ENABLED(FIT_SIGNATURE) && !ret)
                ret = fit_pre_load_data(params->keydir, dest_blob, ptr);
 
        if (!ret) {
@@ -137,7 +137,7 @@ static int fdt_property_file(struct image_tool_params *params,
        int ret;
        int fd;
 
-       fd = open(fname, O_RDWR | O_BINARY);
+       fd = open(fname, O_RDONLY | O_BINARY);
        if (fd < 0) {
                fprintf(stderr, "%s: Can't open %s: %s\n",
                        params->cmdname, fname, strerror(errno));
@@ -497,7 +497,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 {
        void *buf = NULL;
        int buf_ptr;
-       int fit_size, new_size;
+       int fit_size, unpadded_size, new_size, pad_boundary;
        int fd;
        struct stat sbuf;
        void *fdt;
@@ -564,9 +564,13 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
        /* Pack the FDT and place the data after it */
        fdt_pack(fdt);
 
-       new_size = fdt_totalsize(fdt);
-       new_size = ALIGN(new_size, align_size);
+       unpadded_size = fdt_totalsize(fdt);
+       new_size = ALIGN(unpadded_size, align_size);
        fdt_set_totalsize(fdt, new_size);
+       if (unpadded_size < fit_size) {
+               pad_boundary = new_size < fit_size ? new_size : fit_size;
+               memset(fdt + unpadded_size, 0, pad_boundary - unpadded_size);
+       }
        debug("Size reduced from %x to %x\n", fit_size, fdt_totalsize(fdt));
        debug("External data size %x\n", buf_ptr);
        munmap(fdt, sbuf.st_size);
@@ -616,6 +620,8 @@ err:
 static int fit_import_data(struct image_tool_params *params, const char *fname)
 {
        void *fdt, *old_fdt;
+       void *data = NULL;
+       const char *ext_data_prop = NULL;
        int fit_size, new_size, size, data_base;
        int fd;
        struct stat sbuf;
@@ -659,14 +665,28 @@ static int fit_import_data(struct image_tool_params *params, const char *fname)
                int buf_ptr;
                int len;
 
-               buf_ptr = fdtdec_get_int(fdt, node, "data-offset", -1);
-               len = fdtdec_get_int(fdt, node, "data-size", -1);
-               if (buf_ptr == -1 || len == -1)
+               /*
+                * FIT_DATA_OFFSET_PROP and FIT_DATA_POSITION_PROP are never both present,
+                *  but if they are, prefer FIT_DATA_OFFSET_PROP as it was there first
+                */
+               buf_ptr = fdtdec_get_int(fdt, node, FIT_DATA_POSITION_PROP, -1);
+               if (buf_ptr != -1) {
+                       ext_data_prop = FIT_DATA_POSITION_PROP;
+                       data = old_fdt + buf_ptr;
+               }
+               buf_ptr = fdtdec_get_int(fdt, node, FIT_DATA_OFFSET_PROP, -1);
+               if (buf_ptr != -1) {
+                       ext_data_prop = FIT_DATA_OFFSET_PROP;
+                       data = old_fdt + data_base + buf_ptr;
+               }
+               len = fdtdec_get_int(fdt, node, FIT_DATA_SIZE_PROP, -1);
+               if (!data || len == -1)
                        continue;
                debug("Importing data size %x\n", len);
 
-               ret = fdt_setprop(fdt, node, "data",
-                                 old_fdt + data_base + buf_ptr, len);
+               ret = fdt_setprop(fdt, node, FIT_DATA_PROP, data, len);
+               ret = fdt_delprop(fdt, node, ext_data_prop);
+
                if (ret) {
                        debug("%s: Failed to write property: %s\n", __func__,
                              fdt_strerror(ret));
This page took 0.024354 seconds and 4 git commands to generate.