cmd_bootm.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  1. /*
  2. * (C) Copyright 2000-2009
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * Boot support
  9. */
  10. #include <common.h>
  11. #include <watchdog.h>
  12. #include <command.h>
  13. #include <image.h>
  14. #include <malloc.h>
  15. #include <u-boot/zlib.h>
  16. #include <bzlib.h>
  17. #include <environment.h>
  18. #include <lmb.h>
  19. #include <linux/ctype.h>
  20. #include <asm/byteorder.h>
  21. #include <asm/io.h>
  22. #include <linux/compiler.h>
  23. #if defined(CONFIG_BOOTM_VXWORKS) && \
  24. (defined(CONFIG_PPC) || defined(CONFIG_ARM))
  25. #include <vxworks.h>
  26. #endif
  27. #if defined(CONFIG_CMD_USB)
  28. #include <usb.h>
  29. #endif
  30. #if defined(CONFIG_OF_LIBFDT)
  31. #include <libfdt.h>
  32. #include <fdt_support.h>
  33. #endif
  34. #ifdef CONFIG_LZMA
  35. #include <lzma/LzmaTypes.h>
  36. #include <lzma/LzmaDec.h>
  37. #include <lzma/LzmaTools.h>
  38. #endif /* CONFIG_LZMA */
  39. #ifdef CONFIG_LZO
  40. #include <linux/lzo.h>
  41. #endif /* CONFIG_LZO */
  42. DECLARE_GLOBAL_DATA_PTR;
  43. #ifndef CONFIG_SYS_BOOTM_LEN
  44. #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
  45. #endif
  46. #ifdef CONFIG_BZIP2
  47. extern void bz_internal_error(int);
  48. #endif
  49. #if defined(CONFIG_CMD_IMI)
  50. static int image_info(unsigned long addr);
  51. #endif
  52. #if defined(CONFIG_CMD_IMLS)
  53. #include <flash.h>
  54. #include <mtd/cfi_flash.h>
  55. extern flash_info_t flash_info[]; /* info for FLASH chips */
  56. #endif
  57. #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
  58. static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  59. #endif
  60. #include <linux/err.h>
  61. #include <nand.h>
  62. #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
  63. static void fixup_silent_linux(void);
  64. #endif
  65. static int do_bootm_standalone(int flag, int argc, char * const argv[],
  66. bootm_headers_t *images);
  67. static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
  68. char * const argv[], bootm_headers_t *images,
  69. ulong *os_data, ulong *os_len);
  70. /*
  71. * Continue booting an OS image; caller already has:
  72. * - copied image header to global variable `header'
  73. * - checked header magic number, checksums (both header & image),
  74. * - verified image architecture (PPC) and type (KERNEL or MULTI),
  75. * - loaded (first part of) image to header load address,
  76. * - disabled interrupts.
  77. *
  78. * @flag: Flags indicating what to do (BOOTM_STATE_...)
  79. * @argc: Number of arguments. Note that the arguments are shifted down
  80. * so that 0 is the first argument not processed by U-Boot, and
  81. * argc is adjusted accordingly. This avoids confusion as to how
  82. * many arguments are available for the OS.
  83. * @images: Pointers to os/initrd/fdt
  84. * @return 1 on error. On success the OS boots so this function does
  85. * not return.
  86. */
  87. typedef int boot_os_fn(int flag, int argc, char * const argv[],
  88. bootm_headers_t *images);
  89. #ifdef CONFIG_BOOTM_LINUX
  90. extern boot_os_fn do_bootm_linux;
  91. #endif
  92. #ifdef CONFIG_BOOTM_NETBSD
  93. static boot_os_fn do_bootm_netbsd;
  94. #endif
  95. #if defined(CONFIG_LYNXKDI)
  96. static boot_os_fn do_bootm_lynxkdi;
  97. extern void lynxkdi_boot(image_header_t *);
  98. #endif
  99. #ifdef CONFIG_BOOTM_RTEMS
  100. static boot_os_fn do_bootm_rtems;
  101. #endif
  102. #if defined(CONFIG_BOOTM_OSE)
  103. static boot_os_fn do_bootm_ose;
  104. #endif
  105. #if defined(CONFIG_BOOTM_PLAN9)
  106. static boot_os_fn do_bootm_plan9;
  107. #endif
  108. #if defined(CONFIG_BOOTM_VXWORKS) && \
  109. (defined(CONFIG_PPC) || defined(CONFIG_ARM))
  110. static boot_os_fn do_bootm_vxworks;
  111. #endif
  112. #if defined(CONFIG_CMD_ELF)
  113. static boot_os_fn do_bootm_qnxelf;
  114. int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  115. int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  116. #endif
  117. #if defined(CONFIG_INTEGRITY)
  118. static boot_os_fn do_bootm_integrity;
  119. #endif
  120. static boot_os_fn *boot_os[] = {
  121. [IH_OS_U_BOOT] = do_bootm_standalone,
  122. #ifdef CONFIG_BOOTM_LINUX
  123. [IH_OS_LINUX] = do_bootm_linux,
  124. #endif
  125. #ifdef CONFIG_BOOTM_NETBSD
  126. [IH_OS_NETBSD] = do_bootm_netbsd,
  127. #endif
  128. #ifdef CONFIG_LYNXKDI
  129. [IH_OS_LYNXOS] = do_bootm_lynxkdi,
  130. #endif
  131. #ifdef CONFIG_BOOTM_RTEMS
  132. [IH_OS_RTEMS] = do_bootm_rtems,
  133. #endif
  134. #if defined(CONFIG_BOOTM_OSE)
  135. [IH_OS_OSE] = do_bootm_ose,
  136. #endif
  137. #if defined(CONFIG_BOOTM_PLAN9)
  138. [IH_OS_PLAN9] = do_bootm_plan9,
  139. #endif
  140. #if defined(CONFIG_BOOTM_VXWORKS) && \
  141. (defined(CONFIG_PPC) || defined(CONFIG_ARM))
  142. [IH_OS_VXWORKS] = do_bootm_vxworks,
  143. #endif
  144. #if defined(CONFIG_CMD_ELF)
  145. [IH_OS_QNX] = do_bootm_qnxelf,
  146. #endif
  147. #ifdef CONFIG_INTEGRITY
  148. [IH_OS_INTEGRITY] = do_bootm_integrity,
  149. #endif
  150. };
  151. bootm_headers_t images; /* pointers to os/initrd/fdt images */
  152. /* Allow for arch specific config before we boot */
  153. static void __arch_preboot_os(void)
  154. {
  155. /* please define platform specific arch_preboot_os() */
  156. }
  157. void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
  158. #define IH_INITRD_ARCH IH_ARCH_DEFAULT
  159. #ifdef CONFIG_LMB
  160. static void boot_start_lmb(bootm_headers_t *images)
  161. {
  162. ulong mem_start;
  163. phys_size_t mem_size;
  164. lmb_init(&images->lmb);
  165. mem_start = getenv_bootm_low();
  166. mem_size = getenv_bootm_size();
  167. lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
  168. arch_lmb_reserve(&images->lmb);
  169. board_lmb_reserve(&images->lmb);
  170. }
  171. #else
  172. #define lmb_reserve(lmb, base, size)
  173. static inline void boot_start_lmb(bootm_headers_t *images) { }
  174. #endif
  175. static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  176. {
  177. memset((void *)&images, 0, sizeof(images));
  178. images.verify = getenv_yesno("verify");
  179. boot_start_lmb(&images);
  180. bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start");
  181. images.state = BOOTM_STATE_START;
  182. return 0;
  183. }
  184. static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
  185. char * const argv[])
  186. {
  187. const void *os_hdr;
  188. bool ep_found = false;
  189. /* get kernel image header, start address and length */
  190. os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
  191. &images, &images.os.image_start, &images.os.image_len);
  192. if (images.os.image_len == 0) {
  193. puts("ERROR: can't get kernel image!\n");
  194. return 1;
  195. }
  196. /* get image parameters */
  197. switch (genimg_get_format(os_hdr)) {
  198. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  199. case IMAGE_FORMAT_LEGACY:
  200. images.os.type = image_get_type(os_hdr);
  201. images.os.comp = image_get_comp(os_hdr);
  202. images.os.os = image_get_os(os_hdr);
  203. images.os.end = image_get_image_end(os_hdr);
  204. images.os.load = image_get_load(os_hdr);
  205. break;
  206. #endif
  207. #if defined(CONFIG_FIT)
  208. case IMAGE_FORMAT_FIT:
  209. if (fit_image_get_type(images.fit_hdr_os,
  210. images.fit_noffset_os, &images.os.type)) {
  211. puts("Can't get image type!\n");
  212. bootstage_error(BOOTSTAGE_ID_FIT_TYPE);
  213. return 1;
  214. }
  215. if (fit_image_get_comp(images.fit_hdr_os,
  216. images.fit_noffset_os, &images.os.comp)) {
  217. puts("Can't get image compression!\n");
  218. bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION);
  219. return 1;
  220. }
  221. if (fit_image_get_os(images.fit_hdr_os,
  222. images.fit_noffset_os, &images.os.os)) {
  223. puts("Can't get image OS!\n");
  224. bootstage_error(BOOTSTAGE_ID_FIT_OS);
  225. return 1;
  226. }
  227. images.os.end = fit_get_end(images.fit_hdr_os);
  228. if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
  229. &images.os.load)) {
  230. puts("Can't get image load address!\n");
  231. bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR);
  232. return 1;
  233. }
  234. break;
  235. #endif
  236. #ifdef CONFIG_ANDROID_BOOT_IMAGE
  237. case IMAGE_FORMAT_ANDROID:
  238. images.os.type = IH_TYPE_KERNEL;
  239. images.os.comp = IH_COMP_NONE;
  240. images.os.os = IH_OS_LINUX;
  241. images.ep = images.os.load;
  242. ep_found = true;
  243. images.os.end = android_image_get_end(os_hdr);
  244. images.os.load = android_image_get_kload(os_hdr);
  245. break;
  246. #endif
  247. default:
  248. puts("ERROR: unknown image format type!\n");
  249. return 1;
  250. }
  251. /* find kernel entry point */
  252. if (images.legacy_hdr_valid) {
  253. images.ep = image_get_ep(&images.legacy_hdr_os_copy);
  254. #if defined(CONFIG_FIT)
  255. } else if (images.fit_uname_os) {
  256. int ret;
  257. ret = fit_image_get_entry(images.fit_hdr_os,
  258. images.fit_noffset_os, &images.ep);
  259. if (ret) {
  260. puts("Can't get entry point property!\n");
  261. return 1;
  262. }
  263. #endif
  264. } else if (!ep_found) {
  265. puts("Could not find kernel entry point!\n");
  266. return 1;
  267. }
  268. if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
  269. images.os.load = images.os.image_start;
  270. images.ep += images.os.load;
  271. }
  272. images.os.start = (ulong)os_hdr;
  273. return 0;
  274. }
  275. static int bootm_find_ramdisk(int flag, int argc, char * const argv[])
  276. {
  277. int ret;
  278. /* find ramdisk */
  279. ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
  280. &images.rd_start, &images.rd_end);
  281. if (ret) {
  282. puts("Ramdisk image is corrupt or invalid\n");
  283. return 1;
  284. }
  285. return 0;
  286. }
  287. #if defined(CONFIG_OF_LIBFDT)
  288. static int bootm_find_fdt(int flag, int argc, char * const argv[])
  289. {
  290. int ret;
  291. /* find flattened device tree */
  292. ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images,
  293. &images.ft_addr, &images.ft_len);
  294. if (ret) {
  295. puts("Could not find a valid device tree\n");
  296. return 1;
  297. }
  298. set_working_fdt_addr(images.ft_addr);
  299. return 0;
  300. }
  301. #endif
  302. static int bootm_find_other(cmd_tbl_t *cmdtp, int flag, int argc,
  303. char * const argv[])
  304. {
  305. if (((images.os.type == IH_TYPE_KERNEL) ||
  306. (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
  307. (images.os.type == IH_TYPE_MULTI)) &&
  308. (images.os.os == IH_OS_LINUX ||
  309. images.os.os == IH_OS_VXWORKS)) {
  310. if (bootm_find_ramdisk(flag, argc, argv))
  311. return 1;
  312. #if defined(CONFIG_OF_LIBFDT)
  313. if (bootm_find_fdt(flag, argc, argv))
  314. return 1;
  315. #endif
  316. }
  317. return 0;
  318. }
  319. #define BOOTM_ERR_RESET -1
  320. #define BOOTM_ERR_OVERLAP -2
  321. #define BOOTM_ERR_UNIMPLEMENTED -3
  322. static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end,
  323. int boot_progress)
  324. {
  325. image_info_t os = images->os;
  326. uint8_t comp = os.comp;
  327. ulong load = os.load;
  328. ulong blob_start = os.start;
  329. ulong blob_end = os.end;
  330. ulong image_start = os.image_start;
  331. ulong image_len = os.image_len;
  332. __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
  333. int no_overlap = 0;
  334. void *load_buf, *image_buf;
  335. #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
  336. int ret;
  337. #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
  338. const char *type_name = genimg_get_type_name(os.type);
  339. load_buf = map_sysmem(load, unc_len);
  340. image_buf = map_sysmem(image_start, image_len);
  341. switch (comp) {
  342. case IH_COMP_NONE:
  343. if (load == image_start) {
  344. printf(" XIP %s ... ", type_name);
  345. no_overlap = 1;
  346. } else {
  347. printf(" Loading %s ... ", type_name);
  348. memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);
  349. }
  350. *load_end = load + image_len;
  351. break;
  352. #ifdef CONFIG_GZIP
  353. case IH_COMP_GZIP:
  354. printf(" Uncompressing %s ... ", type_name);
  355. if (gunzip(load_buf, unc_len, image_buf, &image_len) != 0) {
  356. puts("GUNZIP: uncompress, out-of-mem or overwrite "
  357. "error - must RESET board to recover\n");
  358. if (boot_progress)
  359. bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
  360. return BOOTM_ERR_RESET;
  361. }
  362. *load_end = load + image_len;
  363. break;
  364. #endif /* CONFIG_GZIP */
  365. #ifdef CONFIG_BZIP2
  366. case IH_COMP_BZIP2:
  367. printf(" Uncompressing %s ... ", type_name);
  368. /*
  369. * If we've got less than 4 MB of malloc() space,
  370. * use slower decompression algorithm which requires
  371. * at most 2300 KB of memory.
  372. */
  373. int i = BZ2_bzBuffToBuffDecompress(load_buf, &unc_len,
  374. image_buf, image_len,
  375. CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
  376. if (i != BZ_OK) {
  377. printf("BUNZIP2: uncompress or overwrite error %d "
  378. "- must RESET board to recover\n", i);
  379. if (boot_progress)
  380. bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
  381. return BOOTM_ERR_RESET;
  382. }
  383. *load_end = load + unc_len;
  384. break;
  385. #endif /* CONFIG_BZIP2 */
  386. #ifdef CONFIG_LZMA
  387. case IH_COMP_LZMA: {
  388. SizeT lzma_len = unc_len;
  389. printf(" Uncompressing %s ... ", type_name);
  390. ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len,
  391. image_buf, image_len);
  392. unc_len = lzma_len;
  393. if (ret != SZ_OK) {
  394. printf("LZMA: uncompress or overwrite error %d "
  395. "- must RESET board to recover\n", ret);
  396. bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
  397. return BOOTM_ERR_RESET;
  398. }
  399. *load_end = load + unc_len;
  400. break;
  401. }
  402. #endif /* CONFIG_LZMA */
  403. #ifdef CONFIG_LZO
  404. case IH_COMP_LZO: {
  405. size_t size = unc_len;
  406. printf(" Uncompressing %s ... ", type_name);
  407. ret = lzop_decompress(image_buf, image_len, load_buf, &size);
  408. if (ret != LZO_E_OK) {
  409. printf("LZO: uncompress or overwrite error %d "
  410. "- must RESET board to recover\n", ret);
  411. if (boot_progress)
  412. bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
  413. return BOOTM_ERR_RESET;
  414. }
  415. *load_end = load + size;
  416. break;
  417. }
  418. #endif /* CONFIG_LZO */
  419. default:
  420. printf("Unimplemented compression type %d\n", comp);
  421. return BOOTM_ERR_UNIMPLEMENTED;
  422. }
  423. flush_cache(load, (*load_end - load) * sizeof(ulong));
  424. puts("OK\n");
  425. debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
  426. bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
  427. if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
  428. debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
  429. blob_start, blob_end);
  430. debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
  431. *load_end);
  432. /* Check what type of image this is. */
  433. if (images->legacy_hdr_valid) {
  434. if (image_get_type(&images->legacy_hdr_os_copy)
  435. == IH_TYPE_MULTI)
  436. puts("WARNING: legacy format multi component image overwritten\n");
  437. return BOOTM_ERR_OVERLAP;
  438. } else {
  439. puts("ERROR: new format image overwritten - must RESET the board to recover\n");
  440. bootstage_error(BOOTSTAGE_ID_OVERWRITTEN);
  441. return BOOTM_ERR_RESET;
  442. }
  443. }
  444. return 0;
  445. }
  446. static int do_bootm_standalone(int flag, int argc, char * const argv[],
  447. bootm_headers_t *images)
  448. {
  449. char *s;
  450. int (*appl)(int, char * const []);
  451. /* Don't start if "autostart" is set to "no" */
  452. if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
  453. setenv_hex("filesize", images->os.image_len);
  454. return 0;
  455. }
  456. appl = (int (*)(int, char * const []))images->ep;
  457. appl(argc, argv);
  458. return 0;
  459. }
  460. /* we overload the cmd field with our state machine info instead of a
  461. * function pointer */
  462. static cmd_tbl_t cmd_bootm_sub[] = {
  463. U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
  464. U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
  465. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  466. U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
  467. #endif
  468. #ifdef CONFIG_OF_LIBFDT
  469. U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
  470. #endif
  471. U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
  472. U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
  473. U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
  474. U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""),
  475. U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
  476. };
  477. static int boot_selected_os(int argc, char * const argv[], int state,
  478. bootm_headers_t *images, boot_os_fn *boot_fn)
  479. {
  480. arch_preboot_os();
  481. boot_fn(state, argc, argv, images);
  482. /* Stand-alone may return when 'autostart' is 'no' */
  483. if (images->os.type == IH_TYPE_STANDALONE ||
  484. state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */
  485. return 0;
  486. bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
  487. #ifdef DEBUG
  488. puts("\n## Control returned to monitor - resetting...\n");
  489. #endif
  490. return BOOTM_ERR_RESET;
  491. }
  492. /**
  493. * bootm_disable_interrupts() - Disable interrupts in preparation for load/boot
  494. *
  495. * @return interrupt flag (0 if interrupts were disabled, non-zero if they were
  496. * enabled)
  497. */
  498. static ulong bootm_disable_interrupts(void)
  499. {
  500. ulong iflag;
  501. /*
  502. * We have reached the point of no return: we are going to
  503. * overwrite all exception vector code, so we cannot easily
  504. * recover from any failures any more...
  505. */
  506. iflag = disable_interrupts();
  507. #ifdef CONFIG_NETCONSOLE
  508. /* Stop the ethernet stack if NetConsole could have left it up */
  509. eth_halt();
  510. eth_unregister(eth_get_dev());
  511. #endif
  512. #if defined(CONFIG_CMD_USB)
  513. /*
  514. * turn off USB to prevent the host controller from writing to the
  515. * SDRAM while Linux is booting. This could happen (at least for OHCI
  516. * controller), because the HCCA (Host Controller Communication Area)
  517. * lies within the SDRAM and the host controller writes continously to
  518. * this area (as busmaster!). The HccaFrameNumber is for example
  519. * updated every 1 ms within the HCCA structure in SDRAM! For more
  520. * details see the OpenHCI specification.
  521. */
  522. usb_stop();
  523. #endif
  524. return iflag;
  525. }
  526. /**
  527. * Execute selected states of the bootm command.
  528. *
  529. * Note the arguments to this state must be the first argument, Any 'bootm'
  530. * or sub-command arguments must have already been taken.
  531. *
  532. * Note that if states contains more than one flag it MUST contain
  533. * BOOTM_STATE_START, since this handles and consumes the command line args.
  534. *
  535. * Also note that aside from boot_os_fn functions and bootm_load_os no other
  536. * functions we store the return value of in 'ret' may use a negative return
  537. * value, without special handling.
  538. *
  539. * @param cmdtp Pointer to bootm command table entry
  540. * @param flag Command flags (CMD_FLAG_...)
  541. * @param argc Number of subcommand arguments (0 = no arguments)
  542. * @param argv Arguments
  543. * @param states Mask containing states to run (BOOTM_STATE_...)
  544. * @param images Image header information
  545. * @param boot_progress 1 to show boot progress, 0 to not do this
  546. * @return 0 if ok, something else on error. Some errors will cause this
  547. * function to perform a reboot! If states contains BOOTM_STATE_OS_GO
  548. * then the intent is to boot an OS, so this function will not return
  549. * unless the image type is standalone.
  550. */
  551. static int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc,
  552. char * const argv[], int states, bootm_headers_t *images,
  553. int boot_progress)
  554. {
  555. boot_os_fn *boot_fn;
  556. ulong iflag = 0;
  557. int ret = 0, need_boot_fn;
  558. images->state |= states;
  559. /*
  560. * Work through the states and see how far we get. We stop on
  561. * any error.
  562. */
  563. if (states & BOOTM_STATE_START)
  564. ret = bootm_start(cmdtp, flag, argc, argv);
  565. if (!ret && (states & BOOTM_STATE_FINDOS))
  566. ret = bootm_find_os(cmdtp, flag, argc, argv);
  567. if (!ret && (states & BOOTM_STATE_FINDOTHER)) {
  568. ret = bootm_find_other(cmdtp, flag, argc, argv);
  569. argc = 0; /* consume the args */
  570. }
  571. /* Load the OS */
  572. if (!ret && (states & BOOTM_STATE_LOADOS)) {
  573. ulong load_end;
  574. iflag = bootm_disable_interrupts();
  575. ret = bootm_load_os(images, &load_end, 0);
  576. if (ret == 0)
  577. lmb_reserve(&images->lmb, images->os.load,
  578. (load_end - images->os.load));
  579. else if (ret && ret != BOOTM_ERR_OVERLAP)
  580. goto err;
  581. else if (ret == BOOTM_ERR_OVERLAP)
  582. ret = 0;
  583. #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
  584. if (images->os.os == IH_OS_LINUX)
  585. fixup_silent_linux();
  586. #endif
  587. }
  588. /* Relocate the ramdisk */
  589. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  590. if (!ret && (states & BOOTM_STATE_RAMDISK)) {
  591. ulong rd_len = images->rd_end - images->rd_start;
  592. ret = boot_ramdisk_high(&images->lmb, images->rd_start,
  593. rd_len, &images->initrd_start, &images->initrd_end);
  594. if (!ret) {
  595. setenv_hex("initrd_start", images->initrd_start);
  596. setenv_hex("initrd_end", images->initrd_end);
  597. }
  598. }
  599. #endif
  600. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
  601. if (!ret && (states & BOOTM_STATE_FDT)) {
  602. boot_fdt_add_mem_rsv_regions(&images->lmb, images->ft_addr);
  603. ret = boot_relocate_fdt(&images->lmb, &images->ft_addr,
  604. &images->ft_len);
  605. }
  606. #endif
  607. /* From now on, we need the OS boot function */
  608. if (ret)
  609. return ret;
  610. boot_fn = boot_os[images->os.os];
  611. need_boot_fn = states & (BOOTM_STATE_OS_CMDLINE |
  612. BOOTM_STATE_OS_BD_T | BOOTM_STATE_OS_PREP |
  613. BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO);
  614. if (boot_fn == NULL && need_boot_fn) {
  615. if (iflag)
  616. enable_interrupts();
  617. printf("ERROR: booting os '%s' (%d) is not supported\n",
  618. genimg_get_os_name(images->os.os), images->os.os);
  619. bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS);
  620. return 1;
  621. }
  622. /* Call various other states that are not generally used */
  623. if (!ret && (states & BOOTM_STATE_OS_CMDLINE))
  624. ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images);
  625. if (!ret && (states & BOOTM_STATE_OS_BD_T))
  626. ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
  627. if (!ret && (states & BOOTM_STATE_OS_PREP))
  628. ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
  629. #ifdef CONFIG_TRACE
  630. /* Pretend to run the OS, then run a user command */
  631. if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) {
  632. char *cmd_list = getenv("fakegocmd");
  633. ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO,
  634. images, boot_fn);
  635. if (!ret && cmd_list)
  636. ret = run_command_list(cmd_list, -1, flag);
  637. }
  638. #endif
  639. /* Check for unsupported subcommand. */
  640. if (ret) {
  641. puts("subcommand not supported\n");
  642. return ret;
  643. }
  644. /* Now run the OS! We hope this doesn't return */
  645. if (!ret && (states & BOOTM_STATE_OS_GO))
  646. ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_GO,
  647. images, boot_fn);
  648. /* Deal with any fallout */
  649. err:
  650. if (iflag)
  651. enable_interrupts();
  652. if (ret == BOOTM_ERR_UNIMPLEMENTED)
  653. bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
  654. else if (ret == BOOTM_ERR_RESET)
  655. do_reset(cmdtp, flag, argc, argv);
  656. return ret;
  657. }
  658. static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
  659. char * const argv[])
  660. {
  661. int ret = 0;
  662. long state;
  663. cmd_tbl_t *c;
  664. c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
  665. argc--; argv++;
  666. if (c) {
  667. state = (long)c->cmd;
  668. if (state == BOOTM_STATE_START)
  669. state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER;
  670. } else {
  671. /* Unrecognized command */
  672. return CMD_RET_USAGE;
  673. }
  674. if (state != BOOTM_STATE_START && images.state >= state) {
  675. printf("Trying to execute a command out of order\n");
  676. return CMD_RET_USAGE;
  677. }
  678. ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0);
  679. return ret;
  680. }
  681. /*******************************************************************/
  682. /* bootm - boot application image from image in memory */
  683. /*******************************************************************/
  684. int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  685. {
  686. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  687. static int relocated = 0;
  688. if (!relocated) {
  689. int i;
  690. /* relocate boot function table */
  691. for (i = 0; i < ARRAY_SIZE(boot_os); i++)
  692. if (boot_os[i] != NULL)
  693. boot_os[i] += gd->reloc_off;
  694. /* relocate names of sub-command table */
  695. for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
  696. cmd_bootm_sub[i].name += gd->reloc_off;
  697. relocated = 1;
  698. }
  699. #endif
  700. /* determine if we have a sub command */
  701. argc--; argv++;
  702. if (argc > 0) {
  703. char *endp;
  704. simple_strtoul(argv[0], &endp, 16);
  705. /* endp pointing to NULL means that argv[0] was just a
  706. * valid number, pass it along to the normal bootm processing
  707. *
  708. * If endp is ':' or '#' assume a FIT identifier so pass
  709. * along for normal processing.
  710. *
  711. * Right now we assume the first arg should never be '-'
  712. */
  713. if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
  714. return do_bootm_subcommand(cmdtp, flag, argc, argv);
  715. }
  716. return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START |
  717. BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER |
  718. BOOTM_STATE_LOADOS |
  719. #if defined(CONFIG_PPC) || defined(CONFIG_MIPS)
  720. BOOTM_STATE_OS_CMDLINE |
  721. #endif
  722. BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  723. BOOTM_STATE_OS_GO, &images, 1);
  724. }
  725. int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
  726. {
  727. const char *ep = getenv("autostart");
  728. if (ep && !strcmp(ep, "yes")) {
  729. char *local_args[2];
  730. local_args[0] = (char *)cmd;
  731. local_args[1] = NULL;
  732. printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
  733. return do_bootm(cmdtp, 0, 1, local_args);
  734. }
  735. return 0;
  736. }
  737. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  738. /**
  739. * image_get_kernel - verify legacy format kernel image
  740. * @img_addr: in RAM address of the legacy format image to be verified
  741. * @verify: data CRC verification flag
  742. *
  743. * image_get_kernel() verifies legacy image integrity and returns pointer to
  744. * legacy image header if image verification was completed successfully.
  745. *
  746. * returns:
  747. * pointer to a legacy image header if valid image was found
  748. * otherwise return NULL
  749. */
  750. static image_header_t *image_get_kernel(ulong img_addr, int verify)
  751. {
  752. image_header_t *hdr = (image_header_t *)img_addr;
  753. if (!image_check_magic(hdr)) {
  754. puts("Bad Magic Number\n");
  755. bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC);
  756. return NULL;
  757. }
  758. bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER);
  759. if (!image_check_hcrc(hdr)) {
  760. puts("Bad Header Checksum\n");
  761. bootstage_error(BOOTSTAGE_ID_CHECK_HEADER);
  762. return NULL;
  763. }
  764. bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM);
  765. image_print_contents(hdr);
  766. if (verify) {
  767. puts(" Verifying Checksum ... ");
  768. if (!image_check_dcrc(hdr)) {
  769. printf("Bad Data CRC\n");
  770. bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM);
  771. return NULL;
  772. }
  773. puts("OK\n");
  774. }
  775. bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH);
  776. if (!image_check_target_arch(hdr)) {
  777. printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
  778. bootstage_error(BOOTSTAGE_ID_CHECK_ARCH);
  779. return NULL;
  780. }
  781. return hdr;
  782. }
  783. #endif
  784. /**
  785. * boot_get_kernel - find kernel image
  786. * @os_data: pointer to a ulong variable, will hold os data start address
  787. * @os_len: pointer to a ulong variable, will hold os data length
  788. *
  789. * boot_get_kernel() tries to find a kernel image, verifies its integrity
  790. * and locates kernel data.
  791. *
  792. * returns:
  793. * pointer to image header if valid image was found, plus kernel start
  794. * address and length, otherwise NULL
  795. */
  796. static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
  797. char * const argv[], bootm_headers_t *images, ulong *os_data,
  798. ulong *os_len)
  799. {
  800. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  801. image_header_t *hdr;
  802. #endif
  803. ulong img_addr;
  804. const void *buf;
  805. #if defined(CONFIG_FIT)
  806. const char *fit_uname_config = NULL;
  807. const char *fit_uname_kernel = NULL;
  808. int os_noffset;
  809. #endif
  810. /* find out kernel image address */
  811. if (argc < 1) {
  812. img_addr = load_addr;
  813. debug("* kernel: default image load address = 0x%08lx\n",
  814. load_addr);
  815. #if defined(CONFIG_FIT)
  816. } else if (fit_parse_conf(argv[0], load_addr, &img_addr,
  817. &fit_uname_config)) {
  818. debug("* kernel: config '%s' from image at 0x%08lx\n",
  819. fit_uname_config, img_addr);
  820. } else if (fit_parse_subimage(argv[0], load_addr, &img_addr,
  821. &fit_uname_kernel)) {
  822. debug("* kernel: subimage '%s' from image at 0x%08lx\n",
  823. fit_uname_kernel, img_addr);
  824. #endif
  825. } else {
  826. img_addr = simple_strtoul(argv[0], NULL, 16);
  827. debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
  828. }
  829. bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
  830. /* copy from dataflash if needed */
  831. img_addr = genimg_get_image(img_addr);
  832. /* check image type, for FIT images get FIT kernel node */
  833. *os_data = *os_len = 0;
  834. buf = map_sysmem(img_addr, 0);
  835. switch (genimg_get_format(buf)) {
  836. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  837. case IMAGE_FORMAT_LEGACY:
  838. printf("## Booting kernel from Legacy Image at %08lx ...\n",
  839. img_addr);
  840. hdr = image_get_kernel(img_addr, images->verify);
  841. if (!hdr)
  842. return NULL;
  843. bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
  844. /* get os_data and os_len */
  845. switch (image_get_type(hdr)) {
  846. case IH_TYPE_KERNEL:
  847. case IH_TYPE_KERNEL_NOLOAD:
  848. *os_data = image_get_data(hdr);
  849. *os_len = image_get_data_size(hdr);
  850. break;
  851. case IH_TYPE_MULTI:
  852. image_multi_getimg(hdr, 0, os_data, os_len);
  853. break;
  854. case IH_TYPE_STANDALONE:
  855. *os_data = image_get_data(hdr);
  856. *os_len = image_get_data_size(hdr);
  857. break;
  858. default:
  859. printf("Wrong Image Type for %s command\n",
  860. cmdtp->name);
  861. bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
  862. return NULL;
  863. }
  864. /*
  865. * copy image header to allow for image overwrites during
  866. * kernel decompression.
  867. */
  868. memmove(&images->legacy_hdr_os_copy, hdr,
  869. sizeof(image_header_t));
  870. /* save pointer to image header */
  871. images->legacy_hdr_os = hdr;
  872. images->legacy_hdr_valid = 1;
  873. bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
  874. break;
  875. #endif
  876. #if defined(CONFIG_FIT)
  877. case IMAGE_FORMAT_FIT:
  878. os_noffset = fit_image_load(images, FIT_KERNEL_PROP,
  879. img_addr,
  880. &fit_uname_kernel, &fit_uname_config,
  881. IH_ARCH_DEFAULT, IH_TYPE_KERNEL,
  882. BOOTSTAGE_ID_FIT_KERNEL_START,
  883. FIT_LOAD_IGNORED, os_data, os_len);
  884. if (os_noffset < 0)
  885. return NULL;
  886. images->fit_hdr_os = map_sysmem(img_addr, 0);
  887. images->fit_uname_os = fit_uname_kernel;
  888. images->fit_uname_cfg = fit_uname_config;
  889. images->fit_noffset_os = os_noffset;
  890. break;
  891. #endif
  892. #ifdef CONFIG_ANDROID_BOOT_IMAGE
  893. case IMAGE_FORMAT_ANDROID:
  894. printf("## Booting Android Image at 0x%08lx ...\n", img_addr);
  895. if (android_image_get_kernel((void *)img_addr, images->verify,
  896. os_data, os_len))
  897. return NULL;
  898. break;
  899. #endif
  900. default:
  901. printf("Wrong Image Format for %s command\n", cmdtp->name);
  902. bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO);
  903. return NULL;
  904. }
  905. debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
  906. *os_data, *os_len, *os_len);
  907. return buf;
  908. }
  909. #ifdef CONFIG_SYS_LONGHELP
  910. static char bootm_help_text[] =
  911. "[addr [arg ...]]\n - boot application image stored in memory\n"
  912. "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
  913. "\t'arg' can be the address of an initrd image\n"
  914. #if defined(CONFIG_OF_LIBFDT)
  915. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  916. "\ta third argument is required which is the address of the\n"
  917. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  918. "\tuse a '-' for the second argument. If you do not pass a third\n"
  919. "\ta bd_info struct will be passed instead\n"
  920. #endif
  921. #if defined(CONFIG_FIT)
  922. "\t\nFor the new multi component uImage format (FIT) addresses\n"
  923. "\tmust be extened to include component or configuration unit name:\n"
  924. "\taddr:<subimg_uname> - direct component image specification\n"
  925. "\taddr#<conf_uname> - configuration specification\n"
  926. "\tUse iminfo command to get the list of existing component\n"
  927. "\timages and configurations.\n"
  928. #endif
  929. "\nSub-commands to do part of the bootm sequence. The sub-commands "
  930. "must be\n"
  931. "issued in the order below (it's ok to not issue all sub-commands):\n"
  932. "\tstart [addr [arg ...]]\n"
  933. "\tloados - load OS image\n"
  934. #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
  935. "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
  936. #endif
  937. #if defined(CONFIG_OF_LIBFDT)
  938. "\tfdt - relocate flat device tree\n"
  939. #endif
  940. "\tcmdline - OS specific command line processing/setup\n"
  941. "\tbdt - OS specific bd_t processing\n"
  942. "\tprep - OS specific prep before relocation or go\n"
  943. "\tgo - start OS";
  944. #endif
  945. U_BOOT_CMD(
  946. bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
  947. "boot application image from memory", bootm_help_text
  948. );
  949. /*******************************************************************/
  950. /* bootd - boot default image */
  951. /*******************************************************************/
  952. #if defined(CONFIG_CMD_BOOTD)
  953. int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  954. {
  955. return run_command(getenv("bootcmd"), flag);
  956. }
  957. U_BOOT_CMD(
  958. boot, 1, 1, do_bootd,
  959. "boot default, i.e., run 'bootcmd'",
  960. ""
  961. );
  962. /* keep old command name "bootd" for backward compatibility */
  963. U_BOOT_CMD(
  964. bootd, 1, 1, do_bootd,
  965. "boot default, i.e., run 'bootcmd'",
  966. ""
  967. );
  968. #endif
  969. /*******************************************************************/
  970. /* iminfo - print header info for a requested image */
  971. /*******************************************************************/
  972. #if defined(CONFIG_CMD_IMI)
  973. static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  974. {
  975. int arg;
  976. ulong addr;
  977. int rcode = 0;
  978. if (argc < 2) {
  979. return image_info(load_addr);
  980. }
  981. for (arg = 1; arg < argc; ++arg) {
  982. addr = simple_strtoul(argv[arg], NULL, 16);
  983. if (image_info(addr) != 0)
  984. rcode = 1;
  985. }
  986. return rcode;
  987. }
  988. static int image_info(ulong addr)
  989. {
  990. void *hdr = (void *)addr;
  991. printf("\n## Checking Image at %08lx ...\n", addr);
  992. switch (genimg_get_format(hdr)) {
  993. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  994. case IMAGE_FORMAT_LEGACY:
  995. puts(" Legacy image found\n");
  996. if (!image_check_magic(hdr)) {
  997. puts(" Bad Magic Number\n");
  998. return 1;
  999. }
  1000. if (!image_check_hcrc(hdr)) {
  1001. puts(" Bad Header Checksum\n");
  1002. return 1;
  1003. }
  1004. image_print_contents(hdr);
  1005. puts(" Verifying Checksum ... ");
  1006. if (!image_check_dcrc(hdr)) {
  1007. puts(" Bad Data CRC\n");
  1008. return 1;
  1009. }
  1010. puts("OK\n");
  1011. return 0;
  1012. #endif
  1013. #if defined(CONFIG_FIT)
  1014. case IMAGE_FORMAT_FIT:
  1015. puts(" FIT image found\n");
  1016. if (!fit_check_format(hdr)) {
  1017. puts("Bad FIT image format!\n");
  1018. return 1;
  1019. }
  1020. fit_print_contents(hdr);
  1021. if (!fit_all_image_verify(hdr)) {
  1022. puts("Bad hash in FIT image!\n");
  1023. return 1;
  1024. }
  1025. return 0;
  1026. #endif
  1027. default:
  1028. puts("Unknown image format!\n");
  1029. break;
  1030. }
  1031. return 1;
  1032. }
  1033. U_BOOT_CMD(
  1034. iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
  1035. "print header information for application image",
  1036. "addr [addr ...]\n"
  1037. " - print header information for application image starting at\n"
  1038. " address 'addr' in memory; this includes verification of the\n"
  1039. " image contents (magic number, header and payload checksums)"
  1040. );
  1041. #endif
  1042. /*******************************************************************/
  1043. /* imls - list all images found in flash */
  1044. /*******************************************************************/
  1045. #if defined(CONFIG_CMD_IMLS)
  1046. static int do_imls_nor(void)
  1047. {
  1048. flash_info_t *info;
  1049. int i, j;
  1050. void *hdr;
  1051. for (i = 0, info = &flash_info[0];
  1052. i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
  1053. if (info->flash_id == FLASH_UNKNOWN)
  1054. goto next_bank;
  1055. for (j = 0; j < info->sector_count; ++j) {
  1056. hdr = (void *)info->start[j];
  1057. if (!hdr)
  1058. goto next_sector;
  1059. switch (genimg_get_format(hdr)) {
  1060. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  1061. case IMAGE_FORMAT_LEGACY:
  1062. if (!image_check_hcrc(hdr))
  1063. goto next_sector;
  1064. printf("Legacy Image at %08lX:\n", (ulong)hdr);
  1065. image_print_contents(hdr);
  1066. puts(" Verifying Checksum ... ");
  1067. if (!image_check_dcrc(hdr)) {
  1068. puts("Bad Data CRC\n");
  1069. } else {
  1070. puts("OK\n");
  1071. }
  1072. break;
  1073. #endif
  1074. #if defined(CONFIG_FIT)
  1075. case IMAGE_FORMAT_FIT:
  1076. if (!fit_check_format(hdr))
  1077. goto next_sector;
  1078. printf("FIT Image at %08lX:\n", (ulong)hdr);
  1079. fit_print_contents(hdr);
  1080. break;
  1081. #endif
  1082. default:
  1083. goto next_sector;
  1084. }
  1085. next_sector: ;
  1086. }
  1087. next_bank: ;
  1088. }
  1089. return 0;
  1090. }
  1091. #endif
  1092. #if defined(CONFIG_CMD_IMLS_NAND)
  1093. static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
  1094. size_t len)
  1095. {
  1096. void *imgdata;
  1097. int ret;
  1098. imgdata = malloc(len);
  1099. if (!imgdata) {
  1100. printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
  1101. nand_dev, off);
  1102. printf(" Low memory(cannot allocate memory for image)\n");
  1103. return -ENOMEM;
  1104. }
  1105. ret = nand_read_skip_bad(nand, off, &len,
  1106. imgdata);
  1107. if (ret < 0 && ret != -EUCLEAN) {
  1108. free(imgdata);
  1109. return ret;
  1110. }
  1111. if (!image_check_hcrc(imgdata)) {
  1112. free(imgdata);
  1113. return 0;
  1114. }
  1115. printf("Legacy Image at NAND device %d offset %08llX:\n",
  1116. nand_dev, off);
  1117. image_print_contents(imgdata);
  1118. puts(" Verifying Checksum ... ");
  1119. if (!image_check_dcrc(imgdata))
  1120. puts("Bad Data CRC\n");
  1121. else
  1122. puts("OK\n");
  1123. free(imgdata);
  1124. return 0;
  1125. }
  1126. static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
  1127. size_t len)
  1128. {
  1129. void *imgdata;
  1130. int ret;
  1131. imgdata = malloc(len);
  1132. if (!imgdata) {
  1133. printf("May be a FIT Image at NAND device %d offset %08llX:\n",
  1134. nand_dev, off);
  1135. printf(" Low memory(cannot allocate memory for image)\n");
  1136. return -ENOMEM;
  1137. }
  1138. ret = nand_read_skip_bad(nand, off, &len,
  1139. imgdata);
  1140. if (ret < 0 && ret != -EUCLEAN) {
  1141. free(imgdata);
  1142. return ret;
  1143. }
  1144. if (!fit_check_format(imgdata)) {
  1145. free(imgdata);
  1146. return 0;
  1147. }
  1148. printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
  1149. fit_print_contents(imgdata);
  1150. free(imgdata);
  1151. return 0;
  1152. }
  1153. static int do_imls_nand(void)
  1154. {
  1155. nand_info_t *nand;
  1156. int nand_dev = nand_curr_device;
  1157. size_t len;
  1158. loff_t off;
  1159. u32 buffer[16];
  1160. if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
  1161. puts("\nNo NAND devices available\n");
  1162. return -ENODEV;
  1163. }
  1164. printf("\n");
  1165. for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
  1166. nand = &nand_info[nand_dev];
  1167. if (!nand->name || !nand->size)
  1168. continue;
  1169. for (off = 0; off < nand->size; off += nand->erasesize) {
  1170. const image_header_t *header;
  1171. int ret;
  1172. if (nand_block_isbad(nand, off))
  1173. continue;
  1174. len = sizeof(buffer);
  1175. ret = nand_read(nand, off, &len, (u8 *)buffer);
  1176. if (ret < 0 && ret != -EUCLEAN) {
  1177. printf("NAND read error %d at offset %08llX\n",
  1178. ret, off);
  1179. continue;
  1180. }
  1181. switch (genimg_get_format(buffer)) {
  1182. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  1183. case IMAGE_FORMAT_LEGACY:
  1184. header = (const image_header_t *)buffer;
  1185. len = image_get_image_size(header);
  1186. nand_imls_legacyimage(nand, nand_dev, off, len);
  1187. break;
  1188. #endif
  1189. #if defined(CONFIG_FIT)
  1190. case IMAGE_FORMAT_FIT:
  1191. len = fit_get_size(buffer);
  1192. nand_imls_fitimage(nand, nand_dev, off, len);
  1193. break;
  1194. #endif
  1195. }
  1196. }
  1197. }
  1198. return 0;
  1199. }
  1200. #endif
  1201. #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
  1202. static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1203. {
  1204. int ret_nor = 0, ret_nand = 0;
  1205. #if defined(CONFIG_CMD_IMLS)
  1206. ret_nor = do_imls_nor();
  1207. #endif
  1208. #if defined(CONFIG_CMD_IMLS_NAND)
  1209. ret_nand = do_imls_nand();
  1210. #endif
  1211. if (ret_nor)
  1212. return ret_nor;
  1213. if (ret_nand)
  1214. return ret_nand;
  1215. return (0);
  1216. }
  1217. U_BOOT_CMD(
  1218. imls, 1, 1, do_imls,
  1219. "list all images found in flash",
  1220. "\n"
  1221. " - Prints information about all images found at sector/block\n"
  1222. " boundaries in nor/nand flash."
  1223. );
  1224. #endif
  1225. /*******************************************************************/
  1226. /* helper routines */
  1227. /*******************************************************************/
  1228. #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
  1229. #define CONSOLE_ARG "console="
  1230. #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
  1231. static void fixup_silent_linux(void)
  1232. {
  1233. char *buf;
  1234. const char *env_val;
  1235. char *cmdline = getenv("bootargs");
  1236. int want_silent;
  1237. /*
  1238. * Only fix cmdline when requested. The environment variable can be:
  1239. *
  1240. * no - we never fixup
  1241. * yes - we always fixup
  1242. * unset - we rely on the console silent flag
  1243. */
  1244. want_silent = getenv_yesno("silent_linux");
  1245. if (want_silent == 0)
  1246. return;
  1247. else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT))
  1248. return;
  1249. debug("before silent fix-up: %s\n", cmdline);
  1250. if (cmdline && (cmdline[0] != '\0')) {
  1251. char *start = strstr(cmdline, CONSOLE_ARG);
  1252. /* Allocate space for maximum possible new command line */
  1253. buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
  1254. if (!buf) {
  1255. debug("%s: out of memory\n", __func__);
  1256. return;
  1257. }
  1258. if (start) {
  1259. char *end = strchr(start, ' ');
  1260. int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN;
  1261. strncpy(buf, cmdline, num_start_bytes);
  1262. if (end)
  1263. strcpy(buf + num_start_bytes, end);
  1264. else
  1265. buf[num_start_bytes] = '\0';
  1266. } else {
  1267. sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
  1268. }
  1269. env_val = buf;
  1270. } else {
  1271. buf = NULL;
  1272. env_val = CONSOLE_ARG;
  1273. }
  1274. setenv("bootargs", env_val);
  1275. debug("after silent fix-up: %s\n", env_val);
  1276. free(buf);
  1277. }
  1278. #endif /* CONFIG_SILENT_CONSOLE */
  1279. #if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9)
  1280. static void copy_args(char *dest, int argc, char * const argv[], char delim)
  1281. {
  1282. int i;
  1283. for (i = 0; i < argc; i++) {
  1284. if (i > 0)
  1285. *dest++ = delim;
  1286. strcpy(dest, argv[i]);
  1287. dest += strlen(argv[i]);
  1288. }
  1289. }
  1290. #endif
  1291. /*******************************************************************/
  1292. /* OS booting routines */
  1293. /*******************************************************************/
  1294. #ifdef CONFIG_BOOTM_NETBSD
  1295. static int do_bootm_netbsd(int flag, int argc, char * const argv[],
  1296. bootm_headers_t *images)
  1297. {
  1298. void (*loader)(bd_t *, image_header_t *, char *, char *);
  1299. image_header_t *os_hdr, *hdr;
  1300. ulong kernel_data, kernel_len;
  1301. char *consdev;
  1302. char *cmdline;
  1303. if (flag != BOOTM_STATE_OS_GO)
  1304. return 0;
  1305. #if defined(CONFIG_FIT)
  1306. if (!images->legacy_hdr_valid) {
  1307. fit_unsupported_reset("NetBSD");
  1308. return 1;
  1309. }
  1310. #endif
  1311. hdr = images->legacy_hdr_os;
  1312. /*
  1313. * Booting a (NetBSD) kernel image
  1314. *
  1315. * This process is pretty similar to a standalone application:
  1316. * The (first part of an multi-) image must be a stage-2 loader,
  1317. * which in turn is responsible for loading & invoking the actual
  1318. * kernel. The only differences are the parameters being passed:
  1319. * besides the board info strucure, the loader expects a command
  1320. * line, the name of the console device, and (optionally) the
  1321. * address of the original image header.
  1322. */
  1323. os_hdr = NULL;
  1324. if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
  1325. image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
  1326. if (kernel_len)
  1327. os_hdr = hdr;
  1328. }
  1329. consdev = "";
  1330. #if defined(CONFIG_8xx_CONS_SMC1)
  1331. consdev = "smc1";
  1332. #elif defined(CONFIG_8xx_CONS_SMC2)
  1333. consdev = "smc2";
  1334. #elif defined(CONFIG_8xx_CONS_SCC2)
  1335. consdev = "scc2";
  1336. #elif defined(CONFIG_8xx_CONS_SCC3)
  1337. consdev = "scc3";
  1338. #endif
  1339. if (argc > 0) {
  1340. ulong len;
  1341. int i;
  1342. for (i = 0, len = 0; i < argc; i += 1)
  1343. len += strlen(argv[i]) + 1;
  1344. cmdline = malloc(len);
  1345. copy_args(cmdline, argc, argv, ' ');
  1346. } else if ((cmdline = getenv("bootargs")) == NULL) {
  1347. cmdline = "";
  1348. }
  1349. loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
  1350. printf("## Transferring control to NetBSD stage-2 loader "
  1351. "(at address %08lx) ...\n",
  1352. (ulong)loader);
  1353. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1354. /*
  1355. * NetBSD Stage-2 Loader Parameters:
  1356. * arg[0]: pointer to board info data
  1357. * arg[1]: image load address
  1358. * arg[2]: char pointer to the console device to use
  1359. * arg[3]: char pointer to the boot arguments
  1360. */
  1361. (*loader)(gd->bd, os_hdr, consdev, cmdline);
  1362. return 1;
  1363. }
  1364. #endif /* CONFIG_BOOTM_NETBSD*/
  1365. #ifdef CONFIG_LYNXKDI
  1366. static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
  1367. bootm_headers_t *images)
  1368. {
  1369. image_header_t *hdr = &images->legacy_hdr_os_copy;
  1370. if (flag != BOOTM_STATE_OS_GO)
  1371. return 0;
  1372. #if defined(CONFIG_FIT)
  1373. if (!images->legacy_hdr_valid) {
  1374. fit_unsupported_reset("Lynx");
  1375. return 1;
  1376. }
  1377. #endif
  1378. lynxkdi_boot((image_header_t *)hdr);
  1379. return 1;
  1380. }
  1381. #endif /* CONFIG_LYNXKDI */
  1382. #ifdef CONFIG_BOOTM_RTEMS
  1383. static int do_bootm_rtems(int flag, int argc, char * const argv[],
  1384. bootm_headers_t *images)
  1385. {
  1386. void (*entry_point)(bd_t *);
  1387. if (flag != BOOTM_STATE_OS_GO)
  1388. return 0;
  1389. #if defined(CONFIG_FIT)
  1390. if (!images->legacy_hdr_valid) {
  1391. fit_unsupported_reset("RTEMS");
  1392. return 1;
  1393. }
  1394. #endif
  1395. entry_point = (void (*)(bd_t *))images->ep;
  1396. printf("## Transferring control to RTEMS (at address %08lx) ...\n",
  1397. (ulong)entry_point);
  1398. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1399. /*
  1400. * RTEMS Parameters:
  1401. * r3: ptr to board info data
  1402. */
  1403. (*entry_point)(gd->bd);
  1404. return 1;
  1405. }
  1406. #endif /* CONFIG_BOOTM_RTEMS */
  1407. #if defined(CONFIG_BOOTM_OSE)
  1408. static int do_bootm_ose(int flag, int argc, char * const argv[],
  1409. bootm_headers_t *images)
  1410. {
  1411. void (*entry_point)(void);
  1412. if (flag != BOOTM_STATE_OS_GO)
  1413. return 0;
  1414. #if defined(CONFIG_FIT)
  1415. if (!images->legacy_hdr_valid) {
  1416. fit_unsupported_reset("OSE");
  1417. return 1;
  1418. }
  1419. #endif
  1420. entry_point = (void (*)(void))images->ep;
  1421. printf("## Transferring control to OSE (at address %08lx) ...\n",
  1422. (ulong)entry_point);
  1423. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1424. /*
  1425. * OSE Parameters:
  1426. * None
  1427. */
  1428. (*entry_point)();
  1429. return 1;
  1430. }
  1431. #endif /* CONFIG_BOOTM_OSE */
  1432. #if defined(CONFIG_BOOTM_PLAN9)
  1433. static int do_bootm_plan9(int flag, int argc, char * const argv[],
  1434. bootm_headers_t *images)
  1435. {
  1436. void (*entry_point)(void);
  1437. char *s;
  1438. if (flag != BOOTM_STATE_OS_GO)
  1439. return 0;
  1440. #if defined(CONFIG_FIT)
  1441. if (!images->legacy_hdr_valid) {
  1442. fit_unsupported_reset("Plan 9");
  1443. return 1;
  1444. }
  1445. #endif
  1446. /* See README.plan9 */
  1447. s = getenv("confaddr");
  1448. if (s != NULL) {
  1449. char *confaddr = (char *)simple_strtoul(s, NULL, 16);
  1450. if (argc > 0) {
  1451. copy_args(confaddr, argc, argv, '\n');
  1452. } else {
  1453. s = getenv("bootargs");
  1454. if (s != NULL)
  1455. strcpy(confaddr, s);
  1456. }
  1457. }
  1458. entry_point = (void (*)(void))images->ep;
  1459. printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
  1460. (ulong)entry_point);
  1461. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1462. /*
  1463. * Plan 9 Parameters:
  1464. * None
  1465. */
  1466. (*entry_point)();
  1467. return 1;
  1468. }
  1469. #endif /* CONFIG_BOOTM_PLAN9 */
  1470. #if defined(CONFIG_BOOTM_VXWORKS) && \
  1471. (defined(CONFIG_PPC) || defined(CONFIG_ARM))
  1472. void do_bootvx_fdt(bootm_headers_t *images)
  1473. {
  1474. #if defined(CONFIG_OF_LIBFDT)
  1475. int ret;
  1476. char *bootline;
  1477. ulong of_size = images->ft_len;
  1478. char **of_flat_tree = &images->ft_addr;
  1479. struct lmb *lmb = &images->lmb;
  1480. if (*of_flat_tree) {
  1481. boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
  1482. ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
  1483. if (ret)
  1484. return;
  1485. ret = fdt_add_subnode(*of_flat_tree, 0, "chosen");
  1486. if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) {
  1487. bootline = getenv("bootargs");
  1488. if (bootline) {
  1489. ret = fdt_find_and_setprop(*of_flat_tree,
  1490. "/chosen", "bootargs",
  1491. bootline,
  1492. strlen(bootline) + 1, 1);
  1493. if (ret < 0) {
  1494. printf("## ERROR: %s : %s\n", __func__,
  1495. fdt_strerror(ret));
  1496. return;
  1497. }
  1498. }
  1499. } else {
  1500. printf("## ERROR: %s : %s\n", __func__,
  1501. fdt_strerror(ret));
  1502. return;
  1503. }
  1504. }
  1505. #endif
  1506. boot_prep_vxworks(images);
  1507. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1508. #if defined(CONFIG_OF_LIBFDT)
  1509. printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...\n",
  1510. (ulong)images->ep, (ulong)*of_flat_tree);
  1511. #else
  1512. printf("## Starting vxWorks at 0x%08lx\n", (ulong)images->ep);
  1513. #endif
  1514. boot_jump_vxworks(images);
  1515. puts("## vxWorks terminated\n");
  1516. }
  1517. static int do_bootm_vxworks(int flag, int argc, char * const argv[],
  1518. bootm_headers_t *images)
  1519. {
  1520. if (flag != BOOTM_STATE_OS_GO)
  1521. return 0;
  1522. #if defined(CONFIG_FIT)
  1523. if (!images->legacy_hdr_valid) {
  1524. fit_unsupported_reset("VxWorks");
  1525. return 1;
  1526. }
  1527. #endif
  1528. do_bootvx_fdt(images);
  1529. return 1;
  1530. }
  1531. #endif
  1532. #if defined(CONFIG_CMD_ELF)
  1533. static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
  1534. bootm_headers_t *images)
  1535. {
  1536. char *local_args[2];
  1537. char str[16];
  1538. if (flag != BOOTM_STATE_OS_GO)
  1539. return 0;
  1540. #if defined(CONFIG_FIT)
  1541. if (!images->legacy_hdr_valid) {
  1542. fit_unsupported_reset("QNX");
  1543. return 1;
  1544. }
  1545. #endif
  1546. sprintf(str, "%lx", images->ep); /* write entry-point into string */
  1547. local_args[0] = argv[0];
  1548. local_args[1] = str; /* and provide it via the arguments */
  1549. do_bootelf(NULL, 0, 2, local_args);
  1550. return 1;
  1551. }
  1552. #endif
  1553. #ifdef CONFIG_INTEGRITY
  1554. static int do_bootm_integrity(int flag, int argc, char * const argv[],
  1555. bootm_headers_t *images)
  1556. {
  1557. void (*entry_point)(void);
  1558. if (flag != BOOTM_STATE_OS_GO)
  1559. return 0;
  1560. #if defined(CONFIG_FIT)
  1561. if (!images->legacy_hdr_valid) {
  1562. fit_unsupported_reset("INTEGRITY");
  1563. return 1;
  1564. }
  1565. #endif
  1566. entry_point = (void (*)(void))images->ep;
  1567. printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
  1568. (ulong)entry_point);
  1569. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1570. /*
  1571. * INTEGRITY Parameters:
  1572. * None
  1573. */
  1574. (*entry_point)();
  1575. return 1;
  1576. }
  1577. #endif
  1578. #ifdef CONFIG_CMD_BOOTZ
  1579. int __weak bootz_setup(ulong image, ulong *start, ulong *end)
  1580. {
  1581. /* Please define bootz_setup() for your platform */
  1582. puts("Your platform's zImage format isn't supported yet!\n");
  1583. return -1;
  1584. }
  1585. /*
  1586. * zImage booting support
  1587. */
  1588. static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
  1589. char * const argv[], bootm_headers_t *images)
  1590. {
  1591. int ret;
  1592. ulong zi_start, zi_end;
  1593. ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
  1594. images, 1);
  1595. /* Setup Linux kernel zImage entry point */
  1596. if (!argc) {
  1597. images->ep = load_addr;
  1598. debug("* kernel: default image load address = 0x%08lx\n",
  1599. load_addr);
  1600. } else {
  1601. images->ep = simple_strtoul(argv[0], NULL, 16);
  1602. debug("* kernel: cmdline image address = 0x%08lx\n",
  1603. images->ep);
  1604. }
  1605. ret = bootz_setup(images->ep, &zi_start, &zi_end);
  1606. if (ret != 0)
  1607. return 1;
  1608. lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
  1609. /*
  1610. * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
  1611. * have a header that provide this informaiton.
  1612. */
  1613. if (bootm_find_ramdisk(flag, argc, argv))
  1614. return 1;
  1615. #if defined(CONFIG_OF_LIBFDT)
  1616. if (bootm_find_fdt(flag, argc, argv))
  1617. return 1;
  1618. #endif
  1619. return 0;
  1620. }
  1621. int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1622. {
  1623. int ret;
  1624. /* Consume 'bootz' */
  1625. argc--; argv++;
  1626. if (bootz_start(cmdtp, flag, argc, argv, &images))
  1627. return 1;
  1628. /*
  1629. * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
  1630. * disable interrupts ourselves
  1631. */
  1632. bootm_disable_interrupts();
  1633. images.os.os = IH_OS_LINUX;
  1634. ret = do_bootm_states(cmdtp, flag, argc, argv,
  1635. BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  1636. BOOTM_STATE_OS_GO,
  1637. &images, 1);
  1638. return ret;
  1639. }
  1640. #ifdef CONFIG_SYS_LONGHELP
  1641. static char bootz_help_text[] =
  1642. "[addr [initrd[:size]] [fdt]]\n"
  1643. " - boot Linux zImage stored in memory\n"
  1644. "\tThe argument 'initrd' is optional and specifies the address\n"
  1645. "\tof the initrd in memory. The optional argument ':size' allows\n"
  1646. "\tspecifying the size of RAW initrd.\n"
  1647. #if defined(CONFIG_OF_LIBFDT)
  1648. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  1649. "\ta third argument is required which is the address of the\n"
  1650. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  1651. "\tuse a '-' for the second argument. If you do not pass a third\n"
  1652. "\ta bd_info struct will be passed instead\n"
  1653. #endif
  1654. "";
  1655. #endif
  1656. U_BOOT_CMD(
  1657. bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
  1658. "boot Linux zImage image from memory", bootz_help_text
  1659. );
  1660. #endif /* CONFIG_CMD_BOOTZ */