cmd_bootm.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. /*
  2. * (C) Copyright 2000-2002
  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 <zlib.h>
  32. #include <bzlib.h>
  33. #include <environment.h>
  34. #include <asm/byteorder.h>
  35. /*cmd_boot.c*/
  36. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  37. #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
  38. #include <rtc.h>
  39. #endif
  40. #ifdef CFG_HUSH_PARSER
  41. #include <hush.h>
  42. #endif
  43. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  44. # include <status_led.h>
  45. # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
  46. #else
  47. # define SHOW_BOOT_PROGRESS(arg)
  48. #endif
  49. #ifdef CFG_INIT_RAM_LOCK
  50. #include <asm/cache.h>
  51. #endif
  52. #ifdef CONFIG_LOGBUFFER
  53. #include <logbuff.h>
  54. #endif
  55. #ifdef CONFIG_HAS_DATAFLASH
  56. #include <dataflash.h>
  57. #endif
  58. /*
  59. * Some systems (for example LWMON) have very short watchdog periods;
  60. * we must make sure to split long operations like memmove() or
  61. * crc32() into reasonable chunks.
  62. */
  63. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  64. # define CHUNKSZ (64 * 1024)
  65. #endif
  66. int gunzip (void *, int, unsigned char *, int *);
  67. static void *zalloc(void *, unsigned, unsigned);
  68. static void zfree(void *, void *, unsigned);
  69. #if (CONFIG_COMMANDS & CFG_CMD_IMI)
  70. static int image_info (unsigned long addr);
  71. #endif
  72. #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
  73. #include <flash.h>
  74. extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
  75. static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  76. #endif
  77. static void print_type (image_header_t *hdr);
  78. #ifdef __I386__
  79. image_header_t *fake_header(image_header_t *hdr, void *ptr, int size);
  80. #endif
  81. /*
  82. * Continue booting an OS image; caller already has:
  83. * - copied image header to global variable `header'
  84. * - checked header magic number, checksums (both header & image),
  85. * - verified image architecture (PPC) and type (KERNEL or MULTI),
  86. * - loaded (first part of) image to header load address,
  87. * - disabled interrupts.
  88. */
  89. typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
  90. int argc, char *argv[],
  91. ulong addr, /* of image to boot */
  92. ulong *len_ptr, /* multi-file image length table */
  93. int verify); /* getenv("verify")[0] != 'n' */
  94. #ifdef DEBUG
  95. extern int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  96. #endif
  97. #ifdef CONFIG_PPC
  98. static boot_os_Fcn do_bootm_linux;
  99. #else
  100. extern boot_os_Fcn do_bootm_linux;
  101. #endif
  102. static boot_os_Fcn do_bootm_netbsd;
  103. static boot_os_Fcn do_bootm_rtems;
  104. #if (CONFIG_COMMANDS & CFG_CMD_ELF)
  105. static boot_os_Fcn do_bootm_vxworks;
  106. static boot_os_Fcn do_bootm_qnxelf;
  107. int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
  108. int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
  109. #endif /* CFG_CMD_ELF */
  110. #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
  111. static boot_os_Fcn do_bootm_artos;
  112. #endif
  113. #ifdef CONFIG_LYNXKDI
  114. static boot_os_Fcn do_bootm_lynxkdi;
  115. extern void lynxkdi_boot( image_header_t * );
  116. #endif
  117. image_header_t header;
  118. ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
  119. int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  120. {
  121. ulong iflag;
  122. ulong addr;
  123. ulong data, len, checksum;
  124. ulong *len_ptr;
  125. uint unc_len = 0x400000;
  126. int i, verify;
  127. char *name, *s;
  128. int (*appl)(cmd_tbl_t *, int, int, char *[]);
  129. image_header_t *hdr = &header;
  130. s = getenv ("verify");
  131. verify = (s && (*s == 'n')) ? 0 : 1;
  132. if (argc < 2) {
  133. addr = load_addr;
  134. } else {
  135. addr = simple_strtoul(argv[1], NULL, 16);
  136. }
  137. SHOW_BOOT_PROGRESS (1);
  138. printf ("## Booting image at %08lx ...\n", addr);
  139. /* Copy header so we can blank CRC field for re-calculation */
  140. #ifdef CONFIG_HAS_DATAFLASH
  141. if (addr_dataflash(addr)){
  142. read_dataflash(addr, sizeof(image_header_t), (char *)&header);
  143. } else
  144. #endif
  145. memmove (&header, (char *)addr, sizeof(image_header_t));
  146. if (ntohl(hdr->ih_magic) != IH_MAGIC) {
  147. #ifdef __I386__ /* correct image format not implemented yet - fake it */
  148. if (fake_header(hdr, (void*)addr, -1) != NULL) {
  149. /* to compensate for the addition below */
  150. addr -= sizeof(image_header_t);
  151. /* turnof verify,
  152. * fake_header() does not fake the data crc
  153. */
  154. verify = 0;
  155. } else
  156. #endif /* __I386__ */
  157. {
  158. printf ("Bad Magic Number\n");
  159. SHOW_BOOT_PROGRESS (-1);
  160. return 1;
  161. }
  162. }
  163. SHOW_BOOT_PROGRESS (2);
  164. data = (ulong)&header;
  165. len = sizeof(image_header_t);
  166. checksum = ntohl(hdr->ih_hcrc);
  167. hdr->ih_hcrc = 0;
  168. if (crc32 (0, (char *)data, len) != checksum) {
  169. printf ("Bad Header Checksum\n");
  170. SHOW_BOOT_PROGRESS (-2);
  171. return 1;
  172. }
  173. SHOW_BOOT_PROGRESS (3);
  174. /* for multi-file images we need the data part, too */
  175. print_image_hdr (hdr);
  176. data = addr + sizeof(image_header_t);
  177. len = ntohl(hdr->ih_size);
  178. #ifdef CONFIG_HAS_DATAFLASH
  179. if (addr_dataflash(addr)){
  180. read_dataflash(data, len, (char *)CFG_LOAD_ADDR);
  181. data = CFG_LOAD_ADDR;
  182. }
  183. #endif
  184. if (verify) {
  185. printf (" Verifying Checksum ... ");
  186. if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
  187. printf ("Bad Data CRC\n");
  188. SHOW_BOOT_PROGRESS (-3);
  189. return 1;
  190. }
  191. printf ("OK\n");
  192. }
  193. SHOW_BOOT_PROGRESS (4);
  194. len_ptr = (ulong *)data;
  195. #if defined(__PPC__)
  196. if (hdr->ih_arch != IH_CPU_PPC)
  197. #elif defined(__ARM__)
  198. if (hdr->ih_arch != IH_CPU_ARM)
  199. #elif defined(__I386__)
  200. if (hdr->ih_arch != IH_CPU_I386)
  201. #elif defined(__mips__)
  202. if (hdr->ih_arch != IH_CPU_MIPS)
  203. #elif defined(__nios__)
  204. if (hdr->ih_arch != IH_CPU_NIOS)
  205. #else
  206. # error Unknown CPU type
  207. #endif
  208. {
  209. printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
  210. SHOW_BOOT_PROGRESS (-4);
  211. return 1;
  212. }
  213. SHOW_BOOT_PROGRESS (5);
  214. switch (hdr->ih_type) {
  215. case IH_TYPE_STANDALONE: name = "Standalone Application";
  216. /* A second argument overwrites the load address */
  217. if (argc > 2) {
  218. hdr->ih_load = simple_strtoul(argv[2], NULL, 16);
  219. }
  220. break;
  221. case IH_TYPE_KERNEL: name = "Kernel Image";
  222. break;
  223. case IH_TYPE_MULTI: name = "Multi-File Image";
  224. len = ntohl(len_ptr[0]);
  225. /* OS kernel is always the first image */
  226. data += 8; /* kernel_len + terminator */
  227. for (i=1; len_ptr[i]; ++i)
  228. data += 4;
  229. break;
  230. default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
  231. SHOW_BOOT_PROGRESS (-5);
  232. return 1;
  233. }
  234. SHOW_BOOT_PROGRESS (6);
  235. /*
  236. * We have reached the point of no return: we are going to
  237. * overwrite all exception vector code, so we cannot easily
  238. * recover from any failures any more...
  239. */
  240. iflag = disable_interrupts();
  241. #ifdef CONFIG_AMIGAONEG3SE
  242. /*
  243. * We've possible left the caches enabled during
  244. * bios emulation, so turn them off again
  245. */
  246. icache_disable();
  247. invalidate_l1_instruction_cache();
  248. flush_data_cache();
  249. dcache_disable();
  250. #endif
  251. switch (hdr->ih_comp) {
  252. case IH_COMP_NONE:
  253. if(ntohl(hdr->ih_load) == addr) {
  254. printf (" XIP %s ... ", name);
  255. } else {
  256. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  257. size_t l = len;
  258. void *to = (void *)ntohl(hdr->ih_load);
  259. void *from = (void *)data;
  260. printf (" Loading %s ... ", name);
  261. while (l > 0) {
  262. size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
  263. WATCHDOG_RESET();
  264. memmove (to, from, tail);
  265. to += tail;
  266. from += tail;
  267. l -= tail;
  268. }
  269. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  270. memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
  271. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  272. }
  273. break;
  274. case IH_COMP_GZIP:
  275. printf (" Uncompressing %s ... ", name);
  276. if (gunzip ((void *)ntohl(hdr->ih_load), unc_len,
  277. (uchar *)data, (int *)&len) != 0) {
  278. printf ("GUNZIP ERROR - must RESET board to recover\n");
  279. SHOW_BOOT_PROGRESS (-6);
  280. do_reset (cmdtp, flag, argc, argv);
  281. }
  282. break;
  283. #ifdef CONFIG_BZIP2
  284. case IH_COMP_BZIP2:
  285. printf (" Uncompressing %s ... ", name);
  286. i = BZ2_bzBuffToBuffDecompress ((char*)ntohl(hdr->ih_load),
  287. &unc_len, (char *)data, len, 0, 0);
  288. if (i != BZ_OK) {
  289. printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
  290. SHOW_BOOT_PROGRESS (-6);
  291. udelay(100000);
  292. do_reset (cmdtp, flag, argc, argv);
  293. }
  294. break;
  295. #endif /* CONFIG_BZIP2 */
  296. default:
  297. if (iflag)
  298. enable_interrupts();
  299. printf ("Unimplemented compression type %d\n", hdr->ih_comp);
  300. SHOW_BOOT_PROGRESS (-7);
  301. return 1;
  302. }
  303. printf ("OK\n");
  304. SHOW_BOOT_PROGRESS (7);
  305. switch (hdr->ih_type) {
  306. case IH_TYPE_STANDALONE:
  307. if (iflag)
  308. enable_interrupts();
  309. /* load (and uncompress), but don't start if "autostart"
  310. * is set to "no"
  311. */
  312. if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
  313. char buf[32];
  314. sprintf(buf, "%lX", len);
  315. setenv("filesize", buf);
  316. return 0;
  317. }
  318. appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
  319. (*appl)(cmdtp, flag, argc-1, &argv[1]);
  320. return 0;
  321. case IH_TYPE_KERNEL:
  322. case IH_TYPE_MULTI:
  323. /* handled below */
  324. break;
  325. default:
  326. if (iflag)
  327. enable_interrupts();
  328. printf ("Can't boot image type %d\n", hdr->ih_type);
  329. SHOW_BOOT_PROGRESS (-8);
  330. return 1;
  331. }
  332. SHOW_BOOT_PROGRESS (8);
  333. switch (hdr->ih_os) {
  334. default: /* handled by (original) Linux case */
  335. case IH_OS_LINUX:
  336. do_bootm_linux (cmdtp, flag, argc, argv,
  337. addr, len_ptr, verify);
  338. break;
  339. case IH_OS_NETBSD:
  340. do_bootm_netbsd (cmdtp, flag, argc, argv,
  341. addr, len_ptr, verify);
  342. break;
  343. #ifdef CONFIG_LYNXKDI
  344. case IH_OS_LYNXOS:
  345. do_bootm_lynxkdi (cmdtp, flag, argc, argv,
  346. addr, len_ptr, verify);
  347. break;
  348. #endif
  349. case IH_OS_RTEMS:
  350. do_bootm_rtems (cmdtp, flag, argc, argv,
  351. addr, len_ptr, verify);
  352. break;
  353. #if (CONFIG_COMMANDS & CFG_CMD_ELF)
  354. case IH_OS_VXWORKS:
  355. do_bootm_vxworks (cmdtp, flag, argc, argv,
  356. addr, len_ptr, verify);
  357. break;
  358. case IH_OS_QNX:
  359. do_bootm_qnxelf (cmdtp, flag, argc, argv,
  360. addr, len_ptr, verify);
  361. break;
  362. #endif /* CFG_CMD_ELF */
  363. #ifdef CONFIG_ARTOS
  364. case IH_OS_ARTOS:
  365. do_bootm_artos (cmdtp, flag, argc, argv,
  366. addr, len_ptr, verify);
  367. break;
  368. #endif
  369. }
  370. SHOW_BOOT_PROGRESS (-9);
  371. #ifdef DEBUG
  372. printf ("\n## Control returned to monitor - resetting...\n");
  373. do_reset (cmdtp, flag, argc, argv);
  374. #endif
  375. return 1;
  376. }
  377. U_BOOT_CMD(
  378. bootm, CFG_MAXARGS, 1, do_bootm,
  379. "bootm - boot application image from memory\n",
  380. "[addr [arg ...]]\n - boot application image stored in memory\n"
  381. " passing arguments 'arg ...'; when booting a Linux kernel,\n"
  382. " 'arg' can be the address of an initrd image\n"
  383. );
  384. #ifdef CONFIG_PPC
  385. static void
  386. do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
  387. int argc, char *argv[],
  388. ulong addr,
  389. ulong *len_ptr,
  390. int verify)
  391. {
  392. DECLARE_GLOBAL_DATA_PTR;
  393. ulong sp;
  394. ulong len, checksum;
  395. ulong initrd_start, initrd_end;
  396. ulong cmd_start, cmd_end;
  397. ulong initrd_high;
  398. ulong data;
  399. int initrd_copy_to_ram = 1;
  400. char *cmdline;
  401. char *s;
  402. bd_t *kbd;
  403. void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
  404. image_header_t *hdr = &header;
  405. if ((s = getenv ("initrd_high")) != NULL) {
  406. /* a value of "no" or a similar string will act like 0,
  407. * turning the "load high" feature off. This is intentional.
  408. */
  409. initrd_high = simple_strtoul(s, NULL, 16);
  410. if (initrd_high == ~0)
  411. initrd_copy_to_ram = 0;
  412. } else { /* not set, no restrictions to load high */
  413. initrd_high = ~0;
  414. }
  415. #ifdef CONFIG_LOGBUFFER
  416. kbd=gd->bd;
  417. /* Prevent initrd from overwriting logbuffer */
  418. if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
  419. initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
  420. debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
  421. #endif
  422. /*
  423. * Booting a (Linux) kernel image
  424. *
  425. * Allocate space for command line and board info - the
  426. * address should be as high as possible within the reach of
  427. * the kernel (see CFG_BOOTMAPSZ settings), but in unused
  428. * memory, which means far enough below the current stack
  429. * pointer.
  430. */
  431. asm( "mr %0,1": "=r"(sp) : );
  432. debug ("## Current stack ends at 0x%08lX ", sp);
  433. sp -= 2048; /* just to be sure */
  434. if (sp > CFG_BOOTMAPSZ)
  435. sp = CFG_BOOTMAPSZ;
  436. sp &= ~0xF;
  437. debug ("=> set upper limit to 0x%08lX\n", sp);
  438. cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
  439. kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
  440. if ((s = getenv("bootargs")) == NULL)
  441. s = "";
  442. strcpy (cmdline, s);
  443. cmd_start = (ulong)&cmdline[0];
  444. cmd_end = cmd_start + strlen(cmdline);
  445. *kbd = *(gd->bd);
  446. #ifdef DEBUG
  447. printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
  448. do_bdinfo (NULL, 0, 0, NULL);
  449. #endif
  450. if ((s = getenv ("clocks_in_mhz")) != NULL) {
  451. /* convert all clock information to MHz */
  452. kbd->bi_intfreq /= 1000000L;
  453. kbd->bi_busfreq /= 1000000L;
  454. #if defined(CONFIG_8260)
  455. kbd->bi_cpmfreq /= 1000000L;
  456. kbd->bi_brgfreq /= 1000000L;
  457. kbd->bi_sccfreq /= 1000000L;
  458. kbd->bi_vco /= 1000000L;
  459. #endif /* CONFIG_8260 */
  460. #if defined(CONFIG_MPC5XXXX)
  461. kbd->bi_ipbfreq /= 1000000L;
  462. kbd->bi_pcifreq /= 1000000L;
  463. #endif /* CONFIG_MPC5XXXX */
  464. }
  465. kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
  466. /*
  467. * Check if there is an initrd image
  468. */
  469. if (argc >= 3) {
  470. SHOW_BOOT_PROGRESS (9);
  471. addr = simple_strtoul(argv[2], NULL, 16);
  472. printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
  473. /* Copy header so we can blank CRC field for re-calculation */
  474. memmove (&header, (char *)addr, sizeof(image_header_t));
  475. if (hdr->ih_magic != IH_MAGIC) {
  476. printf ("Bad Magic Number\n");
  477. SHOW_BOOT_PROGRESS (-10);
  478. do_reset (cmdtp, flag, argc, argv);
  479. }
  480. data = (ulong)&header;
  481. len = sizeof(image_header_t);
  482. checksum = hdr->ih_hcrc;
  483. hdr->ih_hcrc = 0;
  484. if (crc32 (0, (char *)data, len) != checksum) {
  485. printf ("Bad Header Checksum\n");
  486. SHOW_BOOT_PROGRESS (-11);
  487. do_reset (cmdtp, flag, argc, argv);
  488. }
  489. SHOW_BOOT_PROGRESS (10);
  490. print_image_hdr (hdr);
  491. data = addr + sizeof(image_header_t);
  492. len = hdr->ih_size;
  493. if (verify) {
  494. ulong csum = 0;
  495. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  496. ulong cdata = data, edata = cdata + len;
  497. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  498. printf (" Verifying Checksum ... ");
  499. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  500. while (cdata < edata) {
  501. ulong chunk = edata - cdata;
  502. if (chunk > CHUNKSZ)
  503. chunk = CHUNKSZ;
  504. csum = crc32 (csum, (char *)cdata, chunk);
  505. cdata += chunk;
  506. WATCHDOG_RESET();
  507. }
  508. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  509. csum = crc32 (0, (char *)data, len);
  510. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  511. if (csum != hdr->ih_dcrc) {
  512. printf ("Bad Data CRC\n");
  513. SHOW_BOOT_PROGRESS (-12);
  514. do_reset (cmdtp, flag, argc, argv);
  515. }
  516. printf ("OK\n");
  517. }
  518. SHOW_BOOT_PROGRESS (11);
  519. if ((hdr->ih_os != IH_OS_LINUX) ||
  520. (hdr->ih_arch != IH_CPU_PPC) ||
  521. (hdr->ih_type != IH_TYPE_RAMDISK) ) {
  522. printf ("No Linux PPC Ramdisk Image\n");
  523. SHOW_BOOT_PROGRESS (-13);
  524. do_reset (cmdtp, flag, argc, argv);
  525. }
  526. /*
  527. * Now check if we have a multifile image
  528. */
  529. } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
  530. u_long tail = ntohl(len_ptr[0]) % 4;
  531. int i;
  532. SHOW_BOOT_PROGRESS (13);
  533. /* skip kernel length and terminator */
  534. data = (ulong)(&len_ptr[2]);
  535. /* skip any additional image length fields */
  536. for (i=1; len_ptr[i]; ++i)
  537. data += 4;
  538. /* add kernel length, and align */
  539. data += ntohl(len_ptr[0]);
  540. if (tail) {
  541. data += 4 - tail;
  542. }
  543. len = ntohl(len_ptr[1]);
  544. } else {
  545. /*
  546. * no initrd image
  547. */
  548. SHOW_BOOT_PROGRESS (14);
  549. len = data = 0;
  550. }
  551. if (!data) {
  552. debug ("No initrd\n");
  553. }
  554. if (data) {
  555. if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
  556. initrd_start = data;
  557. initrd_end = initrd_start + len;
  558. } else {
  559. initrd_start = (ulong)kbd - len;
  560. initrd_start &= ~(4096 - 1); /* align on page */
  561. if (initrd_high) {
  562. ulong nsp;
  563. /*
  564. * the inital ramdisk does not need to be within
  565. * CFG_BOOTMAPSZ as it is not accessed until after
  566. * the mm system is initialised.
  567. *
  568. * do the stack bottom calculation again and see if
  569. * the initrd will fit just below the monitor stack
  570. * bottom without overwriting the area allocated
  571. * above for command line args and board info.
  572. */
  573. asm( "mr %0,1": "=r"(nsp) : );
  574. nsp -= 2048; /* just to be sure */
  575. nsp &= ~0xF;
  576. if (nsp > initrd_high) /* limit as specified */
  577. nsp = initrd_high;
  578. nsp -= len;
  579. nsp &= ~(4096 - 1); /* align on page */
  580. if (nsp >= sp)
  581. initrd_start = nsp;
  582. }
  583. SHOW_BOOT_PROGRESS (12);
  584. debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
  585. data, data + len - 1, len, len);
  586. initrd_end = initrd_start + len;
  587. printf (" Loading Ramdisk to %08lx, end %08lx ... ",
  588. initrd_start, initrd_end);
  589. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  590. {
  591. size_t l = len;
  592. void *to = (void *)initrd_start;
  593. void *from = (void *)data;
  594. while (l > 0) {
  595. size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
  596. WATCHDOG_RESET();
  597. memmove (to, from, tail);
  598. to += tail;
  599. from += tail;
  600. l -= tail;
  601. }
  602. }
  603. #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
  604. memmove ((void *)initrd_start, (void *)data, len);
  605. #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
  606. printf ("OK\n");
  607. }
  608. } else {
  609. initrd_start = 0;
  610. initrd_end = 0;
  611. }
  612. debug ("## Transferring control to Linux (at address %08lx) ...\n",
  613. (ulong)kernel);
  614. SHOW_BOOT_PROGRESS (15);
  615. #ifdef CFG_INIT_RAM_LOCK
  616. unlock_ram_in_cache();
  617. #endif
  618. /*
  619. * Linux Kernel Parameters:
  620. * r3: ptr to board info data
  621. * r4: initrd_start or 0 if no initrd
  622. * r5: initrd_end - unused if r4 is 0
  623. * r6: Start of command line string
  624. * r7: End of command line string
  625. */
  626. (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
  627. }
  628. #endif /* CONFIG_PPC */
  629. static void
  630. do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
  631. int argc, char *argv[],
  632. ulong addr,
  633. ulong *len_ptr,
  634. int verify)
  635. {
  636. DECLARE_GLOBAL_DATA_PTR;
  637. image_header_t *hdr = &header;
  638. void (*loader)(bd_t *, image_header_t *, char *, char *);
  639. image_header_t *img_addr;
  640. char *consdev;
  641. char *cmdline;
  642. /*
  643. * Booting a (NetBSD) kernel image
  644. *
  645. * This process is pretty similar to a standalone application:
  646. * The (first part of an multi-) image must be a stage-2 loader,
  647. * which in turn is responsible for loading & invoking the actual
  648. * kernel. The only differences are the parameters being passed:
  649. * besides the board info strucure, the loader expects a command
  650. * line, the name of the console device, and (optionally) the
  651. * address of the original image header.
  652. */
  653. img_addr = 0;
  654. if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
  655. img_addr = (image_header_t *) addr;
  656. consdev = "";
  657. #if defined (CONFIG_8xx_CONS_SMC1)
  658. consdev = "smc1";
  659. #elif defined (CONFIG_8xx_CONS_SMC2)
  660. consdev = "smc2";
  661. #elif defined (CONFIG_8xx_CONS_SCC2)
  662. consdev = "scc2";
  663. #elif defined (CONFIG_8xx_CONS_SCC3)
  664. consdev = "scc3";
  665. #endif
  666. if (argc > 2) {
  667. ulong len;
  668. int i;
  669. for (i=2, len=0 ; i<argc ; i+=1)
  670. len += strlen (argv[i]) + 1;
  671. cmdline = malloc (len);
  672. for (i=2, len=0 ; i<argc ; i+=1) {
  673. if (i > 2)
  674. cmdline[len++] = ' ';
  675. strcpy (&cmdline[len], argv[i]);
  676. len += strlen (argv[i]);
  677. }
  678. } else if ((cmdline = getenv("bootargs")) == NULL) {
  679. cmdline = "";
  680. }
  681. loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
  682. printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
  683. (ulong)loader);
  684. SHOW_BOOT_PROGRESS (15);
  685. /*
  686. * NetBSD Stage-2 Loader Parameters:
  687. * r3: ptr to board info data
  688. * r4: image address
  689. * r5: console device
  690. * r6: boot args string
  691. */
  692. (*loader) (gd->bd, img_addr, consdev, cmdline);
  693. }
  694. #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
  695. /* Function that returns a character from the environment */
  696. extern uchar (*env_get_char)(int);
  697. static void
  698. do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
  699. int argc, char *argv[],
  700. ulong addr,
  701. ulong *len_ptr,
  702. int verify)
  703. {
  704. DECLARE_GLOBAL_DATA_PTR;
  705. ulong top;
  706. char *s, *cmdline;
  707. char **fwenv, **ss;
  708. int i, j, nxt, len, envno, envsz;
  709. bd_t *kbd;
  710. void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
  711. image_header_t *hdr = &header;
  712. /*
  713. * Booting an ARTOS kernel image + application
  714. */
  715. /* this used to be the top of memory, but was wrong... */
  716. #ifdef CONFIG_PPC
  717. /* get stack pointer */
  718. asm volatile ("mr %0,1" : "=r"(top) );
  719. #endif
  720. debug ("## Current stack ends at 0x%08lX ", top);
  721. top -= 2048; /* just to be sure */
  722. if (top > CFG_BOOTMAPSZ)
  723. top = CFG_BOOTMAPSZ;
  724. top &= ~0xF;
  725. debug ("=> set upper limit to 0x%08lX\n", top);
  726. /* first check the artos specific boot args, then the linux args*/
  727. if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
  728. s = "";
  729. /* get length of cmdline, and place it */
  730. len = strlen(s);
  731. top = (top - (len + 1)) & ~0xF;
  732. cmdline = (char *)top;
  733. debug ("## cmdline at 0x%08lX ", top);
  734. strcpy(cmdline, s);
  735. /* copy bdinfo */
  736. top = (top - sizeof(bd_t)) & ~0xF;
  737. debug ("## bd at 0x%08lX ", top);
  738. kbd = (bd_t *)top;
  739. memcpy(kbd, gd->bd, sizeof(bd_t));
  740. /* first find number of env entries, and their size */
  741. envno = 0;
  742. envsz = 0;
  743. for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
  744. for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
  745. ;
  746. envno++;
  747. envsz += (nxt - i) + 1; /* plus trailing zero */
  748. }
  749. envno++; /* plus the terminating zero */
  750. debug ("## %u envvars total size %u ", envno, envsz);
  751. top = (top - sizeof(char **)*envno) & ~0xF;
  752. fwenv = (char **)top;
  753. debug ("## fwenv at 0x%08lX ", top);
  754. top = (top - envsz) & ~0xF;
  755. s = (char *)top;
  756. ss = fwenv;
  757. /* now copy them */
  758. for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
  759. for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
  760. ;
  761. *ss++ = s;
  762. for (j = i; j < nxt; ++j)
  763. *s++ = env_get_char(j);
  764. *s++ = '\0';
  765. }
  766. *ss++ = NULL; /* terminate */
  767. entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
  768. (*entry)(kbd, cmdline, fwenv, top);
  769. }
  770. #endif
  771. #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
  772. int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  773. {
  774. int rcode = 0;
  775. #ifndef CFG_HUSH_PARSER
  776. if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
  777. #else
  778. if (parse_string_outer(getenv("bootcmd"),
  779. FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
  780. #endif
  781. return rcode;
  782. }
  783. U_BOOT_CMD(
  784. boot, 1, 1, do_bootd,
  785. "boot - boot default, i.e., run 'bootcmd'\n",
  786. NULL
  787. );
  788. /* keep old command name "bootd" for backward compatibility */
  789. U_BOOT_CMD(
  790. bootd, 1, 1, do_bootd,
  791. "bootd - boot default, i.e., run 'bootcmd'\n",
  792. NULL
  793. );
  794. #endif
  795. #if (CONFIG_COMMANDS & CFG_CMD_IMI)
  796. int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  797. {
  798. int arg;
  799. ulong addr;
  800. int rcode=0;
  801. if (argc < 2) {
  802. return image_info (load_addr);
  803. }
  804. for (arg=1; arg <argc; ++arg) {
  805. addr = simple_strtoul(argv[arg], NULL, 16);
  806. if (image_info (addr) != 0) rcode = 1;
  807. }
  808. return rcode;
  809. }
  810. static int image_info (ulong addr)
  811. {
  812. ulong data, len, checksum;
  813. image_header_t *hdr = &header;
  814. printf ("\n## Checking Image at %08lx ...\n", addr);
  815. /* Copy header so we can blank CRC field for re-calculation */
  816. memmove (&header, (char *)addr, sizeof(image_header_t));
  817. if (ntohl(hdr->ih_magic) != IH_MAGIC) {
  818. printf (" Bad Magic Number\n");
  819. return 1;
  820. }
  821. data = (ulong)&header;
  822. len = sizeof(image_header_t);
  823. checksum = ntohl(hdr->ih_hcrc);
  824. hdr->ih_hcrc = 0;
  825. if (crc32 (0, (char *)data, len) != checksum) {
  826. printf (" Bad Header Checksum\n");
  827. return 1;
  828. }
  829. /* for multi-file images we need the data part, too */
  830. print_image_hdr ((image_header_t *)addr);
  831. data = addr + sizeof(image_header_t);
  832. len = ntohl(hdr->ih_size);
  833. printf (" Verifying Checksum ... ");
  834. if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
  835. printf (" Bad Data CRC\n");
  836. return 1;
  837. }
  838. printf ("OK\n");
  839. return 0;
  840. }
  841. U_BOOT_CMD(
  842. iminfo, CFG_MAXARGS, 1, do_iminfo,
  843. "iminfo - print header information for application image\n",
  844. "addr [addr ...]\n"
  845. " - print header information for application image starting at\n"
  846. " address 'addr' in memory; this includes verification of the\n"
  847. " image contents (magic number, header and payload checksums)\n"
  848. );
  849. #endif /* CFG_CMD_IMI */
  850. #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
  851. /*-----------------------------------------------------------------------
  852. * List all images found in flash.
  853. */
  854. int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  855. {
  856. flash_info_t *info;
  857. int i, j;
  858. image_header_t *hdr;
  859. ulong checksum;
  860. for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
  861. if (info->flash_id == FLASH_UNKNOWN)
  862. goto next_bank;
  863. for (j=0; j<CFG_MAX_FLASH_SECT; ++j) {
  864. if (!(hdr=(image_header_t *)info->start[j]) ||
  865. (ntohl(hdr->ih_magic) != IH_MAGIC))
  866. goto next_sector;
  867. /* Copy header so we can blank CRC field for re-calculation */
  868. memmove (&header, (char *)hdr, sizeof(image_header_t));
  869. checksum = ntohl(header.ih_hcrc);
  870. header.ih_hcrc = 0;
  871. if (crc32 (0, (char *)&header, sizeof(image_header_t))
  872. != checksum)
  873. goto next_sector;
  874. printf ("Image at %08lX:\n", (ulong)hdr);
  875. print_image_hdr( hdr );
  876. putc ('\n');
  877. next_sector: ;
  878. }
  879. next_bank: ;
  880. }
  881. return (0);
  882. }
  883. U_BOOT_CMD(
  884. imls, 1, 1, do_imls,
  885. "imls - list all images found in flash\n",
  886. "\n"
  887. " - Prints information about all images found at sector\n"
  888. " boundaries in flash.\n"
  889. );
  890. #endif /* CFG_CMD_IMLS */
  891. void
  892. print_image_hdr (image_header_t *hdr)
  893. {
  894. #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
  895. time_t timestamp = (time_t)ntohl(hdr->ih_time);
  896. struct rtc_time tm;
  897. #endif
  898. printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
  899. #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
  900. to_tm (timestamp, &tm);
  901. printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
  902. tm.tm_year, tm.tm_mon, tm.tm_mday,
  903. tm.tm_hour, tm.tm_min, tm.tm_sec);
  904. #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
  905. printf (" Image Type: "); print_type(hdr); printf ("\n");
  906. printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
  907. print_size (ntohl(hdr->ih_size), "\n");
  908. printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
  909. printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
  910. if (hdr->ih_type == IH_TYPE_MULTI) {
  911. int i;
  912. ulong len;
  913. ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
  914. printf (" Contents:\n");
  915. for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
  916. printf (" Image %d: %8ld Bytes = ", i, len);
  917. print_size (len, "\n");
  918. }
  919. }
  920. }
  921. static void
  922. print_type (image_header_t *hdr)
  923. {
  924. char *os, *arch, *type, *comp;
  925. switch (hdr->ih_os) {
  926. case IH_OS_INVALID: os = "Invalid OS"; break;
  927. case IH_OS_NETBSD: os = "NetBSD"; break;
  928. case IH_OS_LINUX: os = "Linux"; break;
  929. case IH_OS_VXWORKS: os = "VxWorks"; break;
  930. case IH_OS_QNX: os = "QNX"; break;
  931. case IH_OS_U_BOOT: os = "U-Boot"; break;
  932. case IH_OS_RTEMS: os = "RTEMS"; break;
  933. #ifdef CONFIG_ARTOS
  934. case IH_OS_ARTOS: os = "ARTOS"; break;
  935. #endif
  936. #ifdef CONFIG_LYNXKDI
  937. case IH_OS_LYNXOS: os = "LynxOS"; break;
  938. #endif
  939. default: os = "Unknown OS"; break;
  940. }
  941. switch (hdr->ih_arch) {
  942. case IH_CPU_INVALID: arch = "Invalid CPU"; break;
  943. case IH_CPU_ALPHA: arch = "Alpha"; break;
  944. case IH_CPU_ARM: arch = "ARM"; break;
  945. case IH_CPU_I386: arch = "Intel x86"; break;
  946. case IH_CPU_IA64: arch = "IA64"; break;
  947. case IH_CPU_MIPS: arch = "MIPS"; break;
  948. case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
  949. case IH_CPU_PPC: arch = "PowerPC"; break;
  950. case IH_CPU_S390: arch = "IBM S390"; break;
  951. case IH_CPU_SH: arch = "SuperH"; break;
  952. case IH_CPU_SPARC: arch = "SPARC"; break;
  953. case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
  954. case IH_CPU_M68K: arch = "M68K"; break;
  955. default: arch = "Unknown Architecture"; break;
  956. }
  957. switch (hdr->ih_type) {
  958. case IH_TYPE_INVALID: type = "Invalid Image"; break;
  959. case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
  960. case IH_TYPE_KERNEL: type = "Kernel Image"; break;
  961. case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
  962. case IH_TYPE_MULTI: type = "Multi-File Image"; break;
  963. case IH_TYPE_FIRMWARE: type = "Firmware"; break;
  964. case IH_TYPE_SCRIPT: type = "Script"; break;
  965. default: type = "Unknown Image"; break;
  966. }
  967. switch (hdr->ih_comp) {
  968. case IH_COMP_NONE: comp = "uncompressed"; break;
  969. case IH_COMP_GZIP: comp = "gzip compressed"; break;
  970. case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
  971. default: comp = "unknown compression"; break;
  972. }
  973. printf ("%s %s %s (%s)", arch, os, type, comp);
  974. }
  975. #define ZALLOC_ALIGNMENT 16
  976. static void *zalloc(void *x, unsigned items, unsigned size)
  977. {
  978. void *p;
  979. size *= items;
  980. size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
  981. p = malloc (size);
  982. return (p);
  983. }
  984. static void zfree(void *x, void *addr, unsigned nb)
  985. {
  986. free (addr);
  987. }
  988. #define HEAD_CRC 2
  989. #define EXTRA_FIELD 4
  990. #define ORIG_NAME 8
  991. #define COMMENT 0x10
  992. #define RESERVED 0xe0
  993. #define DEFLATED 8
  994. int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
  995. {
  996. z_stream s;
  997. int r, i, flags;
  998. /* skip header */
  999. i = 10;
  1000. flags = src[3];
  1001. if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
  1002. printf ("Error: Bad gzipped data\n");
  1003. return (-1);
  1004. }
  1005. if ((flags & EXTRA_FIELD) != 0)
  1006. i = 12 + src[10] + (src[11] << 8);
  1007. if ((flags & ORIG_NAME) != 0)
  1008. while (src[i++] != 0)
  1009. ;
  1010. if ((flags & COMMENT) != 0)
  1011. while (src[i++] != 0)
  1012. ;
  1013. if ((flags & HEAD_CRC) != 0)
  1014. i += 2;
  1015. if (i >= *lenp) {
  1016. printf ("Error: gunzip out of data in header\n");
  1017. return (-1);
  1018. }
  1019. s.zalloc = zalloc;
  1020. s.zfree = zfree;
  1021. #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
  1022. s.outcb = (cb_func)WATCHDOG_RESET;
  1023. #else
  1024. s.outcb = Z_NULL;
  1025. #endif /* CONFIG_HW_WATCHDOG */
  1026. r = inflateInit2(&s, -MAX_WBITS);
  1027. if (r != Z_OK) {
  1028. printf ("Error: inflateInit2() returned %d\n", r);
  1029. return (-1);
  1030. }
  1031. s.next_in = src + i;
  1032. s.avail_in = *lenp - i;
  1033. s.next_out = dst;
  1034. s.avail_out = dstlen;
  1035. r = inflate(&s, Z_FINISH);
  1036. if (r != Z_OK && r != Z_STREAM_END) {
  1037. printf ("Error: inflate() returned %d\n", r);
  1038. return (-1);
  1039. }
  1040. *lenp = s.next_out - (unsigned char *) dst;
  1041. inflateEnd(&s);
  1042. return (0);
  1043. }
  1044. #ifdef CONFIG_BZIP2
  1045. void bz_internal_error(int errcode)
  1046. {
  1047. printf ("BZIP2 internal error %d\n", errcode);
  1048. }
  1049. #endif /* CONFIG_BZIP2 */
  1050. static void
  1051. do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  1052. ulong addr, ulong *len_ptr, int verify)
  1053. {
  1054. DECLARE_GLOBAL_DATA_PTR;
  1055. image_header_t *hdr = &header;
  1056. void (*entry_point)(bd_t *);
  1057. entry_point = (void (*)(bd_t *)) hdr->ih_ep;
  1058. printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
  1059. (ulong)entry_point);
  1060. SHOW_BOOT_PROGRESS (15);
  1061. /*
  1062. * RTEMS Parameters:
  1063. * r3: ptr to board info data
  1064. */
  1065. (*entry_point ) ( gd->bd );
  1066. }
  1067. #if (CONFIG_COMMANDS & CFG_CMD_ELF)
  1068. static void
  1069. do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  1070. ulong addr, ulong *len_ptr, int verify)
  1071. {
  1072. image_header_t *hdr = &header;
  1073. char str[80];
  1074. sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
  1075. setenv("loadaddr", str);
  1076. do_bootvx(cmdtp, 0, 0, NULL);
  1077. }
  1078. static void
  1079. do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
  1080. ulong addr, ulong *len_ptr, int verify)
  1081. {
  1082. image_header_t *hdr = &header;
  1083. char *local_args[2];
  1084. char str[16];
  1085. sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
  1086. local_args[0] = argv[0];
  1087. local_args[1] = str; /* and provide it via the arguments */
  1088. do_bootelf(cmdtp, 0, 2, local_args);
  1089. }
  1090. #endif /* CFG_CMD_ELF */
  1091. #ifdef CONFIG_LYNXKDI
  1092. static void
  1093. do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
  1094. int argc, char *argv[],
  1095. ulong addr,
  1096. ulong *len_ptr,
  1097. int verify)
  1098. {
  1099. lynxkdi_boot( &header );
  1100. }
  1101. #endif /* CONFIG_LYNXKDI */