cmd_bootm.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  217. size_t l = len;
  218. void *to = (void *)image_get_load (hdr);
  219. void *from = (void *)data;
  220. printf (" Loading %s ... ", name);
  221. while (l > 0) {
  222. size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
  223. WATCHDOG_RESET();
  224. memmove (to, from, tail);
  225. to += tail;
  226. from += tail;
  227. l -= tail;
  228. }
  229. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  230. memmove ((void *)image_get_load (hdr), (uchar *)data, len);
  231. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  232. }
  233. break;
  234. case IH_COMP_GZIP:
  235. printf (" Uncompressing %s ... ", name);
  236. if (gunzip ((void *)image_get_load (hdr), unc_len,
  237. (uchar *)data, &len) != 0) {
  238. puts ("GUNZIP ERROR - must RESET board to recover\n");
  239. show_boot_progress (-6);
  240. do_reset (cmdtp, flag, argc, argv);
  241. }
  242. break;
  243. #ifdef CONFIG_BZIP2
  244. case IH_COMP_BZIP2:
  245. printf (" Uncompressing %s ... ", name);
  246. /*
  247. * If we've got less than 4 MB of malloc() space,
  248. * use slower decompression algorithm which requires
  249. * at most 2300 KB of memory.
  250. */
  251. i = BZ2_bzBuffToBuffDecompress ((char*)image_get_load (hdr),
  252. &unc_len, (char *)data, len,
  253. CFG_MALLOC_LEN < (4096 * 1024), 0);
  254. if (i != BZ_OK) {
  255. printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
  256. show_boot_progress (-6);
  257. do_reset (cmdtp, flag, argc, argv);
  258. }
  259. break;
  260. #endif /* CONFIG_BZIP2 */
  261. default:
  262. if (iflag)
  263. enable_interrupts();
  264. printf ("Unimplemented compression type %d\n", image_get_comp (hdr));
  265. show_boot_progress (-7);
  266. return 1;
  267. }
  268. puts ("OK\n");
  269. show_boot_progress (7);
  270. switch (image_get_type (hdr)) {
  271. case IH_TYPE_STANDALONE:
  272. if (iflag)
  273. enable_interrupts();
  274. /* load (and uncompress), but don't start if "autostart"
  275. * is set to "no"
  276. */
  277. if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
  278. char buf[32];
  279. sprintf(buf, "%lX", len);
  280. setenv("filesize", buf);
  281. return 0;
  282. }
  283. appl = (int (*)(int, char *[]))image_get_ep (hdr);
  284. (*appl)(argc-1, &argv[1]);
  285. return 0;
  286. case IH_TYPE_KERNEL:
  287. case IH_TYPE_MULTI:
  288. /* handled below */
  289. break;
  290. default:
  291. if (iflag)
  292. enable_interrupts();
  293. printf ("Can't boot image type %d\n", image_get_type (hdr));
  294. show_boot_progress (-8);
  295. return 1;
  296. }
  297. show_boot_progress (8);
  298. switch (image_get_os (hdr)) {
  299. default: /* handled by (original) Linux case */
  300. case IH_OS_LINUX:
  301. #ifdef CONFIG_SILENT_CONSOLE
  302. fixup_silent_linux();
  303. #endif
  304. do_bootm_linux (cmdtp, flag, argc, argv,
  305. addr, len_ptr, verify);
  306. break;
  307. case IH_OS_NETBSD:
  308. do_bootm_netbsd (cmdtp, flag, argc, argv,
  309. addr, len_ptr, verify);
  310. break;
  311. #ifdef CONFIG_LYNXKDI
  312. case IH_OS_LYNXOS:
  313. do_bootm_lynxkdi (cmdtp, flag, argc, argv,
  314. addr, len_ptr, verify);
  315. break;
  316. #endif
  317. case IH_OS_RTEMS:
  318. do_bootm_rtems (cmdtp, flag, argc, argv,
  319. addr, len_ptr, verify);
  320. break;
  321. #if defined(CONFIG_CMD_ELF)
  322. case IH_OS_VXWORKS:
  323. do_bootm_vxworks (cmdtp, flag, argc, argv,
  324. addr, len_ptr, verify);
  325. break;
  326. case IH_OS_QNX:
  327. do_bootm_qnxelf (cmdtp, flag, argc, argv,
  328. addr, len_ptr, verify);
  329. break;
  330. #endif
  331. #ifdef CONFIG_ARTOS
  332. case IH_OS_ARTOS:
  333. do_bootm_artos (cmdtp, flag, argc, argv,
  334. addr, len_ptr, verify);
  335. break;
  336. #endif
  337. }
  338. show_boot_progress (-9);
  339. #ifdef DEBUG
  340. puts ("\n## Control returned to monitor - resetting...\n");
  341. do_reset (cmdtp, flag, argc, argv);
  342. #endif
  343. return 1;
  344. }
  345. U_BOOT_CMD(
  346. bootm, CFG_MAXARGS, 1, do_bootm,
  347. "bootm - boot application image from memory\n",
  348. "[addr [arg ...]]\n - boot application image stored in memory\n"
  349. "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
  350. "\t'arg' can be the address of an initrd image\n"
  351. #if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
  352. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  353. "\ta third argument is required which is the address of the\n"
  354. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  355. "\tuse a '-' for the second argument. If you do not pass a third\n"
  356. "\ta bd_info struct will be passed instead\n"
  357. #endif
  358. );
  359. #ifdef CONFIG_SILENT_CONSOLE
  360. static void
  361. fixup_silent_linux ()
  362. {
  363. char buf[256], *start, *end;
  364. char *cmdline = getenv ("bootargs");
  365. /* Only fix cmdline when requested */
  366. if (!(gd->flags & GD_FLG_SILENT))
  367. return;
  368. debug ("before silent fix-up: %s\n", cmdline);
  369. if (cmdline) {
  370. if ((start = strstr (cmdline, "console=")) != NULL) {
  371. end = strchr (start, ' ');
  372. strncpy (buf, cmdline, (start - cmdline + 8));
  373. if (end)
  374. strcpy (buf + (start - cmdline + 8), end);
  375. else
  376. buf[start - cmdline + 8] = '\0';
  377. } else {
  378. strcpy (buf, cmdline);
  379. strcat (buf, " console=");
  380. }
  381. } else {
  382. strcpy (buf, "console=");
  383. }
  384. setenv ("bootargs", buf);
  385. debug ("after silent fix-up: %s\n", buf);
  386. }
  387. #endif /* CONFIG_SILENT_CONSOLE */
  388. static void
  389. do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
  390. int argc, char *argv[],
  391. ulong addr,
  392. ulong *len_ptr,
  393. int verify)
  394. {
  395. image_header_t *hdr = &header;
  396. void (*loader)(bd_t *, image_header_t *, char *, char *);
  397. image_header_t *img_addr;
  398. char *consdev;
  399. char *cmdline;
  400. /*
  401. * Booting a (NetBSD) kernel image
  402. *
  403. * This process is pretty similar to a standalone application:
  404. * The (first part of an multi-) image must be a stage-2 loader,
  405. * which in turn is responsible for loading & invoking the actual
  406. * kernel. The only differences are the parameters being passed:
  407. * besides the board info strucure, the loader expects a command
  408. * line, the name of the console device, and (optionally) the
  409. * address of the original image header.
  410. */
  411. img_addr = 0;
  412. if ((image_check_type (hdr, IH_TYPE_MULTI)) && (len_ptr[1]))
  413. img_addr = (image_header_t *) addr;
  414. consdev = "";
  415. #if defined (CONFIG_8xx_CONS_SMC1)
  416. consdev = "smc1";
  417. #elif defined (CONFIG_8xx_CONS_SMC2)
  418. consdev = "smc2";
  419. #elif defined (CONFIG_8xx_CONS_SCC2)
  420. consdev = "scc2";
  421. #elif defined (CONFIG_8xx_CONS_SCC3)
  422. consdev = "scc3";
  423. #endif
  424. if (argc > 2) {
  425. ulong len;
  426. int i;
  427. for (i=2, len=0 ; i<argc ; i+=1)
  428. len += strlen (argv[i]) + 1;
  429. cmdline = malloc (len);
  430. for (i=2, len=0 ; i<argc ; i+=1) {
  431. if (i > 2)
  432. cmdline[len++] = ' ';
  433. strcpy (&cmdline[len], argv[i]);
  434. len += strlen (argv[i]);
  435. }
  436. } else if ((cmdline = getenv("bootargs")) == NULL) {
  437. cmdline = "";
  438. }
  439. loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
  440. printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
  441. (ulong)loader);
  442. show_boot_progress (15);
  443. /*
  444. * NetBSD Stage-2 Loader Parameters:
  445. * r3: ptr to board info data
  446. * r4: image address
  447. * r5: console device
  448. * r6: boot args string
  449. */
  450. (*loader) (gd->bd, img_addr, consdev, cmdline);
  451. }
  452. #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
  453. /* Function that returns a character from the environment */
  454. extern uchar (*env_get_char)(int);
  455. static void
  456. do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
  457. int argc, char *argv[],
  458. ulong addr,
  459. ulong *len_ptr,
  460. int verify)
  461. {
  462. ulong top;
  463. char *s, *cmdline;
  464. char **fwenv, **ss;
  465. int i, j, nxt, len, envno, envsz;
  466. bd_t *kbd;
  467. void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
  468. image_header_t *hdr = &header;
  469. /*
  470. * Booting an ARTOS kernel image + application
  471. */
  472. /* this used to be the top of memory, but was wrong... */
  473. #ifdef CONFIG_PPC
  474. /* get stack pointer */
  475. asm volatile ("mr %0,1" : "=r"(top) );
  476. #endif
  477. debug ("## Current stack ends at 0x%08lX ", top);
  478. top -= 2048; /* just to be sure */
  479. if (top > CFG_BOOTMAPSZ)
  480. top = CFG_BOOTMAPSZ;
  481. top &= ~0xF;
  482. debug ("=> set upper limit to 0x%08lX\n", top);
  483. /* first check the artos specific boot args, then the linux args*/
  484. if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
  485. s = "";
  486. /* get length of cmdline, and place it */
  487. len = strlen(s);
  488. top = (top - (len + 1)) & ~0xF;
  489. cmdline = (char *)top;
  490. debug ("## cmdline at 0x%08lX ", top);
  491. strcpy(cmdline, s);
  492. /* copy bdinfo */
  493. top = (top - sizeof(bd_t)) & ~0xF;
  494. debug ("## bd at 0x%08lX ", top);
  495. kbd = (bd_t *)top;
  496. memcpy(kbd, gd->bd, sizeof(bd_t));
  497. /* first find number of env entries, and their size */
  498. envno = 0;
  499. envsz = 0;
  500. for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
  501. for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
  502. ;
  503. envno++;
  504. envsz += (nxt - i) + 1; /* plus trailing zero */
  505. }
  506. envno++; /* plus the terminating zero */
  507. debug ("## %u envvars total size %u ", envno, envsz);
  508. top = (top - sizeof(char **)*envno) & ~0xF;
  509. fwenv = (char **)top;
  510. debug ("## fwenv at 0x%08lX ", top);
  511. top = (top - envsz) & ~0xF;
  512. s = (char *)top;
  513. ss = fwenv;
  514. /* now copy them */
  515. for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
  516. for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
  517. ;
  518. *ss++ = s;
  519. for (j = i; j < nxt; ++j)
  520. *s++ = env_get_char(j);
  521. *s++ = '\0';
  522. }
  523. *ss++ = NULL; /* terminate */
  524. entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
  525. (*entry)(kbd, cmdline, fwenv, top);
  526. }
  527. #endif
  528. #if defined(CONFIG_CMD_BOOTD)
  529. int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  530. {
  531. int rcode = 0;
  532. #ifndef CFG_HUSH_PARSER
  533. if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
  534. #else
  535. if (parse_string_outer(getenv("bootcmd"),
  536. FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
  537. #endif
  538. return rcode;
  539. }
  540. U_BOOT_CMD(
  541. boot, 1, 1, do_bootd,
  542. "boot - boot default, i.e., run 'bootcmd'\n",
  543. NULL
  544. );
  545. /* keep old command name "bootd" for backward compatibility */
  546. U_BOOT_CMD(
  547. bootd, 1, 1, do_bootd,
  548. "bootd - boot default, i.e., run 'bootcmd'\n",
  549. NULL
  550. );
  551. #endif
  552. #if defined(CONFIG_CMD_IMI)
  553. int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  554. {
  555. int arg;
  556. ulong addr;
  557. int rcode=0;
  558. if (argc < 2) {
  559. return image_info (load_addr);
  560. }
  561. for (arg=1; arg <argc; ++arg) {
  562. addr = simple_strtoul(argv[arg], NULL, 16);
  563. if (image_info (addr) != 0) rcode = 1;
  564. }
  565. return rcode;
  566. }
  567. static int image_info (ulong addr)
  568. {
  569. image_header_t *hdr = (image_header_t *)addr;
  570. printf ("\n## Checking Image at %08lx ...\n", addr);
  571. if (!image_check_magic (hdr)) {
  572. puts (" Bad Magic Number\n");
  573. return 1;
  574. }
  575. if (!image_check_hcrc (hdr)) {
  576. puts (" Bad Header Checksum\n");
  577. return 1;
  578. }
  579. print_image_hdr (hdr);
  580. puts (" Verifying Checksum ... ");
  581. if (!image_check_dcrc (hdr)) {
  582. puts (" Bad Data CRC\n");
  583. return 1;
  584. }
  585. puts ("OK\n");
  586. return 0;
  587. }
  588. U_BOOT_CMD(
  589. iminfo, CFG_MAXARGS, 1, do_iminfo,
  590. "iminfo - print header information for application image\n",
  591. "addr [addr ...]\n"
  592. " - print header information for application image starting at\n"
  593. " address 'addr' in memory; this includes verification of the\n"
  594. " image contents (magic number, header and payload checksums)\n"
  595. );
  596. #endif
  597. #if defined(CONFIG_CMD_IMLS)
  598. /*-----------------------------------------------------------------------
  599. * List all images found in flash.
  600. */
  601. int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  602. {
  603. flash_info_t *info;
  604. int i, j;
  605. image_header_t *hdr;
  606. for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
  607. if (info->flash_id == FLASH_UNKNOWN)
  608. goto next_bank;
  609. for (j=0; j<info->sector_count; ++j) {
  610. hdr = (image_header_t *)info->start[j];
  611. if (!hdr || !image_check_magic (hdr))
  612. goto next_sector;
  613. if (!image_check_hcrc (hdr))
  614. goto next_sector;
  615. printf ("Image at %08lX:\n", (ulong)hdr);
  616. print_image_hdr (hdr);
  617. puts (" Verifying Checksum ... ");
  618. if (!image_check_dcrc (hdr)) {
  619. puts ("Bad Data CRC\n");
  620. } else {
  621. puts ("OK\n");
  622. }
  623. next_sector: ;
  624. }
  625. next_bank: ;
  626. }
  627. return (0);
  628. }
  629. U_BOOT_CMD(
  630. imls, 1, 1, do_imls,
  631. "imls - list all images found in flash\n",
  632. "\n"
  633. " - Prints information about all images found at sector\n"
  634. " boundaries in flash.\n"
  635. );
  636. #endif
  637. void
  638. print_image_hdr (image_header_t *hdr)
  639. {
  640. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
  641. time_t timestamp = (time_t)image_get_time (hdr);
  642. struct rtc_time tm;
  643. #endif
  644. printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr));
  645. #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
  646. to_tm (timestamp, &tm);
  647. printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
  648. tm.tm_year, tm.tm_mon, tm.tm_mday,
  649. tm.tm_hour, tm.tm_min, tm.tm_sec);
  650. #endif
  651. puts (" Image Type: "); print_type(hdr);
  652. printf ("\n Data Size: %d Bytes = ", image_get_data_size (hdr));
  653. print_size (image_get_data_size (hdr), "\n");
  654. printf (" Load Address: %08x\n"
  655. " Entry Point: %08x\n",
  656. image_get_load (hdr), image_get_ep (hdr));
  657. if (image_check_type (hdr, IH_TYPE_MULTI)) {
  658. int i;
  659. ulong len;
  660. ulong *len_ptr = (ulong *)((ulong)hdr + image_get_header_size ());
  661. puts (" Contents:\n");
  662. for (i=0; (len = image_to_cpu (*len_ptr)); ++i, ++len_ptr) {
  663. printf (" Image %d: %8ld Bytes = ", i, len);
  664. print_size (len, "\n");
  665. }
  666. }
  667. }
  668. static void
  669. print_type (image_header_t *hdr)
  670. {
  671. char *os, *arch, *type, *comp;
  672. switch (image_get_os (hdr)) {
  673. case IH_OS_INVALID: os = "Invalid OS"; break;
  674. case IH_OS_NETBSD: os = "NetBSD"; break;
  675. case IH_OS_LINUX: os = "Linux"; break;
  676. case IH_OS_VXWORKS: os = "VxWorks"; break;
  677. case IH_OS_QNX: os = "QNX"; break;
  678. case IH_OS_U_BOOT: os = "U-Boot"; break;
  679. case IH_OS_RTEMS: os = "RTEMS"; break;
  680. #ifdef CONFIG_ARTOS
  681. case IH_OS_ARTOS: os = "ARTOS"; break;
  682. #endif
  683. #ifdef CONFIG_LYNXKDI
  684. case IH_OS_LYNXOS: os = "LynxOS"; break;
  685. #endif
  686. default: os = "Unknown OS"; break;
  687. }
  688. switch (image_get_arch (hdr)) {
  689. case IH_ARCH_INVALID: arch = "Invalid CPU"; break;
  690. case IH_ARCH_ALPHA: arch = "Alpha"; break;
  691. case IH_ARCH_ARM: arch = "ARM"; break;
  692. case IH_ARCH_AVR32: arch = "AVR32"; break;
  693. case IH_ARCH_BLACKFIN: arch = "Blackfin"; break;
  694. case IH_ARCH_I386: arch = "Intel x86"; break;
  695. case IH_ARCH_IA64: arch = "IA64"; break;
  696. case IH_ARCH_M68K: arch = "M68K"; break;
  697. case IH_ARCH_MICROBLAZE:arch = "Microblaze"; break;
  698. case IH_ARCH_MIPS64: arch = "MIPS 64 Bit"; break;
  699. case IH_ARCH_MIPS: arch = "MIPS"; break;
  700. case IH_ARCH_NIOS2: arch = "Nios-II"; break;
  701. case IH_ARCH_NIOS: arch = "Nios"; break;
  702. case IH_ARCH_PPC: arch = "PowerPC"; break;
  703. case IH_ARCH_S390: arch = "IBM S390"; break;
  704. case IH_ARCH_SH: arch = "SuperH"; break;
  705. case IH_ARCH_SPARC64: arch = "SPARC 64 Bit"; break;
  706. case IH_ARCH_SPARC: arch = "SPARC"; break;
  707. default: arch = "Unknown Architecture"; break;
  708. }
  709. switch (image_get_type (hdr)) {
  710. case IH_TYPE_INVALID: type = "Invalid Image"; break;
  711. case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
  712. case IH_TYPE_KERNEL: type = "Kernel Image"; break;
  713. case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
  714. case IH_TYPE_MULTI: type = "Multi-File Image"; break;
  715. case IH_TYPE_FIRMWARE: type = "Firmware"; break;
  716. case IH_TYPE_SCRIPT: type = "Script"; break;
  717. case IH_TYPE_FLATDT: type = "Flat Device Tree"; break;
  718. default: type = "Unknown Image"; break;
  719. }
  720. switch (image_get_comp (hdr)) {
  721. case IH_COMP_NONE: comp = "uncompressed"; break;
  722. case IH_COMP_GZIP: comp = "gzip compressed"; break;
  723. case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
  724. default: comp = "unknown compression"; break;
  725. }
  726. printf ("%s %s %s (%s)", arch, os, type, comp);
  727. }
  728. static void
  729. do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  730. ulong addr, ulong *len_ptr, int verify)
  731. {
  732. image_header_t *hdr = &header;
  733. void (*entry_point)(bd_t *);
  734. entry_point = (void (*)(bd_t *))image_get_ep (hdr);
  735. printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
  736. (ulong)entry_point);
  737. show_boot_progress (15);
  738. /*
  739. * RTEMS Parameters:
  740. * r3: ptr to board info data
  741. */
  742. (*entry_point ) ( gd->bd );
  743. }
  744. #if defined(CONFIG_CMD_ELF)
  745. static void
  746. do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  747. ulong addr, ulong *len_ptr, int verify)
  748. {
  749. image_header_t *hdr = &header;
  750. char str[80];
  751. sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
  752. setenv("loadaddr", str);
  753. do_bootvx(cmdtp, 0, 0, NULL);
  754. }
  755. static void
  756. do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  757. ulong addr, ulong *len_ptr, int verify)
  758. {
  759. image_header_t *hdr = &header;
  760. char *local_args[2];
  761. char str[16];
  762. sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
  763. local_args[0] = argv[0];
  764. local_args[1] = str; /* and provide it via the arguments */
  765. do_bootelf(cmdtp, 0, 2, local_args);
  766. }
  767. #endif
  768. #ifdef CONFIG_LYNXKDI
  769. static void
  770. do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
  771. int argc, char *argv[],
  772. ulong addr,
  773. ulong *len_ptr,
  774. int verify)
  775. {
  776. lynxkdi_boot( &header );
  777. }
  778. #endif /* CONFIG_LYNXKDI */