cmd_bootm.c 37 KB

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