image.c 83 KB

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