#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,
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",
+ debug("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));
goto out;
}
- buf = malloc(512);
+ buf = calloc(1, 512);
if (!buf) {
printf("Can't allocate buffer to copy file\n");
goto out;
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)) {
+ if (fit_check_format(fit, IMAGE_SIZE_INVAL)) {
printf("Bad FIT image format\n");
return -1;
}