diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2007-07-05 18:01:23 +0200 |
---|---|---|
committer | Sascha Hauer <sha@octopus.labnet.pengutronix.de> | 2007-07-05 18:01:23 +0200 |
commit | 11a0b5a0dd5f092777de41db00f3ffa8a95d698c (patch) | |
tree | 519db270d85dbbab4dab0928ed43a0c156436093 | |
parent | 3533c30ef469bd5e6ff1f715fcaae4a64066e612 (diff) | |
download | barebox-11a0b5a0dd5f092777de41db00f3ffa8a95d698c.tar.gz barebox-11a0b5a0dd5f092777de41db00f3ffa8a95d698c.tar.xz |
svn_rev_108
removed ifdefs, moved ping to own file, fix timeout handler
-rw-r--r-- | net/Makefile | 15 | ||||
-rw-r--r-- | net/bootp.c | 99 | ||||
-rw-r--r-- | net/eth.c | 393 | ||||
-rw-r--r-- | net/net.c | 159 | ||||
-rw-r--r-- | net/nfs.c | 30 | ||||
-rw-r--r-- | net/rarp.c | 9 | ||||
-rw-r--r-- | net/sntp.c | 44 | ||||
-rw-r--r-- | net/tftp.c | 35 |
8 files changed, 106 insertions, 678 deletions
diff --git a/net/Makefile b/net/Makefile index 1fb5bed7ed..c100e4ffe2 100644 --- a/net/Makefile +++ b/net/Makefile @@ -1,7 +1,8 @@ -obj-y += bootp.o -obj-y += eth.o -obj-y += net.o -obj-y += nfs.o -obj-y += rarp.o -obj-y += sntp.o -obj-y += tftp.o +obj-$(CONFIG_NET) += bootp.o +obj-$(CONFIG_NET) += eth.o +obj-$(CONFIG_NET) += net.o +obj-$(CONFIG_NET_NFS) += nfs.o +obj-$(CONFIG_NET_RARP) += rarp.o +obj-$(CONFIG_NET_SNTP) += sntp.o +obj-$(CONFIG_NET_TFTP) += tftp.o +obj-$(CONFIG_NET_PING) += ping.o diff --git a/net/bootp.c b/net/bootp.c index baded4d1c2..8b7e923c05 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -28,8 +28,6 @@ #define BOOTP_VENDOR_MAGIC 0x63825363 /* RFC1048 Magic Cookie */ -#if (CONFIG_COMMANDS & CFG_CMD_NET) - #define TIMEOUT 5 /* Seconds before trying BOOTP again */ #ifndef CONFIG_NET_RETRY_COUNT # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */ @@ -50,7 +48,7 @@ int BootpTry; ulong seed1, seed2; #endif -#if (CONFIG_COMMANDS & CFG_CMD_DHCP) +#ifdef CONFIG_NET_DHCP dhcp_state_t dhcp_state = INIT; unsigned long dhcp_leasetime = 0; IPaddr_t NetDHCPServerIP = 0; @@ -291,7 +289,6 @@ static void BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) { Bootp_t *bp; - char *s; debug ("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%d)\n", src, dest, len, sizeof (Bootp_t)); @@ -333,7 +330,7 @@ BootpTimeout(void) puts ("\nRetry count exceeded; starting again\n"); NetStartAgain (); } else { - NetSetTimeout (TIMEOUT * CFG_HZ, BootpTimeout); + NetSetTimeout (TIMEOUT * SECOND, BootpTimeout); BootpRequest (); } } @@ -341,7 +338,7 @@ BootpTimeout(void) /* * Initialize BOOTP extension fields in the request. */ -#if (CONFIG_COMMANDS & CFG_CMD_DHCP) +#ifdef CONFIG_NET_DHCP static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP) { u8 *start = e; @@ -468,7 +465,7 @@ static int BootpExtended (u8 * e) *e++ = 83; *e++ = 99; -#if (CONFIG_COMMANDS & CFG_CMD_DHCP) +#ifdef CONFIG_NET_DHCP *e++ = 53; /* DHCP Message Type */ *e++ = 1; *e++ = DHCP_DISCOVER; @@ -534,84 +531,10 @@ BootpRequest (void) Bootp_t *bp; int ext_len, pktlen, iplen; -#if (CONFIG_COMMANDS & CFG_CMD_DHCP) +#ifdef CONFIG_NET_DHCP dhcp_state = INIT; #endif -#ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */ - unsigned char bi_enetaddr[6]; - int reg; - char *e,*s; - char tmp[64]; - ulong tst1, tst2, sum, m_mask, m_value = 0; - - if (BootpTry ==0) { - /* get our mac */ - reg = getenv_r ("ethaddr", tmp, sizeof(tmp)); - s = (reg > 0) ? tmp : NULL; - - for (reg=0; reg<6; ++reg) { - bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0; - if (s) { - s = (*e) ? e+1 : e; - } - } -#ifdef DEBUG - puts ("BootpRequest => Our Mac: "); - for (reg=0; reg<6; reg++) { - printf ("%x%c", - bi_enetaddr[reg], - reg==5 ? '\n' : ':'); - } -#endif /* DEBUG */ - - /* Mac-Manipulation 2 get seed1 */ - tst1=0; - tst2=0; - for (reg=2; reg<6; reg++) { - tst1 = tst1 << 8; - tst1 = tst1 | bi_enetaddr[reg]; - } - for (reg=0; reg<2; reg++) { - tst2 = tst2 | bi_enetaddr[reg]; - tst2 = tst2 << 8; - } - - seed1 = tst1^tst2; - - /* Mirror seed1*/ - m_mask=0x1; - for (reg=1;reg<=32;reg++) { - m_value |= (m_mask & seed1); - seed1 = seed1 >> 1; - m_value = m_value << 1; - } - seed1 = m_value; - seed2 = 0xB78D0945; - } - - /* Random Number Generator */ - - for (reg=0;reg<=0;reg++) { - sum = seed1 + seed2; - if (sum < seed1 || sum < seed2) - sum++; - seed2 = seed1; - seed1 = sum; - - if (BootpTry<=2) { /* Start with max 1024 * 1ms */ - sum = sum >> (22-BootpTry); - } else { /*After 3rd BOOTP request max 8192 * 1ms */ - sum = sum >> 19; - } - } - - printf ("Random delay: %ld ms...\n", sum); - for (reg=0; reg <sum; reg++) { - udelay(1000); /*Wait 1ms*/ - } -#endif /* CONFIG_BOOTP_RANDOM_DELAY */ - printf("BOOTP broadcast %d\n", ++BootpTry); pkt = NetTxPacket; memset ((void*)pkt, 0, PKTSIZE); @@ -634,6 +557,7 @@ BootpRequest (void) bp->bp_hlen = HWL_ETHER; bp->bp_hops = 0; /* FIXME what is this? */ +#warning this is broken // bp->bp_secs = htons(get_timer(0) / CFG_HZ); NetWriteIP(&bp->bp_ciaddr, 0); NetWriteIP(&bp->bp_yiaddr, 0); @@ -643,7 +567,7 @@ BootpRequest (void) copy_filename (bp->bp_file, BootFile, sizeof(bp->bp_file)); /* Request additional information from the BOOTP/DHCP server */ -#if (CONFIG_COMMANDS & CFG_CMD_DHCP) +#ifdef CONFIG_NET_DHCP ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0); #else ext_len = BootpExtended((u8 *)bp->bp_vend); @@ -668,9 +592,9 @@ BootpRequest (void) pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + ext_len; iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len; NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen); - NetSetTimeout(SELECT_TIMEOUT * CFG_HZ, BootpTimeout); + NetSetTimeout(SELECT_TIMEOUT * SECOND, BootpTimeout); -#if (CONFIG_COMMANDS & CFG_CMD_DHCP) +#ifdef CONFIG_NET_DHCP dhcp_state = SELECTING; NetSetHandler(DhcpHandler); #else @@ -679,7 +603,7 @@ BootpRequest (void) NetSendPacket(NetTxPacket, pktlen); } -#if (CONFIG_COMMANDS & CFG_CMD_DHCP) +#ifdef CONFIG_NET_DHCP static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp) { uchar *end = popt + BOOTP_HDR_SIZE; @@ -885,7 +809,7 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) BootpCopyNetParams(bp); /* Store net params from reply */ - NetSetTimeout(TIMEOUT * CFG_HZ, BootpTimeout); + NetSetTimeout(TIMEOUT * SECOND, BootpTimeout); DhcpSendRequestPkt(bp); #ifdef CFG_BOOTFILE_PREFIX } @@ -924,4 +848,3 @@ void DhcpRequest(void) } #endif /* CFG_CMD_DHCP */ -#endif /* CFG_CMD_NET */ @@ -26,392 +26,6 @@ #include <net.h> #include <miiphy.h> -#if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI) - -#ifdef CFG_GT_6426x -extern int gt6426x_eth_initialize(bd_t *bis); -#endif - -extern int au1x00_enet_initialize(bd_t*); -extern int dc21x4x_initialize(bd_t*); -extern int e1000_initialize(bd_t*); -extern int eepro100_initialize(bd_t*); -extern int eth_3com_initialize(bd_t*); -extern int fec_initialize(bd_t*); -extern int inca_switch_initialize(bd_t*); -extern int mpc5xxx_fec_initialize(bd_t*); -extern int mpc8220_fec_initialize(bd_t*); -extern int mv6436x_eth_initialize(bd_t *); -extern int mv6446x_eth_initialize(bd_t *); -extern int natsemi_initialize(bd_t*); -extern int ns8382x_initialize(bd_t*); -extern int pcnet_initialize(bd_t*); -extern int plb2800_eth_initialize(bd_t*); -extern int ppc_4xx_eth_initialize(bd_t *); -extern int rtl8139_initialize(bd_t*); -extern int rtl8169_initialize(bd_t*); -extern int scc_initialize(bd_t*); -extern int skge_initialize(bd_t*); -extern int tsec_initialize(bd_t*, int, char *); -extern int npe_initialize(bd_t *); -extern int uec_initialize(int); - -struct eth_device *eth_get_dev(void) -{ - return eth_current; -} - -struct eth_device *eth_get_dev_by_name(char *devname) -{ - struct eth_device *dev, *target_dev; - - if (!eth_devices) - return NULL; - - dev = eth_devices; - target_dev = NULL; - do { - if (strcmp(devname, dev->name) == 0) { - target_dev = dev; - break; - } - dev = dev->next; - } while (dev != eth_devices); - - return target_dev; -} - -int eth_get_dev_index (void) -{ - struct eth_device *dev; - int num = 0; - - if (!eth_devices) { - return (-1); - } - - for (dev = eth_devices; dev; dev = dev->next) { - if (dev == eth_current) - break; - ++num; - } - - if (dev) { - return (num); - } - - return (0); -} - -int eth_register(struct eth_device* dev) -{ - struct eth_device *d; - - if (!eth_devices) { - eth_current = eth_devices = dev; -#ifdef CONFIG_NET_MULTI - /* update current ethernet name */ - { - char *act = getenv("ethact"); - if (act == NULL || strcmp(act, eth_current->name) != 0) - setenv("ethact", eth_current->name); - } -#endif - } else { - for (d=eth_devices; d->next!=eth_devices; d=d->next); - d->next = dev; - } - - dev->state = ETH_STATE_INIT; - dev->next = eth_devices; - - return 0; -} - -int eth_initialize(bd_t *bis) -{ - char enetvar[32], env_enetaddr[6]; - int i, eth_number = 0; - char *tmp, *end; - - eth_devices = NULL; - eth_current = NULL; - -#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) - miiphy_init(); -#endif - -#if defined(CONFIG_DB64360) || defined(CONFIG_CPCI750) - mv6436x_eth_initialize(bis); -#endif -#if defined(CONFIG_DB64460) || defined(CONFIG_P3Mx) - mv6446x_eth_initialize(bis); -#endif -#if defined(CONFIG_4xx) && !defined(CONFIG_IOP480) && !defined(CONFIG_AP1000) - ppc_4xx_eth_initialize(bis); -#endif -#ifdef CONFIG_INCA_IP_SWITCH - inca_switch_initialize(bis); -#endif -#ifdef CONFIG_PLB2800_ETHER - plb2800_eth_initialize(bis); -#endif -#ifdef SCC_ENET - scc_initialize(bis); -#endif -#if defined(CONFIG_MPC5xxx_FEC) - mpc5xxx_fec_initialize(bis); -#endif -#if defined(CONFIG_MPC8220_FEC) - mpc8220_fec_initialize(bis); -#endif -#if defined(CONFIG_SK98) - skge_initialize(bis); -#endif -#if defined(CONFIG_MPC85XX_TSEC1) - tsec_initialize(bis, 0, CONFIG_MPC85XX_TSEC1_NAME); -#elif defined(CONFIG_MPC83XX_TSEC1) - tsec_initialize(bis, 0, CONFIG_MPC83XX_TSEC1_NAME); -#endif -#if defined(CONFIG_MPC85XX_TSEC2) - tsec_initialize(bis, 1, CONFIG_MPC85XX_TSEC2_NAME); -#elif defined(CONFIG_MPC83XX_TSEC2) - tsec_initialize(bis, 1, CONFIG_MPC83XX_TSEC2_NAME); -#endif -#if defined(CONFIG_MPC85XX_FEC) - tsec_initialize(bis, 2, CONFIG_MPC85XX_FEC_NAME); -#else -# if defined(CONFIG_MPC85XX_TSEC3) - tsec_initialize(bis, 2, CONFIG_MPC85XX_TSEC3_NAME); -# elif defined(CONFIG_MPC83XX_TSEC3) - tsec_initialize(bis, 2, CONFIG_MPC83XX_TSEC3_NAME); -# endif -# if defined(CONFIG_MPC85XX_TSEC4) - tsec_initialize(bis, 3, CONFIG_MPC85XX_TSEC4_NAME); -# elif defined(CONFIG_MPC83XX_TSEC4) - tsec_initialize(bis, 3, CONFIG_MPC83XX_TSEC4_NAME); -# endif -#endif -#if defined(CONFIG_UEC_ETH1) - uec_initialize(0); -#endif -#if defined(CONFIG_UEC_ETH2) - uec_initialize(1); -#endif -#if defined(CONFIG_MPC86XX_TSEC1) - tsec_initialize(bis, 0, CONFIG_MPC86XX_TSEC1_NAME); -#endif - -#if defined(CONFIG_MPC86XX_TSEC2) - tsec_initialize(bis, 1, CONFIG_MPC86XX_TSEC2_NAME); -#endif - -#if defined(CONFIG_MPC86XX_TSEC3) - tsec_initialize(bis, 2, CONFIG_MPC86XX_TSEC3_NAME); -#endif - -#if defined(CONFIG_MPC86XX_TSEC4) - tsec_initialize(bis, 3, CONFIG_MPC86XX_TSEC4_NAME); -#endif - -#if defined(FEC_ENET) || defined(CONFIG_ETHER_ON_FCC) - fec_initialize(bis); -#endif -#if defined(CONFIG_AU1X00) - au1x00_enet_initialize(bis); -#endif -#if defined(CONFIG_IXP4XX_NPE) - npe_initialize(bis); -#endif -#ifdef CONFIG_E1000 - e1000_initialize(bis); -#endif -#ifdef CONFIG_EEPRO100 - eepro100_initialize(bis); -#endif -#ifdef CONFIG_TULIP - dc21x4x_initialize(bis); -#endif -#ifdef CONFIG_3COM - eth_3com_initialize(bis); -#endif -#ifdef CONFIG_PCNET - pcnet_initialize(bis); -#endif -#ifdef CFG_GT_6426x - gt6426x_eth_initialize(bis); -#endif -#ifdef CONFIG_NATSEMI - natsemi_initialize(bis); -#endif -#ifdef CONFIG_NS8382X - ns8382x_initialize(bis); -#endif -#if defined(CONFIG_RTL8139) - rtl8139_initialize(bis); -#endif -#if defined(CONFIG_RTL8169) - rtl8169_initialize(bis); -#endif - - if (!eth_devices) { - puts ("No ethernet found.\n"); - } else { - struct eth_device *dev = eth_devices; - char *ethprime = getenv ("ethprime"); - - do { - if (eth_number) - puts (", "); - - printf("%s", dev->name); - - if (ethprime && strcmp (dev->name, ethprime) == 0) { - eth_current = dev; - puts (" [PRIME]"); - } - - sprintf(enetvar, eth_number ? "eth%daddr" : "ethaddr", eth_number); - tmp = getenv (enetvar); - - for (i=0; i<6; i++) { - env_enetaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0; - if (tmp) - tmp = (*end) ? end+1 : end; - } - - if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6)) { - if (memcmp(dev->enetaddr, "\0\0\0\0\0\0", 6) && - memcmp(dev->enetaddr, env_enetaddr, 6)) - { - printf ("\nWarning: %s MAC addresses don't match:\n", - dev->name); - printf ("Address in SROM is " - "%02X:%02X:%02X:%02X:%02X:%02X\n", - dev->enetaddr[0], dev->enetaddr[1], - dev->enetaddr[2], dev->enetaddr[3], - dev->enetaddr[4], dev->enetaddr[5]); - printf ("Address in environment is " - "%02X:%02X:%02X:%02X:%02X:%02X\n", - env_enetaddr[0], env_enetaddr[1], - env_enetaddr[2], env_enetaddr[3], - env_enetaddr[4], env_enetaddr[5]); - } - - memcpy(dev->enetaddr, env_enetaddr, 6); - } - - eth_number++; - dev = dev->next; - } while(dev != eth_devices); - -#ifdef CONFIG_NET_MULTI - /* update current ethernet name */ - if (eth_current) { - char *act = getenv("ethact"); - if (act == NULL || strcmp(act, eth_current->name) != 0) - setenv("ethact", eth_current->name); - } else - setenv("ethact", NULL); -#endif - - putc ('\n'); - } - - return eth_number; -} - -void eth_set_enetaddr(int num, char *addr) { - struct eth_device *dev; - unsigned char enetaddr[6]; - char *end; - int i; - - debug ("eth_set_enetaddr(num=%d, addr=%s)\n", num, addr); - - if (!eth_devices) - return; - - for (i=0; i<6; i++) { - enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0; - if (addr) - addr = (*end) ? end+1 : end; - } - - dev = eth_devices; - while(num-- > 0) { - dev = dev->next; - - if (dev == eth_devices) - return; - } - - debug ( "Setting new HW address on %s\n" - "New Address is %02X:%02X:%02X:%02X:%02X:%02X\n", - dev->name, - enetaddr[0], enetaddr[1], - enetaddr[2], enetaddr[3], - enetaddr[4], enetaddr[5]); - - memcpy(dev->enetaddr, enetaddr, 6); -} - -void eth_try_another(int first_restart) -{ - static struct eth_device *first_failed = NULL; - - if (!eth_current) - return; - - if (first_restart) { - first_failed = eth_current; - } - - eth_current = eth_current->next; - -#ifdef CONFIG_NET_MULTI - /* update current ethernet name */ - { - char *act = getenv("ethact"); - if (act == NULL || strcmp(act, eth_current->name) != 0) - setenv("ethact", eth_current->name); - } -#endif - - if (first_failed == eth_current) { - NetRestartWrap = 1; - } -} - -#ifdef CONFIG_NET_MULTI -void eth_set_current(void) -{ - char *act; - struct eth_device* old_current; - - if (!eth_current) /* XXX no current */ - return; - - act = getenv("ethact"); - if (act != NULL) { - old_current = eth_current; - do { - if (strcmp(eth_current->name, act) == 0) - return; - eth_current = eth_current->next; - } while (old_current != eth_current); - } - - setenv("ethact", eth_current->name); -} -#endif - -char *eth_get_name (void) -{ - return (eth_current ? eth_current->name : "unknown"); -} -#elif (CONFIG_COMMANDS & CFG_CMD_NET) && !defined(CONFIG_NET_MULTI) - static struct eth_device *eth_current; void eth_set_current(struct eth_device *eth) @@ -469,7 +83,8 @@ extern int ns7520_miiphy_initialize(bd_t *bis); int eth_initialize(bd_t *bis) { unsigned char ethaddr_tmp[20]; - unsigned char *ethaddr, *e = NULL; + unsigned char *ethaddr; + char *e = NULL; int i; if (!eth_current) { @@ -504,6 +119,7 @@ int eth_initialize(bd_t *bis) return -1; } + printf("got MAC address from Environment: %s\n",ethaddr); for(i = 0; i < 6; i++) { eth_current->enetaddr[i] = ethaddr ? simple_strtoul (ethaddr, &e, 16) : 0; if (ethaddr) { @@ -517,7 +133,7 @@ int eth_initialize(bd_t *bis) miiphy_init(); #endif -#if defined(CONFIG_AT91RM9200) +#if defined(CONFIG_DRIVER_NET_AT91_ETHER) at91rm9200_miiphy_initialize(bis); #endif #if defined(CONFIG_4xx) && !defined(CONFIG_IOP480) \ @@ -532,4 +148,3 @@ int eth_initialize(bd_t *bis) #endif return 0; } -#endif @@ -87,12 +87,10 @@ #include <status_led.h> #include <miiphy.h> #endif -#if (CONFIG_COMMANDS & CFG_CMD_SNTP) +#ifdef CONFIG_NET_SNTP #include "sntp.h" #endif -#if (CONFIG_COMMANDS & CFG_CMD_NET) - DECLARE_GLOBAL_DATA_PTR; #define ARP_TIMEOUT (5 * SECOND) /* Seconds before trying ARP again */ @@ -148,17 +146,17 @@ ushort NetOurNativeVLAN = 0xFFFF; /* ditto */ char BootFile[128]; /* Boot File name */ -#if (CONFIG_COMMANDS & CFG_CMD_PING) +#ifdef CONFIG_NET_PING IPaddr_t NetPingIP; /* the ip address to ping */ -static void PingStart(void); +extern void PingStart(void); #endif #if (CONFIG_COMMANDS & CFG_CMD_CDP) static void CDPStart(void); #endif -#if (CONFIG_COMMANDS & CFG_CMD_SNTP) +#ifdef CONFIG_NET_SNTP IPaddr_t NetNtpServerIP; /* NTP server IP address */ int NetTimeOffset=0; /* offset time from UTC */ #endif @@ -174,8 +172,8 @@ volatile uchar *NetRxPackets[PKTBUFSRX]; /* Receive packets */ static rxhand_f *packetHandler; /* Current RX packet handler */ static thand_f *timeHandler; /* Current timeout handler */ -static ulong timeStart; /* Time base value */ -static ulong timeDelta; /* Current timeout value */ +static uint64_t timeStart; /* Time base value */ +static uint64_t timeDelta; /* Current timeout value */ volatile uchar *NetTxPacket = 0; /* THE transmit packet */ static int net_check_prereq (proto_t protocol); @@ -188,7 +186,7 @@ uchar *NetArpWaitPacketMAC; /* MAC address of waiting packet's destinatio uchar *NetArpWaitTxPacket; /* THE transmit packet */ int NetArpWaitTxPacketSize; uchar NetArpWaitPacketBuf[PKTSIZE_ALIGN + PKTALIGN]; -ulong NetArpWaitTimerStart; +uint64_t NetArpWaitTimerStart; int NetArpWaitTry; void ArpRequest (void) @@ -262,8 +260,12 @@ void ArpTimeoutCheck(void) int NetLoop(proto_t protocol) { + IPaddr_t ip; bd_t *bd = gd->bd; + ip = getenv_IPaddr ("ipaddr"); + NetCopyIP(&NetOurIP, &ip); + #ifdef CONFIG_NET_MULTI NetRestarted = 0; NetDevExists = 0; @@ -320,37 +322,36 @@ restart: */ switch (protocol) { -#if (CONFIG_COMMANDS & CFG_CMD_NFS) +#ifdef CONFIG_NET_NFS case NFS: #endif -#if (CONFIG_COMMANDS & CFG_CMD_PING) +#ifdef CONFIG_NET_PING case PING: #endif -#if (CONFIG_COMMANDS & CFG_CMD_SNTP) +#ifdef CONFIG_NET_SNTP case SNTP: #endif case NETCONS: case TFTP: - NetCopyIP(&NetOurIP, &bd->bi_ip_addr); NetOurGatewayIP = getenv_IPaddr ("gatewayip"); NetOurSubnetMask= getenv_IPaddr ("netmask"); NetOurVLAN = getenv_VLAN("vlan"); NetOurNativeVLAN = getenv_VLAN("nvlan"); switch (protocol) { -#if (CONFIG_COMMANDS & CFG_CMD_NFS) +#ifdef CONFIG_NET_NFS case NFS: #endif case NETCONS: case TFTP: NetServerIP = getenv_IPaddr ("serverip"); break; -#if (CONFIG_COMMANDS & CFG_CMD_PING) +#ifdef CONFIG_NET_PING case PING: /* nothing */ break; #endif -#if (CONFIG_COMMANDS & CFG_CMD_SNTP) +#ifdef CONFIG_NET_SNTP case SNTP: /* nothing */ break; @@ -395,12 +396,13 @@ restart: NetDevExists = 1; #endif switch (protocol) { +#ifdef CONFIG_NET_TFTP case TFTP: /* always use ARP to get server ethernet address */ TftpStart(); break; - -#if (CONFIG_COMMANDS & CFG_CMD_DHCP) +#endif +#ifdef CONFIG_NET_DHCP case DHCP: /* Start with a clean slate... */ BootpTry = 0; @@ -408,23 +410,24 @@ restart: NetServerIP = getenv_IPaddr ("serverip"); DhcpRequest(); /* Basically same as BOOTP */ break; -#endif /* CFG_CMD_DHCP */ +#endif case BOOTP: BootpTry = 0; BootpRequest (); break; - +#ifdef CONFIG_NET_RARP case RARP: RarpTry = 0; RarpRequest (); break; -#if (CONFIG_COMMANDS & CFG_CMD_PING) +#endif +#ifdef CONFIG_NET_PING case PING: PingStart(); break; #endif -#if (CONFIG_COMMANDS & CFG_CMD_NFS) +#ifdef CONFIG_NET_NFS case NFS: NfsStart(); break; @@ -439,7 +442,7 @@ restart: NcStart(); break; #endif -#if (CONFIG_COMMANDS & CFG_CMD_SNTP) +#ifdef CONFIG_NET_SNTP case SNTP: SntpStart(); break; @@ -498,7 +501,7 @@ restart: * Check for a timeout, and run the timeout handler * if we have one. */ - if (timeHandler && ((get_time_ns() - timeStart) > timeDelta)) { + if (timeHandler && is_timeout(timeStart, timeDelta)) { thand_f *x; #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) @@ -579,7 +582,7 @@ void NetStartAgain (void) return; } #ifndef CONFIG_NET_MULTI - NetSetTimeout (10 * CFG_HZ, startAgainTimeout); + NetSetTimeout (10 * SECOND, startAgainTimeout); NetSetHandler (startAgainHandler); #else /* !CONFIG_NET_MULTI*/ eth_halt (); @@ -588,7 +591,7 @@ void NetStartAgain (void) if (NetRestartWrap) { NetRestartWrap = 0; if (NetDevExists && !once) { - NetSetTimeout (10 * CFG_HZ, startAgainTimeout); + NetSetTimeout (10 * SECOND, startAgainTimeout); NetSetHandler (startAgainHandler); } else { NetState = NETLOOP_FAIL; @@ -681,96 +684,6 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len) return 0; /* transmitted */ } -#if (CONFIG_COMMANDS & CFG_CMD_PING) -static ushort PingSeqNo; - -int PingSend(void) -{ - static uchar mac[6]; - volatile IP_t *ip; - volatile ushort *s; - uchar *pkt; - - /* XXX always send arp request */ - - memcpy(mac, NetEtherNullAddr, 6); - -#ifdef ET_DEBUG - printf("sending ARP for %08lx\n", NetPingIP); -#endif - - NetArpWaitPacketIP = NetPingIP; - NetArpWaitPacketMAC = mac; - - pkt = NetArpWaitTxPacket; - pkt += NetSetEther(pkt, mac, PROT_IP); - - ip = (volatile IP_t *)pkt; - - /* - * Construct an IP and ICMP header. (need to set no fragment bit - XXX) - */ - ip->ip_hl_v = 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */ - ip->ip_tos = 0; - ip->ip_len = htons(IP_HDR_SIZE_NO_UDP + 8); - ip->ip_id = htons(NetIPID++); - ip->ip_off = htons(0x4000); /* No fragmentation */ - ip->ip_ttl = 255; - ip->ip_p = 0x01; /* ICMP */ - ip->ip_sum = 0; - NetCopyIP((void*)&ip->ip_src, &NetOurIP); /* already in network byte order */ - NetCopyIP((void*)&ip->ip_dst, &NetPingIP); /* - "" - */ - ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2); - - s = &ip->udp_src; /* XXX ICMP starts here */ - s[0] = htons(0x0800); /* echo-request, code */ - s[1] = 0; /* checksum */ - s[2] = 0; /* identifier */ - s[3] = htons(PingSeqNo++); /* sequence number */ - s[1] = ~NetCksum((uchar *)s, 8/2); - - /* size of the waiting packet */ - NetArpWaitTxPacketSize = (pkt - NetArpWaitTxPacket) + IP_HDR_SIZE_NO_UDP + 8; - - /* and do the ARP request */ - NetArpWaitTry = 1; - NetArpWaitTimerStart = get_time_ns(); - ArpRequest(); - return 1; /* waiting */ -} - -static void -PingTimeout (void) -{ - eth_halt(); - NetState = NETLOOP_FAIL; /* we did not get the reply */ -} - -static void -PingHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len) -{ - IPaddr_t tmp; - volatile IP_t *ip = (volatile IP_t *)pkt; - - tmp = NetReadIP((void *)&ip->ip_src); - if (tmp != NetPingIP) - return; - - NetState = NETLOOP_SUCCESS; -} - -static void PingStart(void) -{ -#if defined(CONFIG_NET_MULTI) - printf ("Using %s device\n", eth_get_name()); -#endif /* CONFIG_NET_MULTI */ - NetSetTimeout (10 * CFG_HZ, PingTimeout); - NetSetHandler (PingHandler); - - PingSend(); -} -#endif /* CFG_CMD_PING */ - #if (CONFIG_COMMANDS & CFG_CMD_CDP) #define CDP_DEVICE_ID_TLV 0x0001 @@ -787,7 +700,7 @@ static void PingStart(void) #define CDP_SYSOBJECT_TLV 0x0015 #define CDP_MANAGEMENT_ADDRESS_TLV 0x0016 -#define CDP_TIMEOUT (CFG_HZ/4) /* one packet every 250ms */ +#define CDP_TIMEOUT (250 * MSECOND) /* one packet every 250ms */ static int CDPSeq; static int CDPOK; @@ -1410,7 +1323,7 @@ NetReceive(volatile uchar * inpkt, int len) print_IPaddr(icmph->un.gateway); putc(' '); return; -#if (CONFIG_COMMANDS & CFG_CMD_PING) +#ifdef CONFIG_NET_PING case ICMP_ECHO_REPLY: /* * IP header OK. Pass the packet to the current handler. @@ -1490,7 +1403,7 @@ static int net_check_prereq (proto_t protocol) { switch (protocol) { /* Fall through */ -#if (CONFIG_COMMANDS & CFG_CMD_PING) +#ifdef CONFIG_NET_PING case PING: if (NetPingIP == 0) { puts ("*** ERROR: ping address not given\n"); @@ -1498,7 +1411,7 @@ static int net_check_prereq (proto_t protocol) } goto common; #endif -#if (CONFIG_COMMANDS & CFG_CMD_SNTP) +#ifdef CONFIG_NET_SNTP case SNTP: if (NetNtpServerIP == 0) { puts ("*** ERROR: NTP server address not given\n"); @@ -1506,7 +1419,7 @@ static int net_check_prereq (proto_t protocol) } goto common; #endif -#if (CONFIG_COMMANDS & CFG_CMD_NFS) +#ifdef CONFIG_NET_NFS case NFS: #endif case NETCONS: @@ -1515,9 +1428,7 @@ static int net_check_prereq (proto_t protocol) puts ("*** ERROR: `serverip' not set\n"); return (1); } -#if (CONFIG_COMMANDS & (CFG_CMD_PING | CFG_CMD_SNTP)) common: -#endif if (NetOurIP == 0) { puts ("*** ERROR: `ipaddr' not set\n"); @@ -1667,8 +1578,6 @@ void copy_filename (char *dst, char *src, int size) *dst = '\0'; } -#endif /* CFG_CMD_NET */ - void ip_to_string (IPaddr_t x, char *s) { x = ntohl (x); @@ -24,6 +24,7 @@ #include <common.h> #include <command.h> +#include <clock.h> #include <net.h> #include <malloc.h> #include "nfs.h" @@ -31,8 +32,6 @@ /*#define NFS_DEBUG*/ -#if ((CONFIG_COMMANDS & CFG_CMD_NET) && (CONFIG_COMMANDS & CFG_CMD_NFS)) - #define HASHES_PER_LINE 65 /* Number of "loading" hashes per line */ #define NFS_TIMEOUT 60 @@ -68,28 +67,8 @@ static __inline__ int store_block (uchar * src, unsigned offset, unsigned len) { ulong newsize = offset + len; -#ifdef CFG_DIRECT_FLASH_NFS - int i, rc = 0; - for (i=0; i<CFG_MAX_FLASH_BANKS; i++) { - /* start address in flash? */ - if (load_addr + offset >= flash_info[i].start[0]) { - rc = 1; - break; - } - } - - if (rc) { /* Flash is destination for this packet */ - rc = flash_write ((uchar *)src, (ulong)(load_addr+offset), len); - if (rc) { - flash_perror (rc); - return -1; - } - } else -#endif /* CFG_DIRECT_FLASH_NFS */ - { - (void)memcpy ((void *)(load_addr + offset), src, len); - } + memcpy ((void *)(load_addr + offset), src, len); if (NetBootFileXferSize < (offset+len)) NetBootFileXferSize = newsize; @@ -670,7 +649,7 @@ NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len) case STATE_READ_REQ: rlen = nfs_read_reply (pkt, len); - NetSetTimeout (NFS_TIMEOUT * CFG_HZ, NfsTimeout); + NetSetTimeout (NFS_TIMEOUT * SECOND, NfsTimeout); if (rlen > 0) { nfs_offset += rlen; NfsSend (); @@ -759,7 +738,7 @@ NfsStart (void) printf ("\nLoad address: 0x%lx\n" "Loading: *\b", load_addr); - NetSetTimeout (NFS_TIMEOUT * CFG_HZ, NfsTimeout); + NetSetTimeout (NFS_TIMEOUT * SECOND, NfsTimeout); NetSetHandler (NfsHandler); NfsTimeoutCount = 0; @@ -774,4 +753,3 @@ NfsStart (void) NfsSend (); } -#endif /* CONFIG_COMMANDS & CFG_CMD_NFS */ diff --git a/net/rarp.c b/net/rarp.c index 33d2f65486..e4efa2476c 100644 --- a/net/rarp.c +++ b/net/rarp.c @@ -23,14 +23,13 @@ #include <common.h> #include <command.h> +#include <clock.h> #include <net.h> #include "nfs.h" #include "bootp.h" #include "rarp.h" #include "tftp.h" -#if (CONFIG_COMMANDS & CFG_CMD_NET) - #define TIMEOUT 5 /* Seconds before trying BOOTP again */ #ifndef CONFIG_NET_RETRY_COUNT # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */ @@ -47,7 +46,6 @@ int RarpTry; static void RarpHandler(uchar * dummi0, unsigned dummi1, unsigned dummi2, unsigned dummi3) { - char *s; #ifdef DEBUG puts ("Got good RARP\n"); #endif @@ -65,7 +63,7 @@ RarpTimeout(void) puts ("\nRetry count exceeded; starting again\n"); NetStartAgain (); } else { - NetSetTimeout (TIMEOUT * CFG_HZ, RarpTimeout); + NetSetTimeout (TIMEOUT * SECOND, RarpTimeout); RarpRequest (); } } @@ -100,8 +98,7 @@ RarpRequest (void) NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE); - NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout); + NetSetTimeout(TIMEOUT * SECOND, RarpTimeout); NetSetHandler(RarpHandler); } -#endif /* CFG_CMD_NET */ diff --git a/net/sntp.c b/net/sntp.c index db8c2c2799..df22caef24 100644 --- a/net/sntp.c +++ b/net/sntp.c @@ -7,13 +7,12 @@ #include <common.h> #include <command.h> +#include <clock.h> #include <net.h> #include <rtc.h> #include "sntp.h" -#if ((CONFIG_COMMANDS & CFG_CMD_NET) && (CONFIG_COMMANDS & CFG_CMD_SNTP)) - #define SNTP_TIMEOUT 10 static int SntpOurPort; @@ -35,7 +34,7 @@ SntpSend (void) memcpy ((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE, (char *)&pkt, pktlen); - SntpOurPort = 10000 + (get_timer(0) % 4096); + SntpOurPort = 10000 + ((uint32_t)get_time_ns() % 4096); sport = NTP_SERVICE_PORT; NetSendUDPPacket (NetServerEther, NetNtpServerIP, sport, SntpOurPort, pktlen); @@ -82,11 +81,46 @@ SntpStart (void) { debug ("%s\n", __FUNCTION__); - NetSetTimeout (SNTP_TIMEOUT * CFG_HZ, SntpTimeout); + NetSetTimeout (SNTP_TIMEOUT * SECOND, SntpTimeout); NetSetHandler(SntpHandler); memset (NetServerEther, 0, 6); SntpSend (); } -#endif /* CONFIG_COMMANDS & CFG_CMD_SNTP */ +int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + char *toff; + + if (argc < 2) { + NetNtpServerIP = getenv_IPaddr ("ntpserverip"); + if (NetNtpServerIP == 0) { + printf ("ntpserverip not set\n"); + return (1); + } + } else { + NetNtpServerIP = string_to_ip(argv[1]); + if (NetNtpServerIP == 0) { + printf ("Bad NTP server IP address\n"); + return (1); + } + } + + toff = getenv ("timeoffset"); + if (toff == NULL) NetTimeOffset = 0; + else NetTimeOffset = simple_strtol (toff, NULL, 10); + + if (NetLoop(SNTP) < 0) { + printf("SNTP failed: host %s not responding\n", argv[1]); + return 1; + } + + return 0; +} + +U_BOOT_CMD( + sntp, 2, 1, do_sntp, + "sntp\t- synchronize RTC via network\n", + "[NTP server IP]\n" +); + diff --git a/net/tftp.c b/net/tftp.c index b3fb2c4f0d..79b41a3d11 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -13,8 +13,6 @@ #undef ET_DEBUG -#if (CONFIG_COMMANDS & CFG_CMD_NET) - #define WELL_KNOWN_PORT 69 /* Well known TFTP port # */ #define TIMEOUT 5 /* Seconds to timeout for a lost pkt */ #ifndef CONFIG_NET_RETRY_COUNT @@ -58,36 +56,11 @@ static int TftpState; static char default_filename[DEFAULT_NAME_LEN]; static char *tftp_filename; -#ifdef CFG_DIRECT_FLASH_TFTP -extern flash_info_t flash_info[]; -#endif - static __inline__ void store_block (unsigned block, uchar * src, unsigned len) { ulong offset = block * TFTP_BLOCK_SIZE + TftpBlockWrapOffset; ulong newsize = offset + len; -#ifdef CFG_DIRECT_FLASH_TFTP - int i, rc = 0; - - for (i=0; i<CFG_MAX_FLASH_BANKS; i++) { - /* start address in flash? */ - if (load_addr + offset >= flash_info[i].start[0]) { - rc = 1; - break; - } - } - - if (rc) { /* Flash is destination for this packet */ - rc = flash_write ((char *)src, (ulong)(load_addr+offset), len); - if (rc) { - flash_perror (rc); - NetState = NETLOOP_FAIL; - return; - } - } - else -#endif /* CFG_DIRECT_FLASH_TFTP */ { (void)memcpy((void *)(load_addr + offset), src, len); } @@ -267,7 +240,7 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len) } TftpLastBlock = TftpBlock; - NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout); + NetSetTimeout (TIMEOUT * SECOND, TftpTimeout); store_block (TftpBlock - 1, pkt + 2, len); @@ -305,7 +278,7 @@ TftpTimeout (void) NetStartAgain (); } else { puts ("T "); - NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout); + NetSetTimeout (TIMEOUT * SECOND, TftpTimeout); TftpSend (); } } @@ -363,7 +336,7 @@ TftpStart (void) puts ("Loading: *\b"); - NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout); + NetSetTimeout (TIMEOUT * SECOND, TftpTimeout); NetSetHandler (TftpHandler); TftpServerPort = WELL_KNOWN_PORT; @@ -386,5 +359,3 @@ TftpStart (void) TftpSend (); } - -#endif /* CFG_CMD_NET */ |