cmd_bootm.c 37 KB

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