image.c 84 KB

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