cmd_bootm.c 37 KB

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