image-fit.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471
  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. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #ifdef USE_HOSTCC
  28. #include "mkimage.h"
  29. #include <image.h>
  30. #include <time.h>
  31. #else
  32. #include <common.h>
  33. #endif /* !USE_HOSTCC*/
  34. #include <bootstage.h>
  35. #include <sha1.h>
  36. #include <u-boot/crc.h>
  37. #include <u-boot/md5.h>
  38. /*****************************************************************************/
  39. /* New uImage format routines */
  40. /*****************************************************************************/
  41. #ifndef USE_HOSTCC
  42. static int fit_parse_spec(const char *spec, char sepc, ulong addr_curr,
  43. ulong *addr, const char **name)
  44. {
  45. const char *sep;
  46. *addr = addr_curr;
  47. *name = NULL;
  48. sep = strchr(spec, sepc);
  49. if (sep) {
  50. if (sep - spec > 0)
  51. *addr = simple_strtoul(spec, NULL, 16);
  52. *name = sep + 1;
  53. return 1;
  54. }
  55. return 0;
  56. }
  57. /**
  58. * fit_parse_conf - parse FIT configuration spec
  59. * @spec: input string, containing configuration spec
  60. * @add_curr: current image address (to be used as a possible default)
  61. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  62. * configuration
  63. * @conf_name double pointer to a char, will hold pointer to a configuration
  64. * unit name
  65. *
  66. * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
  67. * where <addr> is a FIT image address that contains configuration
  68. * with a <conf> unit name.
  69. *
  70. * Address part is optional, and if omitted default add_curr will
  71. * be used instead.
  72. *
  73. * returns:
  74. * 1 if spec is a valid configuration string,
  75. * addr and conf_name are set accordingly
  76. * 0 otherwise
  77. */
  78. int fit_parse_conf(const char *spec, ulong addr_curr,
  79. ulong *addr, const char **conf_name)
  80. {
  81. return fit_parse_spec(spec, '#', addr_curr, addr, conf_name);
  82. }
  83. /**
  84. * fit_parse_subimage - parse FIT subimage spec
  85. * @spec: input string, containing subimage spec
  86. * @add_curr: current image address (to be used as a possible default)
  87. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  88. * subimage
  89. * @image_name: double pointer to a char, will hold pointer to a subimage name
  90. *
  91. * fit_parse_subimage() expects subimage spec in the for of
  92. * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
  93. * subimage with a <subimg> unit name.
  94. *
  95. * Address part is optional, and if omitted default add_curr will
  96. * be used instead.
  97. *
  98. * returns:
  99. * 1 if spec is a valid subimage string,
  100. * addr and image_name are set accordingly
  101. * 0 otherwise
  102. */
  103. int fit_parse_subimage(const char *spec, ulong addr_curr,
  104. ulong *addr, const char **image_name)
  105. {
  106. return fit_parse_spec(spec, ':', addr_curr, addr, image_name);
  107. }
  108. #endif /* !USE_HOSTCC */
  109. static void fit_get_debug(const void *fit, int noffset,
  110. char *prop_name, int err)
  111. {
  112. debug("Can't get '%s' property from FIT 0x%08lx, node: offset %d, name %s (%s)\n",
  113. prop_name, (ulong)fit, noffset, fit_get_name(fit, noffset, NULL),
  114. fdt_strerror(err));
  115. }
  116. /**
  117. * fit_print_contents - prints out the contents of the FIT format image
  118. * @fit: pointer to the FIT format image header
  119. * @p: pointer to prefix string
  120. *
  121. * fit_print_contents() formats a multi line FIT image contents description.
  122. * The routine prints out FIT image properties (root node level) follwed by
  123. * the details of each component image.
  124. *
  125. * returns:
  126. * no returned results
  127. */
  128. void fit_print_contents(const void *fit)
  129. {
  130. char *desc;
  131. char *uname;
  132. int images_noffset;
  133. int confs_noffset;
  134. int noffset;
  135. int ndepth;
  136. int count = 0;
  137. int ret;
  138. const char *p;
  139. time_t timestamp;
  140. #ifdef USE_HOSTCC
  141. p = "";
  142. #else
  143. p = " ";
  144. #endif
  145. /* Root node properties */
  146. ret = fit_get_desc(fit, 0, &desc);
  147. printf("%sFIT description: ", p);
  148. if (ret)
  149. printf("unavailable\n");
  150. else
  151. printf("%s\n", desc);
  152. if (IMAGE_ENABLE_TIMESTAMP) {
  153. ret = fit_get_timestamp(fit, 0, &timestamp);
  154. printf("%sCreated: ", p);
  155. if (ret)
  156. printf("unavailable\n");
  157. else
  158. genimg_print_time(timestamp);
  159. }
  160. /* Find images parent node offset */
  161. images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
  162. if (images_noffset < 0) {
  163. printf("Can't find images parent node '%s' (%s)\n",
  164. FIT_IMAGES_PATH, fdt_strerror(images_noffset));
  165. return;
  166. }
  167. /* Process its subnodes, print out component images details */
  168. for (ndepth = 0, count = 0,
  169. noffset = fdt_next_node(fit, images_noffset, &ndepth);
  170. (noffset >= 0) && (ndepth > 0);
  171. noffset = fdt_next_node(fit, noffset, &ndepth)) {
  172. if (ndepth == 1) {
  173. /*
  174. * Direct child node of the images parent node,
  175. * i.e. component image node.
  176. */
  177. printf("%s Image %u (%s)\n", p, count++,
  178. fit_get_name(fit, noffset, NULL));
  179. fit_image_print(fit, noffset, p);
  180. }
  181. }
  182. /* Find configurations parent node offset */
  183. confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
  184. if (confs_noffset < 0) {
  185. debug("Can't get configurations parent node '%s' (%s)\n",
  186. FIT_CONFS_PATH, fdt_strerror(confs_noffset));
  187. return;
  188. }
  189. /* get default configuration unit name from default property */
  190. uname = (char *)fdt_getprop(fit, noffset, FIT_DEFAULT_PROP, NULL);
  191. if (uname)
  192. printf("%s Default Configuration: '%s'\n", p, uname);
  193. /* Process its subnodes, print out configurations details */
  194. for (ndepth = 0, count = 0,
  195. noffset = fdt_next_node(fit, confs_noffset, &ndepth);
  196. (noffset >= 0) && (ndepth > 0);
  197. noffset = fdt_next_node(fit, noffset, &ndepth)) {
  198. if (ndepth == 1) {
  199. /*
  200. * Direct child node of the configurations parent node,
  201. * i.e. configuration node.
  202. */
  203. printf("%s Configuration %u (%s)\n", p, count++,
  204. fit_get_name(fit, noffset, NULL));
  205. fit_conf_print(fit, noffset, p);
  206. }
  207. }
  208. }
  209. /**
  210. * fit_image_print - prints out the FIT component image details
  211. * @fit: pointer to the FIT format image header
  212. * @image_noffset: offset of the component image node
  213. * @p: pointer to prefix string
  214. *
  215. * fit_image_print() lists all mandatory properies for the processed component
  216. * image. If present, hash nodes are printed out as well. Load
  217. * address for images of type firmware is also printed out. Since the load
  218. * address is not mandatory for firmware images, it will be output as
  219. * "unavailable" when not present.
  220. *
  221. * returns:
  222. * no returned results
  223. */
  224. void fit_image_print(const void *fit, int image_noffset, const char *p)
  225. {
  226. char *desc;
  227. uint8_t type, arch, os, comp;
  228. size_t size;
  229. ulong load, entry;
  230. const void *data;
  231. int noffset;
  232. int ndepth;
  233. int ret;
  234. /* Mandatory properties */
  235. ret = fit_get_desc(fit, image_noffset, &desc);
  236. printf("%s Description: ", p);
  237. if (ret)
  238. printf("unavailable\n");
  239. else
  240. printf("%s\n", desc);
  241. fit_image_get_type(fit, image_noffset, &type);
  242. printf("%s Type: %s\n", p, genimg_get_type_name(type));
  243. fit_image_get_comp(fit, image_noffset, &comp);
  244. printf("%s Compression: %s\n", p, genimg_get_comp_name(comp));
  245. ret = fit_image_get_data(fit, image_noffset, &data, &size);
  246. #ifndef USE_HOSTCC
  247. printf("%s Data Start: ", p);
  248. if (ret)
  249. printf("unavailable\n");
  250. else
  251. printf("0x%08lx\n", (ulong)data);
  252. #endif
  253. printf("%s Data Size: ", p);
  254. if (ret)
  255. printf("unavailable\n");
  256. else
  257. genimg_print_size(size);
  258. /* Remaining, type dependent properties */
  259. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
  260. (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
  261. (type == IH_TYPE_FLATDT)) {
  262. fit_image_get_arch(fit, image_noffset, &arch);
  263. printf("%s Architecture: %s\n", p, genimg_get_arch_name(arch));
  264. }
  265. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_RAMDISK)) {
  266. fit_image_get_os(fit, image_noffset, &os);
  267. printf("%s OS: %s\n", p, genimg_get_os_name(os));
  268. }
  269. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
  270. (type == IH_TYPE_FIRMWARE) || (type == IH_TYPE_RAMDISK)) {
  271. ret = fit_image_get_load(fit, image_noffset, &load);
  272. printf("%s Load Address: ", p);
  273. if (ret)
  274. printf("unavailable\n");
  275. else
  276. printf("0x%08lx\n", load);
  277. }
  278. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
  279. (type == IH_TYPE_RAMDISK)) {
  280. fit_image_get_entry(fit, image_noffset, &entry);
  281. printf("%s Entry Point: ", p);
  282. if (ret)
  283. printf("unavailable\n");
  284. else
  285. printf("0x%08lx\n", entry);
  286. }
  287. /* Process all hash subnodes of the component image node */
  288. for (ndepth = 0, noffset = fdt_next_node(fit, image_noffset, &ndepth);
  289. (noffset >= 0) && (ndepth > 0);
  290. noffset = fdt_next_node(fit, noffset, &ndepth)) {
  291. if (ndepth == 1) {
  292. /* Direct child node of the component image node */
  293. fit_image_print_hash(fit, noffset, p);
  294. }
  295. }
  296. }
  297. /**
  298. * fit_image_print_hash - prints out the hash node details
  299. * @fit: pointer to the FIT format image header
  300. * @noffset: offset of the hash node
  301. * @p: pointer to prefix string
  302. *
  303. * fit_image_print_hash() lists properies for the processed hash node
  304. *
  305. * returns:
  306. * no returned results
  307. */
  308. void fit_image_print_hash(const void *fit, int noffset, const char *p)
  309. {
  310. char *algo;
  311. uint8_t *value;
  312. int value_len;
  313. int i, ret;
  314. /*
  315. * Check subnode name, must be equal to "hash".
  316. * Multiple hash nodes require unique unit node
  317. * names, e.g. hash@1, hash@2, etc.
  318. */
  319. if (strncmp(fit_get_name(fit, noffset, NULL),
  320. FIT_HASH_NODENAME, strlen(FIT_HASH_NODENAME)) != 0)
  321. return;
  322. debug("%s Hash node: '%s'\n", p,
  323. fit_get_name(fit, noffset, NULL));
  324. printf("%s Hash algo: ", p);
  325. if (fit_image_hash_get_algo(fit, noffset, &algo)) {
  326. printf("invalid/unsupported\n");
  327. return;
  328. }
  329. printf("%s\n", algo);
  330. ret = fit_image_hash_get_value(fit, noffset, &value,
  331. &value_len);
  332. printf("%s Hash value: ", p);
  333. if (ret) {
  334. printf("unavailable\n");
  335. } else {
  336. for (i = 0; i < value_len; i++)
  337. printf("%02x", value[i]);
  338. printf("\n");
  339. }
  340. debug("%s Hash len: %d\n", p, value_len);
  341. }
  342. /**
  343. * fit_get_desc - get node description property
  344. * @fit: pointer to the FIT format image header
  345. * @noffset: node offset
  346. * @desc: double pointer to the char, will hold pointer to the descrption
  347. *
  348. * fit_get_desc() reads description property from a given node, if
  349. * description is found pointer to it is returened in third call argument.
  350. *
  351. * returns:
  352. * 0, on success
  353. * -1, on failure
  354. */
  355. int fit_get_desc(const void *fit, int noffset, char **desc)
  356. {
  357. int len;
  358. *desc = (char *)fdt_getprop(fit, noffset, FIT_DESC_PROP, &len);
  359. if (*desc == NULL) {
  360. fit_get_debug(fit, noffset, FIT_DESC_PROP, len);
  361. return -1;
  362. }
  363. return 0;
  364. }
  365. /**
  366. * fit_get_timestamp - get node timestamp property
  367. * @fit: pointer to the FIT format image header
  368. * @noffset: node offset
  369. * @timestamp: pointer to the time_t, will hold read timestamp
  370. *
  371. * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
  372. * is found and has a correct size its value is retured in third call
  373. * argument.
  374. *
  375. * returns:
  376. * 0, on success
  377. * -1, on property read failure
  378. * -2, on wrong timestamp size
  379. */
  380. int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp)
  381. {
  382. int len;
  383. const void *data;
  384. data = fdt_getprop(fit, noffset, FIT_TIMESTAMP_PROP, &len);
  385. if (data == NULL) {
  386. fit_get_debug(fit, noffset, FIT_TIMESTAMP_PROP, len);
  387. return -1;
  388. }
  389. if (len != sizeof(uint32_t)) {
  390. debug("FIT timestamp with incorrect size of (%u)\n", len);
  391. return -2;
  392. }
  393. *timestamp = uimage_to_cpu(*((uint32_t *)data));
  394. return 0;
  395. }
  396. /**
  397. * fit_image_get_node - get node offset for component image of a given unit name
  398. * @fit: pointer to the FIT format image header
  399. * @image_uname: component image node unit name
  400. *
  401. * fit_image_get_node() finds a component image (withing the '/images'
  402. * node) of a provided unit name. If image is found its node offset is
  403. * returned to the caller.
  404. *
  405. * returns:
  406. * image node offset when found (>=0)
  407. * negative number on failure (FDT_ERR_* code)
  408. */
  409. int fit_image_get_node(const void *fit, const char *image_uname)
  410. {
  411. int noffset, images_noffset;
  412. images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
  413. if (images_noffset < 0) {
  414. debug("Can't find images parent node '%s' (%s)\n",
  415. FIT_IMAGES_PATH, fdt_strerror(images_noffset));
  416. return images_noffset;
  417. }
  418. noffset = fdt_subnode_offset(fit, images_noffset, image_uname);
  419. if (noffset < 0) {
  420. debug("Can't get node offset for image unit name: '%s' (%s)\n",
  421. image_uname, fdt_strerror(noffset));
  422. }
  423. return noffset;
  424. }
  425. /**
  426. * fit_image_get_os - get os id for a given component image node
  427. * @fit: pointer to the FIT format image header
  428. * @noffset: component image node offset
  429. * @os: pointer to the uint8_t, will hold os numeric id
  430. *
  431. * fit_image_get_os() finds os property in a given component image node.
  432. * If the property is found, its (string) value is translated to the numeric
  433. * id which is returned to the caller.
  434. *
  435. * returns:
  436. * 0, on success
  437. * -1, on failure
  438. */
  439. int fit_image_get_os(const void *fit, int noffset, uint8_t *os)
  440. {
  441. int len;
  442. const void *data;
  443. /* Get OS name from property data */
  444. data = fdt_getprop(fit, noffset, FIT_OS_PROP, &len);
  445. if (data == NULL) {
  446. fit_get_debug(fit, noffset, FIT_OS_PROP, len);
  447. *os = -1;
  448. return -1;
  449. }
  450. /* Translate OS name to id */
  451. *os = genimg_get_os_id(data);
  452. return 0;
  453. }
  454. /**
  455. * fit_image_get_arch - get arch id for a given component image node
  456. * @fit: pointer to the FIT format image header
  457. * @noffset: component image node offset
  458. * @arch: pointer to the uint8_t, will hold arch numeric id
  459. *
  460. * fit_image_get_arch() finds arch property in a given component image node.
  461. * If the property is found, its (string) value is translated to the numeric
  462. * id which is returned to the caller.
  463. *
  464. * returns:
  465. * 0, on success
  466. * -1, on failure
  467. */
  468. int fit_image_get_arch(const void *fit, int noffset, uint8_t *arch)
  469. {
  470. int len;
  471. const void *data;
  472. /* Get architecture name from property data */
  473. data = fdt_getprop(fit, noffset, FIT_ARCH_PROP, &len);
  474. if (data == NULL) {
  475. fit_get_debug(fit, noffset, FIT_ARCH_PROP, len);
  476. *arch = -1;
  477. return -1;
  478. }
  479. /* Translate architecture name to id */
  480. *arch = genimg_get_arch_id(data);
  481. return 0;
  482. }
  483. /**
  484. * fit_image_get_type - get type id for a given component image node
  485. * @fit: pointer to the FIT format image header
  486. * @noffset: component image node offset
  487. * @type: pointer to the uint8_t, will hold type numeric id
  488. *
  489. * fit_image_get_type() finds type property in a given component image node.
  490. * If the property is found, its (string) value is translated to the numeric
  491. * id which is returned to the caller.
  492. *
  493. * returns:
  494. * 0, on success
  495. * -1, on failure
  496. */
  497. int fit_image_get_type(const void *fit, int noffset, uint8_t *type)
  498. {
  499. int len;
  500. const void *data;
  501. /* Get image type name from property data */
  502. data = fdt_getprop(fit, noffset, FIT_TYPE_PROP, &len);
  503. if (data == NULL) {
  504. fit_get_debug(fit, noffset, FIT_TYPE_PROP, len);
  505. *type = -1;
  506. return -1;
  507. }
  508. /* Translate image type name to id */
  509. *type = genimg_get_type_id(data);
  510. return 0;
  511. }
  512. /**
  513. * fit_image_get_comp - get comp id for a given component image node
  514. * @fit: pointer to the FIT format image header
  515. * @noffset: component image node offset
  516. * @comp: pointer to the uint8_t, will hold comp numeric id
  517. *
  518. * fit_image_get_comp() finds comp property in a given component image node.
  519. * If the property is found, its (string) value is translated to the numeric
  520. * id which is returned to the caller.
  521. *
  522. * returns:
  523. * 0, on success
  524. * -1, on failure
  525. */
  526. int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp)
  527. {
  528. int len;
  529. const void *data;
  530. /* Get compression name from property data */
  531. data = fdt_getprop(fit, noffset, FIT_COMP_PROP, &len);
  532. if (data == NULL) {
  533. fit_get_debug(fit, noffset, FIT_COMP_PROP, len);
  534. *comp = -1;
  535. return -1;
  536. }
  537. /* Translate compression name to id */
  538. *comp = genimg_get_comp_id(data);
  539. return 0;
  540. }
  541. /**
  542. * fit_image_get_load() - get load addr property for given component image node
  543. * @fit: pointer to the FIT format image header
  544. * @noffset: component image node offset
  545. * @load: pointer to the uint32_t, will hold load address
  546. *
  547. * fit_image_get_load() finds load address property in a given component
  548. * image node. If the property is found, its value is returned to the caller.
  549. *
  550. * returns:
  551. * 0, on success
  552. * -1, on failure
  553. */
  554. int fit_image_get_load(const void *fit, int noffset, ulong *load)
  555. {
  556. int len;
  557. const uint32_t *data;
  558. data = fdt_getprop(fit, noffset, FIT_LOAD_PROP, &len);
  559. if (data == NULL) {
  560. fit_get_debug(fit, noffset, FIT_LOAD_PROP, len);
  561. return -1;
  562. }
  563. *load = uimage_to_cpu(*data);
  564. return 0;
  565. }
  566. /**
  567. * fit_image_get_entry() - get entry point address property
  568. * @fit: pointer to the FIT format image header
  569. * @noffset: component image node offset
  570. * @entry: pointer to the uint32_t, will hold entry point address
  571. *
  572. * This gets the entry point address property for a given component image
  573. * node.
  574. *
  575. * fit_image_get_entry() finds entry point address property in a given
  576. * component image node. If the property is found, its value is returned
  577. * to the caller.
  578. *
  579. * returns:
  580. * 0, on success
  581. * -1, on failure
  582. */
  583. int fit_image_get_entry(const void *fit, int noffset, ulong *entry)
  584. {
  585. int len;
  586. const uint32_t *data;
  587. data = fdt_getprop(fit, noffset, FIT_ENTRY_PROP, &len);
  588. if (data == NULL) {
  589. fit_get_debug(fit, noffset, FIT_ENTRY_PROP, len);
  590. return -1;
  591. }
  592. *entry = uimage_to_cpu(*data);
  593. return 0;
  594. }
  595. /**
  596. * fit_image_get_data - get data property and its size for a given component image node
  597. * @fit: pointer to the FIT format image header
  598. * @noffset: component image node offset
  599. * @data: double pointer to void, will hold data property's data address
  600. * @size: pointer to size_t, will hold data property's data size
  601. *
  602. * fit_image_get_data() finds data property in a given component image node.
  603. * If the property is found its data start address and size are returned to
  604. * the caller.
  605. *
  606. * returns:
  607. * 0, on success
  608. * -1, on failure
  609. */
  610. int fit_image_get_data(const void *fit, int noffset,
  611. const void **data, size_t *size)
  612. {
  613. int len;
  614. *data = fdt_getprop(fit, noffset, FIT_DATA_PROP, &len);
  615. if (*data == NULL) {
  616. fit_get_debug(fit, noffset, FIT_DATA_PROP, len);
  617. *size = 0;
  618. return -1;
  619. }
  620. *size = len;
  621. return 0;
  622. }
  623. /**
  624. * fit_image_hash_get_algo - get hash algorithm name
  625. * @fit: pointer to the FIT format image header
  626. * @noffset: hash node offset
  627. * @algo: double pointer to char, will hold pointer to the algorithm name
  628. *
  629. * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
  630. * If the property is found its data start address is returned to the caller.
  631. *
  632. * returns:
  633. * 0, on success
  634. * -1, on failure
  635. */
  636. int fit_image_hash_get_algo(const void *fit, int noffset, char **algo)
  637. {
  638. int len;
  639. *algo = (char *)fdt_getprop(fit, noffset, FIT_ALGO_PROP, &len);
  640. if (*algo == NULL) {
  641. fit_get_debug(fit, noffset, FIT_ALGO_PROP, len);
  642. return -1;
  643. }
  644. return 0;
  645. }
  646. /**
  647. * fit_image_hash_get_value - get hash value and length
  648. * @fit: pointer to the FIT format image header
  649. * @noffset: hash node offset
  650. * @value: double pointer to uint8_t, will hold address of a hash value data
  651. * @value_len: pointer to an int, will hold hash data length
  652. *
  653. * fit_image_hash_get_value() finds hash value property in a given hash node.
  654. * If the property is found its data start address and size are returned to
  655. * the caller.
  656. *
  657. * returns:
  658. * 0, on success
  659. * -1, on failure
  660. */
  661. int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value,
  662. int *value_len)
  663. {
  664. int len;
  665. *value = (uint8_t *)fdt_getprop(fit, noffset, FIT_VALUE_PROP, &len);
  666. if (*value == NULL) {
  667. fit_get_debug(fit, noffset, FIT_VALUE_PROP, len);
  668. *value_len = 0;
  669. return -1;
  670. }
  671. *value_len = len;
  672. return 0;
  673. }
  674. /**
  675. * fit_image_hash_get_ignore - get hash ignore flag
  676. * @fit: pointer to the FIT format image header
  677. * @noffset: hash node offset
  678. * @ignore: pointer to an int, will hold hash ignore flag
  679. *
  680. * fit_image_hash_get_ignore() finds hash ignore property in a given hash node.
  681. * If the property is found and non-zero, the hash algorithm is not verified by
  682. * u-boot automatically.
  683. *
  684. * returns:
  685. * 0, on ignore not found
  686. * value, on ignore found
  687. */
  688. static int fit_image_hash_get_ignore(const void *fit, int noffset, int *ignore)
  689. {
  690. int len;
  691. int *value;
  692. value = (int *)fdt_getprop(fit, noffset, FIT_IGNORE_PROP, &len);
  693. if (value == NULL || len != sizeof(int))
  694. *ignore = 0;
  695. else
  696. *ignore = *value;
  697. return 0;
  698. }
  699. /**
  700. * fit_set_timestamp - set node timestamp property
  701. * @fit: pointer to the FIT format image header
  702. * @noffset: node offset
  703. * @timestamp: timestamp value to be set
  704. *
  705. * fit_set_timestamp() attempts to set timestamp property in the requested
  706. * node and returns operation status to the caller.
  707. *
  708. * returns:
  709. * 0, on success
  710. * -1, on property read failure
  711. */
  712. int fit_set_timestamp(void *fit, int noffset, time_t timestamp)
  713. {
  714. uint32_t t;
  715. int ret;
  716. t = cpu_to_uimage(timestamp);
  717. ret = fdt_setprop(fit, noffset, FIT_TIMESTAMP_PROP, &t,
  718. sizeof(uint32_t));
  719. if (ret) {
  720. printf("Can't set '%s' property for '%s' node (%s)\n",
  721. FIT_TIMESTAMP_PROP, fit_get_name(fit, noffset, NULL),
  722. fdt_strerror(ret));
  723. return -1;
  724. }
  725. return 0;
  726. }
  727. /**
  728. * calculate_hash - calculate and return hash for provided input data
  729. * @data: pointer to the input data
  730. * @data_len: data length
  731. * @algo: requested hash algorithm
  732. * @value: pointer to the char, will hold hash value data (caller must
  733. * allocate enough free space)
  734. * value_len: length of the calculated hash
  735. *
  736. * calculate_hash() computes input data hash according to the requested
  737. * algorithm.
  738. * Resulting hash value is placed in caller provided 'value' buffer, length
  739. * of the calculated hash is returned via value_len pointer argument.
  740. *
  741. * returns:
  742. * 0, on success
  743. * -1, when algo is unsupported
  744. */
  745. int calculate_hash(const void *data, int data_len, const char *algo,
  746. uint8_t *value, int *value_len)
  747. {
  748. if (strcmp(algo, "crc32") == 0) {
  749. *((uint32_t *)value) = crc32_wd(0, data, data_len,
  750. CHUNKSZ_CRC32);
  751. *((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value));
  752. *value_len = 4;
  753. } else if (strcmp(algo, "sha1") == 0) {
  754. sha1_csum_wd((unsigned char *)data, data_len,
  755. (unsigned char *)value, CHUNKSZ_SHA1);
  756. *value_len = 20;
  757. } else if (strcmp(algo, "md5") == 0) {
  758. md5_wd((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
  759. *value_len = 16;
  760. } else {
  761. debug("Unsupported hash alogrithm\n");
  762. return -1;
  763. }
  764. return 0;
  765. }
  766. static int fit_image_check_hash(const void *fit, int noffset, const void *data,
  767. size_t size, char **err_msgp)
  768. {
  769. uint8_t value[FIT_MAX_HASH_LEN];
  770. int value_len;
  771. char *algo;
  772. uint8_t *fit_value;
  773. int fit_value_len;
  774. int ignore;
  775. *err_msgp = NULL;
  776. if (fit_image_hash_get_algo(fit, noffset, &algo)) {
  777. *err_msgp = " error!\nCan't get hash algo "
  778. "property";
  779. return -1;
  780. }
  781. printf("%s", algo);
  782. if (IMAGE_ENABLE_IGNORE) {
  783. fit_image_hash_get_ignore(fit, noffset, &ignore);
  784. if (ignore) {
  785. printf("-skipped ");
  786. return 0;
  787. }
  788. }
  789. if (fit_image_hash_get_value(fit, noffset, &fit_value,
  790. &fit_value_len)) {
  791. *err_msgp = " error!\nCan't get hash value "
  792. "property";
  793. return -1;
  794. }
  795. if (calculate_hash(data, size, algo, value, &value_len)) {
  796. *err_msgp = " error!\n"
  797. "Unsupported hash algorithm";
  798. return -1;
  799. }
  800. if (value_len != fit_value_len) {
  801. *err_msgp = " error !\nBad hash value len";
  802. return -1;
  803. } else if (memcmp(value, fit_value, value_len) != 0) {
  804. *err_msgp = " error!\nBad hash value";
  805. return -1;
  806. }
  807. return 0;
  808. }
  809. /**
  810. * fit_image_verify - verify data intergity
  811. * @fit: pointer to the FIT format image header
  812. * @image_noffset: component image node offset
  813. *
  814. * fit_image_verify() goes over component image hash nodes,
  815. * re-calculates each data hash and compares with the value stored in hash
  816. * node.
  817. *
  818. * returns:
  819. * 1, if all hashes are valid
  820. * 0, otherwise (or on error)
  821. */
  822. int fit_image_verify(const void *fit, int image_noffset)
  823. {
  824. const void *data;
  825. size_t size;
  826. int noffset;
  827. char *err_msg = "";
  828. /* Get image data and data length */
  829. if (fit_image_get_data(fit, image_noffset, &data, &size)) {
  830. printf("Can't get image data/size\n");
  831. return 0;
  832. }
  833. /* Process all hash subnodes of the component image node */
  834. for (noffset = fdt_first_subnode(fit, image_noffset);
  835. noffset >= 0;
  836. noffset = fdt_next_subnode(fit, noffset)) {
  837. const char *name = fit_get_name(fit, noffset, NULL);
  838. /*
  839. * Check subnode name, must be equal to "hash".
  840. * Multiple hash nodes require unique unit node
  841. * names, e.g. hash@1, hash@2, etc.
  842. */
  843. if (!strncmp(name, FIT_HASH_NODENAME,
  844. strlen(FIT_HASH_NODENAME))) {
  845. if (fit_image_check_hash(fit, noffset, data, size,
  846. &err_msg))
  847. goto error;
  848. puts("+ ");
  849. }
  850. }
  851. if (noffset == -FDT_ERR_TRUNCATED || noffset == -FDT_ERR_BADSTRUCTURE) {
  852. err_msg = " error!\nCorrupted or truncated tree";
  853. goto error;
  854. }
  855. return 1;
  856. error:
  857. printf("%s for '%s' hash node in '%s' image node\n",
  858. err_msg, fit_get_name(fit, noffset, NULL),
  859. fit_get_name(fit, image_noffset, NULL));
  860. return 0;
  861. }
  862. /**
  863. * fit_all_image_verify - verify data intergity for all images
  864. * @fit: pointer to the FIT format image header
  865. *
  866. * fit_all_image_verify() goes over all images in the FIT and
  867. * for every images checks if all it's hashes are valid.
  868. *
  869. * returns:
  870. * 1, if all hashes of all images are valid
  871. * 0, otherwise (or on error)
  872. */
  873. int fit_all_image_verify(const void *fit)
  874. {
  875. int images_noffset;
  876. int noffset;
  877. int ndepth;
  878. int count;
  879. /* Find images parent node offset */
  880. images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
  881. if (images_noffset < 0) {
  882. printf("Can't find images parent node '%s' (%s)\n",
  883. FIT_IMAGES_PATH, fdt_strerror(images_noffset));
  884. return 0;
  885. }
  886. /* Process all image subnodes, check hashes for each */
  887. printf("## Checking hash(es) for FIT Image at %08lx ...\n",
  888. (ulong)fit);
  889. for (ndepth = 0, count = 0,
  890. noffset = fdt_next_node(fit, images_noffset, &ndepth);
  891. (noffset >= 0) && (ndepth > 0);
  892. noffset = fdt_next_node(fit, noffset, &ndepth)) {
  893. if (ndepth == 1) {
  894. /*
  895. * Direct child node of the images parent node,
  896. * i.e. component image node.
  897. */
  898. printf(" Hash(es) for Image %u (%s): ", count++,
  899. fit_get_name(fit, noffset, NULL));
  900. if (!fit_image_verify(fit, noffset))
  901. return 0;
  902. printf("\n");
  903. }
  904. }
  905. return 1;
  906. }
  907. /**
  908. * fit_image_check_os - check whether image node is of a given os type
  909. * @fit: pointer to the FIT format image header
  910. * @noffset: component image node offset
  911. * @os: requested image os
  912. *
  913. * fit_image_check_os() reads image os property and compares its numeric
  914. * id with the requested os. Comparison result is returned to the caller.
  915. *
  916. * returns:
  917. * 1 if image is of given os type
  918. * 0 otherwise (or on error)
  919. */
  920. int fit_image_check_os(const void *fit, int noffset, uint8_t os)
  921. {
  922. uint8_t image_os;
  923. if (fit_image_get_os(fit, noffset, &image_os))
  924. return 0;
  925. return (os == image_os);
  926. }
  927. /**
  928. * fit_image_check_arch - check whether image node is of a given arch
  929. * @fit: pointer to the FIT format image header
  930. * @noffset: component image node offset
  931. * @arch: requested imagearch
  932. *
  933. * fit_image_check_arch() reads image arch property and compares its numeric
  934. * id with the requested arch. Comparison result is returned to the caller.
  935. *
  936. * returns:
  937. * 1 if image is of given arch
  938. * 0 otherwise (or on error)
  939. */
  940. int fit_image_check_arch(const void *fit, int noffset, uint8_t arch)
  941. {
  942. uint8_t image_arch;
  943. if (fit_image_get_arch(fit, noffset, &image_arch))
  944. return 0;
  945. return (arch == image_arch);
  946. }
  947. /**
  948. * fit_image_check_type - check whether image node is of a given type
  949. * @fit: pointer to the FIT format image header
  950. * @noffset: component image node offset
  951. * @type: requested image type
  952. *
  953. * fit_image_check_type() reads image type property and compares its numeric
  954. * id with the requested type. Comparison result is returned to the caller.
  955. *
  956. * returns:
  957. * 1 if image is of given type
  958. * 0 otherwise (or on error)
  959. */
  960. int fit_image_check_type(const void *fit, int noffset, uint8_t type)
  961. {
  962. uint8_t image_type;
  963. if (fit_image_get_type(fit, noffset, &image_type))
  964. return 0;
  965. return (type == image_type);
  966. }
  967. /**
  968. * fit_image_check_comp - check whether image node uses given compression
  969. * @fit: pointer to the FIT format image header
  970. * @noffset: component image node offset
  971. * @comp: requested image compression type
  972. *
  973. * fit_image_check_comp() reads image compression property and compares its
  974. * numeric id with the requested compression type. Comparison result is
  975. * returned to the caller.
  976. *
  977. * returns:
  978. * 1 if image uses requested compression
  979. * 0 otherwise (or on error)
  980. */
  981. int fit_image_check_comp(const void *fit, int noffset, uint8_t comp)
  982. {
  983. uint8_t image_comp;
  984. if (fit_image_get_comp(fit, noffset, &image_comp))
  985. return 0;
  986. return (comp == image_comp);
  987. }
  988. /**
  989. * fit_check_format - sanity check FIT image format
  990. * @fit: pointer to the FIT format image header
  991. *
  992. * fit_check_format() runs a basic sanity FIT image verification.
  993. * Routine checks for mandatory properties, nodes, etc.
  994. *
  995. * returns:
  996. * 1, on success
  997. * 0, on failure
  998. */
  999. int fit_check_format(const void *fit)
  1000. {
  1001. /* mandatory / node 'description' property */
  1002. if (fdt_getprop(fit, 0, FIT_DESC_PROP, NULL) == NULL) {
  1003. debug("Wrong FIT format: no description\n");
  1004. return 0;
  1005. }
  1006. if (IMAGE_ENABLE_TIMESTAMP) {
  1007. /* mandatory / node 'timestamp' property */
  1008. if (fdt_getprop(fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
  1009. debug("Wrong FIT format: no timestamp\n");
  1010. return 0;
  1011. }
  1012. }
  1013. /* mandatory subimages parent '/images' node */
  1014. if (fdt_path_offset(fit, FIT_IMAGES_PATH) < 0) {
  1015. debug("Wrong FIT format: no images parent node\n");
  1016. return 0;
  1017. }
  1018. return 1;
  1019. }
  1020. /**
  1021. * fit_conf_find_compat
  1022. * @fit: pointer to the FIT format image header
  1023. * @fdt: pointer to the device tree to compare against
  1024. *
  1025. * fit_conf_find_compat() attempts to find the configuration whose fdt is the
  1026. * most compatible with the passed in device tree.
  1027. *
  1028. * Example:
  1029. *
  1030. * / o image-tree
  1031. * |-o images
  1032. * | |-o fdt@1
  1033. * | |-o fdt@2
  1034. * |
  1035. * |-o configurations
  1036. * |-o config@1
  1037. * | |-fdt = fdt@1
  1038. * |
  1039. * |-o config@2
  1040. * |-fdt = fdt@2
  1041. *
  1042. * / o U-Boot fdt
  1043. * |-compatible = "foo,bar", "bim,bam"
  1044. *
  1045. * / o kernel fdt1
  1046. * |-compatible = "foo,bar",
  1047. *
  1048. * / o kernel fdt2
  1049. * |-compatible = "bim,bam", "baz,biz"
  1050. *
  1051. * Configuration 1 would be picked because the first string in U-Boot's
  1052. * compatible list, "foo,bar", matches a compatible string in the root of fdt1.
  1053. * "bim,bam" in fdt2 matches the second string which isn't as good as fdt1.
  1054. *
  1055. * returns:
  1056. * offset to the configuration to use if one was found
  1057. * -1 otherwise
  1058. */
  1059. int fit_conf_find_compat(const void *fit, const void *fdt)
  1060. {
  1061. int ndepth = 0;
  1062. int noffset, confs_noffset, images_noffset;
  1063. const void *fdt_compat;
  1064. int fdt_compat_len;
  1065. int best_match_offset = 0;
  1066. int best_match_pos = 0;
  1067. confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
  1068. images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
  1069. if (confs_noffset < 0 || images_noffset < 0) {
  1070. debug("Can't find configurations or images nodes.\n");
  1071. return -1;
  1072. }
  1073. fdt_compat = fdt_getprop(fdt, 0, "compatible", &fdt_compat_len);
  1074. if (!fdt_compat) {
  1075. debug("Fdt for comparison has no \"compatible\" property.\n");
  1076. return -1;
  1077. }
  1078. /*
  1079. * Loop over the configurations in the FIT image.
  1080. */
  1081. for (noffset = fdt_next_node(fit, confs_noffset, &ndepth);
  1082. (noffset >= 0) && (ndepth > 0);
  1083. noffset = fdt_next_node(fit, noffset, &ndepth)) {
  1084. const void *kfdt;
  1085. const char *kfdt_name;
  1086. int kfdt_noffset;
  1087. const char *cur_fdt_compat;
  1088. int len;
  1089. size_t size;
  1090. int i;
  1091. if (ndepth > 1)
  1092. continue;
  1093. kfdt_name = fdt_getprop(fit, noffset, "fdt", &len);
  1094. if (!kfdt_name) {
  1095. debug("No fdt property found.\n");
  1096. continue;
  1097. }
  1098. kfdt_noffset = fdt_subnode_offset(fit, images_noffset,
  1099. kfdt_name);
  1100. if (kfdt_noffset < 0) {
  1101. debug("No image node named \"%s\" found.\n",
  1102. kfdt_name);
  1103. continue;
  1104. }
  1105. /*
  1106. * Get a pointer to this configuration's fdt.
  1107. */
  1108. if (fit_image_get_data(fit, kfdt_noffset, &kfdt, &size)) {
  1109. debug("Failed to get fdt \"%s\".\n", kfdt_name);
  1110. continue;
  1111. }
  1112. len = fdt_compat_len;
  1113. cur_fdt_compat = fdt_compat;
  1114. /*
  1115. * Look for a match for each U-Boot compatibility string in
  1116. * turn in this configuration's fdt.
  1117. */
  1118. for (i = 0; len > 0 &&
  1119. (!best_match_offset || best_match_pos > i); i++) {
  1120. int cur_len = strlen(cur_fdt_compat) + 1;
  1121. if (!fdt_node_check_compatible(kfdt, 0,
  1122. cur_fdt_compat)) {
  1123. best_match_offset = noffset;
  1124. best_match_pos = i;
  1125. break;
  1126. }
  1127. len -= cur_len;
  1128. cur_fdt_compat += cur_len;
  1129. }
  1130. }
  1131. if (!best_match_offset) {
  1132. debug("No match found.\n");
  1133. return -1;
  1134. }
  1135. return best_match_offset;
  1136. }
  1137. /**
  1138. * fit_conf_get_node - get node offset for configuration of a given unit name
  1139. * @fit: pointer to the FIT format image header
  1140. * @conf_uname: configuration node unit name
  1141. *
  1142. * fit_conf_get_node() finds a configuration (withing the '/configurations'
  1143. * parant node) of a provided unit name. If configuration is found its node
  1144. * offset is returned to the caller.
  1145. *
  1146. * When NULL is provided in second argument fit_conf_get_node() will search
  1147. * for a default configuration node instead. Default configuration node unit
  1148. * name is retrived from FIT_DEFAULT_PROP property of the '/configurations'
  1149. * node.
  1150. *
  1151. * returns:
  1152. * configuration node offset when found (>=0)
  1153. * negative number on failure (FDT_ERR_* code)
  1154. */
  1155. int fit_conf_get_node(const void *fit, const char *conf_uname)
  1156. {
  1157. int noffset, confs_noffset;
  1158. int len;
  1159. confs_noffset = fdt_path_offset(fit, FIT_CONFS_PATH);
  1160. if (confs_noffset < 0) {
  1161. debug("Can't find configurations parent node '%s' (%s)\n",
  1162. FIT_CONFS_PATH, fdt_strerror(confs_noffset));
  1163. return confs_noffset;
  1164. }
  1165. if (conf_uname == NULL) {
  1166. /* get configuration unit name from the default property */
  1167. debug("No configuration specified, trying default...\n");
  1168. conf_uname = (char *)fdt_getprop(fit, confs_noffset,
  1169. FIT_DEFAULT_PROP, &len);
  1170. if (conf_uname == NULL) {
  1171. fit_get_debug(fit, confs_noffset, FIT_DEFAULT_PROP,
  1172. len);
  1173. return len;
  1174. }
  1175. debug("Found default configuration: '%s'\n", conf_uname);
  1176. }
  1177. noffset = fdt_subnode_offset(fit, confs_noffset, conf_uname);
  1178. if (noffset < 0) {
  1179. debug("Can't get node offset for configuration unit name: '%s' (%s)\n",
  1180. conf_uname, fdt_strerror(noffset));
  1181. }
  1182. return noffset;
  1183. }
  1184. static int __fit_conf_get_prop_node(const void *fit, int noffset,
  1185. const char *prop_name)
  1186. {
  1187. char *uname;
  1188. int len;
  1189. /* get kernel image unit name from configuration kernel property */
  1190. uname = (char *)fdt_getprop(fit, noffset, prop_name, &len);
  1191. if (uname == NULL)
  1192. return len;
  1193. return fit_image_get_node(fit, uname);
  1194. }
  1195. /**
  1196. * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
  1197. * a given configuration
  1198. * @fit: pointer to the FIT format image header
  1199. * @noffset: configuration node offset
  1200. *
  1201. * fit_conf_get_kernel_node() retrives kernel image node unit name from
  1202. * configuration FIT_KERNEL_PROP property and translates it to the node
  1203. * offset.
  1204. *
  1205. * returns:
  1206. * image node offset when found (>=0)
  1207. * negative number on failure (FDT_ERR_* code)
  1208. */
  1209. int fit_conf_get_kernel_node(const void *fit, int noffset)
  1210. {
  1211. return __fit_conf_get_prop_node(fit, noffset, FIT_KERNEL_PROP);
  1212. }
  1213. /**
  1214. * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
  1215. * a given configuration
  1216. * @fit: pointer to the FIT format image header
  1217. * @noffset: configuration node offset
  1218. *
  1219. * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
  1220. * configuration FIT_KERNEL_PROP property and translates it to the node
  1221. * offset.
  1222. *
  1223. * returns:
  1224. * image node offset when found (>=0)
  1225. * negative number on failure (FDT_ERR_* code)
  1226. */
  1227. int fit_conf_get_ramdisk_node(const void *fit, int noffset)
  1228. {
  1229. return __fit_conf_get_prop_node(fit, noffset, FIT_RAMDISK_PROP);
  1230. }
  1231. /**
  1232. * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
  1233. * a given configuration
  1234. * @fit: pointer to the FIT format image header
  1235. * @noffset: configuration node offset
  1236. *
  1237. * fit_conf_get_fdt_node() retrives fdt image node unit name from
  1238. * configuration FIT_KERNEL_PROP property and translates it to the node
  1239. * offset.
  1240. *
  1241. * returns:
  1242. * image node offset when found (>=0)
  1243. * negative number on failure (FDT_ERR_* code)
  1244. */
  1245. int fit_conf_get_fdt_node(const void *fit, int noffset)
  1246. {
  1247. return __fit_conf_get_prop_node(fit, noffset, FIT_FDT_PROP);
  1248. }
  1249. /**
  1250. * fit_conf_print - prints out the FIT configuration details
  1251. * @fit: pointer to the FIT format image header
  1252. * @noffset: offset of the configuration node
  1253. * @p: pointer to prefix string
  1254. *
  1255. * fit_conf_print() lists all mandatory properies for the processed
  1256. * configuration node.
  1257. *
  1258. * returns:
  1259. * no returned results
  1260. */
  1261. void fit_conf_print(const void *fit, int noffset, const char *p)
  1262. {
  1263. char *desc;
  1264. char *uname;
  1265. int ret;
  1266. /* Mandatory properties */
  1267. ret = fit_get_desc(fit, noffset, &desc);
  1268. printf("%s Description: ", p);
  1269. if (ret)
  1270. printf("unavailable\n");
  1271. else
  1272. printf("%s\n", desc);
  1273. uname = (char *)fdt_getprop(fit, noffset, FIT_KERNEL_PROP, NULL);
  1274. printf("%s Kernel: ", p);
  1275. if (uname == NULL)
  1276. printf("unavailable\n");
  1277. else
  1278. printf("%s\n", uname);
  1279. /* Optional properties */
  1280. uname = (char *)fdt_getprop(fit, noffset, FIT_RAMDISK_PROP, NULL);
  1281. if (uname)
  1282. printf("%s Init Ramdisk: %s\n", p, uname);
  1283. uname = (char *)fdt_getprop(fit, noffset, FIT_FDT_PROP, NULL);
  1284. if (uname)
  1285. printf("%s FDT: %s\n", p, uname);
  1286. }
  1287. /**
  1288. * fit_check_ramdisk - verify FIT format ramdisk subimage
  1289. * @fit_hdr: pointer to the FIT ramdisk header
  1290. * @rd_noffset: ramdisk subimage node offset within FIT image
  1291. * @arch: requested ramdisk image architecture type
  1292. * @verify: data CRC verification flag
  1293. *
  1294. * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
  1295. * specified FIT image.
  1296. *
  1297. * returns:
  1298. * 1, on success
  1299. * 0, on failure
  1300. */
  1301. #ifndef USE_HOSTCC
  1302. int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch,
  1303. int verify)
  1304. {
  1305. fit_image_print(fit, rd_noffset, " ");
  1306. if (verify) {
  1307. puts(" Verifying Hash Integrity ... ");
  1308. if (!fit_image_verify(fit, rd_noffset)) {
  1309. puts("Bad Data Hash\n");
  1310. bootstage_error(BOOTSTAGE_ID_FIT_RD_HASH);
  1311. return 0;
  1312. }
  1313. puts("OK\n");
  1314. }
  1315. bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL);
  1316. if (!fit_image_check_os(fit, rd_noffset, IH_OS_LINUX) ||
  1317. !fit_image_check_arch(fit, rd_noffset, arch) ||
  1318. !fit_image_check_type(fit, rd_noffset, IH_TYPE_RAMDISK)) {
  1319. printf("No Linux %s Ramdisk Image\n",
  1320. genimg_get_arch_name(arch));
  1321. bootstage_error(BOOTSTAGE_ID_FIT_RD_CHECK_ALL);
  1322. return 0;
  1323. }
  1324. bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL_OK);
  1325. return 1;
  1326. }
  1327. #endif /* USE_HOSTCC */