cmd_bootm.c 35 KB

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