cmd_bootm.c 37 KB

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