cmd_bootm.c 29 KB

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