cmd_bootm.c 37 KB

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