⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loader.c.svn-base

📁 realtek的8186芯片ADSL路由AP源代码
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
#define ntohs#define uint16 unsigned shortunsigned short ipchksum(unsigned short *ptr, int count, unsigned short resid){	register unsigned int sum = resid;       if ( count==0)        	return(sum);        	while(count > 1) {		sum += ntohs(*ptr);			if ( sum>>31)			sum = (sum&0xffff) + ((sum>>16)&0xffff);		ptr++;		count -= 2;	}	if (count > 0) 		sum += (*((unsigned char*)ptr) << 8) & 0xff00;	while (sum >> 16)		sum = (sum & 0xffff) + (sum >> 16);	if (sum == 0xffff) 		sum = 0;	return (unsigned short)sum;}// return 0 if OK, else return -1;int writeImageSingle(unsigned char *src) {	IMGHDR *pHeader;	void *pData;	unsigned int csum, length;	char *wdst, *wsrc;	pHeader = (IMGHDR *)src;	pData = (void *)  (&pHeader[1]);	if (APPLICATION_IMAGE != pHeader->key) {		printf("Unknown key. %x\n\r", pHeader);			return -1;	}	//if (!(pHeader->type & FLASHIMAGE)) {	//	printf("DRAM loading not currently supported.\n");	//	return -1;	//}	printf("Image length=%d, flashp=%xh\n\r", pHeader->length, pHeader->flashp);	length = pHeader->length;	csum = pHeader->chksum;	//csum = ipchksum((uint16*) src, length, csum);	csum = ipchksum((uint16*) &pHeader[1], length, csum);	if (csum != 0) {		printf("checksum failed\n\r");		return -1;			}	wdst = pHeader->flashp;		if (pHeader->type&KEEPHEADER) {		wsrc = src;		length += sizeof(IMGHDR);	} else {		wsrc = (char *)&pHeader[1];	}	write_file(wdst, wsrc, length);	return 0;}int writeImage(IMGHDR *pHeader) {	unsigned int totallength, length;	unsigned char *datap;	IMGHDR *pTmpHdr;	int ret;	//printf("App key=%x    type=%02x\n", pHeader->key, pHeader->type);	if (APPLICATION_IMAGE != pHeader->key) {				return -1;	}		if ( !(pHeader->type&MULTIHEADER))     	{     		       	return writeImageSingle(pHeader);     	}	totallength = pHeader->length;	pTmpHdr = &pHeader[1];		length = pTmpHdr->length + sizeof(IMGHDR);	datap = (char *)pTmpHdr;	//printf("Length=%d\n", pHeader->length);	while (totallength > length) {		ret = writeImageSingle(pTmpHdr);		if (ret) {					return ret;		}		datap = &datap[ pTmpHdr->length + sizeof(IMGHDR) ];		pTmpHdr = (IMGHDR *)datap;		length += (pTmpHdr->length + sizeof(IMGHDR));		datap = (char *)pTmpHdr;	}	return writeImageSingle(pTmpHdr);}/*<==== Andrew. Added to support OSK header ====*/int xmodem_download(unsigned long dest){unsigned long len;char *load_buf = (char*)bParam.load;char *dest_buf = (char*)dest;	get_param(&bParam);	load_buf = (char*)bParam.load;	if(load_buf)	{		xModemStart();		printf("xModem upload...\n\r");    	len = xModemRxBuffer(load_buf, 2*1024*1024);		if(len!=0)		{			printf("\n\rwriting file...%x %x %d\n\r", dest_buf, load_buf, len);			if (writeImage(load_buf)) {				printf("No header, assuming raw binary\n\r");				return write_file(dest_buf, load_buf, len);			}			//return write_file(dest_buf, load_buf, len);		}		else			printf("\n\rdownload failed!!\n\r");	} 	else		printf("\n\rdownload buffer failed!!\n\r");	return ERROR;}int cmd_shell(void){char buf[256];	print_banner();	while(1)	{		if(kbd_proc(buf, sizeof(buf)))			cmd_proc(buf);	}}#ifdef CONFIG_RTL867X_LOADER_SUPPORT_HTTP_SERVERextern int Lan_Transmit(void * buff, unsigned int length);void	rs_httpd(void){	struct tcp_pcb	*pcb;	char	ch;	unsigned char	a,b,c,d;	memcpy(netif.IEEEIA, &bParam.mac[0], 6);//	printf("\nMAC: %02x-%02x-%02x-%02x-%02x-%02x.\n", //		netif.IEEEIA[0], netif.IEEEIA[1], netif.IEEEIA[2], netif.IEEEIA[3], netif.IEEEIA[4], netif.IEEEIA[5]);	netif.send = Lan_Transmit;	    netif.ip=bParam.ip;        Lan_Initialize(&bParam.mac[0]);    	/* create vlan *//*	rtl_vlan_param_t vp;	bzero((void *) &vp, sizeof(rtl_vlan_param_t));	memcpy(&vp.gMac, &bdinfo.mac[0], 6);	vp.egressUntag = 0x1f;	vp.mtu = 1500;	vp.memberPort = 0x1f;	if ( swCore_vlanCreate(8, &vp) != 0 )	{		printf( "\nCreating vlan fails.\n" );		while(1);	}*/	/* request an IP address through BOOTP *//*	printf("\n********'b' to get IP address through BOOTP.\n********'h' to set IP address manually.\n");//	printf("\n********'h' to set IP address manually.\n");//	printf("test0\n");	if ( getchar(&ch) )	{		if ( ch == 'h' ) {			printf("Enter IP address XX.XX.XX.XX:");			netif.ip = strToIp();			printf("\n");		} else if ( ch == 'b' ) {			netRequestIP ();		}	}*/		//	printf("Start initialization.\n");#ifdef STATS	stats_init();//	printf("stats_init over.\n");#endif	mem_init();//	printf("mem_init over.\n");	pbuf_init();//	printf("pbuf_init over.\n");	memp_init();//	printf("memp_init over.\n");	ip_init();//	printf("ip_init over.\n");	tcp_init();//	printf("tcp_init over.\n");	//	while(1);	pcb = tcp_new();		if (tcp_bind(pcb, (u32_t*)&(netif.ip), HTTP_SRV_PORT)!=ERR_OK) {//		printf("Bind fail. At line: %d, in file %s\n", __LINE__, __FILE__);	}//	printf("pcb bind port is %d\n", pcb->local_port);	if ((pcb=tcp_listen(pcb))==NULL) {//		printf("Bind fail. At line: %d, in file %s\n", __LINE__, __FILE__);	}//	printf("test2\n");	pcb->accept = http_accept;//	tcp_accept(pcb, http_accept);//	tcp_recv(pcb, http_recv);//	printf("test3\n");//	printf( "Listening on port %d\n",HTTP_SRV_PORT);	printf("The local IP is %d.%d.%d.%d\nListening......\n", (netif.ip>>24)&0xff, (netif.ip>>16)&0xff, (netif.ip>>8)&0xff, (netif.ip)&0xff);//	printf("Listening......\n");	while(1) {		processPacket();	}}#endif//led offvoid reset_led(void){  int i;  	*((unsigned long*)0xB9C01000)=0x00E80000;	for (i=0;i<0x1000;i++) asm("nop");#ifdef MINIMODEL_SUPPORT	*((unsigned long*)0xB9C01004)=0x00A00000;	//mini model#elif Flash_AA21_GPA5        *((unsigned long*)0xB9C01004)=0x00C00000; //Kevin Chung for Flash AA21 defined to GPA5 .#else	*((unsigned long*)0xB9C01004)=0x00E00000;#endif#ifdef CONFIG_TR068		for (i=0;i<0x1000;i++) asm("nop");	*((unsigned long*)0xB9C01010) = 0x00c00000;  //config B6,B7 as output	*((unsigned long*)0xB9C01014) = 0x00400000; //config Power LED#endif}int check_loader_mode(int mode){	unsigned long start, mcr0,sicr;	char flashSize[][8]={"1M", "2M", "4M", "8M"};	char sdramSize[][8]={"2M", "8M", "16M"};	if(mode)		goto run_loader_shell;	mcr0=((*((unsigned long*)0xB9000000))>>28)&0x0F;	sicr = *((unsigned long *)0xB9c04000);    	printf("\n\r\n\r");    	printf("Booting(%s/%s)...\n\r", flashSize[mcr0>>2], sdramSize[mcr0&0x03]);    	printf("Press 'ESC' to enter BOOT console...\n\r");	get_param(&bParam);	// system configuration ( MII selection, internal/external NIC PHY )	if(bParam.MII_select & 0x00000001){//		printf("Using Ext. PHY\n\r");#ifdef Flash_AA21_GPA5 //big_model		*((unsigned long*)0xb9c04000) = sicr|0x200;	//GPIO interface as PCI#else		*((unsigned long*)0xB9c04000) = sicr|0x200;#endif	} else {#ifdef Flash_AA21_GPA5                *((unsigned long*)0xb9c04000) = (sicr&0xfffffdff)|0x20;     //GPIO interfaceas PCI#else                *((unsigned long*)0xb9c04000) = (sicr&0xfffffdff);     //GPIO interfaceas PCI#endif		printf("Using Int. PHY\n\r");	}    *((volatile unsigned long*)0xB9C01010)=0x0c800000;    *((volatile unsigned long*)0xB9C01014)=0x00400000;	reset_led();// addition by Kevin Chung 2007/09/19 for TR068 LED#ifdef CONFIG_TR068	gpioTR068();#endif#ifdef CONFIG_RE8306//	printf("Enable RTL8306..\n\r");    	Enable_8306();	 #endif	//ENABLE_8306    	start = get_sys_time();	while(!timeout(start, 1000))		if(check_break(0x1B))			goto run_loader_shell;				if((!strcmp(bParam.bootline, "re0")) || 		(run_gzip_file(bParam.app, bParam.entry)==ERROR))	{		unsigned int image_len;		char *mac;		char filename[32];		unsigned char *load_buf = (char*)bParam.load;		mac = bParam.mac[0];		Lan_Initialize(mac);		/*		 * Decompress failed, try to use web upgrade F/W, wake up httpd.		 */		if(strcmp(bParam.bootline, "re0")) {			get_param(&bParam);		    	rs_httpd();		}        	if ( bootpReceive (mac, &image_len, 0, 0, filename, load_buf) != 0 )            		printf("bootp ERROR\n\r");		else		{			void (*appStart)(void);			appStart = (void*)bParam.entry;			if(bParam.load!=bParam.entry)			{				if(load_buf[0]==0x1f && load_buf[1]==0x8b)				{					printf("Decompress file...\n\r");					decompress_image((char*)bParam.entry, 1024*1024*2,(char*)bParam.load, image_len);				}				else					memcpy((char*)bParam.entry, (char*)bParam.load, image_len);			}			appStart();		}	}run_loader_shell:	cmd_shell();	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -