cmd_bootm.c 48 KB

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