cmd_bootm.c 28 KB

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