cmd_bootm.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. /*
  2. * (C) Copyright 2000-2006
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #define DEBUG
  24. /*
  25. * Boot support
  26. */
  27. #include <common.h>
  28. #include <watchdog.h>
  29. #include <command.h>
  30. #include <image.h>
  31. #include <malloc.h>
  32. #include <zlib.h>
  33. #include <bzlib.h>
  34. #include <environment.h>
  35. #include <asm/byteorder.h>
  36. #if defined(CONFIG_OF_LIBFDT)
  37. #include <fdt.h>
  38. #include <libfdt.h>
  39. #include <fdt_support.h>
  40. #elif defined(CONFIG_OF_FLAT_TREE)
  41. #include <ft_build.h>
  42. #endif
  43. DECLARE_GLOBAL_DATA_PTR;
  44. /*cmd_boot.c*/
  45. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  46. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
  47. #include <rtc.h>
  48. #endif
  49. #ifdef CFG_HUSH_PARSER
  50. #include <hush.h>
  51. #endif
  52. #ifdef CONFIG_HAS_DATAFLASH
  53. #include <dataflash.h>
  54. #endif
  55. int gunzip (void *, int, unsigned char *, unsigned long *);
  56. #ifdef CONFIG_BZIP2
  57. extern void bz_internal_error(int);
  58. #endif
  59. #if defined(CONFIG_CMD_IMI)
  60. static int image_info (unsigned long addr);
  61. #endif
  62. #if defined(CONFIG_CMD_IMLS)
  63. #include <flash.h>
  64. extern flash_info_t flash_info[]; /* info for FLASH chips */
  65. static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  66. #endif
  67. static void print_type (image_header_t *hdr);
  68. /*
  69. * Continue booting an OS image; caller already has:
  70. * - copied image header to global variable `header'
  71. * - checked header magic number, checksums (both header & image),
  72. * - verified image architecture (PPC) and type (KERNEL or MULTI),
  73. * - loaded (first part of) image to header load address,
  74. * - disabled interrupts.
  75. */
  76. typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
  77. int argc, char *argv[],
  78. ulong addr, /* of image to boot */
  79. ulong *len_ptr, /* multi-file image length table */
  80. int verify); /* getenv("verify")[0] != 'n' */
  81. extern boot_os_Fcn do_bootm_linux;
  82. #ifdef CONFIG_SILENT_CONSOLE
  83. static void fixup_silent_linux (void);
  84. #endif
  85. static boot_os_Fcn do_bootm_netbsd;
  86. static boot_os_Fcn do_bootm_rtems;
  87. #if defined(CONFIG_CMD_ELF)
  88. static boot_os_Fcn do_bootm_vxworks;
  89. static boot_os_Fcn do_bootm_qnxelf;
  90. int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
  91. int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
  92. #endif
  93. #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
  94. static boot_os_Fcn do_bootm_artos;
  95. #endif
  96. #ifdef CONFIG_LYNXKDI
  97. static boot_os_Fcn do_bootm_lynxkdi;
  98. extern void lynxkdi_boot( image_header_t * );
  99. #endif
  100. #ifndef CFG_BOOTM_LEN
  101. #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
  102. #endif
  103. image_header_t header;
  104. ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
  105. int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  106. {
  107. ulong iflag;
  108. ulong addr;
  109. ulong data, len;
  110. ulong *len_ptr;
  111. uint unc_len = CFG_BOOTM_LEN;
  112. int i, verify;
  113. char *name, *s;
  114. int (*appl)(int, char *[]);
  115. image_header_t *hdr = &header;
  116. verify = getenv_verify ();
  117. if (argc < 2) {
  118. addr = load_addr;
  119. } else {
  120. addr = simple_strtoul(argv[1], NULL, 16);
  121. }
  122. show_boot_progress (1);
  123. printf ("## Booting image at %08lx ...\n", addr);
  124. /* Copy header so we can blank CRC field for re-calculation */
  125. #ifdef CONFIG_HAS_DATAFLASH
  126. if (addr_dataflash(addr)){
  127. read_dataflash (addr, image_get_header_size (), (char *)&header);
  128. } else
  129. #endif
  130. memmove (&header, (char *)addr, image_get_header_size ());
  131. if (!image_check_magic(hdr)) {
  132. puts ("Bad Magic Number\n");
  133. show_boot_progress (-1);
  134. return 1;
  135. }
  136. show_boot_progress (2);
  137. if (!image_check_hcrc (hdr)) {
  138. puts ("Bad Header Checksum\n");
  139. show_boot_progress (-2);
  140. return 1;
  141. }
  142. show_boot_progress (3);
  143. #ifdef CONFIG_HAS_DATAFLASH
  144. if (addr_dataflash(addr)){
  145. len = image_get_image_size (hdr);
  146. read_dataflash(addr, len, (char *)CFG_LOAD_ADDR);
  147. addr = CFG_LOAD_ADDR;
  148. }
  149. #endif
  150. /* for multi-file images we need the data part, too */
  151. print_image_hdr ((image_header_t *)addr);
  152. len = image_get_data_size (hdr);
  153. data = addr + image_get_header_size ();
  154. len_ptr = (ulong *)data;
  155. if (verify) {
  156. puts (" Verifying Checksum ... ");
  157. if (!image_check_dcrc ((image_header_t *)addr)) {
  158. printf ("Bad Data CRC\n");
  159. show_boot_progress (-3);
  160. return 1;
  161. }
  162. puts ("OK\n");
  163. }
  164. show_boot_progress (4);
  165. if (!image_check_target_arch (hdr)) {
  166. printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
  167. show_boot_progress (-4);
  168. return 1;
  169. }
  170. show_boot_progress (5);
  171. switch (image_get_type (hdr)) {
  172. case IH_TYPE_STANDALONE:
  173. name = "Standalone Application";
  174. /* A second argument overwrites the load address */
  175. if (argc > 2) {
  176. image_set_load (hdr, simple_strtoul (argv[2], NULL, 16));
  177. }
  178. break;
  179. case IH_TYPE_KERNEL:
  180. name = "Kernel Image";
  181. break;
  182. case IH_TYPE_MULTI:
  183. name = "Multi-File Image";
  184. len = image_to_cpu (len_ptr[0]);
  185. /* OS kernel is always the first image */
  186. data += 8; /* kernel_len + terminator */
  187. for (i=1; len_ptr[i]; ++i)
  188. data += 4;
  189. break;
  190. default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
  191. show_boot_progress (-5);
  192. return 1;
  193. }
  194. show_boot_progress (6);
  195. /*
  196. * We have reached the point of no return: we are going to
  197. * overwrite all exception vector code, so we cannot easily
  198. * recover from any failures any more...
  199. */
  200. iflag = disable_interrupts();
  201. #ifdef CONFIG_AMIGAONEG3SE
  202. /*
  203. * We've possible left the caches enabled during
  204. * bios emulation, so turn them off again
  205. */
  206. icache_disable();
  207. invalidate_l1_instruction_cache();
  208. flush_data_cache();
  209. dcache_disable();
  210. #endif
  211. switch (image_get_comp (hdr)) {
  212. case IH_COMP_NONE:
  213. if (image_get_load (hdr) == addr) {
  214. printf (" XIP %s ... ", name);
  215. } else {
  216. printf (" Loading %s ... ", name);
  217. memmove_wd ((void *)image_get_load (hdr),
  218. (void *)data, len, CHUNKSZ);
  219. puts("OK\n");
  220. }
  221. break;
  222. case IH_COMP_GZIP:
  223. printf (" Uncompressing %s ... ", name);
  224. if (gunzip ((void *)image_get_load (hdr), unc_len,
  225. (uchar *)data, &len) != 0) {
  226. puts ("GUNZIP ERROR - must RESET board to recover\n");
  227. show_boot_progress (-6);
  228. do_reset (cmdtp, flag, argc, argv);
  229. }
  230. break;
  231. #ifdef CONFIG_BZIP2
  232. case IH_COMP_BZIP2:
  233. printf (" Uncompressing %s ... ", name);
  234. /*
  235. * If we've got less than 4 MB of malloc() space,
  236. * use slower decompression algorithm which requires
  237. * at most 2300 KB of memory.
  238. */
  239. i = BZ2_bzBuffToBuffDecompress ((char*)image_get_load (hdr),
  240. &unc_len, (char *)data, len,
  241. CFG_MALLOC_LEN < (4096 * 1024), 0);
  242. if (i != BZ_OK) {
  243. printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
  244. show_boot_progress (-6);
  245. do_reset (cmdtp, flag, argc, argv);
  246. }
  247. break;
  248. #endif /* CONFIG_BZIP2 */
  249. default:
  250. if (iflag)
  251. enable_interrupts();
  252. printf ("Unimplemented compression type %d\n", image_get_comp (hdr));
  253. show_boot_progress (-7);
  254. return 1;
  255. }
  256. puts ("OK\n");
  257. show_boot_progress (7);
  258. switch (image_get_type (hdr)) {
  259. case IH_TYPE_STANDALONE:
  260. if (iflag)
  261. enable_interrupts();
  262. /* load (and uncompress), but don't start if "autostart"
  263. * is set to "no"
  264. */
  265. if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
  266. char buf[32];
  267. sprintf(buf, "%lX", len);
  268. setenv("filesize", buf);
  269. return 0;
  270. }
  271. appl = (int (*)(int, char *[]))image_get_ep (hdr);
  272. (*appl)(argc-1, &argv[1]);
  273. return 0;
  274. case IH_TYPE_KERNEL:
  275. case IH_TYPE_MULTI:
  276. /* handled below */
  277. break;
  278. default:
  279. if (iflag)
  280. enable_interrupts();
  281. printf ("Can't boot image type %d\n", image_get_type (hdr));
  282. show_boot_progress (-8);
  283. return 1;
  284. }
  285. show_boot_progress (8);
  286. switch (image_get_os (hdr)) {
  287. default: /* handled by (original) Linux case */
  288. case IH_OS_LINUX:
  289. #ifdef CONFIG_SILENT_CONSOLE
  290. fixup_silent_linux();
  291. #endif
  292. do_bootm_linux (cmdtp, flag, argc, argv,
  293. addr, len_ptr, verify);
  294. break;
  295. case IH_OS_NETBSD:
  296. do_bootm_netbsd (cmdtp, flag, argc, argv,
  297. addr, len_ptr, verify);
  298. break;
  299. #ifdef CONFIG_LYNXKDI
  300. case IH_OS_LYNXOS:
  301. do_bootm_lynxkdi (cmdtp, flag, argc, argv,
  302. addr, len_ptr, verify);
  303. break;
  304. #endif
  305. case IH_OS_RTEMS:
  306. do_bootm_rtems (cmdtp, flag, argc, argv,
  307. addr, len_ptr, verify);
  308. break;
  309. #if defined(CONFIG_CMD_ELF)
  310. case IH_OS_VXWORKS:
  311. do_bootm_vxworks (cmdtp, flag, argc, argv,
  312. addr, len_ptr, verify);
  313. break;
  314. case IH_OS_QNX:
  315. do_bootm_qnxelf (cmdtp, flag, argc, argv,
  316. addr, len_ptr, verify);
  317. break;
  318. #endif
  319. #ifdef CONFIG_ARTOS
  320. case IH_OS_ARTOS:
  321. do_bootm_artos (cmdtp, flag, argc, argv,
  322. addr, len_ptr, verify);
  323. break;
  324. #endif
  325. }
  326. show_boot_progress (-9);
  327. #ifdef DEBUG
  328. puts ("\n## Control returned to monitor - resetting...\n");
  329. do_reset (cmdtp, flag, argc, argv);
  330. #endif
  331. return 1;
  332. }
  333. U_BOOT_CMD(
  334. bootm, CFG_MAXARGS, 1, do_bootm,
  335. "bootm - boot application image from memory\n",
  336. "[addr [arg ...]]\n - boot application image stored in memory\n"
  337. "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
  338. "\t'arg' can be the address of an initrd image\n"
  339. #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
  340. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  341. "\ta third argument is required which is the address of the\n"
  342. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  343. "\tuse a '-' for the second argument. If you do not pass a third\n"
  344. "\ta bd_info struct will be passed instead\n"
  345. #endif
  346. );
  347. #ifdef CONFIG_SILENT_CONSOLE
  348. static void
  349. fixup_silent_linux ()
  350. {
  351. char buf[256], *start, *end;
  352. char *cmdline = getenv ("bootargs");
  353. /* Only fix cmdline when requested */
  354. if (!(gd->flags & GD_FLG_SILENT))
  355. return;
  356. debug ("before silent fix-up: %s\n", cmdline);
  357. if (cmdline) {
  358. if ((start = strstr (cmdline, "console=")) != NULL) {
  359. end = strchr (start, ' ');
  360. strncpy (buf, cmdline, (start - cmdline + 8));
  361. if (end)
  362. strcpy (buf + (start - cmdline + 8), end);
  363. else
  364. buf[start - cmdline + 8] = '\0';
  365. } else {
  366. strcpy (buf, cmdline);
  367. strcat (buf, " console=");
  368. }
  369. } else {
  370. strcpy (buf, "console=");
  371. }
  372. setenv ("bootargs", buf);
  373. debug ("after silent fix-up: %s\n", buf);
  374. }
  375. #endif /* CONFIG_SILENT_CONSOLE */
  376. static void
  377. do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
  378. int argc, char *argv[],
  379. ulong addr,
  380. ulong *len_ptr,
  381. int verify)
  382. {
  383. image_header_t *hdr = &header;
  384. void (*loader)(bd_t *, image_header_t *, char *, char *);
  385. image_header_t *img_addr;
  386. char *consdev;
  387. char *cmdline;
  388. /*
  389. * Booting a (NetBSD) kernel image
  390. *
  391. * This process is pretty similar to a standalone application:
  392. * The (first part of an multi-) image must be a stage-2 loader,
  393. * which in turn is responsible for loading & invoking the actual
  394. * kernel. The only differences are the parameters being passed:
  395. * besides the board info strucure, the loader expects a command
  396. * line, the name of the console device, and (optionally) the
  397. * address of the original image header.
  398. */
  399. img_addr = 0;
  400. if ((image_check_type (hdr, IH_TYPE_MULTI)) && (len_ptr[1]))
  401. img_addr = (image_header_t *) addr;
  402. consdev = "";
  403. #if defined (CONFIG_8xx_CONS_SMC1)
  404. consdev = "smc1";
  405. #elif defined (CONFIG_8xx_CONS_SMC2)
  406. consdev = "smc2";
  407. #elif defined (CONFIG_8xx_CONS_SCC2)
  408. consdev = "scc2";
  409. #elif defined (CONFIG_8xx_CONS_SCC3)
  410. consdev = "scc3";
  411. #endif
  412. if (argc > 2) {
  413. ulong len;
  414. int i;
  415. for (i=2, len=0 ; i<argc ; i+=1)
  416. len += strlen (argv[i]) + 1;
  417. cmdline = malloc (len);
  418. for (i=2, len=0 ; i<argc ; i+=1) {
  419. if (i > 2)
  420. cmdline[len++] = ' ';
  421. strcpy (&cmdline[len], argv[i]);
  422. len += strlen (argv[i]);
  423. }
  424. } else if ((cmdline = getenv("bootargs")) == NULL) {
  425. cmdline = "";
  426. }
  427. loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
  428. printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
  429. (ulong)loader);
  430. show_boot_progress (15);
  431. /*
  432. * NetBSD Stage-2 Loader Parameters:
  433. * r3: ptr to board info data
  434. * r4: image address
  435. * r5: console device
  436. * r6: boot args string
  437. */
  438. (*loader) (gd->bd, img_addr, consdev, cmdline);
  439. }
  440. #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
  441. /* Function that returns a character from the environment */
  442. extern uchar (*env_get_char)(int);
  443. static void
  444. do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
  445. int argc, char *argv[],
  446. ulong addr,
  447. ulong *len_ptr,
  448. int verify)
  449. {
  450. ulong top;
  451. char *s, *cmdline;
  452. char **fwenv, **ss;
  453. int i, j, nxt, len, envno, envsz;
  454. bd_t *kbd;
  455. void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
  456. image_header_t *hdr = &header;
  457. /*
  458. * Booting an ARTOS kernel image + application
  459. */
  460. /* this used to be the top of memory, but was wrong... */
  461. #ifdef CONFIG_PPC
  462. /* get stack pointer */
  463. asm volatile ("mr %0,1" : "=r"(top) );
  464. #endif
  465. debug ("## Current stack ends at 0x%08lX ", top);
  466. top -= 2048; /* just to be sure */
  467. if (top > CFG_BOOTMAPSZ)
  468. top = CFG_BOOTMAPSZ;
  469. top &= ~0xF;
  470. debug ("=> set upper limit to 0x%08lX\n", top);
  471. /* first check the artos specific boot args, then the linux args*/
  472. if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
  473. s = "";
  474. /* get length of cmdline, and place it */
  475. len = strlen(s);
  476. top = (top - (len + 1)) & ~0xF;
  477. cmdline = (char *)top;
  478. debug ("## cmdline at 0x%08lX ", top);
  479. strcpy(cmdline, s);
  480. /* copy bdinfo */
  481. top = (top - sizeof(bd_t)) & ~0xF;
  482. debug ("## bd at 0x%08lX ", top);
  483. kbd = (bd_t *)top;
  484. memcpy(kbd, gd->bd, sizeof(bd_t));
  485. /* first find number of env entries, and their size */
  486. envno = 0;
  487. envsz = 0;
  488. for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
  489. for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
  490. ;
  491. envno++;
  492. envsz += (nxt - i) + 1; /* plus trailing zero */
  493. }
  494. envno++; /* plus the terminating zero */
  495. debug ("## %u envvars total size %u ", envno, envsz);
  496. top = (top - sizeof(char **)*envno) & ~0xF;
  497. fwenv = (char **)top;
  498. debug ("## fwenv at 0x%08lX ", top);
  499. top = (top - envsz) & ~0xF;
  500. s = (char *)top;
  501. ss = fwenv;
  502. /* now copy them */
  503. for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
  504. for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
  505. ;
  506. *ss++ = s;
  507. for (j = i; j < nxt; ++j)
  508. *s++ = env_get_char(j);
  509. *s++ = '\0';
  510. }
  511. *ss++ = NULL; /* terminate */
  512. entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
  513. (*entry)(kbd, cmdline, fwenv, top);
  514. }
  515. #endif
  516. #if defined(CONFIG_CMD_BOOTD)
  517. int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  518. {
  519. int rcode = 0;
  520. #ifndef CFG_HUSH_PARSER
  521. if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
  522. #else
  523. if (parse_string_outer(getenv("bootcmd"),
  524. FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
  525. #endif
  526. return rcode;
  527. }
  528. U_BOOT_CMD(
  529. boot, 1, 1, do_bootd,
  530. "boot - boot default, i.e., run 'bootcmd'\n",
  531. NULL
  532. );
  533. /* keep old command name "bootd" for backward compatibility */
  534. U_BOOT_CMD(
  535. bootd, 1, 1, do_bootd,
  536. "bootd - boot default, i.e., run 'bootcmd'\n",
  537. NULL
  538. );
  539. #endif
  540. #if defined(CONFIG_CMD_IMI)
  541. int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  542. {
  543. int arg;
  544. ulong addr;
  545. int rcode=0;
  546. if (argc < 2) {
  547. return image_info (load_addr);
  548. }
  549. for (arg=1; arg <argc; ++arg) {
  550. addr = simple_strtoul(argv[arg], NULL, 16);
  551. if (image_info (addr) != 0) rcode = 1;
  552. }
  553. return rcode;
  554. }
  555. static int image_info (ulong addr)
  556. {
  557. image_header_t *hdr = (image_header_t *)addr;
  558. printf ("\n## Checking Image at %08lx ...\n", addr);
  559. if (!image_check_magic (hdr)) {
  560. puts (" Bad Magic Number\n");
  561. return 1;
  562. }
  563. if (!image_check_hcrc (hdr)) {
  564. puts (" Bad Header Checksum\n");
  565. return 1;
  566. }
  567. print_image_hdr (hdr);
  568. puts (" Verifying Checksum ... ");
  569. if (!image_check_dcrc (hdr)) {
  570. puts (" Bad Data CRC\n");
  571. return 1;
  572. }
  573. puts ("OK\n");
  574. return 0;
  575. }
  576. U_BOOT_CMD(
  577. iminfo, CFG_MAXARGS, 1, do_iminfo,
  578. "iminfo - print header information for application image\n",
  579. "addr [addr ...]\n"
  580. " - print header information for application image starting at\n"
  581. " address 'addr' in memory; this includes verification of the\n"
  582. " image contents (magic number, header and payload checksums)\n"
  583. );
  584. #endif
  585. #if defined(CONFIG_CMD_IMLS)
  586. /*-----------------------------------------------------------------------
  587. * List all images found in flash.
  588. */
  589. int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  590. {
  591. flash_info_t *info;
  592. int i, j;
  593. image_header_t *hdr;
  594. for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
  595. if (info->flash_id == FLASH_UNKNOWN)
  596. goto next_bank;
  597. for (j=0; j<info->sector_count; ++j) {
  598. hdr = (image_header_t *)info->start[j];
  599. if (!hdr || !image_check_magic (hdr))
  600. goto next_sector;
  601. if (!image_check_hcrc (hdr))
  602. goto next_sector;
  603. printf ("Image at %08lX:\n", (ulong)hdr);
  604. print_image_hdr (hdr);
  605. puts (" Verifying Checksum ... ");
  606. if (!image_check_dcrc (hdr)) {
  607. puts ("Bad Data CRC\n");
  608. } else {
  609. puts ("OK\n");
  610. }
  611. next_sector: ;
  612. }
  613. next_bank: ;
  614. }
  615. return (0);
  616. }
  617. U_BOOT_CMD(
  618. imls, 1, 1, do_imls,
  619. "imls - list all images found in flash\n",
  620. "\n"
  621. " - Prints information about all images found at sector\n"
  622. " boundaries in flash.\n"
  623. );
  624. #endif
  625. void
  626. print_image_hdr (image_header_t *hdr)
  627. {
  628. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
  629. time_t timestamp = (time_t)image_get_time (hdr);
  630. struct rtc_time tm;
  631. #endif
  632. printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr));
  633. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
  634. to_tm (timestamp, &tm);
  635. printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
  636. tm.tm_year, tm.tm_mon, tm.tm_mday,
  637. tm.tm_hour, tm.tm_min, tm.tm_sec);
  638. #endif
  639. puts (" Image Type: "); print_type(hdr);
  640. printf ("\n Data Size: %d Bytes = ", image_get_data_size (hdr));
  641. print_size (image_get_data_size (hdr), "\n");
  642. printf (" Load Address: %08x\n"
  643. " Entry Point: %08x\n",
  644. image_get_load (hdr), image_get_ep (hdr));
  645. if (image_check_type (hdr, IH_TYPE_MULTI)) {
  646. int i;
  647. ulong len;
  648. ulong *len_ptr = (ulong *)((ulong)hdr + image_get_header_size ());
  649. puts (" Contents:\n");
  650. for (i=0; (len = image_to_cpu (*len_ptr)); ++i, ++len_ptr) {
  651. printf (" Image %d: %8ld Bytes = ", i, len);
  652. print_size (len, "\n");
  653. }
  654. }
  655. }
  656. static void
  657. print_type (image_header_t *hdr)
  658. {
  659. char *os, *arch, *type, *comp;
  660. switch (image_get_os (hdr)) {
  661. case IH_OS_INVALID: os = "Invalid OS"; break;
  662. case IH_OS_NETBSD: os = "NetBSD"; break;
  663. case IH_OS_LINUX: os = "Linux"; break;
  664. case IH_OS_VXWORKS: os = "VxWorks"; break;
  665. case IH_OS_QNX: os = "QNX"; break;
  666. case IH_OS_U_BOOT: os = "U-Boot"; break;
  667. case IH_OS_RTEMS: os = "RTEMS"; break;
  668. #ifdef CONFIG_ARTOS
  669. case IH_OS_ARTOS: os = "ARTOS"; break;
  670. #endif
  671. #ifdef CONFIG_LYNXKDI
  672. case IH_OS_LYNXOS: os = "LynxOS"; break;
  673. #endif
  674. default: os = "Unknown OS"; break;
  675. }
  676. switch (image_get_arch (hdr)) {
  677. case IH_ARCH_INVALID: arch = "Invalid CPU"; break;
  678. case IH_ARCH_ALPHA: arch = "Alpha"; break;
  679. case IH_ARCH_ARM: arch = "ARM"; break;
  680. case IH_ARCH_AVR32: arch = "AVR32"; break;
  681. case IH_ARCH_BLACKFIN: arch = "Blackfin"; break;
  682. case IH_ARCH_I386: arch = "Intel x86"; break;
  683. case IH_ARCH_IA64: arch = "IA64"; break;
  684. case IH_ARCH_M68K: arch = "M68K"; break;
  685. case IH_ARCH_MICROBLAZE:arch = "Microblaze"; break;
  686. case IH_ARCH_MIPS64: arch = "MIPS 64 Bit"; break;
  687. case IH_ARCH_MIPS: arch = "MIPS"; break;
  688. case IH_ARCH_NIOS2: arch = "Nios-II"; break;
  689. case IH_ARCH_NIOS: arch = "Nios"; break;
  690. case IH_ARCH_PPC: arch = "PowerPC"; break;
  691. case IH_ARCH_S390: arch = "IBM S390"; break;
  692. case IH_ARCH_SH: arch = "SuperH"; break;
  693. case IH_ARCH_SPARC64: arch = "SPARC 64 Bit"; break;
  694. case IH_ARCH_SPARC: arch = "SPARC"; break;
  695. default: arch = "Unknown Architecture"; break;
  696. }
  697. switch (image_get_type (hdr)) {
  698. case IH_TYPE_INVALID: type = "Invalid Image"; break;
  699. case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
  700. case IH_TYPE_KERNEL: type = "Kernel Image"; break;
  701. case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
  702. case IH_TYPE_MULTI: type = "Multi-File Image"; break;
  703. case IH_TYPE_FIRMWARE: type = "Firmware"; break;
  704. case IH_TYPE_SCRIPT: type = "Script"; break;
  705. case IH_TYPE_FLATDT: type = "Flat Device Tree"; break;
  706. default: type = "Unknown Image"; break;
  707. }
  708. switch (image_get_comp (hdr)) {
  709. case IH_COMP_NONE: comp = "uncompressed"; break;
  710. case IH_COMP_GZIP: comp = "gzip compressed"; break;
  711. case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
  712. default: comp = "unknown compression"; break;
  713. }
  714. printf ("%s %s %s (%s)", arch, os, type, comp);
  715. }
  716. static void
  717. do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  718. ulong addr, ulong *len_ptr, int verify)
  719. {
  720. image_header_t *hdr = &header;
  721. void (*entry_point)(bd_t *);
  722. entry_point = (void (*)(bd_t *))image_get_ep (hdr);
  723. printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
  724. (ulong)entry_point);
  725. show_boot_progress (15);
  726. /*
  727. * RTEMS Parameters:
  728. * r3: ptr to board info data
  729. */
  730. (*entry_point ) ( gd->bd );
  731. }
  732. #if defined(CONFIG_CMD_ELF)
  733. static void
  734. do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  735. ulong addr, ulong *len_ptr, int verify)
  736. {
  737. image_header_t *hdr = &header;
  738. char str[80];
  739. sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
  740. setenv("loadaddr", str);
  741. do_bootvx(cmdtp, 0, 0, NULL);
  742. }
  743. static void
  744. do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  745. ulong addr, ulong *len_ptr, int verify)
  746. {
  747. image_header_t *hdr = &header;
  748. char *local_args[2];
  749. char str[16];
  750. sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
  751. local_args[0] = argv[0];
  752. local_args[1] = str; /* and provide it via the arguments */
  753. do_bootelf(cmdtp, 0, 2, local_args);
  754. }
  755. #endif
  756. #ifdef CONFIG_LYNXKDI
  757. static void
  758. do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
  759. int argc, char *argv[],
  760. ulong addr,
  761. ulong *len_ptr,
  762. int verify)
  763. {
  764. lynxkdi_boot( &header );
  765. }
  766. #endif /* CONFIG_LYNXKDI */