cmd_bootm.c 20 KB

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