cmd_bootm.c 38 KB

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