cmd_bootm.c 23 KB

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