cmd_bootm.c 27 KB

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