cmd_bootm.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  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, &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. #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
  293. int ret;
  294. #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
  295. const char *type_name = genimg_get_type_name(os.type);
  296. switch (comp) {
  297. case IH_COMP_NONE:
  298. if (load == blob_start || load == image_start) {
  299. printf(" XIP %s ... ", type_name);
  300. no_overlap = 1;
  301. } else {
  302. printf(" Loading %s ... ", type_name);
  303. memmove_wd((void *)load, (void *)image_start,
  304. image_len, CHUNKSZ);
  305. }
  306. *load_end = load + image_len;
  307. puts("OK\n");
  308. break;
  309. #ifdef CONFIG_GZIP
  310. case IH_COMP_GZIP:
  311. printf(" Uncompressing %s ... ", type_name);
  312. if (gunzip((void *)load, unc_len,
  313. (uchar *)image_start, &image_len) != 0) {
  314. puts("GUNZIP: uncompress, out-of-mem or overwrite "
  315. "error - must RESET board to recover\n");
  316. if (boot_progress)
  317. bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
  318. return BOOTM_ERR_RESET;
  319. }
  320. *load_end = load + image_len;
  321. break;
  322. #endif /* CONFIG_GZIP */
  323. #ifdef CONFIG_BZIP2
  324. case IH_COMP_BZIP2:
  325. printf(" Uncompressing %s ... ", type_name);
  326. /*
  327. * If we've got less than 4 MB of malloc() space,
  328. * use slower decompression algorithm which requires
  329. * at most 2300 KB of memory.
  330. */
  331. int i = BZ2_bzBuffToBuffDecompress((char *)load,
  332. &unc_len, (char *)image_start, image_len,
  333. CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
  334. if (i != BZ_OK) {
  335. printf("BUNZIP2: uncompress or overwrite error %d "
  336. "- must RESET board to recover\n", i);
  337. if (boot_progress)
  338. bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
  339. return BOOTM_ERR_RESET;
  340. }
  341. *load_end = load + unc_len;
  342. break;
  343. #endif /* CONFIG_BZIP2 */
  344. #ifdef CONFIG_LZMA
  345. case IH_COMP_LZMA: {
  346. SizeT lzma_len = unc_len;
  347. printf(" Uncompressing %s ... ", type_name);
  348. ret = lzmaBuffToBuffDecompress(
  349. (unsigned char *)load, &lzma_len,
  350. (unsigned char *)image_start, 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((const unsigned char *)image_start,
  366. image_len, (unsigned char *)load,
  367. &unc_len);
  368. if (ret != LZO_E_OK) {
  369. printf("LZO: uncompress or overwrite error %d "
  370. "- must RESET board to recover\n", ret);
  371. if (boot_progress)
  372. bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
  373. return BOOTM_ERR_RESET;
  374. }
  375. *load_end = load + unc_len;
  376. break;
  377. #endif /* CONFIG_LZO */
  378. default:
  379. printf("Unimplemented compression type %d\n", comp);
  380. return BOOTM_ERR_UNIMPLEMENTED;
  381. }
  382. flush_cache(load, (*load_end - load) * sizeof(ulong));
  383. puts("OK\n");
  384. debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
  385. bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
  386. if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
  387. debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
  388. blob_start, blob_end);
  389. debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
  390. *load_end);
  391. return BOOTM_ERR_OVERLAP;
  392. }
  393. return 0;
  394. }
  395. static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
  396. {
  397. char *s;
  398. int (*appl)(int, char * const []);
  399. /* Don't start if "autostart" is set to "no" */
  400. if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
  401. setenv_hex("filesize", images.os.image_len);
  402. return 0;
  403. }
  404. appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
  405. (*appl)(argc-1, &argv[1]);
  406. return 0;
  407. }
  408. /* we overload the cmd field with our state machine info instead of a
  409. * function pointer */
  410. static cmd_tbl_t cmd_bootm_sub[] = {
  411. U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
  412. U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
  413. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  414. U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
  415. #endif
  416. #ifdef CONFIG_OF_LIBFDT
  417. U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
  418. #endif
  419. U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
  420. U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
  421. U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
  422. U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
  423. };
  424. static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
  425. char * const argv[])
  426. {
  427. int ret = 0;
  428. long state;
  429. cmd_tbl_t *c;
  430. boot_os_fn *boot_fn;
  431. c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
  432. if (c) {
  433. state = (long)c->cmd;
  434. /* treat start special since it resets the state machine */
  435. if (state == BOOTM_STATE_START) {
  436. argc--;
  437. argv++;
  438. return bootm_start(cmdtp, flag, argc, argv);
  439. }
  440. } else {
  441. /* Unrecognized command */
  442. return CMD_RET_USAGE;
  443. }
  444. if (images.state < BOOTM_STATE_START ||
  445. images.state >= state) {
  446. printf("Trying to execute a command out of order\n");
  447. return CMD_RET_USAGE;
  448. }
  449. images.state |= state;
  450. boot_fn = boot_os[images.os.os];
  451. switch (state) {
  452. ulong load_end;
  453. case BOOTM_STATE_START:
  454. /* should never occur */
  455. break;
  456. case BOOTM_STATE_LOADOS:
  457. ret = bootm_load_os(images.os, &load_end, 0);
  458. if (ret)
  459. return ret;
  460. lmb_reserve(&images.lmb, images.os.load,
  461. (load_end - images.os.load));
  462. break;
  463. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  464. case BOOTM_STATE_RAMDISK:
  465. {
  466. ulong rd_len = images.rd_end - images.rd_start;
  467. ret = boot_ramdisk_high(&images.lmb, images.rd_start,
  468. rd_len, &images.initrd_start, &images.initrd_end);
  469. if (ret)
  470. return ret;
  471. setenv_hex("initrd_start", images.initrd_start);
  472. setenv_hex("initrd_end", images.initrd_end);
  473. }
  474. break;
  475. #endif
  476. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
  477. case BOOTM_STATE_FDT:
  478. {
  479. boot_fdt_add_mem_rsv_regions(&images.lmb,
  480. images.ft_addr);
  481. ret = boot_relocate_fdt(&images.lmb,
  482. &images.ft_addr, &images.ft_len);
  483. break;
  484. }
  485. #endif
  486. case BOOTM_STATE_OS_CMDLINE:
  487. ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
  488. if (ret)
  489. printf("cmdline subcommand not supported\n");
  490. break;
  491. case BOOTM_STATE_OS_BD_T:
  492. ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
  493. if (ret)
  494. printf("bdt subcommand not supported\n");
  495. break;
  496. case BOOTM_STATE_OS_PREP:
  497. ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
  498. if (ret)
  499. printf("prep subcommand not supported\n");
  500. break;
  501. case BOOTM_STATE_OS_GO:
  502. disable_interrupts();
  503. #ifdef CONFIG_NETCONSOLE
  504. /*
  505. * Stop the ethernet stack if NetConsole could have
  506. * left it up
  507. */
  508. eth_halt();
  509. #endif
  510. arch_preboot_os();
  511. boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
  512. break;
  513. }
  514. return ret;
  515. }
  516. /*******************************************************************/
  517. /* bootm - boot application image from image in memory */
  518. /*******************************************************************/
  519. int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  520. {
  521. ulong iflag;
  522. ulong load_end = 0;
  523. int ret;
  524. boot_os_fn *boot_fn;
  525. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  526. static int relocated = 0;
  527. if (!relocated) {
  528. int i;
  529. /* relocate boot function table */
  530. for (i = 0; i < ARRAY_SIZE(boot_os); i++)
  531. if (boot_os[i] != NULL)
  532. boot_os[i] += gd->reloc_off;
  533. /* relocate names of sub-command table */
  534. for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
  535. cmd_bootm_sub[i].name += gd->reloc_off;
  536. relocated = 1;
  537. }
  538. #endif
  539. /* determine if we have a sub command */
  540. if (argc > 1) {
  541. char *endp;
  542. simple_strtoul(argv[1], &endp, 16);
  543. /* endp pointing to NULL means that argv[1] was just a
  544. * valid number, pass it along to the normal bootm processing
  545. *
  546. * If endp is ':' or '#' assume a FIT identifier so pass
  547. * along for normal processing.
  548. *
  549. * Right now we assume the first arg should never be '-'
  550. */
  551. if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
  552. return do_bootm_subcommand(cmdtp, flag, argc, argv);
  553. }
  554. if (bootm_start(cmdtp, flag, argc, argv))
  555. return 1;
  556. /*
  557. * We have reached the point of no return: we are going to
  558. * overwrite all exception vector code, so we cannot easily
  559. * recover from any failures any more...
  560. */
  561. iflag = disable_interrupts();
  562. #ifdef CONFIG_NETCONSOLE
  563. /* Stop the ethernet stack if NetConsole could have left it up */
  564. eth_halt();
  565. #endif
  566. #if defined(CONFIG_CMD_USB)
  567. /*
  568. * turn off USB to prevent the host controller from writing to the
  569. * SDRAM while Linux is booting. This could happen (at least for OHCI
  570. * controller), because the HCCA (Host Controller Communication Area)
  571. * lies within the SDRAM and the host controller writes continously to
  572. * this area (as busmaster!). The HccaFrameNumber is for example
  573. * updated every 1 ms within the HCCA structure in SDRAM! For more
  574. * details see the OpenHCI specification.
  575. */
  576. usb_stop();
  577. #endif
  578. ret = bootm_load_os(images.os, &load_end, 1);
  579. if (ret < 0) {
  580. if (ret == BOOTM_ERR_RESET)
  581. do_reset(cmdtp, flag, argc, argv);
  582. if (ret == BOOTM_ERR_OVERLAP) {
  583. if (images.legacy_hdr_valid) {
  584. image_header_t *hdr;
  585. hdr = &images.legacy_hdr_os_copy;
  586. if (image_get_type(hdr) == IH_TYPE_MULTI)
  587. puts("WARNING: legacy format multi "
  588. "component image "
  589. "overwritten\n");
  590. } else {
  591. puts("ERROR: new format image overwritten - "
  592. "must RESET the board to recover\n");
  593. bootstage_error(BOOTSTAGE_ID_OVERWRITTEN);
  594. do_reset(cmdtp, flag, argc, argv);
  595. }
  596. }
  597. if (ret == BOOTM_ERR_UNIMPLEMENTED) {
  598. if (iflag)
  599. enable_interrupts();
  600. bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
  601. return 1;
  602. }
  603. }
  604. lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
  605. if (images.os.type == IH_TYPE_STANDALONE) {
  606. if (iflag)
  607. enable_interrupts();
  608. /* This may return when 'autostart' is 'no' */
  609. bootm_start_standalone(iflag, argc, argv);
  610. return 0;
  611. }
  612. bootstage_mark(BOOTSTAGE_ID_CHECK_BOOT_OS);
  613. #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
  614. if (images.os.os == IH_OS_LINUX)
  615. fixup_silent_linux();
  616. #endif
  617. boot_fn = boot_os[images.os.os];
  618. if (boot_fn == NULL) {
  619. if (iflag)
  620. enable_interrupts();
  621. printf("ERROR: booting os '%s' (%d) is not supported\n",
  622. genimg_get_os_name(images.os.os), images.os.os);
  623. bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS);
  624. return 1;
  625. }
  626. arch_preboot_os();
  627. boot_fn(0, argc, argv, &images);
  628. bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
  629. #ifdef DEBUG
  630. puts("\n## Control returned to monitor - resetting...\n");
  631. #endif
  632. do_reset(cmdtp, flag, argc, argv);
  633. return 1;
  634. }
  635. int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
  636. {
  637. const char *ep = getenv("autostart");
  638. if (ep && !strcmp(ep, "yes")) {
  639. char *local_args[2];
  640. local_args[0] = (char *)cmd;
  641. local_args[1] = NULL;
  642. printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
  643. return do_bootm(cmdtp, 0, 1, local_args);
  644. }
  645. return 0;
  646. }
  647. /**
  648. * image_get_kernel - verify legacy format kernel image
  649. * @img_addr: in RAM address of the legacy format image to be verified
  650. * @verify: data CRC verification flag
  651. *
  652. * image_get_kernel() verifies legacy image integrity and returns pointer to
  653. * legacy image header if image verification was completed successfully.
  654. *
  655. * returns:
  656. * pointer to a legacy image header if valid image was found
  657. * otherwise return NULL
  658. */
  659. static image_header_t *image_get_kernel(ulong img_addr, int verify)
  660. {
  661. image_header_t *hdr = (image_header_t *)img_addr;
  662. if (!image_check_magic(hdr)) {
  663. puts("Bad Magic Number\n");
  664. bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC);
  665. return NULL;
  666. }
  667. bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER);
  668. if (!image_check_hcrc(hdr)) {
  669. puts("Bad Header Checksum\n");
  670. bootstage_error(BOOTSTAGE_ID_CHECK_HEADER);
  671. return NULL;
  672. }
  673. bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM);
  674. image_print_contents(hdr);
  675. if (verify) {
  676. puts(" Verifying Checksum ... ");
  677. if (!image_check_dcrc(hdr)) {
  678. printf("Bad Data CRC\n");
  679. bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM);
  680. return NULL;
  681. }
  682. puts("OK\n");
  683. }
  684. bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH);
  685. if (!image_check_target_arch(hdr)) {
  686. printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
  687. bootstage_error(BOOTSTAGE_ID_CHECK_ARCH);
  688. return NULL;
  689. }
  690. return hdr;
  691. }
  692. /**
  693. * fit_check_kernel - verify FIT format kernel subimage
  694. * @fit_hdr: pointer to the FIT image header
  695. * os_noffset: kernel subimage node offset within FIT image
  696. * @verify: data CRC verification flag
  697. *
  698. * fit_check_kernel() verifies integrity of the kernel subimage and from
  699. * specified FIT image.
  700. *
  701. * returns:
  702. * 1, on success
  703. * 0, on failure
  704. */
  705. #if defined(CONFIG_FIT)
  706. static int fit_check_kernel(const void *fit, int os_noffset, int verify)
  707. {
  708. fit_image_print(fit, os_noffset, " ");
  709. if (verify) {
  710. puts(" Verifying Hash Integrity ... ");
  711. if (!fit_image_verify(fit, os_noffset)) {
  712. puts("Bad Data Hash\n");
  713. bootstage_error(BOOTSTAGE_ID_FIT_CHECK_HASH);
  714. return 0;
  715. }
  716. puts("OK\n");
  717. }
  718. bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_ARCH);
  719. if (!fit_image_check_target_arch(fit, os_noffset)) {
  720. puts("Unsupported Architecture\n");
  721. bootstage_error(BOOTSTAGE_ID_FIT_CHECK_ARCH);
  722. return 0;
  723. }
  724. bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
  725. if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL) &&
  726. !fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL_NOLOAD)) {
  727. puts("Not a kernel image\n");
  728. bootstage_error(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
  729. return 0;
  730. }
  731. bootstage_mark(BOOTSTAGE_ID_FIT_CHECKED);
  732. return 1;
  733. }
  734. #endif /* CONFIG_FIT */
  735. /**
  736. * boot_get_kernel - find kernel image
  737. * @os_data: pointer to a ulong variable, will hold os data start address
  738. * @os_len: pointer to a ulong variable, will hold os data length
  739. *
  740. * boot_get_kernel() tries to find a kernel image, verifies its integrity
  741. * and locates kernel data.
  742. *
  743. * returns:
  744. * pointer to image header if valid image was found, plus kernel start
  745. * address and length, otherwise NULL
  746. */
  747. static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
  748. char * const argv[], bootm_headers_t *images, ulong *os_data,
  749. ulong *os_len)
  750. {
  751. image_header_t *hdr;
  752. ulong img_addr;
  753. const void *buf;
  754. #if defined(CONFIG_FIT)
  755. const void *fit_hdr;
  756. const char *fit_uname_config = NULL;
  757. const char *fit_uname_kernel = NULL;
  758. const void *data;
  759. size_t len;
  760. int cfg_noffset;
  761. int os_noffset;
  762. #endif
  763. /* find out kernel image address */
  764. if (argc < 2) {
  765. img_addr = load_addr;
  766. debug("* kernel: default image load address = 0x%08lx\n",
  767. load_addr);
  768. #if defined(CONFIG_FIT)
  769. } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
  770. &fit_uname_config)) {
  771. debug("* kernel: config '%s' from image at 0x%08lx\n",
  772. fit_uname_config, img_addr);
  773. } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
  774. &fit_uname_kernel)) {
  775. debug("* kernel: subimage '%s' from image at 0x%08lx\n",
  776. fit_uname_kernel, img_addr);
  777. #endif
  778. } else {
  779. img_addr = simple_strtoul(argv[1], NULL, 16);
  780. debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
  781. }
  782. bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
  783. /* copy from dataflash if needed */
  784. img_addr = genimg_get_image(img_addr);
  785. /* check image type, for FIT images get FIT kernel node */
  786. *os_data = *os_len = 0;
  787. buf = map_sysmem(img_addr, 0);
  788. switch (genimg_get_format(buf)) {
  789. case IMAGE_FORMAT_LEGACY:
  790. printf("## Booting kernel from Legacy Image at %08lx ...\n",
  791. img_addr);
  792. hdr = image_get_kernel(img_addr, images->verify);
  793. if (!hdr)
  794. return NULL;
  795. bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
  796. /* get os_data and os_len */
  797. switch (image_get_type(hdr)) {
  798. case IH_TYPE_KERNEL:
  799. case IH_TYPE_KERNEL_NOLOAD:
  800. *os_data = image_get_data(hdr);
  801. *os_len = image_get_data_size(hdr);
  802. break;
  803. case IH_TYPE_MULTI:
  804. image_multi_getimg(hdr, 0, os_data, os_len);
  805. break;
  806. case IH_TYPE_STANDALONE:
  807. *os_data = image_get_data(hdr);
  808. *os_len = image_get_data_size(hdr);
  809. break;
  810. default:
  811. printf("Wrong Image Type for %s command\n",
  812. cmdtp->name);
  813. bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
  814. return NULL;
  815. }
  816. /*
  817. * copy image header to allow for image overwrites during
  818. * kernel decompression.
  819. */
  820. memmove(&images->legacy_hdr_os_copy, hdr,
  821. sizeof(image_header_t));
  822. /* save pointer to image header */
  823. images->legacy_hdr_os = hdr;
  824. images->legacy_hdr_valid = 1;
  825. bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
  826. break;
  827. #if defined(CONFIG_FIT)
  828. case IMAGE_FORMAT_FIT:
  829. fit_hdr = buf;
  830. printf("## Booting kernel from FIT Image at %08lx ...\n",
  831. img_addr);
  832. if (!fit_check_format(fit_hdr)) {
  833. puts("Bad FIT kernel image format!\n");
  834. bootstage_error(BOOTSTAGE_ID_FIT_FORMAT);
  835. return NULL;
  836. }
  837. bootstage_mark(BOOTSTAGE_ID_FIT_FORMAT);
  838. if (!fit_uname_kernel) {
  839. /*
  840. * no kernel image node unit name, try to get config
  841. * node first. If config unit node name is NULL
  842. * fit_conf_get_node() will try to find default config
  843. * node
  844. */
  845. bootstage_mark(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
  846. #ifdef CONFIG_FIT_BEST_MATCH
  847. if (fit_uname_config)
  848. cfg_noffset =
  849. fit_conf_get_node(fit_hdr,
  850. fit_uname_config);
  851. else
  852. cfg_noffset =
  853. fit_conf_find_compat(fit_hdr,
  854. gd->fdt_blob);
  855. #else
  856. cfg_noffset = fit_conf_get_node(fit_hdr,
  857. fit_uname_config);
  858. #endif
  859. if (cfg_noffset < 0) {
  860. bootstage_error(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
  861. return NULL;
  862. }
  863. /* save configuration uname provided in the first
  864. * bootm argument
  865. */
  866. images->fit_uname_cfg = fdt_get_name(fit_hdr,
  867. cfg_noffset,
  868. NULL);
  869. printf(" Using '%s' configuration\n",
  870. images->fit_uname_cfg);
  871. bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
  872. os_noffset = fit_conf_get_kernel_node(fit_hdr,
  873. cfg_noffset);
  874. fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
  875. NULL);
  876. } else {
  877. /* get kernel component image node offset */
  878. bootstage_mark(BOOTSTAGE_ID_FIT_UNIT_NAME);
  879. os_noffset = fit_image_get_node(fit_hdr,
  880. fit_uname_kernel);
  881. }
  882. if (os_noffset < 0) {
  883. bootstage_error(BOOTSTAGE_ID_FIT_CONFIG);
  884. return NULL;
  885. }
  886. printf(" Trying '%s' kernel subimage\n", fit_uname_kernel);
  887. bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE);
  888. if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
  889. return NULL;
  890. /* get kernel image data address and length */
  891. if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
  892. puts("Could not find kernel subimage data!\n");
  893. bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR);
  894. return NULL;
  895. }
  896. bootstage_mark(BOOTSTAGE_ID_FIT_KERNEL_INFO);
  897. *os_len = len;
  898. *os_data = (ulong)data;
  899. images->fit_hdr_os = (void *)fit_hdr;
  900. images->fit_uname_os = fit_uname_kernel;
  901. images->fit_noffset_os = os_noffset;
  902. break;
  903. #endif
  904. default:
  905. printf("Wrong Image Format for %s command\n", cmdtp->name);
  906. bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO);
  907. return NULL;
  908. }
  909. debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
  910. *os_data, *os_len, *os_len);
  911. return buf;
  912. }
  913. #ifdef CONFIG_SYS_LONGHELP
  914. static char bootm_help_text[] =
  915. "[addr [arg ...]]\n - boot application image stored in memory\n"
  916. "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
  917. "\t'arg' can be the address of an initrd image\n"
  918. #if defined(CONFIG_OF_LIBFDT)
  919. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  920. "\ta third argument is required which is the address of the\n"
  921. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  922. "\tuse a '-' for the second argument. If you do not pass a third\n"
  923. "\ta bd_info struct will be passed instead\n"
  924. #endif
  925. #if defined(CONFIG_FIT)
  926. "\t\nFor the new multi component uImage format (FIT) addresses\n"
  927. "\tmust be extened to include component or configuration unit name:\n"
  928. "\taddr:<subimg_uname> - direct component image specification\n"
  929. "\taddr#<conf_uname> - configuration specification\n"
  930. "\tUse iminfo command to get the list of existing component\n"
  931. "\timages and configurations.\n"
  932. #endif
  933. "\nSub-commands to do part of the bootm sequence. The sub-commands "
  934. "must be\n"
  935. "issued in the order below (it's ok to not issue all sub-commands):\n"
  936. "\tstart [addr [arg ...]]\n"
  937. "\tloados - load OS image\n"
  938. #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
  939. "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
  940. #endif
  941. #if defined(CONFIG_OF_LIBFDT)
  942. "\tfdt - relocate flat device tree\n"
  943. #endif
  944. "\tcmdline - OS specific command line processing/setup\n"
  945. "\tbdt - OS specific bd_t processing\n"
  946. "\tprep - OS specific prep before relocation or go\n"
  947. "\tgo - start OS";
  948. #endif
  949. U_BOOT_CMD(
  950. bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
  951. "boot application image from memory", bootm_help_text
  952. );
  953. /*******************************************************************/
  954. /* bootd - boot default image */
  955. /*******************************************************************/
  956. #if defined(CONFIG_CMD_BOOTD)
  957. int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  958. {
  959. int rcode = 0;
  960. if (run_command(getenv("bootcmd"), flag) < 0)
  961. rcode = 1;
  962. return rcode;
  963. }
  964. U_BOOT_CMD(
  965. boot, 1, 1, do_bootd,
  966. "boot default, i.e., run 'bootcmd'",
  967. ""
  968. );
  969. /* keep old command name "bootd" for backward compatibility */
  970. U_BOOT_CMD(
  971. bootd, 1, 1, do_bootd,
  972. "boot default, i.e., run 'bootcmd'",
  973. ""
  974. );
  975. #endif
  976. /*******************************************************************/
  977. /* iminfo - print header info for a requested image */
  978. /*******************************************************************/
  979. #if defined(CONFIG_CMD_IMI)
  980. static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  981. {
  982. int arg;
  983. ulong addr;
  984. int rcode = 0;
  985. if (argc < 2) {
  986. return image_info(load_addr);
  987. }
  988. for (arg = 1; arg < argc; ++arg) {
  989. addr = simple_strtoul(argv[arg], NULL, 16);
  990. if (image_info(addr) != 0)
  991. rcode = 1;
  992. }
  993. return rcode;
  994. }
  995. static int image_info(ulong addr)
  996. {
  997. void *hdr = (void *)addr;
  998. printf("\n## Checking Image at %08lx ...\n", addr);
  999. switch (genimg_get_format(hdr)) {
  1000. case IMAGE_FORMAT_LEGACY:
  1001. puts(" Legacy image found\n");
  1002. if (!image_check_magic(hdr)) {
  1003. puts(" Bad Magic Number\n");
  1004. return 1;
  1005. }
  1006. if (!image_check_hcrc(hdr)) {
  1007. puts(" Bad Header Checksum\n");
  1008. return 1;
  1009. }
  1010. image_print_contents(hdr);
  1011. puts(" Verifying Checksum ... ");
  1012. if (!image_check_dcrc(hdr)) {
  1013. puts(" Bad Data CRC\n");
  1014. return 1;
  1015. }
  1016. puts("OK\n");
  1017. return 0;
  1018. #if defined(CONFIG_FIT)
  1019. case IMAGE_FORMAT_FIT:
  1020. puts(" FIT image found\n");
  1021. if (!fit_check_format(hdr)) {
  1022. puts("Bad FIT image format!\n");
  1023. return 1;
  1024. }
  1025. fit_print_contents(hdr);
  1026. if (!fit_all_image_verify(hdr)) {
  1027. puts("Bad hash in FIT image!\n");
  1028. return 1;
  1029. }
  1030. return 0;
  1031. #endif
  1032. default:
  1033. puts("Unknown image format!\n");
  1034. break;
  1035. }
  1036. return 1;
  1037. }
  1038. U_BOOT_CMD(
  1039. iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
  1040. "print header information for application image",
  1041. "addr [addr ...]\n"
  1042. " - print header information for application image starting at\n"
  1043. " address 'addr' in memory; this includes verification of the\n"
  1044. " image contents (magic number, header and payload checksums)"
  1045. );
  1046. #endif
  1047. /*******************************************************************/
  1048. /* imls - list all images found in flash */
  1049. /*******************************************************************/
  1050. #if defined(CONFIG_CMD_IMLS)
  1051. static int do_imls_nor(void)
  1052. {
  1053. flash_info_t *info;
  1054. int i, j;
  1055. void *hdr;
  1056. for (i = 0, info = &flash_info[0];
  1057. i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
  1058. if (info->flash_id == FLASH_UNKNOWN)
  1059. goto next_bank;
  1060. for (j = 0; j < info->sector_count; ++j) {
  1061. hdr = (void *)info->start[j];
  1062. if (!hdr)
  1063. goto next_sector;
  1064. switch (genimg_get_format(hdr)) {
  1065. case IMAGE_FORMAT_LEGACY:
  1066. if (!image_check_hcrc(hdr))
  1067. goto next_sector;
  1068. printf("Legacy Image at %08lX:\n", (ulong)hdr);
  1069. image_print_contents(hdr);
  1070. puts(" Verifying Checksum ... ");
  1071. if (!image_check_dcrc(hdr)) {
  1072. puts("Bad Data CRC\n");
  1073. } else {
  1074. puts("OK\n");
  1075. }
  1076. break;
  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. case IMAGE_FORMAT_LEGACY:
  1186. header = (const image_header_t *)buffer;
  1187. len = image_get_image_size(header);
  1188. nand_imls_legacyimage(nand, nand_dev, off, len);
  1189. break;
  1190. #if defined(CONFIG_FIT)
  1191. case IMAGE_FORMAT_FIT:
  1192. len = fit_get_size(buffer);
  1193. nand_imls_fitimage(nand, nand_dev, off, len);
  1194. break;
  1195. #endif
  1196. }
  1197. }
  1198. }
  1199. return 0;
  1200. }
  1201. #endif
  1202. #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
  1203. static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1204. {
  1205. int ret_nor = 0, ret_nand = 0;
  1206. #if defined(CONFIG_CMD_IMLS)
  1207. ret_nor = do_imls_nor();
  1208. #endif
  1209. #if defined(CONFIG_CMD_IMLS_NAND)
  1210. ret_nand = do_imls_nand();
  1211. #endif
  1212. if (ret_nor)
  1213. return ret_nor;
  1214. if (ret_nand)
  1215. return ret_nand;
  1216. return (0);
  1217. }
  1218. U_BOOT_CMD(
  1219. imls, 1, 1, do_imls,
  1220. "list all images found in flash",
  1221. "\n"
  1222. " - Prints information about all images found at sector/block\n"
  1223. " boundaries in nor/nand flash."
  1224. );
  1225. #endif
  1226. /*******************************************************************/
  1227. /* helper routines */
  1228. /*******************************************************************/
  1229. #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
  1230. #define CONSOLE_ARG "console="
  1231. #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
  1232. static void fixup_silent_linux(void)
  1233. {
  1234. char *buf;
  1235. const char *env_val;
  1236. char *cmdline = getenv("bootargs");
  1237. /* Only fix cmdline when requested */
  1238. if (!(gd->flags & GD_FLG_SILENT))
  1239. return;
  1240. debug("before silent fix-up: %s\n", cmdline);
  1241. if (cmdline && (cmdline[0] != '\0')) {
  1242. char *start = strstr(cmdline, CONSOLE_ARG);
  1243. /* Allocate space for maximum possible new command line */
  1244. buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
  1245. if (!buf) {
  1246. debug("%s: out of memory\n", __func__);
  1247. return;
  1248. }
  1249. if (start) {
  1250. char *end = strchr(start, ' ');
  1251. int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN;
  1252. strncpy(buf, cmdline, num_start_bytes);
  1253. if (end)
  1254. strcpy(buf + num_start_bytes, end);
  1255. else
  1256. buf[num_start_bytes] = '\0';
  1257. } else {
  1258. sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
  1259. }
  1260. env_val = buf;
  1261. } else {
  1262. buf = NULL;
  1263. env_val = CONSOLE_ARG;
  1264. }
  1265. setenv("bootargs", env_val);
  1266. debug("after silent fix-up: %s\n", env_val);
  1267. free(buf);
  1268. }
  1269. #endif /* CONFIG_SILENT_CONSOLE */
  1270. /*******************************************************************/
  1271. /* OS booting routines */
  1272. /*******************************************************************/
  1273. #ifdef CONFIG_BOOTM_NETBSD
  1274. static int do_bootm_netbsd(int flag, int argc, char * const argv[],
  1275. bootm_headers_t *images)
  1276. {
  1277. void (*loader)(bd_t *, image_header_t *, char *, char *);
  1278. image_header_t *os_hdr, *hdr;
  1279. ulong kernel_data, kernel_len;
  1280. char *consdev;
  1281. char *cmdline;
  1282. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1283. return 1;
  1284. #if defined(CONFIG_FIT)
  1285. if (!images->legacy_hdr_valid) {
  1286. fit_unsupported_reset("NetBSD");
  1287. return 1;
  1288. }
  1289. #endif
  1290. hdr = images->legacy_hdr_os;
  1291. /*
  1292. * Booting a (NetBSD) kernel image
  1293. *
  1294. * This process is pretty similar to a standalone application:
  1295. * The (first part of an multi-) image must be a stage-2 loader,
  1296. * which in turn is responsible for loading & invoking the actual
  1297. * kernel. The only differences are the parameters being passed:
  1298. * besides the board info strucure, the loader expects a command
  1299. * line, the name of the console device, and (optionally) the
  1300. * address of the original image header.
  1301. */
  1302. os_hdr = NULL;
  1303. if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
  1304. image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
  1305. if (kernel_len)
  1306. os_hdr = hdr;
  1307. }
  1308. consdev = "";
  1309. #if defined(CONFIG_8xx_CONS_SMC1)
  1310. consdev = "smc1";
  1311. #elif defined(CONFIG_8xx_CONS_SMC2)
  1312. consdev = "smc2";
  1313. #elif defined(CONFIG_8xx_CONS_SCC2)
  1314. consdev = "scc2";
  1315. #elif defined(CONFIG_8xx_CONS_SCC3)
  1316. consdev = "scc3";
  1317. #endif
  1318. if (argc > 2) {
  1319. ulong len;
  1320. int i;
  1321. for (i = 2, len = 0; i < argc; i += 1)
  1322. len += strlen(argv[i]) + 1;
  1323. cmdline = malloc(len);
  1324. for (i = 2, len = 0; i < argc; i += 1) {
  1325. if (i > 2)
  1326. cmdline[len++] = ' ';
  1327. strcpy(&cmdline[len], argv[i]);
  1328. len += strlen(argv[i]);
  1329. }
  1330. } else if ((cmdline = getenv("bootargs")) == NULL) {
  1331. cmdline = "";
  1332. }
  1333. loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
  1334. printf("## Transferring control to NetBSD stage-2 loader "
  1335. "(at address %08lx) ...\n",
  1336. (ulong)loader);
  1337. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1338. /*
  1339. * NetBSD Stage-2 Loader Parameters:
  1340. * r3: ptr to board info data
  1341. * r4: image address
  1342. * r5: console device
  1343. * r6: boot args string
  1344. */
  1345. (*loader)(gd->bd, os_hdr, consdev, cmdline);
  1346. return 1;
  1347. }
  1348. #endif /* CONFIG_BOOTM_NETBSD*/
  1349. #ifdef CONFIG_LYNXKDI
  1350. static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
  1351. bootm_headers_t *images)
  1352. {
  1353. image_header_t *hdr = &images->legacy_hdr_os_copy;
  1354. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1355. return 1;
  1356. #if defined(CONFIG_FIT)
  1357. if (!images->legacy_hdr_valid) {
  1358. fit_unsupported_reset("Lynx");
  1359. return 1;
  1360. }
  1361. #endif
  1362. lynxkdi_boot((image_header_t *)hdr);
  1363. return 1;
  1364. }
  1365. #endif /* CONFIG_LYNXKDI */
  1366. #ifdef CONFIG_BOOTM_RTEMS
  1367. static int do_bootm_rtems(int flag, int argc, char * const argv[],
  1368. bootm_headers_t *images)
  1369. {
  1370. void (*entry_point)(bd_t *);
  1371. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1372. return 1;
  1373. #if defined(CONFIG_FIT)
  1374. if (!images->legacy_hdr_valid) {
  1375. fit_unsupported_reset("RTEMS");
  1376. return 1;
  1377. }
  1378. #endif
  1379. entry_point = (void (*)(bd_t *))images->ep;
  1380. printf("## Transferring control to RTEMS (at address %08lx) ...\n",
  1381. (ulong)entry_point);
  1382. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1383. /*
  1384. * RTEMS Parameters:
  1385. * r3: ptr to board info data
  1386. */
  1387. (*entry_point)(gd->bd);
  1388. return 1;
  1389. }
  1390. #endif /* CONFIG_BOOTM_RTEMS */
  1391. #if defined(CONFIG_BOOTM_OSE)
  1392. static int do_bootm_ose(int flag, int argc, char * const argv[],
  1393. bootm_headers_t *images)
  1394. {
  1395. void (*entry_point)(void);
  1396. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1397. return 1;
  1398. #if defined(CONFIG_FIT)
  1399. if (!images->legacy_hdr_valid) {
  1400. fit_unsupported_reset("OSE");
  1401. return 1;
  1402. }
  1403. #endif
  1404. entry_point = (void (*)(void))images->ep;
  1405. printf("## Transferring control to OSE (at address %08lx) ...\n",
  1406. (ulong)entry_point);
  1407. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1408. /*
  1409. * OSE Parameters:
  1410. * None
  1411. */
  1412. (*entry_point)();
  1413. return 1;
  1414. }
  1415. #endif /* CONFIG_BOOTM_OSE */
  1416. #if defined(CONFIG_BOOTM_PLAN9)
  1417. static int do_bootm_plan9(int flag, int argc, char * const argv[],
  1418. bootm_headers_t *images)
  1419. {
  1420. void (*entry_point)(void);
  1421. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1422. return 1;
  1423. #if defined(CONFIG_FIT)
  1424. if (!images->legacy_hdr_valid) {
  1425. fit_unsupported_reset("Plan 9");
  1426. return 1;
  1427. }
  1428. #endif
  1429. entry_point = (void (*)(void))images->ep;
  1430. printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
  1431. (ulong)entry_point);
  1432. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1433. /*
  1434. * Plan 9 Parameters:
  1435. * None
  1436. */
  1437. (*entry_point)();
  1438. return 1;
  1439. }
  1440. #endif /* CONFIG_BOOTM_PLAN9 */
  1441. #if defined(CONFIG_CMD_ELF)
  1442. static int do_bootm_vxworks(int flag, int argc, char * const argv[],
  1443. bootm_headers_t *images)
  1444. {
  1445. char str[80];
  1446. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1447. return 1;
  1448. #if defined(CONFIG_FIT)
  1449. if (!images->legacy_hdr_valid) {
  1450. fit_unsupported_reset("VxWorks");
  1451. return 1;
  1452. }
  1453. #endif
  1454. sprintf(str, "%lx", images->ep); /* write entry-point into string */
  1455. setenv("loadaddr", str);
  1456. do_bootvx(NULL, 0, 0, NULL);
  1457. return 1;
  1458. }
  1459. static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
  1460. bootm_headers_t *images)
  1461. {
  1462. char *local_args[2];
  1463. char str[16];
  1464. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1465. return 1;
  1466. #if defined(CONFIG_FIT)
  1467. if (!images->legacy_hdr_valid) {
  1468. fit_unsupported_reset("QNX");
  1469. return 1;
  1470. }
  1471. #endif
  1472. sprintf(str, "%lx", images->ep); /* write entry-point into string */
  1473. local_args[0] = argv[0];
  1474. local_args[1] = str; /* and provide it via the arguments */
  1475. do_bootelf(NULL, 0, 2, local_args);
  1476. return 1;
  1477. }
  1478. #endif
  1479. #ifdef CONFIG_INTEGRITY
  1480. static int do_bootm_integrity(int flag, int argc, char * const argv[],
  1481. bootm_headers_t *images)
  1482. {
  1483. void (*entry_point)(void);
  1484. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1485. return 1;
  1486. #if defined(CONFIG_FIT)
  1487. if (!images->legacy_hdr_valid) {
  1488. fit_unsupported_reset("INTEGRITY");
  1489. return 1;
  1490. }
  1491. #endif
  1492. entry_point = (void (*)(void))images->ep;
  1493. printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
  1494. (ulong)entry_point);
  1495. bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  1496. /*
  1497. * INTEGRITY Parameters:
  1498. * None
  1499. */
  1500. (*entry_point)();
  1501. return 1;
  1502. }
  1503. #endif
  1504. #ifdef CONFIG_CMD_BOOTZ
  1505. static int __bootz_setup(void *image, void **start, void **end)
  1506. {
  1507. /* Please define bootz_setup() for your platform */
  1508. puts("Your platform's zImage format isn't supported yet!\n");
  1509. return -1;
  1510. }
  1511. int bootz_setup(void *image, void **start, void **end)
  1512. __attribute__((weak, alias("__bootz_setup")));
  1513. /*
  1514. * zImage booting support
  1515. */
  1516. static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
  1517. char * const argv[], bootm_headers_t *images)
  1518. {
  1519. int ret;
  1520. void *zi_start, *zi_end;
  1521. memset(images, 0, sizeof(bootm_headers_t));
  1522. boot_start_lmb(images);
  1523. /* Setup Linux kernel zImage entry point */
  1524. if (argc < 2) {
  1525. images->ep = load_addr;
  1526. debug("* kernel: default image load address = 0x%08lx\n",
  1527. load_addr);
  1528. } else {
  1529. images->ep = simple_strtoul(argv[1], NULL, 16);
  1530. debug("* kernel: cmdline image address = 0x%08lx\n",
  1531. images->ep);
  1532. }
  1533. ret = bootz_setup((void *)images->ep, &zi_start, &zi_end);
  1534. if (ret != 0)
  1535. return 1;
  1536. lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
  1537. /* Find ramdisk */
  1538. ret = boot_get_ramdisk(argc, argv, images, IH_INITRD_ARCH,
  1539. &images->rd_start, &images->rd_end);
  1540. if (ret) {
  1541. puts("Ramdisk image is corrupt or invalid\n");
  1542. return 1;
  1543. }
  1544. #if defined(CONFIG_OF_LIBFDT)
  1545. /* find flattened device tree */
  1546. ret = boot_get_fdt(flag, argc, argv, images,
  1547. &images->ft_addr, &images->ft_len);
  1548. if (ret) {
  1549. puts("Could not find a valid device tree\n");
  1550. return 1;
  1551. }
  1552. set_working_fdt_addr(images->ft_addr);
  1553. #endif
  1554. return 0;
  1555. }
  1556. static int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1557. {
  1558. bootm_headers_t images;
  1559. if (bootz_start(cmdtp, flag, argc, argv, &images))
  1560. return 1;
  1561. /*
  1562. * We have reached the point of no return: we are going to
  1563. * overwrite all exception vector code, so we cannot easily
  1564. * recover from any failures any more...
  1565. */
  1566. disable_interrupts();
  1567. #ifdef CONFIG_NETCONSOLE
  1568. /* Stop the ethernet stack if NetConsole could have left it up */
  1569. eth_halt();
  1570. #endif
  1571. #if defined(CONFIG_CMD_USB)
  1572. /*
  1573. * turn off USB to prevent the host controller from writing to the
  1574. * SDRAM while Linux is booting. This could happen (at least for OHCI
  1575. * controller), because the HCCA (Host Controller Communication Area)
  1576. * lies within the SDRAM and the host controller writes continously to
  1577. * this area (as busmaster!). The HccaFrameNumber is for example
  1578. * updated every 1 ms within the HCCA structure in SDRAM! For more
  1579. * details see the OpenHCI specification.
  1580. */
  1581. usb_stop();
  1582. #endif
  1583. #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
  1584. fixup_silent_linux();
  1585. #endif
  1586. arch_preboot_os();
  1587. do_bootm_linux(0, argc, argv, &images);
  1588. #ifdef DEBUG
  1589. puts("\n## Control returned to monitor - resetting...\n");
  1590. #endif
  1591. do_reset(cmdtp, flag, argc, argv);
  1592. return 1;
  1593. }
  1594. #ifdef CONFIG_SYS_LONGHELP
  1595. static char bootz_help_text[] =
  1596. "[addr [initrd[:size]] [fdt]]\n"
  1597. " - boot Linux zImage stored in memory\n"
  1598. "\tThe argument 'initrd' is optional and specifies the address\n"
  1599. "\tof the initrd in memory. The optional argument ':size' allows\n"
  1600. "\tspecifying the size of RAW initrd.\n"
  1601. #if defined(CONFIG_OF_LIBFDT)
  1602. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  1603. "\ta third argument is required which is the address of the\n"
  1604. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  1605. "\tuse a '-' for the second argument. If you do not pass a third\n"
  1606. "\ta bd_info struct will be passed instead\n"
  1607. #endif
  1608. "";
  1609. #endif
  1610. U_BOOT_CMD(
  1611. bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
  1612. "boot Linux zImage image from memory", bootz_help_text
  1613. );
  1614. #endif /* CONFIG_CMD_BOOTZ */