cmd_bootm.c 37 KB

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