cmd_bootm.c 21 KB

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