cmd_bootm.c 37 KB

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