亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ian_xmodem.c

?? umon bootloader source code, support mips cpu.
?? C
?? 第 1 頁 / 共 3 頁
字號:
/* 
 * ian_xmodem.c
 *
 * X and Y modem file download and upload protocols.
 *
 * by Nick Patavalis (npat@inaccessnetworks.com)
 *
 *	General notice:
 *	This code is part of a boot-monitor package developed as a generic base
 *	platform for embedded system designs.  As such, it is likely to be
 *	distributed to various projects beyond the control of the original
 *	author.  Please notify the author of any enhancements made or bugs found
 *	so that all may benefit from the changes.  In addition, notification back
 *	to the author will allow the new user to pick up changes that may have
 *	been made by other users after this version of the code was distributed.
 *
 *	Note1: the majority of this code was edited with 4-space tabs.
 *	Note2: as more and more contributions are accepted, the term "author"
 *		   is becoming a mis-representation of credit.
 *
 *	Original author:	Ed Sutter
 *	Email:				esutter@lucent.com
 *	Phone:				908-582-2351
 *
 * $Id: ian_xmodem.c,v 2.0 2006/09/22 05:28:45 lxw Exp $
 */

/***************************************************************************/

#include "config.h"
#include "genlib.h"
#include "stddefs.h"
#include "flash.h"
#include "tfs.h"
#include "tfsprivate.h"
#include "cli.h"
#include "ascii.h"

/***************************************************************************/

#if INCLUDE_XMODEM

/* These "wait" functions may be better placed in chario.c.  They
 * are here for now, because this version of xmodem is the only
 * module that uses them.
 */

int
waitchar(int tmo)
{
	int timeout;
	int rval;

	timeout = tmo * LoopsPerSecond;
	while(!gotachar() && timeout)
		timeout--;
	if (timeout)
		rval = getchar();
	else
		rval = -1;

	return(rval);
}

void
waitclear (void)
{
	ulong timeout;

	while (1) {
		timeout = 1 * LoopsPerSecond;

		while(!gotachar() && timeout)
			timeout--;
		if (!timeout)
			break;
		getchar();
	}
}

int
waitbytes (char *buf, int cnt, int tmo)
{
	ulong timeout;
	int	i;

	for(i=0; i<cnt; i++) {
		timeout = tmo * LoopsPerSecond;
		while(!gotachar() && timeout)
			timeout--;
	    if (!timeout)
			break;
		buf[i] = (char)getchar();
	}
	return (i < cnt) ? -1 : i;
}

char ian_xmodem_cvsid[] = "$Id: ian_xmodem.c,v 2.0 2006/09/22 05:28:45 lxw Exp $";

/***************************************************************************/

/* RCV: Frame timeout. Time to wait for next frame, before sending a NAK */
#define FRAME_TMO  5
/* RCV: Character timeout. Characters in the same frame should normally 
   not be more than CHAR_TMO seconds appart */
#define CHAR_TMO   1
/* TRN: Transmiter timeout. Usually a large value. The standard suggests 
   something in the order of 1m */
#define TRANS_TMO  20
/* TRN: Number of times to retransmit a frame before quiting */
#define RETR_MAX   10
/* TRN: Number of invalid characters (i.e. not ACK or NAK) received 
   by the transmiter before quiting. This *not* the right way to do 
   things. The right way is to wait for a valid char up to TRANS_TMO 
   secs, and then quit. Unfortunatelly without timers, this behavior is 
   a bit tricky to implement. So this crude approxomation will have to do 
   for the moment. */
#define NOISE_MAX 100

/* Maximum number of files per Y-modem transfer */
#define YFILES_MAX 10

/***************************************************************************/

/* X/Ymodem protocol: */
#define SOH ASCII_SOH
#define STX ASCII_STX
#define EOT ASCII_EOT
#define ACK ASCII_ACK
#define NAK ASCII_NAK
#define CAN ASCII_CAN
#define ESC ASCII_ESC
#define BS  ASCII_BS

#define PKTLEN_128 128
#define PKTLEN_1K  1024

/***************************************************************************/

enum _xmodem_ops {
	XNULL = 0,
	XUP,
	XDOWN
};

enum _protocol_type {
	XMODEM = 0,
	YMODEM = 1
};

#define XERR_GEN  (-1)
#define XERR_TOUT (-2)
#define XERR_SYNC (-3)
#define XERR_CAN  (-4)
#define XERR_UCAN (-5)
#define XERR_RETR (-6)
#define XERR_HEAD (-7)
#define XERR_TFS  (-8)
#define XERR_NOFILE (-9)
#define XERR_NOSIZE (-10)

static char *xerr_msgs[] = {
	"E00:No Error",
	"E01:General Error",
	"E02:Timeout",
	"E03:Synchronization error",
	"E04:Operation canceled",
	"E05:Operation canceled by user",
	"E06:Maximum retransmitions exceeded",
	"E07:Invalid header-block",
	"E08:TFS error",
	"E09:File not found",
	"E10:Cannot determine file size"
};

/***************************************************************************/

/* struct yinfo:
 * used to pass information to and from the y-modem transfer functions.
 */
struct yinfo {	
	int usecrc;      /* use 16bit CRC instead of 8bit checksum */
	int onek;        /* use 1k blocks instead of 128bytes blocks */ 
	int verify;      /* operate in verification-mode */
	ulong baseaddr;  /* start address for the first file data transfer */
	char *flags;     /* TFS file flags (same for all files) */
	char *info;      /* TFS file info (same for all files) */

	int filecnt;                         /* number of files processed */
	char fname[YFILES_MAX][TFSNAMESIZE]; /* names of files processed */
	ulong dataddr[YFILES_MAX];           /* start address of each file */
	long size[YFILES_MAX];               /* size of each file in bytes */
	long pktcnt[YFILES_MAX];             /* number of frames exchanged */
	long errcnt[YFILES_MAX];             /* number of verification errors */
	ulong firsterrat[YFILES_MAX];        /* offset of first error */
};

/* struct xinfo:
 * used to pass information to and from the x-modem transfer functions.
 */
struct xinfo {
	int     usecrc;      /* use 16bit CRC instead of 8bit checksum */
	int     onek;        /* use 1k blocks instead of 128bytes blocks */ 
	int     verify;      /* operate in verification-mode */
	ulong	dataddr;	 /* start address for data transfer */
	long	size;	     /* size of the tansfer in bytes */
	int		pktcnt;		 /* number of packets processed */
	int		errcnt;		 /* number of errors (used in verify mode) */
	ulong	firsterrat;  /* pointer to location if first error (vrf mode) */
};

/***************************************************************************/

/* local prototypes */

static int Xup(struct xinfo *, int);
static int Xdown(struct xinfo *, int);
static int Ydown(struct yinfo *);
static int Yup(struct yinfo *);
static int getPacket(uchar *, int, int);
static void putPacket (uchar *, int, int, int);
static char *xerr_msg(int);
static void doCAN(void);

/***************************************************************************/

/* Defined globaly to conserve stack-space. Ugly but effective. */
static struct yinfo yif;
static struct xinfo xif;
static uchar pktbuff[PKTLEN_1K];

/* Used to pass-back the TFS error code, in case of a TFS error */
int tfserr;

/***************************************************************************/

char *XmodemHelp[] = {
	"X/Y modem file transfer",
#if INCLUDE_TFS
#if INCLUDE_FLASH
	"-[a:BckdF:f:i:s:t:uvy]",
#else /* of INCLUDE_FLASH */
	"-[a:ckdF:f:i:s:t:uvy]",
#endif /* of INCLUDE_FLASH */
#else /* of INCLUDE_TFS */
#if INCLUDE_FLASH
	"-[a:Bckds:t:uvy]",
#else /* of INCLUDE_FLASH */
	"-[a:ckds:t:uvy]",
#endif /* of INCLUDE_FLASH */
#endif /* of INCLUDE_TFS */
	"Options:",
	" -a{##}     address (overrides default of APPRAMBASE)",
#if INCLUDE_FLASH
	" -B         Program boot-sector (i.e. uMon-binary reload)",
#endif
	" -c         have xmodem receiver request the use of CRC (def = chksum)",
	"            have ymodem receiver request the use of chksum (def = CRC)",
	" -k         send 1K frames (default = 128bytes)",
	" -d         download",
#if INCLUDE_TFS
	" -F{name}   filename",
	" -f{flags}  file flags (see tfs)",
	" -i{info}   file info (see tfs)",
#endif
	" -s{##}     size (overrides computed size)",
	" -u         upload",
	" -v         verify only",
	" -y         use YMODEM extensions",
	"Notes:",
	" * Either -d or -u must be specified (-B implies -d).",
	" * The -c argument affects only the receiver (download operations).",
    "   The -k option affects only the transmitter (upload operations).",
#if INCLUDE_TFS
    " * YMODEM downloads: The file-name and size arguments are ignored,",
    "   since they are supplied by the sender. Multiple files can be",
    "   downloaded. Each file is downloaded at the address specified by",
    "   the '-a' argument (or at APPRAMBASE), and then saved to the TFS.",
    "   A summary of the files downloaded, their sizes and the download",
	"   locations is displayed at the end of the transfer.", 
#else /* of INCLUDE_TFS */
    " * YMODEM downloads: The file-name and size arguments are ignored,",
    "   since they are supplied by the sender. Multiple files can be",
    "   downloaded. The files are stored sequencially starting at the", 
    "   address specified with '-a' (or at APPRAMBASE). A summary of the",
    "   files downloaded, their sizes and the download locations is",
    "   displayed at the end of the transfer.",
#endif /* of INCLUDE_TFS */
#if INCLUDE_FLASH
    "   If -B is given, the boot-sector is programmed with the contents",
    "   of the last file downloaded.",
#endif
#if INCLUDE_TFS
	" * XMODEM downloads: Only one file can be downloaded. A 128-byte",
    "   modulo is forced on file size. The file is downloaded at the address",
    "   specified by '-a' (or at APPRAMBASE), and then saved to a TFS file",
    "   if a file-name argument is given. The '-s' option can be used to", 
    "   override the 128-bytes modulo when transferring a file to TFS.",
#else /* of INCLUDE_TFS */
	" * XMODEM downloads: Only one file can be downloaded. A 128-byte",
    "   modulo is forced on file size. The file is downloaded at the address",
    "   specified by '-a' (or at APPRAMBASE).",
#endif /* of INCLUDE_TFS */
#if INCLUDE_FLASH
    "   If -B is given, the boot-sector is programmed with the contents",
    "   of the downloaded file.",
#endif /* of INCLUDE_FLASH */
#if INCLUDE_TFS
    " * X/YMODEM uploads: Only one file can be uploaded. The size argument",
    "   is ignored since it is taken form the TFS. Before the file is", 
	"   uploaded it is copied at the address specified by '-a' (or at", 
    "   APPRAMBASE).",
#else /* of INCLUDE_TFS */
    " * X/YMODEM uploads: Only one file can be uploaded. The size argument",
    "   is mandatory (since there is no other way to know the number of", 
    "   bytes to transfer). The data (file) to be uploaded are taken form",
    "   the address specified by '-a' (or from APPRAMBASE).",
#endif /* of INCLUDE_TFS */
	(char *)0,
};

/***************************************************************************/

int
Xmodem(int argc,char *argv[])
{
#if INCLUDE_TFS
	TFILE	*tfp;
#endif
	char fname[TFSNAMESIZE+1], *info, *flags;
	int	opt, xop, newboot, usecrc, verify, onek, ymodem;
	ulong dataddr;
	long size;
	int i, r;

	/* Initialize to defaults */
	dataddr = getAppRamStart();
	xop = XNULL;
	newboot = 0;
	usecrc = 0;
	fname[0]='\0';
	info = (char *)0;
	flags = (char *)0;
	onek = 0;
	size = 0;
	verify = 0;
	ymodem = 0;

	/* Parse command line arguments */
	while ((opt=getopt(argc,argv,"a:Bci:f:dF:ks:uvy")) != -1) {
		switch(opt) {
		case 'a':
			dataddr = strtoul(optarg,(char **)0,0);
			break;
#if INCLUDE_FLASH
		case 'B':
			xop = XDOWN;
			newboot = 1;
			break;
#endif
		case 'c':
			usecrc = 1;
			break;
		case 'd':
			xop = XDOWN;
			break;
#if INCLUDE_TFS
		case 'F':
			strncpy(fname, optarg, TFSNAMESIZE);
			break;
		case 'f':
			flags = optarg;
			break;
		case 'i':
			info = optarg;
			break;
#endif
		case 'k':
			onek = 1;
			break;
		case 's':
			size = (ulong)strtoul(optarg,(char **)0,0);
			break;
		case 'u':
			xop = XUP;
			break;
		case 'v':
			verify = 1;
			break;
		case 'y':
			ymodem = 1;
			break;
		default:
			return(CMD_PARAM_ERROR);
		}
	}

	/* There should be no arguments after the option list. */
	if (argc != optind)
		return(CMD_PARAM_ERROR);

	if ( xop == XUP ) {

		/* UPLOAD: Host <-- Micromonitor */

		if ( ymodem ) {

			/* we 're using the Y-Modem extensions */

			yif.onek = onek;
			yif.baseaddr = dataddr;
			yif.filecnt = 1;
			if (fname && fname[0]) {
				strcpy(yif.fname[0], fname);
			} else {
				strcpy(yif.fname[0], "noname");
			}
			yif.size[0] = size;

#if ! INCLUDE_TFS
			if ( yif.size[0] <= 0 ) {
				printf("%s\n", xerr_msg(XERR_NOSIZE));
				return(CMD_FAILURE);
			}
#endif

			r = Yup(&yif);

			printf("\n");

			if ( yif.filecnt > 0 ) {
				printf("Sent %d file%s.\n",
					   yif.filecnt, (yif.filecnt > 1) ? "s" : "");
				for (i = 0; i < yif.filecnt; i++) {
					printf(" %s: %ld bytes, %ld blocks, @ 0x%08lx\n",
						   yif.fname[i] ? yif.fname[i] : "<noname>",
						   yif.size[i],
						   yif.pktcnt[i],
						   yif.dataddr[i]);
				}
			}

			if ( r < 0 ) {
				printf("%s\n", xerr_msg(r));
				return(CMD_FAILURE);
			}			

		} else {

			/* plain X-modem */

			xif.dataddr = dataddr;
			xif.size = size;
			xif.onek = onek;

			if ( fname && fname[0] ) {
#if INCLUDE_TFS
				if ( ! (tfp = tfsstat(fname)) ) {
					printf("%s\n", xerr_msg(XERR_NOFILE));
					return(CMD_FAILURE);
				}
				memcpy((char *)(xif.dataddr), TFS_BASE(tfp), tfp->filsize);
				xif.size = size = tfp->filsize;
#endif
			}

			if ( xif.size <= 0 ) {
				printf("%s\n", xerr_msg(XERR_NOSIZE));
				return(CMD_FAILURE);
			}

			r = Xup(&xif, XMODEM);

			printf("\n");

			if ( r < 0 ) {
				printf("%s\n", xerr_msg(r));
				return(CMD_FAILURE);
			}

			printf("Sent 1 file.\n");

			printf(" %s: %ld bytes, %d blocks, @ 0x%08lx\n",
				   fname[0] ? fname : "<no-name>",
				   xif.size,
				   xif.pktcnt,
				   xif.dataddr);
		}

	} else if ( xop == XDOWN ) {

		/* DOWNLOAD: Host --> Micromonitor */

		if ( ymodem ) {

			/* Use Y-Modem extensions */

			yif.baseaddr = dataddr;
			yif.usecrc = !usecrc;
			yif.verify = verify;
			yif.flags = flags;
			yif.info = info;

			r = Ydown(&yif);

			printf("\n");

			if ( yif.filecnt ) {
				printf("Rcvd %d file%s.\n",
					   yif.filecnt, (yif.filecnt > 1) ? "s" : "");
				if ( yif.verify ) {
					for (i = 0; i < yif.filecnt; i++) {
						printf(" %s: %ld bytes, %ld blocks, %ld errors, " 
							   "first err @ 0x%08lx\n",
							   yif.fname[i] ? yif.fname[i] : "<noname>",
							   yif.size[i],
							   yif.pktcnt[i],
							   yif.errcnt[i], yif.firsterrat[i]);
					}
				} else {
					for (i = 0; i < yif.filecnt; i++) {
						printf(" %s: %ld bytes, %ld blocks, @ 0x%08lx\n",
							   yif.fname[i] ? yif.fname[i] : "<noname>",
							   yif.size[i],
							   yif.pktcnt[i],
							   yif.dataddr[i]);
					}
				}
			}

			if ( r < 0 ) {
				if ( r == XERR_TFS ) {
					printf("%s: %s: %s\n",
						   xerr_msg(XERR_TFS),
						   yif.fname[yif.filecnt], 
						   (char *)tfsctrl(TFS_ERRMSG,tfserr,0));
				} else {
					printf("%s\n", xerr_msg(r));
				}
				return(CMD_FAILURE);
			}

		} else {

			/* plain X-Modem */

			xif.dataddr = dataddr;
			xif.usecrc = usecrc;
			xif.verify = verify;

			if (verify && fname && fname[0]) {
#if INCLUDE_TFS
				if (! (tfp = tfsstat(fname)) ) {
					printf("%s\n", xerr_msg(XERR_NOFILE));

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲永久免费av| 国产人成亚洲第一网站在线播放 | 欧美日韩大陆在线| 岛国一区二区在线观看| 国产一区二区三区四区五区入口 | 欧美日韩久久一区| 欧美制服丝袜第一页| 日本道免费精品一区二区三区| 波波电影院一区二区三区| 国产69精品久久777的优势| 视频一区视频二区中文字幕| 亚洲一级电影视频| 男人的j进女人的j一区| 免费人成网站在线观看欧美高清| 香蕉加勒比综合久久| 午夜激情一区二区| 久久99国产精品尤物| 美腿丝袜一区二区三区| 国内久久精品视频| 风间由美一区二区三区在线观看| 成人网页在线观看| 波多野结衣91| 欧美日韩在线播放三区四区| 欧美另类z0zxhd电影| 日韩精品一区二区在线观看| 欧美一级片免费看| 日韩午夜激情av| 久久综合九色综合欧美就去吻| 国产亚洲成aⅴ人片在线观看| 中文字幕中文乱码欧美一区二区| 国产精品萝li| 国产精品盗摄一区二区三区| 欧美日韩国产小视频| 5566中文字幕一区二区电影| 日韩精品影音先锋| 色婷婷激情一区二区三区| 97久久超碰国产精品电影| 欧美日韩中文精品| 欧美日韩国产三级| 欧美视频日韩视频在线观看| 精品国产123| 日韩伦理电影网| 在线观看免费亚洲| 91麻豆精品国产91久久久久| 国产精品久久久久久户外露出| 1区2区3区欧美| 亚洲色图欧美在线| 国产一区二区三区高清播放| 色爱区综合激月婷婷| 久久网这里都是精品| 国内精品伊人久久久久影院对白| 不卡区在线中文字幕| 在线观看日韩毛片| 国产精品你懂的在线| 欧美精品久久天天躁| 欧美高清一级片在线| 国产精品美女久久久久久久网站| 国产精品网曝门| 亚洲免费观看高清在线观看| 亚洲黄色小说网站| 在线不卡a资源高清| 日韩精品一区二区三区三区免费| 国产精品美女视频| 亚洲国产欧美在线人成| 精品国一区二区三区| 国产精品素人一区二区| 亚洲综合色噜噜狠狠| 国产伦精品一区二区三区免费迷| 色香色香欲天天天影视综合网| 色香蕉久久蜜桃| 国产精品区一区二区三| 国产做a爰片久久毛片| 日韩三级视频中文字幕| 亚洲成人动漫av| 欧美在线free| 亚洲成精国产精品女| 97精品国产露脸对白| 成人免费在线播放视频| 成人午夜大片免费观看| 久久久久久一级片| 成人性生交大片免费看在线播放| 欧美精品一区二区不卡| 青青草成人在线观看| 7777精品伊人久久久大香线蕉经典版下载 | 久久嫩草精品久久久久| 久久亚洲一区二区三区明星换脸 | 亚洲色图视频免费播放| 日韩电影在线免费看| 777色狠狠一区二区三区| 亚洲理论在线观看| 成人美女视频在线看| 石原莉奈在线亚洲三区| 丰满放荡岳乱妇91ww| 国产成人三级在线观看| 亚洲日本免费电影| 蜜桃精品在线观看| 国产精品成人一区二区三区夜夜夜| 毛片不卡一区二区| 欧美精品少妇一区二区三区| 美女一区二区三区| 精品国精品国产尤物美女| 亚洲va国产va欧美va观看| 丁香亚洲综合激情啪啪综合| 最新日韩av在线| 国产成a人亚洲精| 一本色道久久综合亚洲91| 国产日韩欧美a| 色综合久久久久综合体桃花网| 中文字幕五月欧美| jlzzjlzz国产精品久久| 亚洲人一二三区| 欧美精品高清视频| 国产日韩欧美综合一区| 成人性视频网站| 久久久99久久精品欧美| 国产伦精品一区二区三区免费| 日韩西西人体444www| 国产日产欧产精品推荐色| 日本二三区不卡| 综合久久综合久久| 国产中文一区二区三区| 亚洲综合免费观看高清完整版在线| 亚洲国产精品传媒在线观看| 国产精品中文欧美| 国产精品久久久一区麻豆最新章节| 国产一区二区三区精品欧美日韩一区二区三区 | 在线观看国产日韩| 日本最新不卡在线| 久久综合色天天久久综合图片| 不卡高清视频专区| 日韩成人一区二区三区在线观看| 亚洲在线观看免费视频| 欧美一级电影网站| 色妹子一区二区| 国产一区二区日韩精品| 精品亚洲欧美一区| 天使萌一区二区三区免费观看| 91黄色激情网站| 91色|porny| 日精品一区二区| 国产精品乱码妇女bbbb| 日韩一区二区电影网| 欧美日韩黄视频| 国产精品麻豆视频| 亚洲一区在线播放| 亚洲一区电影777| 国产又粗又猛又爽又黄91精品| 亚洲精品一二三区| 欧美精品一区二区三区在线| 丁香婷婷综合五月| 精品在线免费视频| 亚洲另类在线视频| 91麻豆精品国产无毒不卡在线观看 | 精品国产一二三| 色婷婷久久久亚洲一区二区三区| 亚洲成人三级小说| 国产精品毛片久久久久久| 亚洲欧美国产三级| 成人精品视频一区二区三区尤物| 1区2区3区欧美| 欧美一区二区在线不卡| 免费在线观看一区| 一区二区三区四区亚洲| 日本aⅴ亚洲精品中文乱码| 成人欧美一区二区三区白人| 欧美一二三在线| 久久夜色精品国产噜噜av | 亚洲精品成a人| 久久久91精品国产一区二区精品| 亚洲激情中文1区| 国产三级精品视频| 欧美经典一区二区三区| 国产一区二区三区不卡在线观看| 亚洲在线免费播放| 一区二区在线观看不卡| 北条麻妃一区二区三区| 成人国产免费视频| 91论坛在线播放| 7777精品伊人久久久大香线蕉经典版下载 | 精品国产亚洲一区二区三区在线观看| 欧美电影免费观看高清完整版 | 欧美日韩一卡二卡三卡| 日韩欧美亚洲另类制服综合在线| 午夜一区二区三区在线观看| 日韩美女精品在线| 欧美在线观看视频在线| 国产电影精品久久禁18| 91精品办公室少妇高潮对白| 国产不卡视频在线播放| 欧美性生活影院| 日本韩国欧美在线| 色诱亚洲精品久久久久久| 日韩一区二区三| 欧美色涩在线第一页| 欧美视频在线一区二区三区| 精品久久五月天| 日本伊人午夜精品| 91网上在线视频| 精品粉嫩超白一线天av| 亚洲男同1069视频|