#include "fit_common.h"
#include "mkimage.h"
#include <image.h>
+#include <string.h>
#include <stdarg.h>
#include <version.h>
#include <u-boot/crc.h>
}
/* for first image creation, add a timestamp at offset 0 i.e., root */
- if (params->datafile) {
+ if (params->datafile || params->reset_timestamp) {
time_t time = imagetool_get_source_date(params->cmdname,
sbuf.st_mtime);
ret = fit_set_timestamp(ptr, 0, time);
}
if (!ret) {
- ret = fit_add_verification_data(params->keydir, dest_blob, ptr,
+ ret = fit_add_verification_data(params->keydir,
+ params->keyfile, dest_blob, ptr,
params->comment,
params->require_keys,
params->engine_id,
- params->cmdname);
+ params->cmdname,
+ params->algo_name,
+ ¶ms->summary);
}
if (dest_blob) {
if (size < 0)
return -1;
- /* Add space for properties */
+ /* Add space for properties and hash node */
total_size += size + 300;
}
str[len] = '\0';
}
+/**
+ * add_crc_node() - Add a hash node to request a CRC checksum for an image
+ *
+ * @fdt: Device tree to add to (in sequential-write mode)
+ */
+static void add_crc_node(void *fdt)
+{
+ fdt_begin_node(fdt, "hash-1");
+ fdt_property_string(fdt, FIT_ALGO_PROP, "crc32");
+ fdt_end_node(fdt);
+}
+
/**
* fit_write_images() - Write out a list of images to the FIT
*
ret = fdt_property_file(params, fdt, FIT_DATA_PROP, params->datafile);
if (ret)
return ret;
+ add_crc_node(fdt);
fdt_end_node(fdt);
/* Now the device tree files if available */
genimg_get_arch_short_name(params->arch));
fdt_property_string(fdt, FIT_COMP_PROP,
genimg_get_comp_short_name(IH_COMP_NONE));
+ add_crc_node(fdt);
fdt_end_node(fdt);
}
params->fit_ramdisk);
if (ret)
return ret;
-
+ add_crc_node(fdt);
fdt_end_node(fdt);
}
size = fit_calc_size(params);
if (size < 0)
return -1;
- buf = malloc(size);
+ buf = calloc(1, size);
if (!buf) {
fprintf(stderr, "%s: Out of memory (%d bytes)\n",
params->cmdname, size);
* Allocate space to hold the image data we will extract,
* extral space allocate for image alignment to prevent overflow.
*/
- buf = malloc(fit_size + (align_size * image_number));
+ buf = calloc(1, fit_size + (align_size * image_number));
if (!buf) {
ret = -ENOMEM;
goto err_munmap;
/* 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);
+ fprintf(stderr,
+ "External offset %x overlaps FIT length %x\n",
+ params->external_offset, new_size);
ret = -EINVAL;
goto err;
}
/* Allocate space to hold the new FIT */
size = sbuf.st_size + 16384;
- fdt = malloc(size);
+ fdt = calloc(1, size);
if (!fdt) {
fprintf(stderr, "%s: Failed to allocate memory (%d bytes)\n",
__func__, size);
continue;
debug("Importing data size %x\n", len);
- ret = fdt_setprop(fdt, node, "data", fdt + data_base + buf_ptr,
- len);
+ ret = fdt_setprop(fdt, node, "data",
+ old_fdt + data_base + buf_ptr, len);
if (ret) {
debug("%s: Failed to write property: %s\n", __func__,
fdt_strerror(ret));
return ret;
}
-static int copyfile(const char *src, const char *dst)
-{
- int fd_src = -1, fd_dst = -1;
- void *buf = NULL;
- ssize_t size;
- size_t count;
- int ret = -1;
-
- fd_src = open(src, O_RDONLY);
- if (fd_src < 0) {
- printf("Can't open file %s (%s)\n", src, strerror(errno));
- goto out;
- }
-
- fd_dst = open(dst, O_WRONLY | O_CREAT, 0666);
- if (fd_dst < 0) {
- printf("Can't open file %s (%s)\n", dst, strerror(errno));
- goto out;
- }
-
- buf = malloc(512);
- if (!buf) {
- printf("Can't allocate buffer to copy file\n");
- goto out;
- }
-
- while (1) {
- size = read(fd_src, buf, 512);
- if (size < 0) {
- printf("Can't read file %s\n", src);
- goto out;
- }
- if (!size)
- break;
-
- count = size;
- size = write(fd_dst, buf, count);
- if (size < 0) {
- printf("Can't write file %s\n", dst);
- goto out;
- }
- }
-
- ret = 0;
-
- out:
- if (fd_src >= 0)
- close(fd_src);
- if (fd_dst >= 0)
- close(fd_dst);
- if (buf)
- free(buf);
-
- return ret;
-}
-
/**
* fit_handle_file - main FIT file processing function
*
if (strlen (params->imagefile) +
strlen (MKIMAGE_TMPFILE_SUFFIX) + 1 > sizeof (tmpfile)) {
fprintf (stderr, "%s: Image file name (%s) too long, "
- "can't create tmpfile",
+ "can't create tmpfile.\n",
params->imagefile, params->cmdname);
return (EXIT_FAILURE);
}
snprintf(cmd, sizeof(cmd), "cp \"%s\" \"%s\"",
params->imagefile, tmpfile);
}
+ if (strlen(cmd) >= MKIMAGE_MAX_DTC_CMDLINE_LEN - 1) {
+ fprintf(stderr, "WARNING: command-line for FIT creation might be truncated and will probably fail.\n");
+ }
if (*cmd && system(cmd) == -1) {
fprintf (stderr, "%s: system(%s) failed: %s\n",
/* Indent string is defined in header image.h */
p = IMAGE_INDENT_STRING;
- if (!fit_check_format(fit)) {
- printf("Bad FIT image format\n");
- return -1;
- }
-
/* Find images parent node offset */
images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
if (images_noffset < 0) {