cmd_bootm.c 37 KB

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