cmd_bootm.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  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 <linux/compiler.h>
  38. #if defined(CONFIG_CMD_USB)
  39. #include <usb.h>
  40. #endif
  41. #ifdef CONFIG_SYS_HUSH_PARSER
  42. #include <hush.h>
  43. #endif
  44. #if defined(CONFIG_OF_LIBFDT)
  45. #include <fdt.h>
  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. static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  72. #endif
  73. #ifdef CONFIG_SILENT_CONSOLE
  74. static void fixup_silent_linux(void);
  75. #endif
  76. static image_header_t *image_get_kernel(ulong img_addr, int verify);
  77. #if defined(CONFIG_FIT)
  78. static int fit_check_kernel(const void *fit, int os_noffset, int verify);
  79. #endif
  80. static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
  81. char * const argv[], bootm_headers_t *images,
  82. ulong *os_data, ulong *os_len);
  83. /*
  84. * Continue booting an OS image; caller already has:
  85. * - copied image header to global variable `header'
  86. * - checked header magic number, checksums (both header & image),
  87. * - verified image architecture (PPC) and type (KERNEL or MULTI),
  88. * - loaded (first part of) image to header load address,
  89. * - disabled interrupts.
  90. */
  91. typedef int boot_os_fn(int flag, int argc, char * const argv[],
  92. bootm_headers_t *images); /* pointers to os/initrd/fdt */
  93. #ifdef CONFIG_BOOTM_LINUX
  94. extern boot_os_fn do_bootm_linux;
  95. #endif
  96. #ifdef CONFIG_BOOTM_NETBSD
  97. static boot_os_fn do_bootm_netbsd;
  98. #endif
  99. #if defined(CONFIG_LYNXKDI)
  100. static boot_os_fn do_bootm_lynxkdi;
  101. extern void lynxkdi_boot(image_header_t *);
  102. #endif
  103. #ifdef CONFIG_BOOTM_RTEMS
  104. static boot_os_fn do_bootm_rtems;
  105. #endif
  106. #if defined(CONFIG_BOOTM_OSE)
  107. static boot_os_fn do_bootm_ose;
  108. #endif
  109. #if defined(CONFIG_CMD_ELF)
  110. static boot_os_fn do_bootm_vxworks;
  111. static boot_os_fn do_bootm_qnxelf;
  112. int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  113. int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  114. #endif
  115. #if defined(CONFIG_INTEGRITY)
  116. static boot_os_fn do_bootm_integrity;
  117. #endif
  118. static boot_os_fn *boot_os[] = {
  119. #ifdef CONFIG_BOOTM_LINUX
  120. [IH_OS_LINUX] = do_bootm_linux,
  121. #endif
  122. #ifdef CONFIG_BOOTM_NETBSD
  123. [IH_OS_NETBSD] = do_bootm_netbsd,
  124. #endif
  125. #ifdef CONFIG_LYNXKDI
  126. [IH_OS_LYNXOS] = do_bootm_lynxkdi,
  127. #endif
  128. #ifdef CONFIG_BOOTM_RTEMS
  129. [IH_OS_RTEMS] = do_bootm_rtems,
  130. #endif
  131. #if defined(CONFIG_BOOTM_OSE)
  132. [IH_OS_OSE] = do_bootm_ose,
  133. #endif
  134. #if defined(CONFIG_CMD_ELF)
  135. [IH_OS_VXWORKS] = do_bootm_vxworks,
  136. [IH_OS_QNX] = do_bootm_qnxelf,
  137. #endif
  138. #ifdef CONFIG_INTEGRITY
  139. [IH_OS_INTEGRITY] = do_bootm_integrity,
  140. #endif
  141. };
  142. bootm_headers_t images; /* pointers to os/initrd/fdt images */
  143. /* Allow for arch specific config before we boot */
  144. void __arch_preboot_os(void)
  145. {
  146. /* please define platform specific arch_preboot_os() */
  147. }
  148. void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
  149. #define IH_INITRD_ARCH IH_ARCH_DEFAULT
  150. static void bootm_start_lmb(void)
  151. {
  152. #ifdef CONFIG_LMB
  153. ulong mem_start;
  154. phys_size_t mem_size;
  155. lmb_init(&images.lmb);
  156. mem_start = getenv_bootm_low();
  157. mem_size = getenv_bootm_size();
  158. lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
  159. arch_lmb_reserve(&images.lmb);
  160. board_lmb_reserve(&images.lmb);
  161. #else
  162. # define lmb_reserve(lmb, base, size)
  163. #endif
  164. }
  165. static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  166. {
  167. void *os_hdr;
  168. int ret;
  169. memset((void *)&images, 0, sizeof(images));
  170. images.verify = getenv_yesno("verify");
  171. bootm_start_lmb();
  172. /* get kernel image header, start address and length */
  173. os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
  174. &images, &images.os.image_start, &images.os.image_len);
  175. if (images.os.image_len == 0) {
  176. puts("ERROR: can't get kernel image!\n");
  177. return 1;
  178. }
  179. /* get image parameters */
  180. switch (genimg_get_format(os_hdr)) {
  181. case IMAGE_FORMAT_LEGACY:
  182. images.os.type = image_get_type(os_hdr);
  183. images.os.comp = image_get_comp(os_hdr);
  184. images.os.os = image_get_os(os_hdr);
  185. images.os.end = image_get_image_end(os_hdr);
  186. images.os.load = image_get_load(os_hdr);
  187. break;
  188. #if defined(CONFIG_FIT)
  189. case IMAGE_FORMAT_FIT:
  190. if (fit_image_get_type(images.fit_hdr_os,
  191. images.fit_noffset_os, &images.os.type)) {
  192. puts("Can't get image type!\n");
  193. show_boot_progress(-109);
  194. return 1;
  195. }
  196. if (fit_image_get_comp(images.fit_hdr_os,
  197. images.fit_noffset_os, &images.os.comp)) {
  198. puts("Can't get image compression!\n");
  199. show_boot_progress(-110);
  200. return 1;
  201. }
  202. if (fit_image_get_os(images.fit_hdr_os,
  203. images.fit_noffset_os, &images.os.os)) {
  204. puts("Can't get image OS!\n");
  205. show_boot_progress(-111);
  206. return 1;
  207. }
  208. images.os.end = fit_get_end(images.fit_hdr_os);
  209. if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
  210. &images.os.load)) {
  211. puts("Can't get image load address!\n");
  212. show_boot_progress(-112);
  213. return 1;
  214. }
  215. break;
  216. #endif
  217. default:
  218. puts("ERROR: unknown image format type!\n");
  219. return 1;
  220. }
  221. /* find kernel entry point */
  222. if (images.legacy_hdr_valid) {
  223. images.ep = image_get_ep(&images.legacy_hdr_os_copy);
  224. #if defined(CONFIG_FIT)
  225. } else if (images.fit_uname_os) {
  226. ret = fit_image_get_entry(images.fit_hdr_os,
  227. images.fit_noffset_os, &images.ep);
  228. if (ret) {
  229. puts("Can't get entry point property!\n");
  230. return 1;
  231. }
  232. #endif
  233. } else {
  234. puts("Could not find kernel entry point!\n");
  235. return 1;
  236. }
  237. if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
  238. images.os.load = images.os.image_start;
  239. images.ep += images.os.load;
  240. }
  241. if (((images.os.type == IH_TYPE_KERNEL) ||
  242. (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
  243. (images.os.type == IH_TYPE_MULTI)) &&
  244. (images.os.os == IH_OS_LINUX)) {
  245. /* find ramdisk */
  246. ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
  247. &images.rd_start, &images.rd_end);
  248. if (ret) {
  249. puts("Ramdisk image is corrupt or invalid\n");
  250. return 1;
  251. }
  252. #if defined(CONFIG_OF_LIBFDT)
  253. /* find flattened device tree */
  254. ret = boot_get_fdt(flag, argc, argv, &images,
  255. &images.ft_addr, &images.ft_len);
  256. if (ret) {
  257. puts("Could not find a valid device tree\n");
  258. return 1;
  259. }
  260. set_working_fdt_addr(images.ft_addr);
  261. #endif
  262. }
  263. images.os.start = (ulong)os_hdr;
  264. images.state = BOOTM_STATE_START;
  265. return 0;
  266. }
  267. #define BOOTM_ERR_RESET -1
  268. #define BOOTM_ERR_OVERLAP -2
  269. #define BOOTM_ERR_UNIMPLEMENTED -3
  270. static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
  271. {
  272. uint8_t comp = os.comp;
  273. ulong load = os.load;
  274. ulong blob_start = os.start;
  275. ulong blob_end = os.end;
  276. ulong image_start = os.image_start;
  277. ulong image_len = os.image_len;
  278. __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
  279. int no_overlap = 0;
  280. #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
  281. int ret;
  282. #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
  283. const char *type_name = genimg_get_type_name(os.type);
  284. switch (comp) {
  285. case IH_COMP_NONE:
  286. if (load == blob_start || load == image_start) {
  287. printf(" XIP %s ... ", type_name);
  288. no_overlap = 1;
  289. } else {
  290. printf(" Loading %s ... ", type_name);
  291. memmove_wd((void *)load, (void *)image_start,
  292. image_len, CHUNKSZ);
  293. }
  294. *load_end = load + image_len;
  295. puts("OK\n");
  296. break;
  297. #ifdef CONFIG_GZIP
  298. case IH_COMP_GZIP:
  299. printf(" Uncompressing %s ... ", type_name);
  300. if (gunzip((void *)load, unc_len,
  301. (uchar *)image_start, &image_len) != 0) {
  302. puts("GUNZIP: uncompress, out-of-mem or overwrite "
  303. "error - must RESET board to recover\n");
  304. if (boot_progress)
  305. show_boot_progress(-6);
  306. return BOOTM_ERR_RESET;
  307. }
  308. *load_end = load + image_len;
  309. break;
  310. #endif /* CONFIG_GZIP */
  311. #ifdef CONFIG_BZIP2
  312. case IH_COMP_BZIP2:
  313. printf(" Uncompressing %s ... ", type_name);
  314. /*
  315. * If we've got less than 4 MB of malloc() space,
  316. * use slower decompression algorithm which requires
  317. * at most 2300 KB of memory.
  318. */
  319. int i = BZ2_bzBuffToBuffDecompress((char *)load,
  320. &unc_len, (char *)image_start, image_len,
  321. CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
  322. if (i != BZ_OK) {
  323. printf("BUNZIP2: uncompress or overwrite error %d "
  324. "- must RESET board to recover\n", i);
  325. if (boot_progress)
  326. show_boot_progress(-6);
  327. return BOOTM_ERR_RESET;
  328. }
  329. *load_end = load + unc_len;
  330. break;
  331. #endif /* CONFIG_BZIP2 */
  332. #ifdef CONFIG_LZMA
  333. case IH_COMP_LZMA: {
  334. SizeT lzma_len = unc_len;
  335. printf(" Uncompressing %s ... ", type_name);
  336. ret = lzmaBuffToBuffDecompress(
  337. (unsigned char *)load, &lzma_len,
  338. (unsigned char *)image_start, image_len);
  339. unc_len = lzma_len;
  340. if (ret != SZ_OK) {
  341. printf("LZMA: uncompress or overwrite error %d "
  342. "- must RESET board to recover\n", ret);
  343. show_boot_progress(-6);
  344. return BOOTM_ERR_RESET;
  345. }
  346. *load_end = load + unc_len;
  347. break;
  348. }
  349. #endif /* CONFIG_LZMA */
  350. #ifdef CONFIG_LZO
  351. case IH_COMP_LZO:
  352. printf(" Uncompressing %s ... ", type_name);
  353. ret = lzop_decompress((const unsigned char *)image_start,
  354. image_len, (unsigned char *)load,
  355. &unc_len);
  356. if (ret != LZO_E_OK) {
  357. printf("LZO: uncompress or overwrite error %d "
  358. "- must RESET board to recover\n", ret);
  359. if (boot_progress)
  360. show_boot_progress(-6);
  361. return BOOTM_ERR_RESET;
  362. }
  363. *load_end = load + unc_len;
  364. break;
  365. #endif /* CONFIG_LZO */
  366. default:
  367. printf("Unimplemented compression type %d\n", comp);
  368. return BOOTM_ERR_UNIMPLEMENTED;
  369. }
  370. flush_cache(load, (*load_end - load) * sizeof(ulong));
  371. puts("OK\n");
  372. debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
  373. if (boot_progress)
  374. show_boot_progress(7);
  375. if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
  376. debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
  377. blob_start, blob_end);
  378. debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
  379. *load_end);
  380. return BOOTM_ERR_OVERLAP;
  381. }
  382. return 0;
  383. }
  384. static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
  385. {
  386. char *s;
  387. int (*appl)(int, char * const []);
  388. /* Don't start if "autostart" is set to "no" */
  389. if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
  390. char buf[32];
  391. sprintf(buf, "%lX", images.os.image_len);
  392. setenv("filesize", buf);
  393. return 0;
  394. }
  395. appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
  396. (*appl)(argc-1, &argv[1]);
  397. return 0;
  398. }
  399. /* we overload the cmd field with our state machine info instead of a
  400. * function pointer */
  401. static cmd_tbl_t cmd_bootm_sub[] = {
  402. U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
  403. U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
  404. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  405. U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
  406. #endif
  407. #ifdef CONFIG_OF_LIBFDT
  408. U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
  409. #endif
  410. U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
  411. U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
  412. U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
  413. U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
  414. };
  415. int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
  416. char * const argv[])
  417. {
  418. int ret = 0;
  419. long state;
  420. cmd_tbl_t *c;
  421. boot_os_fn *boot_fn;
  422. c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
  423. if (c) {
  424. state = (long)c->cmd;
  425. /* treat start special since it resets the state machine */
  426. if (state == BOOTM_STATE_START) {
  427. argc--;
  428. argv++;
  429. return bootm_start(cmdtp, flag, argc, argv);
  430. }
  431. } else {
  432. /* Unrecognized command */
  433. return cmd_usage(cmdtp);
  434. }
  435. if (images.state >= state) {
  436. printf("Trying to execute a command out of order\n");
  437. return cmd_usage(cmdtp);
  438. }
  439. images.state |= state;
  440. boot_fn = boot_os[images.os.os];
  441. switch (state) {
  442. ulong load_end;
  443. case BOOTM_STATE_START:
  444. /* should never occur */
  445. break;
  446. case BOOTM_STATE_LOADOS:
  447. ret = bootm_load_os(images.os, &load_end, 0);
  448. if (ret)
  449. return ret;
  450. lmb_reserve(&images.lmb, images.os.load,
  451. (load_end - images.os.load));
  452. break;
  453. #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  454. case BOOTM_STATE_RAMDISK:
  455. {
  456. ulong rd_len = images.rd_end - images.rd_start;
  457. char str[17];
  458. ret = boot_ramdisk_high(&images.lmb, images.rd_start,
  459. rd_len, &images.initrd_start, &images.initrd_end);
  460. if (ret)
  461. return ret;
  462. sprintf(str, "%lx", images.initrd_start);
  463. setenv("initrd_start", str);
  464. sprintf(str, "%lx", images.initrd_end);
  465. setenv("initrd_end", str);
  466. }
  467. break;
  468. #endif
  469. #if defined(CONFIG_OF_LIBFDT)
  470. case BOOTM_STATE_FDT:
  471. {
  472. boot_fdt_add_mem_rsv_regions(&images.lmb,
  473. images.ft_addr);
  474. ret = boot_relocate_fdt(&images.lmb,
  475. &images.ft_addr, &images.ft_len);
  476. break;
  477. }
  478. #endif
  479. case BOOTM_STATE_OS_CMDLINE:
  480. ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
  481. if (ret)
  482. printf("cmdline subcommand not supported\n");
  483. break;
  484. case BOOTM_STATE_OS_BD_T:
  485. ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
  486. if (ret)
  487. printf("bdt subcommand not supported\n");
  488. break;
  489. case BOOTM_STATE_OS_PREP:
  490. ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
  491. if (ret)
  492. printf("prep subcommand not supported\n");
  493. break;
  494. case BOOTM_STATE_OS_GO:
  495. disable_interrupts();
  496. arch_preboot_os();
  497. boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
  498. break;
  499. }
  500. return ret;
  501. }
  502. /*******************************************************************/
  503. /* bootm - boot application image from image in memory */
  504. /*******************************************************************/
  505. int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  506. {
  507. ulong iflag;
  508. ulong load_end = 0;
  509. int ret;
  510. boot_os_fn *boot_fn;
  511. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  512. static int relocated = 0;
  513. /* relocate boot function table */
  514. if (!relocated) {
  515. int i;
  516. for (i = 0; i < ARRAY_SIZE(boot_os); i++)
  517. if (boot_os[i] != NULL)
  518. boot_os[i] += gd->reloc_off;
  519. relocated = 1;
  520. }
  521. #endif
  522. /* determine if we have a sub command */
  523. if (argc > 1) {
  524. char *endp;
  525. simple_strtoul(argv[1], &endp, 16);
  526. /* endp pointing to NULL means that argv[1] was just a
  527. * valid number, pass it along to the normal bootm processing
  528. *
  529. * If endp is ':' or '#' assume a FIT identifier so pass
  530. * along for normal processing.
  531. *
  532. * Right now we assume the first arg should never be '-'
  533. */
  534. if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
  535. return do_bootm_subcommand(cmdtp, flag, argc, argv);
  536. }
  537. if (bootm_start(cmdtp, flag, argc, argv))
  538. return 1;
  539. /*
  540. * We have reached the point of no return: we are going to
  541. * overwrite all exception vector code, so we cannot easily
  542. * recover from any failures any more...
  543. */
  544. iflag = disable_interrupts();
  545. #if defined(CONFIG_CMD_USB)
  546. /*
  547. * turn off USB to prevent the host controller from writing to the
  548. * SDRAM while Linux is booting. This could happen (at least for OHCI
  549. * controller), because the HCCA (Host Controller Communication Area)
  550. * lies within the SDRAM and the host controller writes continously to
  551. * this area (as busmaster!). The HccaFrameNumber is for example
  552. * updated every 1 ms within the HCCA structure in SDRAM! For more
  553. * details see the OpenHCI specification.
  554. */
  555. usb_stop();
  556. #endif
  557. ret = bootm_load_os(images.os, &load_end, 1);
  558. if (ret < 0) {
  559. if (ret == BOOTM_ERR_RESET)
  560. do_reset(cmdtp, flag, argc, argv);
  561. if (ret == BOOTM_ERR_OVERLAP) {
  562. if (images.legacy_hdr_valid) {
  563. image_header_t *hdr;
  564. hdr = &images.legacy_hdr_os_copy;
  565. if (image_get_type(hdr) == IH_TYPE_MULTI)
  566. puts("WARNING: legacy format multi "
  567. "component image "
  568. "overwritten\n");
  569. } else {
  570. puts("ERROR: new format image overwritten - "
  571. "must RESET the board to recover\n");
  572. show_boot_progress(-113);
  573. do_reset(cmdtp, flag, argc, argv);
  574. }
  575. }
  576. if (ret == BOOTM_ERR_UNIMPLEMENTED) {
  577. if (iflag)
  578. enable_interrupts();
  579. show_boot_progress(-7);
  580. return 1;
  581. }
  582. }
  583. lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
  584. if (images.os.type == IH_TYPE_STANDALONE) {
  585. if (iflag)
  586. enable_interrupts();
  587. /* This may return when 'autostart' is 'no' */
  588. bootm_start_standalone(iflag, argc, argv);
  589. return 0;
  590. }
  591. show_boot_progress(8);
  592. #ifdef CONFIG_SILENT_CONSOLE
  593. if (images.os.os == IH_OS_LINUX)
  594. fixup_silent_linux();
  595. #endif
  596. boot_fn = boot_os[images.os.os];
  597. if (boot_fn == NULL) {
  598. if (iflag)
  599. enable_interrupts();
  600. printf("ERROR: booting os '%s' (%d) is not supported\n",
  601. genimg_get_os_name(images.os.os), images.os.os);
  602. show_boot_progress(-8);
  603. return 1;
  604. }
  605. arch_preboot_os();
  606. boot_fn(0, argc, argv, &images);
  607. show_boot_progress(-9);
  608. #ifdef DEBUG
  609. puts("\n## Control returned to monitor - resetting...\n");
  610. #endif
  611. do_reset(cmdtp, flag, argc, argv);
  612. return 1;
  613. }
  614. int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
  615. {
  616. const char *ep = getenv("autostart");
  617. if (ep && !strcmp(ep, "yes")) {
  618. char *local_args[2];
  619. local_args[0] = (char *)cmd;
  620. local_args[1] = NULL;
  621. printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
  622. return do_bootm(cmdtp, 0, 1, local_args);
  623. }
  624. return 0;
  625. }
  626. /**
  627. * image_get_kernel - verify legacy format kernel image
  628. * @img_addr: in RAM address of the legacy format image to be verified
  629. * @verify: data CRC verification flag
  630. *
  631. * image_get_kernel() verifies legacy image integrity and returns pointer to
  632. * legacy image header if image verification was completed successfully.
  633. *
  634. * returns:
  635. * pointer to a legacy image header if valid image was found
  636. * otherwise return NULL
  637. */
  638. static image_header_t *image_get_kernel(ulong img_addr, int verify)
  639. {
  640. image_header_t *hdr = (image_header_t *)img_addr;
  641. if (!image_check_magic(hdr)) {
  642. puts("Bad Magic Number\n");
  643. show_boot_progress(-1);
  644. return NULL;
  645. }
  646. show_boot_progress(2);
  647. if (!image_check_hcrc(hdr)) {
  648. puts("Bad Header Checksum\n");
  649. show_boot_progress(-2);
  650. return NULL;
  651. }
  652. show_boot_progress(3);
  653. image_print_contents(hdr);
  654. if (verify) {
  655. puts(" Verifying Checksum ... ");
  656. if (!image_check_dcrc(hdr)) {
  657. printf("Bad Data CRC\n");
  658. show_boot_progress(-3);
  659. return NULL;
  660. }
  661. puts("OK\n");
  662. }
  663. show_boot_progress(4);
  664. if (!image_check_target_arch(hdr)) {
  665. printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
  666. show_boot_progress(-4);
  667. return NULL;
  668. }
  669. return hdr;
  670. }
  671. /**
  672. * fit_check_kernel - verify FIT format kernel subimage
  673. * @fit_hdr: pointer to the FIT image header
  674. * os_noffset: kernel subimage node offset within FIT image
  675. * @verify: data CRC verification flag
  676. *
  677. * fit_check_kernel() verifies integrity of the kernel subimage and from
  678. * specified FIT image.
  679. *
  680. * returns:
  681. * 1, on success
  682. * 0, on failure
  683. */
  684. #if defined(CONFIG_FIT)
  685. static int fit_check_kernel(const void *fit, int os_noffset, int verify)
  686. {
  687. fit_image_print(fit, os_noffset, " ");
  688. if (verify) {
  689. puts(" Verifying Hash Integrity ... ");
  690. if (!fit_image_check_hashes(fit, os_noffset)) {
  691. puts("Bad Data Hash\n");
  692. show_boot_progress(-104);
  693. return 0;
  694. }
  695. puts("OK\n");
  696. }
  697. show_boot_progress(105);
  698. if (!fit_image_check_target_arch(fit, os_noffset)) {
  699. puts("Unsupported Architecture\n");
  700. show_boot_progress(-105);
  701. return 0;
  702. }
  703. show_boot_progress(106);
  704. if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL) &&
  705. !fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL_NOLOAD)) {
  706. puts("Not a kernel image\n");
  707. show_boot_progress(-106);
  708. return 0;
  709. }
  710. show_boot_progress(107);
  711. return 1;
  712. }
  713. #endif /* CONFIG_FIT */
  714. /**
  715. * boot_get_kernel - find kernel image
  716. * @os_data: pointer to a ulong variable, will hold os data start address
  717. * @os_len: pointer to a ulong variable, will hold os data length
  718. *
  719. * boot_get_kernel() tries to find a kernel image, verifies its integrity
  720. * and locates kernel data.
  721. *
  722. * returns:
  723. * pointer to image header if valid image was found, plus kernel start
  724. * address and length, otherwise NULL
  725. */
  726. static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
  727. char * const argv[], bootm_headers_t *images, ulong *os_data,
  728. ulong *os_len)
  729. {
  730. image_header_t *hdr;
  731. ulong img_addr;
  732. #if defined(CONFIG_FIT)
  733. void *fit_hdr;
  734. const char *fit_uname_config = NULL;
  735. const char *fit_uname_kernel = NULL;
  736. const void *data;
  737. size_t len;
  738. int cfg_noffset;
  739. int os_noffset;
  740. #endif
  741. /* find out kernel image address */
  742. if (argc < 2) {
  743. img_addr = load_addr;
  744. debug("* kernel: default image load address = 0x%08lx\n",
  745. load_addr);
  746. #if defined(CONFIG_FIT)
  747. } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
  748. &fit_uname_config)) {
  749. debug("* kernel: config '%s' from image at 0x%08lx\n",
  750. fit_uname_config, img_addr);
  751. } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
  752. &fit_uname_kernel)) {
  753. debug("* kernel: subimage '%s' from image at 0x%08lx\n",
  754. fit_uname_kernel, img_addr);
  755. #endif
  756. } else {
  757. img_addr = simple_strtoul(argv[1], NULL, 16);
  758. debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
  759. }
  760. show_boot_progress(1);
  761. /* copy from dataflash if needed */
  762. img_addr = genimg_get_image(img_addr);
  763. /* check image type, for FIT images get FIT kernel node */
  764. *os_data = *os_len = 0;
  765. switch (genimg_get_format((void *)img_addr)) {
  766. case IMAGE_FORMAT_LEGACY:
  767. printf("## Booting kernel from Legacy Image at %08lx ...\n",
  768. img_addr);
  769. hdr = image_get_kernel(img_addr, images->verify);
  770. if (!hdr)
  771. return NULL;
  772. show_boot_progress(5);
  773. /* get os_data and os_len */
  774. switch (image_get_type(hdr)) {
  775. case IH_TYPE_KERNEL:
  776. case IH_TYPE_KERNEL_NOLOAD:
  777. *os_data = image_get_data(hdr);
  778. *os_len = image_get_data_size(hdr);
  779. break;
  780. case IH_TYPE_MULTI:
  781. image_multi_getimg(hdr, 0, os_data, os_len);
  782. break;
  783. case IH_TYPE_STANDALONE:
  784. *os_data = image_get_data(hdr);
  785. *os_len = image_get_data_size(hdr);
  786. break;
  787. default:
  788. printf("Wrong Image Type for %s command\n",
  789. cmdtp->name);
  790. show_boot_progress(-5);
  791. return NULL;
  792. }
  793. /*
  794. * copy image header to allow for image overwrites during
  795. * kernel decompression.
  796. */
  797. memmove(&images->legacy_hdr_os_copy, hdr,
  798. sizeof(image_header_t));
  799. /* save pointer to image header */
  800. images->legacy_hdr_os = hdr;
  801. images->legacy_hdr_valid = 1;
  802. show_boot_progress(6);
  803. break;
  804. #if defined(CONFIG_FIT)
  805. case IMAGE_FORMAT_FIT:
  806. fit_hdr = (void *)img_addr;
  807. printf("## Booting kernel from FIT Image at %08lx ...\n",
  808. img_addr);
  809. if (!fit_check_format(fit_hdr)) {
  810. puts("Bad FIT kernel image format!\n");
  811. show_boot_progress(-100);
  812. return NULL;
  813. }
  814. show_boot_progress(100);
  815. if (!fit_uname_kernel) {
  816. /*
  817. * no kernel image node unit name, try to get config
  818. * node first. If config unit node name is NULL
  819. * fit_conf_get_node() will try to find default config
  820. * node
  821. */
  822. show_boot_progress(101);
  823. cfg_noffset = fit_conf_get_node(fit_hdr,
  824. fit_uname_config);
  825. if (cfg_noffset < 0) {
  826. show_boot_progress(-101);
  827. return NULL;
  828. }
  829. /* save configuration uname provided in the first
  830. * bootm argument
  831. */
  832. images->fit_uname_cfg = fdt_get_name(fit_hdr,
  833. cfg_noffset,
  834. NULL);
  835. printf(" Using '%s' configuration\n",
  836. images->fit_uname_cfg);
  837. show_boot_progress(103);
  838. os_noffset = fit_conf_get_kernel_node(fit_hdr,
  839. cfg_noffset);
  840. fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
  841. NULL);
  842. } else {
  843. /* get kernel component image node offset */
  844. show_boot_progress(102);
  845. os_noffset = fit_image_get_node(fit_hdr,
  846. fit_uname_kernel);
  847. }
  848. if (os_noffset < 0) {
  849. show_boot_progress(-103);
  850. return NULL;
  851. }
  852. printf(" Trying '%s' kernel subimage\n", fit_uname_kernel);
  853. show_boot_progress(104);
  854. if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
  855. return NULL;
  856. /* get kernel image data address and length */
  857. if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
  858. puts("Could not find kernel subimage data!\n");
  859. show_boot_progress(-107);
  860. return NULL;
  861. }
  862. show_boot_progress(108);
  863. *os_len = len;
  864. *os_data = (ulong)data;
  865. images->fit_hdr_os = fit_hdr;
  866. images->fit_uname_os = fit_uname_kernel;
  867. images->fit_noffset_os = os_noffset;
  868. break;
  869. #endif
  870. default:
  871. printf("Wrong Image Format for %s command\n", cmdtp->name);
  872. show_boot_progress(-108);
  873. return NULL;
  874. }
  875. debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
  876. *os_data, *os_len, *os_len);
  877. return (void *)img_addr;
  878. }
  879. U_BOOT_CMD(
  880. bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
  881. "boot application image from memory",
  882. "[addr [arg ...]]\n - boot application image stored in memory\n"
  883. "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
  884. "\t'arg' can be the address of an initrd image\n"
  885. #if defined(CONFIG_OF_LIBFDT)
  886. "\tWhen booting a Linux kernel which requires a flat device-tree\n"
  887. "\ta third argument is required which is the address of the\n"
  888. "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
  889. "\tuse a '-' for the second argument. If you do not pass a third\n"
  890. "\ta bd_info struct will be passed instead\n"
  891. #endif
  892. #if defined(CONFIG_FIT)
  893. "\t\nFor the new multi component uImage format (FIT) addresses\n"
  894. "\tmust be extened to include component or configuration unit name:\n"
  895. "\taddr:<subimg_uname> - direct component image specification\n"
  896. "\taddr#<conf_uname> - configuration specification\n"
  897. "\tUse iminfo command to get the list of existing component\n"
  898. "\timages and configurations.\n"
  899. #endif
  900. "\nSub-commands to do part of the bootm sequence. The sub-commands "
  901. "must be\n"
  902. "issued in the order below (it's ok to not issue all sub-commands):\n"
  903. "\tstart [addr [arg ...]]\n"
  904. "\tloados - load OS image\n"
  905. #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
  906. "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
  907. #endif
  908. #if defined(CONFIG_OF_LIBFDT)
  909. "\tfdt - relocate flat device tree\n"
  910. #endif
  911. "\tcmdline - OS specific command line processing/setup\n"
  912. "\tbdt - OS specific bd_t processing\n"
  913. "\tprep - OS specific prep before relocation or go\n"
  914. "\tgo - start OS"
  915. );
  916. /*******************************************************************/
  917. /* bootd - boot default image */
  918. /*******************************************************************/
  919. #if defined(CONFIG_CMD_BOOTD)
  920. int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  921. {
  922. int rcode = 0;
  923. #ifndef CONFIG_SYS_HUSH_PARSER
  924. if (builtin_run_command(getenv("bootcmd"), flag) < 0)
  925. rcode = 1;
  926. #else
  927. if (parse_string_outer(getenv("bootcmd"),
  928. FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
  929. rcode = 1;
  930. #endif
  931. return rcode;
  932. }
  933. U_BOOT_CMD(
  934. boot, 1, 1, do_bootd,
  935. "boot default, i.e., run 'bootcmd'",
  936. ""
  937. );
  938. /* keep old command name "bootd" for backward compatibility */
  939. U_BOOT_CMD(
  940. bootd, 1, 1, do_bootd,
  941. "boot default, i.e., run 'bootcmd'",
  942. ""
  943. );
  944. #endif
  945. /*******************************************************************/
  946. /* iminfo - print header info for a requested image */
  947. /*******************************************************************/
  948. #if defined(CONFIG_CMD_IMI)
  949. int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  950. {
  951. int arg;
  952. ulong addr;
  953. int rcode = 0;
  954. if (argc < 2) {
  955. return image_info(load_addr);
  956. }
  957. for (arg = 1; arg < argc; ++arg) {
  958. addr = simple_strtoul(argv[arg], NULL, 16);
  959. if (image_info(addr) != 0)
  960. rcode = 1;
  961. }
  962. return rcode;
  963. }
  964. static int image_info(ulong addr)
  965. {
  966. void *hdr = (void *)addr;
  967. printf("\n## Checking Image at %08lx ...\n", addr);
  968. switch (genimg_get_format(hdr)) {
  969. case IMAGE_FORMAT_LEGACY:
  970. puts(" Legacy image found\n");
  971. if (!image_check_magic(hdr)) {
  972. puts(" Bad Magic Number\n");
  973. return 1;
  974. }
  975. if (!image_check_hcrc(hdr)) {
  976. puts(" Bad Header Checksum\n");
  977. return 1;
  978. }
  979. image_print_contents(hdr);
  980. puts(" Verifying Checksum ... ");
  981. if (!image_check_dcrc(hdr)) {
  982. puts(" Bad Data CRC\n");
  983. return 1;
  984. }
  985. puts("OK\n");
  986. return 0;
  987. #if defined(CONFIG_FIT)
  988. case IMAGE_FORMAT_FIT:
  989. puts(" FIT image found\n");
  990. if (!fit_check_format(hdr)) {
  991. puts("Bad FIT image format!\n");
  992. return 1;
  993. }
  994. fit_print_contents(hdr);
  995. if (!fit_all_image_check_hashes(hdr)) {
  996. puts("Bad hash in FIT image!\n");
  997. return 1;
  998. }
  999. return 0;
  1000. #endif
  1001. default:
  1002. puts("Unknown image format!\n");
  1003. break;
  1004. }
  1005. return 1;
  1006. }
  1007. U_BOOT_CMD(
  1008. iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
  1009. "print header information for application image",
  1010. "addr [addr ...]\n"
  1011. " - print header information for application image starting at\n"
  1012. " address 'addr' in memory; this includes verification of the\n"
  1013. " image contents (magic number, header and payload checksums)"
  1014. );
  1015. #endif
  1016. /*******************************************************************/
  1017. /* imls - list all images found in flash */
  1018. /*******************************************************************/
  1019. #if defined(CONFIG_CMD_IMLS)
  1020. int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1021. {
  1022. flash_info_t *info;
  1023. int i, j;
  1024. void *hdr;
  1025. for (i = 0, info = &flash_info[0];
  1026. i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
  1027. if (info->flash_id == FLASH_UNKNOWN)
  1028. goto next_bank;
  1029. for (j = 0; j < info->sector_count; ++j) {
  1030. hdr = (void *)info->start[j];
  1031. if (!hdr)
  1032. goto next_sector;
  1033. switch (genimg_get_format(hdr)) {
  1034. case IMAGE_FORMAT_LEGACY:
  1035. if (!image_check_hcrc(hdr))
  1036. goto next_sector;
  1037. printf("Legacy Image at %08lX:\n", (ulong)hdr);
  1038. image_print_contents(hdr);
  1039. puts(" Verifying Checksum ... ");
  1040. if (!image_check_dcrc(hdr)) {
  1041. puts("Bad Data CRC\n");
  1042. } else {
  1043. puts("OK\n");
  1044. }
  1045. break;
  1046. #if defined(CONFIG_FIT)
  1047. case IMAGE_FORMAT_FIT:
  1048. if (!fit_check_format(hdr))
  1049. goto next_sector;
  1050. printf("FIT Image at %08lX:\n", (ulong)hdr);
  1051. fit_print_contents(hdr);
  1052. break;
  1053. #endif
  1054. default:
  1055. goto next_sector;
  1056. }
  1057. next_sector: ;
  1058. }
  1059. next_bank: ;
  1060. }
  1061. return (0);
  1062. }
  1063. U_BOOT_CMD(
  1064. imls, 1, 1, do_imls,
  1065. "list all images found in flash",
  1066. "\n"
  1067. " - Prints information about all images found at sector\n"
  1068. " boundaries in flash."
  1069. );
  1070. #endif
  1071. /*******************************************************************/
  1072. /* helper routines */
  1073. /*******************************************************************/
  1074. #ifdef CONFIG_SILENT_CONSOLE
  1075. static void fixup_silent_linux(void)
  1076. {
  1077. char buf[256], *start, *end;
  1078. char *cmdline = getenv("bootargs");
  1079. /* Only fix cmdline when requested */
  1080. if (!(gd->flags & GD_FLG_SILENT))
  1081. return;
  1082. debug("before silent fix-up: %s\n", cmdline);
  1083. if (cmdline) {
  1084. start = strstr(cmdline, "console=");
  1085. if (start) {
  1086. end = strchr(start, ' ');
  1087. strncpy(buf, cmdline, (start - cmdline + 8));
  1088. if (end)
  1089. strcpy(buf + (start - cmdline + 8), end);
  1090. else
  1091. buf[start - cmdline + 8] = '\0';
  1092. } else {
  1093. strcpy(buf, cmdline);
  1094. strcat(buf, " console=");
  1095. }
  1096. } else {
  1097. strcpy(buf, "console=");
  1098. }
  1099. setenv("bootargs", buf);
  1100. debug("after silent fix-up: %s\n", buf);
  1101. }
  1102. #endif /* CONFIG_SILENT_CONSOLE */
  1103. /*******************************************************************/
  1104. /* OS booting routines */
  1105. /*******************************************************************/
  1106. #ifdef CONFIG_BOOTM_NETBSD
  1107. static int do_bootm_netbsd(int flag, int argc, char * const argv[],
  1108. bootm_headers_t *images)
  1109. {
  1110. void (*loader)(bd_t *, image_header_t *, char *, char *);
  1111. image_header_t *os_hdr, *hdr;
  1112. ulong kernel_data, kernel_len;
  1113. char *consdev;
  1114. char *cmdline;
  1115. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1116. return 1;
  1117. #if defined(CONFIG_FIT)
  1118. if (!images->legacy_hdr_valid) {
  1119. fit_unsupported_reset("NetBSD");
  1120. return 1;
  1121. }
  1122. #endif
  1123. hdr = images->legacy_hdr_os;
  1124. /*
  1125. * Booting a (NetBSD) kernel image
  1126. *
  1127. * This process is pretty similar to a standalone application:
  1128. * The (first part of an multi-) image must be a stage-2 loader,
  1129. * which in turn is responsible for loading & invoking the actual
  1130. * kernel. The only differences are the parameters being passed:
  1131. * besides the board info strucure, the loader expects a command
  1132. * line, the name of the console device, and (optionally) the
  1133. * address of the original image header.
  1134. */
  1135. os_hdr = NULL;
  1136. if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
  1137. image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
  1138. if (kernel_len)
  1139. os_hdr = hdr;
  1140. }
  1141. consdev = "";
  1142. #if defined(CONFIG_8xx_CONS_SMC1)
  1143. consdev = "smc1";
  1144. #elif defined(CONFIG_8xx_CONS_SMC2)
  1145. consdev = "smc2";
  1146. #elif defined(CONFIG_8xx_CONS_SCC2)
  1147. consdev = "scc2";
  1148. #elif defined(CONFIG_8xx_CONS_SCC3)
  1149. consdev = "scc3";
  1150. #endif
  1151. if (argc > 2) {
  1152. ulong len;
  1153. int i;
  1154. for (i = 2, len = 0; i < argc; i += 1)
  1155. len += strlen(argv[i]) + 1;
  1156. cmdline = malloc(len);
  1157. for (i = 2, len = 0; i < argc; i += 1) {
  1158. if (i > 2)
  1159. cmdline[len++] = ' ';
  1160. strcpy(&cmdline[len], argv[i]);
  1161. len += strlen(argv[i]);
  1162. }
  1163. } else if ((cmdline = getenv("bootargs")) == NULL) {
  1164. cmdline = "";
  1165. }
  1166. loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
  1167. printf("## Transferring control to NetBSD stage-2 loader "
  1168. "(at address %08lx) ...\n",
  1169. (ulong)loader);
  1170. show_boot_progress(15);
  1171. /*
  1172. * NetBSD Stage-2 Loader Parameters:
  1173. * r3: ptr to board info data
  1174. * r4: image address
  1175. * r5: console device
  1176. * r6: boot args string
  1177. */
  1178. (*loader)(gd->bd, os_hdr, consdev, cmdline);
  1179. return 1;
  1180. }
  1181. #endif /* CONFIG_BOOTM_NETBSD*/
  1182. #ifdef CONFIG_LYNXKDI
  1183. static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
  1184. bootm_headers_t *images)
  1185. {
  1186. image_header_t *hdr = &images->legacy_hdr_os_copy;
  1187. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1188. return 1;
  1189. #if defined(CONFIG_FIT)
  1190. if (!images->legacy_hdr_valid) {
  1191. fit_unsupported_reset("Lynx");
  1192. return 1;
  1193. }
  1194. #endif
  1195. lynxkdi_boot((image_header_t *)hdr);
  1196. return 1;
  1197. }
  1198. #endif /* CONFIG_LYNXKDI */
  1199. #ifdef CONFIG_BOOTM_RTEMS
  1200. static int do_bootm_rtems(int flag, int argc, char * const argv[],
  1201. bootm_headers_t *images)
  1202. {
  1203. void (*entry_point)(bd_t *);
  1204. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1205. return 1;
  1206. #if defined(CONFIG_FIT)
  1207. if (!images->legacy_hdr_valid) {
  1208. fit_unsupported_reset("RTEMS");
  1209. return 1;
  1210. }
  1211. #endif
  1212. entry_point = (void (*)(bd_t *))images->ep;
  1213. printf("## Transferring control to RTEMS (at address %08lx) ...\n",
  1214. (ulong)entry_point);
  1215. show_boot_progress(15);
  1216. /*
  1217. * RTEMS Parameters:
  1218. * r3: ptr to board info data
  1219. */
  1220. (*entry_point)(gd->bd);
  1221. return 1;
  1222. }
  1223. #endif /* CONFIG_BOOTM_RTEMS */
  1224. #if defined(CONFIG_BOOTM_OSE)
  1225. static int do_bootm_ose(int flag, int argc, char * const argv[],
  1226. bootm_headers_t *images)
  1227. {
  1228. void (*entry_point)(void);
  1229. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1230. return 1;
  1231. #if defined(CONFIG_FIT)
  1232. if (!images->legacy_hdr_valid) {
  1233. fit_unsupported_reset("OSE");
  1234. return 1;
  1235. }
  1236. #endif
  1237. entry_point = (void (*)(void))images->ep;
  1238. printf("## Transferring control to OSE (at address %08lx) ...\n",
  1239. (ulong)entry_point);
  1240. show_boot_progress(15);
  1241. /*
  1242. * OSE Parameters:
  1243. * None
  1244. */
  1245. (*entry_point)();
  1246. return 1;
  1247. }
  1248. #endif /* CONFIG_BOOTM_OSE */
  1249. #if defined(CONFIG_CMD_ELF)
  1250. static int do_bootm_vxworks(int flag, int argc, char * const argv[],
  1251. bootm_headers_t *images)
  1252. {
  1253. char str[80];
  1254. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1255. return 1;
  1256. #if defined(CONFIG_FIT)
  1257. if (!images->legacy_hdr_valid) {
  1258. fit_unsupported_reset("VxWorks");
  1259. return 1;
  1260. }
  1261. #endif
  1262. sprintf(str, "%lx", images->ep); /* write entry-point into string */
  1263. setenv("loadaddr", str);
  1264. do_bootvx(NULL, 0, 0, NULL);
  1265. return 1;
  1266. }
  1267. static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
  1268. bootm_headers_t *images)
  1269. {
  1270. char *local_args[2];
  1271. char str[16];
  1272. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1273. return 1;
  1274. #if defined(CONFIG_FIT)
  1275. if (!images->legacy_hdr_valid) {
  1276. fit_unsupported_reset("QNX");
  1277. return 1;
  1278. }
  1279. #endif
  1280. sprintf(str, "%lx", images->ep); /* write entry-point into string */
  1281. local_args[0] = argv[0];
  1282. local_args[1] = str; /* and provide it via the arguments */
  1283. do_bootelf(NULL, 0, 2, local_args);
  1284. return 1;
  1285. }
  1286. #endif
  1287. #ifdef CONFIG_INTEGRITY
  1288. static int do_bootm_integrity(int flag, int argc, char * const argv[],
  1289. bootm_headers_t *images)
  1290. {
  1291. void (*entry_point)(void);
  1292. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  1293. return 1;
  1294. #if defined(CONFIG_FIT)
  1295. if (!images->legacy_hdr_valid) {
  1296. fit_unsupported_reset("INTEGRITY");
  1297. return 1;
  1298. }
  1299. #endif
  1300. entry_point = (void (*)(void))images->ep;
  1301. printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
  1302. (ulong)entry_point);
  1303. show_boot_progress(15);
  1304. /*
  1305. * INTEGRITY Parameters:
  1306. * None
  1307. */
  1308. (*entry_point)();
  1309. return 1;
  1310. }
  1311. #endif