cmd_bootm.c 37 KB

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