cmd_bootm.c 36 KB

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