cmd_bootm.c 37 KB

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