image-host.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /*
  2. * Copyright (c) 2013, Google Inc.
  3. *
  4. * (C) Copyright 2008 Semihalf
  5. *
  6. * (C) Copyright 2000-2006
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include "mkimage.h"
  12. #include <bootm.h>
  13. #include <image.h>
  14. #include <version.h>
  15. /**
  16. * fit_set_hash_value - set hash value in requested has node
  17. * @fit: pointer to the FIT format image header
  18. * @noffset: hash node offset
  19. * @value: hash value to be set
  20. * @value_len: hash value length
  21. *
  22. * fit_set_hash_value() attempts to set hash value in a node at offset
  23. * given and returns operation status to the caller.
  24. *
  25. * returns
  26. * 0, on success
  27. * -1, on failure
  28. */
  29. static int fit_set_hash_value(void *fit, int noffset, uint8_t *value,
  30. int value_len)
  31. {
  32. int ret;
  33. ret = fdt_setprop(fit, noffset, FIT_VALUE_PROP, value, value_len);
  34. if (ret) {
  35. printf("Can't set hash '%s' property for '%s' node(%s)\n",
  36. FIT_VALUE_PROP, fit_get_name(fit, noffset, NULL),
  37. fdt_strerror(ret));
  38. return ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
  39. }
  40. return 0;
  41. }
  42. /**
  43. * fit_image_process_hash - Process a single subnode of the images/ node
  44. *
  45. * Check each subnode and process accordingly. For hash nodes we generate
  46. * a hash of the supplised data and store it in the node.
  47. *
  48. * @fit: pointer to the FIT format image header
  49. * @image_name: name of image being processes (used to display errors)
  50. * @noffset: subnode offset
  51. * @data: data to process
  52. * @size: size of data in bytes
  53. * @return 0 if ok, -1 on error
  54. */
  55. static int fit_image_process_hash(void *fit, const char *image_name,
  56. int noffset, const void *data, size_t size)
  57. {
  58. uint8_t value[FIT_MAX_HASH_LEN];
  59. const char *node_name;
  60. int value_len;
  61. char *algo;
  62. int ret;
  63. node_name = fit_get_name(fit, noffset, NULL);
  64. if (fit_image_hash_get_algo(fit, noffset, &algo)) {
  65. printf("Can't get hash algo property for '%s' hash node in '%s' image node\n",
  66. node_name, image_name);
  67. return -ENOENT;
  68. }
  69. if (calculate_hash(data, size, algo, value, &value_len)) {
  70. printf("Unsupported hash algorithm (%s) for '%s' hash node in '%s' image node\n",
  71. algo, node_name, image_name);
  72. return -EPROTONOSUPPORT;
  73. }
  74. ret = fit_set_hash_value(fit, noffset, value, value_len);
  75. if (ret) {
  76. printf("Can't set hash value for '%s' hash node in '%s' image node\n",
  77. node_name, image_name);
  78. return ret;
  79. }
  80. return 0;
  81. }
  82. /**
  83. * fit_image_write_sig() - write the signature to a FIT
  84. *
  85. * This writes the signature and signer data to the FIT.
  86. *
  87. * @fit: pointer to the FIT format image header
  88. * @noffset: hash node offset
  89. * @value: signature value to be set
  90. * @value_len: signature value length
  91. * @comment: Text comment to write (NULL for none)
  92. *
  93. * returns
  94. * 0, on success
  95. * -FDT_ERR_..., on failure
  96. */
  97. static int fit_image_write_sig(void *fit, int noffset, uint8_t *value,
  98. int value_len, const char *comment, const char *region_prop,
  99. int region_proplen)
  100. {
  101. int string_size;
  102. int ret;
  103. /*
  104. * Get the current string size, before we update the FIT and add
  105. * more
  106. */
  107. string_size = fdt_size_dt_strings(fit);
  108. ret = fdt_setprop(fit, noffset, FIT_VALUE_PROP, value, value_len);
  109. if (!ret) {
  110. ret = fdt_setprop_string(fit, noffset, "signer-name",
  111. "mkimage");
  112. }
  113. if (!ret) {
  114. ret = fdt_setprop_string(fit, noffset, "signer-version",
  115. PLAIN_VERSION);
  116. }
  117. if (comment && !ret)
  118. ret = fdt_setprop_string(fit, noffset, "comment", comment);
  119. if (!ret)
  120. ret = fit_set_timestamp(fit, noffset, time(NULL));
  121. if (region_prop && !ret) {
  122. uint32_t strdata[2];
  123. ret = fdt_setprop(fit, noffset, "hashed-nodes",
  124. region_prop, region_proplen);
  125. strdata[0] = 0;
  126. strdata[1] = cpu_to_fdt32(string_size);
  127. if (!ret) {
  128. ret = fdt_setprop(fit, noffset, "hashed-strings",
  129. strdata, sizeof(strdata));
  130. }
  131. }
  132. return ret;
  133. }
  134. static int fit_image_setup_sig(struct image_sign_info *info,
  135. const char *keydir, void *fit, const char *image_name,
  136. int noffset, const char *require_keys)
  137. {
  138. const char *node_name;
  139. char *algo_name;
  140. node_name = fit_get_name(fit, noffset, NULL);
  141. if (fit_image_hash_get_algo(fit, noffset, &algo_name)) {
  142. printf("Can't get algo property for '%s' signature node in '%s' image node\n",
  143. node_name, image_name);
  144. return -1;
  145. }
  146. memset(info, '\0', sizeof(*info));
  147. info->keydir = keydir;
  148. info->keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
  149. info->fit = fit;
  150. info->node_offset = noffset;
  151. info->algo = image_get_sig_algo(algo_name);
  152. info->require_keys = require_keys;
  153. if (!info->algo) {
  154. printf("Unsupported signature algorithm (%s) for '%s' signature node in '%s' image node\n",
  155. algo_name, node_name, image_name);
  156. return -1;
  157. }
  158. return 0;
  159. }
  160. /**
  161. * fit_image_process_sig- Process a single subnode of the images/ node
  162. *
  163. * Check each subnode and process accordingly. For signature nodes we
  164. * generate a signed hash of the supplised data and store it in the node.
  165. *
  166. * @keydir: Directory containing keys to use for signing
  167. * @keydest: Destination FDT blob to write public keys into
  168. * @fit: pointer to the FIT format image header
  169. * @image_name: name of image being processes (used to display errors)
  170. * @noffset: subnode offset
  171. * @data: data to process
  172. * @size: size of data in bytes
  173. * @comment: Comment to add to signature nodes
  174. * @require_keys: Mark all keys as 'required'
  175. * @return 0 if ok, -1 on error
  176. */
  177. static int fit_image_process_sig(const char *keydir, void *keydest,
  178. void *fit, const char *image_name,
  179. int noffset, const void *data, size_t size,
  180. const char *comment, int require_keys)
  181. {
  182. struct image_sign_info info;
  183. struct image_region region;
  184. const char *node_name;
  185. uint8_t *value;
  186. uint value_len;
  187. int ret;
  188. if (fit_image_setup_sig(&info, keydir, fit, image_name, noffset,
  189. require_keys ? "image" : NULL))
  190. return -1;
  191. node_name = fit_get_name(fit, noffset, NULL);
  192. region.data = data;
  193. region.size = size;
  194. ret = info.algo->sign(&info, &region, 1, &value, &value_len);
  195. if (ret) {
  196. printf("Failed to sign '%s' signature node in '%s' image node: %d\n",
  197. node_name, image_name, ret);
  198. /* We allow keys to be missing */
  199. if (ret == -ENOENT)
  200. return 0;
  201. return -1;
  202. }
  203. ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
  204. NULL, 0);
  205. if (ret) {
  206. if (ret == -FDT_ERR_NOSPACE)
  207. return -ENOSPC;
  208. printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
  209. node_name, image_name, fdt_strerror(ret));
  210. return -1;
  211. }
  212. free(value);
  213. /* Get keyname again, as FDT has changed and invalidated our pointer */
  214. info.keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
  215. if (keydest)
  216. ret = info.algo->add_verify_data(&info, keydest);
  217. else
  218. return -1;
  219. /*
  220. * Write the public key into the supplied FDT file; this might fail
  221. * several times, since we try signing with successively increasing
  222. * size values
  223. */
  224. if (keydest && ret)
  225. return ret;
  226. return 0;
  227. }
  228. /**
  229. * fit_image_add_verification_data() - calculate/set verig. data for image node
  230. *
  231. * This adds hash and signature values for an component image node.
  232. *
  233. * All existing hash subnodes are checked, if algorithm property is set to
  234. * one of the supported hash algorithms, hash value is computed and
  235. * corresponding hash node property is set, for example:
  236. *
  237. * Input component image node structure:
  238. *
  239. * o image@1 (at image_noffset)
  240. * | - data = [binary data]
  241. * o hash@1
  242. * |- algo = "sha1"
  243. *
  244. * Output component image node structure:
  245. *
  246. * o image@1 (at image_noffset)
  247. * | - data = [binary data]
  248. * o hash@1
  249. * |- algo = "sha1"
  250. * |- value = sha1(data)
  251. *
  252. * For signature details, please see doc/uImage.FIT/signature.txt
  253. *
  254. * @keydir Directory containing *.key and *.crt files (or NULL)
  255. * @keydest FDT Blob to write public keys into (NULL if none)
  256. * @fit: Pointer to the FIT format image header
  257. * @image_noffset: Requested component image node
  258. * @comment: Comment to add to signature nodes
  259. * @require_keys: Mark all keys as 'required'
  260. * @return: 0 on success, <0 on failure
  261. */
  262. int fit_image_add_verification_data(const char *keydir, void *keydest,
  263. void *fit, int image_noffset, const char *comment,
  264. int require_keys)
  265. {
  266. const char *image_name;
  267. const void *data;
  268. size_t size;
  269. int noffset;
  270. /* Get image data and data length */
  271. if (fit_image_get_data(fit, image_noffset, &data, &size)) {
  272. printf("Can't get image data/size\n");
  273. return -1;
  274. }
  275. image_name = fit_get_name(fit, image_noffset, NULL);
  276. /* Process all hash subnodes of the component image node */
  277. for (noffset = fdt_first_subnode(fit, image_noffset);
  278. noffset >= 0;
  279. noffset = fdt_next_subnode(fit, noffset)) {
  280. const char *node_name;
  281. int ret = 0;
  282. /*
  283. * Check subnode name, must be equal to "hash" or "signature".
  284. * Multiple hash nodes require unique unit node
  285. * names, e.g. hash@1, hash@2, signature@1, etc.
  286. */
  287. node_name = fit_get_name(fit, noffset, NULL);
  288. if (!strncmp(node_name, FIT_HASH_NODENAME,
  289. strlen(FIT_HASH_NODENAME))) {
  290. ret = fit_image_process_hash(fit, image_name, noffset,
  291. data, size);
  292. } else if (IMAGE_ENABLE_SIGN && keydir &&
  293. !strncmp(node_name, FIT_SIG_NODENAME,
  294. strlen(FIT_SIG_NODENAME))) {
  295. ret = fit_image_process_sig(keydir, keydest,
  296. fit, image_name, noffset, data, size,
  297. comment, require_keys);
  298. }
  299. if (ret)
  300. return ret;
  301. }
  302. return 0;
  303. }
  304. struct strlist {
  305. int count;
  306. char **strings;
  307. };
  308. static void strlist_init(struct strlist *list)
  309. {
  310. memset(list, '\0', sizeof(*list));
  311. }
  312. static void strlist_free(struct strlist *list)
  313. {
  314. int i;
  315. for (i = 0; i < list->count; i++)
  316. free(list->strings[i]);
  317. free(list->strings);
  318. }
  319. static int strlist_add(struct strlist *list, const char *str)
  320. {
  321. char *dup;
  322. dup = strdup(str);
  323. list->strings = realloc(list->strings,
  324. (list->count + 1) * sizeof(char *));
  325. if (!list || !str)
  326. return -1;
  327. list->strings[list->count++] = dup;
  328. return 0;
  329. }
  330. static const char *fit_config_get_image_list(void *fit, int noffset,
  331. int *lenp, int *allow_missingp)
  332. {
  333. static const char default_list[] = FIT_KERNEL_PROP "\0"
  334. FIT_FDT_PROP;
  335. const char *prop;
  336. /* If there is an "image" property, use that */
  337. prop = fdt_getprop(fit, noffset, "sign-images", lenp);
  338. if (prop) {
  339. *allow_missingp = 0;
  340. return *lenp ? prop : NULL;
  341. }
  342. /* Default image list */
  343. *allow_missingp = 1;
  344. *lenp = sizeof(default_list);
  345. return default_list;
  346. }
  347. static int fit_config_get_hash_list(void *fit, int conf_noffset,
  348. int sig_offset, struct strlist *node_inc)
  349. {
  350. int allow_missing;
  351. const char *prop, *iname, *end;
  352. const char *conf_name, *sig_name;
  353. char name[200], path[200];
  354. int image_count;
  355. int ret, len;
  356. conf_name = fit_get_name(fit, conf_noffset, NULL);
  357. sig_name = fit_get_name(fit, sig_offset, NULL);
  358. /*
  359. * Build a list of nodes we need to hash. We always need the root
  360. * node and the configuration.
  361. */
  362. strlist_init(node_inc);
  363. snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH, conf_name);
  364. if (strlist_add(node_inc, "/") ||
  365. strlist_add(node_inc, name))
  366. goto err_mem;
  367. /* Get a list of images that we intend to sign */
  368. prop = fit_config_get_image_list(fit, sig_offset, &len,
  369. &allow_missing);
  370. if (!prop)
  371. return 0;
  372. /* Locate the images */
  373. end = prop + len;
  374. image_count = 0;
  375. for (iname = prop; iname < end; iname += strlen(iname) + 1) {
  376. int noffset;
  377. int image_noffset;
  378. int hash_count;
  379. image_noffset = fit_conf_get_prop_node(fit, conf_noffset,
  380. iname);
  381. if (image_noffset < 0) {
  382. printf("Failed to find image '%s' in configuration '%s/%s'\n",
  383. iname, conf_name, sig_name);
  384. if (allow_missing)
  385. continue;
  386. return -ENOENT;
  387. }
  388. ret = fdt_get_path(fit, image_noffset, path, sizeof(path));
  389. if (ret < 0)
  390. goto err_path;
  391. if (strlist_add(node_inc, path))
  392. goto err_mem;
  393. snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH,
  394. conf_name);
  395. /* Add all this image's hashes */
  396. hash_count = 0;
  397. for (noffset = fdt_first_subnode(fit, image_noffset);
  398. noffset >= 0;
  399. noffset = fdt_next_subnode(fit, noffset)) {
  400. const char *name = fit_get_name(fit, noffset, NULL);
  401. if (strncmp(name, FIT_HASH_NODENAME,
  402. strlen(FIT_HASH_NODENAME)))
  403. continue;
  404. ret = fdt_get_path(fit, noffset, path, sizeof(path));
  405. if (ret < 0)
  406. goto err_path;
  407. if (strlist_add(node_inc, path))
  408. goto err_mem;
  409. hash_count++;
  410. }
  411. if (!hash_count) {
  412. printf("Failed to find any hash nodes in configuration '%s/%s' image '%s' - without these it is not possible to verify this image\n",
  413. conf_name, sig_name, iname);
  414. return -ENOMSG;
  415. }
  416. image_count++;
  417. }
  418. if (!image_count) {
  419. printf("Failed to find any images for configuration '%s/%s'\n",
  420. conf_name, sig_name);
  421. return -ENOMSG;
  422. }
  423. return 0;
  424. err_mem:
  425. printf("Out of memory processing configuration '%s/%s'\n", conf_name,
  426. sig_name);
  427. return -ENOMEM;
  428. err_path:
  429. printf("Failed to get path for image '%s' in configuration '%s/%s': %s\n",
  430. iname, conf_name, sig_name, fdt_strerror(ret));
  431. return -ENOENT;
  432. }
  433. static int fit_config_get_data(void *fit, int conf_noffset, int noffset,
  434. struct image_region **regionp, int *region_countp,
  435. char **region_propp, int *region_proplen)
  436. {
  437. char * const exc_prop[] = {"data"};
  438. struct strlist node_inc;
  439. struct image_region *region;
  440. struct fdt_region fdt_regions[100];
  441. const char *conf_name, *sig_name;
  442. char path[200];
  443. int count, i;
  444. char *region_prop;
  445. int ret, len;
  446. conf_name = fit_get_name(fit, conf_noffset, NULL);
  447. sig_name = fit_get_name(fit, conf_noffset, NULL);
  448. debug("%s: conf='%s', sig='%s'\n", __func__, conf_name, sig_name);
  449. /* Get a list of nodes we want to hash */
  450. ret = fit_config_get_hash_list(fit, conf_noffset, noffset, &node_inc);
  451. if (ret)
  452. return ret;
  453. /* Get a list of regions to hash */
  454. count = fdt_find_regions(fit, node_inc.strings, node_inc.count,
  455. exc_prop, ARRAY_SIZE(exc_prop),
  456. fdt_regions, ARRAY_SIZE(fdt_regions),
  457. path, sizeof(path), 1);
  458. if (count < 0) {
  459. printf("Failed to hash configuration '%s/%s': %s\n", conf_name,
  460. sig_name, fdt_strerror(ret));
  461. return -EIO;
  462. }
  463. if (count == 0) {
  464. printf("No data to hash for configuration '%s/%s': %s\n",
  465. conf_name, sig_name, fdt_strerror(ret));
  466. return -EINVAL;
  467. }
  468. /* Build our list of data blocks */
  469. region = fit_region_make_list(fit, fdt_regions, count, NULL);
  470. if (!region) {
  471. printf("Out of memory hashing configuration '%s/%s'\n",
  472. conf_name, sig_name);
  473. return -ENOMEM;
  474. }
  475. /* Create a list of all hashed properties */
  476. debug("Hash nodes:\n");
  477. for (i = len = 0; i < node_inc.count; i++) {
  478. debug(" %s\n", node_inc.strings[i]);
  479. len += strlen(node_inc.strings[i]) + 1;
  480. }
  481. region_prop = malloc(len);
  482. if (!region_prop) {
  483. printf("Out of memory setting up regions for configuration '%s/%s'\n",
  484. conf_name, sig_name);
  485. return -ENOMEM;
  486. }
  487. for (i = len = 0; i < node_inc.count;
  488. len += strlen(node_inc.strings[i]) + 1, i++)
  489. strcpy(region_prop + len, node_inc.strings[i]);
  490. strlist_free(&node_inc);
  491. *region_countp = count;
  492. *regionp = region;
  493. *region_propp = region_prop;
  494. *region_proplen = len;
  495. return 0;
  496. }
  497. static int fit_config_process_sig(const char *keydir, void *keydest,
  498. void *fit, const char *conf_name, int conf_noffset,
  499. int noffset, const char *comment, int require_keys)
  500. {
  501. struct image_sign_info info;
  502. const char *node_name;
  503. struct image_region *region;
  504. char *region_prop;
  505. int region_proplen;
  506. int region_count;
  507. uint8_t *value;
  508. uint value_len;
  509. int ret;
  510. node_name = fit_get_name(fit, noffset, NULL);
  511. if (fit_config_get_data(fit, conf_noffset, noffset, &region,
  512. &region_count, &region_prop, &region_proplen))
  513. return -1;
  514. if (fit_image_setup_sig(&info, keydir, fit, conf_name, noffset,
  515. require_keys ? "conf" : NULL))
  516. return -1;
  517. ret = info.algo->sign(&info, region, region_count, &value, &value_len);
  518. free(region);
  519. if (ret) {
  520. printf("Failed to sign '%s' signature node in '%s' conf node\n",
  521. node_name, conf_name);
  522. /* We allow keys to be missing */
  523. if (ret == -ENOENT)
  524. return 0;
  525. return -1;
  526. }
  527. ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
  528. region_prop, region_proplen);
  529. if (ret) {
  530. if (ret == -FDT_ERR_NOSPACE)
  531. return -ENOSPC;
  532. printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
  533. node_name, conf_name, fdt_strerror(ret));
  534. return -1;
  535. }
  536. free(value);
  537. free(region_prop);
  538. /* Get keyname again, as FDT has changed and invalidated our pointer */
  539. info.keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
  540. /* Write the public key into the supplied FDT file */
  541. if (keydest) {
  542. ret = info.algo->add_verify_data(&info, keydest);
  543. if (ret == -ENOSPC)
  544. return -ENOSPC;
  545. if (ret) {
  546. printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
  547. node_name, conf_name);
  548. }
  549. return ret;
  550. }
  551. return 0;
  552. }
  553. static int fit_config_add_verification_data(const char *keydir, void *keydest,
  554. void *fit, int conf_noffset, const char *comment,
  555. int require_keys)
  556. {
  557. const char *conf_name;
  558. int noffset;
  559. conf_name = fit_get_name(fit, conf_noffset, NULL);
  560. /* Process all hash subnodes of the configuration node */
  561. for (noffset = fdt_first_subnode(fit, conf_noffset);
  562. noffset >= 0;
  563. noffset = fdt_next_subnode(fit, noffset)) {
  564. const char *node_name;
  565. int ret = 0;
  566. node_name = fit_get_name(fit, noffset, NULL);
  567. if (!strncmp(node_name, FIT_SIG_NODENAME,
  568. strlen(FIT_SIG_NODENAME))) {
  569. ret = fit_config_process_sig(keydir, keydest,
  570. fit, conf_name, conf_noffset, noffset, comment,
  571. require_keys);
  572. }
  573. if (ret)
  574. return ret;
  575. }
  576. return 0;
  577. }
  578. int fit_add_verification_data(const char *keydir, void *keydest, void *fit,
  579. const char *comment, int require_keys)
  580. {
  581. int images_noffset, confs_noffset;
  582. int noffset;
  583. int ret;
  584. /* Find images parent node offset */
  585. images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
  586. if (images_noffset < 0) {
  587. printf("Can't find images parent node '%s' (%s)\n",
  588. FIT_IMAGES_PATH, fdt_strerror(images_noffset));
  589. return images_noffset;
  590. }
  591. /* Process its subnodes, print out component images details */
  592. for (noffset = fdt_first_subnode(fit, images_noffset);
  593. noffset >= 0;
  594. noffset = fdt_next_subnode(fit, noffset)) {
  595. /*
  596. * Direct child node of the images parent node,
  597. * i.e. component image node.
  598. */
  599. ret = fit_image_add_verification_data(keydir, keydest,
  600. fit, noffset, comment, require_keys);
  601. if (ret)
  602. return ret;
  603. }
  604. /* If there are no keys, we can't sign configurations */
  605. if (!IMAGE_ENABLE_SIGN || !keydir)
  606. return 0;
  607. /* Find configurations parent node offset */
  608. confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
  609. if (confs_noffset < 0) {
  610. printf("Can't find images parent node '%s' (%s)\n",
  611. FIT_CONFS_PATH, fdt_strerror(confs_noffset));
  612. return -ENOENT;
  613. }
  614. /* Process its subnodes, print out component images details */
  615. for (noffset = fdt_first_subnode(fit, confs_noffset);
  616. noffset >= 0;
  617. noffset = fdt_next_subnode(fit, noffset)) {
  618. ret = fit_config_add_verification_data(keydir, keydest,
  619. fit, noffset, comment,
  620. require_keys);
  621. if (ret)
  622. return ret;
  623. }
  624. return 0;
  625. }
  626. #ifdef CONFIG_FIT_SIGNATURE
  627. int fit_check_sign(const void *fit, const void *key)
  628. {
  629. int cfg_noffset;
  630. int ret;
  631. cfg_noffset = fit_conf_get_node(fit, NULL);
  632. if (!cfg_noffset)
  633. return -1;
  634. printf("Verifying Hash Integrity ... ");
  635. ret = fit_config_verify(fit, cfg_noffset);
  636. if (ret)
  637. return ret;
  638. ret = bootm_host_load_images(fit, cfg_noffset);
  639. return ret;
  640. }
  641. #endif