cmd_bootm.c 27 KB

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