cmd_bootm.c 28 KB

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