cmd_bootm.c 29 KB

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