image.c 83 KB

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