image-host.c 20 KB

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