for SPL boot has external data. Existence of 'data-offset' can be used to
identify which format is used.
+For FIT image with external data, it would be better to align each blob of data
+to block(512 byte) for block device, so that we don't need to do the copy when
+read the image data in SPL. Pass '-B 0x200' to mkimage to align the FIT
+structure and data to 512 byte, other values available for other align size.
+
9) Examples
-----------
*/
static int fit_extract_data(struct image_tool_params *params, const char *fname)
{
- void *buf;
+ void *buf = NULL;
int buf_ptr;
int fit_size, new_size;
int fd;
int ret;
int images;
int node;
+ int image_number;
+ int align_size;
+ align_size = params->bl_len ? params->bl_len : 4;
fd = mmap_fdt(params->cmdname, fname, 0, &fdt, &sbuf, false, false);
if (fd < 0)
return -EIO;
fit_size = fdt_totalsize(fdt);
- /* Allocate space to hold the image data we will extract */
- buf = malloc(fit_size);
- if (!buf) {
- ret = -ENOMEM;
- goto err_munmap;
- }
- buf_ptr = 0;
-
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_munmap;
}
+ image_number = fdtdec_get_child_count(fdt, images);
+
+ /*
+ * 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));
+ if (!buf) {
+ ret = -ENOMEM;
+ goto err_munmap;
+ }
+ buf_ptr = 0;
for (node = fdt_first_subnode(fdt, images);
node >= 0;
buf_ptr);
}
fdt_setprop_u32(fdt, node, FIT_DATA_SIZE_PROP, len);
-
- buf_ptr += (len + 3) & ~3;
+ buf_ptr += ALIGN(len, align_size);
}
/* Pack the FDT and place the data after it */
fdt_pack(fdt);
+ new_size = fdt_totalsize(fdt);
+ new_size = ALIGN(new_size, align_size);
+ fdt_set_totalsize(fdt, new_size);
debug("Size reduced from %x to %x\n", fit_size, fdt_totalsize(fdt));
debug("External data size %x\n", buf_ptr);
- new_size = fdt_totalsize(fdt);
- new_size = (new_size + 3) & ~3;
munmap(fdt, sbuf.st_size);
if (ftruncate(fd, new_size)) {
" -i => input filename for ramdisk file\n");
#ifdef CONFIG_FIT_SIGNATURE
fprintf(stderr,
- "Signing / verified boot options: [-E] [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n"
+ "Signing / verified boot options: [-E] [-B size] [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n"
" -E => place data outside of the FIT structure\n"
+ " -B => align size in hex for FIT structure and header\n"
" -k => set directory containing private keys\n"
" -K => write public keys to this .dtb file\n"
" -c => add comment in signature node\n"
int opt;
while ((opt = getopt(argc, argv,
- "a:A:b:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qsT:vVx")) != -1) {
+ "a:A:b:B:c:C:d:D:e:Ef:Fk:i:K:ln:N:p:O:rR:qsT:vVx")) != -1) {
switch (opt) {
case 'a':
params.addr = strtoull(optarg, &ptr, 16);
params.cmdname, optarg);
exit(EXIT_FAILURE);
}
+ break;
+ case 'B':
+ params.bl_len = strtoull(optarg, &ptr, 16);
+ if (*ptr) {
+ fprintf(stderr, "%s: invalid block length %s\n",
+ params.cmdname, optarg);
+ exit(EXIT_FAILURE);
+ }
+
break;
case 'c':
params.comment = optarg;