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