image.c 69 KB

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