cmd_bootm.c 38 KB

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