blob: 9ac525623bcab172a847ab23fc0ddb89b9a85dd3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +05302/*
3 * (C) Copyright 2008 Semihalf
4 *
5 * (C) Copyright 2000-2004
6 * DENX Software Engineering
7 * Wolfgang Denk, wd@denx.de
8 *
9 * Updated-by: Prafulla Wadaskar <prafulla@marvell.com>
10 * FIT image specific code abstracted from mkimage.c
11 * some functions added to address abstraction
12 *
13 * All rights reserved.
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +053014 */
15
Guilherme Maciel Ferreira8ed4d1c2013-12-01 12:43:10 -070016#include "imagetool.h"
Heiko Schocher3cb743c2014-03-03 12:19:29 +010017#include "fit_common.h"
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +053018#include "mkimage.h"
19#include <image.h>
Sven Roederercbcb3992020-04-27 02:08:39 +020020#include <string.h>
Simon Glass88e31cb2016-02-22 22:55:51 -070021#include <stdarg.h>
22#include <version.h>
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +053023#include <u-boot/crc.h>
24
25static image_header_t header;
26
Simon Glass802aa822014-06-02 22:04:53 -060027static int fit_add_file_data(struct image_tool_params *params, size_t size_inc,
28 const char *tmpfile)
29{
30 int tfd, destfd = 0;
31 void *dest_blob = NULL;
32 off_t destfd_size = 0;
33 struct stat sbuf;
34 void *ptr;
35 int ret = 0;
36
Luca Boccassibff733f2019-05-14 19:35:02 +010037 tfd = mmap_fdt(params->cmdname, tmpfile, size_inc, &ptr, &sbuf, true,
38 false);
Simon Glass802aa822014-06-02 22:04:53 -060039 if (tfd < 0)
40 return -EIO;
41
42 if (params->keydest) {
43 struct stat dest_sbuf;
44
45 destfd = mmap_fdt(params->cmdname, params->keydest, size_inc,
Luca Boccassibff733f2019-05-14 19:35:02 +010046 &dest_blob, &dest_sbuf, false,
47 false);
Simon Glass802aa822014-06-02 22:04:53 -060048 if (destfd < 0) {
49 ret = -EIO;
50 goto err_keydest;
51 }
52 destfd_size = dest_sbuf.st_size;
53 }
54
55 /* for first image creation, add a timestamp at offset 0 i.e., root */
Simon Glass472ee0c2020-07-09 18:39:43 -060056 if (params->datafile || params->reset_timestamp) {
Alex Kiernanc4c7e0d2018-06-20 20:10:51 +000057 time_t time = imagetool_get_source_date(params->cmdname,
58 sbuf.st_mtime);
Vagrant Cascadianf8e066c2016-06-16 12:28:40 -070059 ret = fit_set_timestamp(ptr, 0, time);
60 }
Simon Glass802aa822014-06-02 22:04:53 -060061
62 if (!ret) {
Philippe Reynes3148e422019-12-18 18:25:41 +010063 ret = fit_cipher_data(params->keydir, dest_blob, ptr,
64 params->comment,
65 params->require_keys,
66 params->engine_id,
67 params->cmdname);
68 }
69
70 if (!ret) {
Alexandru Gagniuc8fcea122021-02-19 12:45:17 -060071 ret = fit_add_verification_data(params->keydir,
72 params->keyfile, dest_blob, ptr,
Simon Glass802aa822014-06-02 22:04:53 -060073 params->comment,
George McCollister23d14892017-01-06 13:14:17 -060074 params->require_keys,
Alex Kiernan697fcdc2018-06-20 20:10:52 +000075 params->engine_id,
Jan Kiszka4043f322022-01-14 10:21:19 +010076 params->cmdname,
77 params->algo_name);
Simon Glass802aa822014-06-02 22:04:53 -060078 }
79
80 if (dest_blob) {
81 munmap(dest_blob, destfd_size);
82 close(destfd);
83 }
84
85err_keydest:
86 munmap(ptr, sbuf.st_size);
87 close(tfd);
Simon Glass802aa822014-06-02 22:04:53 -060088 return ret;
89}
90
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +053091/**
Simon Glass88e31cb2016-02-22 22:55:51 -070092 * fit_calc_size() - Calculate the approximate size of the FIT we will generate
93 */
94static int fit_calc_size(struct image_tool_params *params)
95{
Simon Glassbd8bc5d2016-02-22 22:55:52 -070096 struct content_info *cont;
Simon Glass88e31cb2016-02-22 22:55:51 -070097 int size, total_size;
98
99 size = imagetool_get_filesize(params, params->datafile);
100 if (size < 0)
101 return -1;
Simon Glass88e31cb2016-02-22 22:55:51 -0700102 total_size = size;
Tomeu Vizoso8d83ed22016-11-04 14:22:15 +0100103
104 if (params->fit_ramdisk) {
105 size = imagetool_get_filesize(params, params->fit_ramdisk);
106 if (size < 0)
107 return -1;
108 total_size += size;
109 }
110
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700111 for (cont = params->content_head; cont; cont = cont->next) {
112 size = imagetool_get_filesize(params, cont->fname);
113 if (size < 0)
114 return -1;
Simon Glass88e31cb2016-02-22 22:55:51 -0700115
Simon Glass611fd912020-05-27 07:24:55 -0600116 /* Add space for properties and hash node */
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700117 total_size += size + 300;
118 }
Simon Glass88e31cb2016-02-22 22:55:51 -0700119
120 /* Add plenty of space for headers, properties, nodes, etc. */
121 total_size += 4096;
122
123 return total_size;
124}
125
126static int fdt_property_file(struct image_tool_params *params,
127 void *fdt, const char *name, const char *fname)
128{
129 struct stat sbuf;
130 void *ptr;
131 int ret;
132 int fd;
133
134 fd = open(fname, O_RDWR | O_BINARY);
135 if (fd < 0) {
136 fprintf(stderr, "%s: Can't open %s: %s\n",
137 params->cmdname, fname, strerror(errno));
138 return -1;
139 }
140
141 if (fstat(fd, &sbuf) < 0) {
142 fprintf(stderr, "%s: Can't stat %s: %s\n",
143 params->cmdname, fname, strerror(errno));
144 goto err;
145 }
146
147 ret = fdt_property_placeholder(fdt, "data", sbuf.st_size, &ptr);
148 if (ret)
Simon Glass9ab7f052016-03-16 07:45:42 -0600149 goto err;
Simon Glass88e31cb2016-02-22 22:55:51 -0700150 ret = read(fd, ptr, sbuf.st_size);
151 if (ret != sbuf.st_size) {
152 fprintf(stderr, "%s: Can't read %s: %s\n",
153 params->cmdname, fname, strerror(errno));
154 goto err;
155 }
Simon Glass9ab7f052016-03-16 07:45:42 -0600156 close(fd);
Simon Glass88e31cb2016-02-22 22:55:51 -0700157
158 return 0;
159err:
160 close(fd);
161 return -1;
162}
163
164static int fdt_property_strf(void *fdt, const char *name, const char *fmt, ...)
165{
166 char str[100];
167 va_list ptr;
168
169 va_start(ptr, fmt);
170 vsnprintf(str, sizeof(str), fmt, ptr);
171 va_end(ptr);
172 return fdt_property_string(fdt, name, str);
173}
174
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700175static void get_basename(char *str, int size, const char *fname)
176{
177 const char *p, *start, *end;
178 int len;
179
180 /*
181 * Use the base name as the 'name' field. So for example:
182 *
183 * "arch/arm/dts/sun7i-a20-bananapro.dtb"
184 * becomes "sun7i-a20-bananapro"
185 */
186 p = strrchr(fname, '/');
187 start = p ? p + 1 : fname;
188 p = strrchr(fname, '.');
189 end = p ? p : fname + strlen(fname);
190 len = end - start;
191 if (len >= size)
192 len = size - 1;
193 memcpy(str, start, len);
194 str[len] = '\0';
195}
196
Simon Glass88e31cb2016-02-22 22:55:51 -0700197/**
Simon Glass611fd912020-05-27 07:24:55 -0600198 * add_crc_node() - Add a hash node to request a CRC checksum for an image
199 *
200 * @fdt: Device tree to add to (in sequential-write mode)
201 */
202static void add_crc_node(void *fdt)
203{
204 fdt_begin_node(fdt, "hash-1");
205 fdt_property_string(fdt, FIT_ALGO_PROP, "crc32");
206 fdt_end_node(fdt);
207}
208
209/**
Simon Glass88e31cb2016-02-22 22:55:51 -0700210 * fit_write_images() - Write out a list of images to the FIT
211 *
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700212 * We always include the main image (params->datafile). If there are device
Andre Przywara9ef25e82017-12-04 02:05:12 +0000213 * tree files, we include an fdt- node for each of those too.
Simon Glass88e31cb2016-02-22 22:55:51 -0700214 */
215static int fit_write_images(struct image_tool_params *params, char *fdt)
216{
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700217 struct content_info *cont;
Simon Glass88e31cb2016-02-22 22:55:51 -0700218 const char *typename;
219 char str[100];
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700220 int upto;
Simon Glass88e31cb2016-02-22 22:55:51 -0700221 int ret;
222
223 fdt_begin_node(fdt, "images");
224
225 /* First the main image */
226 typename = genimg_get_type_short_name(params->fit_image_type);
Andre Przywara9ef25e82017-12-04 02:05:12 +0000227 snprintf(str, sizeof(str), "%s-1", typename);
Simon Glass88e31cb2016-02-22 22:55:51 -0700228 fdt_begin_node(fdt, str);
Michal Simeka4e678d2018-07-20 12:31:02 +0200229 fdt_property_string(fdt, FIT_DESC_PROP, params->imagename);
230 fdt_property_string(fdt, FIT_TYPE_PROP, typename);
231 fdt_property_string(fdt, FIT_ARCH_PROP,
Simon Glassaeeea7f2016-06-30 10:52:12 -0600232 genimg_get_arch_short_name(params->arch));
Michal Simeka4e678d2018-07-20 12:31:02 +0200233 fdt_property_string(fdt, FIT_OS_PROP,
234 genimg_get_os_short_name(params->os));
235 fdt_property_string(fdt, FIT_COMP_PROP,
Simon Glass88e31cb2016-02-22 22:55:51 -0700236 genimg_get_comp_short_name(params->comp));
Michal Simeka4e678d2018-07-20 12:31:02 +0200237 fdt_property_u32(fdt, FIT_LOAD_PROP, params->addr);
238 fdt_property_u32(fdt, FIT_ENTRY_PROP, params->ep);
Simon Glass88e31cb2016-02-22 22:55:51 -0700239
240 /*
241 * Put data last since it is large. SPL may only load the first part
242 * of the DT, so this way it can access all the above fields.
243 */
Michal Simeka4e678d2018-07-20 12:31:02 +0200244 ret = fdt_property_file(params, fdt, FIT_DATA_PROP, params->datafile);
Simon Glass88e31cb2016-02-22 22:55:51 -0700245 if (ret)
246 return ret;
Simon Glass611fd912020-05-27 07:24:55 -0600247 add_crc_node(fdt);
Simon Glass88e31cb2016-02-22 22:55:51 -0700248 fdt_end_node(fdt);
249
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700250 /* Now the device tree files if available */
251 upto = 0;
252 for (cont = params->content_head; cont; cont = cont->next) {
253 if (cont->type != IH_TYPE_FLATDT)
254 continue;
Michal Sojka8a90ce82019-09-13 12:43:12 +0200255 typename = genimg_get_type_short_name(cont->type);
Andre Przywara9ef25e82017-12-04 02:05:12 +0000256 snprintf(str, sizeof(str), "%s-%d", FIT_FDT_PROP, ++upto);
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700257 fdt_begin_node(fdt, str);
258
259 get_basename(str, sizeof(str), cont->fname);
Michal Simeka4e678d2018-07-20 12:31:02 +0200260 fdt_property_string(fdt, FIT_DESC_PROP, str);
261 ret = fdt_property_file(params, fdt, FIT_DATA_PROP,
262 cont->fname);
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700263 if (ret)
264 return ret;
Michal Simeka4e678d2018-07-20 12:31:02 +0200265 fdt_property_string(fdt, FIT_TYPE_PROP, typename);
266 fdt_property_string(fdt, FIT_ARCH_PROP,
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700267 genimg_get_arch_short_name(params->arch));
Michal Simeka4e678d2018-07-20 12:31:02 +0200268 fdt_property_string(fdt, FIT_COMP_PROP,
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700269 genimg_get_comp_short_name(IH_COMP_NONE));
Simon Glass611fd912020-05-27 07:24:55 -0600270 add_crc_node(fdt);
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700271 fdt_end_node(fdt);
272 }
273
Tomeu Vizoso8d83ed22016-11-04 14:22:15 +0100274 /* And a ramdisk file if available */
275 if (params->fit_ramdisk) {
Andre Przywara9ef25e82017-12-04 02:05:12 +0000276 fdt_begin_node(fdt, FIT_RAMDISK_PROP "-1");
Tomeu Vizoso8d83ed22016-11-04 14:22:15 +0100277
Michal Simeka4e678d2018-07-20 12:31:02 +0200278 fdt_property_string(fdt, FIT_TYPE_PROP, FIT_RAMDISK_PROP);
279 fdt_property_string(fdt, FIT_OS_PROP,
280 genimg_get_os_short_name(params->os));
Michal Sojka8a90ce82019-09-13 12:43:12 +0200281 fdt_property_string(fdt, FIT_ARCH_PROP,
282 genimg_get_arch_short_name(params->arch));
Tomeu Vizoso8d83ed22016-11-04 14:22:15 +0100283
Michal Simeka4e678d2018-07-20 12:31:02 +0200284 ret = fdt_property_file(params, fdt, FIT_DATA_PROP,
285 params->fit_ramdisk);
Tomeu Vizoso8d83ed22016-11-04 14:22:15 +0100286 if (ret)
287 return ret;
Simon Glass611fd912020-05-27 07:24:55 -0600288 add_crc_node(fdt);
Tomeu Vizoso8d83ed22016-11-04 14:22:15 +0100289 fdt_end_node(fdt);
290 }
291
Simon Glass88e31cb2016-02-22 22:55:51 -0700292 fdt_end_node(fdt);
293
294 return 0;
295}
296
297/**
298 * fit_write_configs() - Write out a list of configurations to the FIT
299 *
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700300 * If there are device tree files, we include a configuration for each, which
301 * selects the main image (params->datafile) and its corresponding device
302 * tree file.
303 *
304 * Otherwise we just create a configuration with the main image in it.
Simon Glass88e31cb2016-02-22 22:55:51 -0700305 */
306static void fit_write_configs(struct image_tool_params *params, char *fdt)
307{
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700308 struct content_info *cont;
Simon Glass88e31cb2016-02-22 22:55:51 -0700309 const char *typename;
310 char str[100];
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700311 int upto;
Simon Glass88e31cb2016-02-22 22:55:51 -0700312
313 fdt_begin_node(fdt, "configurations");
Michal Simeka4e678d2018-07-20 12:31:02 +0200314 fdt_property_string(fdt, FIT_DEFAULT_PROP, "conf-1");
Simon Glass88e31cb2016-02-22 22:55:51 -0700315
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700316 upto = 0;
317 for (cont = params->content_head; cont; cont = cont->next) {
318 if (cont->type != IH_TYPE_FLATDT)
319 continue;
320 typename = genimg_get_type_short_name(cont->type);
Andre Przywara9ef25e82017-12-04 02:05:12 +0000321 snprintf(str, sizeof(str), "conf-%d", ++upto);
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700322 fdt_begin_node(fdt, str);
323
324 get_basename(str, sizeof(str), cont->fname);
Michal Simeka4e678d2018-07-20 12:31:02 +0200325 fdt_property_string(fdt, FIT_DESC_PROP, str);
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700326
327 typename = genimg_get_type_short_name(params->fit_image_type);
Andre Przywara9ef25e82017-12-04 02:05:12 +0000328 snprintf(str, sizeof(str), "%s-1", typename);
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700329 fdt_property_string(fdt, typename, str);
Abel Vesa7e0cb5e2019-03-12 08:34:32 +0000330 fdt_property_string(fdt, FIT_LOADABLE_PROP, str);
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700331
Tomeu Vizoso8d83ed22016-11-04 14:22:15 +0100332 if (params->fit_ramdisk)
333 fdt_property_string(fdt, FIT_RAMDISK_PROP,
Andre Przywara9ef25e82017-12-04 02:05:12 +0000334 FIT_RAMDISK_PROP "-1");
Tomeu Vizoso8d83ed22016-11-04 14:22:15 +0100335
Andre Przywara9ef25e82017-12-04 02:05:12 +0000336 snprintf(str, sizeof(str), FIT_FDT_PROP "-%d", upto);
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700337 fdt_property_string(fdt, FIT_FDT_PROP, str);
338 fdt_end_node(fdt);
339 }
Tomeu Vizoso8d83ed22016-11-04 14:22:15 +0100340
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700341 if (!upto) {
Andre Przywara9ef25e82017-12-04 02:05:12 +0000342 fdt_begin_node(fdt, "conf-1");
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700343 typename = genimg_get_type_short_name(params->fit_image_type);
Andre Przywara9ef25e82017-12-04 02:05:12 +0000344 snprintf(str, sizeof(str), "%s-1", typename);
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700345 fdt_property_string(fdt, typename, str);
Tomeu Vizoso8d83ed22016-11-04 14:22:15 +0100346
347 if (params->fit_ramdisk)
348 fdt_property_string(fdt, FIT_RAMDISK_PROP,
Andre Przywara9ef25e82017-12-04 02:05:12 +0000349 FIT_RAMDISK_PROP "-1");
Tomeu Vizoso8d83ed22016-11-04 14:22:15 +0100350
Simon Glassbd8bc5d2016-02-22 22:55:52 -0700351 fdt_end_node(fdt);
352 }
Simon Glass88e31cb2016-02-22 22:55:51 -0700353
354 fdt_end_node(fdt);
355}
356
357static int fit_build_fdt(struct image_tool_params *params, char *fdt, int size)
358{
359 int ret;
360
361 ret = fdt_create(fdt, size);
362 if (ret)
363 return ret;
364 fdt_finish_reservemap(fdt);
365 fdt_begin_node(fdt, "");
Michal Simeka4e678d2018-07-20 12:31:02 +0200366 fdt_property_strf(fdt, FIT_DESC_PROP,
Simon Glass88e31cb2016-02-22 22:55:51 -0700367 "%s image with one or more FDT blobs",
368 genimg_get_type_name(params->fit_image_type));
369 fdt_property_strf(fdt, "creator", "U-Boot mkimage %s", PLAIN_VERSION);
370 fdt_property_u32(fdt, "#address-cells", 1);
371 ret = fit_write_images(params, fdt);
372 if (ret)
373 return ret;
374 fit_write_configs(params, fdt);
375 fdt_end_node(fdt);
376 ret = fdt_finish(fdt);
377 if (ret)
378 return ret;
379
380 return fdt_totalsize(fdt);
381}
382
383static int fit_build(struct image_tool_params *params, const char *fname)
384{
385 char *buf;
386 int size;
387 int ret;
388 int fd;
389
390 size = fit_calc_size(params);
391 if (size < 0)
392 return -1;
Fabio Estevamc2248cb2020-07-27 21:03:13 -0300393 buf = calloc(1, size);
Simon Glass88e31cb2016-02-22 22:55:51 -0700394 if (!buf) {
395 fprintf(stderr, "%s: Out of memory (%d bytes)\n",
396 params->cmdname, size);
397 return -1;
398 }
399 ret = fit_build_fdt(params, buf, size);
400 if (ret < 0) {
401 fprintf(stderr, "%s: Failed to build FIT image\n",
402 params->cmdname);
Simon Glassc0ee1ca2016-03-16 07:45:41 -0600403 goto err_buf;
Simon Glass88e31cb2016-02-22 22:55:51 -0700404 }
405 size = ret;
406 fd = open(fname, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666);
407 if (fd < 0) {
408 fprintf(stderr, "%s: Can't open %s: %s\n",
409 params->cmdname, fname, strerror(errno));
Tom Rinib8286652017-09-26 22:14:44 -0400410 goto err_buf;
Simon Glass88e31cb2016-02-22 22:55:51 -0700411 }
412 ret = write(fd, buf, size);
413 if (ret != size) {
414 fprintf(stderr, "%s: Can't write %s: %s\n",
415 params->cmdname, fname, strerror(errno));
Simon Glass88e31cb2016-02-22 22:55:51 -0700416 goto err;
417 }
418 close(fd);
Simon Glassc0ee1ca2016-03-16 07:45:41 -0600419 free(buf);
Simon Glass88e31cb2016-02-22 22:55:51 -0700420
421 return 0;
422err:
Simon Glassc0ee1ca2016-03-16 07:45:41 -0600423 close(fd);
424err_buf:
Simon Glass88e31cb2016-02-22 22:55:51 -0700425 free(buf);
426 return -1;
427}
428
429/**
Simon Glassafd728c2016-02-22 22:55:53 -0700430 * fit_extract_data() - Move all data outside the FIT
431 *
432 * This takes a normal FIT file and removes all the 'data' properties from it.
433 * The data is placed in an area after the FIT so that it can be accessed
434 * using an offset into that area. The 'data' properties turn into
435 * 'data-offset' properties.
436 *
437 * This function cannot cope with FITs with 'data-offset' properties. All
438 * data must be in 'data' properties on entry.
439 */
440static int fit_extract_data(struct image_tool_params *params, const char *fname)
441{
Kever Yang8e238b52020-03-30 11:56:24 +0800442 void *buf = NULL;
Simon Glassafd728c2016-02-22 22:55:53 -0700443 int buf_ptr;
444 int fit_size, new_size;
445 int fd;
446 struct stat sbuf;
447 void *fdt;
448 int ret;
449 int images;
450 int node;
Kever Yang8e238b52020-03-30 11:56:24 +0800451 int image_number;
452 int align_size;
Simon Glassafd728c2016-02-22 22:55:53 -0700453
Tom Rini96642972020-05-06 11:05:17 -0400454 align_size = params->bl_len ? params->bl_len : 4;
Luca Boccassibff733f2019-05-14 19:35:02 +0100455 fd = mmap_fdt(params->cmdname, fname, 0, &fdt, &sbuf, false, false);
Simon Glassafd728c2016-02-22 22:55:53 -0700456 if (fd < 0)
457 return -EIO;
458 fit_size = fdt_totalsize(fdt);
459
Simon Glassafd728c2016-02-22 22:55:53 -0700460 images = fdt_path_offset(fdt, FIT_IMAGES_PATH);
461 if (images < 0) {
462 debug("%s: Cannot find /images node: %d\n", __func__, images);
463 ret = -EINVAL;
Simon Glass4e7505f2016-03-16 07:45:39 -0600464 goto err_munmap;
Simon Glassafd728c2016-02-22 22:55:53 -0700465 }
Kever Yang8e238b52020-03-30 11:56:24 +0800466 image_number = fdtdec_get_child_count(fdt, images);
467
468 /*
469 * Allocate space to hold the image data we will extract,
470 * extral space allocate for image alignment to prevent overflow.
471 */
Fabio Estevamc2248cb2020-07-27 21:03:13 -0300472 buf = calloc(1, fit_size + (align_size * image_number));
Kever Yang8e238b52020-03-30 11:56:24 +0800473 if (!buf) {
474 ret = -ENOMEM;
475 goto err_munmap;
476 }
477 buf_ptr = 0;
Simon Glassafd728c2016-02-22 22:55:53 -0700478
479 for (node = fdt_first_subnode(fdt, images);
480 node >= 0;
481 node = fdt_next_subnode(fdt, node)) {
482 const char *data;
483 int len;
484
Michal Simeka4e678d2018-07-20 12:31:02 +0200485 data = fdt_getprop(fdt, node, FIT_DATA_PROP, &len);
Simon Glassafd728c2016-02-22 22:55:53 -0700486 if (!data)
487 continue;
488 memcpy(buf + buf_ptr, data, len);
489 debug("Extracting data size %x\n", len);
490
Michal Simeka4e678d2018-07-20 12:31:02 +0200491 ret = fdt_delprop(fdt, node, FIT_DATA_PROP);
Simon Glassafd728c2016-02-22 22:55:53 -0700492 if (ret) {
493 ret = -EPERM;
Simon Glass4e7505f2016-03-16 07:45:39 -0600494 goto err_munmap;
Simon Glassafd728c2016-02-22 22:55:53 -0700495 }
Teddy Reeda8457622016-06-09 19:38:02 -0700496 if (params->external_offset > 0) {
497 /* An external offset positions the data absolutely. */
Michal Simeka4e678d2018-07-20 12:31:02 +0200498 fdt_setprop_u32(fdt, node, FIT_DATA_POSITION_PROP,
Teddy Reeda8457622016-06-09 19:38:02 -0700499 params->external_offset + buf_ptr);
500 } else {
Michal Simeka4e678d2018-07-20 12:31:02 +0200501 fdt_setprop_u32(fdt, node, FIT_DATA_OFFSET_PROP,
502 buf_ptr);
Teddy Reeda8457622016-06-09 19:38:02 -0700503 }
Michal Simeka4e678d2018-07-20 12:31:02 +0200504 fdt_setprop_u32(fdt, node, FIT_DATA_SIZE_PROP, len);
Kever Yang8e238b52020-03-30 11:56:24 +0800505 buf_ptr += ALIGN(len, align_size);
Simon Glassafd728c2016-02-22 22:55:53 -0700506 }
507
508 /* Pack the FDT and place the data after it */
509 fdt_pack(fdt);
510
Kever Yang8e238b52020-03-30 11:56:24 +0800511 new_size = fdt_totalsize(fdt);
Tom Rini96642972020-05-06 11:05:17 -0400512 new_size = ALIGN(new_size, align_size);
Kever Yang8e238b52020-03-30 11:56:24 +0800513 fdt_set_totalsize(fdt, new_size);
Simon Glassafd728c2016-02-22 22:55:53 -0700514 debug("Size reduced from %x to %x\n", fit_size, fdt_totalsize(fdt));
515 debug("External data size %x\n", buf_ptr);
Simon Glassafd728c2016-02-22 22:55:53 -0700516 munmap(fdt, sbuf.st_size);
517
518 if (ftruncate(fd, new_size)) {
519 debug("%s: Failed to truncate file: %s\n", __func__,
520 strerror(errno));
521 ret = -EIO;
522 goto err;
523 }
Teddy Reeda8457622016-06-09 19:38:02 -0700524
525 /* Check if an offset for the external data was set. */
526 if (params->external_offset > 0) {
527 if (params->external_offset < new_size) {
Simon Glass00c06772022-01-09 20:13:38 -0700528 fprintf(stderr,
529 "External offset %x overlaps FIT length %x\n",
530 params->external_offset, new_size);
Teddy Reeda8457622016-06-09 19:38:02 -0700531 ret = -EINVAL;
532 goto err;
533 }
534 new_size = params->external_offset;
535 }
Simon Glassafd728c2016-02-22 22:55:53 -0700536 if (lseek(fd, new_size, SEEK_SET) < 0) {
537 debug("%s: Failed to seek to end of file: %s\n", __func__,
538 strerror(errno));
539 ret = -EIO;
540 goto err;
541 }
542 if (write(fd, buf, buf_ptr) != buf_ptr) {
543 debug("%s: Failed to write external data to file %s\n",
544 __func__, strerror(errno));
545 ret = -EIO;
546 goto err;
547 }
Tom Rinib8286652017-09-26 22:14:44 -0400548 free(buf);
Simon Glass4e7505f2016-03-16 07:45:39 -0600549 close(fd);
550 return 0;
Simon Glassafd728c2016-02-22 22:55:53 -0700551
Simon Glass4e7505f2016-03-16 07:45:39 -0600552err_munmap:
553 munmap(fdt, sbuf.st_size);
Simon Glassafd728c2016-02-22 22:55:53 -0700554err:
Bin Meng6eb238742020-04-18 01:59:11 -0700555 free(buf);
Simon Glassafd728c2016-02-22 22:55:53 -0700556 close(fd);
557 return ret;
558}
559
Simon Glassd11b7002016-02-22 22:55:54 -0700560static int fit_import_data(struct image_tool_params *params, const char *fname)
561{
562 void *fdt, *old_fdt;
563 int fit_size, new_size, size, data_base;
564 int fd;
565 struct stat sbuf;
566 int ret;
567 int images;
568 int node;
569
Luca Boccassibff733f2019-05-14 19:35:02 +0100570 fd = mmap_fdt(params->cmdname, fname, 0, &old_fdt, &sbuf, false, false);
Simon Glassd11b7002016-02-22 22:55:54 -0700571 if (fd < 0)
572 return -EIO;
573 fit_size = fdt_totalsize(old_fdt);
Kever Yang8c11bc12020-03-30 11:56:22 +0800574 data_base = ALIGN(fit_size, 4);
Simon Glassd11b7002016-02-22 22:55:54 -0700575
576 /* Allocate space to hold the new FIT */
577 size = sbuf.st_size + 16384;
Fabio Estevamc2248cb2020-07-27 21:03:13 -0300578 fdt = calloc(1, size);
Simon Glassd11b7002016-02-22 22:55:54 -0700579 if (!fdt) {
580 fprintf(stderr, "%s: Failed to allocate memory (%d bytes)\n",
581 __func__, size);
582 ret = -ENOMEM;
Lihua Zhao4536ef82020-04-18 01:59:10 -0700583 goto err_munmap;
Simon Glassd11b7002016-02-22 22:55:54 -0700584 }
585 ret = fdt_open_into(old_fdt, fdt, size);
586 if (ret) {
587 debug("%s: Failed to expand FIT: %s\n", __func__,
588 fdt_strerror(errno));
589 ret = -EINVAL;
Lihua Zhao4536ef82020-04-18 01:59:10 -0700590 goto err_munmap;
Simon Glassd11b7002016-02-22 22:55:54 -0700591 }
592
593 images = fdt_path_offset(fdt, FIT_IMAGES_PATH);
594 if (images < 0) {
595 debug("%s: Cannot find /images node: %d\n", __func__, images);
596 ret = -EINVAL;
Lihua Zhao4536ef82020-04-18 01:59:10 -0700597 goto err_munmap;
Simon Glassd11b7002016-02-22 22:55:54 -0700598 }
599
600 for (node = fdt_first_subnode(fdt, images);
601 node >= 0;
602 node = fdt_next_subnode(fdt, node)) {
603 int buf_ptr;
604 int len;
605
606 buf_ptr = fdtdec_get_int(fdt, node, "data-offset", -1);
607 len = fdtdec_get_int(fdt, node, "data-size", -1);
608 if (buf_ptr == -1 || len == -1)
609 continue;
610 debug("Importing data size %x\n", len);
611
Patrick Oppenlander14139f52020-07-30 14:31:48 +1000612 ret = fdt_setprop(fdt, node, "data",
613 old_fdt + data_base + buf_ptr, len);
Simon Glassd11b7002016-02-22 22:55:54 -0700614 if (ret) {
615 debug("%s: Failed to write property: %s\n", __func__,
616 fdt_strerror(ret));
617 ret = -EINVAL;
Lihua Zhao4536ef82020-04-18 01:59:10 -0700618 goto err_munmap;
Simon Glassd11b7002016-02-22 22:55:54 -0700619 }
620 }
621
Lihua Zhao4536ef82020-04-18 01:59:10 -0700622 munmap(old_fdt, sbuf.st_size);
623
Tom Rinia29829e2017-10-07 11:27:59 -0400624 /* Close the old fd so we can re-use it. */
Simon Glassd11b7002016-02-22 22:55:54 -0700625 close(fd);
626
627 /* Pack the FDT and place the data after it */
628 fdt_pack(fdt);
629
630 new_size = fdt_totalsize(fdt);
631 debug("Size expanded from %x to %x\n", fit_size, new_size);
632
633 fd = open(fname, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666);
634 if (fd < 0) {
635 fprintf(stderr, "%s: Can't open %s: %s\n",
636 params->cmdname, fname, strerror(errno));
Tom Rinia29829e2017-10-07 11:27:59 -0400637 ret = -EIO;
Lihua Zhao4536ef82020-04-18 01:59:10 -0700638 goto err;
Simon Glassd11b7002016-02-22 22:55:54 -0700639 }
640 if (write(fd, fdt, new_size) != new_size) {
641 debug("%s: Failed to write external data to file %s\n",
642 __func__, strerror(errno));
643 ret = -EIO;
Lihua Zhao4536ef82020-04-18 01:59:10 -0700644 goto err;
Simon Glassd11b7002016-02-22 22:55:54 -0700645 }
Simon Glassd11b7002016-02-22 22:55:54 -0700646
Lihua Zhao4536ef82020-04-18 01:59:10 -0700647 free(fdt);
Tom Rinia29829e2017-10-07 11:27:59 -0400648 close(fd);
Lihua Zhao4536ef82020-04-18 01:59:10 -0700649 return 0;
650
651err_munmap:
Tom Rinib8286652017-09-26 22:14:44 -0400652 munmap(old_fdt, sbuf.st_size);
Lihua Zhao4536ef82020-04-18 01:59:10 -0700653err:
Simon Glass5014cc12016-03-16 07:45:38 -0600654 free(fdt);
Lihua Zhao4536ef82020-04-18 01:59:10 -0700655 close(fd);
Simon Glassd11b7002016-02-22 22:55:54 -0700656 return ret;
657}
658
Philippe Reynes3148e422019-12-18 18:25:41 +0100659static int copyfile(const char *src, const char *dst)
660{
661 int fd_src = -1, fd_dst = -1;
662 void *buf = NULL;
663 ssize_t size;
664 size_t count;
665 int ret = -1;
666
667 fd_src = open(src, O_RDONLY);
668 if (fd_src < 0) {
669 printf("Can't open file %s (%s)\n", src, strerror(errno));
670 goto out;
671 }
672
Thomas Hebb97caa072020-03-01 10:47:53 -0800673 fd_dst = open(dst, O_WRONLY | O_CREAT, 0666);
Philippe Reynes3148e422019-12-18 18:25:41 +0100674 if (fd_dst < 0) {
675 printf("Can't open file %s (%s)\n", dst, strerror(errno));
676 goto out;
677 }
678
Fabio Estevamc2248cb2020-07-27 21:03:13 -0300679 buf = calloc(1, 512);
Philippe Reynes3148e422019-12-18 18:25:41 +0100680 if (!buf) {
681 printf("Can't allocate buffer to copy file\n");
682 goto out;
683 }
684
685 while (1) {
686 size = read(fd_src, buf, 512);
687 if (size < 0) {
688 printf("Can't read file %s\n", src);
689 goto out;
690 }
691 if (!size)
692 break;
693
694 count = size;
695 size = write(fd_dst, buf, count);
696 if (size < 0) {
697 printf("Can't write file %s\n", dst);
698 goto out;
699 }
700 }
701
702 ret = 0;
703
704 out:
705 if (fd_src >= 0)
706 close(fd_src);
707 if (fd_dst >= 0)
708 close(fd_dst);
709 if (buf)
710 free(buf);
711
712 return ret;
713}
714
Simon Glassafd728c2016-02-22 22:55:53 -0700715/**
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530716 * fit_handle_file - main FIT file processing function
717 *
718 * fit_handle_file() runs dtc to convert .its to .itb, includes
719 * binary data, updates timestamp property and calculates hashes.
720 *
721 * datafile - .its file
722 * imagefile - .itb file
723 *
724 * returns:
725 * only on success, otherwise calls exit (EXIT_FAILURE);
726 */
Guilherme Maciel Ferreira8ed4d1c2013-12-01 12:43:10 -0700727static int fit_handle_file(struct image_tool_params *params)
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530728{
729 char tmpfile[MKIMAGE_MAX_TMPFILE_LEN];
Philippe Reynes3148e422019-12-18 18:25:41 +0100730 char bakfile[MKIMAGE_MAX_TMPFILE_LEN + 4] = {0};
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530731 char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN];
Simon Glass802aa822014-06-02 22:04:53 -0600732 size_t size_inc;
733 int ret;
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530734
735 /* Flattened Image Tree (FIT) format handling */
736 debug ("FIT format handling\n");
737
738 /* call dtc to include binary properties into the tmp file */
739 if (strlen (params->imagefile) +
740 strlen (MKIMAGE_TMPFILE_SUFFIX) + 1 > sizeof (tmpfile)) {
741 fprintf (stderr, "%s: Image file name (%s) too long, "
Sven Roederer88be5d32021-05-25 23:15:27 +0200742 "can't create tmpfile.\n",
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530743 params->imagefile, params->cmdname);
744 return (EXIT_FAILURE);
745 }
746 sprintf (tmpfile, "%s%s", params->imagefile, MKIMAGE_TMPFILE_SUFFIX);
747
Simon Glassce8c3ca2013-06-13 15:10:05 -0700748 /* We either compile the source file, or use the existing FIT image */
Simon Glass88e31cb2016-02-22 22:55:51 -0700749 if (params->auto_its) {
750 if (fit_build(params, tmpfile)) {
751 fprintf(stderr, "%s: failed to build FIT\n",
752 params->cmdname);
753 return EXIT_FAILURE;
754 }
755 *cmd = '\0';
756 } else if (params->datafile) {
Stefan Theilff6c3b22018-03-08 09:00:13 +0100757 /* dtc -I dts -O dtb -p 500 -o tmpfile datafile */
758 snprintf(cmd, sizeof(cmd), "%s %s -o \"%s\" \"%s\"",
759 MKIMAGE_DTC, params->dtc, tmpfile, params->datafile);
Simon Glassce8c3ca2013-06-13 15:10:05 -0700760 debug("Trying to execute \"%s\"\n", cmd);
761 } else {
Mirza, Taimoor74a21dd2017-10-04 20:28:03 +0500762 snprintf(cmd, sizeof(cmd), "cp \"%s\" \"%s\"",
Simon Glassce8c3ca2013-06-13 15:10:05 -0700763 params->imagefile, tmpfile);
764 }
Sven Roederercbcb3992020-04-27 02:08:39 +0200765 if (strlen(cmd) >= MKIMAGE_MAX_DTC_CMDLINE_LEN - 1) {
766 fprintf(stderr, "WARNING: command-line for FIT creation might be truncated and will probably fail.\n");
767 }
Philippe Reynes3148e422019-12-18 18:25:41 +0100768
Simon Glass88e31cb2016-02-22 22:55:51 -0700769 if (*cmd && system(cmd) == -1) {
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530770 fprintf (stderr, "%s: system(%s) failed: %s\n",
771 params->cmdname, cmd, strerror(errno));
Simon Glass4161c412013-05-08 08:05:57 +0000772 goto err_system;
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530773 }
774
Simon Glassd11b7002016-02-22 22:55:54 -0700775 /* Move the data so it is internal to the FIT, if needed */
776 ret = fit_import_data(params, tmpfile);
777 if (ret)
778 goto err_system;
779
Simon Glass802aa822014-06-02 22:04:53 -0600780 /*
Philippe Reynes3148e422019-12-18 18:25:41 +0100781 * Copy the tmpfile to bakfile, then in the following loop
782 * we copy bakfile to tmpfile. So we always start from the
783 * beginning.
784 */
785 sprintf(bakfile, "%s%s", tmpfile, ".bak");
786 rename(tmpfile, bakfile);
787
788 /*
Simon Glass802aa822014-06-02 22:04:53 -0600789 * Set hashes for images in the blob. Unfortunately we may need more
790 * space in either FDT, so keep trying until we succeed.
791 *
792 * Note: this is pretty inefficient for signing, since we must
793 * calculate the signature every time. It would be better to calculate
794 * all the data and then store it in a separate step. However, this
795 * would be considerably more complex to implement. Generally a few
796 * steps of this loop is enough to sign with several keys.
797 */
798 for (size_inc = 0; size_inc < 64 * 1024; size_inc += 1024) {
Philippe Reynes3148e422019-12-18 18:25:41 +0100799 if (copyfile(bakfile, tmpfile) < 0) {
800 printf("Can't copy %s to %s\n", bakfile, tmpfile);
801 ret = -EIO;
802 break;
803 }
Simon Glass802aa822014-06-02 22:04:53 -0600804 ret = fit_add_file_data(params, size_inc, tmpfile);
805 if (!ret || ret != -ENOSPC)
806 break;
Simon Glassb4d8b092013-06-13 15:10:04 -0700807 }
808
Simon Glass802aa822014-06-02 22:04:53 -0600809 if (ret) {
Simon Glass061752e2016-07-03 09:40:43 -0600810 fprintf(stderr, "%s Can't add hashes to FIT blob: %d\n",
811 params->cmdname, ret);
Simon Glass802aa822014-06-02 22:04:53 -0600812 goto err_system;
Simon Glassb4d8b092013-06-13 15:10:04 -0700813 }
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530814
Simon Glassafd728c2016-02-22 22:55:53 -0700815 /* Move the data so it is external to the FIT, if requested */
816 if (params->external_data) {
817 ret = fit_extract_data(params, tmpfile);
818 if (ret)
819 goto err_system;
820 }
821
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530822 if (rename (tmpfile, params->imagefile) == -1) {
823 fprintf (stderr, "%s: Can't rename %s to %s: %s\n",
824 params->cmdname, tmpfile, params->imagefile,
825 strerror (errno));
826 unlink (tmpfile);
Philippe Reynes3148e422019-12-18 18:25:41 +0100827 unlink(bakfile);
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530828 unlink (params->imagefile);
Simon Glass802aa822014-06-02 22:04:53 -0600829 return EXIT_FAILURE;
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530830 }
Philippe Reynes3148e422019-12-18 18:25:41 +0100831 unlink(bakfile);
Simon Glass802aa822014-06-02 22:04:53 -0600832 return EXIT_SUCCESS;
Simon Glass4161c412013-05-08 08:05:57 +0000833
Simon Glass4161c412013-05-08 08:05:57 +0000834err_system:
835 unlink(tmpfile);
Philippe Reynes3148e422019-12-18 18:25:41 +0100836 unlink(bakfile);
Simon Glass4161c412013-05-08 08:05:57 +0000837 return -1;
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530838}
839
Guilherme Maciel Ferreira3c46bcd2015-01-15 02:54:42 -0200840/**
841 * fit_image_extract - extract a FIT component image
842 * @fit: pointer to the FIT format image header
843 * @image_noffset: offset of the component image node
844 * @file_name: name of the file to store the FIT sub-image
845 *
846 * returns:
847 * zero in case of success or a negative value if fail.
848 */
849static int fit_image_extract(
850 const void *fit,
851 int image_noffset,
852 const char *file_name)
853{
854 const void *file_data;
855 size_t file_size = 0;
Andrew F. Davis166d5e92019-09-17 17:09:34 -0400856 int ret;
Guilherme Maciel Ferreira3c46bcd2015-01-15 02:54:42 -0200857
Andrew F. Davis166d5e92019-09-17 17:09:34 -0400858 /* get the data address and size of component at offset "image_noffset" */
859 ret = fit_image_get_data_and_size(fit, image_noffset, &file_data, &file_size);
860 if (ret) {
861 fprintf(stderr, "Could not get component information\n");
862 return ret;
863 }
Guilherme Maciel Ferreira3c46bcd2015-01-15 02:54:42 -0200864
865 /* save the "file_data" into the file specified by "file_name" */
866 return imagetool_save_subimage(file_name, (ulong) file_data, file_size);
867}
868
869/**
870 * fit_extract_contents - retrieve a sub-image component from the FIT image
871 * @ptr: pointer to the FIT format image header
872 * @params: command line parameters
873 *
874 * returns:
875 * zero in case of success or a negative value if fail.
876 */
877static int fit_extract_contents(void *ptr, struct image_tool_params *params)
878{
879 int images_noffset;
880 int noffset;
881 int ndepth;
882 const void *fit = ptr;
883 int count = 0;
884 const char *p;
885
886 /* Indent string is defined in header image.h */
887 p = IMAGE_INDENT_STRING;
888
Guilherme Maciel Ferreira3c46bcd2015-01-15 02:54:42 -0200889 /* Find images parent node offset */
890 images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
891 if (images_noffset < 0) {
892 printf("Can't find images parent node '%s' (%s)\n",
893 FIT_IMAGES_PATH, fdt_strerror(images_noffset));
894 return -1;
895 }
896
897 /* Avoid any overrun */
898 count = fit_get_subimage_count(fit, images_noffset);
899 if ((params->pflag < 0) || (count <= params->pflag)) {
900 printf("No such component at '%d'\n", params->pflag);
901 return -1;
902 }
903
904 /* Process its subnodes, extract the desired component from image */
905 for (ndepth = 0, count = 0,
906 noffset = fdt_next_node(fit, images_noffset, &ndepth);
907 (noffset >= 0) && (ndepth > 0);
908 noffset = fdt_next_node(fit, noffset, &ndepth)) {
909 if (ndepth == 1) {
910 /*
911 * Direct child node of the images parent node,
912 * i.e. component image node.
913 */
914 if (params->pflag == count) {
915 printf("Extracted:\n%s Image %u (%s)\n", p,
916 count, fit_get_name(fit, noffset, NULL));
917
918 fit_image_print(fit, noffset, p);
919
920 return fit_image_extract(fit, noffset,
921 params->outfile);
922 }
923
924 count++;
925 }
926 }
927
928 return 0;
929}
930
Guilherme Maciel Ferreira8ed4d1c2013-12-01 12:43:10 -0700931static int fit_check_params(struct image_tool_params *params)
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530932{
Simon Glass88e31cb2016-02-22 22:55:51 -0700933 if (params->auto_its)
934 return 0;
Heinrich Schuchardt915f5aa2019-12-11 13:51:38 +0100935 return ((params->dflag && params->fflag) ||
936 (params->fflag && params->lflag) ||
937 (params->lflag && params->dflag));
Prafulla Wadaskarfabf3cf2009-08-19 17:36:46 +0530938}
939
Guilherme Maciel Ferreira28be1cf2015-01-15 02:48:07 -0200940U_BOOT_IMAGE_TYPE(
941 fitimage,
942 "FIT Image support",
943 sizeof(image_header_t),
944 (void *)&header,
945 fit_check_params,
946 fit_verify_header,
947 fit_print_contents,
948 NULL,
Guilherme Maciel Ferreira3c46bcd2015-01-15 02:54:42 -0200949 fit_extract_contents,
Guilherme Maciel Ferreira28be1cf2015-01-15 02:48:07 -0200950 fit_check_image_types,
951 fit_handle_file,
952 NULL /* FIT images use DTB header */
953);