cmd_bootm.c 37 KB

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