image.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507
  1. /*
  2. * (C) Copyright 2008 Semihalf
  3. *
  4. * (C) Copyright 2000-2006
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #ifndef USE_HOSTCC
  26. #include <common.h>
  27. #include <watchdog.h>
  28. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  29. #include <status_led.h>
  30. #endif
  31. #ifdef CONFIG_HAS_DATAFLASH
  32. #include <dataflash.h>
  33. #endif
  34. #ifdef CONFIG_LOGBUFFER
  35. #include <logbuff.h>
  36. #endif
  37. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
  38. #include <rtc.h>
  39. #endif
  40. #include <image.h>
  41. #if defined(CONFIG_FIT) || defined (CONFIG_OF_LIBFDT)
  42. #include <fdt.h>
  43. #include <libfdt.h>
  44. #include <fdt_support.h>
  45. #endif
  46. #if defined(CONFIG_FIT)
  47. #include <u-boot/md5.h>
  48. #include <sha1.h>
  49. static int fit_check_ramdisk (const void *fit, int os_noffset,
  50. uint8_t arch, int verify);
  51. #endif
  52. #ifdef CONFIG_CMD_BDI
  53. extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  54. #endif
  55. DECLARE_GLOBAL_DATA_PTR;
  56. static image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch,
  57. int verify);
  58. #else
  59. #include "mkimage.h"
  60. #include <u-boot/md5.h>
  61. #include <time.h>
  62. #include <image.h>
  63. #endif /* !USE_HOSTCC*/
  64. typedef struct table_entry {
  65. int id; /* as defined in image.h */
  66. char *sname; /* short (input) name */
  67. char *lname; /* long (output) name */
  68. } table_entry_t;
  69. static table_entry_t uimage_arch[] = {
  70. { IH_ARCH_INVALID, NULL, "Invalid ARCH", },
  71. { IH_ARCH_ALPHA, "alpha", "Alpha", },
  72. { IH_ARCH_ARM, "arm", "ARM", },
  73. { IH_ARCH_I386, "x86", "Intel x86", },
  74. { IH_ARCH_IA64, "ia64", "IA64", },
  75. { IH_ARCH_M68K, "m68k", "M68K", },
  76. { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", },
  77. { IH_ARCH_MIPS, "mips", "MIPS", },
  78. { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", },
  79. { IH_ARCH_NIOS, "nios", "NIOS", },
  80. { IH_ARCH_NIOS2, "nios2", "NIOS II", },
  81. { IH_ARCH_PPC, "powerpc", "PowerPC", },
  82. { IH_ARCH_PPC, "ppc", "PowerPC", },
  83. { IH_ARCH_S390, "s390", "IBM S390", },
  84. { IH_ARCH_SH, "sh", "SuperH", },
  85. { IH_ARCH_SPARC, "sparc", "SPARC", },
  86. { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", },
  87. { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", },
  88. { IH_ARCH_AVR32, "avr32", "AVR32", },
  89. { -1, "", "", },
  90. };
  91. static table_entry_t uimage_os[] = {
  92. { IH_OS_INVALID, NULL, "Invalid OS", },
  93. #if defined(CONFIG_ARTOS) || defined(USE_HOSTCC)
  94. { IH_OS_ARTOS, "artos", "ARTOS", },
  95. #endif
  96. { IH_OS_LINUX, "linux", "Linux", },
  97. #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
  98. { IH_OS_LYNXOS, "lynxos", "LynxOS", },
  99. #endif
  100. { IH_OS_NETBSD, "netbsd", "NetBSD", },
  101. { IH_OS_RTEMS, "rtems", "RTEMS", },
  102. { IH_OS_U_BOOT, "u-boot", "U-Boot", },
  103. #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
  104. { IH_OS_QNX, "qnx", "QNX", },
  105. { IH_OS_VXWORKS, "vxworks", "VxWorks", },
  106. #endif
  107. #ifdef USE_HOSTCC
  108. { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
  109. { IH_OS_DELL, "dell", "Dell", },
  110. { IH_OS_ESIX, "esix", "Esix", },
  111. { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
  112. { IH_OS_IRIX, "irix", "Irix", },
  113. { IH_OS_NCR, "ncr", "NCR", },
  114. { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
  115. { IH_OS_PSOS, "psos", "pSOS", },
  116. { IH_OS_SCO, "sco", "SCO", },
  117. { IH_OS_SOLARIS, "solaris", "Solaris", },
  118. { IH_OS_SVR4, "svr4", "SVR4", },
  119. #endif
  120. { -1, "", "", },
  121. };
  122. static table_entry_t uimage_type[] = {
  123. { IH_TYPE_INVALID, NULL, "Invalid Image", },
  124. { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
  125. { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
  126. { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
  127. { IH_TYPE_MULTI, "multi", "Multi-File Image", },
  128. { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
  129. { IH_TYPE_SCRIPT, "script", "Script", },
  130. { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
  131. { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
  132. { -1, "", "", },
  133. };
  134. static table_entry_t uimage_comp[] = {
  135. { IH_COMP_NONE, "none", "uncompressed", },
  136. { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
  137. { IH_COMP_GZIP, "gzip", "gzip compressed", },
  138. { -1, "", "", },
  139. };
  140. uint32_t crc32 (uint32_t, const unsigned char *, uint);
  141. uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
  142. static void genimg_print_size (uint32_t size);
  143. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  144. static void genimg_print_time (time_t timestamp);
  145. #endif
  146. /*****************************************************************************/
  147. /* Legacy format routines */
  148. /*****************************************************************************/
  149. int image_check_hcrc (image_header_t *hdr)
  150. {
  151. ulong hcrc;
  152. ulong len = image_get_header_size ();
  153. image_header_t header;
  154. /* Copy header so we can blank CRC field for re-calculation */
  155. memmove (&header, (char *)hdr, image_get_header_size ());
  156. image_set_hcrc (&header, 0);
  157. hcrc = crc32 (0, (unsigned char *)&header, len);
  158. return (hcrc == image_get_hcrc (hdr));
  159. }
  160. int image_check_dcrc (image_header_t *hdr)
  161. {
  162. ulong data = image_get_data (hdr);
  163. ulong len = image_get_data_size (hdr);
  164. ulong dcrc = crc32_wd (0, (unsigned char *)data, len, CHUNKSZ_CRC32);
  165. return (dcrc == image_get_dcrc (hdr));
  166. }
  167. /**
  168. * image_multi_count - get component (sub-image) count
  169. * @hdr: pointer to the header of the multi component image
  170. *
  171. * image_multi_count() returns number of components in a multi
  172. * component image.
  173. *
  174. * Note: no checking of the image type is done, caller must pass
  175. * a valid multi component image.
  176. *
  177. * returns:
  178. * number of components
  179. */
  180. ulong image_multi_count (image_header_t *hdr)
  181. {
  182. ulong i, count = 0;
  183. uint32_t *size;
  184. /* get start of the image payload, which in case of multi
  185. * component images that points to a table of component sizes */
  186. size = (uint32_t *)image_get_data (hdr);
  187. /* count non empty slots */
  188. for (i = 0; size[i]; ++i)
  189. count++;
  190. return count;
  191. }
  192. /**
  193. * image_multi_getimg - get component data address and size
  194. * @hdr: pointer to the header of the multi component image
  195. * @idx: index of the requested component
  196. * @data: pointer to a ulong variable, will hold component data address
  197. * @len: pointer to a ulong variable, will hold component size
  198. *
  199. * image_multi_getimg() returns size and data address for the requested
  200. * component in a multi component image.
  201. *
  202. * Note: no checking of the image type is done, caller must pass
  203. * a valid multi component image.
  204. *
  205. * returns:
  206. * data address and size of the component, if idx is valid
  207. * 0 in data and len, if idx is out of range
  208. */
  209. void image_multi_getimg (image_header_t *hdr, ulong idx,
  210. ulong *data, ulong *len)
  211. {
  212. int i;
  213. uint32_t *size;
  214. ulong offset, count, img_data;
  215. /* get number of component */
  216. count = image_multi_count (hdr);
  217. /* get start of the image payload, which in case of multi
  218. * component images that points to a table of component sizes */
  219. size = (uint32_t *)image_get_data (hdr);
  220. /* get address of the proper component data start, which means
  221. * skipping sizes table (add 1 for last, null entry) */
  222. img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t);
  223. if (idx < count) {
  224. *len = uimage_to_cpu (size[idx]);
  225. offset = 0;
  226. /* go over all indices preceding requested component idx */
  227. for (i = 0; i < idx; i++) {
  228. /* add up i-th component size, rounding up to 4 bytes */
  229. offset += (uimage_to_cpu (size[i]) + 3) & ~3 ;
  230. }
  231. /* calculate idx-th component data address */
  232. *data = img_data + offset;
  233. } else {
  234. *len = 0;
  235. *data = 0;
  236. }
  237. }
  238. static void image_print_type (image_header_t *hdr)
  239. {
  240. const char *os, *arch, *type, *comp;
  241. os = genimg_get_os_name (image_get_os (hdr));
  242. arch = genimg_get_arch_name (image_get_arch (hdr));
  243. type = genimg_get_type_name (image_get_type (hdr));
  244. comp = genimg_get_comp_name (image_get_comp (hdr));
  245. printf ("%s %s %s (%s)\n", arch, os, type, comp);
  246. }
  247. /**
  248. * image_print_contents - prints out the contents of the legacy format image
  249. * @hdr: pointer to the legacy format image header
  250. * @p: pointer to prefix string
  251. *
  252. * image_print_contents() formats a multi line legacy image contents description.
  253. * The routine prints out all header fields followed by the size/offset data
  254. * for MULTI/SCRIPT images.
  255. *
  256. * returns:
  257. * no returned results
  258. */
  259. void image_print_contents (image_header_t *hdr)
  260. {
  261. const char *p;
  262. #ifdef USE_HOSTCC
  263. p = "";
  264. #else
  265. p = " ";
  266. #endif
  267. printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr));
  268. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  269. printf ("%sCreated: ", p);
  270. genimg_print_time ((time_t)image_get_time (hdr));
  271. #endif
  272. printf ("%sImage Type: ", p);
  273. image_print_type (hdr);
  274. printf ("%sData Size: ", p);
  275. genimg_print_size (image_get_data_size (hdr));
  276. printf ("%sLoad Address: %08x\n", p, image_get_load (hdr));
  277. printf ("%sEntry Point: %08x\n", p, image_get_ep (hdr));
  278. if (image_check_type (hdr, IH_TYPE_MULTI) ||
  279. image_check_type (hdr, IH_TYPE_SCRIPT)) {
  280. int i;
  281. ulong data, len;
  282. ulong count = image_multi_count (hdr);
  283. printf ("%sContents:\n", p);
  284. for (i = 0; i < count; i++) {
  285. image_multi_getimg (hdr, i, &data, &len);
  286. printf ("%s Image %d: ", p, i);
  287. genimg_print_size (len);
  288. if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) {
  289. /*
  290. * the user may need to know offsets
  291. * if planning to do something with
  292. * multiple files
  293. */
  294. printf ("%s Offset = 0x%08lx\n", p, data);
  295. }
  296. }
  297. }
  298. }
  299. #ifndef USE_HOSTCC
  300. /**
  301. * image_get_ramdisk - get and verify ramdisk image
  302. * @rd_addr: ramdisk image start address
  303. * @arch: expected ramdisk architecture
  304. * @verify: checksum verification flag
  305. *
  306. * image_get_ramdisk() returns a pointer to the verified ramdisk image
  307. * header. Routine receives image start address and expected architecture
  308. * flag. Verification done covers data and header integrity and os/type/arch
  309. * fields checking.
  310. *
  311. * If dataflash support is enabled routine checks for dataflash addresses
  312. * and handles required dataflash reads.
  313. *
  314. * returns:
  315. * pointer to a ramdisk image header, if image was found and valid
  316. * otherwise, return NULL
  317. */
  318. static image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch,
  319. int verify)
  320. {
  321. image_header_t *rd_hdr = (image_header_t *)rd_addr;
  322. if (!image_check_magic (rd_hdr)) {
  323. puts ("Bad Magic Number\n");
  324. show_boot_progress (-10);
  325. return NULL;
  326. }
  327. if (!image_check_hcrc (rd_hdr)) {
  328. puts ("Bad Header Checksum\n");
  329. show_boot_progress (-11);
  330. return NULL;
  331. }
  332. show_boot_progress (10);
  333. image_print_contents (rd_hdr);
  334. if (verify) {
  335. puts(" Verifying Checksum ... ");
  336. if (!image_check_dcrc (rd_hdr)) {
  337. puts ("Bad Data CRC\n");
  338. show_boot_progress (-12);
  339. return NULL;
  340. }
  341. puts("OK\n");
  342. }
  343. show_boot_progress (11);
  344. if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
  345. !image_check_arch (rd_hdr, arch) ||
  346. !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
  347. printf ("No Linux %s Ramdisk Image\n",
  348. genimg_get_arch_name(arch));
  349. show_boot_progress (-13);
  350. return NULL;
  351. }
  352. return rd_hdr;
  353. }
  354. #endif /* !USE_HOSTCC */
  355. /*****************************************************************************/
  356. /* Shared dual-format routines */
  357. /*****************************************************************************/
  358. #ifndef USE_HOSTCC
  359. int getenv_yesno (char *var)
  360. {
  361. char *s = getenv (var);
  362. return (s && (*s == 'n')) ? 0 : 1;
  363. }
  364. ulong getenv_bootm_low(void)
  365. {
  366. char *s = getenv ("bootm_low");
  367. if (s) {
  368. ulong tmp = simple_strtoul (s, NULL, 16);
  369. return tmp;
  370. }
  371. #if defined(CFG_SDRAM_BASE)
  372. return CFG_SDRAM_BASE;
  373. #elif defined(CONFIG_ARM)
  374. return gd->bd->bi_dram[0].start;
  375. #else
  376. return 0;
  377. #endif
  378. }
  379. ulong getenv_bootm_size(void)
  380. {
  381. char *s = getenv ("bootm_size");
  382. if (s) {
  383. ulong tmp = simple_strtoul (s, NULL, 16);
  384. return tmp;
  385. }
  386. #if defined(CONFIG_ARM)
  387. return gd->bd->bi_dram[0].size;
  388. #else
  389. return gd->bd->bi_memsize;
  390. #endif
  391. }
  392. void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
  393. {
  394. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  395. while (len > 0) {
  396. size_t tail = (len > chunksz) ? chunksz : len;
  397. WATCHDOG_RESET ();
  398. memmove (to, from, tail);
  399. to += tail;
  400. from += tail;
  401. len -= tail;
  402. }
  403. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  404. memmove (to, from, len);
  405. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  406. }
  407. #endif /* !USE_HOSTCC */
  408. static void genimg_print_size (uint32_t size)
  409. {
  410. #ifndef USE_HOSTCC
  411. printf ("%d Bytes = ", size);
  412. print_size (size, "\n");
  413. #else
  414. printf ("%d Bytes = %.2f kB = %.2f MB\n",
  415. size, (double)size / 1.024e3,
  416. (double)size / 1.048576e6);
  417. #endif
  418. }
  419. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  420. static void genimg_print_time (time_t timestamp)
  421. {
  422. #ifndef USE_HOSTCC
  423. struct rtc_time tm;
  424. to_tm (timestamp, &tm);
  425. printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
  426. tm.tm_year, tm.tm_mon, tm.tm_mday,
  427. tm.tm_hour, tm.tm_min, tm.tm_sec);
  428. #else
  429. printf ("%s", ctime(&timestamp));
  430. #endif
  431. }
  432. #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
  433. /**
  434. * get_table_entry_name - translate entry id to long name
  435. * @table: pointer to a translation table for entries of a specific type
  436. * @msg: message to be returned when translation fails
  437. * @id: entry id to be translated
  438. *
  439. * get_table_entry_name() will go over translation table trying to find
  440. * entry that matches given id. If matching entry is found, its long
  441. * name is returned to the caller.
  442. *
  443. * returns:
  444. * long entry name if translation succeeds
  445. * msg otherwise
  446. */
  447. static char *get_table_entry_name (table_entry_t *table, char *msg, int id)
  448. {
  449. for (; table->id >= 0; ++table) {
  450. if (table->id == id)
  451. return (table->lname);
  452. }
  453. return (msg);
  454. }
  455. const char *genimg_get_os_name (uint8_t os)
  456. {
  457. return (get_table_entry_name (uimage_os, "Unknown OS", os));
  458. }
  459. const char *genimg_get_arch_name (uint8_t arch)
  460. {
  461. return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
  462. }
  463. const char *genimg_get_type_name (uint8_t type)
  464. {
  465. return (get_table_entry_name (uimage_type, "Unknown Image", type));
  466. }
  467. const char *genimg_get_comp_name (uint8_t comp)
  468. {
  469. return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
  470. }
  471. /**
  472. * get_table_entry_id - translate short entry name to id
  473. * @table: pointer to a translation table for entries of a specific type
  474. * @table_name: to be used in case of error
  475. * @name: entry short name to be translated
  476. *
  477. * get_table_entry_id() will go over translation table trying to find
  478. * entry that matches given short name. If matching entry is found,
  479. * its id returned to the caller.
  480. *
  481. * returns:
  482. * entry id if translation succeeds
  483. * -1 otherwise
  484. */
  485. static int get_table_entry_id (table_entry_t *table,
  486. const char *table_name, const char *name)
  487. {
  488. table_entry_t *t;
  489. #ifdef USE_HOSTCC
  490. int first = 1;
  491. for (t = table; t->id >= 0; ++t) {
  492. if (t->sname && strcasecmp(t->sname, name) == 0)
  493. return (t->id);
  494. }
  495. fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
  496. for (t = table; t->id >= 0; ++t) {
  497. if (t->sname == NULL)
  498. continue;
  499. fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
  500. first = 0;
  501. }
  502. fprintf (stderr, "\n");
  503. #else
  504. for (t = table; t->id >= 0; ++t) {
  505. if (t->sname && strcmp(t->sname, name) == 0)
  506. return (t->id);
  507. }
  508. debug ("Invalid %s Type: %s\n", table_name, name);
  509. #endif /* USE_HOSTCC */
  510. return (-1);
  511. }
  512. int genimg_get_os_id (const char *name)
  513. {
  514. return (get_table_entry_id (uimage_os, "OS", name));
  515. }
  516. int genimg_get_arch_id (const char *name)
  517. {
  518. return (get_table_entry_id (uimage_arch, "CPU", name));
  519. }
  520. int genimg_get_type_id (const char *name)
  521. {
  522. return (get_table_entry_id (uimage_type, "Image", name));
  523. }
  524. int genimg_get_comp_id (const char *name)
  525. {
  526. return (get_table_entry_id (uimage_comp, "Compression", name));
  527. }
  528. #ifndef USE_HOSTCC
  529. /**
  530. * genimg_get_format - get image format type
  531. * @img_addr: image start address
  532. *
  533. * genimg_get_format() checks whether provided address points to a valid
  534. * legacy or FIT image.
  535. *
  536. * New uImage format and FDT blob are based on a libfdt. FDT blob
  537. * may be passed directly or embedded in a FIT image. In both situations
  538. * genimg_get_format() must be able to dectect libfdt header.
  539. *
  540. * returns:
  541. * image format type or IMAGE_FORMAT_INVALID if no image is present
  542. */
  543. int genimg_get_format (void *img_addr)
  544. {
  545. ulong format = IMAGE_FORMAT_INVALID;
  546. image_header_t *hdr;
  547. #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
  548. char *fit_hdr;
  549. #endif
  550. hdr = (image_header_t *)img_addr;
  551. if (image_check_magic(hdr))
  552. format = IMAGE_FORMAT_LEGACY;
  553. #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
  554. else {
  555. fit_hdr = (char *)img_addr;
  556. if (fdt_check_header (fit_hdr) == 0)
  557. format = IMAGE_FORMAT_FIT;
  558. }
  559. #endif
  560. return format;
  561. }
  562. /**
  563. * genimg_get_image - get image from special storage (if necessary)
  564. * @img_addr: image start address
  565. *
  566. * genimg_get_image() checks if provided image start adddress is located
  567. * in a dataflash storage. If so, image is moved to a system RAM memory.
  568. *
  569. * returns:
  570. * image start address after possible relocation from special storage
  571. */
  572. ulong genimg_get_image (ulong img_addr)
  573. {
  574. ulong ram_addr = img_addr;
  575. #ifdef CONFIG_HAS_DATAFLASH
  576. ulong h_size, d_size;
  577. if (addr_dataflash (img_addr)){
  578. /* ger RAM address */
  579. ram_addr = CFG_LOAD_ADDR;
  580. /* get header size */
  581. h_size = image_get_header_size ();
  582. #if defined(CONFIG_FIT)
  583. if (sizeof(struct fdt_header) > h_size)
  584. h_size = sizeof(struct fdt_header);
  585. #endif
  586. /* read in header */
  587. debug (" Reading image header from dataflash address "
  588. "%08lx to RAM address %08lx\n", img_addr, ram_addr);
  589. read_dataflash (img_addr, h_size, (char *)ram_addr);
  590. /* get data size */
  591. switch (genimg_get_format ((void *)ram_addr)) {
  592. case IMAGE_FORMAT_LEGACY:
  593. d_size = image_get_data_size ((image_header_t *)ram_addr);
  594. debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
  595. ram_addr, d_size);
  596. break;
  597. #if defined(CONFIG_FIT)
  598. case IMAGE_FORMAT_FIT:
  599. d_size = fit_get_size ((const void *)ram_addr) - h_size;
  600. debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
  601. ram_addr, d_size);
  602. break;
  603. #endif
  604. default:
  605. printf (" No valid image found at 0x%08lx\n", img_addr);
  606. return ram_addr;
  607. }
  608. /* read in image data */
  609. debug (" Reading image remaining data from dataflash address "
  610. "%08lx to RAM address %08lx\n", img_addr + h_size,
  611. ram_addr + h_size);
  612. read_dataflash (img_addr + h_size, d_size,
  613. (char *)(ram_addr + h_size));
  614. }
  615. #endif /* CONFIG_HAS_DATAFLASH */
  616. return ram_addr;
  617. }
  618. /**
  619. * fit_has_config - check if there is a valid FIT configuration
  620. * @images: pointer to the bootm command headers structure
  621. *
  622. * fit_has_config() checks if there is a FIT configuration in use
  623. * (if FTI support is present).
  624. *
  625. * returns:
  626. * 0, no FIT support or no configuration found
  627. * 1, configuration found
  628. */
  629. int genimg_has_config (bootm_headers_t *images)
  630. {
  631. #if defined(CONFIG_FIT)
  632. if (images->fit_uname_cfg)
  633. return 1;
  634. #endif
  635. return 0;
  636. }
  637. /**
  638. * boot_get_ramdisk - main ramdisk handling routine
  639. * @argc: command argument count
  640. * @argv: command argument list
  641. * @images: pointer to the bootm images structure
  642. * @arch: expected ramdisk architecture
  643. * @rd_start: pointer to a ulong variable, will hold ramdisk start address
  644. * @rd_end: pointer to a ulong variable, will hold ramdisk end
  645. *
  646. * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
  647. * Curently supported are the following ramdisk sources:
  648. * - multicomponent kernel/ramdisk image,
  649. * - commandline provided address of decicated ramdisk image.
  650. *
  651. * returns:
  652. * 0, if ramdisk image was found and valid, or skiped
  653. * rd_start and rd_end are set to ramdisk start/end addresses if
  654. * ramdisk image is found and valid
  655. *
  656. * 1, if ramdisk image is found but corrupted
  657. * rd_start and rd_end are set to 0 if no ramdisk exists
  658. */
  659. int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images,
  660. uint8_t arch, ulong *rd_start, ulong *rd_end)
  661. {
  662. ulong rd_addr, rd_load;
  663. ulong rd_data, rd_len;
  664. image_header_t *rd_hdr;
  665. #if defined(CONFIG_FIT)
  666. void *fit_hdr;
  667. const char *fit_uname_config = NULL;
  668. const char *fit_uname_ramdisk = NULL;
  669. ulong default_addr;
  670. int rd_noffset;
  671. int cfg_noffset;
  672. const void *data;
  673. size_t size;
  674. #endif
  675. *rd_start = 0;
  676. *rd_end = 0;
  677. /*
  678. * Look for a '-' which indicates to ignore the
  679. * ramdisk argument
  680. */
  681. if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
  682. debug ("## Skipping init Ramdisk\n");
  683. rd_len = rd_data = 0;
  684. } else if (argc >= 3 || genimg_has_config (images)) {
  685. #if defined(CONFIG_FIT)
  686. if (argc >= 3) {
  687. /*
  688. * If the init ramdisk comes from the FIT image and
  689. * the FIT image address is omitted in the command
  690. * line argument, try to use os FIT image address or
  691. * default load address.
  692. */
  693. if (images->fit_uname_os)
  694. default_addr = (ulong)images->fit_hdr_os;
  695. else
  696. default_addr = load_addr;
  697. if (fit_parse_conf (argv[2], default_addr,
  698. &rd_addr, &fit_uname_config)) {
  699. debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
  700. fit_uname_config, rd_addr);
  701. } else if (fit_parse_subimage (argv[2], default_addr,
  702. &rd_addr, &fit_uname_ramdisk)) {
  703. debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
  704. fit_uname_ramdisk, rd_addr);
  705. } else
  706. #endif
  707. {
  708. rd_addr = simple_strtoul(argv[2], NULL, 16);
  709. debug ("* ramdisk: cmdline image address = 0x%08lx\n",
  710. rd_addr);
  711. }
  712. #if defined(CONFIG_FIT)
  713. } else {
  714. /* use FIT configuration provided in first bootm
  715. * command argument
  716. */
  717. rd_addr = (ulong)images->fit_hdr_os;
  718. fit_uname_config = images->fit_uname_cfg;
  719. debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
  720. fit_uname_config, rd_addr);
  721. /*
  722. * Check whether configuration has ramdisk defined,
  723. * if not, don't try to use it, quit silently.
  724. */
  725. fit_hdr = (void *)rd_addr;
  726. cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
  727. if (cfg_noffset < 0) {
  728. debug ("* ramdisk: no such config\n");
  729. return 0;
  730. }
  731. rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
  732. if (rd_noffset < 0) {
  733. debug ("* ramdisk: no ramdisk in config\n");
  734. return 0;
  735. }
  736. }
  737. #endif
  738. /* copy from dataflash if needed */
  739. rd_addr = genimg_get_image (rd_addr);
  740. /*
  741. * Check if there is an initrd image at the
  742. * address provided in the second bootm argument
  743. * check image type, for FIT images get FIT node.
  744. */
  745. switch (genimg_get_format ((void *)rd_addr)) {
  746. case IMAGE_FORMAT_LEGACY:
  747. printf ("## Loading init Ramdisk from Legacy "
  748. "Image at %08lx ...\n", rd_addr);
  749. show_boot_progress (9);
  750. rd_hdr = image_get_ramdisk (rd_addr, arch,
  751. images->verify);
  752. if (rd_hdr == NULL)
  753. return 1;
  754. rd_data = image_get_data (rd_hdr);
  755. rd_len = image_get_data_size (rd_hdr);
  756. rd_load = image_get_load (rd_hdr);
  757. break;
  758. #if defined(CONFIG_FIT)
  759. case IMAGE_FORMAT_FIT:
  760. fit_hdr = (void *)rd_addr;
  761. printf ("## Loading init Ramdisk from FIT "
  762. "Image at %08lx ...\n", rd_addr);
  763. show_boot_progress (120);
  764. if (!fit_check_format (fit_hdr)) {
  765. puts ("Bad FIT ramdisk image format!\n");
  766. show_boot_progress (-120);
  767. return 0;
  768. }
  769. show_boot_progress (121);
  770. if (!fit_uname_ramdisk) {
  771. /*
  772. * no ramdisk image node unit name, try to get config
  773. * node first. If config unit node name is NULL
  774. * fit_conf_get_node() will try to find default config node
  775. */
  776. show_boot_progress (122);
  777. cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
  778. if (cfg_noffset < 0) {
  779. puts ("Could not find configuration node\n");
  780. show_boot_progress (-122);
  781. return 0;
  782. }
  783. fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
  784. printf (" Using '%s' configuration\n", fit_uname_config);
  785. rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
  786. fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
  787. } else {
  788. /* get ramdisk component image node offset */
  789. show_boot_progress (123);
  790. rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
  791. }
  792. if (rd_noffset < 0) {
  793. puts ("Could not find subimage node\n");
  794. show_boot_progress (-124);
  795. return 0;
  796. }
  797. printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
  798. show_boot_progress (125);
  799. if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
  800. return 0;
  801. /* get ramdisk image data address and length */
  802. if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
  803. puts ("Could not find ramdisk subimage data!\n");
  804. show_boot_progress (-127);
  805. return 0;
  806. }
  807. show_boot_progress (128);
  808. rd_data = (ulong)data;
  809. rd_len = size;
  810. if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
  811. puts ("Can't get ramdisk subimage load address!\n");
  812. show_boot_progress (-129);
  813. return 0;
  814. }
  815. show_boot_progress (129);
  816. images->fit_hdr_rd = fit_hdr;
  817. images->fit_uname_rd = fit_uname_ramdisk;
  818. images->fit_noffset_rd = rd_noffset;
  819. break;
  820. #endif
  821. default:
  822. puts ("Wrong Ramdisk Image Format\n");
  823. rd_data = rd_len = rd_load = 0;
  824. }
  825. #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
  826. /*
  827. * We need to copy the ramdisk to SRAM to let Linux boot
  828. */
  829. if (rd_data) {
  830. memmove ((void *)rd_load, (uchar *)rd_data, rd_len);
  831. rd_data = rd_load;
  832. }
  833. #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
  834. } else if (images->legacy_hdr_valid &&
  835. image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
  836. /*
  837. * Now check if we have a legacy mult-component image,
  838. * get second entry data start address and len.
  839. */
  840. show_boot_progress (13);
  841. printf ("## Loading init Ramdisk from multi component "
  842. "Legacy Image at %08lx ...\n",
  843. (ulong)images->legacy_hdr_os);
  844. image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
  845. } else {
  846. /*
  847. * no initrd image
  848. */
  849. show_boot_progress (14);
  850. rd_len = rd_data = 0;
  851. }
  852. if (!rd_data) {
  853. debug ("## No init Ramdisk\n");
  854. } else {
  855. *rd_start = rd_data;
  856. *rd_end = rd_data + rd_len;
  857. }
  858. debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
  859. *rd_start, *rd_end);
  860. return 0;
  861. }
  862. #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
  863. /**
  864. * boot_ramdisk_high - relocate init ramdisk
  865. * @lmb: pointer to lmb handle, will be used for memory mgmt
  866. * @rd_data: ramdisk data start address
  867. * @rd_len: ramdisk data length
  868. * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
  869. * start address (after possible relocation)
  870. * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
  871. * end address (after possible relocation)
  872. *
  873. * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
  874. * variable and if requested ramdisk data is moved to a specified location.
  875. *
  876. * Initrd_start and initrd_end are set to final (after relocation) ramdisk
  877. * start/end addresses if ramdisk image start and len were provided,
  878. * otherwise set initrd_start and initrd_end set to zeros.
  879. *
  880. * returns:
  881. * 0 - success
  882. * -1 - failure
  883. */
  884. int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
  885. ulong *initrd_start, ulong *initrd_end)
  886. {
  887. char *s;
  888. ulong initrd_high;
  889. int initrd_copy_to_ram = 1;
  890. if ((s = getenv ("initrd_high")) != NULL) {
  891. /* a value of "no" or a similar string will act like 0,
  892. * turning the "load high" feature off. This is intentional.
  893. */
  894. initrd_high = simple_strtoul (s, NULL, 16);
  895. if (initrd_high == ~0)
  896. initrd_copy_to_ram = 0;
  897. } else {
  898. /* not set, no restrictions to load high */
  899. initrd_high = ~0;
  900. }
  901. #ifdef CONFIG_LOGBUFFER
  902. /* Prevent initrd from overwriting logbuffer */
  903. lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
  904. #endif
  905. debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
  906. initrd_high, initrd_copy_to_ram);
  907. if (rd_data) {
  908. if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
  909. debug (" in-place initrd\n");
  910. *initrd_start = rd_data;
  911. *initrd_end = rd_data + rd_len;
  912. lmb_reserve(lmb, rd_data, rd_len);
  913. } else {
  914. if (initrd_high)
  915. *initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
  916. else
  917. *initrd_start = lmb_alloc (lmb, rd_len, 0x1000);
  918. if (*initrd_start == 0) {
  919. puts ("ramdisk - allocation error\n");
  920. goto error;
  921. }
  922. show_boot_progress (12);
  923. *initrd_end = *initrd_start + rd_len;
  924. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  925. *initrd_start, *initrd_end);
  926. memmove_wd ((void *)*initrd_start,
  927. (void *)rd_data, rd_len, CHUNKSZ);
  928. puts ("OK\n");
  929. }
  930. } else {
  931. *initrd_start = 0;
  932. *initrd_end = 0;
  933. }
  934. debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
  935. *initrd_start, *initrd_end);
  936. return 0;
  937. error:
  938. return -1;
  939. }
  940. /**
  941. * boot_get_cmdline - allocate and initialize kernel cmdline
  942. * @lmb: pointer to lmb handle, will be used for memory mgmt
  943. * @cmd_start: pointer to a ulong variable, will hold cmdline start
  944. * @cmd_end: pointer to a ulong variable, will hold cmdline end
  945. * @bootmap_base: ulong variable, holds offset in physical memory to
  946. * base of bootmap
  947. *
  948. * boot_get_cmdline() allocates space for kernel command line below
  949. * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
  950. * variable is present its contents is copied to allocated kernel
  951. * command line.
  952. *
  953. * returns:
  954. * 0 - success
  955. * -1 - failure
  956. */
  957. int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
  958. ulong bootmap_base)
  959. {
  960. char *cmdline;
  961. char *s;
  962. cmdline = (char *)lmb_alloc_base(lmb, CFG_BARGSIZE, 0xf,
  963. CFG_BOOTMAPSZ + bootmap_base);
  964. if (cmdline == NULL)
  965. return -1;
  966. if ((s = getenv("bootargs")) == NULL)
  967. s = "";
  968. strcpy(cmdline, s);
  969. *cmd_start = (ulong) & cmdline[0];
  970. *cmd_end = *cmd_start + strlen(cmdline);
  971. debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
  972. return 0;
  973. }
  974. /**
  975. * boot_get_kbd - allocate and initialize kernel copy of board info
  976. * @lmb: pointer to lmb handle, will be used for memory mgmt
  977. * @kbd: double pointer to board info data
  978. * @bootmap_base: ulong variable, holds offset in physical memory to
  979. * base of bootmap
  980. *
  981. * boot_get_kbd() allocates space for kernel copy of board info data below
  982. * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
  983. * the current u-boot board info data.
  984. *
  985. * returns:
  986. * 0 - success
  987. * -1 - failure
  988. */
  989. int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
  990. {
  991. *kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
  992. CFG_BOOTMAPSZ + bootmap_base);
  993. if (*kbd == NULL)
  994. return -1;
  995. **kbd = *(gd->bd);
  996. debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
  997. #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
  998. do_bdinfo(NULL, 0, 0, NULL);
  999. #endif
  1000. return 0;
  1001. }
  1002. #endif /* CONFIG_PPC || CONFIG_M68K */
  1003. #endif /* !USE_HOSTCC */
  1004. #if defined(CONFIG_FIT)
  1005. /*****************************************************************************/
  1006. /* New uImage format routines */
  1007. /*****************************************************************************/
  1008. #ifndef USE_HOSTCC
  1009. static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
  1010. ulong *addr, const char **name)
  1011. {
  1012. const char *sep;
  1013. *addr = addr_curr;
  1014. *name = NULL;
  1015. sep = strchr (spec, sepc);
  1016. if (sep) {
  1017. if (sep - spec > 0)
  1018. *addr = simple_strtoul (spec, NULL, 16);
  1019. *name = sep + 1;
  1020. return 1;
  1021. }
  1022. return 0;
  1023. }
  1024. /**
  1025. * fit_parse_conf - parse FIT configuration spec
  1026. * @spec: input string, containing configuration spec
  1027. * @add_curr: current image address (to be used as a possible default)
  1028. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1029. * configuration
  1030. * @conf_name double pointer to a char, will hold pointer to a configuration
  1031. * unit name
  1032. *
  1033. * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
  1034. * where <addr> is a FIT image address that contains configuration
  1035. * with a <conf> unit name.
  1036. *
  1037. * Address part is optional, and if omitted default add_curr will
  1038. * be used instead.
  1039. *
  1040. * returns:
  1041. * 1 if spec is a valid configuration string,
  1042. * addr and conf_name are set accordingly
  1043. * 0 otherwise
  1044. */
  1045. inline int fit_parse_conf (const char *spec, ulong addr_curr,
  1046. ulong *addr, const char **conf_name)
  1047. {
  1048. return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
  1049. }
  1050. /**
  1051. * fit_parse_subimage - parse FIT subimage spec
  1052. * @spec: input string, containing subimage spec
  1053. * @add_curr: current image address (to be used as a possible default)
  1054. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1055. * subimage
  1056. * @image_name: double pointer to a char, will hold pointer to a subimage name
  1057. *
  1058. * fit_parse_subimage() expects subimage spec in the for of
  1059. * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
  1060. * subimage with a <subimg> unit name.
  1061. *
  1062. * Address part is optional, and if omitted default add_curr will
  1063. * be used instead.
  1064. *
  1065. * returns:
  1066. * 1 if spec is a valid subimage string,
  1067. * addr and image_name are set accordingly
  1068. * 0 otherwise
  1069. */
  1070. inline int fit_parse_subimage (const char *spec, ulong addr_curr,
  1071. ulong *addr, const char **image_name)
  1072. {
  1073. return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
  1074. }
  1075. #endif /* !USE_HOSTCC */
  1076. static void fit_get_debug (const void *fit, int noffset,
  1077. char *prop_name, int err)
  1078. {
  1079. debug ("Can't get '%s' property from FIT 0x%08lx, "
  1080. "node: offset %d, name %s (%s)\n",
  1081. prop_name, (ulong)fit, noffset,
  1082. fit_get_name (fit, noffset, NULL),
  1083. fdt_strerror (err));
  1084. }
  1085. /**
  1086. * fit_print_contents - prints out the contents of the FIT format image
  1087. * @fit: pointer to the FIT format image header
  1088. * @p: pointer to prefix string
  1089. *
  1090. * fit_print_contents() formats a multi line FIT image contents description.
  1091. * The routine prints out FIT image properties (root node level) follwed by
  1092. * the details of each component image.
  1093. *
  1094. * returns:
  1095. * no returned results
  1096. */
  1097. void fit_print_contents (const void *fit)
  1098. {
  1099. char *desc;
  1100. char *uname;
  1101. int images_noffset;
  1102. int confs_noffset;
  1103. int noffset;
  1104. int ndepth;
  1105. int count = 0;
  1106. int ret;
  1107. const char *p;
  1108. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1109. time_t timestamp;
  1110. #endif
  1111. #ifdef USE_HOSTCC
  1112. p = "";
  1113. #else
  1114. p = " ";
  1115. #endif
  1116. /* Root node properties */
  1117. ret = fit_get_desc (fit, 0, &desc);
  1118. printf ("%sFIT description: ", p);
  1119. if (ret)
  1120. printf ("unavailable\n");
  1121. else
  1122. printf ("%s\n", desc);
  1123. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1124. ret = fit_get_timestamp (fit, 0, &timestamp);
  1125. printf ("%sCreated: ", p);
  1126. if (ret)
  1127. printf ("unavailable\n");
  1128. else
  1129. genimg_print_time (timestamp);
  1130. #endif
  1131. /* Find images parent node offset */
  1132. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1133. if (images_noffset < 0) {
  1134. printf ("Can't find images parent node '%s' (%s)\n",
  1135. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1136. return;
  1137. }
  1138. /* Process its subnodes, print out component images details */
  1139. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
  1140. (noffset >= 0) && (ndepth > 0);
  1141. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1142. if (ndepth == 1) {
  1143. /*
  1144. * Direct child node of the images parent node,
  1145. * i.e. component image node.
  1146. */
  1147. printf ("%s Image %u (%s)\n", p, count++,
  1148. fit_get_name(fit, noffset, NULL));
  1149. fit_image_print (fit, noffset, p);
  1150. }
  1151. }
  1152. /* Find configurations parent node offset */
  1153. confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
  1154. if (confs_noffset < 0) {
  1155. debug ("Can't get configurations parent node '%s' (%s)\n",
  1156. FIT_CONFS_PATH, fdt_strerror (confs_noffset));
  1157. return;
  1158. }
  1159. /* get default configuration unit name from default property */
  1160. uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
  1161. if (uname)
  1162. printf ("%s Default Configuration: '%s'\n", p, uname);
  1163. /* Process its subnodes, print out configurations details */
  1164. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
  1165. (noffset >= 0) && (ndepth > 0);
  1166. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1167. if (ndepth == 1) {
  1168. /*
  1169. * Direct child node of the configurations parent node,
  1170. * i.e. configuration node.
  1171. */
  1172. printf ("%s Configuration %u (%s)\n", p, count++,
  1173. fit_get_name(fit, noffset, NULL));
  1174. fit_conf_print (fit, noffset, p);
  1175. }
  1176. }
  1177. }
  1178. /**
  1179. * fit_image_print - prints out the FIT component image details
  1180. * @fit: pointer to the FIT format image header
  1181. * @image_noffset: offset of the component image node
  1182. * @p: pointer to prefix string
  1183. *
  1184. * fit_image_print() lists all mandatory properies for the processed component
  1185. * image. If present, hash nodes are printed out as well.
  1186. *
  1187. * returns:
  1188. * no returned results
  1189. */
  1190. void fit_image_print (const void *fit, int image_noffset, const char *p)
  1191. {
  1192. char *desc;
  1193. uint8_t type, arch, os, comp;
  1194. size_t size;
  1195. ulong load, entry;
  1196. const void *data;
  1197. int noffset;
  1198. int ndepth;
  1199. int ret;
  1200. /* Mandatory properties */
  1201. ret = fit_get_desc (fit, image_noffset, &desc);
  1202. printf ("%s Description: ", p);
  1203. if (ret)
  1204. printf ("unavailable\n");
  1205. else
  1206. printf ("%s\n", desc);
  1207. fit_image_get_type (fit, image_noffset, &type);
  1208. printf ("%s Type: %s\n", p, genimg_get_type_name (type));
  1209. fit_image_get_comp (fit, image_noffset, &comp);
  1210. printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
  1211. ret = fit_image_get_data (fit, image_noffset, &data, &size);
  1212. #ifndef USE_HOSTCC
  1213. printf ("%s Data Start: ", p);
  1214. if (ret)
  1215. printf ("unavailable\n");
  1216. else
  1217. printf ("0x%08lx\n", (ulong)data);
  1218. #endif
  1219. printf ("%s Data Size: ", p);
  1220. if (ret)
  1221. printf ("unavailable\n");
  1222. else
  1223. genimg_print_size (size);
  1224. /* Remaining, type dependent properties */
  1225. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
  1226. (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
  1227. (type == IH_TYPE_FLATDT)) {
  1228. fit_image_get_arch (fit, image_noffset, &arch);
  1229. printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
  1230. }
  1231. if (type == IH_TYPE_KERNEL) {
  1232. fit_image_get_os (fit, image_noffset, &os);
  1233. printf ("%s OS: %s\n", p, genimg_get_os_name (os));
  1234. }
  1235. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
  1236. ret = fit_image_get_load (fit, image_noffset, &load);
  1237. printf ("%s Load Address: ", p);
  1238. if (ret)
  1239. printf ("unavailable\n");
  1240. else
  1241. printf ("0x%08lx\n", load);
  1242. fit_image_get_entry (fit, image_noffset, &entry);
  1243. printf ("%s Entry Point: ", p);
  1244. if (ret)
  1245. printf ("unavailable\n");
  1246. else
  1247. printf ("0x%08lx\n", entry);
  1248. }
  1249. /* Process all hash subnodes of the component image node */
  1250. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1251. (noffset >= 0) && (ndepth > 0);
  1252. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1253. if (ndepth == 1) {
  1254. /* Direct child node of the component image node */
  1255. fit_image_print_hash (fit, noffset, p);
  1256. }
  1257. }
  1258. }
  1259. /**
  1260. * fit_image_print_hash - prints out the hash node details
  1261. * @fit: pointer to the FIT format image header
  1262. * @noffset: offset of the hash node
  1263. * @p: pointer to prefix string
  1264. *
  1265. * fit_image_print_hash() lists properies for the processed hash node
  1266. *
  1267. * returns:
  1268. * no returned results
  1269. */
  1270. void fit_image_print_hash (const void *fit, int noffset, const char *p)
  1271. {
  1272. char *algo;
  1273. uint8_t *value;
  1274. int value_len;
  1275. int i, ret;
  1276. /*
  1277. * Check subnode name, must be equal to "hash".
  1278. * Multiple hash nodes require unique unit node
  1279. * names, e.g. hash@1, hash@2, etc.
  1280. */
  1281. if (strncmp (fit_get_name(fit, noffset, NULL),
  1282. FIT_HASH_NODENAME,
  1283. strlen(FIT_HASH_NODENAME)) != 0)
  1284. return;
  1285. debug ("%s Hash node: '%s'\n", p,
  1286. fit_get_name (fit, noffset, NULL));
  1287. printf ("%s Hash algo: ", p);
  1288. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1289. printf ("invalid/unsupported\n");
  1290. return;
  1291. }
  1292. printf ("%s\n", algo);
  1293. ret = fit_image_hash_get_value (fit, noffset, &value,
  1294. &value_len);
  1295. printf ("%s Hash value: ", p);
  1296. if (ret) {
  1297. printf ("unavailable\n");
  1298. } else {
  1299. for (i = 0; i < value_len; i++)
  1300. printf ("%02x", value[i]);
  1301. printf ("\n");
  1302. }
  1303. debug ("%s Hash len: %d\n", p, value_len);
  1304. }
  1305. /**
  1306. * fit_get_desc - get node description property
  1307. * @fit: pointer to the FIT format image header
  1308. * @noffset: node offset
  1309. * @desc: double pointer to the char, will hold pointer to the descrption
  1310. *
  1311. * fit_get_desc() reads description property from a given node, if
  1312. * description is found pointer to it is returened in third call argument.
  1313. *
  1314. * returns:
  1315. * 0, on success
  1316. * -1, on failure
  1317. */
  1318. int fit_get_desc (const void *fit, int noffset, char **desc)
  1319. {
  1320. int len;
  1321. *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
  1322. if (*desc == NULL) {
  1323. fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
  1324. return -1;
  1325. }
  1326. return 0;
  1327. }
  1328. /**
  1329. * fit_get_timestamp - get node timestamp property
  1330. * @fit: pointer to the FIT format image header
  1331. * @noffset: node offset
  1332. * @timestamp: pointer to the time_t, will hold read timestamp
  1333. *
  1334. * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
  1335. * is found and has a correct size its value is retured in third call
  1336. * argument.
  1337. *
  1338. * returns:
  1339. * 0, on success
  1340. * -1, on property read failure
  1341. * -2, on wrong timestamp size
  1342. */
  1343. int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
  1344. {
  1345. int len;
  1346. const void *data;
  1347. data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
  1348. if (data == NULL) {
  1349. fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
  1350. return -1;
  1351. }
  1352. if (len != sizeof (uint32_t)) {
  1353. debug ("FIT timestamp with incorrect size of (%u)\n", len);
  1354. return -2;
  1355. }
  1356. *timestamp = uimage_to_cpu (*((uint32_t *)data));
  1357. return 0;
  1358. }
  1359. /**
  1360. * fit_image_get_node - get node offset for component image of a given unit name
  1361. * @fit: pointer to the FIT format image header
  1362. * @image_uname: component image node unit name
  1363. *
  1364. * fit_image_get_node() finds a component image (withing the '/images'
  1365. * node) of a provided unit name. If image is found its node offset is
  1366. * returned to the caller.
  1367. *
  1368. * returns:
  1369. * image node offset when found (>=0)
  1370. * negative number on failure (FDT_ERR_* code)
  1371. */
  1372. int fit_image_get_node (const void *fit, const char *image_uname)
  1373. {
  1374. int noffset, images_noffset;
  1375. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1376. if (images_noffset < 0) {
  1377. debug ("Can't find images parent node '%s' (%s)\n",
  1378. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1379. return images_noffset;
  1380. }
  1381. noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
  1382. if (noffset < 0) {
  1383. debug ("Can't get node offset for image unit name: '%s' (%s)\n",
  1384. image_uname, fdt_strerror (noffset));
  1385. }
  1386. return noffset;
  1387. }
  1388. /**
  1389. * fit_image_get_os - get os id for a given component image node
  1390. * @fit: pointer to the FIT format image header
  1391. * @noffset: component image node offset
  1392. * @os: pointer to the uint8_t, will hold os numeric id
  1393. *
  1394. * fit_image_get_os() finds os property in a given component image node.
  1395. * If the property is found, its (string) value is translated to the numeric
  1396. * id which is returned to the caller.
  1397. *
  1398. * returns:
  1399. * 0, on success
  1400. * -1, on failure
  1401. */
  1402. int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
  1403. {
  1404. int len;
  1405. const void *data;
  1406. /* Get OS name from property data */
  1407. data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
  1408. if (data == NULL) {
  1409. fit_get_debug (fit, noffset, FIT_OS_PROP, len);
  1410. *os = -1;
  1411. return -1;
  1412. }
  1413. /* Translate OS name to id */
  1414. *os = genimg_get_os_id (data);
  1415. return 0;
  1416. }
  1417. /**
  1418. * fit_image_get_arch - get arch id for a given component image node
  1419. * @fit: pointer to the FIT format image header
  1420. * @noffset: component image node offset
  1421. * @arch: pointer to the uint8_t, will hold arch numeric id
  1422. *
  1423. * fit_image_get_arch() finds arch property in a given component image node.
  1424. * If the property is found, its (string) value is translated to the numeric
  1425. * id which is returned to the caller.
  1426. *
  1427. * returns:
  1428. * 0, on success
  1429. * -1, on failure
  1430. */
  1431. int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
  1432. {
  1433. int len;
  1434. const void *data;
  1435. /* Get architecture name from property data */
  1436. data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
  1437. if (data == NULL) {
  1438. fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
  1439. *arch = -1;
  1440. return -1;
  1441. }
  1442. /* Translate architecture name to id */
  1443. *arch = genimg_get_arch_id (data);
  1444. return 0;
  1445. }
  1446. /**
  1447. * fit_image_get_type - get type id for a given component image node
  1448. * @fit: pointer to the FIT format image header
  1449. * @noffset: component image node offset
  1450. * @type: pointer to the uint8_t, will hold type numeric id
  1451. *
  1452. * fit_image_get_type() finds type property in a given component image node.
  1453. * If the property is found, its (string) value is translated to the numeric
  1454. * id which is returned to the caller.
  1455. *
  1456. * returns:
  1457. * 0, on success
  1458. * -1, on failure
  1459. */
  1460. int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
  1461. {
  1462. int len;
  1463. const void *data;
  1464. /* Get image type name from property data */
  1465. data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
  1466. if (data == NULL) {
  1467. fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
  1468. *type = -1;
  1469. return -1;
  1470. }
  1471. /* Translate image type name to id */
  1472. *type = genimg_get_type_id (data);
  1473. return 0;
  1474. }
  1475. /**
  1476. * fit_image_get_comp - get comp id for a given component image node
  1477. * @fit: pointer to the FIT format image header
  1478. * @noffset: component image node offset
  1479. * @comp: pointer to the uint8_t, will hold comp numeric id
  1480. *
  1481. * fit_image_get_comp() finds comp property in a given component image node.
  1482. * If the property is found, its (string) value is translated to the numeric
  1483. * id which is returned to the caller.
  1484. *
  1485. * returns:
  1486. * 0, on success
  1487. * -1, on failure
  1488. */
  1489. int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
  1490. {
  1491. int len;
  1492. const void *data;
  1493. /* Get compression name from property data */
  1494. data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
  1495. if (data == NULL) {
  1496. fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
  1497. *comp = -1;
  1498. return -1;
  1499. }
  1500. /* Translate compression name to id */
  1501. *comp = genimg_get_comp_id (data);
  1502. return 0;
  1503. }
  1504. /**
  1505. * fit_image_get_load - get load address property for a given component image node
  1506. * @fit: pointer to the FIT format image header
  1507. * @noffset: component image node offset
  1508. * @load: pointer to the uint32_t, will hold load address
  1509. *
  1510. * fit_image_get_load() finds load address property in a given component image node.
  1511. * If the property is found, its value is returned to the caller.
  1512. *
  1513. * returns:
  1514. * 0, on success
  1515. * -1, on failure
  1516. */
  1517. int fit_image_get_load (const void *fit, int noffset, ulong *load)
  1518. {
  1519. int len;
  1520. const uint32_t *data;
  1521. data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
  1522. if (data == NULL) {
  1523. fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
  1524. return -1;
  1525. }
  1526. *load = uimage_to_cpu (*data);
  1527. return 0;
  1528. }
  1529. /**
  1530. * fit_image_get_entry - get entry point address property for a given component image node
  1531. * @fit: pointer to the FIT format image header
  1532. * @noffset: component image node offset
  1533. * @entry: pointer to the uint32_t, will hold entry point address
  1534. *
  1535. * fit_image_get_entry() finds entry point address property in a given component image node.
  1536. * If the property is found, its value is returned to the caller.
  1537. *
  1538. * returns:
  1539. * 0, on success
  1540. * -1, on failure
  1541. */
  1542. int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
  1543. {
  1544. int len;
  1545. const uint32_t *data;
  1546. data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
  1547. if (data == NULL) {
  1548. fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
  1549. return -1;
  1550. }
  1551. *entry = uimage_to_cpu (*data);
  1552. return 0;
  1553. }
  1554. /**
  1555. * fit_image_get_data - get data property and its size for a given component image node
  1556. * @fit: pointer to the FIT format image header
  1557. * @noffset: component image node offset
  1558. * @data: double pointer to void, will hold data property's data address
  1559. * @size: pointer to size_t, will hold data property's data size
  1560. *
  1561. * fit_image_get_data() finds data property in a given component image node.
  1562. * If the property is found its data start address and size are returned to
  1563. * the caller.
  1564. *
  1565. * returns:
  1566. * 0, on success
  1567. * -1, on failure
  1568. */
  1569. int fit_image_get_data (const void *fit, int noffset,
  1570. const void **data, size_t *size)
  1571. {
  1572. int len;
  1573. *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
  1574. if (*data == NULL) {
  1575. fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
  1576. *size = 0;
  1577. return -1;
  1578. }
  1579. *size = len;
  1580. return 0;
  1581. }
  1582. /**
  1583. * fit_image_hash_get_algo - get hash algorithm name
  1584. * @fit: pointer to the FIT format image header
  1585. * @noffset: hash node offset
  1586. * @algo: double pointer to char, will hold pointer to the algorithm name
  1587. *
  1588. * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
  1589. * If the property is found its data start address is returned to the caller.
  1590. *
  1591. * returns:
  1592. * 0, on success
  1593. * -1, on failure
  1594. */
  1595. int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
  1596. {
  1597. int len;
  1598. *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
  1599. if (*algo == NULL) {
  1600. fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
  1601. return -1;
  1602. }
  1603. return 0;
  1604. }
  1605. /**
  1606. * fit_image_hash_get_value - get hash value and length
  1607. * @fit: pointer to the FIT format image header
  1608. * @noffset: hash node offset
  1609. * @value: double pointer to uint8_t, will hold address of a hash value data
  1610. * @value_len: pointer to an int, will hold hash data length
  1611. *
  1612. * fit_image_hash_get_value() finds hash value property in a given hash node.
  1613. * If the property is found its data start address and size are returned to
  1614. * the caller.
  1615. *
  1616. * returns:
  1617. * 0, on success
  1618. * -1, on failure
  1619. */
  1620. int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
  1621. int *value_len)
  1622. {
  1623. int len;
  1624. *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
  1625. if (*value == NULL) {
  1626. fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
  1627. *value_len = 0;
  1628. return -1;
  1629. }
  1630. *value_len = len;
  1631. return 0;
  1632. }
  1633. /**
  1634. * fit_set_timestamp - set node timestamp property
  1635. * @fit: pointer to the FIT format image header
  1636. * @noffset: node offset
  1637. * @timestamp: timestamp value to be set
  1638. *
  1639. * fit_set_timestamp() attempts to set timestamp property in the requested
  1640. * node and returns operation status to the caller.
  1641. *
  1642. * returns:
  1643. * 0, on success
  1644. * -1, on property read failure
  1645. */
  1646. int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
  1647. {
  1648. uint32_t t;
  1649. int ret;
  1650. t = cpu_to_uimage (timestamp);
  1651. ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
  1652. sizeof (uint32_t));
  1653. if (ret) {
  1654. printf ("Can't set '%s' property for '%s' node (%s)\n",
  1655. FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
  1656. fdt_strerror (ret));
  1657. return -1;
  1658. }
  1659. return 0;
  1660. }
  1661. /**
  1662. * calculate_hash - calculate and return hash for provided input data
  1663. * @data: pointer to the input data
  1664. * @data_len: data length
  1665. * @algo: requested hash algorithm
  1666. * @value: pointer to the char, will hold hash value data (caller must
  1667. * allocate enough free space)
  1668. * value_len: length of the calculated hash
  1669. *
  1670. * calculate_hash() computes input data hash according to the requested algorithm.
  1671. * Resulting hash value is placed in caller provided 'value' buffer, length
  1672. * of the calculated hash is returned via value_len pointer argument.
  1673. *
  1674. * returns:
  1675. * 0, on success
  1676. * -1, when algo is unsupported
  1677. */
  1678. static int calculate_hash (const void *data, int data_len, const char *algo,
  1679. uint8_t *value, int *value_len)
  1680. {
  1681. if (strcmp (algo, "crc32") == 0 ) {
  1682. *((uint32_t *)value) = crc32_wd (0, data, data_len,
  1683. CHUNKSZ_CRC32);
  1684. *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
  1685. *value_len = 4;
  1686. } else if (strcmp (algo, "sha1") == 0 ) {
  1687. sha1_csum_wd ((unsigned char *) data, data_len,
  1688. (unsigned char *) value, CHUNKSZ_SHA1);
  1689. *value_len = 20;
  1690. } else if (strcmp (algo, "md5") == 0 ) {
  1691. md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
  1692. *value_len = 16;
  1693. } else {
  1694. debug ("Unsupported hash alogrithm\n");
  1695. return -1;
  1696. }
  1697. return 0;
  1698. }
  1699. #ifdef USE_HOSTCC
  1700. /**
  1701. * fit_set_hashes - process FIT component image nodes and calculate hashes
  1702. * @fit: pointer to the FIT format image header
  1703. *
  1704. * fit_set_hashes() adds hash values for all component images in the FIT blob.
  1705. * Hashes are calculated for all component images which have hash subnodes
  1706. * with algorithm property set to one of the supported hash algorithms.
  1707. *
  1708. * returns
  1709. * 0, on success
  1710. * libfdt error code, on failure
  1711. */
  1712. int fit_set_hashes (void *fit)
  1713. {
  1714. int images_noffset;
  1715. int noffset;
  1716. int ndepth;
  1717. int ret;
  1718. /* Find images parent node offset */
  1719. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1720. if (images_noffset < 0) {
  1721. printf ("Can't find images parent node '%s' (%s)\n",
  1722. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1723. return images_noffset;
  1724. }
  1725. /* Process its subnodes, print out component images details */
  1726. for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
  1727. (noffset >= 0) && (ndepth > 0);
  1728. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1729. if (ndepth == 1) {
  1730. /*
  1731. * Direct child node of the images parent node,
  1732. * i.e. component image node.
  1733. */
  1734. ret = fit_image_set_hashes (fit, noffset);
  1735. if (ret)
  1736. return ret;
  1737. }
  1738. }
  1739. return 0;
  1740. }
  1741. /**
  1742. * fit_image_set_hashes - calculate/set hashes for given component image node
  1743. * @fit: pointer to the FIT format image header
  1744. * @image_noffset: requested component image node
  1745. *
  1746. * fit_image_set_hashes() adds hash values for an component image node. All
  1747. * existing hash subnodes are checked, if algorithm property is set to one of
  1748. * the supported hash algorithms, hash value is computed and corresponding
  1749. * hash node property is set, for example:
  1750. *
  1751. * Input component image node structure:
  1752. *
  1753. * o image@1 (at image_noffset)
  1754. * | - data = [binary data]
  1755. * o hash@1
  1756. * |- algo = "sha1"
  1757. *
  1758. * Output component image node structure:
  1759. *
  1760. * o image@1 (at image_noffset)
  1761. * | - data = [binary data]
  1762. * o hash@1
  1763. * |- algo = "sha1"
  1764. * |- value = sha1(data)
  1765. *
  1766. * returns:
  1767. * 0 on sucess
  1768. * <0 on failure
  1769. */
  1770. int fit_image_set_hashes (void *fit, int image_noffset)
  1771. {
  1772. const void *data;
  1773. size_t size;
  1774. char *algo;
  1775. uint8_t value[FIT_MAX_HASH_LEN];
  1776. int value_len;
  1777. int noffset;
  1778. int ndepth;
  1779. /* Get image data and data length */
  1780. if (fit_image_get_data (fit, image_noffset, &data, &size)) {
  1781. printf ("Can't get image data/size\n");
  1782. return -1;
  1783. }
  1784. /* Process all hash subnodes of the component image node */
  1785. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1786. (noffset >= 0) && (ndepth > 0);
  1787. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1788. if (ndepth == 1) {
  1789. /* Direct child node of the component image node */
  1790. /*
  1791. * Check subnode name, must be equal to "hash".
  1792. * Multiple hash nodes require unique unit node
  1793. * names, e.g. hash@1, hash@2, etc.
  1794. */
  1795. if (strncmp (fit_get_name(fit, noffset, NULL),
  1796. FIT_HASH_NODENAME,
  1797. strlen(FIT_HASH_NODENAME)) != 0) {
  1798. /* Not a hash subnode, skip it */
  1799. continue;
  1800. }
  1801. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1802. printf ("Can't get hash algo property for "
  1803. "'%s' hash node in '%s' image node\n",
  1804. fit_get_name (fit, noffset, NULL),
  1805. fit_get_name (fit, image_noffset, NULL));
  1806. return -1;
  1807. }
  1808. if (calculate_hash (data, size, algo, value, &value_len)) {
  1809. printf ("Unsupported hash algorithm (%s) for "
  1810. "'%s' hash node in '%s' image node\n",
  1811. algo, fit_get_name (fit, noffset, NULL),
  1812. fit_get_name (fit, image_noffset, NULL));
  1813. return -1;
  1814. }
  1815. if (fit_image_hash_set_value (fit, noffset, value,
  1816. value_len)) {
  1817. printf ("Can't set hash value for "
  1818. "'%s' hash node in '%s' image node\n",
  1819. fit_get_name (fit, noffset, NULL),
  1820. fit_get_name (fit, image_noffset, NULL));
  1821. return -1;
  1822. }
  1823. }
  1824. }
  1825. return 0;
  1826. }
  1827. /**
  1828. * fit_image_hash_set_value - set hash value in requested has node
  1829. * @fit: pointer to the FIT format image header
  1830. * @noffset: hash node offset
  1831. * @value: hash value to be set
  1832. * @value_len: hash value length
  1833. *
  1834. * fit_image_hash_set_value() attempts to set hash value in a node at offset
  1835. * given and returns operation status to the caller.
  1836. *
  1837. * returns
  1838. * 0, on success
  1839. * -1, on failure
  1840. */
  1841. int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
  1842. int value_len)
  1843. {
  1844. int ret;
  1845. ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
  1846. if (ret) {
  1847. printf ("Can't set hash '%s' property for '%s' node (%s)\n",
  1848. FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
  1849. fdt_strerror (ret));
  1850. return -1;
  1851. }
  1852. return 0;
  1853. }
  1854. #endif /* USE_HOSTCC */
  1855. /**
  1856. * fit_image_check_hashes - verify data intergity
  1857. * @fit: pointer to the FIT format image header
  1858. * @image_noffset: component image node offset
  1859. *
  1860. * fit_image_check_hashes() goes over component image hash nodes,
  1861. * re-calculates each data hash and compares with the value stored in hash
  1862. * node.
  1863. *
  1864. * returns:
  1865. * 1, if all hashes are valid
  1866. * 0, otherwise (or on error)
  1867. */
  1868. int fit_image_check_hashes (const void *fit, int image_noffset)
  1869. {
  1870. const void *data;
  1871. size_t size;
  1872. char *algo;
  1873. uint8_t *fit_value;
  1874. int fit_value_len;
  1875. uint8_t value[FIT_MAX_HASH_LEN];
  1876. int value_len;
  1877. int noffset;
  1878. int ndepth;
  1879. char *err_msg = "";
  1880. /* Get image data and data length */
  1881. if (fit_image_get_data (fit, image_noffset, &data, &size)) {
  1882. printf ("Can't get image data/size\n");
  1883. return 0;
  1884. }
  1885. /* Process all hash subnodes of the component image node */
  1886. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1887. (noffset >= 0) && (ndepth > 0);
  1888. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1889. if (ndepth == 1) {
  1890. /* Direct child node of the component image node */
  1891. /*
  1892. * Check subnode name, must be equal to "hash".
  1893. * Multiple hash nodes require unique unit node
  1894. * names, e.g. hash@1, hash@2, etc.
  1895. */
  1896. if (strncmp (fit_get_name(fit, noffset, NULL),
  1897. FIT_HASH_NODENAME,
  1898. strlen(FIT_HASH_NODENAME)) != 0)
  1899. continue;
  1900. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1901. err_msg = "Can't get hash algo property";
  1902. goto error;
  1903. }
  1904. printf ("%s", algo);
  1905. if (fit_image_hash_get_value (fit, noffset, &fit_value,
  1906. &fit_value_len)) {
  1907. err_msg = "Can't get hash value property";
  1908. goto error;
  1909. }
  1910. if (calculate_hash (data, size, algo, value, &value_len)) {
  1911. err_msg = "Unsupported hash algorithm";
  1912. goto error;
  1913. }
  1914. if (value_len != fit_value_len) {
  1915. err_msg = "Bad hash value len";
  1916. goto error;
  1917. } else if (memcmp (value, fit_value, value_len) != 0) {
  1918. err_msg = "Bad hash value";
  1919. goto error;
  1920. }
  1921. printf ("+ ");
  1922. }
  1923. }
  1924. return 1;
  1925. error:
  1926. printf ("%s for '%s' hash node in '%s' image node\n",
  1927. err_msg, fit_get_name (fit, noffset, NULL),
  1928. fit_get_name (fit, image_noffset, NULL));
  1929. return 0;
  1930. }
  1931. /**
  1932. * fit_image_check_os - check whether image node is of a given os type
  1933. * @fit: pointer to the FIT format image header
  1934. * @noffset: component image node offset
  1935. * @os: requested image os
  1936. *
  1937. * fit_image_check_os() reads image os property and compares its numeric
  1938. * id with the requested os. Comparison result is returned to the caller.
  1939. *
  1940. * returns:
  1941. * 1 if image is of given os type
  1942. * 0 otherwise (or on error)
  1943. */
  1944. int fit_image_check_os (const void *fit, int noffset, uint8_t os)
  1945. {
  1946. uint8_t image_os;
  1947. if (fit_image_get_os (fit, noffset, &image_os))
  1948. return 0;
  1949. return (os == image_os);
  1950. }
  1951. /**
  1952. * fit_image_check_arch - check whether image node is of a given arch
  1953. * @fit: pointer to the FIT format image header
  1954. * @noffset: component image node offset
  1955. * @arch: requested imagearch
  1956. *
  1957. * fit_image_check_arch() reads image arch property and compares its numeric
  1958. * id with the requested arch. Comparison result is returned to the caller.
  1959. *
  1960. * returns:
  1961. * 1 if image is of given arch
  1962. * 0 otherwise (or on error)
  1963. */
  1964. int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
  1965. {
  1966. uint8_t image_arch;
  1967. if (fit_image_get_arch (fit, noffset, &image_arch))
  1968. return 0;
  1969. return (arch == image_arch);
  1970. }
  1971. /**
  1972. * fit_image_check_type - check whether image node is of a given type
  1973. * @fit: pointer to the FIT format image header
  1974. * @noffset: component image node offset
  1975. * @type: requested image type
  1976. *
  1977. * fit_image_check_type() reads image type property and compares its numeric
  1978. * id with the requested type. Comparison result is returned to the caller.
  1979. *
  1980. * returns:
  1981. * 1 if image is of given type
  1982. * 0 otherwise (or on error)
  1983. */
  1984. int fit_image_check_type (const void *fit, int noffset, uint8_t type)
  1985. {
  1986. uint8_t image_type;
  1987. if (fit_image_get_type (fit, noffset, &image_type))
  1988. return 0;
  1989. return (type == image_type);
  1990. }
  1991. /**
  1992. * fit_image_check_comp - check whether image node uses given compression
  1993. * @fit: pointer to the FIT format image header
  1994. * @noffset: component image node offset
  1995. * @comp: requested image compression type
  1996. *
  1997. * fit_image_check_comp() reads image compression property and compares its
  1998. * numeric id with the requested compression type. Comparison result is
  1999. * returned to the caller.
  2000. *
  2001. * returns:
  2002. * 1 if image uses requested compression
  2003. * 0 otherwise (or on error)
  2004. */
  2005. int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
  2006. {
  2007. uint8_t image_comp;
  2008. if (fit_image_get_comp (fit, noffset, &image_comp))
  2009. return 0;
  2010. return (comp == image_comp);
  2011. }
  2012. /**
  2013. * fit_check_format - sanity check FIT image format
  2014. * @fit: pointer to the FIT format image header
  2015. *
  2016. * fit_check_format() runs a basic sanity FIT image verification.
  2017. * Routine checks for mandatory properties, nodes, etc.
  2018. *
  2019. * returns:
  2020. * 1, on success
  2021. * 0, on failure
  2022. */
  2023. int fit_check_format (const void *fit)
  2024. {
  2025. /* mandatory / node 'description' property */
  2026. if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
  2027. debug ("Wrong FIT format: no description\n");
  2028. return 0;
  2029. }
  2030. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  2031. /* mandatory / node 'timestamp' property */
  2032. if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
  2033. debug ("Wrong FIT format: no description\n");
  2034. return 0;
  2035. }
  2036. #endif
  2037. /* mandatory subimages parent '/images' node */
  2038. if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
  2039. debug ("Wrong FIT format: no images parent node\n");
  2040. return 0;
  2041. }
  2042. return 1;
  2043. }
  2044. /**
  2045. * fit_conf_get_node - get node offset for configuration of a given unit name
  2046. * @fit: pointer to the FIT format image header
  2047. * @conf_uname: configuration node unit name
  2048. *
  2049. * fit_conf_get_node() finds a configuration (withing the '/configurations'
  2050. * parant node) of a provided unit name. If configuration is found its node offset
  2051. * is returned to the caller.
  2052. *
  2053. * When NULL is provided in second argument fit_conf_get_node() will search
  2054. * for a default configuration node instead. Default configuration node unit name
  2055. * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
  2056. *
  2057. * returns:
  2058. * configuration node offset when found (>=0)
  2059. * negative number on failure (FDT_ERR_* code)
  2060. */
  2061. int fit_conf_get_node (const void *fit, const char *conf_uname)
  2062. {
  2063. int noffset, confs_noffset;
  2064. int len;
  2065. confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
  2066. if (confs_noffset < 0) {
  2067. debug ("Can't find configurations parent node '%s' (%s)\n",
  2068. FIT_CONFS_PATH, fdt_strerror (confs_noffset));
  2069. return confs_noffset;
  2070. }
  2071. if (conf_uname == NULL) {
  2072. /* get configuration unit name from the default property */
  2073. debug ("No configuration specified, trying default...\n");
  2074. conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
  2075. if (conf_uname == NULL) {
  2076. fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
  2077. return len;
  2078. }
  2079. debug ("Found default configuration: '%s'\n", conf_uname);
  2080. }
  2081. noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
  2082. if (noffset < 0) {
  2083. debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
  2084. conf_uname, fdt_strerror (noffset));
  2085. }
  2086. return noffset;
  2087. }
  2088. static int __fit_conf_get_prop_node (const void *fit, int noffset,
  2089. const char *prop_name)
  2090. {
  2091. char *uname;
  2092. int len;
  2093. /* get kernel image unit name from configuration kernel property */
  2094. uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
  2095. if (uname == NULL)
  2096. return len;
  2097. return fit_image_get_node (fit, uname);
  2098. }
  2099. /**
  2100. * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
  2101. * a given configuration
  2102. * @fit: pointer to the FIT format image header
  2103. * @noffset: configuration node offset
  2104. *
  2105. * fit_conf_get_kernel_node() retrives kernel image node unit name from
  2106. * configuration FIT_KERNEL_PROP property and translates it to the node
  2107. * offset.
  2108. *
  2109. * returns:
  2110. * image node offset when found (>=0)
  2111. * negative number on failure (FDT_ERR_* code)
  2112. */
  2113. int fit_conf_get_kernel_node (const void *fit, int noffset)
  2114. {
  2115. return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
  2116. }
  2117. /**
  2118. * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
  2119. * a given configuration
  2120. * @fit: pointer to the FIT format image header
  2121. * @noffset: configuration node offset
  2122. *
  2123. * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
  2124. * configuration FIT_KERNEL_PROP property and translates it to the node
  2125. * offset.
  2126. *
  2127. * returns:
  2128. * image node offset when found (>=0)
  2129. * negative number on failure (FDT_ERR_* code)
  2130. */
  2131. int fit_conf_get_ramdisk_node (const void *fit, int noffset)
  2132. {
  2133. return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
  2134. }
  2135. /**
  2136. * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
  2137. * a given configuration
  2138. * @fit: pointer to the FIT format image header
  2139. * @noffset: configuration node offset
  2140. *
  2141. * fit_conf_get_fdt_node() retrives fdt image node unit name from
  2142. * configuration FIT_KERNEL_PROP property and translates it to the node
  2143. * offset.
  2144. *
  2145. * returns:
  2146. * image node offset when found (>=0)
  2147. * negative number on failure (FDT_ERR_* code)
  2148. */
  2149. int fit_conf_get_fdt_node (const void *fit, int noffset)
  2150. {
  2151. return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
  2152. }
  2153. /**
  2154. * fit_conf_print - prints out the FIT configuration details
  2155. * @fit: pointer to the FIT format image header
  2156. * @noffset: offset of the configuration node
  2157. * @p: pointer to prefix string
  2158. *
  2159. * fit_conf_print() lists all mandatory properies for the processed
  2160. * configuration node.
  2161. *
  2162. * returns:
  2163. * no returned results
  2164. */
  2165. void fit_conf_print (const void *fit, int noffset, const char *p)
  2166. {
  2167. char *desc;
  2168. char *uname;
  2169. int ret;
  2170. /* Mandatory properties */
  2171. ret = fit_get_desc (fit, noffset, &desc);
  2172. printf ("%s Description: ", p);
  2173. if (ret)
  2174. printf ("unavailable\n");
  2175. else
  2176. printf ("%s\n", desc);
  2177. uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
  2178. printf ("%s Kernel: ", p);
  2179. if (uname == NULL)
  2180. printf ("unavailable\n");
  2181. else
  2182. printf ("%s\n", uname);
  2183. /* Optional properties */
  2184. uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
  2185. if (uname)
  2186. printf ("%s Init Ramdisk: %s\n", p, uname);
  2187. uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
  2188. if (uname)
  2189. printf ("%s FDT: %s\n", p, uname);
  2190. }
  2191. /**
  2192. * fit_check_ramdisk - verify FIT format ramdisk subimage
  2193. * @fit_hdr: pointer to the FIT ramdisk header
  2194. * @rd_noffset: ramdisk subimage node offset within FIT image
  2195. * @arch: requested ramdisk image architecture type
  2196. * @verify: data CRC verification flag
  2197. *
  2198. * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
  2199. * specified FIT image.
  2200. *
  2201. * returns:
  2202. * 1, on success
  2203. * 0, on failure
  2204. */
  2205. #ifndef USE_HOSTCC
  2206. static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
  2207. {
  2208. fit_image_print (fit, rd_noffset, " ");
  2209. if (verify) {
  2210. puts (" Verifying Hash Integrity ... ");
  2211. if (!fit_image_check_hashes (fit, rd_noffset)) {
  2212. puts ("Bad Data Hash\n");
  2213. show_boot_progress (-125);
  2214. return 0;
  2215. }
  2216. puts ("OK\n");
  2217. }
  2218. show_boot_progress (126);
  2219. if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
  2220. !fit_image_check_arch (fit, rd_noffset, arch) ||
  2221. !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
  2222. printf ("No Linux %s Ramdisk Image\n",
  2223. genimg_get_arch_name(arch));
  2224. show_boot_progress (-126);
  2225. return 0;
  2226. }
  2227. show_boot_progress (127);
  2228. return 1;
  2229. }
  2230. #endif /* USE_HOSTCC */
  2231. #endif /* CONFIG_FIT */