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

📄 net.c

📁 source code of armboot for s3c4510
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *	Copied from Linux Monitor (LiMon) - Networking. * *	Copyright 1994 - 2000 Neil Russell. *	(See License) *	Copyright 2000 Roland Borde *	Copyright 2000 Paolo Scaffardi *	Copyright 2000, 2001 Wolfgang Denk *  * (C) Copyright 2002 * Sysgo Real-Time Solutions, GmbH <www.elinos.com> * Marius Groeger <mgroeger@sysgo.de> *//* * General Desription: * * The user interface supports commands for BOOTP, RARP, and TFTP. * Also, we support ARP internally. Depending on available data, * these interact as follows: * * BOOTP: * *	Prerequisites:	- own ethernet address *	We want:	- own IP address *			- TFTP server IP address *			- name of bootfile *	Next step:	ARP * * RARP: * *	Prerequisites:	- own ethernet address *	We want:	- own IP address *			- TFTP server IP address *	Next step:	ARP * * ARP: * *	Prerequisites:	- own ethernet address *			- own IP address *			- TFTP server IP address *	We want:	- TFTP server ethernet address *	Next step:	TFTP * * DHCP: * *     Prerequisites:   - own ethernet address *     We want:         - IP, Netmask, ServerIP, Gateway IP *                      - bootfilename, lease time *     Next step:       - TFTP * * TFTP: * *	Prerequisites:	- own ethernet address *			- own IP address *			- TFTP server IP address *			- TFTP server ethernet address *			- name of bootfile (if unknown, we use a default name *			  derived from our own IP address) *	We want:	- load the boot file *	Next step:	none */#include <armboot.h>#include <command.h>#include "net.h"#include "bootp.h"#include "tftp.h"#include "rarp.h"#include "arp.h"#if (CONFIG_COMMANDS & CFG_CMD_NET)//#define 	ET_DEBUG#undef	 	ET_DEBUGchar		BootFile[128];			/* Boot File name			*//** BOOTP EXTENTIONS **/IPaddr_t	NetOurSubnetMask=0;		/* Our subnet mask (0=unknown)	*/IPaddr_t	NetOurGatewayIP=0;		/* Our gateways IP address	*/IPaddr_t	NetOurDNSIP=0;			/* Our DNS IP address		*/char		NetOurNISDomain[32]={0,};	/* Our NIS domain		*/char		NetOurHostName[32]={0,};	/* Our hostname			*/char		NetOurRootPath[64]={0,};	/* Our bootpath			*/ushort		NetBootFileSize=0;		/* Our bootfile size in blocks	*//** END OF BOOTP EXTENTIONS **/ulong		NetBootFileXferSize;	/* The actual transferred size of the bootfile (in bytes) */uchar		NetOurEther[6];		/* Our ethernet address			*/uchar		NetServerEther[6] =	/* Boot server enet address		*/			{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };IPaddr_t	NetOurIP;		/* Our IP addr (0 = unknown)		*/IPaddr_t	NetServerIP;		/* Our IP addr (0 = unknown)		*/volatile uchar *NetRxPkt;		/* Current receive packet		*/int			NetRxPktLen;		/* Current rx packet length		*/unsigned	NetIPID;		/* IP packet ID				*/uchar		NetBcastAddr[6] =	/* Ethernet bcast address		*/			{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };int			NetState;		/* Network loop state			*///karan 20070816 changed//volatile uchar	PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];volatile uchar *NetRxPackets[PKTBUFSRX]; /* Receive packets			*/static rxhand_f *packetHandler;		/* Current RX packet handler		*/static thand_f *timeHandler;		/* Current timeout handler		*/static ulong	timeValue;		/* Current timeout value		*/volatile uchar *NetTxPacket = 0;	/* THE transmit packet			*/bd_t	       *Net_bd;static int net_check_prereq (proto_t protocol);#ifdef ET_DEBUGvoid		hexdump(uchar * data, unsigned long size);#endifvoid		NetPrintEther(volatile uchar * addr);/**********************************************************************//* *	Main network processing loop. */int NetLoop(bd_t *bis, proto_t protocol){	char	*s, *e;	ulong	reg;	//karan 20070816 changed//#if 1#if 0	if (!NetTxPacket) 	{		int	i;		/*		 *	Setup packet buffers, aligned correctly.		 */		NetTxPacket = &PktBuf[0] + (PKTALIGN - 1);		NetTxPacket -= (ulong)NetTxPacket % PKTALIGN;		for (i = 0; i < PKTBUFSRX; i++) 		{			NetRxPackets[i] = NetTxPacket + (i+1)*PKTSIZE_ALIGN;		}	}#endif 	//karan 20070814 changed	//eth_halt();		//eth_init(bis);	NetCopyEther(NetOurEther, bis->bi_enetaddr);#if 0	NetPrintEther(NetOurEther);//add by hill 20070920#endif		restart:	NetState = NETLOOP_CONTINUE;	/*	 *	Start the ball rolling with the given start function.  From	 *	here on, this code is a state machine driven by received	 *	packets and timer events.	 */	if (protocol == TFTP) 	{			/* TFTP */		NetOurIP = bis->bi_ip_addr;		NetServerIP = 0;		s = getenv (bis, "serverip");		for (reg=0; reg<4; ++reg) 		{			ulong val = s ? simple_strtoul(s, &e, 10) : 0;			NetServerIP <<= 8;			NetServerIP |= (val & 0xFF);			if (s) s = (*e) ? e+1 : e;		}		if (net_check_prereq (protocol) != 0) {			return 0;		}		/* always use ARP to get server ethernet address */		ArpTry = 0;		ArpRequest ();	} #if (CONFIG_COMMANDS & CFG_CMD_DHCP)	else if (protocol == DHCP) 	{		if (net_check_prereq (protocol) != 0) {			return 0;		}		/* Start with a clean slate... */		NetOurIP = 0;		NetServerIP = 0;		DhcpRequest();		/* Basically same as BOOTP */	} #endif	/* CFG_CMD_DHCP */#if 0	else 	{				/* BOOTP or RARP */		/*                 * initialize our IP addr to 0 in order to accept ANY                 * IP addr assigned to us by the BOOTP / RARP server		 */		NetOurIP = 0;		NetServerIP = 0;		if (net_check_prereq (protocol) != 0) {			return 0;		}		if (protocol == BOOTP) {			BootpTry = 0;			BootpRequest ();		} else {			RarpTry	 = 0;			RarpRequest ();		}	}#endif	NetBootFileXferSize = 0;	/*	 *	Main packet reception loop.  Loop receiving packets until	 *	someone sets `NetQuit'.	 */	for (;;) 	{		/*		 *	Check the ethernet for a new packet.  The ethernet		 *	receive routine will process it.		 */		eth_rx();		/*		 *	Abort if ctrl-c was pressed.		 */		if (ctrlc()) 		{		  	eth_halt();			printf("\nAbort\n");			return 0;		}		/*		 *	Check for a timeout, and run the timeout handler		 *	if we have one.		 */		if (timeHandler && (get_timer(0) > timeValue)) 		{			thand_f *x;			x = timeHandler;			timeHandler = (thand_f *)0;			(*x)();		}		switch (NetState) 		{			case NETLOOP_RESTART:				goto restart;			case NETLOOP_SUCCESS:				if (NetBootFileXferSize > 0) 				{					char buf[10];					printf("Bytes transferred = %ld (%lx hex)\n", NetBootFileXferSize, NetBootFileXferSize);					sprintf(buf, "%lx", NetBootFileXferSize);					setenv(bis, "filesize", buf);				}				//modified by hill 20070924				//eth_halt();				return 1;			case NETLOOP_FAIL:				return 0;		}	}}/**********************************************************************/static voidstartAgainTimeout(void){	NetState = NETLOOP_RESTART;}static voidstartAgainHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len){	/* Totally ignore the packet */}voidNetStartAgain(void){	NetSetTimeout(10 * CFG_HZ, startAgainTimeout);	NetSetHandler(startAgainHandler);}/**********************************************************************//* *	Miscelaneous bits. */voidNetSetHandler(rxhand_f * f){	packetHandler = f;}//<--hans, added for correct NetLoop time comparison.#if defined(CONFIG_S3C2500)#include "s3c2500.h"#endif//-->hans end#if defined(CONFIG_S3C2510)#include "s3c2510.h"#endif//<--hill,added#if defined (CONFIG_S5N8947)#include "s5n8947.h"#endif//-->hill end//modified by choish --> definedvoidNetSetTimeout(int iv, thand_f * f){	if (iv == 0) 	{		timeHandler = (thand_f *)0;	} 	else 	{		timeHandler = f;//<--hans, added for correct NetLoop time comparison.		#if defined(CONFIG_S3C2500) || defined(CONFIG_S3C2510)		REG_WRITE(TIMER_TDATA_0, 0xf0000000);		#endif//-->hans end//<-- hill 20070924		#if defined(CONFIG_S5N8947)		REG_WRITE(TIMER_TDATA_0, 0xf0000000);		#endif//-->hill end		timeValue = get_timer(0) + iv;	}}void NetSendPacket(volatile uchar * pkt, int len){	(void) eth_send(pkt, len);}void NetReceive(volatile uchar * pkt, int len){	Ethernet_t *et;	IP_t	*ip;	ARP_t	*arp;	int	x;	NetRxPkt = pkt;	NetRxPktLen = len;	et = (Ethernet_t *)pkt;	x = SWAP16(et->et_protlen);	if (x < 1514) 	{		/*		 *	Got a 802 packet.  Check the other protocol field.		 */		x = SWAP16(et->et_prot);		ip = (IP_t *)(pkt + E802_HDR_SIZE);		len -= E802_HDR_SIZE;#ifdef ET_DEBUG		printf("Receive 802 type ET, protocol 0x%x\n", x);#endif	} else {		ip = (IP_t *)(pkt + ETHER_HDR_SIZE);		len -= ETHER_HDR_SIZE;#ifdef ET_DEBUG		printf("Receive non-802 type ET\n");#endif	}	switch (x) {	case PROT_ARP:

⌨️ 快捷键说明

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