2 * Copyright (c) 2013, Google Inc.
4 * (C) Copyright 2008 Semihalf
6 * (C) Copyright 2000-2006
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * SPDX-License-Identifier: GPL-2.0+
16 #include <linux/compiler.h>
17 #include <linux/kconfig.h>
22 DECLARE_GLOBAL_DATA_PTR
;
23 #endif /* !USE_HOSTCC*/
26 #include <bootstage.h>
27 #include <u-boot/crc.h>
28 #include <u-boot/md5.h>
29 #include <u-boot/sha1.h>
30 #include <u-boot/sha256.h>
32 /*****************************************************************************/
33 /* New uImage format routines */
34 /*****************************************************************************/
36 static int fit_parse_spec(const char *spec
, char sepc
, ulong addr_curr
,
37 ulong
*addr
, const char **name
)
44 sep
= strchr(spec
, sepc
);
47 *addr
= simple_strtoul(spec
, NULL
, 16);
57 * fit_parse_conf - parse FIT configuration spec
58 * @spec: input string, containing configuration spec
59 * @add_curr: current image address (to be used as a possible default)
60 * @addr: pointer to a ulong variable, will hold FIT image address of a given
62 * @conf_name double pointer to a char, will hold pointer to a configuration
65 * fit_parse_conf() expects configuration spec in the form of [<addr>]#<conf>,
66 * where <addr> is a FIT image address that contains configuration
67 * with a <conf> unit name.
69 * Address part is optional, and if omitted default add_curr will
73 * 1 if spec is a valid configuration string,
74 * addr and conf_name are set accordingly
77 int fit_parse_conf(const char *spec
, ulong addr_curr
,
78 ulong
*addr
, const char **conf_name
)
80 return fit_parse_spec(spec
, '#', addr_curr
, addr
, conf_name
);
84 * fit_parse_subimage - parse FIT subimage spec
85 * @spec: input string, containing subimage spec
86 * @add_curr: current image address (to be used as a possible default)
87 * @addr: pointer to a ulong variable, will hold FIT image address of a given
89 * @image_name: double pointer to a char, will hold pointer to a subimage name
91 * fit_parse_subimage() expects subimage spec in the form of
92 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
93 * subimage with a <subimg> unit name.
95 * Address part is optional, and if omitted default add_curr will
99 * 1 if spec is a valid subimage string,
100 * addr and image_name are set accordingly
103 int fit_parse_subimage(const char *spec
, ulong addr_curr
,
104 ulong
*addr
, const char **image_name
)
106 return fit_parse_spec(spec
, ':', addr_curr
, addr
, image_name
);
108 #endif /* !USE_HOSTCC */
110 static void fit_get_debug(const void *fit
, int noffset
,
111 char *prop_name
, int err
)
113 debug("Can't get '%s' property from FIT 0x%08lx, node: offset %d, name %s (%s)\n",
114 prop_name
, (ulong
)fit
, noffset
, fit_get_name(fit
, noffset
, NULL
),
119 * fit_get_subimage_count - get component (sub-image) count
120 * @fit: pointer to the FIT format image header
121 * @images_noffset: offset of images node
124 * number of image components
126 int fit_get_subimage_count(const void *fit
, int images_noffset
)
132 /* Process its subnodes, print out component images details */
133 for (ndepth
= 0, count
= 0,
134 noffset
= fdt_next_node(fit
, images_noffset
, &ndepth
);
135 (noffset
>= 0) && (ndepth
> 0);
136 noffset
= fdt_next_node(fit
, noffset
, &ndepth
)) {
145 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_FIT_SPL_PRINT)
147 * fit_print_contents - prints out the contents of the FIT format image
148 * @fit: pointer to the FIT format image header
149 * @p: pointer to prefix string
151 * fit_print_contents() formats a multi line FIT image contents description.
152 * The routine prints out FIT image properties (root node level) followed by
153 * the details of each component image.
156 * no returned results
158 void fit_print_contents(const void *fit
)
171 /* Indent string is defined in header image.h */
172 p
= IMAGE_INDENT_STRING
;
174 /* Root node properties */
175 ret
= fit_get_desc(fit
, 0, &desc
);
176 printf("%sFIT description: ", p
);
178 printf("unavailable\n");
180 printf("%s\n", desc
);
182 if (IMAGE_ENABLE_TIMESTAMP
) {
183 ret
= fit_get_timestamp(fit
, 0, ×tamp
);
184 printf("%sCreated: ", p
);
186 printf("unavailable\n");
188 genimg_print_time(timestamp
);
191 /* Find images parent node offset */
192 images_noffset
= fdt_path_offset(fit
, FIT_IMAGES_PATH
);
193 if (images_noffset
< 0) {
194 printf("Can't find images parent node '%s' (%s)\n",
195 FIT_IMAGES_PATH
, fdt_strerror(images_noffset
));
199 /* Process its subnodes, print out component images details */
200 for (ndepth
= 0, count
= 0,
201 noffset
= fdt_next_node(fit
, images_noffset
, &ndepth
);
202 (noffset
>= 0) && (ndepth
> 0);
203 noffset
= fdt_next_node(fit
, noffset
, &ndepth
)) {
206 * Direct child node of the images parent node,
207 * i.e. component image node.
209 printf("%s Image %u (%s)\n", p
, count
++,
210 fit_get_name(fit
, noffset
, NULL
));
212 fit_image_print(fit
, noffset
, p
);
216 /* Find configurations parent node offset */
217 confs_noffset
= fdt_path_offset(fit
, FIT_CONFS_PATH
);
218 if (confs_noffset
< 0) {
219 debug("Can't get configurations parent node '%s' (%s)\n",
220 FIT_CONFS_PATH
, fdt_strerror(confs_noffset
));
224 /* get default configuration unit name from default property */
225 uname
= (char *)fdt_getprop(fit
, noffset
, FIT_DEFAULT_PROP
, NULL
);
227 printf("%s Default Configuration: '%s'\n", p
, uname
);
229 /* Process its subnodes, print out configurations details */
230 for (ndepth
= 0, count
= 0,
231 noffset
= fdt_next_node(fit
, confs_noffset
, &ndepth
);
232 (noffset
>= 0) && (ndepth
> 0);
233 noffset
= fdt_next_node(fit
, noffset
, &ndepth
)) {
236 * Direct child node of the configurations parent node,
237 * i.e. configuration node.
239 printf("%s Configuration %u (%s)\n", p
, count
++,
240 fit_get_name(fit
, noffset
, NULL
));
242 fit_conf_print(fit
, noffset
, p
);
248 * fit_image_print_data() - prints out the hash node details
249 * @fit: pointer to the FIT format image header
250 * @noffset: offset of the hash node
251 * @p: pointer to prefix string
252 * @type: Type of information to print ("hash" or "sign")
254 * fit_image_print_data() lists properties for the processed hash node
256 * This function avoid using puts() since it prints a newline on the host
257 * but does not in U-Boot.
260 * no returned results
262 static void fit_image_print_data(const void *fit
, int noffset
, const char *p
,
272 debug("%s %s node: '%s'\n", p
, type
,
273 fit_get_name(fit
, noffset
, NULL
));
274 printf("%s %s algo: ", p
, type
);
275 if (fit_image_hash_get_algo(fit
, noffset
, &algo
)) {
276 printf("invalid/unsupported\n");
280 keyname
= fdt_getprop(fit
, noffset
, "key-name-hint", NULL
);
281 required
= fdt_getprop(fit
, noffset
, "required", NULL
) != NULL
;
283 printf(":%s", keyname
);
285 printf(" (required)");
288 ret
= fit_image_hash_get_value(fit
, noffset
, &value
,
290 printf("%s %s value: ", p
, type
);
292 printf("unavailable\n");
294 for (i
= 0; i
< value_len
; i
++)
295 printf("%02x", value
[i
]);
299 debug("%s %s len: %d\n", p
, type
, value_len
);
301 /* Signatures have a time stamp */
302 if (IMAGE_ENABLE_TIMESTAMP
&& keyname
) {
305 printf("%s Timestamp: ", p
);
306 if (fit_get_timestamp(fit
, noffset
, ×tamp
))
307 printf("unavailable\n");
309 genimg_print_time(timestamp
);
314 * fit_image_print_verification_data() - prints out the hash/signature details
315 * @fit: pointer to the FIT format image header
316 * @noffset: offset of the hash or signature node
317 * @p: pointer to prefix string
319 * This lists properties for the processed hash node
322 * no returned results
324 static void fit_image_print_verification_data(const void *fit
, int noffset
,
330 * Check subnode name, must be equal to "hash" or "signature".
331 * Multiple hash/signature nodes require unique unit node
332 * names, e.g. hash@1, hash@2, signature@1, signature@2, etc.
334 name
= fit_get_name(fit
, noffset
, NULL
);
335 if (!strncmp(name
, FIT_HASH_NODENAME
, strlen(FIT_HASH_NODENAME
))) {
336 fit_image_print_data(fit
, noffset
, p
, "Hash");
337 } else if (!strncmp(name
, FIT_SIG_NODENAME
,
338 strlen(FIT_SIG_NODENAME
))) {
339 fit_image_print_data(fit
, noffset
, p
, "Sign");
344 * fit_image_print - prints out the FIT component image details
345 * @fit: pointer to the FIT format image header
346 * @image_noffset: offset of the component image node
347 * @p: pointer to prefix string
349 * fit_image_print() lists all mandatory properties for the processed component
350 * image. If present, hash nodes are printed out as well. Load
351 * address for images of type firmware is also printed out. Since the load
352 * address is not mandatory for firmware images, it will be output as
353 * "unavailable" when not present.
356 * no returned results
358 void fit_image_print(const void *fit
, int image_noffset
, const char *p
)
361 uint8_t type
, arch
, os
, comp
;
369 /* Mandatory properties */
370 ret
= fit_get_desc(fit
, image_noffset
, &desc
);
371 printf("%s Description: ", p
);
373 printf("unavailable\n");
375 printf("%s\n", desc
);
377 if (IMAGE_ENABLE_TIMESTAMP
) {
380 ret
= fit_get_timestamp(fit
, 0, ×tamp
);
381 printf("%s Created: ", p
);
383 printf("unavailable\n");
385 genimg_print_time(timestamp
);
388 fit_image_get_type(fit
, image_noffset
, &type
);
389 printf("%s Type: %s\n", p
, genimg_get_type_name(type
));
391 fit_image_get_comp(fit
, image_noffset
, &comp
);
392 printf("%s Compression: %s\n", p
, genimg_get_comp_name(comp
));
394 ret
= fit_image_get_data(fit
, image_noffset
, &data
, &size
);
397 printf("%s Data Start: ", p
);
399 printf("unavailable\n");
401 void *vdata
= (void *)data
;
403 printf("0x%08lx\n", (ulong
)map_to_sysmem(vdata
));
407 printf("%s Data Size: ", p
);
409 printf("unavailable\n");
411 genimg_print_size(size
);
413 /* Remaining, type dependent properties */
414 if ((type
== IH_TYPE_KERNEL
) || (type
== IH_TYPE_STANDALONE
) ||
415 (type
== IH_TYPE_RAMDISK
) || (type
== IH_TYPE_FIRMWARE
) ||
416 (type
== IH_TYPE_FLATDT
)) {
417 fit_image_get_arch(fit
, image_noffset
, &arch
);
418 printf("%s Architecture: %s\n", p
, genimg_get_arch_name(arch
));
421 if ((type
== IH_TYPE_KERNEL
) || (type
== IH_TYPE_RAMDISK
)) {
422 fit_image_get_os(fit
, image_noffset
, &os
);
423 printf("%s OS: %s\n", p
, genimg_get_os_name(os
));
426 if ((type
== IH_TYPE_KERNEL
) || (type
== IH_TYPE_STANDALONE
) ||
427 (type
== IH_TYPE_FIRMWARE
) || (type
== IH_TYPE_RAMDISK
) ||
428 (type
== IH_TYPE_FPGA
)) {
429 ret
= fit_image_get_load(fit
, image_noffset
, &load
);
430 printf("%s Load Address: ", p
);
432 printf("unavailable\n");
434 printf("0x%08lx\n", load
);
437 if ((type
== IH_TYPE_KERNEL
) || (type
== IH_TYPE_STANDALONE
) ||
438 (type
== IH_TYPE_RAMDISK
)) {
439 ret
= fit_image_get_entry(fit
, image_noffset
, &entry
);
440 printf("%s Entry Point: ", p
);
442 printf("unavailable\n");
444 printf("0x%08lx\n", entry
);
447 /* Process all hash subnodes of the component image node */
448 for (ndepth
= 0, noffset
= fdt_next_node(fit
, image_noffset
, &ndepth
);
449 (noffset
>= 0) && (ndepth
> 0);
450 noffset
= fdt_next_node(fit
, noffset
, &ndepth
)) {
452 /* Direct child node of the component image node */
453 fit_image_print_verification_data(fit
, noffset
, p
);
458 #endif /* !defined(CONFIG_SPL_BUILD) || defined(CONFIG_FIT_SPL_PRINT) */
461 * fit_get_desc - get node description property
462 * @fit: pointer to the FIT format image header
463 * @noffset: node offset
464 * @desc: double pointer to the char, will hold pointer to the description
466 * fit_get_desc() reads description property from a given node, if
467 * description is found pointer to it is returned in third call argument.
473 int fit_get_desc(const void *fit
, int noffset
, char **desc
)
477 *desc
= (char *)fdt_getprop(fit
, noffset
, FIT_DESC_PROP
, &len
);
479 fit_get_debug(fit
, noffset
, FIT_DESC_PROP
, len
);
487 * fit_get_timestamp - get node timestamp property
488 * @fit: pointer to the FIT format image header
489 * @noffset: node offset
490 * @timestamp: pointer to the time_t, will hold read timestamp
492 * fit_get_timestamp() reads timestamp property from given node, if timestamp
493 * is found and has a correct size its value is returned in third call
498 * -1, on property read failure
499 * -2, on wrong timestamp size
501 int fit_get_timestamp(const void *fit
, int noffset
, time_t *timestamp
)
506 data
= fdt_getprop(fit
, noffset
, FIT_TIMESTAMP_PROP
, &len
);
508 fit_get_debug(fit
, noffset
, FIT_TIMESTAMP_PROP
, len
);
511 if (len
!= sizeof(uint32_t)) {
512 debug("FIT timestamp with incorrect size of (%u)\n", len
);
516 *timestamp
= uimage_to_cpu(*((uint32_t *)data
));
521 * fit_image_get_node - get node offset for component image of a given unit name
522 * @fit: pointer to the FIT format image header
523 * @image_uname: component image node unit name
525 * fit_image_get_node() finds a component image (within the '/images'
526 * node) of a provided unit name. If image is found its node offset is
527 * returned to the caller.
530 * image node offset when found (>=0)
531 * negative number on failure (FDT_ERR_* code)
533 int fit_image_get_node(const void *fit
, const char *image_uname
)
535 int noffset
, images_noffset
;
537 images_noffset
= fdt_path_offset(fit
, FIT_IMAGES_PATH
);
538 if (images_noffset
< 0) {
539 debug("Can't find images parent node '%s' (%s)\n",
540 FIT_IMAGES_PATH
, fdt_strerror(images_noffset
));
541 return images_noffset
;
544 noffset
= fdt_subnode_offset(fit
, images_noffset
, image_uname
);
546 debug("Can't get node offset for image unit name: '%s' (%s)\n",
547 image_uname
, fdt_strerror(noffset
));
554 * fit_image_get_os - get os id for a given component image node
555 * @fit: pointer to the FIT format image header
556 * @noffset: component image node offset
557 * @os: pointer to the uint8_t, will hold os numeric id
559 * fit_image_get_os() finds os property in a given component image node.
560 * If the property is found, its (string) value is translated to the numeric
561 * id which is returned to the caller.
567 int fit_image_get_os(const void *fit
, int noffset
, uint8_t *os
)
572 /* Get OS name from property data */
573 data
= fdt_getprop(fit
, noffset
, FIT_OS_PROP
, &len
);
575 fit_get_debug(fit
, noffset
, FIT_OS_PROP
, len
);
580 /* Translate OS name to id */
581 *os
= genimg_get_os_id(data
);
586 * fit_image_get_arch - get arch id for a given component image node
587 * @fit: pointer to the FIT format image header
588 * @noffset: component image node offset
589 * @arch: pointer to the uint8_t, will hold arch numeric id
591 * fit_image_get_arch() finds arch property in a given component image node.
592 * If the property is found, its (string) value is translated to the numeric
593 * id which is returned to the caller.
599 int fit_image_get_arch(const void *fit
, int noffset
, uint8_t *arch
)
604 /* Get architecture name from property data */
605 data
= fdt_getprop(fit
, noffset
, FIT_ARCH_PROP
, &len
);
607 fit_get_debug(fit
, noffset
, FIT_ARCH_PROP
, len
);
612 /* Translate architecture name to id */
613 *arch
= genimg_get_arch_id(data
);
618 * fit_image_get_type - get type id for a given component image node
619 * @fit: pointer to the FIT format image header
620 * @noffset: component image node offset
621 * @type: pointer to the uint8_t, will hold type numeric id
623 * fit_image_get_type() finds type property in a given component image node.
624 * If the property is found, its (string) value is translated to the numeric
625 * id which is returned to the caller.
631 int fit_image_get_type(const void *fit
, int noffset
, uint8_t *type
)
636 /* Get image type name from property data */
637 data
= fdt_getprop(fit
, noffset
, FIT_TYPE_PROP
, &len
);
639 fit_get_debug(fit
, noffset
, FIT_TYPE_PROP
, len
);
644 /* Translate image type name to id */
645 *type
= genimg_get_type_id(data
);
650 * fit_image_get_comp - get comp id for a given component image node
651 * @fit: pointer to the FIT format image header
652 * @noffset: component image node offset
653 * @comp: pointer to the uint8_t, will hold comp numeric id
655 * fit_image_get_comp() finds comp property in a given component image node.
656 * If the property is found, its (string) value is translated to the numeric
657 * id which is returned to the caller.
663 int fit_image_get_comp(const void *fit
, int noffset
, uint8_t *comp
)
668 /* Get compression name from property data */
669 data
= fdt_getprop(fit
, noffset
, FIT_COMP_PROP
, &len
);
671 fit_get_debug(fit
, noffset
, FIT_COMP_PROP
, len
);
676 /* Translate compression name to id */
677 *comp
= genimg_get_comp_id(data
);
681 static int fit_image_get_address(const void *fit
, int noffset
, char *name
,
688 cell
= fdt_getprop(fit
, noffset
, name
, &len
);
690 fit_get_debug(fit
, noffset
, name
, len
);
694 if (len
> sizeof(ulong
)) {
695 printf("Unsupported %s address size\n", name
);
700 /* Use load64 to avoid compiling warning for 32-bit target */
702 load64
= (load64
<< 32) | uimage_to_cpu(*cell
);
705 *load
= (ulong
)load64
;
710 * fit_image_get_load() - get load addr property for given component image node
711 * @fit: pointer to the FIT format image header
712 * @noffset: component image node offset
713 * @load: pointer to the uint32_t, will hold load address
715 * fit_image_get_load() finds load address property in a given component
716 * image node. If the property is found, its value is returned to the caller.
722 int fit_image_get_load(const void *fit
, int noffset
, ulong
*load
)
724 return fit_image_get_address(fit
, noffset
, FIT_LOAD_PROP
, load
);
728 * fit_image_get_entry() - get entry point address property
729 * @fit: pointer to the FIT format image header
730 * @noffset: component image node offset
731 * @entry: pointer to the uint32_t, will hold entry point address
733 * This gets the entry point address property for a given component image
736 * fit_image_get_entry() finds entry point address property in a given
737 * component image node. If the property is found, its value is returned
744 int fit_image_get_entry(const void *fit
, int noffset
, ulong
*entry
)
746 return fit_image_get_address(fit
, noffset
, FIT_ENTRY_PROP
, entry
);
750 * fit_image_get_data - get data property and its size for a given component image node
751 * @fit: pointer to the FIT format image header
752 * @noffset: component image node offset
753 * @data: double pointer to void, will hold data property's data address
754 * @size: pointer to size_t, will hold data property's data size
756 * fit_image_get_data() finds data property in a given component image node.
757 * If the property is found its data start address and size are returned to
764 int fit_image_get_data(const void *fit
, int noffset
,
765 const void **data
, size_t *size
)
769 *data
= fdt_getprop(fit
, noffset
, FIT_DATA_PROP
, &len
);
771 fit_get_debug(fit
, noffset
, FIT_DATA_PROP
, len
);
781 * Get 'data-offset' property from a given image node.
783 * @fit: pointer to the FIT image header
784 * @noffset: component image node offset
785 * @data_offset: holds the data-offset property
789 * -ENOENT if the property could not be found
791 int fit_image_get_data_offset(const void *fit
, int noffset
, int *data_offset
)
795 val
= fdt_getprop(fit
, noffset
, FIT_DATA_OFFSET_PROP
, NULL
);
799 *data_offset
= fdt32_to_cpu(*val
);
805 * Get 'data-size' property from a given image node.
807 * @fit: pointer to the FIT image header
808 * @noffset: component image node offset
809 * @data_size: holds the data-size property
813 * -ENOENT if the property could not be found
815 int fit_image_get_data_size(const void *fit
, int noffset
, int *data_size
)
819 val
= fdt_getprop(fit
, noffset
, FIT_DATA_SIZE_PROP
, NULL
);
823 *data_size
= fdt32_to_cpu(*val
);
829 * fit_image_hash_get_algo - get hash algorithm name
830 * @fit: pointer to the FIT format image header
831 * @noffset: hash node offset
832 * @algo: double pointer to char, will hold pointer to the algorithm name
834 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
835 * If the property is found its data start address is returned to the caller.
841 int fit_image_hash_get_algo(const void *fit
, int noffset
, char **algo
)
845 *algo
= (char *)fdt_getprop(fit
, noffset
, FIT_ALGO_PROP
, &len
);
847 fit_get_debug(fit
, noffset
, FIT_ALGO_PROP
, len
);
855 * fit_image_hash_get_value - get hash value and length
856 * @fit: pointer to the FIT format image header
857 * @noffset: hash node offset
858 * @value: double pointer to uint8_t, will hold address of a hash value data
859 * @value_len: pointer to an int, will hold hash data length
861 * fit_image_hash_get_value() finds hash value property in a given hash node.
862 * If the property is found its data start address and size are returned to
869 int fit_image_hash_get_value(const void *fit
, int noffset
, uint8_t **value
,
874 *value
= (uint8_t *)fdt_getprop(fit
, noffset
, FIT_VALUE_PROP
, &len
);
875 if (*value
== NULL
) {
876 fit_get_debug(fit
, noffset
, FIT_VALUE_PROP
, len
);
886 * fit_image_hash_get_ignore - get hash ignore flag
887 * @fit: pointer to the FIT format image header
888 * @noffset: hash node offset
889 * @ignore: pointer to an int, will hold hash ignore flag
891 * fit_image_hash_get_ignore() finds hash ignore property in a given hash node.
892 * If the property is found and non-zero, the hash algorithm is not verified by
893 * u-boot automatically.
896 * 0, on ignore not found
897 * value, on ignore found
899 static int fit_image_hash_get_ignore(const void *fit
, int noffset
, int *ignore
)
904 value
= (int *)fdt_getprop(fit
, noffset
, FIT_IGNORE_PROP
, &len
);
905 if (value
== NULL
|| len
!= sizeof(int))
913 ulong
fit_get_end(const void *fit
)
915 return map_to_sysmem((void *)(fit
+ fdt_totalsize(fit
)));
919 * fit_set_timestamp - set node timestamp property
920 * @fit: pointer to the FIT format image header
921 * @noffset: node offset
922 * @timestamp: timestamp value to be set
924 * fit_set_timestamp() attempts to set timestamp property in the requested
925 * node and returns operation status to the caller.
929 * -ENOSPC if no space in device tree, -1 for other error
931 int fit_set_timestamp(void *fit
, int noffset
, time_t timestamp
)
936 t
= cpu_to_uimage(timestamp
);
937 ret
= fdt_setprop(fit
, noffset
, FIT_TIMESTAMP_PROP
, &t
,
940 debug("Can't set '%s' property for '%s' node (%s)\n",
941 FIT_TIMESTAMP_PROP
, fit_get_name(fit
, noffset
, NULL
),
943 return ret
== -FDT_ERR_NOSPACE
? -ENOSPC
: -1;
950 * calculate_hash - calculate and return hash for provided input data
951 * @data: pointer to the input data
952 * @data_len: data length
953 * @algo: requested hash algorithm
954 * @value: pointer to the char, will hold hash value data (caller must
955 * allocate enough free space)
956 * value_len: length of the calculated hash
958 * calculate_hash() computes input data hash according to the requested
960 * Resulting hash value is placed in caller provided 'value' buffer, length
961 * of the calculated hash is returned via value_len pointer argument.
965 * -1, when algo is unsupported
967 int calculate_hash(const void *data
, int data_len
, const char *algo
,
968 uint8_t *value
, int *value_len
)
970 if (IMAGE_ENABLE_CRC32
&& strcmp(algo
, "crc32") == 0) {
971 *((uint32_t *)value
) = crc32_wd(0, data
, data_len
,
973 *((uint32_t *)value
) = cpu_to_uimage(*((uint32_t *)value
));
975 } else if (IMAGE_ENABLE_SHA1
&& strcmp(algo
, "sha1") == 0) {
976 sha1_csum_wd((unsigned char *)data
, data_len
,
977 (unsigned char *)value
, CHUNKSZ_SHA1
);
979 } else if (IMAGE_ENABLE_SHA256
&& strcmp(algo
, "sha256") == 0) {
980 sha256_csum_wd((unsigned char *)data
, data_len
,
981 (unsigned char *)value
, CHUNKSZ_SHA256
);
982 *value_len
= SHA256_SUM_LEN
;
983 } else if (IMAGE_ENABLE_MD5
&& strcmp(algo
, "md5") == 0) {
984 md5_wd((unsigned char *)data
, data_len
, value
, CHUNKSZ_MD5
);
987 debug("Unsupported hash alogrithm\n");
993 static int fit_image_check_hash(const void *fit
, int noffset
, const void *data
,
994 size_t size
, char **err_msgp
)
996 uint8_t value
[FIT_MAX_HASH_LEN
];
1005 if (fit_image_hash_get_algo(fit
, noffset
, &algo
)) {
1006 *err_msgp
= "Can't get hash algo property";
1011 if (IMAGE_ENABLE_IGNORE
) {
1012 fit_image_hash_get_ignore(fit
, noffset
, &ignore
);
1014 printf("-skipped ");
1019 if (fit_image_hash_get_value(fit
, noffset
, &fit_value
,
1021 *err_msgp
= "Can't get hash value property";
1025 if (calculate_hash(data
, size
, algo
, value
, &value_len
)) {
1026 *err_msgp
= "Unsupported hash algorithm";
1030 if (value_len
!= fit_value_len
) {
1031 *err_msgp
= "Bad hash value len";
1033 } else if (memcmp(value
, fit_value
, value_len
) != 0) {
1034 *err_msgp
= "Bad hash value";
1042 * fit_image_verify - verify data integrity
1043 * @fit: pointer to the FIT format image header
1044 * @image_noffset: component image node offset
1046 * fit_image_verify() goes over component image hash nodes,
1047 * re-calculates each data hash and compares with the value stored in hash
1051 * 1, if all hashes are valid
1052 * 0, otherwise (or on error)
1054 int fit_image_verify(const void *fit
, int image_noffset
)
1063 /* Get image data and data length */
1064 if (fit_image_get_data(fit
, image_noffset
, &data
, &size
)) {
1065 err_msg
= "Can't get image data/size";
1069 /* Verify all required signatures */
1070 if (IMAGE_ENABLE_VERIFY
&&
1071 fit_image_verify_required_sigs(fit
, image_noffset
, data
, size
,
1072 gd_fdt_blob(), &verify_all
)) {
1073 err_msg
= "Unable to verify required signature";
1077 /* Process all hash subnodes of the component image node */
1078 fdt_for_each_subnode(noffset
, fit
, image_noffset
) {
1079 const char *name
= fit_get_name(fit
, noffset
, NULL
);
1082 * Check subnode name, must be equal to "hash".
1083 * Multiple hash nodes require unique unit node
1084 * names, e.g. hash@1, hash@2, etc.
1086 if (!strncmp(name
, FIT_HASH_NODENAME
,
1087 strlen(FIT_HASH_NODENAME
))) {
1088 if (fit_image_check_hash(fit
, noffset
, data
, size
,
1092 } else if (IMAGE_ENABLE_VERIFY
&& verify_all
&&
1093 !strncmp(name
, FIT_SIG_NODENAME
,
1094 strlen(FIT_SIG_NODENAME
))) {
1095 ret
= fit_image_check_sig(fit
, noffset
, data
,
1096 size
, -1, &err_msg
);
1099 * Show an indication on failure, but do not return
1100 * an error. Only keys marked 'required' can cause
1101 * an image validation failure. See the call to
1102 * fit_image_verify_required_sigs() above.
1111 if (noffset
== -FDT_ERR_TRUNCATED
|| noffset
== -FDT_ERR_BADSTRUCTURE
) {
1112 err_msg
= "Corrupted or truncated tree";
1119 printf(" error!\n%s for '%s' hash node in '%s' image node\n",
1120 err_msg
, fit_get_name(fit
, noffset
, NULL
),
1121 fit_get_name(fit
, image_noffset
, NULL
));
1126 * fit_all_image_verify - verify data integrity for all images
1127 * @fit: pointer to the FIT format image header
1129 * fit_all_image_verify() goes over all images in the FIT and
1130 * for every images checks if all it's hashes are valid.
1133 * 1, if all hashes of all images are valid
1134 * 0, otherwise (or on error)
1136 int fit_all_image_verify(const void *fit
)
1143 /* Find images parent node offset */
1144 images_noffset
= fdt_path_offset(fit
, FIT_IMAGES_PATH
);
1145 if (images_noffset
< 0) {
1146 printf("Can't find images parent node '%s' (%s)\n",
1147 FIT_IMAGES_PATH
, fdt_strerror(images_noffset
));
1151 /* Process all image subnodes, check hashes for each */
1152 printf("## Checking hash(es) for FIT Image at %08lx ...\n",
1154 for (ndepth
= 0, count
= 0,
1155 noffset
= fdt_next_node(fit
, images_noffset
, &ndepth
);
1156 (noffset
>= 0) && (ndepth
> 0);
1157 noffset
= fdt_next_node(fit
, noffset
, &ndepth
)) {
1160 * Direct child node of the images parent node,
1161 * i.e. component image node.
1163 printf(" Hash(es) for Image %u (%s): ", count
,
1164 fit_get_name(fit
, noffset
, NULL
));
1167 if (!fit_image_verify(fit
, noffset
))
1176 * fit_image_check_os - check whether image node is of a given os type
1177 * @fit: pointer to the FIT format image header
1178 * @noffset: component image node offset
1179 * @os: requested image os
1181 * fit_image_check_os() reads image os property and compares its numeric
1182 * id with the requested os. Comparison result is returned to the caller.
1185 * 1 if image is of given os type
1186 * 0 otherwise (or on error)
1188 int fit_image_check_os(const void *fit
, int noffset
, uint8_t os
)
1192 if (fit_image_get_os(fit
, noffset
, &image_os
))
1194 return (os
== image_os
);
1198 * fit_image_check_arch - check whether image node is of a given arch
1199 * @fit: pointer to the FIT format image header
1200 * @noffset: component image node offset
1201 * @arch: requested imagearch
1203 * fit_image_check_arch() reads image arch property and compares its numeric
1204 * id with the requested arch. Comparison result is returned to the caller.
1207 * 1 if image is of given arch
1208 * 0 otherwise (or on error)
1210 int fit_image_check_arch(const void *fit
, int noffset
, uint8_t arch
)
1213 int aarch32_support
= 0;
1215 #ifdef CONFIG_ARM64_SUPPORT_AARCH32
1216 aarch32_support
= 1;
1219 if (fit_image_get_arch(fit
, noffset
, &image_arch
))
1221 return (arch
== image_arch
) ||
1222 (arch
== IH_ARCH_I386
&& image_arch
== IH_ARCH_X86_64
) ||
1223 (arch
== IH_ARCH_ARM64
&& image_arch
== IH_ARCH_ARM
&&
1228 * fit_image_check_type - check whether image node is of a given type
1229 * @fit: pointer to the FIT format image header
1230 * @noffset: component image node offset
1231 * @type: requested image type
1233 * fit_image_check_type() reads image type property and compares its numeric
1234 * id with the requested type. Comparison result is returned to the caller.
1237 * 1 if image is of given type
1238 * 0 otherwise (or on error)
1240 int fit_image_check_type(const void *fit
, int noffset
, uint8_t type
)
1244 if (fit_image_get_type(fit
, noffset
, &image_type
))
1246 return (type
== image_type
);
1250 * fit_image_check_comp - check whether image node uses given compression
1251 * @fit: pointer to the FIT format image header
1252 * @noffset: component image node offset
1253 * @comp: requested image compression type
1255 * fit_image_check_comp() reads image compression property and compares its
1256 * numeric id with the requested compression type. Comparison result is
1257 * returned to the caller.
1260 * 1 if image uses requested compression
1261 * 0 otherwise (or on error)
1263 int fit_image_check_comp(const void *fit
, int noffset
, uint8_t comp
)
1267 if (fit_image_get_comp(fit
, noffset
, &image_comp
))
1269 return (comp
== image_comp
);
1273 * fit_check_format - sanity check FIT image format
1274 * @fit: pointer to the FIT format image header
1276 * fit_check_format() runs a basic sanity FIT image verification.
1277 * Routine checks for mandatory properties, nodes, etc.
1283 int fit_check_format(const void *fit
)
1285 /* mandatory / node 'description' property */
1286 if (fdt_getprop(fit
, 0, FIT_DESC_PROP
, NULL
) == NULL
) {
1287 debug("Wrong FIT format: no description\n");
1291 if (IMAGE_ENABLE_TIMESTAMP
) {
1292 /* mandatory / node 'timestamp' property */
1293 if (fdt_getprop(fit
, 0, FIT_TIMESTAMP_PROP
, NULL
) == NULL
) {
1294 debug("Wrong FIT format: no timestamp\n");
1299 /* mandatory subimages parent '/images' node */
1300 if (fdt_path_offset(fit
, FIT_IMAGES_PATH
) < 0) {
1301 debug("Wrong FIT format: no images parent node\n");
1310 * fit_conf_find_compat
1311 * @fit: pointer to the FIT format image header
1312 * @fdt: pointer to the device tree to compare against
1314 * fit_conf_find_compat() attempts to find the configuration whose fdt is the
1315 * most compatible with the passed in device tree.
1324 * |-o configurations
1332 * |-compatible = "foo,bar", "bim,bam"
1335 * |-compatible = "foo,bar",
1338 * |-compatible = "bim,bam", "baz,biz"
1340 * Configuration 1 would be picked because the first string in U-Boot's
1341 * compatible list, "foo,bar", matches a compatible string in the root of fdt1.
1342 * "bim,bam" in fdt2 matches the second string which isn't as good as fdt1.
1345 * offset to the configuration to use if one was found
1348 int fit_conf_find_compat(const void *fit
, const void *fdt
)
1351 int noffset
, confs_noffset
, images_noffset
;
1352 const void *fdt_compat
;
1354 int best_match_offset
= 0;
1355 int best_match_pos
= 0;
1357 confs_noffset
= fdt_path_offset(fit
, FIT_CONFS_PATH
);
1358 images_noffset
= fdt_path_offset(fit
, FIT_IMAGES_PATH
);
1359 if (confs_noffset
< 0 || images_noffset
< 0) {
1360 debug("Can't find configurations or images nodes.\n");
1364 fdt_compat
= fdt_getprop(fdt
, 0, "compatible", &fdt_compat_len
);
1366 debug("Fdt for comparison has no \"compatible\" property.\n");
1371 * Loop over the configurations in the FIT image.
1373 for (noffset
= fdt_next_node(fit
, confs_noffset
, &ndepth
);
1374 (noffset
>= 0) && (ndepth
> 0);
1375 noffset
= fdt_next_node(fit
, noffset
, &ndepth
)) {
1377 const char *kfdt_name
;
1379 const char *cur_fdt_compat
;
1387 kfdt_name
= fdt_getprop(fit
, noffset
, "fdt", &len
);
1389 debug("No fdt property found.\n");
1392 kfdt_noffset
= fdt_subnode_offset(fit
, images_noffset
,
1394 if (kfdt_noffset
< 0) {
1395 debug("No image node named \"%s\" found.\n",
1400 * Get a pointer to this configuration's fdt.
1402 if (fit_image_get_data(fit
, kfdt_noffset
, &kfdt
, &size
)) {
1403 debug("Failed to get fdt \"%s\".\n", kfdt_name
);
1407 len
= fdt_compat_len
;
1408 cur_fdt_compat
= fdt_compat
;
1410 * Look for a match for each U-Boot compatibility string in
1411 * turn in this configuration's fdt.
1413 for (i
= 0; len
> 0 &&
1414 (!best_match_offset
|| best_match_pos
> i
); i
++) {
1415 int cur_len
= strlen(cur_fdt_compat
) + 1;
1417 if (!fdt_node_check_compatible(kfdt
, 0,
1419 best_match_offset
= noffset
;
1424 cur_fdt_compat
+= cur_len
;
1427 if (!best_match_offset
) {
1428 debug("No match found.\n");
1432 return best_match_offset
;
1436 * fit_conf_get_node - get node offset for configuration of a given unit name
1437 * @fit: pointer to the FIT format image header
1438 * @conf_uname: configuration node unit name
1440 * fit_conf_get_node() finds a configuration (within the '/configurations'
1441 * parent node) of a provided unit name. If configuration is found its node
1442 * offset is returned to the caller.
1444 * When NULL is provided in second argument fit_conf_get_node() will search
1445 * for a default configuration node instead. Default configuration node unit
1446 * name is retrieved from FIT_DEFAULT_PROP property of the '/configurations'
1450 * configuration node offset when found (>=0)
1451 * negative number on failure (FDT_ERR_* code)
1453 int fit_conf_get_node(const void *fit
, const char *conf_uname
)
1455 int noffset
, confs_noffset
;
1458 confs_noffset
= fdt_path_offset(fit
, FIT_CONFS_PATH
);
1459 if (confs_noffset
< 0) {
1460 debug("Can't find configurations parent node '%s' (%s)\n",
1461 FIT_CONFS_PATH
, fdt_strerror(confs_noffset
));
1462 return confs_noffset
;
1465 if (conf_uname
== NULL
) {
1466 /* get configuration unit name from the default property */
1467 debug("No configuration specified, trying default...\n");
1468 conf_uname
= (char *)fdt_getprop(fit
, confs_noffset
,
1469 FIT_DEFAULT_PROP
, &len
);
1470 if (conf_uname
== NULL
) {
1471 fit_get_debug(fit
, confs_noffset
, FIT_DEFAULT_PROP
,
1475 debug("Found default configuration: '%s'\n", conf_uname
);
1478 noffset
= fdt_subnode_offset(fit
, confs_noffset
, conf_uname
);
1480 debug("Can't get node offset for configuration unit name: '%s' (%s)\n",
1481 conf_uname
, fdt_strerror(noffset
));
1487 int fit_conf_get_prop_node(const void *fit
, int noffset
,
1488 const char *prop_name
)
1493 /* get kernel image unit name from configuration kernel property */
1494 uname
= (char *)fdt_getprop(fit
, noffset
, prop_name
, &len
);
1498 return fit_image_get_node(fit
, uname
);
1502 * fit_conf_print - prints out the FIT configuration details
1503 * @fit: pointer to the FIT format image header
1504 * @noffset: offset of the configuration node
1505 * @p: pointer to prefix string
1507 * fit_conf_print() lists all mandatory properties for the processed
1508 * configuration node.
1511 * no returned results
1513 void fit_conf_print(const void *fit
, int noffset
, const char *p
)
1518 int loadables_index
;
1520 /* Mandatory properties */
1521 ret
= fit_get_desc(fit
, noffset
, &desc
);
1522 printf("%s Description: ", p
);
1524 printf("unavailable\n");
1526 printf("%s\n", desc
);
1528 uname
= fdt_getprop(fit
, noffset
, FIT_KERNEL_PROP
, NULL
);
1529 printf("%s Kernel: ", p
);
1531 printf("unavailable\n");
1533 printf("%s\n", uname
);
1535 /* Optional properties */
1536 uname
= fdt_getprop(fit
, noffset
, FIT_RAMDISK_PROP
, NULL
);
1538 printf("%s Init Ramdisk: %s\n", p
, uname
);
1540 uname
= fdt_getprop(fit
, noffset
, FIT_FDT_PROP
, NULL
);
1542 printf("%s FDT: %s\n", p
, uname
);
1544 uname
= fdt_getprop(fit
, noffset
, FIT_FPGA_PROP
, NULL
);
1546 printf("%s FPGA: %s\n", p
, uname
);
1548 /* Print out all of the specified loadables */
1549 for (loadables_index
= 0;
1550 uname
= fdt_stringlist_get(fit
, noffset
, FIT_LOADABLE_PROP
,
1551 loadables_index
, NULL
), uname
;
1552 loadables_index
++) {
1553 if (loadables_index
== 0) {
1554 printf("%s Loadables: ", p
);
1558 printf("%s\n", uname
);
1562 static int fit_image_select(const void *fit
, int rd_noffset
, int verify
)
1564 fit_image_print(fit
, rd_noffset
, " ");
1567 puts(" Verifying Hash Integrity ... ");
1568 if (!fit_image_verify(fit
, rd_noffset
)) {
1569 puts("Bad Data Hash\n");
1578 int fit_get_node_from_config(bootm_headers_t
*images
, const char *prop_name
,
1585 debug("* %s: using config '%s' from image at 0x%08lx\n",
1586 prop_name
, images
->fit_uname_cfg
, addr
);
1588 /* Check whether configuration has this property defined */
1589 fit_hdr
= map_sysmem(addr
, 0);
1590 cfg_noffset
= fit_conf_get_node(fit_hdr
, images
->fit_uname_cfg
);
1591 if (cfg_noffset
< 0) {
1592 debug("* %s: no such config\n", prop_name
);
1596 noffset
= fit_conf_get_prop_node(fit_hdr
, cfg_noffset
, prop_name
);
1598 debug("* %s: no '%s' in config\n", prop_name
, prop_name
);
1606 * fit_get_image_type_property() - get property name for IH_TYPE_...
1608 * @return the properly name where we expect to find the image in the
1611 static const char *fit_get_image_type_property(int type
)
1614 * This is sort-of available in the uimage_type[] table in image.c
1615 * but we don't have access to the short name, and "fdt" is different
1616 * anyway. So let's just keep it here.
1619 case IH_TYPE_FLATDT
:
1620 return FIT_FDT_PROP
;
1621 case IH_TYPE_KERNEL
:
1622 return FIT_KERNEL_PROP
;
1623 case IH_TYPE_RAMDISK
:
1624 return FIT_RAMDISK_PROP
;
1625 case IH_TYPE_X86_SETUP
:
1626 return FIT_SETUP_PROP
;
1627 case IH_TYPE_LOADABLE
:
1628 return FIT_LOADABLE_PROP
;
1630 return FIT_FPGA_PROP
;
1636 int fit_image_load(bootm_headers_t
*images
, ulong addr
,
1637 const char **fit_unamep
, const char **fit_uname_configp
,
1638 int arch
, int image_type
, int bootstage_id
,
1639 enum fit_load_op load_op
, ulong
*datap
, ulong
*lenp
)
1641 int cfg_noffset
, noffset
;
1642 const char *fit_uname
;
1643 const char *fit_uname_config
;
1648 ulong load
, data
, len
;
1653 const char *prop_name
;
1656 fit
= map_sysmem(addr
, 0);
1657 fit_uname
= fit_unamep
? *fit_unamep
: NULL
;
1658 fit_uname_config
= fit_uname_configp
? *fit_uname_configp
: NULL
;
1659 prop_name
= fit_get_image_type_property(image_type
);
1660 printf("## Loading %s from FIT Image at %08lx ...\n", prop_name
, addr
);
1662 bootstage_mark(bootstage_id
+ BOOTSTAGE_SUB_FORMAT
);
1663 if (!fit_check_format(fit
)) {
1664 printf("Bad FIT %s image format!\n", prop_name
);
1665 bootstage_error(bootstage_id
+ BOOTSTAGE_SUB_FORMAT
);
1668 bootstage_mark(bootstage_id
+ BOOTSTAGE_SUB_FORMAT_OK
);
1670 /* get FIT component image node offset */
1671 bootstage_mark(bootstage_id
+ BOOTSTAGE_SUB_UNIT_NAME
);
1672 noffset
= fit_image_get_node(fit
, fit_uname
);
1675 * no image node unit name, try to get config
1676 * node first. If config unit node name is NULL
1677 * fit_conf_get_node() will try to find default config node
1679 bootstage_mark(bootstage_id
+ BOOTSTAGE_SUB_NO_UNIT_NAME
);
1680 if (IMAGE_ENABLE_BEST_MATCH
&& !fit_uname_config
) {
1681 cfg_noffset
= fit_conf_find_compat(fit
, gd_fdt_blob());
1683 cfg_noffset
= fit_conf_get_node(fit
,
1686 if (cfg_noffset
< 0) {
1687 puts("Could not find configuration node\n");
1688 bootstage_error(bootstage_id
+
1689 BOOTSTAGE_SUB_NO_UNIT_NAME
);
1692 fit_uname_config
= fdt_get_name(fit
, cfg_noffset
, NULL
);
1693 printf(" Using '%s' configuration\n", fit_uname_config
);
1694 if (image_type
== IH_TYPE_KERNEL
) {
1695 /* Remember (and possibly verify) this config */
1696 images
->fit_uname_cfg
= fit_uname_config
;
1697 if (IMAGE_ENABLE_VERIFY
&& images
->verify
) {
1698 puts(" Verifying Hash Integrity ... ");
1699 if (fit_config_verify(fit
, cfg_noffset
)) {
1700 puts("Bad Data Hash\n");
1701 bootstage_error(bootstage_id
+
1702 BOOTSTAGE_SUB_HASH
);
1707 bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG
);
1710 noffset
= fit_conf_get_prop_node(fit
, cfg_noffset
,
1712 fit_uname
= fit_get_name(fit
, noffset
, NULL
);
1715 puts("Could not find subimage node\n");
1716 bootstage_error(bootstage_id
+ BOOTSTAGE_SUB_SUBNODE
);
1720 printf(" Trying '%s' %s subimage\n", fit_uname
, prop_name
);
1722 ret
= fit_image_select(fit
, noffset
, images
->verify
);
1724 bootstage_error(bootstage_id
+ BOOTSTAGE_SUB_HASH
);
1728 bootstage_mark(bootstage_id
+ BOOTSTAGE_SUB_CHECK_ARCH
);
1729 #if !defined(USE_HOSTCC) && !defined(CONFIG_SANDBOX)
1730 if (!fit_image_check_target_arch(fit
, noffset
)) {
1731 puts("Unsupported Architecture\n");
1732 bootstage_error(bootstage_id
+ BOOTSTAGE_SUB_CHECK_ARCH
);
1738 fit_image_get_arch(fit
, noffset
, &os_arch
);
1739 images
->os
.arch
= os_arch
;
1742 if (image_type
== IH_TYPE_FLATDT
&&
1743 !fit_image_check_comp(fit
, noffset
, IH_COMP_NONE
)) {
1744 puts("FDT image is compressed");
1745 return -EPROTONOSUPPORT
;
1748 bootstage_mark(bootstage_id
+ BOOTSTAGE_SUB_CHECK_ALL
);
1749 type_ok
= fit_image_check_type(fit
, noffset
, image_type
) ||
1750 fit_image_check_type(fit
, noffset
, IH_TYPE_FIRMWARE
) ||
1751 (image_type
== IH_TYPE_KERNEL
&&
1752 fit_image_check_type(fit
, noffset
, IH_TYPE_KERNEL_NOLOAD
));
1754 os_ok
= image_type
== IH_TYPE_FLATDT
||
1755 image_type
== IH_TYPE_FPGA
||
1756 fit_image_check_os(fit
, noffset
, IH_OS_LINUX
) ||
1757 fit_image_check_os(fit
, noffset
, IH_OS_U_BOOT
) ||
1758 fit_image_check_os(fit
, noffset
, IH_OS_OPENRTOS
);
1761 * If either of the checks fail, we should report an error, but
1762 * if the image type is coming from the "loadables" field, we
1763 * don't care what it is
1765 if ((!type_ok
|| !os_ok
) && image_type
!= IH_TYPE_LOADABLE
) {
1766 fit_image_get_os(fit
, noffset
, &os
);
1767 printf("No %s %s %s Image\n",
1768 genimg_get_os_name(os
),
1769 genimg_get_arch_name(arch
),
1770 genimg_get_type_name(image_type
));
1771 bootstage_error(bootstage_id
+ BOOTSTAGE_SUB_CHECK_ALL
);
1775 bootstage_mark(bootstage_id
+ BOOTSTAGE_SUB_CHECK_ALL_OK
);
1777 /* get image data address and length */
1778 if (fit_image_get_data(fit
, noffset
, &buf
, &size
)) {
1779 printf("Could not find %s subimage data!\n", prop_name
);
1780 bootstage_error(bootstage_id
+ BOOTSTAGE_SUB_GET_DATA
);
1784 #if !defined(USE_HOSTCC) && defined(CONFIG_FIT_IMAGE_POST_PROCESS)
1785 /* perform any post-processing on the image data */
1786 board_fit_image_post_process((void **)&buf
, &size
);
1791 /* verify that image data is a proper FDT blob */
1792 if (image_type
== IH_TYPE_FLATDT
&& fdt_check_header(buf
)) {
1793 puts("Subimage data is not a FDT");
1797 bootstage_mark(bootstage_id
+ BOOTSTAGE_SUB_GET_DATA_OK
);
1800 * Work-around for eldk-4.2 which gives this warning if we try to
1801 * cast in the unmap_sysmem() call:
1802 * warning: initialization discards qualifiers from pointer target type
1805 void *vbuf
= (void *)buf
;
1807 data
= map_to_sysmem(vbuf
);
1810 if (load_op
== FIT_LOAD_IGNORED
) {
1812 } else if (fit_image_get_load(fit
, noffset
, &load
)) {
1813 if (load_op
== FIT_LOAD_REQUIRED
) {
1814 printf("Can't get %s subimage load address!\n",
1816 bootstage_error(bootstage_id
+ BOOTSTAGE_SUB_LOAD
);
1819 } else if (load_op
!= FIT_LOAD_OPTIONAL_NON_ZERO
|| load
) {
1820 ulong image_start
, image_end
;
1825 * move image data to the load address,
1826 * make sure we don't overwrite initial image
1829 image_end
= addr
+ fit_get_size(fit
);
1831 load_end
= load
+ len
;
1832 if (image_type
!= IH_TYPE_KERNEL
&&
1833 load
< image_end
&& load_end
> image_start
) {
1834 printf("Error: %s overwritten\n", prop_name
);
1838 printf(" Loading %s from 0x%08lx to 0x%08lx\n",
1839 prop_name
, data
, load
);
1841 dst
= map_sysmem(load
, len
);
1842 memmove(dst
, buf
, len
);
1845 bootstage_mark(bootstage_id
+ BOOTSTAGE_SUB_LOAD
);
1850 *fit_unamep
= (char *)fit_uname
;
1851 if (fit_uname_configp
)
1852 *fit_uname_configp
= (char *)fit_uname_config
;
1857 int boot_get_setup_fit(bootm_headers_t
*images
, uint8_t arch
,
1858 ulong
*setup_start
, ulong
*setup_len
)
1865 addr
= map_to_sysmem(images
->fit_hdr_os
);
1866 noffset
= fit_get_node_from_config(images
, FIT_SETUP_PROP
, addr
);
1870 ret
= fit_image_load(images
, addr
, NULL
, NULL
, arch
,
1871 IH_TYPE_X86_SETUP
, BOOTSTAGE_ID_FIT_SETUP_START
,
1872 FIT_LOAD_REQUIRED
, setup_start
, &len
);