cmd_bootm.c 28 KB

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