cmd_bootm.c 29 KB

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