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, void *fit, const char *image_name,
157 int noffset, const char *require_keys, const char *engine_id)
159 const char *node_name;
161 const char *padding_name;
163 node_name = fit_get_name(fit, noffset, NULL);
164 if (fit_image_hash_get_algo(fit, noffset, &algo_name)) {
165 printf("Can't get algo property for '%s' signature node in '%s' image node\n",
166 node_name, image_name);
170 padding_name = fdt_getprop(fit, noffset, "padding", NULL);
172 memset(info, '\0', sizeof(*info));
173 info->keydir = keydir;
174 info->keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
176 info->node_offset = noffset;
177 info->name = strdup(algo_name);
178 info->checksum = image_get_checksum_algo(algo_name);
179 info->crypto = image_get_crypto_algo(algo_name);
180 info->padding = image_get_padding_algo(padding_name);
181 info->require_keys = require_keys;
182 info->engine_id = engine_id;
183 if (!info->checksum || !info->crypto) {
184 printf("Unsupported signature algorithm (%s) for '%s' signature node in '%s' image node\n",
185 algo_name, node_name, image_name);
193 * fit_image_process_sig- Process a single subnode of the images/ node
195 * Check each subnode and process accordingly. For signature nodes we
196 * generate a signed hash of the supplised data and store it in the node.
198 * @keydir: Directory containing keys to use for signing
199 * @keydest: Destination FDT blob to write public keys into
200 * @fit: pointer to the FIT format image header
201 * @image_name: name of image being processes (used to display errors)
202 * @noffset: subnode offset
203 * @data: data to process
204 * @size: size of data in bytes
205 * @comment: Comment to add to signature nodes
206 * @require_keys: Mark all keys as 'required'
207 * @engine_id: Engine to use for signing
208 * @return 0 if ok, -1 on error
210 static int fit_image_process_sig(const char *keydir, void *keydest,
211 void *fit, const char *image_name,
212 int noffset, const void *data, size_t size,
213 const char *comment, int require_keys, const char *engine_id,
216 struct image_sign_info info;
217 struct image_region region;
218 const char *node_name;
223 if (fit_image_setup_sig(&info, keydir, fit, image_name, noffset,
224 require_keys ? "image" : NULL, engine_id))
227 node_name = fit_get_name(fit, noffset, NULL);
230 ret = info.crypto->sign(&info, ®ion, 1, &value, &value_len);
232 printf("Failed to sign '%s' signature node in '%s' image node: %d\n",
233 node_name, image_name, ret);
235 /* We allow keys to be missing */
241 ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
244 if (ret == -FDT_ERR_NOSPACE)
246 printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
247 node_name, image_name, fdt_strerror(ret));
252 /* Get keyname again, as FDT has changed and invalidated our pointer */
253 info.keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
256 * Write the public key into the supplied FDT file; this might fail
257 * several times, since we try signing with successively increasing
261 ret = info.crypto->add_verify_data(&info, keydest);
263 printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
264 node_name, image_name);
272 static int fit_image_read_data(char *filename, unsigned char *data,
280 fd = open(filename, O_RDONLY | O_BINARY);
282 printf("Can't open file %s (err=%d => %s)\n",
283 filename, errno, strerror(errno));
287 /* Compute file size */
288 if (fstat(fd, &sbuf) < 0) {
289 printf("Can't fstat file %s (err=%d => %s)\n",
290 filename, errno, strerror(errno));
294 /* Check file size */
295 if (sbuf.st_size != expected_size) {
296 printf("File %s don't have the expected size (size=%lld, expected=%d)\n",
297 filename, (long long)sbuf.st_size, expected_size);
302 n = read(fd, data, sbuf.st_size);
304 printf("Can't read file %s (err=%d => %s)\n",
305 filename, errno, strerror(errno));
309 /* Check that we have read all the file */
310 if (n != sbuf.st_size) {
311 printf("Can't read all file %s (read %zd bytes, expexted %lld)\n",
312 filename, n, (long long)sbuf.st_size);
323 static int get_random_data(void *data, int size)
325 unsigned char *tmp = data;
326 struct timespec date;
330 printf("%s: pointer data is NULL\n", __func__);
335 ret = clock_gettime(CLOCK_MONOTONIC, &date);
337 printf("%s: clock_gettime has failed (err=%d, str=%s)\n",
338 __func__, ret, strerror(errno));
342 srandom(date.tv_nsec);
344 for (i = 0; i < size; i++) {
345 *tmp = random() & 0xff;
353 static int fit_image_setup_cipher(struct image_cipher_info *info,
354 const char *keydir, void *fit,
355 const char *image_name, int image_noffset,
362 if (fit_image_cipher_get_algo(fit, noffset, &algo_name)) {
363 printf("Can't get algo name for cipher in image '%s'\n",
368 info->keydir = keydir;
370 /* Read the key name */
371 info->keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
372 if (!info->keyname) {
373 printf("Can't get key name for cipher in image '%s'\n",
381 * If this property is not provided then mkimage will generate
382 * a random IV and store it in the FIT image
384 info->ivname = fdt_getprop(fit, noffset, "iv-name-hint", NULL);
387 info->node_noffset = noffset;
388 info->name = algo_name;
390 info->cipher = image_get_cipher_algo(algo_name);
392 printf("Can't get algo for cipher '%s'\n", image_name);
396 /* Read the key in the file */
397 snprintf(filename, sizeof(filename), "%s/%s%s",
398 info->keydir, info->keyname, ".bin");
399 info->key = malloc(info->cipher->key_len);
401 printf("Can't allocate memory for key\n");
405 ret = fit_image_read_data(filename, (unsigned char *)info->key,
406 info->cipher->key_len);
410 info->iv = malloc(info->cipher->iv_len);
412 printf("Can't allocate memory for iv\n");
418 /* Read the IV in the file */
419 snprintf(filename, sizeof(filename), "%s/%s%s",
420 info->keydir, info->ivname, ".bin");
421 ret = fit_image_read_data(filename, (unsigned char *)info->iv,
422 info->cipher->iv_len);
424 /* Generate an ramdom IV */
425 ret = get_random_data((void *)info->iv, info->cipher->iv_len);
432 int fit_image_write_cipher(void *fit, int image_noffset, int noffset,
433 const void *data, size_t size,
434 unsigned char *data_ciphered, int data_ciphered_len)
438 /* Replace data with ciphered data */
439 ret = fdt_setprop(fit, image_noffset, FIT_DATA_PROP,
440 data_ciphered, data_ciphered_len);
441 if (ret == -FDT_ERR_NOSPACE) {
446 printf("Can't replace data with ciphered data (err = %d)\n", ret);
450 /* add non ciphered data size */
451 ret = fdt_setprop_u32(fit, image_noffset, "data-size-unciphered", size);
452 if (ret == -FDT_ERR_NOSPACE) {
457 printf("Can't add unciphered data size (err = %d)\n", ret);
466 fit_image_process_cipher(const char *keydir, void *keydest, void *fit,
467 const char *image_name, int image_noffset,
468 int node_noffset, const void *data, size_t size,
471 struct image_cipher_info info;
472 unsigned char *data_ciphered = NULL;
473 int data_ciphered_len;
476 memset(&info, 0, sizeof(info));
478 ret = fit_image_setup_cipher(&info, keydir, fit, image_name,
479 image_noffset, node_noffset);
483 ret = info.cipher->encrypt(&info, data, size,
484 &data_ciphered, &data_ciphered_len);
489 * Write the public key into the supplied FDT file; this might fail
490 * several times, since we try signing with successively increasing
492 * And, if needed, write the iv in the FIT file
495 ret = info.cipher->add_cipher_data(&info, keydest, fit, node_noffset);
497 printf("Failed to add verification data for cipher '%s' in image '%s'\n",
498 info.keyname, image_name);
503 ret = fit_image_write_cipher(fit, image_noffset, node_noffset,
505 data_ciphered, data_ciphered_len);
509 free((void *)info.key);
510 free((void *)info.iv);
514 int fit_image_cipher_data(const char *keydir, void *keydest,
515 void *fit, int image_noffset, const char *comment,
516 int require_keys, const char *engine_id,
519 const char *image_name;
522 int cipher_node_offset, len;
525 image_name = fit_get_name(fit, image_noffset, NULL);
527 printf("Can't get image name\n");
531 /* Get image data and data length */
532 if (fit_image_get_data(fit, image_noffset, &data, &size)) {
533 printf("Can't get image data/size\n");
538 * Don't cipher ciphered data.
540 * If the data-size-unciphered property is present the data for this
541 * image is already encrypted. This is important as 'mkimage -F' can be
542 * run multiple times on a FIT image.
544 if (fdt_getprop(fit, image_noffset, "data-size-unciphered", &len))
546 if (len != -FDT_ERR_NOTFOUND) {
547 printf("Failure testing for data-size-unciphered\n");
551 /* Process cipher node if present */
552 cipher_node_offset = fdt_subnode_offset(fit, image_noffset,
553 FIT_CIPHER_NODENAME);
554 if (cipher_node_offset == -FDT_ERR_NOTFOUND)
556 if (cipher_node_offset < 0) {
557 printf("Failure getting cipher node\n");
560 if (!IMAGE_ENABLE_ENCRYPT || !keydir)
562 return fit_image_process_cipher(keydir, keydest, fit, image_name,
563 image_noffset, cipher_node_offset, data, size, cmdname);
567 * fit_image_add_verification_data() - calculate/set verig. data for image node
569 * This adds hash and signature values for an component image node.
571 * All existing hash subnodes are checked, if algorithm property is set to
572 * one of the supported hash algorithms, hash value is computed and
573 * corresponding hash node property is set, for example:
575 * Input component image node structure:
577 * o image-1 (at image_noffset)
578 * | - data = [binary data]
582 * Output component image node structure:
584 * o image-1 (at image_noffset)
585 * | - data = [binary data]
588 * |- value = sha1(data)
590 * For signature details, please see doc/uImage.FIT/signature.txt
592 * @keydir Directory containing *.key and *.crt files (or NULL)
593 * @keydest FDT Blob to write public keys into (NULL if none)
594 * @fit: Pointer to the FIT format image header
595 * @image_noffset: Requested component image node
596 * @comment: Comment to add to signature nodes
597 * @require_keys: Mark all keys as 'required'
598 * @engine_id: Engine to use for signing
599 * @return: 0 on success, <0 on failure
601 int fit_image_add_verification_data(const char *keydir, void *keydest,
602 void *fit, int image_noffset, const char *comment,
603 int require_keys, const char *engine_id, const char *cmdname)
605 const char *image_name;
610 /* Get image data and data length */
611 if (fit_image_get_data(fit, image_noffset, &data, &size)) {
612 printf("Can't get image data/size\n");
616 image_name = fit_get_name(fit, image_noffset, NULL);
618 /* Process all hash subnodes of the component image node */
619 for (noffset = fdt_first_subnode(fit, image_noffset);
621 noffset = fdt_next_subnode(fit, noffset)) {
622 const char *node_name;
626 * Check subnode name, must be equal to "hash" or "signature".
627 * Multiple hash nodes require unique unit node
628 * names, e.g. hash-1, hash-2, signature-1, etc.
630 node_name = fit_get_name(fit, noffset, NULL);
631 if (!strncmp(node_name, FIT_HASH_NODENAME,
632 strlen(FIT_HASH_NODENAME))) {
633 ret = fit_image_process_hash(fit, image_name, noffset,
635 } else if (IMAGE_ENABLE_SIGN && keydir &&
636 !strncmp(node_name, FIT_SIG_NODENAME,
637 strlen(FIT_SIG_NODENAME))) {
638 ret = fit_image_process_sig(keydir, keydest,
639 fit, image_name, noffset, data, size,
640 comment, require_keys, engine_id, cmdname);
654 static void strlist_init(struct strlist *list)
656 memset(list, '\0', sizeof(*list));
659 static void strlist_free(struct strlist *list)
663 for (i = 0; i < list->count; i++)
664 free(list->strings[i]);
668 static int strlist_add(struct strlist *list, const char *str)
673 list->strings = realloc(list->strings,
674 (list->count + 1) * sizeof(char *));
677 list->strings[list->count++] = dup;
682 static const char *fit_config_get_image_list(void *fit, int noffset,
683 int *lenp, int *allow_missingp)
685 static const char default_list[] = FIT_KERNEL_PROP "\0"
689 /* If there is an "image" property, use that */
690 prop = fdt_getprop(fit, noffset, "sign-images", lenp);
693 return *lenp ? prop : NULL;
696 /* Default image list */
698 *lenp = sizeof(default_list);
703 static int fit_config_add_hash(void *fit, const char *conf_name, const char *sig_name,
704 struct strlist *node_inc, const char *iname, int image_noffset)
706 char name[200], path[200];
711 ret = fdt_get_path(fit, image_noffset, path, sizeof(path));
714 if (strlist_add(node_inc, path))
717 snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH,
720 /* Add all this image's hashes */
722 for (noffset = fdt_first_subnode(fit, image_noffset);
724 noffset = fdt_next_subnode(fit, noffset)) {
725 const char *name = fit_get_name(fit, noffset, NULL);
727 if (strncmp(name, FIT_HASH_NODENAME,
728 strlen(FIT_HASH_NODENAME)))
730 ret = fdt_get_path(fit, noffset, path, sizeof(path));
733 if (strlist_add(node_inc, path))
739 printf("Failed to find any hash nodes in configuration '%s/%s' image '%s' - without these it is not possible to verify this image\n",
740 conf_name, sig_name, iname);
744 /* Add this image's cipher node if present */
745 noffset = fdt_subnode_offset(fit, image_noffset,
746 FIT_CIPHER_NODENAME);
747 if (noffset != -FDT_ERR_NOTFOUND) {
749 printf("Failed to get cipher node in configuration '%s/%s' image '%s': %s\n",
750 conf_name, sig_name, iname,
751 fdt_strerror(noffset));
754 ret = fdt_get_path(fit, noffset, path, sizeof(path));
757 if (strlist_add(node_inc, path))
764 printf("Out of memory processing configuration '%s/%s'\n", conf_name,
769 printf("Failed to get path for image '%s' in configuration '%s/%s': %s\n",
770 iname, conf_name, sig_name, fdt_strerror(ret));
774 static int fit_config_get_hash_list(void *fit, int conf_noffset,
775 int sig_offset, struct strlist *node_inc)
778 const char *prop, *iname, *end;
779 const char *conf_name, *sig_name;
784 conf_name = fit_get_name(fit, conf_noffset, NULL);
785 sig_name = fit_get_name(fit, sig_offset, NULL);
788 * Build a list of nodes we need to hash. We always need the root
789 * node and the configuration.
791 strlist_init(node_inc);
792 snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH, conf_name);
793 if (strlist_add(node_inc, "/") ||
794 strlist_add(node_inc, name))
797 /* Get a list of images that we intend to sign */
798 prop = fit_config_get_image_list(fit, sig_offset, &len,
803 /* Locate the images */
806 for (iname = prop; iname < end; iname += strlen(iname) + 1) {
808 int index, max_index;
810 max_index = fdt_stringlist_count(fit, conf_noffset, iname);
812 for (index = 0; index < max_index; index++) {
813 image_noffset = fit_conf_get_prop_node_index(fit, conf_noffset,
816 if (image_noffset < 0) {
817 printf("Failed to find image '%s' in configuration '%s/%s'\n",
818 iname, conf_name, sig_name);
825 ret = fit_config_add_hash(fit, conf_name,
827 iname, image_noffset);
836 printf("Failed to find any images for configuration '%s/%s'\n",
837 conf_name, sig_name);
844 printf("Out of memory processing configuration '%s/%s'\n", conf_name,
849 static int fit_config_get_data(void *fit, int conf_noffset, int noffset,
850 struct image_region **regionp, int *region_countp,
851 char **region_propp, int *region_proplen)
853 char * const exc_prop[] = {"data"};
854 struct strlist node_inc;
855 struct image_region *region;
856 struct fdt_region fdt_regions[100];
857 const char *conf_name, *sig_name;
863 conf_name = fit_get_name(fit, conf_noffset, NULL);
864 sig_name = fit_get_name(fit, noffset, NULL);
865 debug("%s: conf='%s', sig='%s'\n", __func__, conf_name, sig_name);
867 /* Get a list of nodes we want to hash */
868 ret = fit_config_get_hash_list(fit, conf_noffset, noffset, &node_inc);
872 /* Get a list of regions to hash */
873 count = fdt_find_regions(fit, node_inc.strings, node_inc.count,
874 exc_prop, ARRAY_SIZE(exc_prop),
875 fdt_regions, ARRAY_SIZE(fdt_regions),
876 path, sizeof(path), 1);
878 printf("Failed to hash configuration '%s/%s': %s\n", conf_name,
879 sig_name, fdt_strerror(ret));
883 printf("No data to hash for configuration '%s/%s': %s\n",
884 conf_name, sig_name, fdt_strerror(ret));
888 /* Build our list of data blocks */
889 region = fit_region_make_list(fit, fdt_regions, count, NULL);
891 printf("Out of memory hashing configuration '%s/%s'\n",
892 conf_name, sig_name);
896 /* Create a list of all hashed properties */
897 debug("Hash nodes:\n");
898 for (i = len = 0; i < node_inc.count; i++) {
899 debug(" %s\n", node_inc.strings[i]);
900 len += strlen(node_inc.strings[i]) + 1;
902 region_prop = malloc(len);
904 printf("Out of memory setting up regions for configuration '%s/%s'\n",
905 conf_name, sig_name);
908 for (i = len = 0; i < node_inc.count;
909 len += strlen(node_inc.strings[i]) + 1, i++)
910 strcpy(region_prop + len, node_inc.strings[i]);
911 strlist_free(&node_inc);
913 *region_countp = count;
915 *region_propp = region_prop;
916 *region_proplen = len;
921 static int fit_config_process_sig(const char *keydir, void *keydest,
922 void *fit, const char *conf_name, int conf_noffset,
923 int noffset, const char *comment, int require_keys,
924 const char *engine_id, const char *cmdname)
926 struct image_sign_info info;
927 const char *node_name;
928 struct image_region *region;
936 node_name = fit_get_name(fit, noffset, NULL);
937 if (fit_config_get_data(fit, conf_noffset, noffset, ®ion,
938 ®ion_count, ®ion_prop, ®ion_proplen))
941 if (fit_image_setup_sig(&info, keydir, fit, conf_name, noffset,
942 require_keys ? "conf" : NULL, engine_id))
945 ret = info.crypto->sign(&info, region, region_count, &value,
949 printf("Failed to sign '%s' signature node in '%s' conf node\n",
950 node_name, conf_name);
952 /* We allow keys to be missing */
958 ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
959 region_prop, region_proplen, cmdname);
961 if (ret == -FDT_ERR_NOSPACE)
963 printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
964 node_name, conf_name, fdt_strerror(ret));
970 /* Get keyname again, as FDT has changed and invalidated our pointer */
971 info.keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
973 /* Write the public key into the supplied FDT file */
975 ret = info.crypto->add_verify_data(&info, keydest);
977 printf("Failed to add verification data for '%s' signature node in '%s' configuration node\n",
978 node_name, conf_name);
986 static int fit_config_add_verification_data(const char *keydir, void *keydest,
987 void *fit, int conf_noffset, const char *comment,
988 int require_keys, const char *engine_id, const char *cmdname)
990 const char *conf_name;
993 conf_name = fit_get_name(fit, conf_noffset, NULL);
995 /* Process all hash subnodes of the configuration node */
996 for (noffset = fdt_first_subnode(fit, conf_noffset);
998 noffset = fdt_next_subnode(fit, noffset)) {
999 const char *node_name;
1002 node_name = fit_get_name(fit, noffset, NULL);
1003 if (!strncmp(node_name, FIT_SIG_NODENAME,
1004 strlen(FIT_SIG_NODENAME))) {
1005 ret = fit_config_process_sig(keydir, keydest,
1006 fit, conf_name, conf_noffset, noffset, comment,
1007 require_keys, engine_id, cmdname);
1016 int fit_cipher_data(const char *keydir, void *keydest, void *fit,
1017 const char *comment, int require_keys,
1018 const char *engine_id, const char *cmdname)
1024 /* Find images parent node offset */
1025 images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
1026 if (images_noffset < 0) {
1027 printf("Can't find images parent node '%s' (%s)\n",
1028 FIT_IMAGES_PATH, fdt_strerror(images_noffset));
1029 return images_noffset;
1032 /* Process its subnodes, print out component images details */
1033 for (noffset = fdt_first_subnode(fit, images_noffset);
1035 noffset = fdt_next_subnode(fit, noffset)) {
1037 * Direct child node of the images parent node,
1038 * i.e. component image node.
1040 ret = fit_image_cipher_data(keydir, keydest,
1041 fit, noffset, comment,
1042 require_keys, engine_id,
1051 int fit_add_verification_data(const char *keydir, void *keydest, void *fit,
1052 const char *comment, int require_keys,
1053 const char *engine_id, const char *cmdname)
1055 int images_noffset, confs_noffset;
1059 /* Find images parent node offset */
1060 images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
1061 if (images_noffset < 0) {
1062 printf("Can't find images parent node '%s' (%s)\n",
1063 FIT_IMAGES_PATH, fdt_strerror(images_noffset));
1064 return images_noffset;
1067 /* Process its subnodes, print out component images details */
1068 for (noffset = fdt_first_subnode(fit, images_noffset);
1070 noffset = fdt_next_subnode(fit, noffset)) {
1072 * Direct child node of the images parent node,
1073 * i.e. component image node.
1075 ret = fit_image_add_verification_data(keydir, keydest,
1076 fit, noffset, comment, require_keys, engine_id,
1082 /* If there are no keys, we can't sign configurations */
1083 if (!IMAGE_ENABLE_SIGN || !keydir)
1086 /* Find configurations parent node offset */
1087 confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
1088 if (confs_noffset < 0) {
1089 printf("Can't find images parent node '%s' (%s)\n",
1090 FIT_CONFS_PATH, fdt_strerror(confs_noffset));
1094 /* Process its subnodes, print out component images details */
1095 for (noffset = fdt_first_subnode(fit, confs_noffset);
1097 noffset = fdt_next_subnode(fit, noffset)) {
1098 ret = fit_config_add_verification_data(keydir, keydest,
1099 fit, noffset, comment,
1101 engine_id, cmdname);
1109 #ifdef CONFIG_FIT_SIGNATURE
1110 int fit_check_sign(const void *fit, const void *key,
1111 const char *fit_uname_config)
1116 cfg_noffset = fit_conf_get_node(fit, fit_uname_config);
1120 printf("Verifying Hash Integrity for node '%s'... ",
1121 fdt_get_name(fit, cfg_noffset, NULL));
1122 ret = fit_config_verify(fit, cfg_noffset);
1125 printf("Verified OK, loading images\n");
1126 ret = bootm_host_load_images(fit, cfg_noffset);