cmd_bootm.c 24 KB

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