cmd_bootm.c 29 KB

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