diff options
Diffstat (limited to 'net')
| -rw-r--r-- | net/bootp.c | 18 | ||||
| -rw-r--r-- | net/eth.c | 74 | ||||
| -rw-r--r-- | net/net.c | 19 | ||||
| -rw-r--r-- | net/tftp.c | 45 |
4 files changed, 118 insertions, 38 deletions
diff --git a/net/bootp.c b/net/bootp.c index b907351f2..8c56c0845 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -330,7 +330,7 @@ BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) /* Retrieve extended information (we must parse the vendor area) */ if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) - BootpVendorProcess(&bp->bp_vend[4], len); + BootpVendorProcess((uchar *)&bp->bp_vend[4], len); NetSetTimeout(0, (thand_f *)0); @@ -387,7 +387,7 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R u8 *x; #endif #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SEND_HOSTNAME) - uchar *hostname; + char *hostname; #endif *e++ = 99; /* RFC1048 Magic Cookie */ @@ -578,7 +578,7 @@ BootpRequest (void) unsigned char bi_enetaddr[6]; int reg; char *e,*s; - uchar tmp[64]; + char tmp[64]; ulong tst1, tst2, sum, m_mask, m_value = 0; if (BootpTry ==0) { @@ -679,9 +679,9 @@ BootpRequest (void) /* Request additional information from the BOOTP/DHCP server */ #if (CONFIG_COMMANDS & CFG_CMD_DHCP) - ext_len = DhcpExtended(bp->bp_vend, DHCP_DISCOVER, 0, 0); + ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0); #else - ext_len = BootpExtended(bp->bp_vend); + ext_len = BootpExtended((u8 *)bp->bp_vend); #endif /* CFG_CMD_DHCP */ /* @@ -836,7 +836,7 @@ static void DhcpSendRequestPkt(Bootp_t *bp_offer) * Copy options from OFFER packet if present */ NetCopyIP(&OfferedIP, &bp->bp_yiaddr); - extlen = DhcpExtended(bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP); + extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP); pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + extlen; iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen; @@ -882,7 +882,7 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) dhcp_state = REQUESTING; if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) - DhcpOptionsProcess(&bp->bp_vend[4]); + DhcpOptionsProcess((u8 *)&bp->bp_vend[4]); BootpCopyNetParams(bp); /* Store net params from reply */ @@ -897,11 +897,11 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len) case REQUESTING: debug ("DHCP State: REQUESTING\n"); - if ( DhcpMessageType(bp->bp_vend) == DHCP_ACK ) { + if ( DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK ) { char *s; if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) - DhcpOptionsProcess(&bp->bp_vend[4]); + DhcpOptionsProcess((u8 *)&bp->bp_vend[4]); BootpCopyNetParams(bp); /* Store net params from reply */ dhcp_state = BOUND; puts ("DHCP client bound to address "); @@ -24,6 +24,7 @@ #include <common.h> #include <command.h> #include <net.h> +#include <miiphy.h> #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI) @@ -47,7 +48,6 @@ 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 ppc_440x_eth_initialize(bd_t *); extern int rtl8139_initialize(bd_t*); extern int rtl8169_initialize(bd_t*); extern int scc_initialize(bd_t*); @@ -61,6 +61,26 @@ 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; @@ -110,13 +130,17 @@ int eth_register(struct eth_device* dev) int eth_initialize(bd_t *bis) { - unsigned char enetvar[32], env_enetaddr[6]; + 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 + #ifdef CONFIG_DB64360 mv6436x_eth_initialize(bis); #endif @@ -126,13 +150,9 @@ int eth_initialize(bd_t *bis) #ifdef CONFIG_DB64460 mv6446x_eth_initialize(bis); #endif -#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \ - ( defined(CONFIG_440) && !defined(CONFIG_NET_MULTI) ) +#if defined(CONFIG_4xx) && !defined(CONFIG_IOP480) && !defined(CONFIG_AP1000) ppc_4xx_eth_initialize(bis); #endif -#if defined(CONFIG_440) && defined(CONFIG_NET_MULTI) - ppc_440x_eth_initialize(bis); -#endif #ifdef CONFIG_INCA_IP_SWITCH inca_switch_initialize(bis); #endif @@ -142,9 +162,6 @@ int eth_initialize(bd_t *bis) #ifdef SCC_ENET scc_initialize(bis); #endif -#if defined(FEC_ENET) || defined(CONFIG_ETHER_ON_FCC) - fec_initialize(bis); -#endif #if defined(CONFIG_MPC5xxx_FEC) mpc5xxx_fec_initialize(bis); #endif @@ -178,6 +195,9 @@ int eth_initialize(bd_t *bis) tsec_initialize(bis, 3, CONFIG_MPC83XX_TSEC4_NAME); # endif #endif +#if defined(FEC_ENET) || defined(CONFIG_ETHER_ON_FCC) + fec_initialize(bis); +#endif #if defined(CONFIG_AU1X00) au1x00_enet_initialize(bis); #endif @@ -307,9 +327,9 @@ void eth_set_enetaddr(int num, char *addr) { debug ( "Setting new HW address on %s\n" "New Address is %02X:%02X:%02X:%02X:%02X:%02X\n", dev->name, - dev->enetaddr[0], dev->enetaddr[1], - dev->enetaddr[2], dev->enetaddr[3], - dev->enetaddr[4], dev->enetaddr[5]); + enetaddr[0], enetaddr[1], + enetaddr[2], enetaddr[3], + enetaddr[4], enetaddr[5]); memcpy(dev->enetaddr, enetaddr, 6); } @@ -418,4 +438,32 @@ char *eth_get_name (void) { return (eth_current ? eth_current->name : "unknown"); } +#elif (CONFIG_COMMANDS & CFG_CMD_NET) && !defined(CONFIG_NET_MULTI) + +extern int at91rm9200_miiphy_initialize(bd_t *bis); +extern int emac4xx_miiphy_initialize(bd_t *bis); +extern int mcf52x2_miiphy_initialize(bd_t *bis); +extern int ns7520_miiphy_initialize(bd_t *bis); + +int eth_initialize(bd_t *bis) +{ +#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) + miiphy_init(); +#endif + +#if defined(CONFIG_AT91RM9200) + at91rm9200_miiphy_initialize(bis); +#endif +#if defined(CONFIG_4xx) && !defined(CONFIG_IOP480) \ + && !defined(CONFIG_AP1000) && !defined(CONFIG_405) + emac4xx_miiphy_initialize(bis); +#endif +#if defined(CONFIG_MCF52x2) + mcf52x2_miiphy_initialize(bis); +#endif +#if defined(CONFIG_NETARM) + ns7520_miiphy_initialize(bis); +#endif + return 0; +} #endif @@ -461,7 +461,7 @@ restart: /* * Echo the inverted link state to the fault LED. */ - if(miiphy_link(CFG_FAULT_MII_ADDR)) { + if(miiphy_link(eth_get_dev()->name, CFG_FAULT_MII_ADDR)) { status_led_set (STATUS_LED_RED, STATUS_LED_OFF); } else { status_led_set (STATUS_LED_RED, STATUS_LED_ON); @@ -512,7 +512,7 @@ restart: /* * Echo the inverted link state to the fault LED. */ - if(miiphy_link(CFG_FAULT_MII_ADDR)) { + if(miiphy_link(eth_get_dev()->name, CFG_FAULT_MII_ADDR)) { status_led_set (STATUS_LED_RED, STATUS_LED_OFF); } else { status_led_set (STATUS_LED_RED, STATUS_LED_ON); @@ -810,6 +810,7 @@ static ushort CDP_compute_csum(const uchar *buff, ushort len) int odd; ulong result = 0; ushort leftover; + ushort *p; if (len > 0) { odd = 1 & (ulong)buff; @@ -819,14 +820,19 @@ static ushort CDP_compute_csum(const uchar *buff, ushort len) buff++; } while (len > 1) { - result += *((const ushort *)buff)++; + p = (ushort *)buff; + result += *p++; + buff = (uchar *)p; if (result & 0x80000000) result = (result & 0xFFFF) + (result >> 16); len -= 2; } if (len) { leftover = (signed short)(*(const signed char *)buff); - /* * XXX CISCO SUCKS big time! (and blows too) */ + /* CISCO SUCKS big time! (and blows too): + * CDP uses the IP checksum algorithm with a twist; + * for the last byte it *sign* extends and sums. + */ result = (result & 0xffff0000) | ((result + leftover) & 0x0000ffff); } while (result >> 16) @@ -1574,10 +1580,11 @@ unsigned NetCksum(uchar * ptr, int len) { ulong xsum; + ushort *p = (ushort *)ptr; xsum = 0; while (len-- > 0) - xsum += *((ushort *)ptr)++; + xsum += *p++; xsum = (xsum & 0xffff) + (xsum >> 16); xsum = (xsum & 0xffff) + (xsum >> 16); return (xsum & 0xffff); @@ -1654,7 +1661,7 @@ NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len) ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2); } -void copy_filename (uchar *dst, uchar *src, int size) +void copy_filename (char *dst, char *src, int size) { if (*src && (*src == '"')) { ++src; diff --git a/net/tftp.c b/net/tftp.c index 64a557666..eca21d294 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -58,7 +58,7 @@ static char default_filename[DEFAULT_NAME_LEN]; static char *tftp_filename; #ifdef CFG_DIRECT_FLASH_TFTP -extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; +extern flash_info_t flash_info[]; #endif static __inline__ void @@ -78,7 +78,7 @@ store_block (unsigned block, uchar * src, unsigned len) } if (rc) { /* Flash is destination for this packet */ - rc = flash_write ((uchar *)src, (ulong)(load_addr+offset), len); + rc = flash_write ((char *)src, (ulong)(load_addr+offset), len); if (rc) { flash_perror (rc); NetState = NETLOOP_FAIL; @@ -106,6 +106,7 @@ TftpSend (void) volatile uchar * pkt; volatile uchar * xp; int len = 0; + volatile ushort *s; /* * We will always be sending some sort of packet, so @@ -117,7 +118,9 @@ TftpSend (void) case STATE_RRQ: xp = pkt; - *((ushort *)pkt)++ = htons(TFTP_RRQ); + s = (ushort *)pkt; + *s++ = htons(TFTP_RRQ); + pkt = (uchar *)s; strcpy ((char *)pkt, tftp_filename); pkt += strlen(tftp_filename) + 1; strcpy ((char *)pkt, "octet"); @@ -135,15 +138,19 @@ TftpSend (void) case STATE_DATA: case STATE_OACK: xp = pkt; - *((ushort *)pkt)++ = htons(TFTP_ACK); - *((ushort *)pkt)++ = htons(TftpBlock); + s = (ushort *)pkt; + *s++ = htons(TFTP_ACK); + *s++ = htons(TftpBlock); + pkt = (uchar *)s; len = pkt - xp; break; case STATE_TOO_LARGE: xp = pkt; - *((ushort *)pkt)++ = htons(TFTP_ERROR); - *((ushort *)pkt)++ = htons(3); + s = (ushort *)pkt; + *s++ = htons(TFTP_ERROR); + *s++ = htons(3); + pkt = (uchar *)s; strcpy ((char *)pkt, "File too large"); pkt += 14 /*strlen("File too large")*/ + 1; len = pkt - xp; @@ -151,8 +158,10 @@ TftpSend (void) case STATE_BAD_MAGIC: xp = pkt; - *((ushort *)pkt)++ = htons(TFTP_ERROR); - *((ushort *)pkt)++ = htons(2); + s = (ushort *)pkt; + *s++ = htons(TFTP_ERROR); + *s++ = htons(2); + pkt = (uchar *)s; strcpy ((char *)pkt, "File has bad magic"); pkt += 18 /*strlen("File has bad magic")*/ + 1; len = pkt - xp; @@ -167,6 +176,7 @@ static void TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len) { ushort proto; + ushort *s; if (dest != TftpOurPort) { return; @@ -180,7 +190,9 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len) } len -= 2; /* warning: don't use increment (++) in ntohs() macros!! */ - proto = *((ushort *)pkt)++; + s = (ushort *)pkt; + proto = *s++; + pkt = (uchar *)s; switch (ntohs(proto)) { case TFTP_RRQ: @@ -301,6 +313,10 @@ TftpTimeout (void) void TftpStart (void) { +#ifdef CONFIG_TFTP_PORT + char *ep; /* Environment pointer */ +#endif + if (BootFile[0] == '\0') { sprintf(default_filename, "%02lX%02lX%02lX%02lX.img", NetOurIP & 0xFF, @@ -352,7 +368,16 @@ TftpStart (void) TftpServerPort = WELL_KNOWN_PORT; TftpTimeoutCount = 0; TftpState = STATE_RRQ; + /* Use a pseudo-random port unless a specific port is set */ TftpOurPort = 1024 + (get_timer(0) % 3072); +#ifdef CONFIG_TFTP_PORT + if ((ep = getenv("tftpdstp")) != NULL) { + TftpServerPort = simple_strtol(ep, NULL, 10); + } + if ((ep = getenv("tftpsrcp")) != NULL) { + TftpOurPort= simple_strtol(ep, NULL, 10); + } +#endif TftpBlock = 0; /* zero out server ether in case the server ip has changed */ |