image.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534
  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. #ifdef CFG_SDRAM_BASE
  402. return CFG_SDRAM_BASE;
  403. #else
  404. return 0;
  405. #endif
  406. }
  407. ulong getenv_bootm_size(void)
  408. {
  409. char *s = getenv ("bootm_size");
  410. if (s) {
  411. ulong tmp = simple_strtoul (s, NULL, 16);
  412. return tmp;
  413. }
  414. return gd->bd->bi_memsize;
  415. }
  416. void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
  417. {
  418. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  419. while (len > 0) {
  420. size_t tail = (len > chunksz) ? chunksz : len;
  421. WATCHDOG_RESET ();
  422. memmove (to, from, tail);
  423. to += tail;
  424. from += tail;
  425. len -= tail;
  426. }
  427. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  428. memmove (to, from, len);
  429. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  430. }
  431. #endif /* !USE_HOSTCC */
  432. static void genimg_print_size (uint32_t size)
  433. {
  434. #ifndef USE_HOSTCC
  435. printf ("%d Bytes = ", size);
  436. print_size (size, "\n");
  437. #else
  438. printf ("%d Bytes = %.2f kB = %.2f MB\n",
  439. size, (double)size / 1.024e3,
  440. (double)size / 1.048576e6);
  441. #endif
  442. }
  443. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  444. static void genimg_print_time (time_t timestamp)
  445. {
  446. #ifndef USE_HOSTCC
  447. struct rtc_time tm;
  448. to_tm (timestamp, &tm);
  449. printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
  450. tm.tm_year, tm.tm_mon, tm.tm_mday,
  451. tm.tm_hour, tm.tm_min, tm.tm_sec);
  452. #else
  453. printf ("%s", ctime(&timestamp));
  454. #endif
  455. }
  456. #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
  457. /**
  458. * get_table_entry_name - translate entry id to long name
  459. * @table: pointer to a translation table for entries of a specific type
  460. * @msg: message to be returned when translation fails
  461. * @id: entry id to be translated
  462. *
  463. * get_table_entry_name() will go over translation table trying to find
  464. * entry that matches given id. If matching entry is found, its long
  465. * name is returned to the caller.
  466. *
  467. * returns:
  468. * long entry name if translation succeeds
  469. * msg otherwise
  470. */
  471. static char *get_table_entry_name (table_entry_t *table, char *msg, int id)
  472. {
  473. for (; table->id >= 0; ++table) {
  474. if (table->id == id)
  475. return (table->lname);
  476. }
  477. return (msg);
  478. }
  479. const char *genimg_get_os_name (uint8_t os)
  480. {
  481. return (get_table_entry_name (uimage_os, "Unknown OS", os));
  482. }
  483. const char *genimg_get_arch_name (uint8_t arch)
  484. {
  485. return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
  486. }
  487. const char *genimg_get_type_name (uint8_t type)
  488. {
  489. return (get_table_entry_name (uimage_type, "Unknown Image", type));
  490. }
  491. const char *genimg_get_comp_name (uint8_t comp)
  492. {
  493. return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
  494. }
  495. /**
  496. * get_table_entry_id - translate short entry name to id
  497. * @table: pointer to a translation table for entries of a specific type
  498. * @table_name: to be used in case of error
  499. * @name: entry short name to be translated
  500. *
  501. * get_table_entry_id() will go over translation table trying to find
  502. * entry that matches given short name. If matching entry is found,
  503. * its id returned to the caller.
  504. *
  505. * returns:
  506. * entry id if translation succeeds
  507. * -1 otherwise
  508. */
  509. static int get_table_entry_id (table_entry_t *table,
  510. const char *table_name, const char *name)
  511. {
  512. table_entry_t *t;
  513. #ifdef USE_HOSTCC
  514. int first = 1;
  515. for (t = table; t->id >= 0; ++t) {
  516. if (t->sname && strcasecmp(t->sname, name) == 0)
  517. return (t->id);
  518. }
  519. fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
  520. for (t = table; t->id >= 0; ++t) {
  521. if (t->sname == NULL)
  522. continue;
  523. fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
  524. first = 0;
  525. }
  526. fprintf (stderr, "\n");
  527. #else
  528. for (t = table; t->id >= 0; ++t) {
  529. if (t->sname && strcmp(t->sname, name) == 0)
  530. return (t->id);
  531. }
  532. debug ("Invalid %s Type: %s\n", table_name, name);
  533. #endif /* USE_HOSTCC */
  534. return (-1);
  535. }
  536. int genimg_get_os_id (const char *name)
  537. {
  538. return (get_table_entry_id (uimage_os, "OS", name));
  539. }
  540. int genimg_get_arch_id (const char *name)
  541. {
  542. return (get_table_entry_id (uimage_arch, "CPU", name));
  543. }
  544. int genimg_get_type_id (const char *name)
  545. {
  546. return (get_table_entry_id (uimage_type, "Image", name));
  547. }
  548. int genimg_get_comp_id (const char *name)
  549. {
  550. return (get_table_entry_id (uimage_comp, "Compression", name));
  551. }
  552. #ifndef USE_HOSTCC
  553. /**
  554. * genimg_get_format - get image format type
  555. * @img_addr: image start address
  556. *
  557. * genimg_get_format() checks whether provided address points to a valid
  558. * legacy or FIT image.
  559. *
  560. * New uImage format and FDT blob are based on a libfdt. FDT blob
  561. * may be passed directly or embedded in a FIT image. In both situations
  562. * genimg_get_format() must be able to dectect libfdt header.
  563. *
  564. * returns:
  565. * image format type or IMAGE_FORMAT_INVALID if no image is present
  566. */
  567. int genimg_get_format (void *img_addr)
  568. {
  569. ulong format = IMAGE_FORMAT_INVALID;
  570. image_header_t *hdr;
  571. #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
  572. char *fit_hdr;
  573. #endif
  574. hdr = (image_header_t *)img_addr;
  575. if (image_check_magic(hdr))
  576. format = IMAGE_FORMAT_LEGACY;
  577. #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
  578. else {
  579. fit_hdr = (char *)img_addr;
  580. if (fdt_check_header (fit_hdr) == 0)
  581. format = IMAGE_FORMAT_FIT;
  582. }
  583. #endif
  584. return format;
  585. }
  586. /**
  587. * genimg_get_image - get image from special storage (if necessary)
  588. * @img_addr: image start address
  589. *
  590. * genimg_get_image() checks if provided image start adddress is located
  591. * in a dataflash storage. If so, image is moved to a system RAM memory.
  592. *
  593. * returns:
  594. * image start address after possible relocation from special storage
  595. */
  596. ulong genimg_get_image (ulong img_addr)
  597. {
  598. ulong ram_addr = img_addr;
  599. #ifdef CONFIG_HAS_DATAFLASH
  600. ulong h_size, d_size;
  601. if (addr_dataflash (img_addr)){
  602. /* ger RAM address */
  603. ram_addr = CFG_LOAD_ADDR;
  604. /* get header size */
  605. h_size = image_get_header_size ();
  606. #if defined(CONFIG_FIT)
  607. if (sizeof(struct fdt_header) > h_size)
  608. h_size = sizeof(struct fdt_header);
  609. #endif
  610. /* read in header */
  611. debug (" Reading image header from dataflash address "
  612. "%08lx to RAM address %08lx\n", img_addr, ram_addr);
  613. read_dataflash (img_addr, h_size, (char *)ram_addr);
  614. /* get data size */
  615. switch (genimg_get_format ((void *)ram_addr)) {
  616. case IMAGE_FORMAT_LEGACY:
  617. d_size = image_get_data_size ((image_header_t *)ram_addr);
  618. debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
  619. ram_addr, d_size);
  620. break;
  621. #if defined(CONFIG_FIT)
  622. case IMAGE_FORMAT_FIT:
  623. d_size = fit_get_size ((const void *)ram_addr) - h_size;
  624. debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
  625. ram_addr, d_size);
  626. break;
  627. #endif
  628. default:
  629. printf (" No valid image found at 0x%08lx\n", img_addr);
  630. return ram_addr;
  631. }
  632. /* read in image data */
  633. debug (" Reading image remaining data from dataflash address "
  634. "%08lx to RAM address %08lx\n", img_addr + h_size,
  635. ram_addr + h_size);
  636. read_dataflash (img_addr + h_size, d_size,
  637. (char *)(ram_addr + h_size));
  638. }
  639. #endif /* CONFIG_HAS_DATAFLASH */
  640. return ram_addr;
  641. }
  642. /**
  643. * fit_has_config - check if there is a valid FIT configuration
  644. * @images: pointer to the bootm command headers structure
  645. *
  646. * fit_has_config() checks if there is a FIT configuration in use
  647. * (if FTI support is present).
  648. *
  649. * returns:
  650. * 0, no FIT support or no configuration found
  651. * 1, configuration found
  652. */
  653. int genimg_has_config (bootm_headers_t *images)
  654. {
  655. #if defined(CONFIG_FIT)
  656. if (images->fit_uname_cfg)
  657. return 1;
  658. #endif
  659. return 0;
  660. }
  661. /**
  662. * boot_get_ramdisk - main ramdisk handling routine
  663. * @argc: command argument count
  664. * @argv: command argument list
  665. * @images: pointer to the bootm images structure
  666. * @arch: expected ramdisk architecture
  667. * @rd_start: pointer to a ulong variable, will hold ramdisk start address
  668. * @rd_end: pointer to a ulong variable, will hold ramdisk end
  669. *
  670. * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
  671. * Curently supported are the following ramdisk sources:
  672. * - multicomponent kernel/ramdisk image,
  673. * - commandline provided address of decicated ramdisk image.
  674. *
  675. * returns:
  676. * 0, if ramdisk image was found and valid, or skiped
  677. * rd_start and rd_end are set to ramdisk start/end addresses if
  678. * ramdisk image is found and valid
  679. *
  680. * 1, if ramdisk image is found but corrupted
  681. * rd_start and rd_end are set to 0 if no ramdisk exists
  682. */
  683. int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images,
  684. uint8_t arch, ulong *rd_start, ulong *rd_end)
  685. {
  686. ulong rd_addr, rd_load;
  687. ulong rd_data, rd_len;
  688. image_header_t *rd_hdr;
  689. #if defined(CONFIG_FIT)
  690. void *fit_hdr;
  691. const char *fit_uname_config = NULL;
  692. const char *fit_uname_ramdisk = NULL;
  693. ulong default_addr;
  694. int rd_noffset;
  695. int cfg_noffset;
  696. const void *data;
  697. size_t size;
  698. #endif
  699. *rd_start = 0;
  700. *rd_end = 0;
  701. /*
  702. * Look for a '-' which indicates to ignore the
  703. * ramdisk argument
  704. */
  705. if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
  706. debug ("## Skipping init Ramdisk\n");
  707. rd_len = rd_data = 0;
  708. } else if (argc >= 3 || genimg_has_config (images)) {
  709. #if defined(CONFIG_FIT)
  710. if (argc >= 3) {
  711. /*
  712. * If the init ramdisk comes from the FIT image and
  713. * the FIT image address is omitted in the command
  714. * line argument, try to use os FIT image address or
  715. * default load address.
  716. */
  717. if (images->fit_uname_os)
  718. default_addr = (ulong)images->fit_hdr_os;
  719. else
  720. default_addr = load_addr;
  721. if (fit_parse_conf (argv[2], default_addr,
  722. &rd_addr, &fit_uname_config)) {
  723. debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
  724. fit_uname_config, rd_addr);
  725. } else if (fit_parse_subimage (argv[2], default_addr,
  726. &rd_addr, &fit_uname_ramdisk)) {
  727. debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
  728. fit_uname_ramdisk, rd_addr);
  729. } else
  730. #endif
  731. {
  732. rd_addr = simple_strtoul(argv[2], NULL, 16);
  733. debug ("* ramdisk: cmdline image address = 0x%08lx\n",
  734. rd_addr);
  735. }
  736. #if defined(CONFIG_FIT)
  737. } else {
  738. /* use FIT configuration provided in first bootm
  739. * command argument
  740. */
  741. rd_addr = (ulong)images->fit_hdr_os;
  742. fit_uname_config = images->fit_uname_cfg;
  743. debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
  744. fit_uname_config, rd_addr);
  745. /*
  746. * Check whether configuration has ramdisk defined,
  747. * if not, don't try to use it, quit silently.
  748. */
  749. fit_hdr = (void *)rd_addr;
  750. cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
  751. if (cfg_noffset < 0) {
  752. debug ("* ramdisk: no such config\n");
  753. return 0;
  754. }
  755. rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
  756. if (rd_noffset < 0) {
  757. debug ("* ramdisk: no ramdisk in config\n");
  758. return 0;
  759. }
  760. }
  761. #endif
  762. /* copy from dataflash if needed */
  763. rd_addr = genimg_get_image (rd_addr);
  764. /*
  765. * Check if there is an initrd image at the
  766. * address provided in the second bootm argument
  767. * check image type, for FIT images get FIT node.
  768. */
  769. switch (genimg_get_format ((void *)rd_addr)) {
  770. case IMAGE_FORMAT_LEGACY:
  771. printf ("## Loading init Ramdisk from Legacy "
  772. "Image at %08lx ...\n", rd_addr);
  773. show_boot_progress (9);
  774. rd_hdr = image_get_ramdisk (rd_addr, arch,
  775. images->verify);
  776. if (rd_hdr == NULL)
  777. return 1;
  778. rd_data = image_get_data (rd_hdr);
  779. rd_len = image_get_data_size (rd_hdr);
  780. rd_load = image_get_load (rd_hdr);
  781. break;
  782. #if defined(CONFIG_FIT)
  783. case IMAGE_FORMAT_FIT:
  784. fit_hdr = (void *)rd_addr;
  785. printf ("## Loading init Ramdisk from FIT "
  786. "Image at %08lx ...\n", rd_addr);
  787. show_boot_progress (120);
  788. if (!fit_check_format (fit_hdr)) {
  789. puts ("Bad FIT ramdisk image format!\n");
  790. show_boot_progress (-120);
  791. return 0;
  792. }
  793. show_boot_progress (121);
  794. if (!fit_uname_ramdisk) {
  795. /*
  796. * no ramdisk image node unit name, try to get config
  797. * node first. If config unit node name is NULL
  798. * fit_conf_get_node() will try to find default config node
  799. */
  800. show_boot_progress (122);
  801. cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
  802. if (cfg_noffset < 0) {
  803. puts ("Could not find configuration node\n");
  804. show_boot_progress (-122);
  805. return 0;
  806. }
  807. fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
  808. printf (" Using '%s' configuration\n", fit_uname_config);
  809. rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
  810. fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
  811. } else {
  812. /* get ramdisk component image node offset */
  813. show_boot_progress (123);
  814. rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
  815. }
  816. if (rd_noffset < 0) {
  817. puts ("Could not find subimage node\n");
  818. show_boot_progress (-124);
  819. return 0;
  820. }
  821. printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
  822. show_boot_progress (125);
  823. if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
  824. return 0;
  825. /* get ramdisk image data address and length */
  826. if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
  827. puts ("Could not find ramdisk subimage data!\n");
  828. show_boot_progress (-127);
  829. return 0;
  830. }
  831. show_boot_progress (128);
  832. rd_data = (ulong)data;
  833. rd_len = size;
  834. if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
  835. puts ("Can't get ramdisk subimage load address!\n");
  836. show_boot_progress (-129);
  837. return 0;
  838. }
  839. show_boot_progress (129);
  840. images->fit_hdr_rd = fit_hdr;
  841. images->fit_uname_rd = fit_uname_ramdisk;
  842. images->fit_noffset_rd = rd_noffset;
  843. break;
  844. #endif
  845. default:
  846. puts ("Wrong Ramdisk Image Format\n");
  847. rd_data = rd_len = rd_load = 0;
  848. }
  849. #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
  850. /*
  851. * We need to copy the ramdisk to SRAM to let Linux boot
  852. */
  853. if (rd_data) {
  854. memmove ((void *)rd_load, (uchar *)rd_data, rd_len);
  855. rd_data = rd_load;
  856. }
  857. #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
  858. } else if (images->legacy_hdr_valid &&
  859. image_check_type (images->legacy_hdr_os, IH_TYPE_MULTI)) {
  860. /*
  861. * Now check if we have a legacy mult-component image,
  862. * get second entry data start address and len.
  863. */
  864. show_boot_progress (13);
  865. printf ("## Loading init Ramdisk from multi component "
  866. "Legacy Image at %08lx ...\n",
  867. (ulong)images->legacy_hdr_os);
  868. image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
  869. } else {
  870. /*
  871. * no initrd image
  872. */
  873. show_boot_progress (14);
  874. rd_len = rd_data = 0;
  875. }
  876. if (!rd_data) {
  877. debug ("## No init Ramdisk\n");
  878. } else {
  879. *rd_start = rd_data;
  880. *rd_end = rd_data + rd_len;
  881. }
  882. debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
  883. *rd_start, *rd_end);
  884. return 0;
  885. }
  886. #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
  887. /**
  888. * boot_ramdisk_high - relocate init ramdisk
  889. * @lmb: pointer to lmb handle, will be used for memory mgmt
  890. * @rd_data: ramdisk data start address
  891. * @rd_len: ramdisk data length
  892. * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
  893. * start address (after possible relocation)
  894. * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
  895. * end address (after possible relocation)
  896. *
  897. * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
  898. * variable and if requested ramdisk data is moved to a specified location.
  899. *
  900. * Initrd_start and initrd_end are set to final (after relocation) ramdisk
  901. * start/end addresses if ramdisk image start and len were provided,
  902. * otherwise set initrd_start and initrd_end set to zeros.
  903. *
  904. * returns:
  905. * 0 - success
  906. * -1 - failure
  907. */
  908. int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
  909. ulong *initrd_start, ulong *initrd_end)
  910. {
  911. char *s;
  912. ulong initrd_high;
  913. int initrd_copy_to_ram = 1;
  914. if ((s = getenv ("initrd_high")) != NULL) {
  915. /* a value of "no" or a similar string will act like 0,
  916. * turning the "load high" feature off. This is intentional.
  917. */
  918. initrd_high = simple_strtoul (s, NULL, 16);
  919. if (initrd_high == ~0)
  920. initrd_copy_to_ram = 0;
  921. } else {
  922. /* not set, no restrictions to load high */
  923. initrd_high = ~0;
  924. }
  925. debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
  926. initrd_high, initrd_copy_to_ram);
  927. if (rd_data) {
  928. if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
  929. debug (" in-place initrd\n");
  930. *initrd_start = rd_data;
  931. *initrd_end = rd_data + rd_len;
  932. lmb_reserve(lmb, rd_data, rd_len);
  933. } else {
  934. if (initrd_high)
  935. *initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
  936. else
  937. *initrd_start = lmb_alloc (lmb, rd_len, 0x1000);
  938. if (*initrd_start == 0) {
  939. puts ("ramdisk - allocation error\n");
  940. goto error;
  941. }
  942. show_boot_progress (12);
  943. *initrd_end = *initrd_start + rd_len;
  944. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  945. *initrd_start, *initrd_end);
  946. memmove_wd ((void *)*initrd_start,
  947. (void *)rd_data, rd_len, CHUNKSZ);
  948. puts ("OK\n");
  949. }
  950. } else {
  951. *initrd_start = 0;
  952. *initrd_end = 0;
  953. }
  954. debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
  955. *initrd_start, *initrd_end);
  956. return 0;
  957. error:
  958. return -1;
  959. }
  960. /**
  961. * boot_get_cmdline - allocate and initialize kernel cmdline
  962. * @lmb: pointer to lmb handle, will be used for memory mgmt
  963. * @cmd_start: pointer to a ulong variable, will hold cmdline start
  964. * @cmd_end: pointer to a ulong variable, will hold cmdline end
  965. * @bootmap_base: ulong variable, holds offset in physical memory to
  966. * base of bootmap
  967. *
  968. * boot_get_cmdline() allocates space for kernel command line below
  969. * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
  970. * variable is present its contents is copied to allocated kernel
  971. * command line.
  972. *
  973. * returns:
  974. * 0 - success
  975. * -1 - failure
  976. */
  977. int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
  978. ulong bootmap_base)
  979. {
  980. char *cmdline;
  981. char *s;
  982. cmdline = (char *)lmb_alloc_base(lmb, CFG_BARGSIZE, 0xf,
  983. CFG_BOOTMAPSZ + bootmap_base);
  984. if (cmdline == NULL)
  985. return -1;
  986. if ((s = getenv("bootargs")) == NULL)
  987. s = "";
  988. strcpy(cmdline, s);
  989. *cmd_start = (ulong) & cmdline[0];
  990. *cmd_end = *cmd_start + strlen(cmdline);
  991. debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
  992. return 0;
  993. }
  994. /**
  995. * boot_get_kbd - allocate and initialize kernel copy of board info
  996. * @lmb: pointer to lmb handle, will be used for memory mgmt
  997. * @kbd: double pointer to board info data
  998. * @bootmap_base: ulong variable, holds offset in physical memory to
  999. * base of bootmap
  1000. *
  1001. * boot_get_kbd() allocates space for kernel copy of board info data below
  1002. * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
  1003. * the current u-boot board info data.
  1004. *
  1005. * returns:
  1006. * 0 - success
  1007. * -1 - failure
  1008. */
  1009. int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
  1010. {
  1011. *kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
  1012. CFG_BOOTMAPSZ + bootmap_base);
  1013. if (*kbd == NULL)
  1014. return -1;
  1015. **kbd = *(gd->bd);
  1016. debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
  1017. #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
  1018. do_bdinfo(NULL, 0, 0, NULL);
  1019. #endif
  1020. return 0;
  1021. }
  1022. #endif /* CONFIG_PPC || CONFIG_M68K */
  1023. #endif /* !USE_HOSTCC */
  1024. #if defined(CONFIG_FIT)
  1025. /*****************************************************************************/
  1026. /* New uImage format routines */
  1027. /*****************************************************************************/
  1028. #ifndef USE_HOSTCC
  1029. static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
  1030. ulong *addr, const char **name)
  1031. {
  1032. const char *sep;
  1033. *addr = addr_curr;
  1034. *name = NULL;
  1035. sep = strchr (spec, sepc);
  1036. if (sep) {
  1037. if (sep - spec > 0)
  1038. *addr = simple_strtoul (spec, NULL, 16);
  1039. *name = sep + 1;
  1040. return 1;
  1041. }
  1042. return 0;
  1043. }
  1044. /**
  1045. * fit_parse_conf - parse FIT configuration spec
  1046. * @spec: input string, containing configuration spec
  1047. * @add_curr: current image address (to be used as a possible default)
  1048. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1049. * configuration
  1050. * @conf_name double pointer to a char, will hold pointer to a configuration
  1051. * unit name
  1052. *
  1053. * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
  1054. * where <addr> is a FIT image address that contains configuration
  1055. * with a <conf> unit name.
  1056. *
  1057. * Address part is optional, and if omitted default add_curr will
  1058. * be used instead.
  1059. *
  1060. * returns:
  1061. * 1 if spec is a valid configuration string,
  1062. * addr and conf_name are set accordingly
  1063. * 0 otherwise
  1064. */
  1065. inline int fit_parse_conf (const char *spec, ulong addr_curr,
  1066. ulong *addr, const char **conf_name)
  1067. {
  1068. return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
  1069. }
  1070. /**
  1071. * fit_parse_subimage - parse FIT subimage spec
  1072. * @spec: input string, containing subimage spec
  1073. * @add_curr: current image address (to be used as a possible default)
  1074. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1075. * subimage
  1076. * @image_name: double pointer to a char, will hold pointer to a subimage name
  1077. *
  1078. * fit_parse_subimage() expects subimage spec in the for of
  1079. * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
  1080. * subimage with a <subimg> unit name.
  1081. *
  1082. * Address part is optional, and if omitted default add_curr will
  1083. * be used instead.
  1084. *
  1085. * returns:
  1086. * 1 if spec is a valid subimage string,
  1087. * addr and image_name are set accordingly
  1088. * 0 otherwise
  1089. */
  1090. inline int fit_parse_subimage (const char *spec, ulong addr_curr,
  1091. ulong *addr, const char **image_name)
  1092. {
  1093. return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
  1094. }
  1095. #endif /* !USE_HOSTCC */
  1096. static void fit_get_debug (const void *fit, int noffset,
  1097. char *prop_name, int err)
  1098. {
  1099. debug ("Can't get '%s' property from FIT 0x%08lx, "
  1100. "node: offset %d, name %s (%s)\n",
  1101. prop_name, (ulong)fit, noffset,
  1102. fit_get_name (fit, noffset, NULL),
  1103. fdt_strerror (err));
  1104. }
  1105. /**
  1106. * __fit_print_contents - prints out the contents of the FIT format image
  1107. * @fit: pointer to the FIT format image header
  1108. * @p: pointer to prefix string
  1109. *
  1110. * __fit_print_contents() formats a multi line FIT image contents description.
  1111. * The routine prints out FIT image properties (root node level) follwed by
  1112. * the details of each component image.
  1113. *
  1114. * returns:
  1115. * no returned results
  1116. */
  1117. static void __fit_print_contents (const void *fit, const char *p)
  1118. {
  1119. char *desc;
  1120. char *uname;
  1121. int images_noffset;
  1122. int confs_noffset;
  1123. int noffset;
  1124. int ndepth;
  1125. int count = 0;
  1126. int ret;
  1127. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1128. time_t timestamp;
  1129. #endif
  1130. /* Root node properties */
  1131. ret = fit_get_desc (fit, 0, &desc);
  1132. printf ("%sFIT description: ", p);
  1133. if (ret)
  1134. printf ("unavailable\n");
  1135. else
  1136. printf ("%s\n", desc);
  1137. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1138. ret = fit_get_timestamp (fit, 0, &timestamp);
  1139. printf ("%sCreated: ", p);
  1140. if (ret)
  1141. printf ("unavailable\n");
  1142. else
  1143. genimg_print_time (timestamp);
  1144. #endif
  1145. /* Find images parent node offset */
  1146. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1147. if (images_noffset < 0) {
  1148. printf ("Can't find images parent node '%s' (%s)\n",
  1149. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1150. return;
  1151. }
  1152. /* Process its subnodes, print out component images details */
  1153. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
  1154. (noffset >= 0) && (ndepth > 0);
  1155. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1156. if (ndepth == 1) {
  1157. /*
  1158. * Direct child node of the images parent node,
  1159. * i.e. component image node.
  1160. */
  1161. printf ("%s Image %u (%s)\n", p, count++,
  1162. fit_get_name(fit, noffset, NULL));
  1163. fit_image_print (fit, noffset, p);
  1164. }
  1165. }
  1166. /* Find configurations parent node offset */
  1167. confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
  1168. if (confs_noffset < 0) {
  1169. debug ("Can't get configurations parent node '%s' (%s)\n",
  1170. FIT_CONFS_PATH, fdt_strerror (confs_noffset));
  1171. return;
  1172. }
  1173. /* get default configuration unit name from default property */
  1174. uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
  1175. if (uname)
  1176. printf ("%s Default Configuration: '%s'\n", p, uname);
  1177. /* Process its subnodes, print out configurations details */
  1178. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
  1179. (noffset >= 0) && (ndepth > 0);
  1180. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1181. if (ndepth == 1) {
  1182. /*
  1183. * Direct child node of the configurations parent node,
  1184. * i.e. configuration node.
  1185. */
  1186. printf ("%s Configuration %u (%s)\n", p, count++,
  1187. fit_get_name(fit, noffset, NULL));
  1188. fit_conf_print (fit, noffset, p);
  1189. }
  1190. }
  1191. }
  1192. inline void fit_print_contents (const void *fit)
  1193. {
  1194. __fit_print_contents (fit, " ");
  1195. }
  1196. inline void fit_print_contents_noindent (const void *fit)
  1197. {
  1198. __fit_print_contents (fit, "");
  1199. }
  1200. /**
  1201. * fit_image_print - prints out the FIT component image details
  1202. * @fit: pointer to the FIT format image header
  1203. * @image_noffset: offset of the component image node
  1204. * @p: pointer to prefix string
  1205. *
  1206. * fit_image_print() lists all mandatory properies for the processed component
  1207. * image. If present, hash nodes are printed out as well.
  1208. *
  1209. * returns:
  1210. * no returned results
  1211. */
  1212. void fit_image_print (const void *fit, int image_noffset, const char *p)
  1213. {
  1214. char *desc;
  1215. uint8_t type, arch, os, comp;
  1216. size_t size;
  1217. ulong load, entry;
  1218. const void *data;
  1219. int noffset;
  1220. int ndepth;
  1221. int ret;
  1222. /* Mandatory properties */
  1223. ret = fit_get_desc (fit, image_noffset, &desc);
  1224. printf ("%s Description: ", p);
  1225. if (ret)
  1226. printf ("unavailable\n");
  1227. else
  1228. printf ("%s\n", desc);
  1229. fit_image_get_type (fit, image_noffset, &type);
  1230. printf ("%s Type: %s\n", p, genimg_get_type_name (type));
  1231. fit_image_get_comp (fit, image_noffset, &comp);
  1232. printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
  1233. ret = fit_image_get_data (fit, image_noffset, &data, &size);
  1234. #ifndef USE_HOSTCC
  1235. printf ("%s Data Start: ", p);
  1236. if (ret)
  1237. printf ("unavailable\n");
  1238. else
  1239. printf ("0x%08lx\n", (ulong)data);
  1240. #endif
  1241. printf ("%s Data Size: ", p);
  1242. if (ret)
  1243. printf ("unavailable\n");
  1244. else
  1245. genimg_print_size (size);
  1246. /* Remaining, type dependent properties */
  1247. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
  1248. (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
  1249. (type == IH_TYPE_FLATDT)) {
  1250. fit_image_get_arch (fit, image_noffset, &arch);
  1251. printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
  1252. }
  1253. if (type == IH_TYPE_KERNEL) {
  1254. fit_image_get_os (fit, image_noffset, &os);
  1255. printf ("%s OS: %s\n", p, genimg_get_os_name (os));
  1256. }
  1257. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
  1258. ret = fit_image_get_load (fit, image_noffset, &load);
  1259. printf ("%s Load Address: ", p);
  1260. if (ret)
  1261. printf ("unavailable\n");
  1262. else
  1263. printf ("0x%08lx\n", load);
  1264. fit_image_get_entry (fit, image_noffset, &entry);
  1265. printf ("%s Entry Point: ", p);
  1266. if (ret)
  1267. printf ("unavailable\n");
  1268. else
  1269. printf ("0x%08lx\n", entry);
  1270. }
  1271. /* Process all hash subnodes of the component image node */
  1272. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1273. (noffset >= 0) && (ndepth > 0);
  1274. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1275. if (ndepth == 1) {
  1276. /* Direct child node of the component image node */
  1277. fit_image_print_hash (fit, noffset, p);
  1278. }
  1279. }
  1280. }
  1281. /**
  1282. * fit_image_print_hash - prints out the hash node details
  1283. * @fit: pointer to the FIT format image header
  1284. * @noffset: offset of the hash node
  1285. * @p: pointer to prefix string
  1286. *
  1287. * fit_image_print_hash() lists properies for the processed hash node
  1288. *
  1289. * returns:
  1290. * no returned results
  1291. */
  1292. void fit_image_print_hash (const void *fit, int noffset, const char *p)
  1293. {
  1294. char *algo;
  1295. uint8_t *value;
  1296. int value_len;
  1297. int i, ret;
  1298. /*
  1299. * Check subnode name, must be equal to "hash".
  1300. * Multiple hash nodes require unique unit node
  1301. * names, e.g. hash@1, hash@2, etc.
  1302. */
  1303. if (strncmp (fit_get_name(fit, noffset, NULL),
  1304. FIT_HASH_NODENAME,
  1305. strlen(FIT_HASH_NODENAME)) != 0)
  1306. return;
  1307. debug ("%s Hash node: '%s'\n", p,
  1308. fit_get_name (fit, noffset, NULL));
  1309. printf ("%s Hash algo: ", p);
  1310. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1311. printf ("invalid/unsupported\n");
  1312. return;
  1313. }
  1314. printf ("%s\n", algo);
  1315. ret = fit_image_hash_get_value (fit, noffset, &value,
  1316. &value_len);
  1317. printf ("%s Hash value: ", p);
  1318. if (ret) {
  1319. printf ("unavailable\n");
  1320. } else {
  1321. for (i = 0; i < value_len; i++)
  1322. printf ("%02x", value[i]);
  1323. printf ("\n");
  1324. }
  1325. debug ("%s Hash len: %d\n", p, value_len);
  1326. }
  1327. /**
  1328. * fit_get_desc - get node description property
  1329. * @fit: pointer to the FIT format image header
  1330. * @noffset: node offset
  1331. * @desc: double pointer to the char, will hold pointer to the descrption
  1332. *
  1333. * fit_get_desc() reads description property from a given node, if
  1334. * description is found pointer to it is returened in third call argument.
  1335. *
  1336. * returns:
  1337. * 0, on success
  1338. * -1, on failure
  1339. */
  1340. int fit_get_desc (const void *fit, int noffset, char **desc)
  1341. {
  1342. int len;
  1343. *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
  1344. if (*desc == NULL) {
  1345. fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
  1346. return -1;
  1347. }
  1348. return 0;
  1349. }
  1350. /**
  1351. * fit_get_timestamp - get node timestamp property
  1352. * @fit: pointer to the FIT format image header
  1353. * @noffset: node offset
  1354. * @timestamp: pointer to the time_t, will hold read timestamp
  1355. *
  1356. * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
  1357. * is found and has a correct size its value is retured in third call
  1358. * argument.
  1359. *
  1360. * returns:
  1361. * 0, on success
  1362. * -1, on property read failure
  1363. * -2, on wrong timestamp size
  1364. */
  1365. int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
  1366. {
  1367. int len;
  1368. const void *data;
  1369. data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
  1370. if (data == NULL) {
  1371. fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
  1372. return -1;
  1373. }
  1374. if (len != sizeof (uint32_t)) {
  1375. debug ("FIT timestamp with incorrect size of (%u)\n", len);
  1376. return -2;
  1377. }
  1378. *timestamp = uimage_to_cpu (*((uint32_t *)data));
  1379. return 0;
  1380. }
  1381. /**
  1382. * fit_image_get_node - get node offset for component image of a given unit name
  1383. * @fit: pointer to the FIT format image header
  1384. * @image_uname: component image node unit name
  1385. *
  1386. * fit_image_get_node() finds a component image (withing the '/images'
  1387. * node) of a provided unit name. If image is found its node offset is
  1388. * returned to the caller.
  1389. *
  1390. * returns:
  1391. * image node offset when found (>=0)
  1392. * negative number on failure (FDT_ERR_* code)
  1393. */
  1394. int fit_image_get_node (const void *fit, const char *image_uname)
  1395. {
  1396. int noffset, images_noffset;
  1397. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1398. if (images_noffset < 0) {
  1399. debug ("Can't find images parent node '%s' (%s)\n",
  1400. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1401. return images_noffset;
  1402. }
  1403. noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
  1404. if (noffset < 0) {
  1405. debug ("Can't get node offset for image unit name: '%s' (%s)\n",
  1406. image_uname, fdt_strerror (noffset));
  1407. }
  1408. return noffset;
  1409. }
  1410. /**
  1411. * fit_image_get_os - get os id for a given component image node
  1412. * @fit: pointer to the FIT format image header
  1413. * @noffset: component image node offset
  1414. * @os: pointer to the uint8_t, will hold os numeric id
  1415. *
  1416. * fit_image_get_os() finds os property in a given component image node.
  1417. * If the property is found, its (string) value is translated to the numeric
  1418. * id which is returned to the caller.
  1419. *
  1420. * returns:
  1421. * 0, on success
  1422. * -1, on failure
  1423. */
  1424. int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
  1425. {
  1426. int len;
  1427. const void *data;
  1428. /* Get OS name from property data */
  1429. data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
  1430. if (data == NULL) {
  1431. fit_get_debug (fit, noffset, FIT_OS_PROP, len);
  1432. *os = -1;
  1433. return -1;
  1434. }
  1435. /* Translate OS name to id */
  1436. *os = genimg_get_os_id (data);
  1437. return 0;
  1438. }
  1439. /**
  1440. * fit_image_get_arch - get arch id for a given component image node
  1441. * @fit: pointer to the FIT format image header
  1442. * @noffset: component image node offset
  1443. * @arch: pointer to the uint8_t, will hold arch numeric id
  1444. *
  1445. * fit_image_get_arch() finds arch property in a given component image node.
  1446. * If the property is found, its (string) value is translated to the numeric
  1447. * id which is returned to the caller.
  1448. *
  1449. * returns:
  1450. * 0, on success
  1451. * -1, on failure
  1452. */
  1453. int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
  1454. {
  1455. int len;
  1456. const void *data;
  1457. /* Get architecture name from property data */
  1458. data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
  1459. if (data == NULL) {
  1460. fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
  1461. *arch = -1;
  1462. return -1;
  1463. }
  1464. /* Translate architecture name to id */
  1465. *arch = genimg_get_arch_id (data);
  1466. return 0;
  1467. }
  1468. /**
  1469. * fit_image_get_type - get type id for a given component image node
  1470. * @fit: pointer to the FIT format image header
  1471. * @noffset: component image node offset
  1472. * @type: pointer to the uint8_t, will hold type numeric id
  1473. *
  1474. * fit_image_get_type() finds type property in a given component image node.
  1475. * If the property is found, its (string) value is translated to the numeric
  1476. * id which is returned to the caller.
  1477. *
  1478. * returns:
  1479. * 0, on success
  1480. * -1, on failure
  1481. */
  1482. int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
  1483. {
  1484. int len;
  1485. const void *data;
  1486. /* Get image type name from property data */
  1487. data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
  1488. if (data == NULL) {
  1489. fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
  1490. *type = -1;
  1491. return -1;
  1492. }
  1493. /* Translate image type name to id */
  1494. *type = genimg_get_type_id (data);
  1495. return 0;
  1496. }
  1497. /**
  1498. * fit_image_get_comp - get comp id for a given component image node
  1499. * @fit: pointer to the FIT format image header
  1500. * @noffset: component image node offset
  1501. * @comp: pointer to the uint8_t, will hold comp numeric id
  1502. *
  1503. * fit_image_get_comp() finds comp property in a given component image node.
  1504. * If the property is found, its (string) value is translated to the numeric
  1505. * id which is returned to the caller.
  1506. *
  1507. * returns:
  1508. * 0, on success
  1509. * -1, on failure
  1510. */
  1511. int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
  1512. {
  1513. int len;
  1514. const void *data;
  1515. /* Get compression name from property data */
  1516. data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
  1517. if (data == NULL) {
  1518. fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
  1519. *comp = -1;
  1520. return -1;
  1521. }
  1522. /* Translate compression name to id */
  1523. *comp = genimg_get_comp_id (data);
  1524. return 0;
  1525. }
  1526. /**
  1527. * fit_image_get_load - get load address property for a given component image node
  1528. * @fit: pointer to the FIT format image header
  1529. * @noffset: component image node offset
  1530. * @load: pointer to the uint32_t, will hold load address
  1531. *
  1532. * fit_image_get_load() finds load address property in a given component image node.
  1533. * If the property is found, its value is returned to the caller.
  1534. *
  1535. * returns:
  1536. * 0, on success
  1537. * -1, on failure
  1538. */
  1539. int fit_image_get_load (const void *fit, int noffset, ulong *load)
  1540. {
  1541. int len;
  1542. const uint32_t *data;
  1543. data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
  1544. if (data == NULL) {
  1545. fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
  1546. return -1;
  1547. }
  1548. *load = uimage_to_cpu (*data);
  1549. return 0;
  1550. }
  1551. /**
  1552. * fit_image_get_entry - get entry point address property for a given component image node
  1553. * @fit: pointer to the FIT format image header
  1554. * @noffset: component image node offset
  1555. * @entry: pointer to the uint32_t, will hold entry point address
  1556. *
  1557. * fit_image_get_entry() finds entry point address property in a given component image node.
  1558. * If the property is found, its value is returned to the caller.
  1559. *
  1560. * returns:
  1561. * 0, on success
  1562. * -1, on failure
  1563. */
  1564. int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
  1565. {
  1566. int len;
  1567. const uint32_t *data;
  1568. data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
  1569. if (data == NULL) {
  1570. fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
  1571. return -1;
  1572. }
  1573. *entry = uimage_to_cpu (*data);
  1574. return 0;
  1575. }
  1576. /**
  1577. * fit_image_get_data - get data property and its size for a given component image node
  1578. * @fit: pointer to the FIT format image header
  1579. * @noffset: component image node offset
  1580. * @data: double pointer to void, will hold data property's data address
  1581. * @size: pointer to size_t, will hold data property's data size
  1582. *
  1583. * fit_image_get_data() finds data property in a given component image node.
  1584. * If the property is found its data start address and size are returned to
  1585. * the caller.
  1586. *
  1587. * returns:
  1588. * 0, on success
  1589. * -1, on failure
  1590. */
  1591. int fit_image_get_data (const void *fit, int noffset,
  1592. const void **data, size_t *size)
  1593. {
  1594. int len;
  1595. *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
  1596. if (*data == NULL) {
  1597. fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
  1598. *size = 0;
  1599. return -1;
  1600. }
  1601. *size = len;
  1602. return 0;
  1603. }
  1604. /**
  1605. * fit_image_hash_get_algo - get hash algorithm name
  1606. * @fit: pointer to the FIT format image header
  1607. * @noffset: hash node offset
  1608. * @algo: double pointer to char, will hold pointer to the algorithm name
  1609. *
  1610. * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
  1611. * If the property is found its data start address is returned to the caller.
  1612. *
  1613. * returns:
  1614. * 0, on success
  1615. * -1, on failure
  1616. */
  1617. int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
  1618. {
  1619. int len;
  1620. *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
  1621. if (*algo == NULL) {
  1622. fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
  1623. return -1;
  1624. }
  1625. return 0;
  1626. }
  1627. /**
  1628. * fit_image_hash_get_value - get hash value and length
  1629. * @fit: pointer to the FIT format image header
  1630. * @noffset: hash node offset
  1631. * @value: double pointer to uint8_t, will hold address of a hash value data
  1632. * @value_len: pointer to an int, will hold hash data length
  1633. *
  1634. * fit_image_hash_get_value() finds hash value property in a given hash node.
  1635. * If the property is found its data start address and size are returned to
  1636. * the caller.
  1637. *
  1638. * returns:
  1639. * 0, on success
  1640. * -1, on failure
  1641. */
  1642. int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
  1643. int *value_len)
  1644. {
  1645. int len;
  1646. *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
  1647. if (*value == NULL) {
  1648. fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
  1649. *value_len = 0;
  1650. return -1;
  1651. }
  1652. *value_len = len;
  1653. return 0;
  1654. }
  1655. /**
  1656. * fit_set_timestamp - set node timestamp property
  1657. * @fit: pointer to the FIT format image header
  1658. * @noffset: node offset
  1659. * @timestamp: timestamp value to be set
  1660. *
  1661. * fit_set_timestamp() attempts to set timestamp property in the requested
  1662. * node and returns operation status to the caller.
  1663. *
  1664. * returns:
  1665. * 0, on success
  1666. * -1, on property read failure
  1667. */
  1668. int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
  1669. {
  1670. uint32_t t;
  1671. int ret;
  1672. t = cpu_to_uimage (timestamp);
  1673. ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
  1674. sizeof (uint32_t));
  1675. if (ret) {
  1676. printf ("Can't set '%s' property for '%s' node (%s)\n",
  1677. FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
  1678. fdt_strerror (ret));
  1679. return -1;
  1680. }
  1681. return 0;
  1682. }
  1683. /**
  1684. * calculate_hash - calculate and return hash for provided input data
  1685. * @data: pointer to the input data
  1686. * @data_len: data length
  1687. * @algo: requested hash algorithm
  1688. * @value: pointer to the char, will hold hash value data (caller must
  1689. * allocate enough free space)
  1690. * value_len: length of the calculated hash
  1691. *
  1692. * calculate_hash() computes input data hash according to the requested algorithm.
  1693. * Resulting hash value is placed in caller provided 'value' buffer, length
  1694. * of the calculated hash is returned via value_len pointer argument.
  1695. *
  1696. * returns:
  1697. * 0, on success
  1698. * -1, when algo is unsupported
  1699. */
  1700. static int calculate_hash (const void *data, int data_len, const char *algo,
  1701. uint8_t *value, int *value_len)
  1702. {
  1703. if (strcmp (algo, "crc32") == 0 ) {
  1704. *((uint32_t *)value) = crc32 (0, data, data_len);
  1705. *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
  1706. *value_len = 4;
  1707. } else if (strcmp (algo, "sha1") == 0 ) {
  1708. sha1_csum ((unsigned char *) data, data_len,
  1709. (unsigned char *) value);
  1710. *value_len = 20;
  1711. } else if (strcmp (algo, "md5") == 0 ) {
  1712. printf ("MD5 not supported\n");
  1713. *value_len = 0;
  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 */