cmd_bootm.c 37 KB

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