X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=tools%2Ffit_image.c;h=4dc8bd8862454598d1bf5383b259707a06cfccba;hb=37d108b64fabc625ae829bc6ee419c163d523c3b;hp=9d553d10fb8e72e41eb46d05bcb9466db8a731e3;hpb=7b0bbd886d553c3cffc5b3eb29256b05856076ee;p=u-boot diff --git a/tools/fit_image.c b/tools/fit_image.c index 9d553d10fb..4dc8bd8862 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -51,13 +51,16 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc, } /* for first image creation, add a timestamp at offset 0 i.e., root */ - if (params->datafile) - ret = fit_set_timestamp(ptr, 0, sbuf.st_mtime); + if (params->datafile) { + time_t time = imagetool_get_source_date(params, sbuf.st_mtime); + ret = fit_set_timestamp(ptr, 0, time); + } if (!ret) { ret = fit_add_verification_data(params->keydir, dest_blob, ptr, params->comment, - params->require_keys); + params->require_keys, + params->engine_id); } if (dest_blob) { @@ -83,8 +86,15 @@ static int fit_calc_size(struct image_tool_params *params) size = imagetool_get_filesize(params, params->datafile); if (size < 0) return -1; - total_size = size; + + if (params->fit_ramdisk) { + size = imagetool_get_filesize(params, params->fit_ramdisk); + if (size < 0) + return -1; + total_size += size; + } + for (cont = params->content_head; cont; cont = cont->next) { size = imagetool_get_filesize(params, cont->fname); if (size < 0) @@ -123,13 +133,14 @@ static int fdt_property_file(struct image_tool_params *params, ret = fdt_property_placeholder(fdt, "data", sbuf.st_size, &ptr); if (ret) - return ret; + goto err; ret = read(fd, ptr, sbuf.st_size); if (ret != sbuf.st_size) { fprintf(stderr, "%s: Can't read %s: %s\n", params->cmdname, fname, strerror(errno)); goto err; } + close(fd); return 0; err: @@ -192,7 +203,8 @@ static int fit_write_images(struct image_tool_params *params, char *fdt) fdt_begin_node(fdt, str); fdt_property_string(fdt, "description", params->imagename); fdt_property_string(fdt, "type", typename); - fdt_property_string(fdt, "arch", genimg_get_arch_name(params->arch)); + fdt_property_string(fdt, "arch", + genimg_get_arch_short_name(params->arch)); fdt_property_string(fdt, "os", genimg_get_os_short_name(params->os)); fdt_property_string(fdt, "compression", genimg_get_comp_short_name(params->comp)); @@ -229,6 +241,20 @@ static int fit_write_images(struct image_tool_params *params, char *fdt) fdt_end_node(fdt); } + /* And a ramdisk file if available */ + if (params->fit_ramdisk) { + fdt_begin_node(fdt, FIT_RAMDISK_PROP "@1"); + + fdt_property_string(fdt, "type", FIT_RAMDISK_PROP); + fdt_property_string(fdt, "os", genimg_get_os_short_name(params->os)); + + ret = fdt_property_file(params, fdt, "data", params->fit_ramdisk); + if (ret) + return ret; + + fdt_end_node(fdt); + } + fdt_end_node(fdt); return 0; @@ -268,15 +294,25 @@ static void fit_write_configs(struct image_tool_params *params, char *fdt) snprintf(str, sizeof(str), "%s@1", typename); fdt_property_string(fdt, typename, str); + if (params->fit_ramdisk) + fdt_property_string(fdt, FIT_RAMDISK_PROP, + FIT_RAMDISK_PROP "@1"); + snprintf(str, sizeof(str), FIT_FDT_PROP "@%d", upto); fdt_property_string(fdt, FIT_FDT_PROP, str); fdt_end_node(fdt); } + if (!upto) { fdt_begin_node(fdt, "conf@1"); typename = genimg_get_type_short_name(params->fit_image_type); snprintf(str, sizeof(str), "%s@1", typename); fdt_property_string(fdt, typename, str); + + if (params->fit_ramdisk) + fdt_property_string(fdt, FIT_RAMDISK_PROP, + FIT_RAMDISK_PROP "@1"); + fdt_end_node(fdt); } @@ -342,7 +378,6 @@ static int fit_build(struct image_tool_params *params, const char *fname) if (ret != size) { fprintf(stderr, "%s: Can't write %s: %s\n", params->cmdname, fname, strerror(errno)); - close(fd); goto err; } close(fd); @@ -416,7 +451,13 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) ret = -EPERM; goto err_munmap; } - fdt_setprop_u32(fdt, node, "data-offset", buf_ptr); + if (params->external_offset > 0) { + /* An external offset positions the data absolutely. */ + fdt_setprop_u32(fdt, node, "data-position", + params->external_offset + buf_ptr); + } else { + fdt_setprop_u32(fdt, node, "data-offset", buf_ptr); + } fdt_setprop_u32(fdt, node, "data-size", len); buf_ptr += (len + 3) & ~3; @@ -437,6 +478,17 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) ret = -EIO; goto err; } + + /* Check if an offset for the external data was set. */ + if (params->external_offset > 0) { + if (params->external_offset < new_size) { + debug("External offset %x overlaps FIT length %x", + params->external_offset, new_size); + ret = -EINVAL; + goto err; + } + new_size = params->external_offset; + } if (lseek(fd, new_size, SEEK_SET) < 0) { debug("%s: Failed to seek to end of file: %s\n", __func__, strerror(errno)); @@ -536,8 +588,8 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) if (fd < 0) { fprintf(stderr, "%s: Can't open %s: %s\n", params->cmdname, fname, strerror(errno)); - ret = -EIO; - goto err; + free(fdt); + return -EIO; } if (write(fd, fdt, new_size) != new_size) { debug("%s: Failed to write external data to file %s\n", @@ -631,8 +683,8 @@ static int fit_handle_file(struct image_tool_params *params) } if (ret) { - fprintf(stderr, "%s Can't add hashes to FIT blob\n", - params->cmdname); + fprintf(stderr, "%s Can't add hashes to FIT blob: %d\n", + params->cmdname, ret); goto err_system; }