cmd_bootm.c 29 KB

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