cmd_bootm.c 38 KB

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