cmd_bootm.c 29 KB

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