image.c 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084
  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. int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base,
  1047. char **of_flat_tree, ulong *of_size)
  1048. {
  1049. char *fdt_blob = *of_flat_tree;
  1050. ulong relocate = 0;
  1051. ulong of_len = 0;
  1052. /* nothing to do */
  1053. if (*of_size == 0)
  1054. return 0;
  1055. if (fdt_check_header (fdt_blob) != 0) {
  1056. fdt_error ("image is not a fdt");
  1057. goto error;
  1058. }
  1059. #ifndef CONFIG_SYS_NO_FLASH
  1060. /* move the blob if it is in flash (set relocate) */
  1061. if (addr2info ((ulong)fdt_blob) != NULL)
  1062. relocate = 1;
  1063. #endif
  1064. /*
  1065. * The blob needs to be inside the boot mapping.
  1066. */
  1067. if (fdt_blob < (char *)bootmap_base)
  1068. relocate = 1;
  1069. if ((fdt_blob + *of_size + CONFIG_SYS_FDT_PAD) >=
  1070. ((char *)CONFIG_SYS_BOOTMAPSZ + bootmap_base))
  1071. relocate = 1;
  1072. /* move flattend device tree if needed */
  1073. if (relocate) {
  1074. int err;
  1075. ulong of_start = 0;
  1076. /* position on a 4K boundary before the alloc_current */
  1077. /* Pad the FDT by a specified amount */
  1078. of_len = *of_size + CONFIG_SYS_FDT_PAD;
  1079. of_start = (unsigned long)lmb_alloc_base(lmb, of_len, 0x1000,
  1080. (CONFIG_SYS_BOOTMAPSZ + bootmap_base));
  1081. if (of_start == 0) {
  1082. puts("device tree - allocation error\n");
  1083. goto error;
  1084. }
  1085. debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
  1086. (ulong)fdt_blob, (ulong)fdt_blob + *of_size - 1,
  1087. of_len, of_len);
  1088. printf (" Loading Device Tree to %08lx, end %08lx ... ",
  1089. of_start, of_start + of_len - 1);
  1090. err = fdt_open_into (fdt_blob, (void *)of_start, of_len);
  1091. if (err != 0) {
  1092. fdt_error ("fdt move failed");
  1093. goto error;
  1094. }
  1095. puts ("OK\n");
  1096. *of_flat_tree = (char *)of_start;
  1097. *of_size = of_len;
  1098. } else {
  1099. *of_flat_tree = fdt_blob;
  1100. of_len = (CONFIG_SYS_BOOTMAPSZ + bootmap_base) - (ulong)fdt_blob;
  1101. lmb_reserve(lmb, (ulong)fdt_blob, of_len);
  1102. fdt_set_totalsize(*of_flat_tree, of_len);
  1103. *of_size = of_len;
  1104. }
  1105. set_working_fdt_addr(*of_flat_tree);
  1106. return 0;
  1107. error:
  1108. return 1;
  1109. }
  1110. /**
  1111. * boot_get_fdt - main fdt handling routine
  1112. * @argc: command argument count
  1113. * @argv: command argument list
  1114. * @images: pointer to the bootm images structure
  1115. * @of_flat_tree: pointer to a char* variable, will hold fdt start address
  1116. * @of_size: pointer to a ulong variable, will hold fdt length
  1117. *
  1118. * boot_get_fdt() is responsible for finding a valid flat device tree image.
  1119. * Curently supported are the following ramdisk sources:
  1120. * - multicomponent kernel/ramdisk image,
  1121. * - commandline provided address of decicated ramdisk image.
  1122. *
  1123. * returns:
  1124. * 0, if fdt image was found and valid, or skipped
  1125. * of_flat_tree and of_size are set to fdt start address and length if
  1126. * fdt image is found and valid
  1127. *
  1128. * 1, if fdt image is found but corrupted
  1129. * of_flat_tree and of_size are set to 0 if no fdt exists
  1130. */
  1131. int boot_get_fdt (int flag, int argc, char * const argv[], bootm_headers_t *images,
  1132. char **of_flat_tree, ulong *of_size)
  1133. {
  1134. const image_header_t *fdt_hdr;
  1135. ulong fdt_addr;
  1136. char *fdt_blob = NULL;
  1137. ulong image_start, image_end;
  1138. ulong load_start, load_end;
  1139. #if defined(CONFIG_FIT)
  1140. void *fit_hdr;
  1141. const char *fit_uname_config = NULL;
  1142. const char *fit_uname_fdt = NULL;
  1143. ulong default_addr;
  1144. int cfg_noffset;
  1145. int fdt_noffset;
  1146. const void *data;
  1147. size_t size;
  1148. #endif
  1149. *of_flat_tree = NULL;
  1150. *of_size = 0;
  1151. if (argc > 3 || genimg_has_config (images)) {
  1152. #if defined(CONFIG_FIT)
  1153. if (argc > 3) {
  1154. /*
  1155. * If the FDT blob comes from the FIT image and the
  1156. * FIT image address is omitted in the command line
  1157. * argument, try to use ramdisk or os FIT image
  1158. * address or default load address.
  1159. */
  1160. if (images->fit_uname_rd)
  1161. default_addr = (ulong)images->fit_hdr_rd;
  1162. else if (images->fit_uname_os)
  1163. default_addr = (ulong)images->fit_hdr_os;
  1164. else
  1165. default_addr = load_addr;
  1166. if (fit_parse_conf (argv[3], default_addr,
  1167. &fdt_addr, &fit_uname_config)) {
  1168. debug ("* fdt: config '%s' from image at 0x%08lx\n",
  1169. fit_uname_config, fdt_addr);
  1170. } else if (fit_parse_subimage (argv[3], default_addr,
  1171. &fdt_addr, &fit_uname_fdt)) {
  1172. debug ("* fdt: subimage '%s' from image at 0x%08lx\n",
  1173. fit_uname_fdt, fdt_addr);
  1174. } else
  1175. #endif
  1176. {
  1177. fdt_addr = simple_strtoul(argv[3], NULL, 16);
  1178. debug ("* fdt: cmdline image address = 0x%08lx\n",
  1179. fdt_addr);
  1180. }
  1181. #if defined(CONFIG_FIT)
  1182. } else {
  1183. /* use FIT configuration provided in first bootm
  1184. * command argument
  1185. */
  1186. fdt_addr = (ulong)images->fit_hdr_os;
  1187. fit_uname_config = images->fit_uname_cfg;
  1188. debug ("* fdt: using config '%s' from image at 0x%08lx\n",
  1189. fit_uname_config, fdt_addr);
  1190. /*
  1191. * Check whether configuration has FDT blob defined,
  1192. * if not quit silently.
  1193. */
  1194. fit_hdr = (void *)fdt_addr;
  1195. cfg_noffset = fit_conf_get_node (fit_hdr,
  1196. fit_uname_config);
  1197. if (cfg_noffset < 0) {
  1198. debug ("* fdt: no such config\n");
  1199. return 0;
  1200. }
  1201. fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
  1202. cfg_noffset);
  1203. if (fdt_noffset < 0) {
  1204. debug ("* fdt: no fdt in config\n");
  1205. return 0;
  1206. }
  1207. }
  1208. #endif
  1209. debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n",
  1210. fdt_addr);
  1211. /* copy from dataflash if needed */
  1212. fdt_addr = genimg_get_image (fdt_addr);
  1213. /*
  1214. * Check if there is an FDT image at the
  1215. * address provided in the second bootm argument
  1216. * check image type, for FIT images get a FIT node.
  1217. */
  1218. switch (genimg_get_format ((void *)fdt_addr)) {
  1219. case IMAGE_FORMAT_LEGACY:
  1220. /* verify fdt_addr points to a valid image header */
  1221. printf ("## Flattened Device Tree from Legacy Image at %08lx\n",
  1222. fdt_addr);
  1223. fdt_hdr = image_get_fdt (fdt_addr);
  1224. if (!fdt_hdr)
  1225. goto error;
  1226. /*
  1227. * move image data to the load address,
  1228. * make sure we don't overwrite initial image
  1229. */
  1230. image_start = (ulong)fdt_hdr;
  1231. image_end = image_get_image_end (fdt_hdr);
  1232. load_start = image_get_load (fdt_hdr);
  1233. load_end = load_start + image_get_data_size (fdt_hdr);
  1234. if ((load_start < image_end) && (load_end > image_start)) {
  1235. fdt_error ("fdt overwritten");
  1236. goto error;
  1237. }
  1238. debug (" Loading FDT from 0x%08lx to 0x%08lx\n",
  1239. image_get_data (fdt_hdr), load_start);
  1240. memmove ((void *)load_start,
  1241. (void *)image_get_data (fdt_hdr),
  1242. image_get_data_size (fdt_hdr));
  1243. fdt_blob = (char *)load_start;
  1244. break;
  1245. case IMAGE_FORMAT_FIT:
  1246. /*
  1247. * This case will catch both: new uImage format
  1248. * (libfdt based) and raw FDT blob (also libfdt
  1249. * based).
  1250. */
  1251. #if defined(CONFIG_FIT)
  1252. /* check FDT blob vs FIT blob */
  1253. if (fit_check_format ((const void *)fdt_addr)) {
  1254. /*
  1255. * FIT image
  1256. */
  1257. fit_hdr = (void *)fdt_addr;
  1258. printf ("## Flattened Device Tree from FIT Image at %08lx\n",
  1259. fdt_addr);
  1260. if (!fit_uname_fdt) {
  1261. /*
  1262. * no FDT blob image node unit name,
  1263. * try to get config node first. If
  1264. * config unit node name is NULL
  1265. * fit_conf_get_node() will try to
  1266. * find default config node
  1267. */
  1268. cfg_noffset = fit_conf_get_node (fit_hdr,
  1269. fit_uname_config);
  1270. if (cfg_noffset < 0) {
  1271. fdt_error ("Could not find configuration node\n");
  1272. goto error;
  1273. }
  1274. fit_uname_config = fdt_get_name (fit_hdr,
  1275. cfg_noffset, NULL);
  1276. printf (" Using '%s' configuration\n",
  1277. fit_uname_config);
  1278. fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
  1279. cfg_noffset);
  1280. fit_uname_fdt = fit_get_name (fit_hdr,
  1281. fdt_noffset, NULL);
  1282. } else {
  1283. /* get FDT component image node offset */
  1284. fdt_noffset = fit_image_get_node (fit_hdr,
  1285. fit_uname_fdt);
  1286. }
  1287. if (fdt_noffset < 0) {
  1288. fdt_error ("Could not find subimage node\n");
  1289. goto error;
  1290. }
  1291. printf (" Trying '%s' FDT blob subimage\n",
  1292. fit_uname_fdt);
  1293. if (!fit_check_fdt (fit_hdr, fdt_noffset,
  1294. images->verify))
  1295. goto error;
  1296. /* get ramdisk image data address and length */
  1297. if (fit_image_get_data (fit_hdr, fdt_noffset,
  1298. &data, &size)) {
  1299. fdt_error ("Could not find FDT subimage data");
  1300. goto error;
  1301. }
  1302. /* verift that image data is a proper FDT blob */
  1303. if (fdt_check_header ((char *)data) != 0) {
  1304. fdt_error ("Subimage data is not a FTD");
  1305. goto error;
  1306. }
  1307. /*
  1308. * move image data to the load address,
  1309. * make sure we don't overwrite initial image
  1310. */
  1311. image_start = (ulong)fit_hdr;
  1312. image_end = fit_get_end (fit_hdr);
  1313. if (fit_image_get_load (fit_hdr, fdt_noffset,
  1314. &load_start) == 0) {
  1315. load_end = load_start + size;
  1316. if ((load_start < image_end) &&
  1317. (load_end > image_start)) {
  1318. fdt_error ("FDT overwritten");
  1319. goto error;
  1320. }
  1321. printf (" Loading FDT from 0x%08lx to 0x%08lx\n",
  1322. (ulong)data, load_start);
  1323. memmove ((void *)load_start,
  1324. (void *)data, size);
  1325. fdt_blob = (char *)load_start;
  1326. } else {
  1327. fdt_blob = (char *)data;
  1328. }
  1329. images->fit_hdr_fdt = fit_hdr;
  1330. images->fit_uname_fdt = fit_uname_fdt;
  1331. images->fit_noffset_fdt = fdt_noffset;
  1332. break;
  1333. } else
  1334. #endif
  1335. {
  1336. /*
  1337. * FDT blob
  1338. */
  1339. fdt_blob = (char *)fdt_addr;
  1340. debug ("* fdt: raw FDT blob\n");
  1341. printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob);
  1342. }
  1343. break;
  1344. default:
  1345. puts ("ERROR: Did not find a cmdline Flattened Device Tree\n");
  1346. goto error;
  1347. }
  1348. printf (" Booting using the fdt blob at 0x%x\n", (int)fdt_blob);
  1349. } else if (images->legacy_hdr_valid &&
  1350. image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
  1351. ulong fdt_data, fdt_len;
  1352. /*
  1353. * Now check if we have a legacy multi-component image,
  1354. * get second entry data start address and len.
  1355. */
  1356. printf ("## Flattened Device Tree from multi "
  1357. "component Image at %08lX\n",
  1358. (ulong)images->legacy_hdr_os);
  1359. image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len);
  1360. if (fdt_len) {
  1361. fdt_blob = (char *)fdt_data;
  1362. printf (" Booting using the fdt at 0x%x\n", (int)fdt_blob);
  1363. if (fdt_check_header (fdt_blob) != 0) {
  1364. fdt_error ("image is not a fdt");
  1365. goto error;
  1366. }
  1367. if (be32_to_cpu (fdt_totalsize (fdt_blob)) != fdt_len) {
  1368. fdt_error ("fdt size != image size");
  1369. goto error;
  1370. }
  1371. } else {
  1372. debug ("## No Flattened Device Tree\n");
  1373. return 0;
  1374. }
  1375. } else {
  1376. debug ("## No Flattened Device Tree\n");
  1377. return 0;
  1378. }
  1379. *of_flat_tree = fdt_blob;
  1380. *of_size = be32_to_cpu (fdt_totalsize (fdt_blob));
  1381. debug (" of_flat_tree at 0x%08lx size 0x%08lx\n",
  1382. (ulong)*of_flat_tree, *of_size);
  1383. return 0;
  1384. error:
  1385. *of_flat_tree = 0;
  1386. *of_size = 0;
  1387. return 1;
  1388. }
  1389. #endif /* CONFIG_OF_LIBFDT */
  1390. #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
  1391. /**
  1392. * boot_get_cmdline - allocate and initialize kernel cmdline
  1393. * @lmb: pointer to lmb handle, will be used for memory mgmt
  1394. * @cmd_start: pointer to a ulong variable, will hold cmdline start
  1395. * @cmd_end: pointer to a ulong variable, will hold cmdline end
  1396. * @bootmap_base: ulong variable, holds offset in physical memory to
  1397. * base of bootmap
  1398. *
  1399. * boot_get_cmdline() allocates space for kernel command line below
  1400. * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
  1401. * variable is present its contents is copied to allocated kernel
  1402. * command line.
  1403. *
  1404. * returns:
  1405. * 0 - success
  1406. * -1 - failure
  1407. */
  1408. int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
  1409. ulong bootmap_base)
  1410. {
  1411. char *cmdline;
  1412. char *s;
  1413. cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
  1414. CONFIG_SYS_BOOTMAPSZ + bootmap_base);
  1415. if (cmdline == NULL)
  1416. return -1;
  1417. if ((s = getenv("bootargs")) == NULL)
  1418. s = "";
  1419. strcpy(cmdline, s);
  1420. *cmd_start = (ulong) & cmdline[0];
  1421. *cmd_end = *cmd_start + strlen(cmdline);
  1422. debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
  1423. return 0;
  1424. }
  1425. /**
  1426. * boot_get_kbd - allocate and initialize kernel copy of board info
  1427. * @lmb: pointer to lmb handle, will be used for memory mgmt
  1428. * @kbd: double pointer to board info data
  1429. * @bootmap_base: ulong variable, holds offset in physical memory to
  1430. * base of bootmap
  1431. *
  1432. * boot_get_kbd() allocates space for kernel copy of board info data below
  1433. * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
  1434. * the current u-boot board info data.
  1435. *
  1436. * returns:
  1437. * 0 - success
  1438. * -1 - failure
  1439. */
  1440. int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
  1441. {
  1442. *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
  1443. CONFIG_SYS_BOOTMAPSZ + bootmap_base);
  1444. if (*kbd == NULL)
  1445. return -1;
  1446. **kbd = *(gd->bd);
  1447. debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
  1448. #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
  1449. do_bdinfo(NULL, 0, 0, NULL);
  1450. #endif
  1451. return 0;
  1452. }
  1453. #endif /* CONFIG_PPC || CONFIG_M68K */
  1454. #endif /* !USE_HOSTCC */
  1455. #if defined(CONFIG_FIT)
  1456. /*****************************************************************************/
  1457. /* New uImage format routines */
  1458. /*****************************************************************************/
  1459. #ifndef USE_HOSTCC
  1460. static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
  1461. ulong *addr, const char **name)
  1462. {
  1463. const char *sep;
  1464. *addr = addr_curr;
  1465. *name = NULL;
  1466. sep = strchr (spec, sepc);
  1467. if (sep) {
  1468. if (sep - spec > 0)
  1469. *addr = simple_strtoul (spec, NULL, 16);
  1470. *name = sep + 1;
  1471. return 1;
  1472. }
  1473. return 0;
  1474. }
  1475. /**
  1476. * fit_parse_conf - parse FIT configuration spec
  1477. * @spec: input string, containing configuration spec
  1478. * @add_curr: current image address (to be used as a possible default)
  1479. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1480. * configuration
  1481. * @conf_name double pointer to a char, will hold pointer to a configuration
  1482. * unit name
  1483. *
  1484. * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
  1485. * where <addr> is a FIT image address that contains configuration
  1486. * with a <conf> unit name.
  1487. *
  1488. * Address part is optional, and if omitted default add_curr will
  1489. * be used instead.
  1490. *
  1491. * returns:
  1492. * 1 if spec is a valid configuration string,
  1493. * addr and conf_name are set accordingly
  1494. * 0 otherwise
  1495. */
  1496. inline int fit_parse_conf (const char *spec, ulong addr_curr,
  1497. ulong *addr, const char **conf_name)
  1498. {
  1499. return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
  1500. }
  1501. /**
  1502. * fit_parse_subimage - parse FIT subimage spec
  1503. * @spec: input string, containing subimage spec
  1504. * @add_curr: current image address (to be used as a possible default)
  1505. * @addr: pointer to a ulong variable, will hold FIT image address of a given
  1506. * subimage
  1507. * @image_name: double pointer to a char, will hold pointer to a subimage name
  1508. *
  1509. * fit_parse_subimage() expects subimage spec in the for of
  1510. * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
  1511. * subimage with a <subimg> unit name.
  1512. *
  1513. * Address part is optional, and if omitted default add_curr will
  1514. * be used instead.
  1515. *
  1516. * returns:
  1517. * 1 if spec is a valid subimage string,
  1518. * addr and image_name are set accordingly
  1519. * 0 otherwise
  1520. */
  1521. inline int fit_parse_subimage (const char *spec, ulong addr_curr,
  1522. ulong *addr, const char **image_name)
  1523. {
  1524. return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
  1525. }
  1526. #endif /* !USE_HOSTCC */
  1527. static void fit_get_debug (const void *fit, int noffset,
  1528. char *prop_name, int err)
  1529. {
  1530. debug ("Can't get '%s' property from FIT 0x%08lx, "
  1531. "node: offset %d, name %s (%s)\n",
  1532. prop_name, (ulong)fit, noffset,
  1533. fit_get_name (fit, noffset, NULL),
  1534. fdt_strerror (err));
  1535. }
  1536. /**
  1537. * fit_print_contents - prints out the contents of the FIT format image
  1538. * @fit: pointer to the FIT format image header
  1539. * @p: pointer to prefix string
  1540. *
  1541. * fit_print_contents() formats a multi line FIT image contents description.
  1542. * The routine prints out FIT image properties (root node level) follwed by
  1543. * the details of each component image.
  1544. *
  1545. * returns:
  1546. * no returned results
  1547. */
  1548. void fit_print_contents (const void *fit)
  1549. {
  1550. char *desc;
  1551. char *uname;
  1552. int images_noffset;
  1553. int confs_noffset;
  1554. int noffset;
  1555. int ndepth;
  1556. int count = 0;
  1557. int ret;
  1558. const char *p;
  1559. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1560. time_t timestamp;
  1561. #endif
  1562. #ifdef USE_HOSTCC
  1563. p = "";
  1564. #else
  1565. p = " ";
  1566. #endif
  1567. /* Root node properties */
  1568. ret = fit_get_desc (fit, 0, &desc);
  1569. printf ("%sFIT description: ", p);
  1570. if (ret)
  1571. printf ("unavailable\n");
  1572. else
  1573. printf ("%s\n", desc);
  1574. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  1575. ret = fit_get_timestamp (fit, 0, &timestamp);
  1576. printf ("%sCreated: ", p);
  1577. if (ret)
  1578. printf ("unavailable\n");
  1579. else
  1580. genimg_print_time (timestamp);
  1581. #endif
  1582. /* Find images parent node offset */
  1583. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1584. if (images_noffset < 0) {
  1585. printf ("Can't find images parent node '%s' (%s)\n",
  1586. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1587. return;
  1588. }
  1589. /* Process its subnodes, print out component images details */
  1590. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
  1591. (noffset >= 0) && (ndepth > 0);
  1592. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1593. if (ndepth == 1) {
  1594. /*
  1595. * Direct child node of the images parent node,
  1596. * i.e. component image node.
  1597. */
  1598. printf ("%s Image %u (%s)\n", p, count++,
  1599. fit_get_name(fit, noffset, NULL));
  1600. fit_image_print (fit, noffset, p);
  1601. }
  1602. }
  1603. /* Find configurations parent node offset */
  1604. confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
  1605. if (confs_noffset < 0) {
  1606. debug ("Can't get configurations parent node '%s' (%s)\n",
  1607. FIT_CONFS_PATH, fdt_strerror (confs_noffset));
  1608. return;
  1609. }
  1610. /* get default configuration unit name from default property */
  1611. uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
  1612. if (uname)
  1613. printf ("%s Default Configuration: '%s'\n", p, uname);
  1614. /* Process its subnodes, print out configurations details */
  1615. for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
  1616. (noffset >= 0) && (ndepth > 0);
  1617. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1618. if (ndepth == 1) {
  1619. /*
  1620. * Direct child node of the configurations parent node,
  1621. * i.e. configuration node.
  1622. */
  1623. printf ("%s Configuration %u (%s)\n", p, count++,
  1624. fit_get_name(fit, noffset, NULL));
  1625. fit_conf_print (fit, noffset, p);
  1626. }
  1627. }
  1628. }
  1629. /**
  1630. * fit_image_print - prints out the FIT component image details
  1631. * @fit: pointer to the FIT format image header
  1632. * @image_noffset: offset of the component image node
  1633. * @p: pointer to prefix string
  1634. *
  1635. * fit_image_print() lists all mandatory properies for the processed component
  1636. * image. If present, hash nodes are printed out as well. Load
  1637. * address for images of type firmware is also printed out. Since the load
  1638. * address is not mandatory for firmware images, it will be output as
  1639. * "unavailable" when not present.
  1640. *
  1641. * returns:
  1642. * no returned results
  1643. */
  1644. void fit_image_print (const void *fit, int image_noffset, const char *p)
  1645. {
  1646. char *desc;
  1647. uint8_t type, arch, os, comp;
  1648. size_t size;
  1649. ulong load, entry;
  1650. const void *data;
  1651. int noffset;
  1652. int ndepth;
  1653. int ret;
  1654. /* Mandatory properties */
  1655. ret = fit_get_desc (fit, image_noffset, &desc);
  1656. printf ("%s Description: ", p);
  1657. if (ret)
  1658. printf ("unavailable\n");
  1659. else
  1660. printf ("%s\n", desc);
  1661. fit_image_get_type (fit, image_noffset, &type);
  1662. printf ("%s Type: %s\n", p, genimg_get_type_name (type));
  1663. fit_image_get_comp (fit, image_noffset, &comp);
  1664. printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
  1665. ret = fit_image_get_data (fit, image_noffset, &data, &size);
  1666. #ifndef USE_HOSTCC
  1667. printf ("%s Data Start: ", p);
  1668. if (ret)
  1669. printf ("unavailable\n");
  1670. else
  1671. printf ("0x%08lx\n", (ulong)data);
  1672. #endif
  1673. printf ("%s Data Size: ", p);
  1674. if (ret)
  1675. printf ("unavailable\n");
  1676. else
  1677. genimg_print_size (size);
  1678. /* Remaining, type dependent properties */
  1679. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
  1680. (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
  1681. (type == IH_TYPE_FLATDT)) {
  1682. fit_image_get_arch (fit, image_noffset, &arch);
  1683. printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
  1684. }
  1685. if (type == IH_TYPE_KERNEL) {
  1686. fit_image_get_os (fit, image_noffset, &os);
  1687. printf ("%s OS: %s\n", p, genimg_get_os_name (os));
  1688. }
  1689. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
  1690. (type == IH_TYPE_FIRMWARE)) {
  1691. ret = fit_image_get_load (fit, image_noffset, &load);
  1692. printf ("%s Load Address: ", p);
  1693. if (ret)
  1694. printf ("unavailable\n");
  1695. else
  1696. printf ("0x%08lx\n", load);
  1697. }
  1698. if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
  1699. fit_image_get_entry (fit, image_noffset, &entry);
  1700. printf ("%s Entry Point: ", p);
  1701. if (ret)
  1702. printf ("unavailable\n");
  1703. else
  1704. printf ("0x%08lx\n", entry);
  1705. }
  1706. /* Process all hash subnodes of the component image node */
  1707. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  1708. (noffset >= 0) && (ndepth > 0);
  1709. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  1710. if (ndepth == 1) {
  1711. /* Direct child node of the component image node */
  1712. fit_image_print_hash (fit, noffset, p);
  1713. }
  1714. }
  1715. }
  1716. /**
  1717. * fit_image_print_hash - prints out the hash node details
  1718. * @fit: pointer to the FIT format image header
  1719. * @noffset: offset of the hash node
  1720. * @p: pointer to prefix string
  1721. *
  1722. * fit_image_print_hash() lists properies for the processed hash node
  1723. *
  1724. * returns:
  1725. * no returned results
  1726. */
  1727. void fit_image_print_hash (const void *fit, int noffset, const char *p)
  1728. {
  1729. char *algo;
  1730. uint8_t *value;
  1731. int value_len;
  1732. int i, ret;
  1733. /*
  1734. * Check subnode name, must be equal to "hash".
  1735. * Multiple hash nodes require unique unit node
  1736. * names, e.g. hash@1, hash@2, etc.
  1737. */
  1738. if (strncmp (fit_get_name(fit, noffset, NULL),
  1739. FIT_HASH_NODENAME,
  1740. strlen(FIT_HASH_NODENAME)) != 0)
  1741. return;
  1742. debug ("%s Hash node: '%s'\n", p,
  1743. fit_get_name (fit, noffset, NULL));
  1744. printf ("%s Hash algo: ", p);
  1745. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  1746. printf ("invalid/unsupported\n");
  1747. return;
  1748. }
  1749. printf ("%s\n", algo);
  1750. ret = fit_image_hash_get_value (fit, noffset, &value,
  1751. &value_len);
  1752. printf ("%s Hash value: ", p);
  1753. if (ret) {
  1754. printf ("unavailable\n");
  1755. } else {
  1756. for (i = 0; i < value_len; i++)
  1757. printf ("%02x", value[i]);
  1758. printf ("\n");
  1759. }
  1760. debug ("%s Hash len: %d\n", p, value_len);
  1761. }
  1762. /**
  1763. * fit_get_desc - get node description property
  1764. * @fit: pointer to the FIT format image header
  1765. * @noffset: node offset
  1766. * @desc: double pointer to the char, will hold pointer to the descrption
  1767. *
  1768. * fit_get_desc() reads description property from a given node, if
  1769. * description is found pointer to it is returened in third call argument.
  1770. *
  1771. * returns:
  1772. * 0, on success
  1773. * -1, on failure
  1774. */
  1775. int fit_get_desc (const void *fit, int noffset, char **desc)
  1776. {
  1777. int len;
  1778. *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
  1779. if (*desc == NULL) {
  1780. fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
  1781. return -1;
  1782. }
  1783. return 0;
  1784. }
  1785. /**
  1786. * fit_get_timestamp - get node timestamp property
  1787. * @fit: pointer to the FIT format image header
  1788. * @noffset: node offset
  1789. * @timestamp: pointer to the time_t, will hold read timestamp
  1790. *
  1791. * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
  1792. * is found and has a correct size its value is retured in third call
  1793. * argument.
  1794. *
  1795. * returns:
  1796. * 0, on success
  1797. * -1, on property read failure
  1798. * -2, on wrong timestamp size
  1799. */
  1800. int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
  1801. {
  1802. int len;
  1803. const void *data;
  1804. data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
  1805. if (data == NULL) {
  1806. fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
  1807. return -1;
  1808. }
  1809. if (len != sizeof (uint32_t)) {
  1810. debug ("FIT timestamp with incorrect size of (%u)\n", len);
  1811. return -2;
  1812. }
  1813. *timestamp = uimage_to_cpu (*((uint32_t *)data));
  1814. return 0;
  1815. }
  1816. /**
  1817. * fit_image_get_node - get node offset for component image of a given unit name
  1818. * @fit: pointer to the FIT format image header
  1819. * @image_uname: component image node unit name
  1820. *
  1821. * fit_image_get_node() finds a component image (withing the '/images'
  1822. * node) of a provided unit name. If image is found its node offset is
  1823. * returned to the caller.
  1824. *
  1825. * returns:
  1826. * image node offset when found (>=0)
  1827. * negative number on failure (FDT_ERR_* code)
  1828. */
  1829. int fit_image_get_node (const void *fit, const char *image_uname)
  1830. {
  1831. int noffset, images_noffset;
  1832. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  1833. if (images_noffset < 0) {
  1834. debug ("Can't find images parent node '%s' (%s)\n",
  1835. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  1836. return images_noffset;
  1837. }
  1838. noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
  1839. if (noffset < 0) {
  1840. debug ("Can't get node offset for image unit name: '%s' (%s)\n",
  1841. image_uname, fdt_strerror (noffset));
  1842. }
  1843. return noffset;
  1844. }
  1845. /**
  1846. * fit_image_get_os - get os id for a given component image node
  1847. * @fit: pointer to the FIT format image header
  1848. * @noffset: component image node offset
  1849. * @os: pointer to the uint8_t, will hold os numeric id
  1850. *
  1851. * fit_image_get_os() finds os property in a given component image node.
  1852. * If the property is found, its (string) value is translated to the numeric
  1853. * id which is returned to the caller.
  1854. *
  1855. * returns:
  1856. * 0, on success
  1857. * -1, on failure
  1858. */
  1859. int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
  1860. {
  1861. int len;
  1862. const void *data;
  1863. /* Get OS name from property data */
  1864. data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
  1865. if (data == NULL) {
  1866. fit_get_debug (fit, noffset, FIT_OS_PROP, len);
  1867. *os = -1;
  1868. return -1;
  1869. }
  1870. /* Translate OS name to id */
  1871. *os = genimg_get_os_id (data);
  1872. return 0;
  1873. }
  1874. /**
  1875. * fit_image_get_arch - get arch id for a given component image node
  1876. * @fit: pointer to the FIT format image header
  1877. * @noffset: component image node offset
  1878. * @arch: pointer to the uint8_t, will hold arch numeric id
  1879. *
  1880. * fit_image_get_arch() finds arch property in a given component image node.
  1881. * If the property is found, its (string) value is translated to the numeric
  1882. * id which is returned to the caller.
  1883. *
  1884. * returns:
  1885. * 0, on success
  1886. * -1, on failure
  1887. */
  1888. int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
  1889. {
  1890. int len;
  1891. const void *data;
  1892. /* Get architecture name from property data */
  1893. data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
  1894. if (data == NULL) {
  1895. fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
  1896. *arch = -1;
  1897. return -1;
  1898. }
  1899. /* Translate architecture name to id */
  1900. *arch = genimg_get_arch_id (data);
  1901. return 0;
  1902. }
  1903. /**
  1904. * fit_image_get_type - get type id for a given component image node
  1905. * @fit: pointer to the FIT format image header
  1906. * @noffset: component image node offset
  1907. * @type: pointer to the uint8_t, will hold type numeric id
  1908. *
  1909. * fit_image_get_type() finds type property in a given component image node.
  1910. * If the property is found, its (string) value is translated to the numeric
  1911. * id which is returned to the caller.
  1912. *
  1913. * returns:
  1914. * 0, on success
  1915. * -1, on failure
  1916. */
  1917. int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
  1918. {
  1919. int len;
  1920. const void *data;
  1921. /* Get image type name from property data */
  1922. data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
  1923. if (data == NULL) {
  1924. fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
  1925. *type = -1;
  1926. return -1;
  1927. }
  1928. /* Translate image type name to id */
  1929. *type = genimg_get_type_id (data);
  1930. return 0;
  1931. }
  1932. /**
  1933. * fit_image_get_comp - get comp id for a given component image node
  1934. * @fit: pointer to the FIT format image header
  1935. * @noffset: component image node offset
  1936. * @comp: pointer to the uint8_t, will hold comp numeric id
  1937. *
  1938. * fit_image_get_comp() finds comp property in a given component image node.
  1939. * If the property is found, its (string) value is translated to the numeric
  1940. * id which is returned to the caller.
  1941. *
  1942. * returns:
  1943. * 0, on success
  1944. * -1, on failure
  1945. */
  1946. int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
  1947. {
  1948. int len;
  1949. const void *data;
  1950. /* Get compression name from property data */
  1951. data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
  1952. if (data == NULL) {
  1953. fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
  1954. *comp = -1;
  1955. return -1;
  1956. }
  1957. /* Translate compression name to id */
  1958. *comp = genimg_get_comp_id (data);
  1959. return 0;
  1960. }
  1961. /**
  1962. * fit_image_get_load - get load address property for a given component image node
  1963. * @fit: pointer to the FIT format image header
  1964. * @noffset: component image node offset
  1965. * @load: pointer to the uint32_t, will hold load address
  1966. *
  1967. * fit_image_get_load() finds load address property in a given component image node.
  1968. * If the property is found, its value is returned to the caller.
  1969. *
  1970. * returns:
  1971. * 0, on success
  1972. * -1, on failure
  1973. */
  1974. int fit_image_get_load (const void *fit, int noffset, ulong *load)
  1975. {
  1976. int len;
  1977. const uint32_t *data;
  1978. data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
  1979. if (data == NULL) {
  1980. fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
  1981. return -1;
  1982. }
  1983. *load = uimage_to_cpu (*data);
  1984. return 0;
  1985. }
  1986. /**
  1987. * fit_image_get_entry - get entry point address property for a given component image node
  1988. * @fit: pointer to the FIT format image header
  1989. * @noffset: component image node offset
  1990. * @entry: pointer to the uint32_t, will hold entry point address
  1991. *
  1992. * fit_image_get_entry() finds entry point address property in a given component image node.
  1993. * If the property is found, its value is returned to the caller.
  1994. *
  1995. * returns:
  1996. * 0, on success
  1997. * -1, on failure
  1998. */
  1999. int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
  2000. {
  2001. int len;
  2002. const uint32_t *data;
  2003. data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
  2004. if (data == NULL) {
  2005. fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
  2006. return -1;
  2007. }
  2008. *entry = uimage_to_cpu (*data);
  2009. return 0;
  2010. }
  2011. /**
  2012. * fit_image_get_data - get data property and its size for a given component image node
  2013. * @fit: pointer to the FIT format image header
  2014. * @noffset: component image node offset
  2015. * @data: double pointer to void, will hold data property's data address
  2016. * @size: pointer to size_t, will hold data property's data size
  2017. *
  2018. * fit_image_get_data() finds data property in a given component image node.
  2019. * If the property is found its data start address and size are returned to
  2020. * the caller.
  2021. *
  2022. * returns:
  2023. * 0, on success
  2024. * -1, on failure
  2025. */
  2026. int fit_image_get_data (const void *fit, int noffset,
  2027. const void **data, size_t *size)
  2028. {
  2029. int len;
  2030. *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
  2031. if (*data == NULL) {
  2032. fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
  2033. *size = 0;
  2034. return -1;
  2035. }
  2036. *size = len;
  2037. return 0;
  2038. }
  2039. /**
  2040. * fit_image_hash_get_algo - get hash algorithm name
  2041. * @fit: pointer to the FIT format image header
  2042. * @noffset: hash node offset
  2043. * @algo: double pointer to char, will hold pointer to the algorithm name
  2044. *
  2045. * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
  2046. * If the property is found its data start address is returned to the caller.
  2047. *
  2048. * returns:
  2049. * 0, on success
  2050. * -1, on failure
  2051. */
  2052. int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
  2053. {
  2054. int len;
  2055. *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
  2056. if (*algo == NULL) {
  2057. fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
  2058. return -1;
  2059. }
  2060. return 0;
  2061. }
  2062. /**
  2063. * fit_image_hash_get_value - get hash value and length
  2064. * @fit: pointer to the FIT format image header
  2065. * @noffset: hash node offset
  2066. * @value: double pointer to uint8_t, will hold address of a hash value data
  2067. * @value_len: pointer to an int, will hold hash data length
  2068. *
  2069. * fit_image_hash_get_value() finds hash value property in a given hash node.
  2070. * If the property is found its data start address and size are returned to
  2071. * the caller.
  2072. *
  2073. * returns:
  2074. * 0, on success
  2075. * -1, on failure
  2076. */
  2077. int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
  2078. int *value_len)
  2079. {
  2080. int len;
  2081. *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
  2082. if (*value == NULL) {
  2083. fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
  2084. *value_len = 0;
  2085. return -1;
  2086. }
  2087. *value_len = len;
  2088. return 0;
  2089. }
  2090. /**
  2091. * fit_set_timestamp - set node timestamp property
  2092. * @fit: pointer to the FIT format image header
  2093. * @noffset: node offset
  2094. * @timestamp: timestamp value to be set
  2095. *
  2096. * fit_set_timestamp() attempts to set timestamp property in the requested
  2097. * node and returns operation status to the caller.
  2098. *
  2099. * returns:
  2100. * 0, on success
  2101. * -1, on property read failure
  2102. */
  2103. int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
  2104. {
  2105. uint32_t t;
  2106. int ret;
  2107. t = cpu_to_uimage (timestamp);
  2108. ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
  2109. sizeof (uint32_t));
  2110. if (ret) {
  2111. printf ("Can't set '%s' property for '%s' node (%s)\n",
  2112. FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
  2113. fdt_strerror (ret));
  2114. return -1;
  2115. }
  2116. return 0;
  2117. }
  2118. /**
  2119. * calculate_hash - calculate and return hash for provided input data
  2120. * @data: pointer to the input data
  2121. * @data_len: data length
  2122. * @algo: requested hash algorithm
  2123. * @value: pointer to the char, will hold hash value data (caller must
  2124. * allocate enough free space)
  2125. * value_len: length of the calculated hash
  2126. *
  2127. * calculate_hash() computes input data hash according to the requested algorithm.
  2128. * Resulting hash value is placed in caller provided 'value' buffer, length
  2129. * of the calculated hash is returned via value_len pointer argument.
  2130. *
  2131. * returns:
  2132. * 0, on success
  2133. * -1, when algo is unsupported
  2134. */
  2135. static int calculate_hash (const void *data, int data_len, const char *algo,
  2136. uint8_t *value, int *value_len)
  2137. {
  2138. if (strcmp (algo, "crc32") == 0 ) {
  2139. *((uint32_t *)value) = crc32_wd (0, data, data_len,
  2140. CHUNKSZ_CRC32);
  2141. *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
  2142. *value_len = 4;
  2143. } else if (strcmp (algo, "sha1") == 0 ) {
  2144. sha1_csum_wd ((unsigned char *) data, data_len,
  2145. (unsigned char *) value, CHUNKSZ_SHA1);
  2146. *value_len = 20;
  2147. } else if (strcmp (algo, "md5") == 0 ) {
  2148. md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
  2149. *value_len = 16;
  2150. } else {
  2151. debug ("Unsupported hash alogrithm\n");
  2152. return -1;
  2153. }
  2154. return 0;
  2155. }
  2156. #ifdef USE_HOSTCC
  2157. /**
  2158. * fit_set_hashes - process FIT component image nodes and calculate hashes
  2159. * @fit: pointer to the FIT format image header
  2160. *
  2161. * fit_set_hashes() adds hash values for all component images in the FIT blob.
  2162. * Hashes are calculated for all component images which have hash subnodes
  2163. * with algorithm property set to one of the supported hash algorithms.
  2164. *
  2165. * returns
  2166. * 0, on success
  2167. * libfdt error code, on failure
  2168. */
  2169. int fit_set_hashes (void *fit)
  2170. {
  2171. int images_noffset;
  2172. int noffset;
  2173. int ndepth;
  2174. int ret;
  2175. /* Find images parent node offset */
  2176. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  2177. if (images_noffset < 0) {
  2178. printf ("Can't find images parent node '%s' (%s)\n",
  2179. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  2180. return images_noffset;
  2181. }
  2182. /* Process its subnodes, print out component images details */
  2183. for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
  2184. (noffset >= 0) && (ndepth > 0);
  2185. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  2186. if (ndepth == 1) {
  2187. /*
  2188. * Direct child node of the images parent node,
  2189. * i.e. component image node.
  2190. */
  2191. ret = fit_image_set_hashes (fit, noffset);
  2192. if (ret)
  2193. return ret;
  2194. }
  2195. }
  2196. return 0;
  2197. }
  2198. /**
  2199. * fit_image_set_hashes - calculate/set hashes for given component image node
  2200. * @fit: pointer to the FIT format image header
  2201. * @image_noffset: requested component image node
  2202. *
  2203. * fit_image_set_hashes() adds hash values for an component image node. All
  2204. * existing hash subnodes are checked, if algorithm property is set to one of
  2205. * the supported hash algorithms, hash value is computed and corresponding
  2206. * hash node property is set, for example:
  2207. *
  2208. * Input component image node structure:
  2209. *
  2210. * o image@1 (at image_noffset)
  2211. * | - data = [binary data]
  2212. * o hash@1
  2213. * |- algo = "sha1"
  2214. *
  2215. * Output component image node structure:
  2216. *
  2217. * o image@1 (at image_noffset)
  2218. * | - data = [binary data]
  2219. * o hash@1
  2220. * |- algo = "sha1"
  2221. * |- value = sha1(data)
  2222. *
  2223. * returns:
  2224. * 0 on sucess
  2225. * <0 on failure
  2226. */
  2227. int fit_image_set_hashes (void *fit, int image_noffset)
  2228. {
  2229. const void *data;
  2230. size_t size;
  2231. char *algo;
  2232. uint8_t value[FIT_MAX_HASH_LEN];
  2233. int value_len;
  2234. int noffset;
  2235. int ndepth;
  2236. /* Get image data and data length */
  2237. if (fit_image_get_data (fit, image_noffset, &data, &size)) {
  2238. printf ("Can't get image data/size\n");
  2239. return -1;
  2240. }
  2241. /* Process all hash subnodes of the component image node */
  2242. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  2243. (noffset >= 0) && (ndepth > 0);
  2244. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  2245. if (ndepth == 1) {
  2246. /* Direct child node of the component image node */
  2247. /*
  2248. * Check subnode name, must be equal to "hash".
  2249. * Multiple hash nodes require unique unit node
  2250. * names, e.g. hash@1, hash@2, etc.
  2251. */
  2252. if (strncmp (fit_get_name(fit, noffset, NULL),
  2253. FIT_HASH_NODENAME,
  2254. strlen(FIT_HASH_NODENAME)) != 0) {
  2255. /* Not a hash subnode, skip it */
  2256. continue;
  2257. }
  2258. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  2259. printf ("Can't get hash algo property for "
  2260. "'%s' hash node in '%s' image node\n",
  2261. fit_get_name (fit, noffset, NULL),
  2262. fit_get_name (fit, image_noffset, NULL));
  2263. return -1;
  2264. }
  2265. if (calculate_hash (data, size, algo, value, &value_len)) {
  2266. printf ("Unsupported hash algorithm (%s) for "
  2267. "'%s' hash node in '%s' image node\n",
  2268. algo, fit_get_name (fit, noffset, NULL),
  2269. fit_get_name (fit, image_noffset, NULL));
  2270. return -1;
  2271. }
  2272. if (fit_image_hash_set_value (fit, noffset, value,
  2273. value_len)) {
  2274. printf ("Can't set hash value for "
  2275. "'%s' hash node in '%s' image node\n",
  2276. fit_get_name (fit, noffset, NULL),
  2277. fit_get_name (fit, image_noffset, NULL));
  2278. return -1;
  2279. }
  2280. }
  2281. }
  2282. return 0;
  2283. }
  2284. /**
  2285. * fit_image_hash_set_value - set hash value in requested has node
  2286. * @fit: pointer to the FIT format image header
  2287. * @noffset: hash node offset
  2288. * @value: hash value to be set
  2289. * @value_len: hash value length
  2290. *
  2291. * fit_image_hash_set_value() attempts to set hash value in a node at offset
  2292. * given and returns operation status to the caller.
  2293. *
  2294. * returns
  2295. * 0, on success
  2296. * -1, on failure
  2297. */
  2298. int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
  2299. int value_len)
  2300. {
  2301. int ret;
  2302. ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
  2303. if (ret) {
  2304. printf ("Can't set hash '%s' property for '%s' node (%s)\n",
  2305. FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
  2306. fdt_strerror (ret));
  2307. return -1;
  2308. }
  2309. return 0;
  2310. }
  2311. #endif /* USE_HOSTCC */
  2312. /**
  2313. * fit_image_check_hashes - verify data intergity
  2314. * @fit: pointer to the FIT format image header
  2315. * @image_noffset: component image node offset
  2316. *
  2317. * fit_image_check_hashes() goes over component image hash nodes,
  2318. * re-calculates each data hash and compares with the value stored in hash
  2319. * node.
  2320. *
  2321. * returns:
  2322. * 1, if all hashes are valid
  2323. * 0, otherwise (or on error)
  2324. */
  2325. int fit_image_check_hashes (const void *fit, int image_noffset)
  2326. {
  2327. const void *data;
  2328. size_t size;
  2329. char *algo;
  2330. uint8_t *fit_value;
  2331. int fit_value_len;
  2332. uint8_t value[FIT_MAX_HASH_LEN];
  2333. int value_len;
  2334. int noffset;
  2335. int ndepth;
  2336. char *err_msg = "";
  2337. /* Get image data and data length */
  2338. if (fit_image_get_data (fit, image_noffset, &data, &size)) {
  2339. printf ("Can't get image data/size\n");
  2340. return 0;
  2341. }
  2342. /* Process all hash subnodes of the component image node */
  2343. for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
  2344. (noffset >= 0) && (ndepth > 0);
  2345. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  2346. if (ndepth == 1) {
  2347. /* Direct child node of the component image node */
  2348. /*
  2349. * Check subnode name, must be equal to "hash".
  2350. * Multiple hash nodes require unique unit node
  2351. * names, e.g. hash@1, hash@2, etc.
  2352. */
  2353. if (strncmp (fit_get_name(fit, noffset, NULL),
  2354. FIT_HASH_NODENAME,
  2355. strlen(FIT_HASH_NODENAME)) != 0)
  2356. continue;
  2357. if (fit_image_hash_get_algo (fit, noffset, &algo)) {
  2358. err_msg = " error!\nCan't get hash algo "
  2359. "property";
  2360. goto error;
  2361. }
  2362. printf ("%s", algo);
  2363. if (fit_image_hash_get_value (fit, noffset, &fit_value,
  2364. &fit_value_len)) {
  2365. err_msg = " error!\nCan't get hash value "
  2366. "property";
  2367. goto error;
  2368. }
  2369. if (calculate_hash (data, size, algo, value, &value_len)) {
  2370. err_msg = " error!\nUnsupported hash algorithm";
  2371. goto error;
  2372. }
  2373. if (value_len != fit_value_len) {
  2374. err_msg = " error !\nBad hash value len";
  2375. goto error;
  2376. } else if (memcmp (value, fit_value, value_len) != 0) {
  2377. err_msg = " error!\nBad hash value";
  2378. goto error;
  2379. }
  2380. printf ("+ ");
  2381. }
  2382. }
  2383. return 1;
  2384. error:
  2385. printf ("%s for '%s' hash node in '%s' image node\n",
  2386. err_msg, fit_get_name (fit, noffset, NULL),
  2387. fit_get_name (fit, image_noffset, NULL));
  2388. return 0;
  2389. }
  2390. /**
  2391. * fit_all_image_check_hashes - verify data intergity for all images
  2392. * @fit: pointer to the FIT format image header
  2393. *
  2394. * fit_all_image_check_hashes() goes over all images in the FIT and
  2395. * for every images checks if all it's hashes are valid.
  2396. *
  2397. * returns:
  2398. * 1, if all hashes of all images are valid
  2399. * 0, otherwise (or on error)
  2400. */
  2401. int fit_all_image_check_hashes (const void *fit)
  2402. {
  2403. int images_noffset;
  2404. int noffset;
  2405. int ndepth;
  2406. int count;
  2407. /* Find images parent node offset */
  2408. images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
  2409. if (images_noffset < 0) {
  2410. printf ("Can't find images parent node '%s' (%s)\n",
  2411. FIT_IMAGES_PATH, fdt_strerror (images_noffset));
  2412. return 0;
  2413. }
  2414. /* Process all image subnodes, check hashes for each */
  2415. printf ("## Checking hash(es) for FIT Image at %08lx ...\n",
  2416. (ulong)fit);
  2417. for (ndepth = 0, count = 0,
  2418. noffset = fdt_next_node (fit, images_noffset, &ndepth);
  2419. (noffset >= 0) && (ndepth > 0);
  2420. noffset = fdt_next_node (fit, noffset, &ndepth)) {
  2421. if (ndepth == 1) {
  2422. /*
  2423. * Direct child node of the images parent node,
  2424. * i.e. component image node.
  2425. */
  2426. printf (" Hash(es) for Image %u (%s): ", count++,
  2427. fit_get_name (fit, noffset, NULL));
  2428. if (!fit_image_check_hashes (fit, noffset))
  2429. return 0;
  2430. printf ("\n");
  2431. }
  2432. }
  2433. return 1;
  2434. }
  2435. /**
  2436. * fit_image_check_os - check whether image node is of a given os type
  2437. * @fit: pointer to the FIT format image header
  2438. * @noffset: component image node offset
  2439. * @os: requested image os
  2440. *
  2441. * fit_image_check_os() reads image os property and compares its numeric
  2442. * id with the requested os. Comparison result is returned to the caller.
  2443. *
  2444. * returns:
  2445. * 1 if image is of given os type
  2446. * 0 otherwise (or on error)
  2447. */
  2448. int fit_image_check_os (const void *fit, int noffset, uint8_t os)
  2449. {
  2450. uint8_t image_os;
  2451. if (fit_image_get_os (fit, noffset, &image_os))
  2452. return 0;
  2453. return (os == image_os);
  2454. }
  2455. /**
  2456. * fit_image_check_arch - check whether image node is of a given arch
  2457. * @fit: pointer to the FIT format image header
  2458. * @noffset: component image node offset
  2459. * @arch: requested imagearch
  2460. *
  2461. * fit_image_check_arch() reads image arch property and compares its numeric
  2462. * id with the requested arch. Comparison result is returned to the caller.
  2463. *
  2464. * returns:
  2465. * 1 if image is of given arch
  2466. * 0 otherwise (or on error)
  2467. */
  2468. int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
  2469. {
  2470. uint8_t image_arch;
  2471. if (fit_image_get_arch (fit, noffset, &image_arch))
  2472. return 0;
  2473. return (arch == image_arch);
  2474. }
  2475. /**
  2476. * fit_image_check_type - check whether image node is of a given type
  2477. * @fit: pointer to the FIT format image header
  2478. * @noffset: component image node offset
  2479. * @type: requested image type
  2480. *
  2481. * fit_image_check_type() reads image type property and compares its numeric
  2482. * id with the requested type. Comparison result is returned to the caller.
  2483. *
  2484. * returns:
  2485. * 1 if image is of given type
  2486. * 0 otherwise (or on error)
  2487. */
  2488. int fit_image_check_type (const void *fit, int noffset, uint8_t type)
  2489. {
  2490. uint8_t image_type;
  2491. if (fit_image_get_type (fit, noffset, &image_type))
  2492. return 0;
  2493. return (type == image_type);
  2494. }
  2495. /**
  2496. * fit_image_check_comp - check whether image node uses given compression
  2497. * @fit: pointer to the FIT format image header
  2498. * @noffset: component image node offset
  2499. * @comp: requested image compression type
  2500. *
  2501. * fit_image_check_comp() reads image compression property and compares its
  2502. * numeric id with the requested compression type. Comparison result is
  2503. * returned to the caller.
  2504. *
  2505. * returns:
  2506. * 1 if image uses requested compression
  2507. * 0 otherwise (or on error)
  2508. */
  2509. int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
  2510. {
  2511. uint8_t image_comp;
  2512. if (fit_image_get_comp (fit, noffset, &image_comp))
  2513. return 0;
  2514. return (comp == image_comp);
  2515. }
  2516. /**
  2517. * fit_check_format - sanity check FIT image format
  2518. * @fit: pointer to the FIT format image header
  2519. *
  2520. * fit_check_format() runs a basic sanity FIT image verification.
  2521. * Routine checks for mandatory properties, nodes, etc.
  2522. *
  2523. * returns:
  2524. * 1, on success
  2525. * 0, on failure
  2526. */
  2527. int fit_check_format (const void *fit)
  2528. {
  2529. /* mandatory / node 'description' property */
  2530. if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
  2531. debug ("Wrong FIT format: no description\n");
  2532. return 0;
  2533. }
  2534. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
  2535. /* mandatory / node 'timestamp' property */
  2536. if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
  2537. debug ("Wrong FIT format: no timestamp\n");
  2538. return 0;
  2539. }
  2540. #endif
  2541. /* mandatory subimages parent '/images' node */
  2542. if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
  2543. debug ("Wrong FIT format: no images parent node\n");
  2544. return 0;
  2545. }
  2546. return 1;
  2547. }
  2548. /**
  2549. * fit_conf_get_node - get node offset for configuration of a given unit name
  2550. * @fit: pointer to the FIT format image header
  2551. * @conf_uname: configuration node unit name
  2552. *
  2553. * fit_conf_get_node() finds a configuration (withing the '/configurations'
  2554. * parant node) of a provided unit name. If configuration is found its node offset
  2555. * is returned to the caller.
  2556. *
  2557. * When NULL is provided in second argument fit_conf_get_node() will search
  2558. * for a default configuration node instead. Default configuration node unit name
  2559. * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
  2560. *
  2561. * returns:
  2562. * configuration node offset when found (>=0)
  2563. * negative number on failure (FDT_ERR_* code)
  2564. */
  2565. int fit_conf_get_node (const void *fit, const char *conf_uname)
  2566. {
  2567. int noffset, confs_noffset;
  2568. int len;
  2569. confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
  2570. if (confs_noffset < 0) {
  2571. debug ("Can't find configurations parent node '%s' (%s)\n",
  2572. FIT_CONFS_PATH, fdt_strerror (confs_noffset));
  2573. return confs_noffset;
  2574. }
  2575. if (conf_uname == NULL) {
  2576. /* get configuration unit name from the default property */
  2577. debug ("No configuration specified, trying default...\n");
  2578. conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
  2579. if (conf_uname == NULL) {
  2580. fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
  2581. return len;
  2582. }
  2583. debug ("Found default configuration: '%s'\n", conf_uname);
  2584. }
  2585. noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
  2586. if (noffset < 0) {
  2587. debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
  2588. conf_uname, fdt_strerror (noffset));
  2589. }
  2590. return noffset;
  2591. }
  2592. static int __fit_conf_get_prop_node (const void *fit, int noffset,
  2593. const char *prop_name)
  2594. {
  2595. char *uname;
  2596. int len;
  2597. /* get kernel image unit name from configuration kernel property */
  2598. uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
  2599. if (uname == NULL)
  2600. return len;
  2601. return fit_image_get_node (fit, uname);
  2602. }
  2603. /**
  2604. * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
  2605. * a given configuration
  2606. * @fit: pointer to the FIT format image header
  2607. * @noffset: configuration node offset
  2608. *
  2609. * fit_conf_get_kernel_node() retrives kernel image node unit name from
  2610. * configuration FIT_KERNEL_PROP property and translates it to the node
  2611. * offset.
  2612. *
  2613. * returns:
  2614. * image node offset when found (>=0)
  2615. * negative number on failure (FDT_ERR_* code)
  2616. */
  2617. int fit_conf_get_kernel_node (const void *fit, int noffset)
  2618. {
  2619. return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
  2620. }
  2621. /**
  2622. * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
  2623. * a given configuration
  2624. * @fit: pointer to the FIT format image header
  2625. * @noffset: configuration node offset
  2626. *
  2627. * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
  2628. * configuration FIT_KERNEL_PROP property and translates it to the node
  2629. * offset.
  2630. *
  2631. * returns:
  2632. * image node offset when found (>=0)
  2633. * negative number on failure (FDT_ERR_* code)
  2634. */
  2635. int fit_conf_get_ramdisk_node (const void *fit, int noffset)
  2636. {
  2637. return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
  2638. }
  2639. /**
  2640. * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
  2641. * a given configuration
  2642. * @fit: pointer to the FIT format image header
  2643. * @noffset: configuration node offset
  2644. *
  2645. * fit_conf_get_fdt_node() retrives fdt image node unit name from
  2646. * configuration FIT_KERNEL_PROP property and translates it to the node
  2647. * offset.
  2648. *
  2649. * returns:
  2650. * image node offset when found (>=0)
  2651. * negative number on failure (FDT_ERR_* code)
  2652. */
  2653. int fit_conf_get_fdt_node (const void *fit, int noffset)
  2654. {
  2655. return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
  2656. }
  2657. /**
  2658. * fit_conf_print - prints out the FIT configuration details
  2659. * @fit: pointer to the FIT format image header
  2660. * @noffset: offset of the configuration node
  2661. * @p: pointer to prefix string
  2662. *
  2663. * fit_conf_print() lists all mandatory properies for the processed
  2664. * configuration node.
  2665. *
  2666. * returns:
  2667. * no returned results
  2668. */
  2669. void fit_conf_print (const void *fit, int noffset, const char *p)
  2670. {
  2671. char *desc;
  2672. char *uname;
  2673. int ret;
  2674. /* Mandatory properties */
  2675. ret = fit_get_desc (fit, noffset, &desc);
  2676. printf ("%s Description: ", p);
  2677. if (ret)
  2678. printf ("unavailable\n");
  2679. else
  2680. printf ("%s\n", desc);
  2681. uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
  2682. printf ("%s Kernel: ", p);
  2683. if (uname == NULL)
  2684. printf ("unavailable\n");
  2685. else
  2686. printf ("%s\n", uname);
  2687. /* Optional properties */
  2688. uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
  2689. if (uname)
  2690. printf ("%s Init Ramdisk: %s\n", p, uname);
  2691. uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
  2692. if (uname)
  2693. printf ("%s FDT: %s\n", p, uname);
  2694. }
  2695. /**
  2696. * fit_check_ramdisk - verify FIT format ramdisk subimage
  2697. * @fit_hdr: pointer to the FIT ramdisk header
  2698. * @rd_noffset: ramdisk subimage node offset within FIT image
  2699. * @arch: requested ramdisk image architecture type
  2700. * @verify: data CRC verification flag
  2701. *
  2702. * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
  2703. * specified FIT image.
  2704. *
  2705. * returns:
  2706. * 1, on success
  2707. * 0, on failure
  2708. */
  2709. #ifndef USE_HOSTCC
  2710. static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
  2711. {
  2712. fit_image_print (fit, rd_noffset, " ");
  2713. if (verify) {
  2714. puts (" Verifying Hash Integrity ... ");
  2715. if (!fit_image_check_hashes (fit, rd_noffset)) {
  2716. puts ("Bad Data Hash\n");
  2717. show_boot_progress (-125);
  2718. return 0;
  2719. }
  2720. puts ("OK\n");
  2721. }
  2722. show_boot_progress (126);
  2723. if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
  2724. !fit_image_check_arch (fit, rd_noffset, arch) ||
  2725. !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
  2726. printf ("No Linux %s Ramdisk Image\n",
  2727. genimg_get_arch_name(arch));
  2728. show_boot_progress (-126);
  2729. return 0;
  2730. }
  2731. show_boot_progress (127);
  2732. return 1;
  2733. }
  2734. #endif /* USE_HOSTCC */
  2735. #endif /* CONFIG_FIT */