cmd_bootm.c 35 KB

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