summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/Makefile12
-rw-r--r--net/bootp.c4
-rw-r--r--net/eth.c7
-rw-r--r--net/net.c36
-rw-r--r--net/nfs.c17
-rw-r--r--net/rarp.c4
-rw-r--r--net/tftp.c36
7 files changed, 69 insertions, 47 deletions
diff --git a/net/Makefile b/net/Makefile
index ff87d87..4f819dd 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -27,14 +27,14 @@ include $(TOPDIR)/config.mk
LIB = $(obj)libnet.a
-COBJS-y += bootp.o
+COBJS-$(CONFIG_CMD_NET) += bootp.o
COBJS-$(CONFIG_CMD_DNS) += dns.o
-COBJS-y += eth.o
-COBJS-y += net.o
-COBJS-y += nfs.o
-COBJS-y += rarp.o
+COBJS-$(CONFIG_CMD_NET) += eth.o
+COBJS-$(CONFIG_CMD_NET) += net.o
+COBJS-$(CONFIG_CMD_NFS) += nfs.o
+COBJS-$(CONFIG_CMD_NET) += rarp.o
COBJS-$(CONFIG_CMD_SNTP) += sntp.o
-COBJS-y += tftp.o
+COBJS-$(CONFIG_CMD_NET) += tftp.o
COBJS := $(COBJS-y)
SRCS := $(COBJS:.o=.c)
diff --git a/net/bootp.c b/net/bootp.c
index 3093852..e679f8b 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -20,8 +20,6 @@
#define BOOTP_VENDOR_MAGIC 0x63825363 /* RFC1048 Magic Cookie */
-#if defined(CONFIG_CMD_NET)
-
#define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */
#ifndef CONFIG_NET_RETRY_COUNT
# define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
@@ -948,5 +946,3 @@ void DhcpRequest(void)
BootpRequest();
}
#endif /* CONFIG_CMD_DHCP */
-
-#endif /* CONFIG_CMD_NET */
diff --git a/net/eth.c b/net/eth.c
index 9b50312..b650a20 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -26,7 +26,6 @@
#include <net.h>
#include <miiphy.h>
-#ifdef CONFIG_CMD_NET
void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
{
char *end;
@@ -60,9 +59,8 @@ int eth_getenv_enetaddr_by_index(int index, uchar *enetaddr)
sprintf(enetvar, index ? "eth%daddr" : "ethaddr", index);
return eth_getenv_enetaddr(enetvar, enetaddr);
}
-#endif
-#if defined(CONFIG_CMD_NET) && defined(CONFIG_NET_MULTI)
+#ifdef CONFIG_NET_MULTI
/*
* CPU and board-specific Ethernet initializations. Aliased function
@@ -492,7 +490,8 @@ char *eth_get_name (void)
{
return (eth_current ? eth_current->name : "unknown");
}
-#elif defined(CONFIG_CMD_NET) && !defined(CONFIG_NET_MULTI)
+
+#else /* !CONFIG_NET_MULTI */
#warning Ethernet driver is deprecated. Please update to use CONFIG_NET_MULTI
diff --git a/net/net.c b/net/net.c
index cab4b2d..595abd9 100644
--- a/net/net.c
+++ b/net/net.c
@@ -96,8 +96,6 @@
#include "dns.h"
#endif
-#if defined(CONFIG_CMD_NET)
-
DECLARE_GLOBAL_DATA_PTR;
#ifndef CONFIG_ARP_TIMEOUT
@@ -197,6 +195,8 @@ volatile uchar *NetTxPacket = 0; /* THE transmit packet */
static int net_check_prereq (proto_t protocol);
+static int NetTryCount;
+
/**********************************************************************/
IPaddr_t NetArpWaitPacketIP;
@@ -320,6 +320,7 @@ NetLoop(proto_t protocol)
NetArpWaitReplyIP = 0;
NetArpWaitTxPacket = NULL;
NetTxPacket = NULL;
+ NetTryCount = 1;
if (!NetTxPacket) {
int i;
@@ -558,17 +559,30 @@ startAgainHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
void NetStartAgain (void)
{
char *nretry;
- int noretry = 0, once = 0;
+ int retry_forever = 0;
+ unsigned long retrycnt = 0;
+
+ nretry = getenv("netretry");
+ if (nretry) {
+ if (!strcmp(nretry, "yes"))
+ retry_forever = 1;
+ else if (!strcmp(nretry, "no"))
+ retrycnt = 0;
+ else if (!strcmp(nretry, "once"))
+ retrycnt = 1;
+ else
+ retrycnt = simple_strtoul(nretry, NULL, 0);
+ } else
+ retry_forever = 1;
- if ((nretry = getenv ("netretry")) != NULL) {
- noretry = (strcmp (nretry, "no") == 0);
- once = (strcmp (nretry, "once") == 0);
- }
- if (noretry) {
- eth_halt ();
+ if ((!retry_forever) && (NetTryCount >= retrycnt)) {
+ eth_halt();
NetState = NETLOOP_FAIL;
return;
}
+
+ NetTryCount++;
+
#ifndef CONFIG_NET_MULTI
NetSetTimeout (10000UL, startAgainTimeout);
NetSetHandler (startAgainHandler);
@@ -580,7 +594,7 @@ void NetStartAgain (void)
eth_init (gd->bd);
if (NetRestartWrap) {
NetRestartWrap = 0;
- if (NetDevExists && !once) {
+ if (NetDevExists) {
NetSetTimeout (10000UL, startAgainTimeout);
NetSetHandler (startAgainHandler);
} else {
@@ -1856,8 +1870,6 @@ void copy_filename (char *dst, char *src, int size)
*dst = '\0';
}
-#endif
-
#if defined(CONFIG_CMD_NFS) || defined(CONFIG_CMD_SNTP) || defined(CONFIG_CMD_DNS)
/*
* make port a little random, but use something trivial to compute
diff --git a/net/nfs.c b/net/nfs.c
index 27395fb..d11bb4c 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -29,8 +29,6 @@
#include "nfs.h"
#include "bootp.h"
-#if defined(CONFIG_CMD_NET) && defined(CONFIG_CMD_NFS)
-
#define HASHES_PER_LINE 65 /* Number of "loading" hashes per line */
#define NFS_RETRY_COUNT 30
#define NFS_TIMEOUT 2000UL
@@ -516,7 +514,7 @@ nfs_readlink_reply (uchar *pkt, unsigned len)
strcat (nfs_path, "/");
pathlen = strlen(nfs_path);
memcpy (nfs_path+pathlen, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
- nfs_path[pathlen+rlen+1] = 0;
+ nfs_path[pathlen + rlen] = 0;
} else {
memcpy (nfs_path, (uchar *)&(rpc_pkt.u.reply.data[2]), rlen);
nfs_path[rlen] = 0;
@@ -571,13 +569,14 @@ Interfaces of U-BOOT
static void
NfsTimeout (void)
{
- if ( NfsTimeoutCount++ < NFS_RETRY_COUNT ) {
+ if ( ++NfsTimeoutCount > NFS_RETRY_COUNT ) {
+ puts ("\nRetry count exceeded; starting again\n");
+ NetStartAgain ();
+ } else {
+ puts("T ");
+ NetSetTimeout (NFS_TIMEOUT, NfsTimeout);
NfsSend ();
- return;
}
- puts ("Timeout\n");
- NetState = NETLOOP_FAIL;
- return;
}
static void
@@ -754,5 +753,3 @@ NfsStart (void)
NfsSend ();
}
-
-#endif
diff --git a/net/rarp.c b/net/rarp.c
index d37981b..9444c03 100644
--- a/net/rarp.c
+++ b/net/rarp.c
@@ -29,8 +29,6 @@
#include "rarp.h"
#include "tftp.h"
-#if defined(CONFIG_CMD_NET)
-
#define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */
#ifndef CONFIG_NET_RETRY_COUNT
# define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
@@ -116,5 +114,3 @@ RarpRequest (void)
NetSetTimeout(TIMEOUT, RarpTimeout);
NetSetHandler(RarpHandler);
}
-
-#endif
diff --git a/net/tftp.c b/net/tftp.c
index cc60a3b..a02463b 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -10,8 +10,6 @@
#include "tftp.h"
#include "bootp.h"
-#if defined(CONFIG_CMD_NET)
-
#define WELL_KNOWN_PORT 69 /* Well known TFTP port # */
#define TIMEOUT 5000UL /* Millisecs to timeout for lost pkt */
#ifndef CONFIG_NET_RETRY_COUNT
@@ -47,6 +45,16 @@ static int TftpTimeoutCountMax = TIMEOUT_COUNT;
ulong TftpRRQTimeoutMSecs = TIMEOUT;
int TftpRRQTimeoutCountMax = TIMEOUT_COUNT;
+enum {
+ TFTP_ERR_UNDEFINED = 0,
+ TFTP_ERR_FILE_NOT_FOUND = 1,
+ TFTP_ERR_ACCESS_DENIED = 2,
+ TFTP_ERR_DISK_FULL = 3,
+ TFTP_ERR_UNEXPECTED_OPCODE = 4,
+ TFTP_ERR_UNKNOWN_TRANSFER_ID = 5,
+ TFTP_ERR_FILE_ALREADY_EXISTS = 6,
+};
+
static IPaddr_t TftpServerIP;
static int TftpServerPort; /* The UDP port at their end */
static int TftpOurPort; /* The UDP port at our end */
@@ -472,11 +480,27 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
case TFTP_ERROR:
printf ("\nTFTP error: '%s' (%d)\n",
pkt + 2, ntohs(*(ushort *)pkt));
- puts ("Starting again\n\n");
+
+ switch (ntohs(*(ushort *)pkt)) {
+ case TFTP_ERR_FILE_NOT_FOUND:
+ case TFTP_ERR_ACCESS_DENIED:
+ puts("Not retrying...\n");
+ eth_halt();
+ NetState = NETLOOP_FAIL;
+ break;
+ case TFTP_ERR_UNDEFINED:
+ case TFTP_ERR_DISK_FULL:
+ case TFTP_ERR_UNEXPECTED_OPCODE:
+ case TFTP_ERR_UNKNOWN_TRANSFER_ID:
+ case TFTP_ERR_FILE_ALREADY_EXISTS:
+ default:
+ puts("Starting again\n\n");
#ifdef CONFIG_MCAST_TFTP
- mcast_cleanup();
+ mcast_cleanup();
#endif
- NetStartAgain ();
+ NetStartAgain();
+ break;
+ }
break;
}
}
@@ -690,5 +714,3 @@ static void parse_multicast_oack(char *pkt, int len)
}
#endif /* Multicast TFTP */
-
-#endif