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,
135 uint32_t t = cpu_to_uimage(timestamp);
137 ret = fdt_setprop(fit, noffset, FIT_TIMESTAMP_PROP, &t,
140 if (region_prop && !ret) {
143 ret = fdt_setprop(fit, noffset, "hashed-nodes",
144 region_prop, region_proplen);
145 /* This is a legacy offset, it is unused, and must remain 0. */
147 strdata[1] = cpu_to_fdt32(string_size);
149 ret = fdt_setprop(fit, noffset, "hashed-strings",
150 strdata, sizeof(strdata));
157 static int fit_image_setup_sig(struct image_sign_info *info,
158 const char *keydir, const char *keyfile, void *fit,
159 const char *image_name, int noffset, const char *require_keys,
160 const char *engine_id)
162 const char *node_name;
164 const char *padding_name;
166 node_name = fit_get_name(fit, noffset, NULL);
167 if (fit_image_hash_get_algo(fit, noffset, &algo_name)) {
168 printf("Can't get algo property for '%s' signature node in '%s' image node\n",
169 node_name, image_name);
173 padding_name = fdt_getprop(fit, noffset, "padding", NULL);
175 memset(info, '\0', sizeof(*info));
176 info->keydir = keydir;
177 info->keyfile = keyfile;
178 info->keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
180 info->node_offset = noffset;
181 info->name = strdup(algo_name);
182 info->checksum = image_get_checksum_algo(algo_name);
183 info->crypto = image_get_crypto_algo(algo_name);
184 info->padding = image_get_padding_algo(padding_name);
185 info->require_keys = require_keys;
186 info->engine_id = engine_id;
187 if (!info->checksum || !info->crypto) {
188 printf("Unsupported signature algorithm (%s) for '%s' signature node in '%s' image node\n",
189 algo_name, node_name, image_name);
197 * fit_image_process_sig- Process a single subnode of the images/ node
199 * Check each subnode and process accordingly. For signature nodes we
200 * generate a signed hash of the supplised data and store it in the node.
202 * @keydir: Directory containing keys to use for signing
203 * @keydest: Destination FDT blob to write public keys into
204 * @fit: pointer to the FIT format image header
205 * @image_name: name of image being processes (used to display errors)
206 * @noffset: subnode offset
207 * @data: data to process
208 * @size: size of data in bytes
209 * @comment: Comment to add to signature nodes
210 * @require_keys: Mark all keys as 'required'
211 * @engine_id: Engine to use for signing
212 * @return 0 if ok, -1 on error
214 static int fit_image_process_sig(const char *keydir, const char *keyfile,
215 void *keydest, void *fit, const char *image_name,
216 int noffset, const void *data, size_t size,
217 const char *comment, int require_keys, const char *engine_id,
220 struct image_sign_info info;
221 struct image_region region;
222 const char *node_name;
227 if (fit_image_setup_sig(&info, keydir, keyfile, fit, image_name,
228 noffset, require_keys ? "image" : NULL,
232 node_name = fit_get_name(fit, noffset, NULL);
235 ret = info.crypto->sign(&info, ®ion, 1, &value, &value_len);
237 printf("Failed to sign '%s' signature node in '%s' image node: %d\n",
238 node_name, image_name, ret);
240 /* We allow keys to be missing */
246 ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
249 if (ret == -FDT_ERR_NOSPACE)
251 printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
252 node_name, image_name, fdt_strerror(ret));
257 /* Get keyname again, as FDT has changed and invalidated our pointer */
258 info.keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
261 * Write the public key into the supplied FDT file; this might fail
262 * several times, since we try signing with successively increasing
266 ret = info.crypto->add_verify_data(&info, keydest);
268 printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
269 node_name, image_name);
277 static int fit_image_read_data(char *filename, unsigned char *data,
285 fd = open(filename, O_RDONLY | O_BINARY);
287 printf("Can't open file %s (err=%d => %s)\n",
288 filename, errno, strerror(errno));
292 /* Compute file size */
293 if (fstat(fd, &sbuf) < 0) {
294 printf("Can't fstat file %s (err=%d => %s)\n",
295 filename, errno, strerror(errno));
299 /* Check file size */
300 if (sbuf.st_size != expected_size) {
301 printf("File %s don't have the expected size (size=%lld, expected=%d)\n",
302 filename, (long long)sbuf.st_size, expected_size);
307 n = read(fd, data, sbuf.st_size);
309 printf("Can't read file %s (err=%d => %s)\n",
310 filename, errno, strerror(errno));
314 /* Check that we have read all the file */
315 if (n != sbuf.st_size) {
316 printf("Can't read all file %s (read %zd bytes, expexted %lld)\n",
317 filename, n, (long long)sbuf.st_size);
328 static int get_random_data(void *data, int size)
330 unsigned char *tmp = data;
331 struct timespec date;
335 printf("%s: pointer data is NULL\n", __func__);
340 ret = clock_gettime(CLOCK_MONOTONIC, &date);
342 printf("%s: clock_gettime has failed (err=%d, str=%s)\n",
343 __func__, ret, strerror(errno));
347 srandom(date.tv_nsec);
349 for (i = 0; i < size; i++) {
350 *tmp = random() & 0xff;
358 static int fit_image_setup_cipher(struct image_cipher_info *info,
359 const char *keydir, void *fit,
360 const char *image_name, int image_noffset,
367 if (fit_image_cipher_get_algo(fit, noffset, &algo_name)) {
368 printf("Can't get algo name for cipher in image '%s'\n",
373 info->keydir = keydir;
375 /* Read the key name */
376 info->keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
377 if (!info->keyname) {
378 printf("Can't get key name for cipher in image '%s'\n",
386 * If this property is not provided then mkimage will generate
387 * a random IV and store it in the FIT image
389 info->ivname = fdt_getprop(fit, noffset, "iv-name-hint", NULL);
392 info->node_noffset = noffset;
393 info->name = algo_name;
395 info->cipher = image_get_cipher_algo(algo_name);
397 printf("Can't get algo for cipher '%s'\n", image_name);
401 /* Read the key in the file */
402 snprintf(filename, sizeof(filename), "%s/%s%s",
403 info->keydir, info->keyname, ".bin");
404 info->key = malloc(info->cipher->key_len);
406 printf("Can't allocate memory for key\n");
410 ret = fit_image_read_data(filename, (unsigned char *)info->key,
411 info->cipher->key_len);
415 info->iv = malloc(info->cipher->iv_len);
417 printf("Can't allocate memory for iv\n");
423 /* Read the IV in the file */
424 snprintf(filename, sizeof(filename), "%s/%s%s",
425 info->keydir, info->ivname, ".bin");
426 ret = fit_image_read_data(filename, (unsigned char *)info->iv,
427 info->cipher->iv_len);
429 /* Generate an ramdom IV */
430 ret = get_random_data((void *)info->iv, info->cipher->iv_len);
437 int fit_image_write_cipher(void *fit, int image_noffset, int noffset,
438 const void *data, size_t size,
439 unsigned char *data_ciphered, int data_ciphered_len)
443 /* Replace data with ciphered data */
444 ret = fdt_setprop(fit, image_noffset, FIT_DATA_PROP,
445 data_ciphered, data_ciphered_len);
446 if (ret == -FDT_ERR_NOSPACE) {
451 printf("Can't replace data with ciphered data (err = %d)\n", ret);
455 /* add non ciphered data size */
456 ret = fdt_setprop_u32(fit, image_noffset, "data-size-unciphered", size);
457 if (ret == -FDT_ERR_NOSPACE) {
462 printf("Can't add unciphered data size (err = %d)\n", ret);
471 fit_image_process_cipher(const char *keydir, void *keydest, void *fit,
472 const char *image_name, int image_noffset,
473 int node_noffset, const void *data, size_t size,
476 struct image_cipher_info info;
477 unsigned char *data_ciphered = NULL;
478 int data_ciphered_len;
481 memset(&info, 0, sizeof(info));
483 ret = fit_image_setup_cipher(&info, keydir, fit, image_name,
484 image_noffset, node_noffset);
488 ret = info.cipher->encrypt(&info, data, size,
489 &data_ciphered, &data_ciphered_len);
494 * Write the public key into the supplied FDT file; this might fail
495 * several times, since we try signing with successively increasing
497 * And, if needed, write the iv in the FIT file
500 ret = info.cipher->add_cipher_data(&info, keydest, fit, node_noffset);
502 printf("Failed to add verification data for cipher '%s' in image '%s'\n",
503 info.keyname, image_name);
508 ret = fit_image_write_cipher(fit, image_noffset, node_noffset,
510 data_ciphered, data_ciphered_len);
514 free((void *)info.key);
515 free((void *)info.iv);
519 int fit_image_cipher_data(const char *keydir, void *keydest,
520 void *fit, int image_noffset, const char *comment,
521 int require_keys, const char *engine_id,
524 const char *image_name;
527 int cipher_node_offset, len;
530 image_name = fit_get_name(fit, image_noffset, NULL);
532 printf("Can't get image name\n");
536 /* Get image data and data length */
537 if (fit_image_get_data(fit, image_noffset, &data, &size)) {
538 printf("Can't get image data/size\n");
543 * Don't cipher ciphered data.
545 * If the data-size-unciphered property is present the data for this
546 * image is already encrypted. This is important as 'mkimage -F' can be
547 * run multiple times on a FIT image.
549 if (fdt_getprop(fit, image_noffset, "data-size-unciphered", &len))
551 if (len != -FDT_ERR_NOTFOUND) {
552 printf("Failure testing for data-size-unciphered\n");
556 /* Process cipher node if present */
557 cipher_node_offset = fdt_subnode_offset(fit, image_noffset,
558 FIT_CIPHER_NODENAME);
559 if (cipher_node_offset == -FDT_ERR_NOTFOUND)
561 if (cipher_node_offset < 0) {
562 printf("Failure getting cipher node\n");
565 if (!IMAGE_ENABLE_ENCRYPT || !keydir)
567 return fit_image_process_cipher(keydir, keydest, fit, image_name,
568 image_noffset, cipher_node_offset, data, size, cmdname);
572 * fit_image_add_verification_data() - calculate/set verig. data for image node
574 * This adds hash and signature values for an component image node.
576 * All existing hash subnodes are checked, if algorithm property is set to
577 * one of the supported hash algorithms, hash value is computed and
578 * corresponding hash node property is set, for example:
580 * Input component image node structure:
582 * o image-1 (at image_noffset)
583 * | - data = [binary data]
587 * Output component image node structure:
589 * o image-1 (at image_noffset)
590 * | - data = [binary data]
593 * |- value = sha1(data)
595 * For signature details, please see doc/uImage.FIT/signature.txt
597 * @keydir Directory containing *.key and *.crt files (or NULL)
598 * @keydest FDT Blob to write public keys into (NULL if none)
599 * @fit: Pointer to the FIT format image header
600 * @image_noffset: Requested component image node
601 * @comment: Comment to add to signature nodes
602 * @require_keys: Mark all keys as 'required'
603 * @engine_id: Engine to use for signing
604 * @return: 0 on success, <0 on failure
606 int fit_image_add_verification_data(const char *keydir, const char *keyfile,
607 void *keydest, void *fit, int image_noffset,
608 const char *comment, int require_keys, const char *engine_id,
611 const char *image_name;
616 /* Get image data and data length */
617 if (fit_image_get_data(fit, image_noffset, &data, &size)) {
618 printf("Can't get image data/size\n");
622 image_name = fit_get_name(fit, image_noffset, NULL);
624 /* Process all hash subnodes of the component image node */
625 for (noffset = fdt_first_subnode(fit, image_noffset);
627 noffset = fdt_next_subnode(fit, noffset)) {
628 const char *node_name;
632 * Check subnode name, must be equal to "hash" or "signature".
633 * Multiple hash nodes require unique unit node
634 * names, e.g. hash-1, hash-2, signature-1, etc.
636 node_name = fit_get_name(fit, noffset, NULL);
637 if (!strncmp(node_name, FIT_HASH_NODENAME,
638 strlen(FIT_HASH_NODENAME))) {
639 ret = fit_image_process_hash(fit, image_name, noffset,
641 } else if (IMAGE_ENABLE_SIGN && (keydir || keyfile) &&
642 !strncmp(node_name, FIT_SIG_NODENAME,
643 strlen(FIT_SIG_NODENAME))) {
644 ret = fit_image_process_sig(keydir, keyfile, keydest,
645 fit, image_name, noffset, data, size,
646 comment, require_keys, engine_id, cmdname);
660 static void strlist_init(struct strlist *list)
662 memset(list, '\0', sizeof(*list));
665 static void strlist_free(struct strlist *list)
669 for (i = 0; i < list->count; i++)
670 free(list->strings[i]);
674 static int strlist_add(struct strlist *list, const char *str)
679 list->strings = realloc(list->strings,
680 (list->count + 1) * sizeof(char *));
683 list->strings[list->count++] = dup;
688 static const char *fit_config_get_image_list(void *fit, int noffset,
689 int *lenp, int *allow_missingp)
691 static const char default_list[] = FIT_KERNEL_PROP "\0"
695 /* If there is an "image" property, use that */
696 prop = fdt_getprop(fit, noffset, "sign-images", lenp);
699 return *lenp ? prop : NULL;
702 /* Default image list */
704 *lenp = sizeof(default_list);
709 static int fit_config_add_hash(void *fit, const char *conf_name, const char *sig_name,
710 struct strlist *node_inc, const char *iname, int image_noffset)
712 char name[200], path[200];
717 ret = fdt_get_path(fit, image_noffset, path, sizeof(path));
720 if (strlist_add(node_inc, path))
723 snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH,
726 /* Add all this image's hashes */
728 for (noffset = fdt_first_subnode(fit, image_noffset);
730 noffset = fdt_next_subnode(fit, noffset)) {
731 const char *name = fit_get_name(fit, noffset, NULL);
733 if (strncmp(name, FIT_HASH_NODENAME,
734 strlen(FIT_HASH_NODENAME)))
736 ret = fdt_get_path(fit, noffset, path, sizeof(path));
739 if (strlist_add(node_inc, path))
745 printf("Failed to find any hash nodes in configuration '%s/%s' image '%s' - without these it is not possible to verify this image\n",
746 conf_name, sig_name, iname);
750 /* Add this image's cipher node if present */
751 noffset = fdt_subnode_offset(fit, image_noffset,
752 FIT_CIPHER_NODENAME);
753 if (noffset != -FDT_ERR_NOTFOUND) {
755 printf("Failed to get cipher node in configuration '%s/%s' image '%s': %s\n",
756 conf_name, sig_name, iname,
757 fdt_strerror(noffset));
760 ret = fdt_get_path(fit, noffset, path, sizeof(path));
763 if (strlist_add(node_inc, path))
770 printf("Out of memory processing configuration '%s/%s'\n", conf_name,
775 printf("Failed to get path for image '%s' in configuration '%s/%s': %s\n",
776 iname, conf_name, sig_name, fdt_strerror(ret));
780 static int fit_config_get_hash_list(void *fit, int conf_noffset,
781 int sig_offset, struct strlist *node_inc)
784 const char *prop, *iname, *end;
785 const char *conf_name, *sig_name;
790 conf_name = fit_get_name(fit, conf_noffset, NULL);
791 sig_name = fit_get_name(fit, sig_offset, NULL);
794 * Build a list of nodes we need to hash. We always need the root
795 * node and the configuration.
797 strlist_init(node_inc);
798 snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH, conf_name);
799 if (strlist_add(node_inc, "/") ||
800 strlist_add(node_inc, name))
803 /* Get a list of images that we intend to sign */
804 prop = fit_config_get_image_list(fit, sig_offset, &len,
809 /* Locate the images */
812 for (iname = prop; iname < end; iname += strlen(iname) + 1) {
814 int index, max_index;
816 max_index = fdt_stringlist_count(fit, conf_noffset, iname);
818 for (index = 0; index < max_index; index++) {
819 image_noffset = fit_conf_get_prop_node_index(fit, conf_noffset,
822 if (image_noffset < 0) {
823 printf("Failed to find image '%s' in configuration '%s/%s'\n",
824 iname, conf_name, sig_name);
831 ret = fit_config_add_hash(fit, conf_name,
833 iname, image_noffset);
842 printf("Failed to find any images for configuration '%s/%s'\n",
843 conf_name, sig_name);
850 printf("Out of memory processing configuration '%s/%s'\n", conf_name,
855 static int fit_config_get_data(void *fit, int conf_noffset, int noffset,
856 struct image_region **regionp, int *region_countp,
857 char **region_propp, int *region_proplen)
859 char * const exc_prop[] = {"data"};
860 struct strlist node_inc;
861 struct image_region *region;
862 struct fdt_region fdt_regions[100];
863 const char *conf_name, *sig_name;
869 conf_name = fit_get_name(fit, conf_noffset, NULL);
870 sig_name = fit_get_name(fit, noffset, NULL);
871 debug("%s: conf='%s', sig='%s'\n", __func__, conf_name, sig_name);
873 /* Get a list of nodes we want to hash */
874 ret = fit_config_get_hash_list(fit, conf_noffset, noffset, &node_inc);
878 /* Get a list of regions to hash */
879 count = fdt_find_regions(fit, node_inc.strings, node_inc.count,
880 exc_prop, ARRAY_SIZE(exc_prop),
881 fdt_regions, ARRAY_SIZE(fdt_regions),
882 path, sizeof(path), 1);
884 printf("Failed to hash configuration '%s/%s': %s\n", conf_name,
885 sig_name, fdt_strerror(ret));
889 printf("No data to hash for configuration '%s/%s': %s\n",
890 conf_name, sig_name, fdt_strerror(ret));
894 /* Build our list of data blocks */
895 region = fit_region_make_list(fit, fdt_regions, count, NULL);
897 printf("Out of memory hashing configuration '%s/%s'\n",
898 conf_name, sig_name);
902 /* Create a list of all hashed properties */
903 debug("Hash nodes:\n");
904 for (i = len = 0; i < node_inc.count; i++) {
905 debug(" %s\n", node_inc.strings[i]);
906 len += strlen(node_inc.strings[i]) + 1;
908 region_prop = malloc(len);
910 printf("Out of memory setting up regions for configuration '%s/%s'\n",
911 conf_name, sig_name);
914 for (i = len = 0; i < node_inc.count;
915 len += strlen(node_inc.strings[i]) + 1, i++)
916 strcpy(region_prop + len, node_inc.strings[i]);
917 strlist_free(&node_inc);
919 *region_countp = count;
921 *region_propp = region_prop;
922 *region_proplen = len;
927 static int fit_config_process_sig(const char *keydir, const char *keyfile,
928 void *keydest, void *fit, const char *conf_name,
929 int conf_noffset, int noffset, const char *comment,
930 int require_keys, const char *engine_id, const char *cmdname)
932 struct image_sign_info info;
933 const char *node_name;
934 struct image_region *region;
942 node_name = fit_get_name(fit, noffset, NULL);
943 if (fit_config_get_data(fit, conf_noffset, noffset, ®ion,
944 ®ion_count, ®ion_prop, ®ion_proplen))
947 if (fit_image_setup_sig(&info, keydir, keyfile, fit, conf_name, noffset,
948 require_keys ? "conf" : NULL, engine_id))
951 ret = info.crypto->sign(&info, region, region_count, &value,
955 printf("Failed to sign '%s' signature node in '%s' conf node\n",
956 node_name, conf_name);
958 /* We allow keys to be missing */
964 ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
965 region_prop, region_proplen, cmdname);
967 if (ret == -FDT_ERR_NOSPACE)
969 printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
970 node_name, conf_name, fdt_strerror(ret));
976 /* Get keyname again, as FDT has changed and invalidated our pointer */
977 info.keyname = fdt_getprop(fit, noffset, FIT_KEY_HINT, NULL);
979 /* Write the public key into the supplied FDT file */
981 ret = info.crypto->add_verify_data(&info, keydest);
983 printf("Failed to add verification data for '%s' signature node in '%s' configuration node\n",
984 node_name, conf_name);
992 static int fit_config_add_verification_data(const char *keydir,
993 const char *keyfile, void *keydest, void *fit, int conf_noffset,
994 const char *comment, int require_keys, const char *engine_id,
997 const char *conf_name;
1000 conf_name = fit_get_name(fit, conf_noffset, NULL);
1002 /* Process all hash subnodes of the configuration node */
1003 for (noffset = fdt_first_subnode(fit, conf_noffset);
1005 noffset = fdt_next_subnode(fit, noffset)) {
1006 const char *node_name;
1009 node_name = fit_get_name(fit, noffset, NULL);
1010 if (!strncmp(node_name, FIT_SIG_NODENAME,
1011 strlen(FIT_SIG_NODENAME))) {
1012 ret = fit_config_process_sig(keydir, keyfile, keydest,
1013 fit, conf_name, conf_noffset, noffset, comment,
1014 require_keys, engine_id, cmdname);
1023 int fit_cipher_data(const char *keydir, void *keydest, void *fit,
1024 const char *comment, int require_keys,
1025 const char *engine_id, const char *cmdname)
1031 /* Find images parent node offset */
1032 images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
1033 if (images_noffset < 0) {
1034 printf("Can't find images parent node '%s' (%s)\n",
1035 FIT_IMAGES_PATH, fdt_strerror(images_noffset));
1036 return images_noffset;
1039 /* Process its subnodes, print out component images details */
1040 for (noffset = fdt_first_subnode(fit, images_noffset);
1042 noffset = fdt_next_subnode(fit, noffset)) {
1044 * Direct child node of the images parent node,
1045 * i.e. component image node.
1047 ret = fit_image_cipher_data(keydir, keydest,
1048 fit, noffset, comment,
1049 require_keys, engine_id,
1058 int fit_add_verification_data(const char *keydir, const char *keyfile,
1059 void *keydest, void *fit, const char *comment,
1060 int require_keys, const char *engine_id,
1061 const char *cmdname)
1063 int images_noffset, confs_noffset;
1067 /* Find images parent node offset */
1068 images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
1069 if (images_noffset < 0) {
1070 printf("Can't find images parent node '%s' (%s)\n",
1071 FIT_IMAGES_PATH, fdt_strerror(images_noffset));
1072 return images_noffset;
1075 /* Process its subnodes, print out component images details */
1076 for (noffset = fdt_first_subnode(fit, images_noffset);
1078 noffset = fdt_next_subnode(fit, noffset)) {
1080 * Direct child node of the images parent node,
1081 * i.e. component image node.
1083 ret = fit_image_add_verification_data(keydir, keyfile, keydest,
1084 fit, noffset, comment, require_keys, engine_id,
1090 /* If there are no keys, we can't sign configurations */
1091 if (!IMAGE_ENABLE_SIGN || !(keydir || keyfile))
1094 /* Find configurations parent node offset */
1095 confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
1096 if (confs_noffset < 0) {
1097 printf("Can't find images parent node '%s' (%s)\n",
1098 FIT_CONFS_PATH, fdt_strerror(confs_noffset));
1102 /* Process its subnodes, print out component images details */
1103 for (noffset = fdt_first_subnode(fit, confs_noffset);
1105 noffset = fdt_next_subnode(fit, noffset)) {
1106 ret = fit_config_add_verification_data(keydir, keyfile, keydest,
1107 fit, noffset, comment,
1109 engine_id, cmdname);
1117 #ifdef CONFIG_FIT_SIGNATURE
1118 int fit_check_sign(const void *fit, const void *key,
1119 const char *fit_uname_config)
1124 cfg_noffset = fit_conf_get_node(fit, fit_uname_config);
1128 printf("Verifying Hash Integrity for node '%s'... ",
1129 fdt_get_name(fit, cfg_noffset, NULL));
1130 ret = fit_config_verify(fit, cfg_noffset);
1133 printf("Verified OK, loading images\n");
1134 ret = bootm_host_load_images(fit, cfg_noffset);