image-host.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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->name = algo_name;
  152. info->checksum = image_get_checksum_algo(algo_name);
  153. info->crypto = image_get_crypto_algo(algo_name);
  154. info->require_keys = require_keys;
  155. if (!info->checksum || !info->crypto) {
  156. printf("Unsupported signature algorithm (%s) for '%s' signature node in '%s' image node\n",
  157. algo_name, node_name, image_name);
  158. return -1;
  159. }
  160. return 0;
  161. }
  162. /**
  163. * fit_image_process_sig- Process a single subnode of the images/ node
  164. *
  165. * Check each subnode and process accordingly. For signature nodes we
  166. * generate a signed hash of the supplised data and store it in the node.
  167. *
  168. * @keydir: Directory containing keys to use for signing
  169. * @keydest: Destination FDT blob to write public keys into
  170. * @fit: pointer to the FIT format image header
  171. * @image_name: name of image being processes (used to display errors)
  172. * @noffset: subnode offset
  173. * @data: data to process
  174. * @size: size of data in bytes
  175. * @comment: Comment to add to signature nodes
  176. * @require_keys: Mark all keys as 'required'
  177. * @return 0 if ok, -1 on error
  178. */
  179. static int fit_image_process_sig(const char *keydir, void *keydest,
  180. void *fit, const char *image_name,
  181. int noffset, const void *data, size_t size,
  182. const char *comment, int require_keys)
  183. {
  184. struct image_sign_info info;
  185. struct image_region region;
  186. const char *node_name;
  187. uint8_t *value;
  188. uint value_len;
  189. int ret;
  190. if (fit_image_setup_sig(&info, keydir, fit, image_name, noffset,
  191. require_keys ? "image" : NULL))
  192. return -1;
  193. node_name = fit_get_name(fit, noffset, NULL);
  194. region.data = data;
  195. region.size = size;
  196. ret = info.crypto->sign(&info, &region, 1, &value, &value_len);
  197. if (ret) {
  198. printf("Failed to sign '%s' signature node in '%s' image node: %d\n",
  199. node_name, image_name, ret);
  200. /* We allow keys to be missing */
  201. if (ret == -ENOENT)
  202. return 0;
  203. return -1;
  204. }
  205. ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
  206. NULL, 0);
  207. if (ret) {
  208. if (ret == -FDT_ERR_NOSPACE)
  209. return -ENOSPC;
  210. printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
  211. node_name, image_name, fdt_strerror(ret));
  212. return -1;
  213. }
  214. free(value);
  215. /* Get keyname again, as FDT has changed and invalidated our pointer */
  216. info.keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
  217. if (keydest)
  218. ret = info.crypto->add_verify_data(&info, keydest);
  219. else
  220. return -1;
  221. /*
  222. * Write the public key into the supplied FDT file; this might fail
  223. * several times, since we try signing with successively increasing
  224. * size values
  225. */
  226. if (keydest && ret)
  227. return ret;
  228. return 0;
  229. }
  230. /**
  231. * fit_image_add_verification_data() - calculate/set verig. data for image node
  232. *
  233. * This adds hash and signature values for an component image node.
  234. *
  235. * All existing hash subnodes are checked, if algorithm property is set to
  236. * one of the supported hash algorithms, hash value is computed and
  237. * corresponding hash node property is set, for example:
  238. *
  239. * Input component image node structure:
  240. *
  241. * o image@1 (at image_noffset)
  242. * | - data = [binary data]
  243. * o hash@1
  244. * |- algo = "sha1"
  245. *
  246. * Output component image node structure:
  247. *
  248. * o image@1 (at image_noffset)
  249. * | - data = [binary data]
  250. * o hash@1
  251. * |- algo = "sha1"
  252. * |- value = sha1(data)
  253. *
  254. * For signature details, please see doc/uImage.FIT/signature.txt
  255. *
  256. * @keydir Directory containing *.key and *.crt files (or NULL)
  257. * @keydest FDT Blob to write public keys into (NULL if none)
  258. * @fit: Pointer to the FIT format image header
  259. * @image_noffset: Requested component image node
  260. * @comment: Comment to add to signature nodes
  261. * @require_keys: Mark all keys as 'required'
  262. * @return: 0 on success, <0 on failure
  263. */
  264. int fit_image_add_verification_data(const char *keydir, void *keydest,
  265. void *fit, int image_noffset, const char *comment,
  266. int require_keys)
  267. {
  268. const char *image_name;
  269. const void *data;
  270. size_t size;
  271. int noffset;
  272. /* Get image data and data length */
  273. if (fit_image_get_data(fit, image_noffset, &data, &size)) {
  274. printf("Can't get image data/size\n");
  275. return -1;
  276. }
  277. image_name = fit_get_name(fit, image_noffset, NULL);
  278. /* Process all hash subnodes of the component image node */
  279. for (noffset = fdt_first_subnode(fit, image_noffset);
  280. noffset >= 0;
  281. noffset = fdt_next_subnode(fit, noffset)) {
  282. const char *node_name;
  283. int ret = 0;
  284. /*
  285. * Check subnode name, must be equal to "hash" or "signature".
  286. * Multiple hash nodes require unique unit node
  287. * names, e.g. hash@1, hash@2, signature@1, etc.
  288. */
  289. node_name = fit_get_name(fit, noffset, NULL);
  290. if (!strncmp(node_name, FIT_HASH_NODENAME,
  291. strlen(FIT_HASH_NODENAME))) {
  292. ret = fit_image_process_hash(fit, image_name, noffset,
  293. data, size);
  294. } else if (IMAGE_ENABLE_SIGN && keydir &&
  295. !strncmp(node_name, FIT_SIG_NODENAME,
  296. strlen(FIT_SIG_NODENAME))) {
  297. ret = fit_image_process_sig(keydir, keydest,
  298. fit, image_name, noffset, data, size,
  299. comment, require_keys);
  300. }
  301. if (ret)
  302. return ret;
  303. }
  304. return 0;
  305. }
  306. struct strlist {
  307. int count;
  308. char **strings;
  309. };
  310. static void strlist_init(struct strlist *list)
  311. {
  312. memset(list, '\0', sizeof(*list));
  313. }
  314. static void strlist_free(struct strlist *list)
  315. {
  316. int i;
  317. for (i = 0; i < list->count; i++)
  318. free(list->strings[i]);
  319. free(list->strings);
  320. }
  321. static int strlist_add(struct strlist *list, const char *str)
  322. {
  323. char *dup;
  324. dup = strdup(str);
  325. list->strings = realloc(list->strings,
  326. (list->count + 1) * sizeof(char *));
  327. if (!list || !str)
  328. return -1;
  329. list->strings[list->count++] = dup;
  330. return 0;
  331. }
  332. static const char *fit_config_get_image_list(void *fit, int noffset,
  333. int *lenp, int *allow_missingp)
  334. {
  335. static const char default_list[] = FIT_KERNEL_PROP "\0"
  336. FIT_FDT_PROP;
  337. const char *prop;
  338. /* If there is an "image" property, use that */
  339. prop = fdt_getprop(fit, noffset, "sign-images", lenp);
  340. if (prop) {
  341. *allow_missingp = 0;
  342. return *lenp ? prop : NULL;
  343. }
  344. /* Default image list */
  345. *allow_missingp = 1;
  346. *lenp = sizeof(default_list);
  347. return default_list;
  348. }
  349. static int fit_config_get_hash_list(void *fit, int conf_noffset,
  350. int sig_offset, struct strlist *node_inc)
  351. {
  352. int allow_missing;
  353. const char *prop, *iname, *end;
  354. const char *conf_name, *sig_name;
  355. char name[200], path[200];
  356. int image_count;
  357. int ret, len;
  358. conf_name = fit_get_name(fit, conf_noffset, NULL);
  359. sig_name = fit_get_name(fit, sig_offset, NULL);
  360. /*
  361. * Build a list of nodes we need to hash. We always need the root
  362. * node and the configuration.
  363. */
  364. strlist_init(node_inc);
  365. snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH, conf_name);
  366. if (strlist_add(node_inc, "/") ||
  367. strlist_add(node_inc, name))
  368. goto err_mem;
  369. /* Get a list of images that we intend to sign */
  370. prop = fit_config_get_image_list(fit, sig_offset, &len,
  371. &allow_missing);
  372. if (!prop)
  373. return 0;
  374. /* Locate the images */
  375. end = prop + len;
  376. image_count = 0;
  377. for (iname = prop; iname < end; iname += strlen(iname) + 1) {
  378. int noffset;
  379. int image_noffset;
  380. int hash_count;
  381. image_noffset = fit_conf_get_prop_node(fit, conf_noffset,
  382. iname);
  383. if (image_noffset < 0) {
  384. printf("Failed to find image '%s' in configuration '%s/%s'\n",
  385. iname, conf_name, sig_name);
  386. if (allow_missing)
  387. continue;
  388. return -ENOENT;
  389. }
  390. ret = fdt_get_path(fit, image_noffset, path, sizeof(path));
  391. if (ret < 0)
  392. goto err_path;
  393. if (strlist_add(node_inc, path))
  394. goto err_mem;
  395. snprintf(name, sizeof(name), "%s/%s", FIT_CONFS_PATH,
  396. conf_name);
  397. /* Add all this image's hashes */
  398. hash_count = 0;
  399. for (noffset = fdt_first_subnode(fit, image_noffset);
  400. noffset >= 0;
  401. noffset = fdt_next_subnode(fit, noffset)) {
  402. const char *name = fit_get_name(fit, noffset, NULL);
  403. if (strncmp(name, FIT_HASH_NODENAME,
  404. strlen(FIT_HASH_NODENAME)))
  405. continue;
  406. ret = fdt_get_path(fit, noffset, path, sizeof(path));
  407. if (ret < 0)
  408. goto err_path;
  409. if (strlist_add(node_inc, path))
  410. goto err_mem;
  411. hash_count++;
  412. }
  413. if (!hash_count) {
  414. printf("Failed to find any hash nodes in configuration '%s/%s' image '%s' - without these it is not possible to verify this image\n",
  415. conf_name, sig_name, iname);
  416. return -ENOMSG;
  417. }
  418. image_count++;
  419. }
  420. if (!image_count) {
  421. printf("Failed to find any images for configuration '%s/%s'\n",
  422. conf_name, sig_name);
  423. return -ENOMSG;
  424. }
  425. return 0;
  426. err_mem:
  427. printf("Out of memory processing configuration '%s/%s'\n", conf_name,
  428. sig_name);
  429. return -ENOMEM;
  430. err_path:
  431. printf("Failed to get path for image '%s' in configuration '%s/%s': %s\n",
  432. iname, conf_name, sig_name, fdt_strerror(ret));
  433. return -ENOENT;
  434. }
  435. static int fit_config_get_data(void *fit, int conf_noffset, int noffset,
  436. struct image_region **regionp, int *region_countp,
  437. char **region_propp, int *region_proplen)
  438. {
  439. char * const exc_prop[] = {"data"};
  440. struct strlist node_inc;
  441. struct image_region *region;
  442. struct fdt_region fdt_regions[100];
  443. const char *conf_name, *sig_name;
  444. char path[200];
  445. int count, i;
  446. char *region_prop;
  447. int ret, len;
  448. conf_name = fit_get_name(fit, conf_noffset, NULL);
  449. sig_name = fit_get_name(fit, conf_noffset, NULL);
  450. debug("%s: conf='%s', sig='%s'\n", __func__, conf_name, sig_name);
  451. /* Get a list of nodes we want to hash */
  452. ret = fit_config_get_hash_list(fit, conf_noffset, noffset, &node_inc);
  453. if (ret)
  454. return ret;
  455. /* Get a list of regions to hash */
  456. count = fdt_find_regions(fit, node_inc.strings, node_inc.count,
  457. exc_prop, ARRAY_SIZE(exc_prop),
  458. fdt_regions, ARRAY_SIZE(fdt_regions),
  459. path, sizeof(path), 1);
  460. if (count < 0) {
  461. printf("Failed to hash configuration '%s/%s': %s\n", conf_name,
  462. sig_name, fdt_strerror(ret));
  463. return -EIO;
  464. }
  465. if (count == 0) {
  466. printf("No data to hash for configuration '%s/%s': %s\n",
  467. conf_name, sig_name, fdt_strerror(ret));
  468. return -EINVAL;
  469. }
  470. /* Build our list of data blocks */
  471. region = fit_region_make_list(fit, fdt_regions, count, NULL);
  472. if (!region) {
  473. printf("Out of memory hashing configuration '%s/%s'\n",
  474. conf_name, sig_name);
  475. return -ENOMEM;
  476. }
  477. /* Create a list of all hashed properties */
  478. debug("Hash nodes:\n");
  479. for (i = len = 0; i < node_inc.count; i++) {
  480. debug(" %s\n", node_inc.strings[i]);
  481. len += strlen(node_inc.strings[i]) + 1;
  482. }
  483. region_prop = malloc(len);
  484. if (!region_prop) {
  485. printf("Out of memory setting up regions for configuration '%s/%s'\n",
  486. conf_name, sig_name);
  487. return -ENOMEM;
  488. }
  489. for (i = len = 0; i < node_inc.count;
  490. len += strlen(node_inc.strings[i]) + 1, i++)
  491. strcpy(region_prop + len, node_inc.strings[i]);
  492. strlist_free(&node_inc);
  493. *region_countp = count;
  494. *regionp = region;
  495. *region_propp = region_prop;
  496. *region_proplen = len;
  497. return 0;
  498. }
  499. static int fit_config_process_sig(const char *keydir, void *keydest,
  500. void *fit, const char *conf_name, int conf_noffset,
  501. int noffset, const char *comment, int require_keys)
  502. {
  503. struct image_sign_info info;
  504. const char *node_name;
  505. struct image_region *region;
  506. char *region_prop;
  507. int region_proplen;
  508. int region_count;
  509. uint8_t *value;
  510. uint value_len;
  511. int ret;
  512. node_name = fit_get_name(fit, noffset, NULL);
  513. if (fit_config_get_data(fit, conf_noffset, noffset, &region,
  514. &region_count, &region_prop, &region_proplen))
  515. return -1;
  516. if (fit_image_setup_sig(&info, keydir, fit, conf_name, noffset,
  517. require_keys ? "conf" : NULL))
  518. return -1;
  519. ret = info.crypto->sign(&info, region, region_count, &value,
  520. &value_len);
  521. free(region);
  522. if (ret) {
  523. printf("Failed to sign '%s' signature node in '%s' conf node\n",
  524. node_name, conf_name);
  525. /* We allow keys to be missing */
  526. if (ret == -ENOENT)
  527. return 0;
  528. return -1;
  529. }
  530. ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
  531. region_prop, region_proplen);
  532. if (ret) {
  533. if (ret == -FDT_ERR_NOSPACE)
  534. return -ENOSPC;
  535. printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
  536. node_name, conf_name, fdt_strerror(ret));
  537. return -1;
  538. }
  539. free(value);
  540. free(region_prop);
  541. /* Get keyname again, as FDT has changed and invalidated our pointer */
  542. info.keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
  543. /* Write the public key into the supplied FDT file */
  544. if (keydest) {
  545. ret = info.crypto->add_verify_data(&info, keydest);
  546. if (ret == -ENOSPC)
  547. return -ENOSPC;
  548. if (ret) {
  549. printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
  550. node_name, conf_name);
  551. }
  552. return ret;
  553. }
  554. return 0;
  555. }
  556. static int fit_config_add_verification_data(const char *keydir, void *keydest,
  557. void *fit, int conf_noffset, const char *comment,
  558. int require_keys)
  559. {
  560. const char *conf_name;
  561. int noffset;
  562. conf_name = fit_get_name(fit, conf_noffset, NULL);
  563. /* Process all hash subnodes of the configuration node */
  564. for (noffset = fdt_first_subnode(fit, conf_noffset);
  565. noffset >= 0;
  566. noffset = fdt_next_subnode(fit, noffset)) {
  567. const char *node_name;
  568. int ret = 0;
  569. node_name = fit_get_name(fit, noffset, NULL);
  570. if (!strncmp(node_name, FIT_SIG_NODENAME,
  571. strlen(FIT_SIG_NODENAME))) {
  572. ret = fit_config_process_sig(keydir, keydest,
  573. fit, conf_name, conf_noffset, noffset, comment,
  574. require_keys);
  575. }
  576. if (ret)
  577. return ret;
  578. }
  579. return 0;
  580. }
  581. int fit_add_verification_data(const char *keydir, void *keydest, void *fit,
  582. const char *comment, int require_keys)
  583. {
  584. int images_noffset, confs_noffset;
  585. int noffset;
  586. int ret;
  587. /* Find images parent node offset */
  588. images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
  589. if (images_noffset < 0) {
  590. printf("Can't find images parent node '%s' (%s)\n",
  591. FIT_IMAGES_PATH, fdt_strerror(images_noffset));
  592. return images_noffset;
  593. }
  594. /* Process its subnodes, print out component images details */
  595. for (noffset = fdt_first_subnode(fit, images_noffset);
  596. noffset >= 0;
  597. noffset = fdt_next_subnode(fit, noffset)) {
  598. /*
  599. * Direct child node of the images parent node,
  600. * i.e. component image node.
  601. */
  602. ret = fit_image_add_verification_data(keydir, keydest,
  603. fit, noffset, comment, require_keys);
  604. if (ret)
  605. return ret;
  606. }
  607. /* If there are no keys, we can't sign configurations */
  608. if (!IMAGE_ENABLE_SIGN || !keydir)
  609. return 0;
  610. /* Find configurations parent node offset */
  611. confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
  612. if (confs_noffset < 0) {
  613. printf("Can't find images parent node '%s' (%s)\n",
  614. FIT_CONFS_PATH, fdt_strerror(confs_noffset));
  615. return -ENOENT;
  616. }
  617. /* Process its subnodes, print out component images details */
  618. for (noffset = fdt_first_subnode(fit, confs_noffset);
  619. noffset >= 0;
  620. noffset = fdt_next_subnode(fit, noffset)) {
  621. ret = fit_config_add_verification_data(keydir, keydest,
  622. fit, noffset, comment,
  623. require_keys);
  624. if (ret)
  625. return ret;
  626. }
  627. return 0;
  628. }
  629. #ifdef CONFIG_FIT_SIGNATURE
  630. int fit_check_sign(const void *fit, const void *key)
  631. {
  632. int cfg_noffset;
  633. int ret;
  634. cfg_noffset = fit_conf_get_node(fit, NULL);
  635. if (!cfg_noffset)
  636. return -1;
  637. printf("Verifying Hash Integrity ... ");
  638. ret = fit_config_verify(fit, cfg_noffset);
  639. if (ret)
  640. return ret;
  641. ret = bootm_host_load_images(fit, cfg_noffset);
  642. return ret;
  643. }
  644. #endif