cmd_bootm.c 21 KB

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