cmd_bootm.c 23 KB

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