cmd_bootm.c 24 KB

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