cmd_bootm.c 34 KB

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