cmd_bootm.c 35 KB

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