cmd_bootm.c 48 KB

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