cmd_bootm.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  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 image_header_t *image_get_kernel (ulong img_addr, int verify)
  260. {
  261. image_header_t *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. image_print_contents (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. return hdr;
  291. }
  292. /**
  293. * get_kernel - find kernel image
  294. * @os_data: pointer to a ulong variable, will hold os data start address
  295. * @os_len: pointer to a ulong variable, will hold os data length
  296. *
  297. * get_kernel() tries to find a kernel image, verifies its integrity
  298. * and locates kernel data.
  299. *
  300. * returns:
  301. * pointer to image header if valid image was found, plus kernel start
  302. * address and length, otherwise NULL
  303. */
  304. static void *get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  305. bootm_headers_t *images, ulong *os_data, ulong *os_len)
  306. {
  307. image_header_t *hdr;
  308. ulong img_addr;
  309. #if defined(CONFIG_FIT)
  310. void *fit_hdr;
  311. const char *fit_uname_config = NULL;
  312. const char *fit_uname_kernel = NULL;
  313. #endif
  314. /* find out kernel image address */
  315. if (argc < 2) {
  316. img_addr = load_addr;
  317. debug ("* kernel: default image load address = 0x%08lx\n",
  318. load_addr);
  319. #if defined(CONFIG_FIT)
  320. } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
  321. &fit_uname_config)) {
  322. debug ("* kernel: config '%s' from image at 0x%08lx\n",
  323. fit_uname_config, img_addr);
  324. } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
  325. &fit_uname_kernel)) {
  326. debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
  327. fit_uname_kernel, img_addr);
  328. #endif
  329. } else {
  330. img_addr = simple_strtoul(argv[1], NULL, 16);
  331. debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
  332. }
  333. show_boot_progress (1);
  334. printf ("## Booting kernel image at %08lx ...\n", img_addr);
  335. /* copy from dataflash if needed */
  336. img_addr = gen_get_image (img_addr);
  337. /* check image type, for FIT images get FIT kernel node */
  338. switch (gen_image_get_format ((void *)img_addr)) {
  339. case IMAGE_FORMAT_LEGACY:
  340. debug ("* kernel: legacy format image\n");
  341. hdr = image_get_kernel (img_addr, images->verify);
  342. if (!hdr)
  343. return NULL;
  344. show_boot_progress (5);
  345. switch (image_get_type (hdr)) {
  346. case IH_TYPE_KERNEL:
  347. *os_data = image_get_data (hdr);
  348. *os_len = image_get_data_size (hdr);
  349. break;
  350. case IH_TYPE_MULTI:
  351. image_multi_getimg (hdr, 0, os_data, os_len);
  352. break;
  353. default:
  354. printf ("Wrong Image Type for %s command\n", cmdtp->name);
  355. show_boot_progress (-5);
  356. return NULL;
  357. }
  358. images->legacy_hdr_os = hdr;
  359. images->legacy_hdr_valid = 1;
  360. break;
  361. #if defined(CONFIG_FIT)
  362. case IMAGE_FORMAT_FIT:
  363. fit_hdr = (void *)img_addr;
  364. debug ("* kernel: FIT format image\n");
  365. fit_unsupported ("kernel");
  366. return NULL;
  367. #endif
  368. default:
  369. printf ("Wrong Image Format for %s command\n", cmdtp->name);
  370. return NULL;
  371. }
  372. debug (" kernel data at 0x%08lx, end = 0x%08lx\n",
  373. *os_data, *os_data + *os_len);
  374. return (void *)img_addr;
  375. }
  376. U_BOOT_CMD(
  377. bootm, CFG_MAXARGS, 1, do_bootm,
  378. "bootm - boot application image from memory\n",
  379. "[addr [arg ...]]\n - boot application image stored in memory\n"
  380. "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
  381. "\t'arg' can be the address of an initrd image\n"
  382. #if defined(CONFIG_OF_LIBFDT)
  383. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  384. "\ta third argument is required which is the address of the\n"
  385. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  386. "\tuse a '-' for the second argument. If you do not pass a third\n"
  387. "\ta bd_info struct will be passed instead\n"
  388. #endif
  389. );
  390. /*******************************************************************/
  391. /* bootd - boot default image */
  392. /*******************************************************************/
  393. #if defined(CONFIG_CMD_BOOTD)
  394. int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  395. {
  396. int rcode = 0;
  397. #ifndef CFG_HUSH_PARSER
  398. if (run_command (getenv ("bootcmd"), flag) < 0)
  399. rcode = 1;
  400. #else
  401. if (parse_string_outer (getenv ("bootcmd"),
  402. FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
  403. rcode = 1;
  404. #endif
  405. return rcode;
  406. }
  407. U_BOOT_CMD(
  408. boot, 1, 1, do_bootd,
  409. "boot - boot default, i.e., run 'bootcmd'\n",
  410. NULL
  411. );
  412. /* keep old command name "bootd" for backward compatibility */
  413. U_BOOT_CMD(
  414. bootd, 1, 1, do_bootd,
  415. "bootd - boot default, i.e., run 'bootcmd'\n",
  416. NULL
  417. );
  418. #endif
  419. /*******************************************************************/
  420. /* iminfo - print header info for a requested image */
  421. /*******************************************************************/
  422. #if defined(CONFIG_CMD_IMI)
  423. int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  424. {
  425. int arg;
  426. ulong addr;
  427. int rcode = 0;
  428. if (argc < 2) {
  429. return image_info (load_addr);
  430. }
  431. for (arg = 1; arg < argc; ++arg) {
  432. addr = simple_strtoul (argv[arg], NULL, 16);
  433. if (image_info (addr) != 0)
  434. rcode = 1;
  435. }
  436. return rcode;
  437. }
  438. static int image_info (ulong addr)
  439. {
  440. void *hdr = (void *)addr;
  441. printf ("\n## Checking Image at %08lx ...\n", addr);
  442. switch (gen_image_get_format (hdr)) {
  443. case IMAGE_FORMAT_LEGACY:
  444. puts (" Legacy image found\n");
  445. if (!image_check_magic (hdr)) {
  446. puts (" Bad Magic Number\n");
  447. return 1;
  448. }
  449. if (!image_check_hcrc (hdr)) {
  450. puts (" Bad Header Checksum\n");
  451. return 1;
  452. }
  453. image_print_contents (hdr);
  454. puts (" Verifying Checksum ... ");
  455. if (!image_check_dcrc (hdr)) {
  456. puts (" Bad Data CRC\n");
  457. return 1;
  458. }
  459. puts ("OK\n");
  460. return 0;
  461. #if defined(CONFIG_FIT)
  462. case IMAGE_FORMAT_FIT:
  463. puts (" FIT image found\n");
  464. fit_unsupported ("iminfo");
  465. return 0;
  466. #endif
  467. default:
  468. puts ("Unknown image format!\n");
  469. break;
  470. }
  471. return 1;
  472. }
  473. U_BOOT_CMD(
  474. iminfo, CFG_MAXARGS, 1, do_iminfo,
  475. "iminfo - print header information for application image\n",
  476. "addr [addr ...]\n"
  477. " - print header information for application image starting at\n"
  478. " address 'addr' in memory; this includes verification of the\n"
  479. " image contents (magic number, header and payload checksums)\n"
  480. );
  481. #endif
  482. /*******************************************************************/
  483. /* imls - list all images found in flash */
  484. /*******************************************************************/
  485. #if defined(CONFIG_CMD_IMLS)
  486. int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  487. {
  488. flash_info_t *info;
  489. int i, j;
  490. void *hdr;
  491. for (i = 0, info = &flash_info[0];
  492. i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
  493. if (info->flash_id == FLASH_UNKNOWN)
  494. goto next_bank;
  495. for (j = 0; j < info->sector_count; ++j) {
  496. hdr = (void *)info->start[j];
  497. if (!hdr)
  498. goto next_sector;
  499. switch (gen_image_get_format (hdr)) {
  500. case IMAGE_FORMAT_LEGACY:
  501. if (!image_check_magic (hdr))
  502. goto next_sector;
  503. if (!image_check_hcrc (hdr))
  504. goto next_sector;
  505. printf ("Legacy Image at %08lX:\n", (ulong)hdr);
  506. image_print_contents (hdr);
  507. puts (" Verifying Checksum ... ");
  508. if (!image_check_dcrc (hdr)) {
  509. puts ("Bad Data CRC\n");
  510. } else {
  511. puts ("OK\n");
  512. }
  513. break;
  514. #if defined(CONFIG_FIT)
  515. case IMAGE_FORMAT_FIT:
  516. printf ("FIT Image at %08lX:\n", (ulong)hdr);
  517. fit_unsupported ("imls");
  518. break;
  519. #endif
  520. default:
  521. goto next_sector;
  522. }
  523. next_sector: ;
  524. }
  525. next_bank: ;
  526. }
  527. return (0);
  528. }
  529. U_BOOT_CMD(
  530. imls, 1, 1, do_imls,
  531. "imls - list all images found in flash\n",
  532. "\n"
  533. " - Prints information about all images found at sector\n"
  534. " boundaries in flash.\n"
  535. );
  536. #endif
  537. /*******************************************************************/
  538. /* helper routines */
  539. /*******************************************************************/
  540. #ifdef CONFIG_SILENT_CONSOLE
  541. static void fixup_silent_linux ()
  542. {
  543. char buf[256], *start, *end;
  544. char *cmdline = getenv ("bootargs");
  545. /* Only fix cmdline when requested */
  546. if (!(gd->flags & GD_FLG_SILENT))
  547. return;
  548. debug ("before silent fix-up: %s\n", cmdline);
  549. if (cmdline) {
  550. if ((start = strstr (cmdline, "console=")) != NULL) {
  551. end = strchr (start, ' ');
  552. strncpy (buf, cmdline, (start - cmdline + 8));
  553. if (end)
  554. strcpy (buf + (start - cmdline + 8), end);
  555. else
  556. buf[start - cmdline + 8] = '\0';
  557. } else {
  558. strcpy (buf, cmdline);
  559. strcat (buf, " console=");
  560. }
  561. } else {
  562. strcpy (buf, "console=");
  563. }
  564. setenv ("bootargs", buf);
  565. debug ("after silent fix-up: %s\n", buf);
  566. }
  567. #endif /* CONFIG_SILENT_CONSOLE */
  568. /*******************************************************************/
  569. /* OS booting routines */
  570. /*******************************************************************/
  571. static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
  572. int argc, char *argv[],
  573. bootm_headers_t *images)
  574. {
  575. void (*loader)(bd_t *, image_header_t *, char *, char *);
  576. image_header_t *os_hdr, *hdr;
  577. ulong kernel_data, kernel_len;
  578. char *consdev;
  579. char *cmdline;
  580. #if defined(CONFIG_FIT)
  581. if (!images->legacy_hdr_valid) {
  582. fit_unsupported_reset ("NetBSD");
  583. do_reset (cmdtp, flag, argc, argv);
  584. }
  585. #endif
  586. hdr = images->legacy_hdr_os;
  587. /*
  588. * Booting a (NetBSD) kernel image
  589. *
  590. * This process is pretty similar to a standalone application:
  591. * The (first part of an multi-) image must be a stage-2 loader,
  592. * which in turn is responsible for loading & invoking the actual
  593. * kernel. The only differences are the parameters being passed:
  594. * besides the board info strucure, the loader expects a command
  595. * line, the name of the console device, and (optionally) the
  596. * address of the original image header.
  597. */
  598. os_hdr = NULL;
  599. if (image_check_type (hdr, IH_TYPE_MULTI)) {
  600. image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
  601. if (kernel_len)
  602. os_hdr = hdr;
  603. }
  604. consdev = "";
  605. #if defined (CONFIG_8xx_CONS_SMC1)
  606. consdev = "smc1";
  607. #elif defined (CONFIG_8xx_CONS_SMC2)
  608. consdev = "smc2";
  609. #elif defined (CONFIG_8xx_CONS_SCC2)
  610. consdev = "scc2";
  611. #elif defined (CONFIG_8xx_CONS_SCC3)
  612. consdev = "scc3";
  613. #endif
  614. if (argc > 2) {
  615. ulong len;
  616. int i;
  617. for (i = 2, len = 0; i < argc; i += 1)
  618. len += strlen (argv[i]) + 1;
  619. cmdline = malloc (len);
  620. for (i = 2, len = 0; i < argc; i += 1) {
  621. if (i > 2)
  622. cmdline[len++] = ' ';
  623. strcpy (&cmdline[len], argv[i]);
  624. len += strlen (argv[i]);
  625. }
  626. } else if ((cmdline = getenv ("bootargs")) == NULL) {
  627. cmdline = "";
  628. }
  629. loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
  630. printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
  631. (ulong)loader);
  632. show_boot_progress (15);
  633. /*
  634. * NetBSD Stage-2 Loader Parameters:
  635. * r3: ptr to board info data
  636. * r4: image address
  637. * r5: console device
  638. * r6: boot args string
  639. */
  640. (*loader) (gd->bd, os_hdr, consdev, cmdline);
  641. }
  642. #ifdef CONFIG_LYNXKDI
  643. static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
  644. int argc, char *argv[],
  645. bootm_headers_t *images)
  646. {
  647. image_header_t *hdr = images->legacy_hdr_os;
  648. #if defined(CONFIG_FIT)
  649. if (!images->legacy_hdr_valid) {
  650. fit_unsupported_reset ("Lynx");
  651. do_reset (cmdtp, flag, argc, argv);
  652. }
  653. #endif
  654. lynxkdi_boot ((image_header_t *)hdr);
  655. }
  656. #endif /* CONFIG_LYNXKDI */
  657. static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
  658. int argc, char *argv[],
  659. bootm_headers_t *images)
  660. {
  661. image_header_t *hdr = images->legacy_hdr_os;
  662. void (*entry_point)(bd_t *);
  663. #if defined(CONFIG_FIT)
  664. if (!images->legacy_hdr_valid) {
  665. fit_unsupported_reset ("RTEMS");
  666. do_reset (cmdtp, flag, argc, argv);
  667. }
  668. #endif
  669. entry_point = (void (*)(bd_t *))image_get_ep (hdr);
  670. printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
  671. (ulong)entry_point);
  672. show_boot_progress (15);
  673. /*
  674. * RTEMS Parameters:
  675. * r3: ptr to board info data
  676. */
  677. (*entry_point)(gd->bd);
  678. }
  679. #if defined(CONFIG_CMD_ELF)
  680. static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
  681. int argc, char *argv[],
  682. bootm_headers_t *images)
  683. {
  684. char str[80];
  685. image_header_t *hdr = images->legacy_hdr_os;
  686. #if defined(CONFIG_FIT)
  687. if (hdr == NULL) {
  688. fit_unsupported_reset ("VxWorks");
  689. do_reset (cmdtp, flag, argc, argv);
  690. }
  691. #endif
  692. sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
  693. setenv("loadaddr", str);
  694. do_bootvx(cmdtp, 0, 0, NULL);
  695. }
  696. static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
  697. int argc, char *argv[],
  698. bootm_headers_t *images)
  699. {
  700. char *local_args[2];
  701. char str[16];
  702. image_header_t *hdr = images->legacy_hdr_os;
  703. #if defined(CONFIG_FIT)
  704. if (!images->legacy_hdr_valid) {
  705. fit_unsupported_reset ("QNX");
  706. do_reset (cmdtp, flag, argc, argv);
  707. }
  708. #endif
  709. sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
  710. local_args[0] = argv[0];
  711. local_args[1] = str; /* and provide it via the arguments */
  712. do_bootelf(cmdtp, 0, 2, local_args);
  713. }
  714. #endif
  715. #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
  716. static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
  717. int argc, char *argv[],
  718. bootm_headers_t *images)
  719. {
  720. ulong top;
  721. char *s, *cmdline;
  722. char **fwenv, **ss;
  723. int i, j, nxt, len, envno, envsz;
  724. bd_t *kbd;
  725. void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
  726. image_header_t *hdr = images->legacy_hdr_os;
  727. #if defined(CONFIG_FIT)
  728. if (!images->legacy_hdr_valid) {
  729. fit_unsupported_reset ("ARTOS");
  730. do_reset (cmdtp, flag, argc, argv);
  731. }
  732. #endif
  733. /*
  734. * Booting an ARTOS kernel image + application
  735. */
  736. /* this used to be the top of memory, but was wrong... */
  737. #ifdef CONFIG_PPC
  738. /* get stack pointer */
  739. asm volatile ("mr %0,1" : "=r"(top) );
  740. #endif
  741. debug ("## Current stack ends at 0x%08lX ", top);
  742. top -= 2048; /* just to be sure */
  743. if (top > CFG_BOOTMAPSZ)
  744. top = CFG_BOOTMAPSZ;
  745. top &= ~0xF;
  746. debug ("=> set upper limit to 0x%08lX\n", top);
  747. /* first check the artos specific boot args, then the linux args*/
  748. if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
  749. s = "";
  750. /* get length of cmdline, and place it */
  751. len = strlen (s);
  752. top = (top - (len + 1)) & ~0xF;
  753. cmdline = (char *)top;
  754. debug ("## cmdline at 0x%08lX ", top);
  755. strcpy (cmdline, s);
  756. /* copy bdinfo */
  757. top = (top - sizeof (bd_t)) & ~0xF;
  758. debug ("## bd at 0x%08lX ", top);
  759. kbd = (bd_t *)top;
  760. memcpy (kbd, gd->bd, sizeof (bd_t));
  761. /* first find number of env entries, and their size */
  762. envno = 0;
  763. envsz = 0;
  764. for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
  765. for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
  766. ;
  767. envno++;
  768. envsz += (nxt - i) + 1; /* plus trailing zero */
  769. }
  770. envno++; /* plus the terminating zero */
  771. debug ("## %u envvars total size %u ", envno, envsz);
  772. top = (top - sizeof (char **) * envno) & ~0xF;
  773. fwenv = (char **)top;
  774. debug ("## fwenv at 0x%08lX ", top);
  775. top = (top - envsz) & ~0xF;
  776. s = (char *)top;
  777. ss = fwenv;
  778. /* now copy them */
  779. for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
  780. for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
  781. ;
  782. *ss++ = s;
  783. for (j = i; j < nxt; ++j)
  784. *s++ = env_get_char (j);
  785. *s++ = '\0';
  786. }
  787. *ss++ = NULL; /* terminate */
  788. entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
  789. (*entry) (kbd, cmdline, fwenv, top);
  790. }
  791. #endif