cmd_bootm.c 37 KB

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