cmd_bootm.c 22 KB

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