X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=tools%2Ffit_image.c;h=6dcc88bae00f7f149ed741b84ed5d8812ce61c1a;hb=8ac8a2630459bacb2d9b6516d49bedad61ca63f8;hp=efd8a97a0b92723a01aae584cd9ce468c8e99735;hpb=d8c4eb60f8d1af74116eaee4f53adc937e618d6f;p=people%2Fms%2Fu-boot.git diff --git a/tools/fit_image.c b/tools/fit_image.c index efd8a97a0b..6dcc88bae0 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -59,7 +59,8 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc, 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) { @@ -371,7 +372,7 @@ static int fit_build(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)); - goto err; + goto err_buf; } ret = write(fd, buf, size); if (ret != size) { @@ -500,6 +501,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) ret = -EIO; goto err; } + free(buf); close(fd); return 0; @@ -535,21 +537,21 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) fprintf(stderr, "%s: Failed to allocate memory (%d bytes)\n", __func__, size); ret = -ENOMEM; - goto err; + goto err_has_fd; } ret = fdt_open_into(old_fdt, fdt, size); if (ret) { debug("%s: Failed to expand FIT: %s\n", __func__, fdt_strerror(errno)); ret = -EINVAL; - goto err; + goto err_has_fd; } images = fdt_path_offset(fdt, FIT_IMAGES_PATH); if (images < 0) { debug("%s: Cannot find /images node: %d\n", __func__, images); ret = -EINVAL; - goto err; + goto err_has_fd; } for (node = fdt_first_subnode(fdt, images); @@ -570,11 +572,11 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) debug("%s: Failed to write property: %s\n", __func__, fdt_strerror(ret)); ret = -EINVAL; - goto err; + goto err_has_fd; } } - munmap(old_fdt, sbuf.st_size); + /* Close the old fd so we can re-use it. */ close(fd); /* Pack the FDT and place the data after it */ @@ -587,21 +589,23 @@ 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)); - free(fdt); - return -EIO; + ret = -EIO; + goto err_no_fd; } if (write(fd, fdt, new_size) != new_size) { debug("%s: Failed to write external data to file %s\n", __func__, strerror(errno)); ret = -EIO; - goto err; + goto err_has_fd; } ret = 0; -err: - free(fdt); +err_has_fd: close(fd); +err_no_fd: + munmap(old_fdt, sbuf.st_size); + free(fdt); return ret; } @@ -647,11 +651,11 @@ static int fit_handle_file(struct image_tool_params *params) *cmd = '\0'; } else if (params->datafile) { /* dtc -I dts -O dtb -p 500 datafile > tmpfile */ - snprintf(cmd, sizeof(cmd), "%s %s %s > %s", + snprintf(cmd, sizeof(cmd), "%s %s \"%s\" > \"%s\"", MKIMAGE_DTC, params->dtc, params->datafile, tmpfile); debug("Trying to execute \"%s\"\n", cmd); } else { - snprintf(cmd, sizeof(cmd), "cp %s %s", + snprintf(cmd, sizeof(cmd), "cp \"%s\" \"%s\"", params->imagefile, tmpfile); } if (*cmd && system(cmd) == -1) {