1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013, Google Inc.
5 * (C) Copyright 2008 Semihalf
7 * (C) Copyright 2000-2006
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
13 #include <fdt_region.h>
18 * fit_set_hash_value - set hash value in requested has node
19 * @fit: pointer to the FIT format image header
20 * @noffset: hash node offset
21 * @value: hash value to be set
22 * @value_len: hash value length
24 * fit_set_hash_value() attempts to set hash value in a node at offset
25 * given and returns operation status to the caller.
31 static int fit_set_hash_value(void *fit, int noffset, uint8_t *value,
36 ret = fdt_setprop(fit, noffset, FIT_VALUE_PROP, value, value_len);
38 printf("Can't set hash '%s' property for '%s' node(%s)\n",
39 FIT_VALUE_PROP, fit_get_name(fit, noffset, NULL),
41 return ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
48 * fit_image_process_hash - Process a single subnode of the images/ node
50 * Check each subnode and process accordingly. For hash nodes we generate
51 * a hash of the supplised data and store it in the node.
53 * @fit: pointer to the FIT format image header
54 * @image_name: name of image being processes (used to display errors)
55 * @noffset: subnode offset
56 * @data: data to process
57 * @size: size of data in bytes
58 * @return 0 if ok, -1 on error
60 static int fit_image_process_hash(void *fit, const char *image_name,
61 int noffset, const void *data, size_t size)
63 uint8_t value[FIT_MAX_HASH_LEN];
64 const char *node_name;
69 node_name = fit_get_name(fit, noffset, NULL);
71 if (fit_image_hash_get_algo(fit, noffset, &algo)) {
72 printf("Can't get hash algo property for '%s' hash node in '%s' image node\n",
73 node_name, image_name);
77 if (calculate_hash(data, size, algo, value, &value_len)) {
78 printf("Unsupported hash algorithm (%s) for '%s' hash node in '%s' image node\n",
79 algo, node_name, image_name);
80 return -EPROTONOSUPPORT;
83 ret = fit_set_hash_value(fit, noffset, value, value_len);
85 printf("Can't set hash value for '%s' hash node in '%s' image node\n",
86 node_name, image_name);
94 * fit_image_write_sig() - write the signature to a FIT
96 * This writes the signature and signer data to the FIT.
98 * @fit: pointer to the FIT format image header
99 * @noffset: hash node offset
100 * @value: signature value to be set
101 * @value_len: signature value length
102 * @comment: Text comment to write (NULL for none)
106 * -FDT_ERR_..., on failure
108 static int fit_image_write_sig(void *fit, int noffset, uint8_t *value,
109 int value_len, const char *comment, const char *region_prop,
110 int region_proplen, const char *cmdname)
116 * Get the current string size, before we update the FIT and add
119 string_size = fdt_size_dt_strings(fit);
121 ret = fdt_setprop(fit, noffset, FIT_VALUE_PROP, value, value_len);
123 ret = fdt_setprop_string(fit, noffset, "signer-name",
127 ret = fdt_setprop_string(fit, noffset, "signer-version",
131 ret = fdt_setprop_string(fit, noffset, "comment", comment);
133 time_t timestamp = imagetool_get_source_date(cmdname,
136 ret = fit_set_timestamp(fit, noffset, timestamp);
138 if (region_prop && !ret) {
141 ret = fdt_setprop(fit, noffset, "hashed-nodes",
142 region_prop, region_proplen);
143 /* This is a legacy offset, it is unused, and must remain 0. */
145 strdata[1] = cpu_to_fdt32(string_size);
147 ret = fdt_setprop(fit, noffset, "hashed-strings",
148 strdata, sizeof(strdata));
155 static int fit_image_setup_sig(struct image_sign_info *info,
156 const char *keydir, const char *keyfile, void *fit,
157 const char *image_name, int noffset, const char *require_keys,
158 const char *engine_id)
160 const char *node_name;
162 const char *padding_name;
164 node_name = fit_get_name(fit, noffset, NULL);
165 if (fit_image_hash_get_algo(fit, noffset, &algo_name)) {
166 printf("Can't get algo property for '%s' signature node in '%s' image node\n",
167 node_name, image_name);
171 padding_name = fdt_getprop(fit, noffset, "padding", NULL);
173 memset(info, '\0', sizeof(*info));
174 info->keydir = keydir;
175 info->keyfile = keyfile;
176 info->keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
178 info->node_offset = noffset;
179 info->name = strdup(algo_name);
180 info->checksum = image_get_checksum_algo(algo_name);
181 info->crypto = image_get_crypto_algo(algo_name);
182 info->padding = image_get_padding_algo(padding_name);
183 info->require_keys = require_keys;
184 info->engine_id = engine_id;
185 if (!info->checksum || !info->crypto) {
186 printf("Unsupported signature algorithm (%s) for '%s' signature node in '%s' image node\n",
187 algo_name, node_name, image_name);
195 * fit_image_process_sig- Process a single subnode of the images/ node
197 * Check each subnode and process accordingly. For signature nodes we
198 * generate a signed hash of the supplised data and store it in the node.
200 * @keydir: Directory containing keys to use for signing
201 * @keydest: Destination FDT blob to write public keys into
202 * @fit: pointer to the FIT format image header
203 * @image_name: name of image being processes (used to display errors)
204 * @noffset: subnode offset
205 * @data: data to process
206 * @size: size of data in bytes
207 * @comment: Comment to add to signature nodes
208 * @require_keys: Mark all keys as 'required'
209 * @engine_id: Engine to use for signing
210 * @return 0 if ok, -1 on error
212 static int fit_image_process_sig(const char *keydir, const char *keyfile,
213 void *keydest, void *fit, const char *image_name,
214 int noffset, const void *data, size_t size,
215 const char *comment, int require_keys, const char *engine_id,
218 struct image_sign_info info;
219 struct image_region region;
220 const char *node_name;
225 if (fit_image_setup_sig(&info, keydir, keyfile, fit, image_name,
226 noffset, require_keys ? "image" : NULL,
230 node_name = fit_get_name(fit, noffset, NULL);
233 ret = info.crypto->sign(&info, ®ion, 1, &value, &value_len);
235 printf("Failed to sign '%s' signature node in '%s' image node: %d\n",
236 node_name, image_name, ret);
238 /* We allow keys to be missing */
244 ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
247 if (ret == -FDT_ERR_NOSPACE)
249 printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
250 node_name, image_name, fdt_strerror(ret));
255 /* Get keyname again, as FDT has changed and invalidated our pointer */
256 info.keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
259 * Write the public key into the supplied FDT file; this might fail
260 * several times, since we try signing with successively increasing
264 ret = info.crypto->add_verify_data(&info, keydest);
266 printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
267 node_name, image_name);
275 static int fit_image_read_data(char *filename, unsigned char *data,
283 fd = open(filename, O_RDONLY | O_BINARY);
285 printf("Can't open file %s (err=%d => %s)\n",
286 filename, errno, strerror(errno));
290 /* Compute file size */
291 if (fstat(fd, &sbuf) < 0) {
292 printf("Can't fstat file %s (err=%d => %s)\n",
293 filename, errno, strerror(errno));
297 /* Check file size */
298 if (sbuf.st_size != expected_size) {
299 printf("File %s don't have the expected size (size=%lld, expected=%d)\n",
300 filename, (long long)sbuf.st_size, expected_size);
305 n = read(fd, data, sbuf.st_size);
307 printf("Can't read file %s (err=%d => %s)\n",
308 filename, errno, strerror(errno));
312 /* Check that we have read all the file */
313 if (n != sbuf.st_size) {
314 printf("Can't read all file %s (read %zd bytes, expexted %lld)\n",
315 filename, n, (long long)sbuf.st_size);
326 static int get_random_data(void *data, int size)
328 unsigned char *tmp = data;
329 struct timespec date;
333 printf("%s: pointer data is NULL\n", __func__);
338 ret = clock_gettime(CLOCK_MONOTONIC, &date);
340 printf("%s: clock_gettime has failed (err=%d, str=%s)\n",
341 __func__, ret, strerror(errno));
345 srandom(date.tv_nsec);
347 for (i = 0; i < size; i++) {
348 *tmp = random() & 0xff;
356 static int fit_image_setup_cipher(struct image_cipher_info *info,
357 const char *keydir, void *fit,
358 const char *image_name, int image_noffset,
365 if (fit_image_cipher_get_algo(fit, noffset, &algo_name)) {
366 printf("Can't get algo name for cipher in image '%s'\n",
371 info->keydir = keydir;
373 /* Read the key name */
374 info->keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
375 if (!info->keyname) {
376 printf("Can't get key name for cipher in image '%s'\n",
384 * If this property is not provided then mkimage will generate
385 * a random IV and store it in the FIT image
387 info->ivname = fdt_getprop(fit, noffset, "iv-name-hint", NULL);
390 info->node_noffset = noffset;
391 info->name = algo_name;
393 info->cipher = image_get_cipher_algo(algo_name);
395 printf("Can't get algo for cipher '%s'\n", image_name);
399 /* Read the key in the file */
400 snprintf(filename, sizeof(filename), "%s/%s%s",
401 info->keydir, info->keyname, ".bin");
402 info->key = malloc(info->cipher->key_len);
404 printf("Can't allocate memory for key\n");
408 ret = fit_image_read_data(filename, (unsigned char *)info->key,
409 info->cipher->key_len);
413 info->iv = malloc(info->cipher->iv_len);
415 printf("Can't allocate memory for iv\n");
421 /* Read the IV in the file */
422 snprintf(filename, sizeof(filename), "%s/%s%s",
423 info->keydir, info->ivname, ".bin");
424 ret = fit_image_read_data(filename, (unsigned char *)info->iv,
425 info->cipher->iv_len);
427 /* Generate an ramdom IV */
428 ret = get_random_data((void *)info->iv, info->cipher->iv_len);
435 int fit_image_write_cipher(void *fit, int image_noffset, int noffset,
436 const void *data, size_t size,
437 unsigned char *data_ciphered, int data_ciphered_len)
441 /* Replace data with ciphered data */
442 ret = fdt_setprop(fit, image_noffset, FIT_DATA_PROP,
443 data_ciphered, data_ciphered_len);
444 if (ret == -FDT_ERR_NOSPACE) {
449 printf("Can't replace data with ciphered data (err = %d)\n", ret);
453 /* add non ciphered data size */
454 ret = fdt_setprop_u32(fit, image_noffset, "data-size-unciphered", size);
455 if (ret == -FDT_ERR_NOSPACE) {
460 printf("Can't add unciphered data size (err = %d)\n", ret);
469 fit_image_process_cipher(const char *keydir, void *keydest, void *fit,
470 const char *image_name, int image_noffset,
471 int node_noffset, const void *data, size_t size,
474 struct image_cipher_info info;
475 unsigned char *data_ciphered = NULL;
476 int data_ciphered_len;
479 memset(&info, 0, sizeof(info));
481 ret = fit_image_setup_cipher(&info, keydir, fit, image_name,
482 image_noffset, node_noffset);
486 ret = info.cipher->encrypt(&info, data, size,
487 &data_ciphered, &data_ciphered_len);
492 * Write the public key into the supplied FDT file; this might fail
493 * several times, since we try signing with successively increasing
495 * And, if needed, write the iv in the FIT file
498 ret = info.cipher->add_cipher_data(&info, keydest, fit, node_noffset);
500 printf("Failed to add verification data for cipher '%s' in image '%s'\n",
501 info.keyname, image_name);
506 ret = fit_image_write_cipher(fit, image_noffset, node_noffset,
508 data_ciphered, data_ciphered_len);
512 free((void *)info.key);
513 free((void *)info.iv);
517 int fit_image_cipher_data(const char *keydir, void *keydest,
518 void *fit, int image_noffset, const char *comment,
519 int require_keys, const char *engine_id,
522 const char *image_name;
525 int cipher_node_offset, len;
528 image_name = fit_get_name(fit, image_noffset, NULL);
530 printf("Can't get image name\n");
534 /* Get image data and data length */
535 if (fit_image_get_data(fit, image_noffset, &data, &size)) {
536 printf("Can't get image data/size\n");
541 * Don't cipher ciphered data.
543 * If the data-size-unciphered property is present the data for this
544 * image is already encrypted. This is important as 'mkimage -F' can be
545 * run multiple times on a FIT image.
547 if (fdt_getprop(fit, image_noffset, "data-size-unciphered", &len))
549 if (len != -FDT_ERR_NOTFOUND) {
550 printf("Failure testing for data-size-unciphered\n");
554 /* Process cipher node if present */
555 cipher_node_offset = fdt_subnode_offset(fit, image_noffset,
556 FIT_CIPHER_NODENAME);
557 if (cipher_node_offset == -FDT_ERR_NOTFOUND)
559 if (cipher_node_offset < 0) {
560 printf("Failure getting cipher node\n");
563 if (!IMAGE_ENABLE_ENCRYPT || !keydir)
565 return fit_image_process_cipher(keydir, keydest, fit, image_name,
566 image_noffset, cipher_node_offset, data, size, cmdname);
570 * fit_image_add_verification_data() - calculate/set verig. data for image node
572 * This adds hash and signature values for an component image node.
574 * All existing hash subnodes are checked, if algorithm property is set to
575 * one of the supported hash algorithms, hash value is computed and
576 * corresponding hash node property is set, for example:
578 * Input component image node structure:
580 * o image-1 (at image_noffset)
581 * | - data = [binary data]
585 * Output component image node structure:
587 * o image-1 (at image_noffset)
588 * | - data = [binary data]
591 * |- value = sha1(data)
593 * For signature details, please see doc/uImage.FIT/signature.txt
595 * @keydir Directory containing *.key and *.crt files (or NULL)
596 * @keydest FDT Blob to write public keys into (NULL if none)
597 * @fit: Pointer to the FIT format image header
598 * @image_noffset: Requested component image node
599 * @comment: Comment to add to signature nodes
600 * @require_keys: Mark all keys as 'required'
601 * @engine_id: Engine to use for signing
602 * @return: 0 on success, <0 on failure
604 int fit_image_add_verification_data(const char *keydir, const char *keyfile,
605 void *keydest, void *fit, int image_noffset,
606 const char *comment, int require_keys, const char *engine_id,
609 const char *image_name;
614 /* Get image data and data length */
615 if (fit_image_get_data(fit, image_noffset, &data, &size)) {
616 printf("Can't get image data/size\n");
620 image_name = fit_get_name(fit, image_noffset, NULL);
622 /* Process all hash subnodes of the component image node */
623 for (noffset = fdt_first_subnode(fit, image_noffset);
625 noffset = fdt_next_subnode(fit, noffset)) {
626 const char *node_name;
630 * Check subnode name, must be equal to "hash" or "signature".
631 * Multiple hash nodes require unique unit node
632 * names, e.g. hash-1, hash-2, signature-1, etc.
634 node_name = fit_get_name(fit, noffset, NULL);
635 if (!strncmp(node_name, FIT_HASH_NODENAME,
636 strlen(FIT_HASH_NODENAME))) {
637 ret = fit_image_process_hash(fit, image_name, noffset,
639 } else if (IMAGE_ENABLE_SIGN && (keydir || keyfile) &&
640 !strncmp(node_name, FIT_SIG_NODENAME,
641 strlen(FIT_SIG_NODENAME))) {
642 ret = fit_image_process_sig(keydir, keyfile, keydest,
643 fit, image_name, noffset, data, size,
644 comment, require_keys, engine_id, cmdname);
658 static void strlist_init(struct strlist *list)
660 memset(list, '\0', sizeof(*list));
663 static void strlist_free(struct strlist *list)
667 for (i = 0; i < list->count; i++)
668 free(list->strings[i]);
672 static int strlist_add(struct strlist *list, const char *str)
677 list->strings = realloc(list->strings,
678 (list->count + 1) * sizeof(char *));
681 list->strings[list->count++] = dup;
686 static const char *fit_config_get_image_list(void *fit, int noffset,
687 int *lenp, int *allow_missingp)
689 static const char default_list[] = FIT_KERNEL_PROP "\0"
693 /* If there is an "image" property, use that */
694 prop = fdt_getprop(fit, noffset, "sign-images", lenp);
697 return *lenp ? prop : NULL;
700 /* Default image list */
702 *lenp = sizeof(default_list);
707 static int fit_config_add_hash(void *fit, const char *conf_name, const char *sig_name,
708 struct strlist *node_inc, const char *iname, int image_noffset)
710 char name[200], path[200];
715 ret = fdt_get_path(fit, image_noffset, path, sizeof(path));
718 if (strlist_add(node_inc, path))
721 snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH,
724 /* Add all this image's hashes */
726 for (noffset = fdt_first_subnode(fit, image_noffset);
728 noffset = fdt_next_subnode(fit, noffset)) {
729 const char *name = fit_get_name(fit, noffset, NULL);
731 if (strncmp(name, FIT_HASH_NODENAME,
732 strlen(FIT_HASH_NODENAME)))
734 ret = fdt_get_path(fit, noffset, path, sizeof(path));
737 if (strlist_add(node_inc, path))
743 printf("Failed to find any hash nodes in configuration '%s/%s' image '%s' - without these it is not possible to verify this image\n",
744 conf_name, sig_name, iname);
748 /* Add this image's cipher node if present */
749 noffset = fdt_subnode_offset(fit, image_noffset,
750 FIT_CIPHER_NODENAME);
751 if (noffset != -FDT_ERR_NOTFOUND) {
753 printf("Failed to get cipher node in configuration '%s/%s' image '%s': %s\n",
754 conf_name, sig_name, iname,
755 fdt_strerror(noffset));
758 ret = fdt_get_path(fit, noffset, path, sizeof(path));
761 if (strlist_add(node_inc, path))
768 printf("Out of memory processing configuration '%s/%s'\n", conf_name,
773 printf("Failed to get path for image '%s' in configuration '%s/%s': %s\n",
774 iname, conf_name, sig_name, fdt_strerror(ret));
778 static int fit_config_get_hash_list(void *fit, int conf_noffset,
779 int sig_offset, struct strlist *node_inc)
782 const char *prop, *iname, *end;
783 const char *conf_name, *sig_name;
788 conf_name = fit_get_name(fit, conf_noffset, NULL);
789 sig_name = fit_get_name(fit, sig_offset, NULL);
792 * Build a list of nodes we need to hash. We always need the root
793 * node and the configuration.
795 strlist_init(node_inc);
796 snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH, conf_name);
797 if (strlist_add(node_inc, "/") ||
798 strlist_add(node_inc, name))
801 /* Get a list of images that we intend to sign */
802 prop = fit_config_get_image_list(fit, sig_offset, &len,
807 /* Locate the images */
810 for (iname = prop; iname < end; iname += strlen(iname) + 1) {
812 int index, max_index;
814 max_index = fdt_stringlist_count(fit, conf_noffset, iname);
816 for (index = 0; index < max_index; index++) {
817 image_noffset = fit_conf_get_prop_node_index(fit, conf_noffset,
820 if (image_noffset < 0) {
821 printf("Failed to find image '%s' in configuration '%s/%s'\n",
822 iname, conf_name, sig_name);
829 ret = fit_config_add_hash(fit, conf_name,
831 iname, image_noffset);
840 printf("Failed to find any images for configuration '%s/%s'\n",
841 conf_name, sig_name);
848 printf("Out of memory processing configuration '%s/%s'\n", conf_name,
853 static int fit_config_get_data(void *fit, int conf_noffset, int noffset,
854 struct image_region **regionp, int *region_countp,
855 char **region_propp, int *region_proplen)
857 char * const exc_prop[] = {"data"};
858 struct strlist node_inc;
859 struct image_region *region;
860 struct fdt_region fdt_regions[100];
861 const char *conf_name, *sig_name;
867 conf_name = fit_get_name(fit, conf_noffset, NULL);
868 sig_name = fit_get_name(fit, noffset, NULL);
869 debug("%s: conf='%s', sig='%s'\n", __func__, conf_name, sig_name);
871 /* Get a list of nodes we want to hash */
872 ret = fit_config_get_hash_list(fit, conf_noffset, noffset, &node_inc);
876 /* Get a list of regions to hash */
877 count = fdt_find_regions(fit, node_inc.strings, node_inc.count,
878 exc_prop, ARRAY_SIZE(exc_prop),
879 fdt_regions, ARRAY_SIZE(fdt_regions),
880 path, sizeof(path), 1);
882 printf("Failed to hash configuration '%s/%s': %s\n", conf_name,
883 sig_name, fdt_strerror(ret));
887 printf("No data to hash for configuration '%s/%s': %s\n",
888 conf_name, sig_name, fdt_strerror(ret));
892 /* Build our list of data blocks */
893 region = fit_region_make_list(fit, fdt_regions, count, NULL);
895 printf("Out of memory hashing configuration '%s/%s'\n",
896 conf_name, sig_name);
900 /* Create a list of all hashed properties */
901 debug("Hash nodes:\n");
902 for (i = len = 0; i < node_inc.count; i++) {
903 debug(" %s\n", node_inc.strings[i]);
904 len += strlen(node_inc.strings[i]) + 1;
906 region_prop = malloc(len);
908 printf("Out of memory setting up regions for configuration '%s/%s'\n",
909 conf_name, sig_name);
912 for (i = len = 0; i < node_inc.count;
913 len += strlen(node_inc.strings[i]) + 1, i++)
914 strcpy(region_prop + len, node_inc.strings[i]);
915 strlist_free(&node_inc);
917 *region_countp = count;
919 *region_propp = region_prop;
920 *region_proplen = len;
925 static int fit_config_process_sig(const char *keydir, const char *keyfile,
926 void *keydest, void *fit, const char *conf_name,
927 int conf_noffset, int noffset, const char *comment,
928 int require_keys, const char *engine_id, const char *cmdname)
930 struct image_sign_info info;
931 const char *node_name;
932 struct image_region *region;
940 node_name = fit_get_name(fit, noffset, NULL);
941 if (fit_config_get_data(fit, conf_noffset, noffset, ®ion,
942 ®ion_count, ®ion_prop, ®ion_proplen))
945 if (fit_image_setup_sig(&info, keydir, keyfile, fit, conf_name, noffset,
946 require_keys ? "conf" : NULL, engine_id))
949 ret = info.crypto->sign(&info, region, region_count, &value,
953 printf("Failed to sign '%s' signature node in '%s' conf node\n",
954 node_name, conf_name);
956 /* We allow keys to be missing */
962 ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
963 region_prop, region_proplen, cmdname);
965 if (ret == -FDT_ERR_NOSPACE)
967 printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
968 node_name, conf_name, fdt_strerror(ret));
974 /* Get keyname again, as FDT has changed and invalidated our pointer */
975 info.keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
977 /* Write the public key into the supplied FDT file */
979 ret = info.crypto->add_verify_data(&info, keydest);
981 printf("Failed to add verification data for '%s' signature node in '%s' configuration node\n",
982 node_name, conf_name);
990 static int fit_config_add_verification_data(const char *keydir,
991 const char *keyfile, void *keydest, void *fit, int conf_noffset,
992 const char *comment, int require_keys, const char *engine_id,
995 const char *conf_name;
998 conf_name = fit_get_name(fit, conf_noffset, NULL);
1000 /* Process all hash subnodes of the configuration node */
1001 for (noffset = fdt_first_subnode(fit, conf_noffset);
1003 noffset = fdt_next_subnode(fit, noffset)) {
1004 const char *node_name;
1007 node_name = fit_get_name(fit, noffset, NULL);
1008 if (!strncmp(node_name, FIT_SIG_NODENAME,
1009 strlen(FIT_SIG_NODENAME))) {
1010 ret = fit_config_process_sig(keydir, keyfile, keydest,
1011 fit, conf_name, conf_noffset, noffset, comment,
1012 require_keys, engine_id, cmdname);
1021 int fit_cipher_data(const char *keydir, void *keydest, void *fit,
1022 const char *comment, int require_keys,
1023 const char *engine_id, const char *cmdname)
1029 /* Find images parent node offset */
1030 images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
1031 if (images_noffset < 0) {
1032 printf("Can't find images parent node '%s' (%s)\n",
1033 FIT_IMAGES_PATH, fdt_strerror(images_noffset));
1034 return images_noffset;
1037 /* Process its subnodes, print out component images details */
1038 for (noffset = fdt_first_subnode(fit, images_noffset);
1040 noffset = fdt_next_subnode(fit, noffset)) {
1042 * Direct child node of the images parent node,
1043 * i.e. component image node.
1045 ret = fit_image_cipher_data(keydir, keydest,
1046 fit, noffset, comment,
1047 require_keys, engine_id,
1056 int fit_add_verification_data(const char *keydir, const char *keyfile,
1057 void *keydest, void *fit, const char *comment,
1058 int require_keys, const char *engine_id,
1059 const char *cmdname)
1061 int images_noffset, confs_noffset;
1065 /* Find images parent node offset */
1066 images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
1067 if (images_noffset < 0) {
1068 printf("Can't find images parent node '%s' (%s)\n",
1069 FIT_IMAGES_PATH, fdt_strerror(images_noffset));
1070 return images_noffset;
1073 /* Process its subnodes, print out component images details */
1074 for (noffset = fdt_first_subnode(fit, images_noffset);
1076 noffset = fdt_next_subnode(fit, noffset)) {
1078 * Direct child node of the images parent node,
1079 * i.e. component image node.
1081 ret = fit_image_add_verification_data(keydir, keyfile, keydest,
1082 fit, noffset, comment, require_keys, engine_id,
1088 /* If there are no keys, we can't sign configurations */
1089 if (!IMAGE_ENABLE_SIGN || !(keydir || keyfile))
1092 /* Find configurations parent node offset */
1093 confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
1094 if (confs_noffset < 0) {
1095 printf("Can't find images parent node '%s' (%s)\n",
1096 FIT_CONFS_PATH, fdt_strerror(confs_noffset));
1100 /* Process its subnodes, print out component images details */
1101 for (noffset = fdt_first_subnode(fit, confs_noffset);
1103 noffset = fdt_next_subnode(fit, noffset)) {
1104 ret = fit_config_add_verification_data(keydir, keyfile, keydest,
1105 fit, noffset, comment,
1107 engine_id, cmdname);
1115 #ifdef CONFIG_FIT_SIGNATURE
1116 int fit_check_sign(const void *fit, const void *key,
1117 const char *fit_uname_config)
1122 cfg_noffset = fit_conf_get_node(fit, fit_uname_config);
1126 printf("Verifying Hash Integrity for node '%s'... ",
1127 fdt_get_name(fit, cfg_noffset, NULL));
1128 ret = fit_config_verify(fit, cfg_noffset);
1131 printf("Verified OK, loading images\n");
1132 ret = bootm_host_load_images(fit, cfg_noffset);