image.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504
  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. /* Prevent initrd from overwriting logbuffer */
  902. lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
  903. debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
  904. initrd_high, initrd_copy_to_ram);
  905. if (rd_data) {
  906. if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
  907. debug (" in-place initrd\n");
  908. *initrd_start = rd_data;
  909. *initrd_end = rd_data + rd_len;
  910. lmb_reserve(lmb, rd_data, rd_len);
  911. } else {
  912. if (initrd_high)
  913. *initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
  914. else
  915. *initrd_start = lmb_alloc (lmb, rd_len, 0x1000);
  916. if (*initrd_start == 0) {
  917. puts ("ramdisk - allocation error\n");
  918. goto error;
  919. }
  920. show_boot_progress (12);
  921. *initrd_end = *initrd_start + rd_len;
  922. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  923. *initrd_start, *initrd_end);
  924. memmove_wd ((void *)*initrd_start,
  925. (void *)rd_data, rd_len, CHUNKSZ);
  926. puts ("OK\n");
  927. }
  928. } else {
  929. *initrd_start = 0;
  930. *initrd_end = 0;
  931. }
  932. debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
  933. *initrd_start, *initrd_end);
  934. return 0;
  935. error:
  936. return -1;
  937. }
  938. /**
  939. * boot_get_cmdline - allocate and initialize kernel cmdline
  940. * @lmb: pointer to lmb handle, will be used for memory mgmt
  941. * @cmd_start: pointer to a ulong variable, will hold cmdline start
  942. * @cmd_end: pointer to a ulong variable, will hold cmdline end
  943. * @bootmap_base: ulong variable, holds offset in physical memory to
  944. * base of bootmap
  945. *
  946. * boot_get_cmdline() allocates space for kernel command line below
  947. * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
  948. * variable is present its contents is copied to allocated kernel
  949. * command line.
  950. *
  951. * returns:
  952. * 0 - success
  953. * -1 - failure
  954. */
  955. int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
  956. ulong bootmap_base)
  957. {
  958. char *cmdline;
  959. char *s;
  960. cmdline = (char *)lmb_alloc_base(lmb, CFG_BARGSIZE, 0xf,
  961. CFG_BOOTMAPSZ + bootmap_base);
  962. if (cmdline == NULL)
  963. return -1;
  964. if ((s = getenv("bootargs")) == NULL)
  965. s = "";
  966. strcpy(cmdline, s);
  967. *cmd_start = (ulong) & cmdline[0];
  968. *cmd_end = *cmd_start + strlen(cmdline);
  969. debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
  970. return 0;
  971. }
  972. /**
  973. * boot_get_kbd - allocate and initialize kernel copy of board info
  974. * @lmb: pointer to lmb handle, will be used for memory mgmt
  975. * @kbd: double pointer to board info data
  976. * @bootmap_base: ulong variable, holds offset in physical memory to
  977. * base of bootmap
  978. *
  979. * boot_get_kbd() allocates space for kernel copy of board info data below
  980. * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
  981. * the current u-boot board info data.
  982. *
  983. * returns:
  984. * 0 - success
  985. * -1 - failure
  986. */
  987. int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
  988. {
  989. *kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
  990. CFG_BOOTMAPSZ + bootmap_base);
  991. if (*kbd == NULL)
  992. return -1;
  993. **kbd = *(gd->bd);
  994. debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
  995. #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
  996. do_bdinfo(NULL, 0, 0, NULL);
  997. #endif
  998. return 0;
  999. }
  1000. #endif /* CONFIG_PPC || CONFIG_M68K */
  1001. #endif /* !USE_HOSTCC */
  1002. #if defined(CONFIG_FIT)
  1003. /*****************************************************************************/
  1004. /* New uImage format routines */
  1005. /*****************************************************************************/
  1006. #ifndef USE_HOSTCC
  1007. static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
  1008. ulong *addr, const char **name)
  1009. {
  1010. const char *sep;
  1011. *addr = addr_curr;
  1012. *name = NULL;
  1013. sep = strchr (spec, sepc);
  1014. if (sep) {
  1015. if (sep - spec > 0)
  1016. *addr = simple_strtoul (spec, NULL, 16);
  1017. *name = sep + 1;
  1018. return 1;
  1019. }
  1020. return 0;
  1021. }
  1022. /**
  1023. * fit_parse_conf - parse FIT configuration spec
  1024. * @spec: input string, containing configuration spec
  1025. * @add_curr: current image address (to be used as a possible default)
  1026. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1027. * configuration
  1028. * @conf_name double pointer to a char, will hold pointer to a configuration
  1029. * unit name
  1030. *
  1031. * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
  1032. * where <addr> is a FIT image address that contains configuration
  1033. * with a <conf> unit name.
  1034. *
  1035. * Address part is optional, and if omitted default add_curr will
  1036. * be used instead.
  1037. *
  1038. * returns:
  1039. * 1 if spec is a valid configuration string,
  1040. * addr and conf_name are set accordingly
  1041. * 0 otherwise
  1042. */
  1043. inline int fit_parse_conf (const char *spec, ulong addr_curr,
  1044. ulong *addr, const char **conf_name)
  1045. {
  1046. return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
  1047. }
  1048. /**
  1049. * fit_parse_subimage - parse FIT subimage spec
  1050. * @spec: input string, containing subimage spec
  1051. * @add_curr: current image address (to be used as a possible default)
  1052. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1053. * subimage
  1054. * @image_name: double pointer to a char, will hold pointer to a subimage name
  1055. *
  1056. * fit_parse_subimage() expects subimage spec in the for of
  1057. * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
  1058. * subimage with a <subimg> unit name.
  1059. *
  1060. * Address part is optional, and if omitted default add_curr will
  1061. * be used instead.
  1062. *
  1063. * returns:
  1064. * 1 if spec is a valid subimage string,
  1065. * addr and image_name are set accordingly
  1066. * 0 otherwise
  1067. */
  1068. inline int fit_parse_subimage (const char *spec, ulong addr_curr,
  1069. ulong *addr, const char **image_name)
  1070. {
  1071. return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
  1072. }
  1073. #endif /* !USE_HOSTCC */
  1074. static void fit_get_debug (const void *fit, int noffset,
  1075. char *prop_name, int err)
  1076. {
  1077. debug ("Can't get '%s' property from FIT 0x%08lx, "
  1078. "node: offset %d, name %s (%s)\n",
  1079. prop_name, (ulong)fit, noffset,
  1080. fit_get_name (fit, noffset, NULL),
  1081. fdt_strerror (err));
  1082. }
  1083. /**
  1084. * fit_print_contents - prints out the contents of the FIT format image
  1085. * @fit: pointer to the FIT format image header
  1086. * @p: pointer to prefix string
  1087. *
  1088. * fit_print_contents() formats a multi line FIT image contents description.
  1089. * The routine prints out FIT image properties (root node level) follwed by
  1090. * the details of each component image.
  1091. *
  1092. * returns:
  1093. * no returned results
  1094. */
  1095. void fit_print_contents (const void *fit)
  1096. {
  1097. char *desc;
  1098. char *uname;
  1099. int images_noffset;
  1100. int confs_noffset;
  1101. int noffset;
  1102. int ndepth;
  1103. int count = 0;
  1104. int ret;
  1105. const char *p;
  1106. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1107. time_t timestamp;
  1108. #endif
  1109. #ifdef USE_HOSTCC
  1110. p = "";
  1111. #else
  1112. p = " ";
  1113. #endif
  1114. /* Root node properties */
  1115. ret = fit_get_desc (fit, 0, &desc);
  1116. printf ("%sFIT description: ", p);
  1117. if (ret)
  1118. printf ("unavailable\n");
  1119. else
  1120. printf ("%s\n", desc);
  1121. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1122. ret = fit_get_timestamp (fit, 0, &timestamp);
  1123. printf ("%sCreated: ", p);
  1124. if (ret)
  1125. printf ("unavailable\n");
  1126. else
  1127. genimg_print_time (timestamp);
  1128. #endif
  1129. /* Find images parent node offset */
  1130. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1131. if (images_noffset < 0) {
  1132. printf ("Can't find images parent node '%s' (%s)\n",
  1133. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1134. return;
  1135. }
  1136. /* Process its subnodes, print out component images details */
  1137. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
  1138. (noffset >= 0) && (ndepth > 0);
  1139. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1140. if (ndepth == 1) {
  1141. /*
  1142. * Direct child node of the images parent node,
  1143. * i.e. component image node.
  1144. */
  1145. printf ("%s Image %u (%s)\n", p, count++,
  1146. fit_get_name(fit, noffset, NULL));
  1147. fit_image_print (fit, noffset, p);
  1148. }
  1149. }
  1150. /* Find configurations parent node offset */
  1151. confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
  1152. if (confs_noffset < 0) {
  1153. debug ("Can't get configurations parent node '%s' (%s)\n",
  1154. FIT_CONFS_PATH, fdt_strerror (confs_noffset));
  1155. return;
  1156. }
  1157. /* get default configuration unit name from default property */
  1158. uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
  1159. if (uname)
  1160. printf ("%s Default Configuration: '%s'\n", p, uname);
  1161. /* Process its subnodes, print out configurations details */
  1162. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
  1163. (noffset >= 0) && (ndepth > 0);
  1164. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1165. if (ndepth == 1) {
  1166. /*
  1167. * Direct child node of the configurations parent node,
  1168. * i.e. configuration node.
  1169. */
  1170. printf ("%s Configuration %u (%s)\n", p, count++,
  1171. fit_get_name(fit, noffset, NULL));
  1172. fit_conf_print (fit, noffset, p);
  1173. }
  1174. }
  1175. }
  1176. /**
  1177. * fit_image_print - prints out the FIT component image details
  1178. * @fit: pointer to the FIT format image header
  1179. * @image_noffset: offset of the component image node
  1180. * @p: pointer to prefix string
  1181. *
  1182. * fit_image_print() lists all mandatory properies for the processed component
  1183. * image. If present, hash nodes are printed out as well.
  1184. *
  1185. * returns:
  1186. * no returned results
  1187. */
  1188. void fit_image_print (const void *fit, int image_noffset, const char *p)
  1189. {
  1190. char *desc;
  1191. uint8_t type, arch, os, comp;
  1192. size_t size;
  1193. ulong load, entry;
  1194. const void *data;
  1195. int noffset;
  1196. int ndepth;
  1197. int ret;
  1198. /* Mandatory properties */
  1199. ret = fit_get_desc (fit, image_noffset, &desc);
  1200. printf ("%s Description: ", p);
  1201. if (ret)
  1202. printf ("unavailable\n");
  1203. else
  1204. printf ("%s\n", desc);
  1205. fit_image_get_type (fit, image_noffset, &type);
  1206. printf ("%s Type: %s\n", p, genimg_get_type_name (type));
  1207. fit_image_get_comp (fit, image_noffset, &comp);
  1208. printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
  1209. ret = fit_image_get_data (fit, image_noffset, &data, &size);
  1210. #ifndef USE_HOSTCC
  1211. printf ("%s Data Start: ", p);
  1212. if (ret)
  1213. printf ("unavailable\n");
  1214. else
  1215. printf ("0x%08lx\n", (ulong)data);
  1216. #endif
  1217. printf ("%s Data Size: ", p);
  1218. if (ret)
  1219. printf ("unavailable\n");
  1220. else
  1221. genimg_print_size (size);
  1222. /* Remaining, type dependent properties */
  1223. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
  1224. (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
  1225. (type == IH_TYPE_FLATDT)) {
  1226. fit_image_get_arch (fit, image_noffset, &arch);
  1227. printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
  1228. }
  1229. if (type == IH_TYPE_KERNEL) {
  1230. fit_image_get_os (fit, image_noffset, &os);
  1231. printf ("%s OS: %s\n", p, genimg_get_os_name (os));
  1232. }
  1233. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
  1234. ret = fit_image_get_load (fit, image_noffset, &load);
  1235. printf ("%s Load Address: ", p);
  1236. if (ret)
  1237. printf ("unavailable\n");
  1238. else
  1239. printf ("0x%08lx\n", load);
  1240. fit_image_get_entry (fit, image_noffset, &entry);
  1241. printf ("%s Entry Point: ", p);
  1242. if (ret)
  1243. printf ("unavailable\n");
  1244. else
  1245. printf ("0x%08lx\n", entry);
  1246. }
  1247. /* Process all hash subnodes of the component image node */
  1248. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1249. (noffset >= 0) && (ndepth > 0);
  1250. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1251. if (ndepth == 1) {
  1252. /* Direct child node of the component image node */
  1253. fit_image_print_hash (fit, noffset, p);
  1254. }
  1255. }
  1256. }
  1257. /**
  1258. * fit_image_print_hash - prints out the hash node details
  1259. * @fit: pointer to the FIT format image header
  1260. * @noffset: offset of the hash node
  1261. * @p: pointer to prefix string
  1262. *
  1263. * fit_image_print_hash() lists properies for the processed hash node
  1264. *
  1265. * returns:
  1266. * no returned results
  1267. */
  1268. void fit_image_print_hash (const void *fit, int noffset, const char *p)
  1269. {
  1270. char *algo;
  1271. uint8_t *value;
  1272. int value_len;
  1273. int i, ret;
  1274. /*
  1275. * Check subnode name, must be equal to "hash".
  1276. * Multiple hash nodes require unique unit node
  1277. * names, e.g. hash@1, hash@2, etc.
  1278. */
  1279. if (strncmp (fit_get_name(fit, noffset, NULL),
  1280. FIT_HASH_NODENAME,
  1281. strlen(FIT_HASH_NODENAME)) != 0)
  1282. return;
  1283. debug ("%s Hash node: '%s'\n", p,
  1284. fit_get_name (fit, noffset, NULL));
  1285. printf ("%s Hash algo: ", p);
  1286. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1287. printf ("invalid/unsupported\n");
  1288. return;
  1289. }
  1290. printf ("%s\n", algo);
  1291. ret = fit_image_hash_get_value (fit, noffset, &value,
  1292. &value_len);
  1293. printf ("%s Hash value: ", p);
  1294. if (ret) {
  1295. printf ("unavailable\n");
  1296. } else {
  1297. for (i = 0; i < value_len; i++)
  1298. printf ("%02x", value[i]);
  1299. printf ("\n");
  1300. }
  1301. debug ("%s Hash len: %d\n", p, value_len);
  1302. }
  1303. /**
  1304. * fit_get_desc - get node description property
  1305. * @fit: pointer to the FIT format image header
  1306. * @noffset: node offset
  1307. * @desc: double pointer to the char, will hold pointer to the descrption
  1308. *
  1309. * fit_get_desc() reads description property from a given node, if
  1310. * description is found pointer to it is returened in third call argument.
  1311. *
  1312. * returns:
  1313. * 0, on success
  1314. * -1, on failure
  1315. */
  1316. int fit_get_desc (const void *fit, int noffset, char **desc)
  1317. {
  1318. int len;
  1319. *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
  1320. if (*desc == NULL) {
  1321. fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
  1322. return -1;
  1323. }
  1324. return 0;
  1325. }
  1326. /**
  1327. * fit_get_timestamp - get node timestamp property
  1328. * @fit: pointer to the FIT format image header
  1329. * @noffset: node offset
  1330. * @timestamp: pointer to the time_t, will hold read timestamp
  1331. *
  1332. * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
  1333. * is found and has a correct size its value is retured in third call
  1334. * argument.
  1335. *
  1336. * returns:
  1337. * 0, on success
  1338. * -1, on property read failure
  1339. * -2, on wrong timestamp size
  1340. */
  1341. int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
  1342. {
  1343. int len;
  1344. const void *data;
  1345. data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
  1346. if (data == NULL) {
  1347. fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
  1348. return -1;
  1349. }
  1350. if (len != sizeof (uint32_t)) {
  1351. debug ("FIT timestamp with incorrect size of (%u)\n", len);
  1352. return -2;
  1353. }
  1354. *timestamp = uimage_to_cpu (*((uint32_t *)data));
  1355. return 0;
  1356. }
  1357. /**
  1358. * fit_image_get_node - get node offset for component image of a given unit name
  1359. * @fit: pointer to the FIT format image header
  1360. * @image_uname: component image node unit name
  1361. *
  1362. * fit_image_get_node() finds a component image (withing the '/images'
  1363. * node) of a provided unit name. If image is found its node offset is
  1364. * returned to the caller.
  1365. *
  1366. * returns:
  1367. * image node offset when found (>=0)
  1368. * negative number on failure (FDT_ERR_* code)
  1369. */
  1370. int fit_image_get_node (const void *fit, const char *image_uname)
  1371. {
  1372. int noffset, images_noffset;
  1373. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1374. if (images_noffset < 0) {
  1375. debug ("Can't find images parent node '%s' (%s)\n",
  1376. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1377. return images_noffset;
  1378. }
  1379. noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
  1380. if (noffset < 0) {
  1381. debug ("Can't get node offset for image unit name: '%s' (%s)\n",
  1382. image_uname, fdt_strerror (noffset));
  1383. }
  1384. return noffset;
  1385. }
  1386. /**
  1387. * fit_image_get_os - get os id for a given component image node
  1388. * @fit: pointer to the FIT format image header
  1389. * @noffset: component image node offset
  1390. * @os: pointer to the uint8_t, will hold os numeric id
  1391. *
  1392. * fit_image_get_os() finds os property in a given component image node.
  1393. * If the property is found, its (string) value is translated to the numeric
  1394. * id which is returned to the caller.
  1395. *
  1396. * returns:
  1397. * 0, on success
  1398. * -1, on failure
  1399. */
  1400. int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
  1401. {
  1402. int len;
  1403. const void *data;
  1404. /* Get OS name from property data */
  1405. data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
  1406. if (data == NULL) {
  1407. fit_get_debug (fit, noffset, FIT_OS_PROP, len);
  1408. *os = -1;
  1409. return -1;
  1410. }
  1411. /* Translate OS name to id */
  1412. *os = genimg_get_os_id (data);
  1413. return 0;
  1414. }
  1415. /**
  1416. * fit_image_get_arch - get arch id for a given component image node
  1417. * @fit: pointer to the FIT format image header
  1418. * @noffset: component image node offset
  1419. * @arch: pointer to the uint8_t, will hold arch numeric id
  1420. *
  1421. * fit_image_get_arch() finds arch property in a given component image node.
  1422. * If the property is found, its (string) value is translated to the numeric
  1423. * id which is returned to the caller.
  1424. *
  1425. * returns:
  1426. * 0, on success
  1427. * -1, on failure
  1428. */
  1429. int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
  1430. {
  1431. int len;
  1432. const void *data;
  1433. /* Get architecture name from property data */
  1434. data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
  1435. if (data == NULL) {
  1436. fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
  1437. *arch = -1;
  1438. return -1;
  1439. }
  1440. /* Translate architecture name to id */
  1441. *arch = genimg_get_arch_id (data);
  1442. return 0;
  1443. }
  1444. /**
  1445. * fit_image_get_type - get type id for a given component image node
  1446. * @fit: pointer to the FIT format image header
  1447. * @noffset: component image node offset
  1448. * @type: pointer to the uint8_t, will hold type numeric id
  1449. *
  1450. * fit_image_get_type() finds type property in a given component image node.
  1451. * If the property is found, its (string) value is translated to the numeric
  1452. * id which is returned to the caller.
  1453. *
  1454. * returns:
  1455. * 0, on success
  1456. * -1, on failure
  1457. */
  1458. int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
  1459. {
  1460. int len;
  1461. const void *data;
  1462. /* Get image type name from property data */
  1463. data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
  1464. if (data == NULL) {
  1465. fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
  1466. *type = -1;
  1467. return -1;
  1468. }
  1469. /* Translate image type name to id */
  1470. *type = genimg_get_type_id (data);
  1471. return 0;
  1472. }
  1473. /**
  1474. * fit_image_get_comp - get comp id for a given component image node
  1475. * @fit: pointer to the FIT format image header
  1476. * @noffset: component image node offset
  1477. * @comp: pointer to the uint8_t, will hold comp numeric id
  1478. *
  1479. * fit_image_get_comp() finds comp property in a given component image node.
  1480. * If the property is found, its (string) value is translated to the numeric
  1481. * id which is returned to the caller.
  1482. *
  1483. * returns:
  1484. * 0, on success
  1485. * -1, on failure
  1486. */
  1487. int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
  1488. {
  1489. int len;
  1490. const void *data;
  1491. /* Get compression name from property data */
  1492. data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
  1493. if (data == NULL) {
  1494. fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
  1495. *comp = -1;
  1496. return -1;
  1497. }
  1498. /* Translate compression name to id */
  1499. *comp = genimg_get_comp_id (data);
  1500. return 0;
  1501. }
  1502. /**
  1503. * fit_image_get_load - get load address property for a given component image node
  1504. * @fit: pointer to the FIT format image header
  1505. * @noffset: component image node offset
  1506. * @load: pointer to the uint32_t, will hold load address
  1507. *
  1508. * fit_image_get_load() finds load address property in a given component image node.
  1509. * If the property is found, its value is returned to the caller.
  1510. *
  1511. * returns:
  1512. * 0, on success
  1513. * -1, on failure
  1514. */
  1515. int fit_image_get_load (const void *fit, int noffset, ulong *load)
  1516. {
  1517. int len;
  1518. const uint32_t *data;
  1519. data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
  1520. if (data == NULL) {
  1521. fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
  1522. return -1;
  1523. }
  1524. *load = uimage_to_cpu (*data);
  1525. return 0;
  1526. }
  1527. /**
  1528. * fit_image_get_entry - get entry point address property for a given component image node
  1529. * @fit: pointer to the FIT format image header
  1530. * @noffset: component image node offset
  1531. * @entry: pointer to the uint32_t, will hold entry point address
  1532. *
  1533. * fit_image_get_entry() finds entry point address property in a given component image node.
  1534. * If the property is found, its value is returned to the caller.
  1535. *
  1536. * returns:
  1537. * 0, on success
  1538. * -1, on failure
  1539. */
  1540. int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
  1541. {
  1542. int len;
  1543. const uint32_t *data;
  1544. data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
  1545. if (data == NULL) {
  1546. fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
  1547. return -1;
  1548. }
  1549. *entry = uimage_to_cpu (*data);
  1550. return 0;
  1551. }
  1552. /**
  1553. * fit_image_get_data - get data property and its size for a given component image node
  1554. * @fit: pointer to the FIT format image header
  1555. * @noffset: component image node offset
  1556. * @data: double pointer to void, will hold data property's data address
  1557. * @size: pointer to size_t, will hold data property's data size
  1558. *
  1559. * fit_image_get_data() finds data property in a given component image node.
  1560. * If the property is found its data start address and size are returned to
  1561. * the caller.
  1562. *
  1563. * returns:
  1564. * 0, on success
  1565. * -1, on failure
  1566. */
  1567. int fit_image_get_data (const void *fit, int noffset,
  1568. const void **data, size_t *size)
  1569. {
  1570. int len;
  1571. *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
  1572. if (*data == NULL) {
  1573. fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
  1574. *size = 0;
  1575. return -1;
  1576. }
  1577. *size = len;
  1578. return 0;
  1579. }
  1580. /**
  1581. * fit_image_hash_get_algo - get hash algorithm name
  1582. * @fit: pointer to the FIT format image header
  1583. * @noffset: hash node offset
  1584. * @algo: double pointer to char, will hold pointer to the algorithm name
  1585. *
  1586. * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
  1587. * If the property is found its data start address is returned to the caller.
  1588. *
  1589. * returns:
  1590. * 0, on success
  1591. * -1, on failure
  1592. */
  1593. int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
  1594. {
  1595. int len;
  1596. *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
  1597. if (*algo == NULL) {
  1598. fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
  1599. return -1;
  1600. }
  1601. return 0;
  1602. }
  1603. /**
  1604. * fit_image_hash_get_value - get hash value and length
  1605. * @fit: pointer to the FIT format image header
  1606. * @noffset: hash node offset
  1607. * @value: double pointer to uint8_t, will hold address of a hash value data
  1608. * @value_len: pointer to an int, will hold hash data length
  1609. *
  1610. * fit_image_hash_get_value() finds hash value property in a given hash node.
  1611. * If the property is found its data start address and size are returned to
  1612. * the caller.
  1613. *
  1614. * returns:
  1615. * 0, on success
  1616. * -1, on failure
  1617. */
  1618. int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
  1619. int *value_len)
  1620. {
  1621. int len;
  1622. *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
  1623. if (*value == NULL) {
  1624. fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
  1625. *value_len = 0;
  1626. return -1;
  1627. }
  1628. *value_len = len;
  1629. return 0;
  1630. }
  1631. /**
  1632. * fit_set_timestamp - set node timestamp property
  1633. * @fit: pointer to the FIT format image header
  1634. * @noffset: node offset
  1635. * @timestamp: timestamp value to be set
  1636. *
  1637. * fit_set_timestamp() attempts to set timestamp property in the requested
  1638. * node and returns operation status to the caller.
  1639. *
  1640. * returns:
  1641. * 0, on success
  1642. * -1, on property read failure
  1643. */
  1644. int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
  1645. {
  1646. uint32_t t;
  1647. int ret;
  1648. t = cpu_to_uimage (timestamp);
  1649. ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
  1650. sizeof (uint32_t));
  1651. if (ret) {
  1652. printf ("Can't set '%s' property for '%s' node (%s)\n",
  1653. FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
  1654. fdt_strerror (ret));
  1655. return -1;
  1656. }
  1657. return 0;
  1658. }
  1659. /**
  1660. * calculate_hash - calculate and return hash for provided input data
  1661. * @data: pointer to the input data
  1662. * @data_len: data length
  1663. * @algo: requested hash algorithm
  1664. * @value: pointer to the char, will hold hash value data (caller must
  1665. * allocate enough free space)
  1666. * value_len: length of the calculated hash
  1667. *
  1668. * calculate_hash() computes input data hash according to the requested algorithm.
  1669. * Resulting hash value is placed in caller provided 'value' buffer, length
  1670. * of the calculated hash is returned via value_len pointer argument.
  1671. *
  1672. * returns:
  1673. * 0, on success
  1674. * -1, when algo is unsupported
  1675. */
  1676. static int calculate_hash (const void *data, int data_len, const char *algo,
  1677. uint8_t *value, int *value_len)
  1678. {
  1679. if (strcmp (algo, "crc32") == 0 ) {
  1680. *((uint32_t *)value) = crc32_wd (0, data, data_len,
  1681. CHUNKSZ_CRC32);
  1682. *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
  1683. *value_len = 4;
  1684. } else if (strcmp (algo, "sha1") == 0 ) {
  1685. sha1_csum_wd ((unsigned char *) data, data_len,
  1686. (unsigned char *) value, CHUNKSZ_SHA1);
  1687. *value_len = 20;
  1688. } else if (strcmp (algo, "md5") == 0 ) {
  1689. md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
  1690. *value_len = 16;
  1691. } else {
  1692. debug ("Unsupported hash alogrithm\n");
  1693. return -1;
  1694. }
  1695. return 0;
  1696. }
  1697. #ifdef USE_HOSTCC
  1698. /**
  1699. * fit_set_hashes - process FIT component image nodes and calculate hashes
  1700. * @fit: pointer to the FIT format image header
  1701. *
  1702. * fit_set_hashes() adds hash values for all component images in the FIT blob.
  1703. * Hashes are calculated for all component images which have hash subnodes
  1704. * with algorithm property set to one of the supported hash algorithms.
  1705. *
  1706. * returns
  1707. * 0, on success
  1708. * libfdt error code, on failure
  1709. */
  1710. int fit_set_hashes (void *fit)
  1711. {
  1712. int images_noffset;
  1713. int noffset;
  1714. int ndepth;
  1715. int ret;
  1716. /* Find images parent node offset */
  1717. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1718. if (images_noffset < 0) {
  1719. printf ("Can't find images parent node '%s' (%s)\n",
  1720. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1721. return images_noffset;
  1722. }
  1723. /* Process its subnodes, print out component images details */
  1724. for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
  1725. (noffset >= 0) && (ndepth > 0);
  1726. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1727. if (ndepth == 1) {
  1728. /*
  1729. * Direct child node of the images parent node,
  1730. * i.e. component image node.
  1731. */
  1732. ret = fit_image_set_hashes (fit, noffset);
  1733. if (ret)
  1734. return ret;
  1735. }
  1736. }
  1737. return 0;
  1738. }
  1739. /**
  1740. * fit_image_set_hashes - calculate/set hashes for given component image node
  1741. * @fit: pointer to the FIT format image header
  1742. * @image_noffset: requested component image node
  1743. *
  1744. * fit_image_set_hashes() adds hash values for an component image node. All
  1745. * existing hash subnodes are checked, if algorithm property is set to one of
  1746. * the supported hash algorithms, hash value is computed and corresponding
  1747. * hash node property is set, for example:
  1748. *
  1749. * Input component image node structure:
  1750. *
  1751. * o image@1 (at image_noffset)
  1752. * | - data = [binary data]
  1753. * o hash@1
  1754. * |- algo = "sha1"
  1755. *
  1756. * Output component image node structure:
  1757. *
  1758. * o image@1 (at image_noffset)
  1759. * | - data = [binary data]
  1760. * o hash@1
  1761. * |- algo = "sha1"
  1762. * |- value = sha1(data)
  1763. *
  1764. * returns:
  1765. * 0 on sucess
  1766. * <0 on failure
  1767. */
  1768. int fit_image_set_hashes (void *fit, int image_noffset)
  1769. {
  1770. const void *data;
  1771. size_t size;
  1772. char *algo;
  1773. uint8_t value[FIT_MAX_HASH_LEN];
  1774. int value_len;
  1775. int noffset;
  1776. int ndepth;
  1777. /* Get image data and data length */
  1778. if (fit_image_get_data (fit, image_noffset, &data, &size)) {
  1779. printf ("Can't get image data/size\n");
  1780. return -1;
  1781. }
  1782. /* Process all hash subnodes of the component image node */
  1783. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1784. (noffset >= 0) && (ndepth > 0);
  1785. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1786. if (ndepth == 1) {
  1787. /* Direct child node of the component image node */
  1788. /*
  1789. * Check subnode name, must be equal to "hash".
  1790. * Multiple hash nodes require unique unit node
  1791. * names, e.g. hash@1, hash@2, etc.
  1792. */
  1793. if (strncmp (fit_get_name(fit, noffset, NULL),
  1794. FIT_HASH_NODENAME,
  1795. strlen(FIT_HASH_NODENAME)) != 0) {
  1796. /* Not a hash subnode, skip it */
  1797. continue;
  1798. }
  1799. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1800. printf ("Can't get hash algo property for "
  1801. "'%s' hash node in '%s' image node\n",
  1802. fit_get_name (fit, noffset, NULL),
  1803. fit_get_name (fit, image_noffset, NULL));
  1804. return -1;
  1805. }
  1806. if (calculate_hash (data, size, algo, value, &value_len)) {
  1807. printf ("Unsupported hash algorithm (%s) for "
  1808. "'%s' hash node in '%s' image node\n",
  1809. algo, fit_get_name (fit, noffset, NULL),
  1810. fit_get_name (fit, image_noffset, NULL));
  1811. return -1;
  1812. }
  1813. if (fit_image_hash_set_value (fit, noffset, value,
  1814. value_len)) {
  1815. printf ("Can't set hash value for "
  1816. "'%s' hash node in '%s' image node\n",
  1817. fit_get_name (fit, noffset, NULL),
  1818. fit_get_name (fit, image_noffset, NULL));
  1819. return -1;
  1820. }
  1821. }
  1822. }
  1823. return 0;
  1824. }
  1825. /**
  1826. * fit_image_hash_set_value - set hash value in requested has node
  1827. * @fit: pointer to the FIT format image header
  1828. * @noffset: hash node offset
  1829. * @value: hash value to be set
  1830. * @value_len: hash value length
  1831. *
  1832. * fit_image_hash_set_value() attempts to set hash value in a node at offset
  1833. * given and returns operation status to the caller.
  1834. *
  1835. * returns
  1836. * 0, on success
  1837. * -1, on failure
  1838. */
  1839. int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
  1840. int value_len)
  1841. {
  1842. int ret;
  1843. ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
  1844. if (ret) {
  1845. printf ("Can't set hash '%s' property for '%s' node (%s)\n",
  1846. FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
  1847. fdt_strerror (ret));
  1848. return -1;
  1849. }
  1850. return 0;
  1851. }
  1852. #endif /* USE_HOSTCC */
  1853. /**
  1854. * fit_image_check_hashes - verify data intergity
  1855. * @fit: pointer to the FIT format image header
  1856. * @image_noffset: component image node offset
  1857. *
  1858. * fit_image_check_hashes() goes over component image hash nodes,
  1859. * re-calculates each data hash and compares with the value stored in hash
  1860. * node.
  1861. *
  1862. * returns:
  1863. * 1, if all hashes are valid
  1864. * 0, otherwise (or on error)
  1865. */
  1866. int fit_image_check_hashes (const void *fit, int image_noffset)
  1867. {
  1868. const void *data;
  1869. size_t size;
  1870. char *algo;
  1871. uint8_t *fit_value;
  1872. int fit_value_len;
  1873. uint8_t value[FIT_MAX_HASH_LEN];
  1874. int value_len;
  1875. int noffset;
  1876. int ndepth;
  1877. char *err_msg = "";
  1878. /* Get image data and data length */
  1879. if (fit_image_get_data (fit, image_noffset, &data, &size)) {
  1880. printf ("Can't get image data/size\n");
  1881. return 0;
  1882. }
  1883. /* Process all hash subnodes of the component image node */
  1884. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1885. (noffset >= 0) && (ndepth > 0);
  1886. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1887. if (ndepth == 1) {
  1888. /* Direct child node of the component image node */
  1889. /*
  1890. * Check subnode name, must be equal to "hash".
  1891. * Multiple hash nodes require unique unit node
  1892. * names, e.g. hash@1, hash@2, etc.
  1893. */
  1894. if (strncmp (fit_get_name(fit, noffset, NULL),
  1895. FIT_HASH_NODENAME,
  1896. strlen(FIT_HASH_NODENAME)) != 0)
  1897. continue;
  1898. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1899. err_msg = "Can't get hash algo property";
  1900. goto error;
  1901. }
  1902. printf ("%s", algo);
  1903. if (fit_image_hash_get_value (fit, noffset, &fit_value,
  1904. &fit_value_len)) {
  1905. err_msg = "Can't get hash value property";
  1906. goto error;
  1907. }
  1908. if (calculate_hash (data, size, algo, value, &value_len)) {
  1909. err_msg = "Unsupported hash algorithm";
  1910. goto error;
  1911. }
  1912. if (value_len != fit_value_len) {
  1913. err_msg = "Bad hash value len";
  1914. goto error;
  1915. } else if (memcmp (value, fit_value, value_len) != 0) {
  1916. err_msg = "Bad hash value";
  1917. goto error;
  1918. }
  1919. printf ("+ ");
  1920. }
  1921. }
  1922. return 1;
  1923. error:
  1924. printf ("%s for '%s' hash node in '%s' image node\n",
  1925. err_msg, fit_get_name (fit, noffset, NULL),
  1926. fit_get_name (fit, image_noffset, NULL));
  1927. return 0;
  1928. }
  1929. /**
  1930. * fit_image_check_os - check whether image node is of a given os type
  1931. * @fit: pointer to the FIT format image header
  1932. * @noffset: component image node offset
  1933. * @os: requested image os
  1934. *
  1935. * fit_image_check_os() reads image os property and compares its numeric
  1936. * id with the requested os. Comparison result is returned to the caller.
  1937. *
  1938. * returns:
  1939. * 1 if image is of given os type
  1940. * 0 otherwise (or on error)
  1941. */
  1942. int fit_image_check_os (const void *fit, int noffset, uint8_t os)
  1943. {
  1944. uint8_t image_os;
  1945. if (fit_image_get_os (fit, noffset, &image_os))
  1946. return 0;
  1947. return (os == image_os);
  1948. }
  1949. /**
  1950. * fit_image_check_arch - check whether image node is of a given arch
  1951. * @fit: pointer to the FIT format image header
  1952. * @noffset: component image node offset
  1953. * @arch: requested imagearch
  1954. *
  1955. * fit_image_check_arch() reads image arch property and compares its numeric
  1956. * id with the requested arch. Comparison result is returned to the caller.
  1957. *
  1958. * returns:
  1959. * 1 if image is of given arch
  1960. * 0 otherwise (or on error)
  1961. */
  1962. int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
  1963. {
  1964. uint8_t image_arch;
  1965. if (fit_image_get_arch (fit, noffset, &image_arch))
  1966. return 0;
  1967. return (arch == image_arch);
  1968. }
  1969. /**
  1970. * fit_image_check_type - check whether image node is of a given type
  1971. * @fit: pointer to the FIT format image header
  1972. * @noffset: component image node offset
  1973. * @type: requested image type
  1974. *
  1975. * fit_image_check_type() reads image type property and compares its numeric
  1976. * id with the requested type. Comparison result is returned to the caller.
  1977. *
  1978. * returns:
  1979. * 1 if image is of given type
  1980. * 0 otherwise (or on error)
  1981. */
  1982. int fit_image_check_type (const void *fit, int noffset, uint8_t type)
  1983. {
  1984. uint8_t image_type;
  1985. if (fit_image_get_type (fit, noffset, &image_type))
  1986. return 0;
  1987. return (type == image_type);
  1988. }
  1989. /**
  1990. * fit_image_check_comp - check whether image node uses given compression
  1991. * @fit: pointer to the FIT format image header
  1992. * @noffset: component image node offset
  1993. * @comp: requested image compression type
  1994. *
  1995. * fit_image_check_comp() reads image compression property and compares its
  1996. * numeric id with the requested compression type. Comparison result is
  1997. * returned to the caller.
  1998. *
  1999. * returns:
  2000. * 1 if image uses requested compression
  2001. * 0 otherwise (or on error)
  2002. */
  2003. int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
  2004. {
  2005. uint8_t image_comp;
  2006. if (fit_image_get_comp (fit, noffset, &image_comp))
  2007. return 0;
  2008. return (comp == image_comp);
  2009. }
  2010. /**
  2011. * fit_check_format - sanity check FIT image format
  2012. * @fit: pointer to the FIT format image header
  2013. *
  2014. * fit_check_format() runs a basic sanity FIT image verification.
  2015. * Routine checks for mandatory properties, nodes, etc.
  2016. *
  2017. * returns:
  2018. * 1, on success
  2019. * 0, on failure
  2020. */
  2021. int fit_check_format (const void *fit)
  2022. {
  2023. /* mandatory / node 'description' property */
  2024. if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
  2025. debug ("Wrong FIT format: no description\n");
  2026. return 0;
  2027. }
  2028. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  2029. /* mandatory / node 'timestamp' property */
  2030. if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
  2031. debug ("Wrong FIT format: no description\n");
  2032. return 0;
  2033. }
  2034. #endif
  2035. /* mandatory subimages parent '/images' node */
  2036. if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
  2037. debug ("Wrong FIT format: no images parent node\n");
  2038. return 0;
  2039. }
  2040. return 1;
  2041. }
  2042. /**
  2043. * fit_conf_get_node - get node offset for configuration of a given unit name
  2044. * @fit: pointer to the FIT format image header
  2045. * @conf_uname: configuration node unit name
  2046. *
  2047. * fit_conf_get_node() finds a configuration (withing the '/configurations'
  2048. * parant node) of a provided unit name. If configuration is found its node offset
  2049. * is returned to the caller.
  2050. *
  2051. * When NULL is provided in second argument fit_conf_get_node() will search
  2052. * for a default configuration node instead. Default configuration node unit name
  2053. * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
  2054. *
  2055. * returns:
  2056. * configuration node offset when found (>=0)
  2057. * negative number on failure (FDT_ERR_* code)
  2058. */
  2059. int fit_conf_get_node (const void *fit, const char *conf_uname)
  2060. {
  2061. int noffset, confs_noffset;
  2062. int len;
  2063. confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
  2064. if (confs_noffset < 0) {
  2065. debug ("Can't find configurations parent node '%s' (%s)\n",
  2066. FIT_CONFS_PATH, fdt_strerror (confs_noffset));
  2067. return confs_noffset;
  2068. }
  2069. if (conf_uname == NULL) {
  2070. /* get configuration unit name from the default property */
  2071. debug ("No configuration specified, trying default...\n");
  2072. conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
  2073. if (conf_uname == NULL) {
  2074. fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
  2075. return len;
  2076. }
  2077. debug ("Found default configuration: '%s'\n", conf_uname);
  2078. }
  2079. noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
  2080. if (noffset < 0) {
  2081. debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
  2082. conf_uname, fdt_strerror (noffset));
  2083. }
  2084. return noffset;
  2085. }
  2086. static int __fit_conf_get_prop_node (const void *fit, int noffset,
  2087. const char *prop_name)
  2088. {
  2089. char *uname;
  2090. int len;
  2091. /* get kernel image unit name from configuration kernel property */
  2092. uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
  2093. if (uname == NULL)
  2094. return len;
  2095. return fit_image_get_node (fit, uname);
  2096. }
  2097. /**
  2098. * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
  2099. * a given configuration
  2100. * @fit: pointer to the FIT format image header
  2101. * @noffset: configuration node offset
  2102. *
  2103. * fit_conf_get_kernel_node() retrives kernel image node unit name from
  2104. * configuration FIT_KERNEL_PROP property and translates it to the node
  2105. * offset.
  2106. *
  2107. * returns:
  2108. * image node offset when found (>=0)
  2109. * negative number on failure (FDT_ERR_* code)
  2110. */
  2111. int fit_conf_get_kernel_node (const void *fit, int noffset)
  2112. {
  2113. return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
  2114. }
  2115. /**
  2116. * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
  2117. * a given configuration
  2118. * @fit: pointer to the FIT format image header
  2119. * @noffset: configuration node offset
  2120. *
  2121. * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
  2122. * configuration FIT_KERNEL_PROP property and translates it to the node
  2123. * offset.
  2124. *
  2125. * returns:
  2126. * image node offset when found (>=0)
  2127. * negative number on failure (FDT_ERR_* code)
  2128. */
  2129. int fit_conf_get_ramdisk_node (const void *fit, int noffset)
  2130. {
  2131. return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
  2132. }
  2133. /**
  2134. * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
  2135. * a given configuration
  2136. * @fit: pointer to the FIT format image header
  2137. * @noffset: configuration node offset
  2138. *
  2139. * fit_conf_get_fdt_node() retrives fdt image node unit name from
  2140. * configuration FIT_KERNEL_PROP property and translates it to the node
  2141. * offset.
  2142. *
  2143. * returns:
  2144. * image node offset when found (>=0)
  2145. * negative number on failure (FDT_ERR_* code)
  2146. */
  2147. int fit_conf_get_fdt_node (const void *fit, int noffset)
  2148. {
  2149. return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
  2150. }
  2151. /**
  2152. * fit_conf_print - prints out the FIT configuration details
  2153. * @fit: pointer to the FIT format image header
  2154. * @noffset: offset of the configuration node
  2155. * @p: pointer to prefix string
  2156. *
  2157. * fit_conf_print() lists all mandatory properies for the processed
  2158. * configuration node.
  2159. *
  2160. * returns:
  2161. * no returned results
  2162. */
  2163. void fit_conf_print (const void *fit, int noffset, const char *p)
  2164. {
  2165. char *desc;
  2166. char *uname;
  2167. int ret;
  2168. /* Mandatory properties */
  2169. ret = fit_get_desc (fit, noffset, &desc);
  2170. printf ("%s Description: ", p);
  2171. if (ret)
  2172. printf ("unavailable\n");
  2173. else
  2174. printf ("%s\n", desc);
  2175. uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
  2176. printf ("%s Kernel: ", p);
  2177. if (uname == NULL)
  2178. printf ("unavailable\n");
  2179. else
  2180. printf ("%s\n", uname);
  2181. /* Optional properties */
  2182. uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
  2183. if (uname)
  2184. printf ("%s Init Ramdisk: %s\n", p, uname);
  2185. uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
  2186. if (uname)
  2187. printf ("%s FDT: %s\n", p, uname);
  2188. }
  2189. /**
  2190. * fit_check_ramdisk - verify FIT format ramdisk subimage
  2191. * @fit_hdr: pointer to the FIT ramdisk header
  2192. * @rd_noffset: ramdisk subimage node offset within FIT image
  2193. * @arch: requested ramdisk image architecture type
  2194. * @verify: data CRC verification flag
  2195. *
  2196. * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
  2197. * specified FIT image.
  2198. *
  2199. * returns:
  2200. * 1, on success
  2201. * 0, on failure
  2202. */
  2203. #ifndef USE_HOSTCC
  2204. static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
  2205. {
  2206. fit_image_print (fit, rd_noffset, " ");
  2207. if (verify) {
  2208. puts (" Verifying Hash Integrity ... ");
  2209. if (!fit_image_check_hashes (fit, rd_noffset)) {
  2210. puts ("Bad Data Hash\n");
  2211. show_boot_progress (-125);
  2212. return 0;
  2213. }
  2214. puts ("OK\n");
  2215. }
  2216. show_boot_progress (126);
  2217. if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
  2218. !fit_image_check_arch (fit, rd_noffset, arch) ||
  2219. !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
  2220. printf ("No Linux %s Ramdisk Image\n",
  2221. genimg_get_arch_name(arch));
  2222. show_boot_progress (-126);
  2223. return 0;
  2224. }
  2225. show_boot_progress (127);
  2226. return 1;
  2227. }
  2228. #endif /* USE_HOSTCC */
  2229. #endif /* CONFIG_FIT */