cmd_bootm.c 24 KB

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