cmd_bootm.c 23 KB

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