cmd_bootm.c 37 KB

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