cmd_bootm.c 47 KB

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