image.c 68 KB

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