cmd_bootm.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520
  1. /*
  2. * (C) Copyright 2000-2009
  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 <u-boot/zlib.h>
  32. #include <bzlib.h>
  33. #include <environment.h>
  34. #include <lmb.h>
  35. #include <linux/ctype.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/compiler.h>
  38. #if defined(CONFIG_CMD_USB)
  39. #include <usb.h>
  40. #endif
  41. #ifdef CONFIG_SYS_HUSH_PARSER
  42. #include <hush.h>
  43. #endif
  44. #if defined(CONFIG_OF_LIBFDT)
  45. #include <fdt.h>
  46. #include <libfdt.h>
  47. #include <fdt_support.h>
  48. #endif
  49. #ifdef CONFIG_LZMA
  50. #include <lzma/LzmaTypes.h>
  51. #include <lzma/LzmaDec.h>
  52. #include <lzma/LzmaTools.h>
  53. #endif /* CONFIG_LZMA */
  54. #ifdef CONFIG_LZO
  55. #include <linux/lzo.h>
  56. #endif /* CONFIG_LZO */
  57. DECLARE_GLOBAL_DATA_PTR;
  58. #ifndef CONFIG_SYS_BOOTM_LEN
  59. #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
  60. #endif
  61. #ifdef CONFIG_BZIP2
  62. extern void bz_internal_error(int);
  63. #endif
  64. #if defined(CONFIG_CMD_IMI)
  65. static int image_info(unsigned long addr);
  66. #endif
  67. #if defined(CONFIG_CMD_IMLS)
  68. #include <flash.h>
  69. #include <mtd/cfi_flash.h>
  70. extern flash_info_t flash_info[]; /* info for FLASH chips */
  71. static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  72. #endif
  73. #ifdef CONFIG_SILENT_CONSOLE
  74. static void fixup_silent_linux(void);
  75. #endif
  76. static image_header_t *image_get_kernel(ulong img_addr, int verify);
  77. #if defined(CONFIG_FIT)
  78. static int fit_check_kernel(const void *fit, int os_noffset, int verify);
  79. #endif
  80. static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
  81. char * const argv[], bootm_headers_t *images,
  82. ulong *os_data, ulong *os_len);
  83. /*
  84. * Continue booting an OS image; caller already has:
  85. * - copied image header to global variable `header'
  86. * - checked header magic number, checksums (both header & image),
  87. * - verified image architecture (PPC) and type (KERNEL or MULTI),
  88. * - loaded (first part of) image to header load address,
  89. * - disabled interrupts.
  90. */
  91. typedef int boot_os_fn(int flag, int argc, char * const argv[],
  92. bootm_headers_t *images); /* pointers to os/initrd/fdt */
  93. #ifdef CONFIG_BOOTM_LINUX
  94. extern boot_os_fn do_bootm_linux;
  95. #endif
  96. #ifdef CONFIG_BOOTM_NETBSD
  97. static boot_os_fn do_bootm_netbsd;
  98. #endif
  99. #if defined(CONFIG_LYNXKDI)
  100. static boot_os_fn do_bootm_lynxkdi;
  101. extern void lynxkdi_boot(image_header_t *);
  102. #endif
  103. #ifdef CONFIG_BOOTM_RTEMS
  104. static boot_os_fn do_bootm_rtems;
  105. #endif
  106. #if defined(CONFIG_BOOTM_OSE)
  107. static boot_os_fn do_bootm_ose;
  108. #endif
  109. #if defined(CONFIG_CMD_ELF)
  110. static boot_os_fn do_bootm_vxworks;
  111. static boot_os_fn do_bootm_qnxelf;
  112. int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  113. int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  114. #endif
  115. #if defined(CONFIG_INTEGRITY)
  116. static boot_os_fn do_bootm_integrity;
  117. #endif
  118. static boot_os_fn *boot_os[] = {
  119. #ifdef CONFIG_BOOTM_LINUX
  120. [IH_OS_LINUX] = do_bootm_linux,
  121. #endif
  122. #ifdef CONFIG_BOOTM_NETBSD
  123. [IH_OS_NETBSD] = do_bootm_netbsd,
  124. #endif
  125. #ifdef CONFIG_LYNXKDI
  126. [IH_OS_LYNXOS] = do_bootm_lynxkdi,
  127. #endif
  128. #ifdef CONFIG_BOOTM_RTEMS
  129. [IH_OS_RTEMS] = do_bootm_rtems,
  130. #endif
  131. #if defined(CONFIG_BOOTM_OSE)
  132. [IH_OS_OSE] = do_bootm_ose,
  133. #endif
  134. #if defined(CONFIG_CMD_ELF)
  135. [IH_OS_VXWORKS] = do_bootm_vxworks,
  136. [IH_OS_QNX] = do_bootm_qnxelf,
  137. #endif
  138. #ifdef CONFIG_INTEGRITY
  139. [IH_OS_INTEGRITY] = do_bootm_integrity,
  140. #endif
  141. };
  142. bootm_headers_t images; /* pointers to os/initrd/fdt images */
  143. /* Allow for arch specific config before we boot */
  144. void __arch_preboot_os(void)
  145. {
  146. /* please define platform specific arch_preboot_os() */
  147. }
  148. void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
  149. #define IH_INITRD_ARCH IH_ARCH_DEFAULT
  150. static void bootm_start_lmb(void)
  151. {
  152. #ifdef CONFIG_LMB
  153. ulong mem_start;
  154. phys_size_t mem_size;
  155. lmb_init(&images.lmb);
  156. mem_start = getenv_bootm_low();
  157. mem_size = getenv_bootm_size();
  158. lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
  159. arch_lmb_reserve(&images.lmb);
  160. board_lmb_reserve(&images.lmb);
  161. #else
  162. # define lmb_reserve(lmb, base, size)
  163. #endif
  164. }
  165. static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  166. {
  167. void *os_hdr;
  168. int ret;
  169. memset((void *)&images, 0, sizeof(images));
  170. images.verify = getenv_yesno("verify");
  171. bootm_start_lmb();
  172. bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start");
  173. /* get kernel image header, start address and length */
  174. os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
  175. &images, &images.os.image_start, &images.os.image_len);
  176. if (images.os.image_len == 0) {
  177. puts("ERROR: can't get kernel image!\n");
  178. return 1;
  179. }
  180. /* get image parameters */
  181. switch (genimg_get_format(os_hdr)) {
  182. case IMAGE_FORMAT_LEGACY:
  183. images.os.type = image_get_type(os_hdr);
  184. images.os.comp = image_get_comp(os_hdr);
  185. images.os.os = image_get_os(os_hdr);
  186. images.os.end = image_get_image_end(os_hdr);
  187. images.os.load = image_get_load(os_hdr);
  188. break;
  189. #if defined(CONFIG_FIT)
  190. case IMAGE_FORMAT_FIT:
  191. if (fit_image_get_type(images.fit_hdr_os,
  192. images.fit_noffset_os, &images.os.type)) {
  193. puts("Can't get image type!\n");
  194. bootstage_error(BOOTSTAGE_ID_FIT_TYPE);
  195. return 1;
  196. }
  197. if (fit_image_get_comp(images.fit_hdr_os,
  198. images.fit_noffset_os, &images.os.comp)) {
  199. puts("Can't get image compression!\n");
  200. bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION);
  201. return 1;
  202. }
  203. if (fit_image_get_os(images.fit_hdr_os,
  204. images.fit_noffset_os, &images.os.os)) {
  205. puts("Can't get image OS!\n");
  206. bootstage_error(BOOTSTAGE_ID_FIT_OS);
  207. return 1;
  208. }
  209. images.os.end = fit_get_end(images.fit_hdr_os);
  210. if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
  211. &images.os.load)) {
  212. puts("Can't get image load address!\n");
  213. bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR);
  214. return 1;
  215. }
  216. break;
  217. #endif
  218. default:
  219. puts("ERROR: unknown image format type!\n");
  220. return 1;
  221. }
  222. /* find kernel entry point */
  223. if (images.legacy_hdr_valid) {
  224. images.ep = image_get_ep(&images.legacy_hdr_os_copy);
  225. #if defined(CONFIG_FIT)
  226. } else if (images.fit_uname_os) {
  227. ret = fit_image_get_entry(images.fit_hdr_os,
  228. images.fit_noffset_os, &images.ep);
  229. if (ret) {
  230. puts("Can't get entry point property!\n");
  231. return 1;
  232. }
  233. #endif
  234. } else {
  235. puts("Could not find kernel entry point!\n");
  236. return 1;
  237. }
  238. if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
  239. images.os.load = images.os.image_start;
  240. images.ep += images.os.load;
  241. }
  242. if (((images.os.type == IH_TYPE_KERNEL) ||
  243. (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
  244. (images.os.type == IH_TYPE_MULTI)) &&
  245. (images.os.os == IH_OS_LINUX)) {
  246. /* find ramdisk */
  247. ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
  248. &images.rd_start, &images.rd_end);
  249. if (ret) {
  250. puts("Ramdisk image is corrupt or invalid\n");
  251. return 1;
  252. }
  253. #if defined(CONFIG_OF_LIBFDT)
  254. /* find flattened device tree */
  255. ret = boot_get_fdt(flag, argc, argv, &images,
  256. &images.ft_addr, &images.ft_len);
  257. if (ret) {
  258. puts("Could not find a valid device tree\n");
  259. return 1;
  260. }
  261. set_working_fdt_addr(images.ft_addr);
  262. #endif
  263. }
  264. images.os.start = (ulong)os_hdr;
  265. images.state = BOOTM_STATE_START;
  266. return 0;
  267. }
  268. #define BOOTM_ERR_RESET -1
  269. #define BOOTM_ERR_OVERLAP -2
  270. #define BOOTM_ERR_UNIMPLEMENTED -3
  271. static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
  272. {
  273. uint8_t comp = os.comp;
  274. ulong load = os.load;
  275. ulong blob_start = os.start;
  276. ulong blob_end = os.end;
  277. ulong image_start = os.image_start;
  278. ulong image_len = os.image_len;
  279. __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
  280. int no_overlap = 0;
  281. #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
  282. int ret;
  283. #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
  284. const char *type_name = genimg_get_type_name(os.type);
  285. switch (comp) {
  286. case IH_COMP_NONE:
  287. if (load == blob_start || load == image_start) {
  288. printf(" XIP %s ... ", type_name);
  289. no_overlap = 1;
  290. } else {
  291. printf(" Loading %s ... ", type_name);
  292. memmove_wd((void *)load, (void *)image_start,
  293. image_len, CHUNKSZ);
  294. }
  295. *load_end = load + image_len;
  296. puts("OK\n");
  297. break;
  298. #ifdef CONFIG_GZIP
  299. case IH_COMP_GZIP:
  300. printf(" Uncompressing %s ... ", type_name);
  301. if (gunzip((void *)load, unc_len,
  302. (uchar *)image_start, &image_len) != 0) {
  303. puts("GUNZIP: uncompress, out-of-mem or overwrite "
  304. "error - must RESET board to recover\n");
  305. if (boot_progress)
  306. bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
  307. return BOOTM_ERR_RESET;
  308. }
  309. *load_end = load + image_len;
  310. break;
  311. #endif /* CONFIG_GZIP */
  312. #ifdef CONFIG_BZIP2
  313. case IH_COMP_BZIP2:
  314. printf(" Uncompressing %s ... ", type_name);
  315. /*
  316. * If we've got less than 4 MB of malloc() space,
  317. * use slower decompression algorithm which requires
  318. * at most 2300 KB of memory.
  319. */
  320. int i = BZ2_bzBuffToBuffDecompress((char *)load,
  321. &unc_len, (char *)image_start, image_len,
  322. CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
  323. if (i != BZ_OK) {
  324. printf("BUNZIP2: uncompress or overwrite error %d "
  325. "- must RESET board to recover\n", i);
  326. if (boot_progress)
  327. bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
  328. return BOOTM_ERR_RESET;
  329. }
  330. *load_end = load + unc_len;
  331. break;
  332. #endif /* CONFIG_BZIP2 */
  333. #ifdef CONFIG_LZMA
  334. case IH_COMP_LZMA: {
  335. SizeT lzma_len = unc_len;
  336. printf(" Uncompressing %s ... ", type_name);
  337. ret = lzmaBuffToBuffDecompress(
  338. (unsigned char *)load, &lzma_len,
  339. (unsigned char *)image_start, image_len);
  340. unc_len = lzma_len;
  341. if (ret != SZ_OK) {
  342. printf("LZMA: uncompress or overwrite error %d "
  343. "- must RESET board to recover\n", ret);
  344. bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
  345. return BOOTM_ERR_RESET;
  346. }
  347. *load_end = load + unc_len;
  348. break;
  349. }
  350. #endif /* CONFIG_LZMA */
  351. #ifdef CONFIG_LZO
  352. case IH_COMP_LZO:
  353. printf(" Uncompressing %s ... ", type_name);
  354. ret = lzop_decompress((const unsigned char *)image_start,
  355. image_len, (unsigned char *)load,
  356. &unc_len);
  357. if (ret != LZO_E_OK) {
  358. printf("LZO: uncompress or overwrite error %d "
  359. "- must RESET board to recover\n", ret);
  360. if (boot_progress)
  361. bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
  362. return BOOTM_ERR_RESET;
  363. }
  364. *load_end = load + unc_len;
  365. break;
  366. #endif /* CONFIG_LZO */
  367. default:
  368. printf("Unimplemented compression type %d\n", comp);
  369. return BOOTM_ERR_UNIMPLEMENTED;
  370. }
  371. flush_cache(load, (*load_end - load) * sizeof(ulong));
  372. puts("OK\n");
  373. debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
  374. bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
  375. if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
  376. debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
  377. blob_start, blob_end);
  378. debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
  379. *load_end);
  380. return BOOTM_ERR_OVERLAP;
  381. }
  382. return 0;
  383. }
  384. static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
  385. {
  386. char *s;
  387. int (*appl)(int, char * const []);
  388. /* Don't start if "autostart" is set to "no" */
  389. if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
  390. char buf[32];
  391. sprintf(buf, "%lX", images.os.image_len);
  392. setenv("filesize", buf);
  393. return 0;
  394. }
  395. appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
  396. (*appl)(argc-1, &argv[1]);
  397. return 0;
  398. }
  399. /* we overload the cmd field with our state machine info instead of a
  400. * function pointer */
  401. static cmd_tbl_t cmd_bootm_sub[] = {
  402. U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
  403. U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
  404. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  405. U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
  406. #endif
  407. #ifdef CONFIG_OF_LIBFDT
  408. U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
  409. #endif
  410. U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
  411. U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
  412. U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
  413. U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
  414. };
  415. int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
  416. char * const argv[])
  417. {
  418. int ret = 0;
  419. long state;
  420. cmd_tbl_t *c;
  421. boot_os_fn *boot_fn;
  422. c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
  423. if (c) {
  424. state = (long)c->cmd;
  425. /* treat start special since it resets the state machine */
  426. if (state == BOOTM_STATE_START) {
  427. argc--;
  428. argv++;
  429. return bootm_start(cmdtp, flag, argc, argv);
  430. }
  431. } else {
  432. /* Unrecognized command */
  433. return CMD_RET_USAGE;
  434. }
  435. if (images.state >= state) {
  436. printf("Trying to execute a command out of order\n");
  437. return CMD_RET_USAGE;
  438. }
  439. images.state |= state;
  440. boot_fn = boot_os[images.os.os];
  441. switch (state) {
  442. ulong load_end;
  443. case BOOTM_STATE_START:
  444. /* should never occur */
  445. break;
  446. case BOOTM_STATE_LOADOS:
  447. ret = bootm_load_os(images.os, &load_end, 0);
  448. if (ret)
  449. return ret;
  450. lmb_reserve(&images.lmb, images.os.load,
  451. (load_end - images.os.load));
  452. break;
  453. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  454. case BOOTM_STATE_RAMDISK:
  455. {
  456. ulong rd_len = images.rd_end - images.rd_start;
  457. char str[17];
  458. ret = boot_ramdisk_high(&images.lmb, images.rd_start,
  459. rd_len, &images.initrd_start, &images.initrd_end);
  460. if (ret)
  461. return ret;
  462. sprintf(str, "%lx", images.initrd_start);
  463. setenv("initrd_start", str);
  464. sprintf(str, "%lx", images.initrd_end);
  465. setenv("initrd_end", str);
  466. }
  467. break;
  468. #endif
  469. #if defined(CONFIG_OF_LIBFDT)
  470. case BOOTM_STATE_FDT:
  471. {
  472. boot_fdt_add_mem_rsv_regions(&images.lmb,
  473. images.ft_addr);
  474. ret = boot_relocate_fdt(&images.lmb,
  475. &images.ft_addr, &images.ft_len);
  476. break;
  477. }
  478. #endif
  479. case BOOTM_STATE_OS_CMDLINE:
  480. ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
  481. if (ret)
  482. printf("cmdline subcommand not supported\n");
  483. break;
  484. case BOOTM_STATE_OS_BD_T:
  485. ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
  486. if (ret)
  487. printf("bdt subcommand not supported\n");
  488. break;
  489. case BOOTM_STATE_OS_PREP:
  490. ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
  491. if (ret)
  492. printf("prep subcommand not supported\n");
  493. break;
  494. case BOOTM_STATE_OS_GO:
  495. disable_interrupts();
  496. arch_preboot_os();
  497. boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
  498. break;
  499. }
  500. return ret;
  501. }
  502. /*******************************************************************/
  503. /* bootm - boot application image from image in memory */
  504. /*******************************************************************/
  505. int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  506. {
  507. ulong iflag;
  508. ulong load_end = 0;
  509. int ret;
  510. boot_os_fn *boot_fn;
  511. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  512. static int relocated = 0;
  513. /* relocate boot function table */
  514. if (!relocated) {
  515. int i;
  516. for (i = 0; i < ARRAY_SIZE(boot_os); i++)
  517. if (boot_os[i] != NULL)
  518. boot_os[i] += gd->reloc_off;
  519. relocated = 1;
  520. }
  521. #endif
  522. /* determine if we have a sub command */
  523. if (argc > 1) {
  524. char *endp;
  525. simple_strtoul(argv[1], &endp, 16);
  526. /* endp pointing to NULL means that argv[1] was just a
  527. * valid number, pass it along to the normal bootm processing
  528. *
  529. * If endp is ':' or '#' assume a FIT identifier so pass
  530. * along for normal processing.
  531. *
  532. * Right now we assume the first arg should never be '-'
  533. */
  534. if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
  535. return do_bootm_subcommand(cmdtp, flag, argc, argv);
  536. }
  537. if (bootm_start(cmdtp, flag, argc, argv))
  538. return 1;
  539. /*
  540. * We have reached the point of no return: we are going to
  541. * overwrite all exception vector code, so we cannot easily
  542. * recover from any failures any more...
  543. */
  544. iflag = disable_interrupts();
  545. #if defined(CONFIG_CMD_USB)
  546. /*
  547. * turn off USB to prevent the host controller from writing to the
  548. * SDRAM while Linux is booting. This could happen (at least for OHCI
  549. * controller), because the HCCA (Host Controller Communication Area)
  550. * lies within the SDRAM and the host controller writes continously to
  551. * this area (as busmaster!). The HccaFrameNumber is for example
  552. * updated every 1 ms within the HCCA structure in SDRAM! For more
  553. * details see the OpenHCI specification.
  554. */
  555. usb_stop();
  556. #endif
  557. ret = bootm_load_os(images.os, &load_end, 1);
  558. if (ret < 0) {
  559. if (ret == BOOTM_ERR_RESET)
  560. do_reset(cmdtp, flag, argc, argv);
  561. if (ret == BOOTM_ERR_OVERLAP) {
  562. if (images.legacy_hdr_valid) {
  563. image_header_t *hdr;
  564. hdr = &images.legacy_hdr_os_copy;
  565. if (image_get_type(hdr) == IH_TYPE_MULTI)
  566. puts("WARNING: legacy format multi "
  567. "component image "
  568. "overwritten\n");
  569. } else {
  570. puts("ERROR: new format image overwritten - "
  571. "must RESET the board to recover\n");
  572. bootstage_error(BOOTSTAGE_ID_OVERWRITTEN);
  573. do_reset(cmdtp, flag, argc, argv);
  574. }
  575. }
  576. if (ret == BOOTM_ERR_UNIMPLEMENTED) {
  577. if (iflag)
  578. enable_interrupts();
  579. bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
  580. return 1;
  581. }
  582. }
  583. lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
  584. if (images.os.type == IH_TYPE_STANDALONE) {
  585. if (iflag)
  586. enable_interrupts();
  587. /* This may return when 'autostart' is 'no' */
  588. bootm_start_standalone(iflag, argc, argv);
  589. return 0;
  590. }
  591. bootstage_mark(BOOTSTAGE_ID_CHECK_BOOT_OS);
  592. #ifdef CONFIG_SILENT_CONSOLE
  593. if (images.os.os == IH_OS_LINUX)
  594. fixup_silent_linux();
  595. #endif
  596. boot_fn = boot_os[images.os.os];
  597. if (boot_fn == NULL) {
  598. if (iflag)
  599. enable_interrupts();
  600. printf("ERROR: booting os '%s' (%d) is not supported\n",
  601. genimg_get_os_name(images.os.os), images.os.os);
  602. bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS);
  603. return 1;
  604. }
  605. arch_preboot_os();
  606. boot_fn(0, argc, argv, &images);
  607. bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
  608. #ifdef DEBUG
  609. puts("\n## Control returned to monitor - resetting...\n");
  610. #endif
  611. do_reset(cmdtp, flag, argc, argv);
  612. return 1;
  613. }
  614. int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
  615. {
  616. const char *ep = getenv("autostart");
  617. if (ep && !strcmp(ep, "yes")) {
  618. char *local_args[2];
  619. local_args[0] = (char *)cmd;
  620. local_args[1] = NULL;
  621. printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
  622. return do_bootm(cmdtp, 0, 1, local_args);
  623. }
  624. return 0;
  625. }
  626. /**
  627. * image_get_kernel - verify legacy format kernel image
  628. * @img_addr: in RAM address of the legacy format image to be verified
  629. * @verify: data CRC verification flag
  630. *
  631. * image_get_kernel() verifies legacy image integrity and returns pointer to
  632. * legacy image header if image verification was completed successfully.
  633. *
  634. * returns:
  635. * pointer to a legacy image header if valid image was found
  636. * otherwise return NULL
  637. */
  638. static image_header_t *image_get_kernel(ulong img_addr, int verify)
  639. {
  640. image_header_t *hdr = (image_header_t *)img_addr;
  641. if (!image_check_magic(hdr)) {
  642. puts("Bad Magic Number\n");
  643. bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC);
  644. return NULL;
  645. }
  646. bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER);
  647. if (!image_check_hcrc(hdr)) {
  648. puts("Bad Header Checksum\n");
  649. bootstage_error(BOOTSTAGE_ID_CHECK_HEADER);
  650. return NULL;
  651. }
  652. bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM);
  653. image_print_contents(hdr);
  654. if (verify) {
  655. puts(" Verifying Checksum ... ");
  656. if (!image_check_dcrc(hdr)) {
  657. printf("Bad Data CRC\n");
  658. bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM);
  659. return NULL;
  660. }
  661. puts("OK\n");
  662. }
  663. bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH);
  664. if (!image_check_target_arch(hdr)) {
  665. printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
  666. bootstage_error(BOOTSTAGE_ID_CHECK_ARCH);
  667. return NULL;
  668. }
  669. return hdr;
  670. }
  671. /**
  672. * fit_check_kernel - verify FIT format kernel subimage
  673. * @fit_hdr: pointer to the FIT image header
  674. * os_noffset: kernel subimage node offset within FIT image
  675. * @verify: data CRC verification flag
  676. *
  677. * fit_check_kernel() verifies integrity of the kernel subimage and from
  678. * specified FIT image.
  679. *
  680. * returns:
  681. * 1, on success
  682. * 0, on failure
  683. */
  684. #if defined(CONFIG_FIT)
  685. static int fit_check_kernel(const void *fit, int os_noffset, int verify)
  686. {
  687. fit_image_print(fit, os_noffset, " ");
  688. if (verify) {
  689. puts(" Verifying Hash Integrity ... ");
  690. if (!fit_image_check_hashes(fit, os_noffset)) {
  691. puts("Bad Data Hash\n");
  692. bootstage_error(BOOTSTAGE_ID_FIT_CHECK_HASH);
  693. return 0;
  694. }
  695. puts("OK\n");
  696. }
  697. bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_ARCH);
  698. if (!fit_image_check_target_arch(fit, os_noffset)) {
  699. puts("Unsupported Architecture\n");
  700. bootstage_error(BOOTSTAGE_ID_FIT_CHECK_ARCH);
  701. return 0;
  702. }
  703. bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
  704. if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL) &&
  705. !fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL_NOLOAD)) {
  706. puts("Not a kernel image\n");
  707. bootstage_error(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
  708. return 0;
  709. }
  710. bootstage_mark(BOOTSTAGE_ID_FIT_CHECKED);
  711. return 1;
  712. }
  713. #endif /* CONFIG_FIT */
  714. /**
  715. * boot_get_kernel - find kernel image
  716. * @os_data: pointer to a ulong variable, will hold os data start address
  717. * @os_len: pointer to a ulong variable, will hold os data length
  718. *
  719. * boot_get_kernel() tries to find a kernel image, verifies its integrity
  720. * and locates kernel data.
  721. *
  722. * returns:
  723. * pointer to image header if valid image was found, plus kernel start
  724. * address and length, otherwise NULL
  725. */
  726. static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
  727. char * const argv[], bootm_headers_t *images, ulong *os_data,
  728. ulong *os_len)
  729. {
  730. image_header_t *hdr;
  731. ulong img_addr;
  732. #if defined(CONFIG_FIT)
  733. void *fit_hdr;
  734. const char *fit_uname_config = NULL;
  735. const char *fit_uname_kernel = NULL;
  736. const void *data;
  737. size_t len;
  738. int cfg_noffset;
  739. int os_noffset;
  740. #endif
  741. /* find out kernel image address */
  742. if (argc < 2) {
  743. img_addr = load_addr;
  744. debug("* kernel: default image load address = 0x%08lx\n",
  745. load_addr);
  746. #if defined(CONFIG_FIT)
  747. } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
  748. &fit_uname_config)) {
  749. debug("* kernel: config '%s' from image at 0x%08lx\n",
  750. fit_uname_config, img_addr);
  751. } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
  752. &fit_uname_kernel)) {
  753. debug("* kernel: subimage '%s' from image at 0x%08lx\n",
  754. fit_uname_kernel, img_addr);
  755. #endif
  756. } else {
  757. img_addr = simple_strtoul(argv[1], NULL, 16);
  758. debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
  759. }
  760. bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
  761. /* copy from dataflash if needed */
  762. img_addr = genimg_get_image(img_addr);
  763. /* check image type, for FIT images get FIT kernel node */
  764. *os_data = *os_len = 0;
  765. switch (genimg_get_format((void *)img_addr)) {
  766. case IMAGE_FORMAT_LEGACY:
  767. printf("## Booting kernel from Legacy Image at %08lx ...\n",
  768. img_addr);
  769. hdr = image_get_kernel(img_addr, images->verify);
  770. if (!hdr)
  771. return NULL;
  772. bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
  773. /* get os_data and os_len */
  774. switch (image_get_type(hdr)) {
  775. case IH_TYPE_KERNEL:
  776. case IH_TYPE_KERNEL_NOLOAD:
  777. *os_data = image_get_data(hdr);
  778. *os_len = image_get_data_size(hdr);
  779. break;
  780. case IH_TYPE_MULTI:
  781. image_multi_getimg(hdr, 0, os_data, os_len);
  782. break;
  783. case IH_TYPE_STANDALONE:
  784. *os_data = image_get_data(hdr);
  785. *os_len = image_get_data_size(hdr);
  786. break;
  787. default:
  788. printf("Wrong Image Type for %s command\n",
  789. cmdtp->name);
  790. bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
  791. return NULL;
  792. }
  793. /*
  794. * copy image header to allow for image overwrites during
  795. * kernel decompression.
  796. */
  797. memmove(&images->legacy_hdr_os_copy, hdr,
  798. sizeof(image_header_t));
  799. /* save pointer to image header */
  800. images->legacy_hdr_os = hdr;
  801. images->legacy_hdr_valid = 1;
  802. bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
  803. break;
  804. #if defined(CONFIG_FIT)
  805. case IMAGE_FORMAT_FIT:
  806. fit_hdr = (void *)img_addr;
  807. printf("## Booting kernel from FIT Image at %08lx ...\n",
  808. img_addr);
  809. if (!fit_check_format(fit_hdr)) {
  810. puts("Bad FIT kernel image format!\n");
  811. bootstage_error(BOOTSTAGE_ID_FIT_FORMAT);
  812. return NULL;
  813. }
  814. bootstage_mark(BOOTSTAGE_ID_FIT_FORMAT);
  815. if (!fit_uname_kernel) {
  816. /*
  817. * no kernel image node unit name, try to get config
  818. * node first. If config unit node name is NULL
  819. * fit_conf_get_node() will try to find default config
  820. * node
  821. */
  822. bootstage_mark(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
  823. cfg_noffset = fit_conf_get_node(fit_hdr,
  824. fit_uname_config);
  825. if (cfg_noffset < 0) {
  826. bootstage_error(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
  827. return NULL;
  828. }
  829. /* save configuration uname provided in the first
  830. * bootm argument
  831. */
  832. images->fit_uname_cfg = fdt_get_name(fit_hdr,
  833. cfg_noffset,
  834. NULL);
  835. printf(" Using '%s' configuration\n",
  836. images->fit_uname_cfg);
  837. bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
  838. os_noffset = fit_conf_get_kernel_node(fit_hdr,
  839. cfg_noffset);
  840. fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
  841. NULL);
  842. } else {
  843. /* get kernel component image node offset */
  844. bootstage_mark(BOOTSTAGE_ID_FIT_UNIT_NAME);
  845. os_noffset = fit_image_get_node(fit_hdr,
  846. fit_uname_kernel);
  847. }
  848. if (os_noffset < 0) {
  849. bootstage_error(BOOTSTAGE_ID_FIT_CONFIG);
  850. return NULL;
  851. }
  852. printf(" Trying '%s' kernel subimage\n", fit_uname_kernel);
  853. bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE);
  854. if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
  855. return NULL;
  856. /* get kernel image data address and length */
  857. if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
  858. puts("Could not find kernel subimage data!\n");
  859. bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR);
  860. return NULL;
  861. }
  862. bootstage_mark(BOOTSTAGE_ID_FIT_KERNEL_INFO);
  863. *os_len = len;
  864. *os_data = (ulong)data;
  865. images->fit_hdr_os = fit_hdr;
  866. images->fit_uname_os = fit_uname_kernel;
  867. images->fit_noffset_os = os_noffset;
  868. break;
  869. #endif
  870. default:
  871. printf("Wrong Image Format for %s command\n", cmdtp->name);
  872. bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO);
  873. return NULL;
  874. }
  875. debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
  876. *os_data, *os_len, *os_len);
  877. return (void *)img_addr;
  878. }
  879. U_BOOT_CMD(
  880. bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
  881. "boot application image from memory",
  882. "[addr [arg ...]]\n - boot application image stored in memory\n"
  883. "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
  884. "\t'arg' can be the address of an initrd image\n"
  885. #if defined(CONFIG_OF_LIBFDT)
  886. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  887. "\ta third argument is required which is the address of the\n"
  888. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  889. "\tuse a '-' for the second argument. If you do not pass a third\n"
  890. "\ta bd_info struct will be passed instead\n"
  891. #endif
  892. #if defined(CONFIG_FIT)
  893. "\t\nFor the new multi component uImage format (FIT) addresses\n"
  894. "\tmust be extened to include component or configuration unit name:\n"
  895. "\taddr:<subimg_uname> - direct component image specification\n"
  896. "\taddr#<conf_uname> - configuration specification\n"
  897. "\tUse iminfo command to get the list of existing component\n"
  898. "\timages and configurations.\n"
  899. #endif
  900. "\nSub-commands to do part of the bootm sequence. The sub-commands "
  901. "must be\n"
  902. "issued in the order below (it's ok to not issue all sub-commands):\n"
  903. "\tstart [addr [arg ...]]\n"
  904. "\tloados - load OS image\n"
  905. #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
  906. "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
  907. #endif
  908. #if defined(CONFIG_OF_LIBFDT)
  909. "\tfdt - relocate flat device tree\n"
  910. #endif
  911. "\tcmdline - OS specific command line processing/setup\n"
  912. "\tbdt - OS specific bd_t processing\n"
  913. "\tprep - OS specific prep before relocation or go\n"
  914. "\tgo - start OS"
  915. );
  916. /*******************************************************************/
  917. /* bootd - boot default image */
  918. /*******************************************************************/
  919. #if defined(CONFIG_CMD_BOOTD)
  920. int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  921. {
  922. int rcode = 0;
  923. if (run_command(getenv("bootcmd"), flag) < 0)
  924. rcode = 1;
  925. return rcode;
  926. }
  927. U_BOOT_CMD(
  928. boot, 1, 1, do_bootd,
  929. "boot default, i.e., run 'bootcmd'",
  930. ""
  931. );
  932. /* keep old command name "bootd" for backward compatibility */
  933. U_BOOT_CMD(
  934. bootd, 1, 1, do_bootd,
  935. "boot default, i.e., run 'bootcmd'",
  936. ""
  937. );
  938. #endif
  939. /*******************************************************************/
  940. /* iminfo - print header info for a requested image */
  941. /*******************************************************************/
  942. #if defined(CONFIG_CMD_IMI)
  943. int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  944. {
  945. int arg;
  946. ulong addr;
  947. int rcode = 0;
  948. if (argc < 2) {
  949. return image_info(load_addr);
  950. }
  951. for (arg = 1; arg < argc; ++arg) {
  952. addr = simple_strtoul(argv[arg], NULL, 16);
  953. if (image_info(addr) != 0)
  954. rcode = 1;
  955. }
  956. return rcode;
  957. }
  958. static int image_info(ulong addr)
  959. {
  960. void *hdr = (void *)addr;
  961. printf("\n## Checking Image at %08lx ...\n", addr);
  962. switch (genimg_get_format(hdr)) {
  963. case IMAGE_FORMAT_LEGACY:
  964. puts(" Legacy image found\n");
  965. if (!image_check_magic(hdr)) {
  966. puts(" Bad Magic Number\n");
  967. return 1;
  968. }
  969. if (!image_check_hcrc(hdr)) {
  970. puts(" Bad Header Checksum\n");
  971. return 1;
  972. }
  973. image_print_contents(hdr);
  974. puts(" Verifying Checksum ... ");
  975. if (!image_check_dcrc(hdr)) {
  976. puts(" Bad Data CRC\n");
  977. return 1;
  978. }
  979. puts("OK\n");
  980. return 0;
  981. #if defined(CONFIG_FIT)
  982. case IMAGE_FORMAT_FIT:
  983. puts(" FIT image found\n");
  984. if (!fit_check_format(hdr)) {
  985. puts("Bad FIT image format!\n");
  986. return 1;
  987. }
  988. fit_print_contents(hdr);
  989. if (!fit_all_image_check_hashes(hdr)) {
  990. puts("Bad hash in FIT image!\n");
  991. return 1;
  992. }
  993. return 0;
  994. #endif
  995. default:
  996. puts("Unknown image format!\n");
  997. break;
  998. }
  999. return 1;
  1000. }
  1001. U_BOOT_CMD(
  1002. iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
  1003. "print header information for application image",
  1004. "addr [addr ...]\n"
  1005. " - print header information for application image starting at\n"
  1006. " address 'addr' in memory; this includes verification of the\n"
  1007. " image contents (magic number, header and payload checksums)"
  1008. );
  1009. #endif
  1010. /*******************************************************************/
  1011. /* imls - list all images found in flash */
  1012. /*******************************************************************/
  1013. #if defined(CONFIG_CMD_IMLS)
  1014. int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1015. {
  1016. flash_info_t *info;
  1017. int i, j;
  1018. void *hdr;
  1019. for (i = 0, info = &flash_info[0];
  1020. i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
  1021. if (info->flash_id == FLASH_UNKNOWN)
  1022. goto next_bank;
  1023. for (j = 0; j < info->sector_count; ++j) {
  1024. hdr = (void *)info->start[j];
  1025. if (!hdr)
  1026. goto next_sector;
  1027. switch (genimg_get_format(hdr)) {
  1028. case IMAGE_FORMAT_LEGACY:
  1029. if (!image_check_hcrc(hdr))
  1030. goto next_sector;
  1031. printf("Legacy Image at %08lX:\n", (ulong)hdr);
  1032. image_print_contents(hdr);
  1033. puts(" Verifying Checksum ... ");
  1034. if (!image_check_dcrc(hdr)) {
  1035. puts("Bad Data CRC\n");
  1036. } else {
  1037. puts("OK\n");
  1038. }
  1039. break;
  1040. #if defined(CONFIG_FIT)
  1041. case IMAGE_FORMAT_FIT:
  1042. if (!fit_check_format(hdr))
  1043. goto next_sector;
  1044. printf("FIT Image at %08lX:\n", (ulong)hdr);
  1045. fit_print_contents(hdr);
  1046. break;
  1047. #endif
  1048. default:
  1049. goto next_sector;
  1050. }
  1051. next_sector: ;
  1052. }
  1053. next_bank: ;
  1054. }
  1055. return (0);
  1056. }
  1057. U_BOOT_CMD(
  1058. imls, 1, 1, do_imls,
  1059. "list all images found in flash",
  1060. "\n"
  1061. " - Prints information about all images found at sector\n"
  1062. " boundaries in flash."
  1063. );
  1064. #endif
  1065. /*******************************************************************/
  1066. /* helper routines */
  1067. /*******************************************************************/
  1068. #ifdef CONFIG_SILENT_CONSOLE
  1069. static void fixup_silent_linux(void)
  1070. {
  1071. char buf[256], *start, *end;
  1072. char *cmdline = getenv("bootargs");
  1073. /* Only fix cmdline when requested */
  1074. if (!(gd->flags & GD_FLG_SILENT))
  1075. return;
  1076. debug("before silent fix-up: %s\n", cmdline);
  1077. if (cmdline) {
  1078. start = strstr(cmdline, "console=");
  1079. if (start) {
  1080. end = strchr(start, ' ');
  1081. strncpy(buf, cmdline, (start - cmdline + 8));
  1082. if (end)
  1083. strcpy(buf + (start - cmdline + 8), end);
  1084. else
  1085. buf[start - cmdline + 8] = '\0';
  1086. } else {
  1087. strcpy(buf, cmdline);
  1088. strcat(buf, " console=");
  1089. }
  1090. } else {
  1091. strcpy(buf, "console=");
  1092. }
  1093. setenv("bootargs", buf);
  1094. debug("after silent fix-up: %s\n", buf);
  1095. }
  1096. #endif /* CONFIG_SILENT_CONSOLE */
  1097. /*******************************************************************/
  1098. /* OS booting routines */
  1099. /*******************************************************************/
  1100. #ifdef CONFIG_BOOTM_NETBSD
  1101. static int do_bootm_netbsd(int flag, int argc, char * const argv[],
  1102. bootm_headers_t *images)
  1103. {
  1104. void (*loader)(bd_t *, image_header_t *, char *, char *);
  1105. image_header_t *os_hdr, *hdr;
  1106. ulong kernel_data, kernel_len;
  1107. char *consdev;
  1108. char *cmdline;
  1109. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1110. return 1;
  1111. #if defined(CONFIG_FIT)
  1112. if (!images->legacy_hdr_valid) {
  1113. fit_unsupported_reset("NetBSD");
  1114. return 1;
  1115. }
  1116. #endif
  1117. hdr = images->legacy_hdr_os;
  1118. /*
  1119. * Booting a (NetBSD) kernel image
  1120. *
  1121. * This process is pretty similar to a standalone application:
  1122. * The (first part of an multi-) image must be a stage-2 loader,
  1123. * which in turn is responsible for loading & invoking the actual
  1124. * kernel. The only differences are the parameters being passed:
  1125. * besides the board info strucure, the loader expects a command
  1126. * line, the name of the console device, and (optionally) the
  1127. * address of the original image header.
  1128. */
  1129. os_hdr = NULL;
  1130. if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
  1131. image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
  1132. if (kernel_len)
  1133. os_hdr = hdr;
  1134. }
  1135. consdev = "";
  1136. #if defined(CONFIG_8xx_CONS_SMC1)
  1137. consdev = "smc1";
  1138. #elif defined(CONFIG_8xx_CONS_SMC2)
  1139. consdev = "smc2";
  1140. #elif defined(CONFIG_8xx_CONS_SCC2)
  1141. consdev = "scc2";
  1142. #elif defined(CONFIG_8xx_CONS_SCC3)
  1143. consdev = "scc3";
  1144. #endif
  1145. if (argc > 2) {
  1146. ulong len;
  1147. int i;
  1148. for (i = 2, len = 0; i < argc; i += 1)
  1149. len += strlen(argv[i]) + 1;
  1150. cmdline = malloc(len);
  1151. for (i = 2, len = 0; i < argc; i += 1) {
  1152. if (i > 2)
  1153. cmdline[len++] = ' ';
  1154. strcpy(&cmdline[len], argv[i]);
  1155. len += strlen(argv[i]);
  1156. }
  1157. } else if ((cmdline = getenv("bootargs")) == NULL) {
  1158. cmdline = "";
  1159. }
  1160. loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
  1161. printf("## Transferring control to NetBSD stage-2 loader "
  1162. "(at address %08lx) ...\n",
  1163. (ulong)loader);
  1164. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1165. /*
  1166. * NetBSD Stage-2 Loader Parameters:
  1167. * r3: ptr to board info data
  1168. * r4: image address
  1169. * r5: console device
  1170. * r6: boot args string
  1171. */
  1172. (*loader)(gd->bd, os_hdr, consdev, cmdline);
  1173. return 1;
  1174. }
  1175. #endif /* CONFIG_BOOTM_NETBSD*/
  1176. #ifdef CONFIG_LYNXKDI
  1177. static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
  1178. bootm_headers_t *images)
  1179. {
  1180. image_header_t *hdr = &images->legacy_hdr_os_copy;
  1181. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1182. return 1;
  1183. #if defined(CONFIG_FIT)
  1184. if (!images->legacy_hdr_valid) {
  1185. fit_unsupported_reset("Lynx");
  1186. return 1;
  1187. }
  1188. #endif
  1189. lynxkdi_boot((image_header_t *)hdr);
  1190. return 1;
  1191. }
  1192. #endif /* CONFIG_LYNXKDI */
  1193. #ifdef CONFIG_BOOTM_RTEMS
  1194. static int do_bootm_rtems(int flag, int argc, char * const argv[],
  1195. bootm_headers_t *images)
  1196. {
  1197. void (*entry_point)(bd_t *);
  1198. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1199. return 1;
  1200. #if defined(CONFIG_FIT)
  1201. if (!images->legacy_hdr_valid) {
  1202. fit_unsupported_reset("RTEMS");
  1203. return 1;
  1204. }
  1205. #endif
  1206. entry_point = (void (*)(bd_t *))images->ep;
  1207. printf("## Transferring control to RTEMS (at address %08lx) ...\n",
  1208. (ulong)entry_point);
  1209. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1210. /*
  1211. * RTEMS Parameters:
  1212. * r3: ptr to board info data
  1213. */
  1214. (*entry_point)(gd->bd);
  1215. return 1;
  1216. }
  1217. #endif /* CONFIG_BOOTM_RTEMS */
  1218. #if defined(CONFIG_BOOTM_OSE)
  1219. static int do_bootm_ose(int flag, int argc, char * const argv[],
  1220. bootm_headers_t *images)
  1221. {
  1222. void (*entry_point)(void);
  1223. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1224. return 1;
  1225. #if defined(CONFIG_FIT)
  1226. if (!images->legacy_hdr_valid) {
  1227. fit_unsupported_reset("OSE");
  1228. return 1;
  1229. }
  1230. #endif
  1231. entry_point = (void (*)(void))images->ep;
  1232. printf("## Transferring control to OSE (at address %08lx) ...\n",
  1233. (ulong)entry_point);
  1234. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1235. /*
  1236. * OSE Parameters:
  1237. * None
  1238. */
  1239. (*entry_point)();
  1240. return 1;
  1241. }
  1242. #endif /* CONFIG_BOOTM_OSE */
  1243. #if defined(CONFIG_CMD_ELF)
  1244. static int do_bootm_vxworks(int flag, int argc, char * const argv[],
  1245. bootm_headers_t *images)
  1246. {
  1247. char str[80];
  1248. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1249. return 1;
  1250. #if defined(CONFIG_FIT)
  1251. if (!images->legacy_hdr_valid) {
  1252. fit_unsupported_reset("VxWorks");
  1253. return 1;
  1254. }
  1255. #endif
  1256. sprintf(str, "%lx", images->ep); /* write entry-point into string */
  1257. setenv("loadaddr", str);
  1258. do_bootvx(NULL, 0, 0, NULL);
  1259. return 1;
  1260. }
  1261. static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
  1262. bootm_headers_t *images)
  1263. {
  1264. char *local_args[2];
  1265. char str[16];
  1266. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1267. return 1;
  1268. #if defined(CONFIG_FIT)
  1269. if (!images->legacy_hdr_valid) {
  1270. fit_unsupported_reset("QNX");
  1271. return 1;
  1272. }
  1273. #endif
  1274. sprintf(str, "%lx", images->ep); /* write entry-point into string */
  1275. local_args[0] = argv[0];
  1276. local_args[1] = str; /* and provide it via the arguments */
  1277. do_bootelf(NULL, 0, 2, local_args);
  1278. return 1;
  1279. }
  1280. #endif
  1281. #ifdef CONFIG_INTEGRITY
  1282. static int do_bootm_integrity(int flag, int argc, char * const argv[],
  1283. bootm_headers_t *images)
  1284. {
  1285. void (*entry_point)(void);
  1286. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1287. return 1;
  1288. #if defined(CONFIG_FIT)
  1289. if (!images->legacy_hdr_valid) {
  1290. fit_unsupported_reset("INTEGRITY");
  1291. return 1;
  1292. }
  1293. #endif
  1294. entry_point = (void (*)(void))images->ep;
  1295. printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
  1296. (ulong)entry_point);
  1297. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1298. /*
  1299. * INTEGRITY Parameters:
  1300. * None
  1301. */
  1302. (*entry_point)();
  1303. return 1;
  1304. }
  1305. #endif