cmd_bootm.c 29 KB

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