image.c 69 KB

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