cmd_bootm.c 27 KB

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