cmd_bootm.c 24 KB

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