cmd_bootm.c 37 KB

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