image.c 85 KB

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