cmd_bootm.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962
  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. int rcode = 0;
  956. if (run_command(getenv("bootcmd"), flag) < 0)
  957. rcode = 1;
  958. return rcode;
  959. }
  960. U_BOOT_CMD(
  961. boot, 1, 1, do_bootd,
  962. "boot default, i.e., run 'bootcmd'",
  963. ""
  964. );
  965. /* keep old command name "bootd" for backward compatibility */
  966. U_BOOT_CMD(
  967. bootd, 1, 1, do_bootd,
  968. "boot default, i.e., run 'bootcmd'",
  969. ""
  970. );
  971. #endif
  972. /*******************************************************************/
  973. /* iminfo - print header info for a requested image */
  974. /*******************************************************************/
  975. #if defined(CONFIG_CMD_IMI)
  976. static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  977. {
  978. int arg;
  979. ulong addr;
  980. int rcode = 0;
  981. if (argc < 2) {
  982. return image_info(load_addr);
  983. }
  984. for (arg = 1; arg < argc; ++arg) {
  985. addr = simple_strtoul(argv[arg], NULL, 16);
  986. if (image_info(addr) != 0)
  987. rcode = 1;
  988. }
  989. return rcode;
  990. }
  991. static int image_info(ulong addr)
  992. {
  993. void *hdr = (void *)addr;
  994. printf("\n## Checking Image at %08lx ...\n", addr);
  995. switch (genimg_get_format(hdr)) {
  996. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  997. case IMAGE_FORMAT_LEGACY:
  998. puts(" Legacy image found\n");
  999. if (!image_check_magic(hdr)) {
  1000. puts(" Bad Magic Number\n");
  1001. return 1;
  1002. }
  1003. if (!image_check_hcrc(hdr)) {
  1004. puts(" Bad Header Checksum\n");
  1005. return 1;
  1006. }
  1007. image_print_contents(hdr);
  1008. puts(" Verifying Checksum ... ");
  1009. if (!image_check_dcrc(hdr)) {
  1010. puts(" Bad Data CRC\n");
  1011. return 1;
  1012. }
  1013. puts("OK\n");
  1014. return 0;
  1015. #endif
  1016. #if defined(CONFIG_FIT)
  1017. case IMAGE_FORMAT_FIT:
  1018. puts(" FIT image found\n");
  1019. if (!fit_check_format(hdr)) {
  1020. puts("Bad FIT image format!\n");
  1021. return 1;
  1022. }
  1023. fit_print_contents(hdr);
  1024. if (!fit_all_image_verify(hdr)) {
  1025. puts("Bad hash in FIT image!\n");
  1026. return 1;
  1027. }
  1028. return 0;
  1029. #endif
  1030. default:
  1031. puts("Unknown image format!\n");
  1032. break;
  1033. }
  1034. return 1;
  1035. }
  1036. U_BOOT_CMD(
  1037. iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
  1038. "print header information for application image",
  1039. "addr [addr ...]\n"
  1040. " - print header information for application image starting at\n"
  1041. " address 'addr' in memory; this includes verification of the\n"
  1042. " image contents (magic number, header and payload checksums)"
  1043. );
  1044. #endif
  1045. /*******************************************************************/
  1046. /* imls - list all images found in flash */
  1047. /*******************************************************************/
  1048. #if defined(CONFIG_CMD_IMLS)
  1049. static int do_imls_nor(void)
  1050. {
  1051. flash_info_t *info;
  1052. int i, j;
  1053. void *hdr;
  1054. for (i = 0, info = &flash_info[0];
  1055. i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
  1056. if (info->flash_id == FLASH_UNKNOWN)
  1057. goto next_bank;
  1058. for (j = 0; j < info->sector_count; ++j) {
  1059. hdr = (void *)info->start[j];
  1060. if (!hdr)
  1061. goto next_sector;
  1062. switch (genimg_get_format(hdr)) {
  1063. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  1064. case IMAGE_FORMAT_LEGACY:
  1065. if (!image_check_hcrc(hdr))
  1066. goto next_sector;
  1067. printf("Legacy Image at %08lX:\n", (ulong)hdr);
  1068. image_print_contents(hdr);
  1069. puts(" Verifying Checksum ... ");
  1070. if (!image_check_dcrc(hdr)) {
  1071. puts("Bad Data CRC\n");
  1072. } else {
  1073. puts("OK\n");
  1074. }
  1075. break;
  1076. #endif
  1077. #if defined(CONFIG_FIT)
  1078. case IMAGE_FORMAT_FIT:
  1079. if (!fit_check_format(hdr))
  1080. goto next_sector;
  1081. printf("FIT Image at %08lX:\n", (ulong)hdr);
  1082. fit_print_contents(hdr);
  1083. break;
  1084. #endif
  1085. default:
  1086. goto next_sector;
  1087. }
  1088. next_sector: ;
  1089. }
  1090. next_bank: ;
  1091. }
  1092. return 0;
  1093. }
  1094. #endif
  1095. #if defined(CONFIG_CMD_IMLS_NAND)
  1096. static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
  1097. size_t len)
  1098. {
  1099. void *imgdata;
  1100. int ret;
  1101. imgdata = malloc(len);
  1102. if (!imgdata) {
  1103. printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
  1104. nand_dev, off);
  1105. printf(" Low memory(cannot allocate memory for image)\n");
  1106. return -ENOMEM;
  1107. }
  1108. ret = nand_read_skip_bad(nand, off, &len,
  1109. imgdata);
  1110. if (ret < 0 && ret != -EUCLEAN) {
  1111. free(imgdata);
  1112. return ret;
  1113. }
  1114. if (!image_check_hcrc(imgdata)) {
  1115. free(imgdata);
  1116. return 0;
  1117. }
  1118. printf("Legacy Image at NAND device %d offset %08llX:\n",
  1119. nand_dev, off);
  1120. image_print_contents(imgdata);
  1121. puts(" Verifying Checksum ... ");
  1122. if (!image_check_dcrc(imgdata))
  1123. puts("Bad Data CRC\n");
  1124. else
  1125. puts("OK\n");
  1126. free(imgdata);
  1127. return 0;
  1128. }
  1129. static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
  1130. size_t len)
  1131. {
  1132. void *imgdata;
  1133. int ret;
  1134. imgdata = malloc(len);
  1135. if (!imgdata) {
  1136. printf("May be a FIT Image at NAND device %d offset %08llX:\n",
  1137. nand_dev, off);
  1138. printf(" Low memory(cannot allocate memory for image)\n");
  1139. return -ENOMEM;
  1140. }
  1141. ret = nand_read_skip_bad(nand, off, &len,
  1142. imgdata);
  1143. if (ret < 0 && ret != -EUCLEAN) {
  1144. free(imgdata);
  1145. return ret;
  1146. }
  1147. if (!fit_check_format(imgdata)) {
  1148. free(imgdata);
  1149. return 0;
  1150. }
  1151. printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
  1152. fit_print_contents(imgdata);
  1153. free(imgdata);
  1154. return 0;
  1155. }
  1156. static int do_imls_nand(void)
  1157. {
  1158. nand_info_t *nand;
  1159. int nand_dev = nand_curr_device;
  1160. size_t len;
  1161. loff_t off;
  1162. u32 buffer[16];
  1163. if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
  1164. puts("\nNo NAND devices available\n");
  1165. return -ENODEV;
  1166. }
  1167. printf("\n");
  1168. for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
  1169. nand = &nand_info[nand_dev];
  1170. if (!nand->name || !nand->size)
  1171. continue;
  1172. for (off = 0; off < nand->size; off += nand->erasesize) {
  1173. const image_header_t *header;
  1174. int ret;
  1175. if (nand_block_isbad(nand, off))
  1176. continue;
  1177. len = sizeof(buffer);
  1178. ret = nand_read(nand, off, &len, (u8 *)buffer);
  1179. if (ret < 0 && ret != -EUCLEAN) {
  1180. printf("NAND read error %d at offset %08llX\n",
  1181. ret, off);
  1182. continue;
  1183. }
  1184. switch (genimg_get_format(buffer)) {
  1185. #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  1186. case IMAGE_FORMAT_LEGACY:
  1187. header = (const image_header_t *)buffer;
  1188. len = image_get_image_size(header);
  1189. nand_imls_legacyimage(nand, nand_dev, off, len);
  1190. break;
  1191. #endif
  1192. #if defined(CONFIG_FIT)
  1193. case IMAGE_FORMAT_FIT:
  1194. len = fit_get_size(buffer);
  1195. nand_imls_fitimage(nand, nand_dev, off, len);
  1196. break;
  1197. #endif
  1198. }
  1199. }
  1200. }
  1201. return 0;
  1202. }
  1203. #endif
  1204. #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
  1205. static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1206. {
  1207. int ret_nor = 0, ret_nand = 0;
  1208. #if defined(CONFIG_CMD_IMLS)
  1209. ret_nor = do_imls_nor();
  1210. #endif
  1211. #if defined(CONFIG_CMD_IMLS_NAND)
  1212. ret_nand = do_imls_nand();
  1213. #endif
  1214. if (ret_nor)
  1215. return ret_nor;
  1216. if (ret_nand)
  1217. return ret_nand;
  1218. return (0);
  1219. }
  1220. U_BOOT_CMD(
  1221. imls, 1, 1, do_imls,
  1222. "list all images found in flash",
  1223. "\n"
  1224. " - Prints information about all images found at sector/block\n"
  1225. " boundaries in nor/nand flash."
  1226. );
  1227. #endif
  1228. /*******************************************************************/
  1229. /* helper routines */
  1230. /*******************************************************************/
  1231. #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
  1232. #define CONSOLE_ARG "console="
  1233. #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
  1234. static void fixup_silent_linux(void)
  1235. {
  1236. char *buf;
  1237. const char *env_val;
  1238. char *cmdline = getenv("bootargs");
  1239. int want_silent;
  1240. /*
  1241. * Only fix cmdline when requested. The environment variable can be:
  1242. *
  1243. * no - we never fixup
  1244. * yes - we always fixup
  1245. * unset - we rely on the console silent flag
  1246. */
  1247. want_silent = getenv_yesno("silent_linux");
  1248. if (want_silent == 0)
  1249. return;
  1250. else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT))
  1251. return;
  1252. debug("before silent fix-up: %s\n", cmdline);
  1253. if (cmdline && (cmdline[0] != '\0')) {
  1254. char *start = strstr(cmdline, CONSOLE_ARG);
  1255. /* Allocate space for maximum possible new command line */
  1256. buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
  1257. if (!buf) {
  1258. debug("%s: out of memory\n", __func__);
  1259. return;
  1260. }
  1261. if (start) {
  1262. char *end = strchr(start, ' ');
  1263. int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN;
  1264. strncpy(buf, cmdline, num_start_bytes);
  1265. if (end)
  1266. strcpy(buf + num_start_bytes, end);
  1267. else
  1268. buf[num_start_bytes] = '\0';
  1269. } else {
  1270. sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
  1271. }
  1272. env_val = buf;
  1273. } else {
  1274. buf = NULL;
  1275. env_val = CONSOLE_ARG;
  1276. }
  1277. setenv("bootargs", env_val);
  1278. debug("after silent fix-up: %s\n", env_val);
  1279. free(buf);
  1280. }
  1281. #endif /* CONFIG_SILENT_CONSOLE */
  1282. #if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9)
  1283. static void copy_args(char *dest, int argc, char * const argv[], char delim)
  1284. {
  1285. int i;
  1286. for (i = 0; i < argc; i++) {
  1287. if (i > 0)
  1288. *dest++ = delim;
  1289. strcpy(dest, argv[i]);
  1290. dest += strlen(argv[i]);
  1291. }
  1292. }
  1293. #endif
  1294. /*******************************************************************/
  1295. /* OS booting routines */
  1296. /*******************************************************************/
  1297. #ifdef CONFIG_BOOTM_NETBSD
  1298. static int do_bootm_netbsd(int flag, int argc, char * const argv[],
  1299. bootm_headers_t *images)
  1300. {
  1301. void (*loader)(bd_t *, image_header_t *, char *, char *);
  1302. image_header_t *os_hdr, *hdr;
  1303. ulong kernel_data, kernel_len;
  1304. char *consdev;
  1305. char *cmdline;
  1306. if (flag != BOOTM_STATE_OS_GO)
  1307. return 0;
  1308. #if defined(CONFIG_FIT)
  1309. if (!images->legacy_hdr_valid) {
  1310. fit_unsupported_reset("NetBSD");
  1311. return 1;
  1312. }
  1313. #endif
  1314. hdr = images->legacy_hdr_os;
  1315. /*
  1316. * Booting a (NetBSD) kernel image
  1317. *
  1318. * This process is pretty similar to a standalone application:
  1319. * The (first part of an multi-) image must be a stage-2 loader,
  1320. * which in turn is responsible for loading & invoking the actual
  1321. * kernel. The only differences are the parameters being passed:
  1322. * besides the board info strucure, the loader expects a command
  1323. * line, the name of the console device, and (optionally) the
  1324. * address of the original image header.
  1325. */
  1326. os_hdr = NULL;
  1327. if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
  1328. image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
  1329. if (kernel_len)
  1330. os_hdr = hdr;
  1331. }
  1332. consdev = "";
  1333. #if defined(CONFIG_8xx_CONS_SMC1)
  1334. consdev = "smc1";
  1335. #elif defined(CONFIG_8xx_CONS_SMC2)
  1336. consdev = "smc2";
  1337. #elif defined(CONFIG_8xx_CONS_SCC2)
  1338. consdev = "scc2";
  1339. #elif defined(CONFIG_8xx_CONS_SCC3)
  1340. consdev = "scc3";
  1341. #endif
  1342. if (argc > 0) {
  1343. ulong len;
  1344. int i;
  1345. for (i = 0, len = 0; i < argc; i += 1)
  1346. len += strlen(argv[i]) + 1;
  1347. cmdline = malloc(len);
  1348. copy_args(cmdline, argc, argv, ' ');
  1349. } else if ((cmdline = getenv("bootargs")) == NULL) {
  1350. cmdline = "";
  1351. }
  1352. loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
  1353. printf("## Transferring control to NetBSD stage-2 loader "
  1354. "(at address %08lx) ...\n",
  1355. (ulong)loader);
  1356. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1357. /*
  1358. * NetBSD Stage-2 Loader Parameters:
  1359. * arg[0]: pointer to board info data
  1360. * arg[1]: image load address
  1361. * arg[2]: char pointer to the console device to use
  1362. * arg[3]: char pointer to the boot arguments
  1363. */
  1364. (*loader)(gd->bd, os_hdr, consdev, cmdline);
  1365. return 1;
  1366. }
  1367. #endif /* CONFIG_BOOTM_NETBSD*/
  1368. #ifdef CONFIG_LYNXKDI
  1369. static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
  1370. bootm_headers_t *images)
  1371. {
  1372. image_header_t *hdr = &images->legacy_hdr_os_copy;
  1373. if (flag != BOOTM_STATE_OS_GO)
  1374. return 0;
  1375. #if defined(CONFIG_FIT)
  1376. if (!images->legacy_hdr_valid) {
  1377. fit_unsupported_reset("Lynx");
  1378. return 1;
  1379. }
  1380. #endif
  1381. lynxkdi_boot((image_header_t *)hdr);
  1382. return 1;
  1383. }
  1384. #endif /* CONFIG_LYNXKDI */
  1385. #ifdef CONFIG_BOOTM_RTEMS
  1386. static int do_bootm_rtems(int flag, int argc, char * const argv[],
  1387. bootm_headers_t *images)
  1388. {
  1389. void (*entry_point)(bd_t *);
  1390. if (flag != BOOTM_STATE_OS_GO)
  1391. return 0;
  1392. #if defined(CONFIG_FIT)
  1393. if (!images->legacy_hdr_valid) {
  1394. fit_unsupported_reset("RTEMS");
  1395. return 1;
  1396. }
  1397. #endif
  1398. entry_point = (void (*)(bd_t *))images->ep;
  1399. printf("## Transferring control to RTEMS (at address %08lx) ...\n",
  1400. (ulong)entry_point);
  1401. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1402. /*
  1403. * RTEMS Parameters:
  1404. * r3: ptr to board info data
  1405. */
  1406. (*entry_point)(gd->bd);
  1407. return 1;
  1408. }
  1409. #endif /* CONFIG_BOOTM_RTEMS */
  1410. #if defined(CONFIG_BOOTM_OSE)
  1411. static int do_bootm_ose(int flag, int argc, char * const argv[],
  1412. bootm_headers_t *images)
  1413. {
  1414. void (*entry_point)(void);
  1415. if (flag != BOOTM_STATE_OS_GO)
  1416. return 0;
  1417. #if defined(CONFIG_FIT)
  1418. if (!images->legacy_hdr_valid) {
  1419. fit_unsupported_reset("OSE");
  1420. return 1;
  1421. }
  1422. #endif
  1423. entry_point = (void (*)(void))images->ep;
  1424. printf("## Transferring control to OSE (at address %08lx) ...\n",
  1425. (ulong)entry_point);
  1426. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1427. /*
  1428. * OSE Parameters:
  1429. * None
  1430. */
  1431. (*entry_point)();
  1432. return 1;
  1433. }
  1434. #endif /* CONFIG_BOOTM_OSE */
  1435. #if defined(CONFIG_BOOTM_PLAN9)
  1436. static int do_bootm_plan9(int flag, int argc, char * const argv[],
  1437. bootm_headers_t *images)
  1438. {
  1439. void (*entry_point)(void);
  1440. char *s;
  1441. if (flag != BOOTM_STATE_OS_GO)
  1442. return 0;
  1443. #if defined(CONFIG_FIT)
  1444. if (!images->legacy_hdr_valid) {
  1445. fit_unsupported_reset("Plan 9");
  1446. return 1;
  1447. }
  1448. #endif
  1449. /* See README.plan9 */
  1450. s = getenv("confaddr");
  1451. if (s != NULL) {
  1452. char *confaddr = (char *)simple_strtoul(s, NULL, 16);
  1453. if (argc > 0) {
  1454. copy_args(confaddr, argc, argv, '\n');
  1455. } else {
  1456. s = getenv("bootargs");
  1457. if (s != NULL)
  1458. strcpy(confaddr, s);
  1459. }
  1460. }
  1461. entry_point = (void (*)(void))images->ep;
  1462. printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
  1463. (ulong)entry_point);
  1464. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1465. /*
  1466. * Plan 9 Parameters:
  1467. * None
  1468. */
  1469. (*entry_point)();
  1470. return 1;
  1471. }
  1472. #endif /* CONFIG_BOOTM_PLAN9 */
  1473. #if defined(CONFIG_BOOTM_VXWORKS) && \
  1474. (defined(CONFIG_PPC) || defined(CONFIG_ARM))
  1475. void do_bootvx_fdt(bootm_headers_t *images)
  1476. {
  1477. #if defined(CONFIG_OF_LIBFDT)
  1478. int ret;
  1479. char *bootline;
  1480. ulong of_size = images->ft_len;
  1481. char **of_flat_tree = &images->ft_addr;
  1482. struct lmb *lmb = &images->lmb;
  1483. if (*of_flat_tree) {
  1484. boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
  1485. ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
  1486. if (ret)
  1487. return;
  1488. ret = fdt_add_subnode(*of_flat_tree, 0, "chosen");
  1489. if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) {
  1490. bootline = getenv("bootargs");
  1491. if (bootline) {
  1492. ret = fdt_find_and_setprop(*of_flat_tree,
  1493. "/chosen", "bootargs",
  1494. bootline,
  1495. strlen(bootline) + 1, 1);
  1496. if (ret < 0) {
  1497. printf("## ERROR: %s : %s\n", __func__,
  1498. fdt_strerror(ret));
  1499. return;
  1500. }
  1501. }
  1502. } else {
  1503. printf("## ERROR: %s : %s\n", __func__,
  1504. fdt_strerror(ret));
  1505. return;
  1506. }
  1507. }
  1508. #endif
  1509. boot_prep_vxworks(images);
  1510. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1511. #if defined(CONFIG_OF_LIBFDT)
  1512. printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...\n",
  1513. (ulong)images->ep, (ulong)*of_flat_tree);
  1514. #else
  1515. printf("## Starting vxWorks at 0x%08lx\n", (ulong)images->ep);
  1516. #endif
  1517. boot_jump_vxworks(images);
  1518. puts("## vxWorks terminated\n");
  1519. }
  1520. static int do_bootm_vxworks(int flag, int argc, char * const argv[],
  1521. bootm_headers_t *images)
  1522. {
  1523. if (flag != BOOTM_STATE_OS_GO)
  1524. return 0;
  1525. #if defined(CONFIG_FIT)
  1526. if (!images->legacy_hdr_valid) {
  1527. fit_unsupported_reset("VxWorks");
  1528. return 1;
  1529. }
  1530. #endif
  1531. do_bootvx_fdt(images);
  1532. return 1;
  1533. }
  1534. #endif
  1535. #if defined(CONFIG_CMD_ELF)
  1536. static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
  1537. bootm_headers_t *images)
  1538. {
  1539. char *local_args[2];
  1540. char str[16];
  1541. if (flag != BOOTM_STATE_OS_GO)
  1542. return 0;
  1543. #if defined(CONFIG_FIT)
  1544. if (!images->legacy_hdr_valid) {
  1545. fit_unsupported_reset("QNX");
  1546. return 1;
  1547. }
  1548. #endif
  1549. sprintf(str, "%lx", images->ep); /* write entry-point into string */
  1550. local_args[0] = argv[0];
  1551. local_args[1] = str; /* and provide it via the arguments */
  1552. do_bootelf(NULL, 0, 2, local_args);
  1553. return 1;
  1554. }
  1555. #endif
  1556. #ifdef CONFIG_INTEGRITY
  1557. static int do_bootm_integrity(int flag, int argc, char * const argv[],
  1558. bootm_headers_t *images)
  1559. {
  1560. void (*entry_point)(void);
  1561. if (flag != BOOTM_STATE_OS_GO)
  1562. return 0;
  1563. #if defined(CONFIG_FIT)
  1564. if (!images->legacy_hdr_valid) {
  1565. fit_unsupported_reset("INTEGRITY");
  1566. return 1;
  1567. }
  1568. #endif
  1569. entry_point = (void (*)(void))images->ep;
  1570. printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
  1571. (ulong)entry_point);
  1572. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1573. /*
  1574. * INTEGRITY Parameters:
  1575. * None
  1576. */
  1577. (*entry_point)();
  1578. return 1;
  1579. }
  1580. #endif
  1581. #ifdef CONFIG_CMD_BOOTZ
  1582. int __weak bootz_setup(ulong image, ulong *start, ulong *end)
  1583. {
  1584. /* Please define bootz_setup() for your platform */
  1585. puts("Your platform's zImage format isn't supported yet!\n");
  1586. return -1;
  1587. }
  1588. /*
  1589. * zImage booting support
  1590. */
  1591. static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
  1592. char * const argv[], bootm_headers_t *images)
  1593. {
  1594. int ret;
  1595. ulong zi_start, zi_end;
  1596. ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
  1597. images, 1);
  1598. /* Setup Linux kernel zImage entry point */
  1599. if (!argc) {
  1600. images->ep = load_addr;
  1601. debug("* kernel: default image load address = 0x%08lx\n",
  1602. load_addr);
  1603. } else {
  1604. images->ep = simple_strtoul(argv[0], NULL, 16);
  1605. debug("* kernel: cmdline image address = 0x%08lx\n",
  1606. images->ep);
  1607. }
  1608. ret = bootz_setup(images->ep, &zi_start, &zi_end);
  1609. if (ret != 0)
  1610. return 1;
  1611. lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
  1612. /*
  1613. * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
  1614. * have a header that provide this informaiton.
  1615. */
  1616. if (bootm_find_ramdisk(flag, argc, argv))
  1617. return 1;
  1618. #if defined(CONFIG_OF_LIBFDT)
  1619. if (bootm_find_fdt(flag, argc, argv))
  1620. return 1;
  1621. #endif
  1622. return 0;
  1623. }
  1624. int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1625. {
  1626. int ret;
  1627. /* Consume 'bootz' */
  1628. argc--; argv++;
  1629. if (bootz_start(cmdtp, flag, argc, argv, &images))
  1630. return 1;
  1631. /*
  1632. * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
  1633. * disable interrupts ourselves
  1634. */
  1635. bootm_disable_interrupts();
  1636. images.os.os = IH_OS_LINUX;
  1637. ret = do_bootm_states(cmdtp, flag, argc, argv,
  1638. BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  1639. BOOTM_STATE_OS_GO,
  1640. &images, 1);
  1641. return ret;
  1642. }
  1643. #ifdef CONFIG_SYS_LONGHELP
  1644. static char bootz_help_text[] =
  1645. "[addr [initrd[:size]] [fdt]]\n"
  1646. " - boot Linux zImage stored in memory\n"
  1647. "\tThe argument 'initrd' is optional and specifies the address\n"
  1648. "\tof the initrd in memory. The optional argument ':size' allows\n"
  1649. "\tspecifying the size of RAW initrd.\n"
  1650. #if defined(CONFIG_OF_LIBFDT)
  1651. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  1652. "\ta third argument is required which is the address of the\n"
  1653. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  1654. "\tuse a '-' for the second argument. If you do not pass a third\n"
  1655. "\ta bd_info struct will be passed instead\n"
  1656. #endif
  1657. "";
  1658. #endif
  1659. U_BOOT_CMD(
  1660. bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
  1661. "boot Linux zImage image from memory", bootz_help_text
  1662. );
  1663. #endif /* CONFIG_CMD_BOOTZ */