cmd_bootm.c 37 KB

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