image.c 68 KB

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