cmd_bootm.c 35 KB

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