cmd_bootm.c 23 KB

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