mirror of
https://github.com/AsahiLinux/u-boot
synced 2025-02-26 12:27:12 +00:00
net: Make TFTP server timeout configurable
There are two aspects of a TFTP transfer involving timeouts: 1. timeout waiting for initial server reply after sending RRQ 2. timeouts while transferring actual data from the server Since the upcoming auto-update feature attempts a TFTP download during each boot, it is undesirable to have a long delay when the TFTP server is not available. Thus, this commit makes the server timeout (1.) configurable by two global variables: TftpRRQTimeoutMSecs TftpRRQTimeoutCountMax TftpRRQTimeoutMSecs overrides default timeout when trying to connect to a TFTP server, TftpRRQTimeoutCountMax overrides default number of connection retries. The total delay when trying to download a file from a non-existing TFTP server is TftpRRQTimeoutMSecs x TftpRRQTimeoutCountMax milliseconds. Timeouts during file transfers (2.) are unaffected. Signed-off-by: Rafal Czubak <rcz@semihalf.com> Signed-off-by: Bartlomiej Sieka <tur@semihalf.com> Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
This commit is contained in:
parent
49f3bdbba8
commit
e83cc06375
1 changed files with 24 additions and 4 deletions
28
net/tftp.c
28
net/tftp.c
|
@ -34,6 +34,21 @@
|
||||||
#define TFTP_ERROR 5
|
#define TFTP_ERROR 5
|
||||||
#define TFTP_OACK 6
|
#define TFTP_OACK 6
|
||||||
|
|
||||||
|
static ulong TftpTimeoutMSecs = TIMEOUT;
|
||||||
|
static int TftpTimeoutCountMax = TIMEOUT_COUNT;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These globals govern the timeout behavior when attempting a connection to a
|
||||||
|
* TFTP server. TftpRRQTimeoutMSecs specifies the number of milliseconds to
|
||||||
|
* wait for the server to respond to initial connection. Second global,
|
||||||
|
* TftpRRQTimeoutCountMax, gives the number of such connection retries.
|
||||||
|
* TftpRRQTimeoutCountMax must be non-negative and TftpRRQTimeoutMSecs must be
|
||||||
|
* positive. The globals are meant to be set (and restored) by code needing
|
||||||
|
* non-standard timeout behavior when initiating a TFTP transfer.
|
||||||
|
*/
|
||||||
|
ulong TftpRRQTimeoutMSecs = TIMEOUT;
|
||||||
|
int TftpRRQTimeoutCountMax = TIMEOUT_COUNT;
|
||||||
|
|
||||||
static IPaddr_t TftpServerIP;
|
static IPaddr_t TftpServerIP;
|
||||||
static int TftpServerPort; /* The UDP port at their end */
|
static int TftpServerPort; /* The UDP port at their end */
|
||||||
static int TftpOurPort; /* The UDP port at our end */
|
static int TftpOurPort; /* The UDP port at our end */
|
||||||
|
@ -370,7 +385,9 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
|
||||||
}
|
}
|
||||||
|
|
||||||
TftpLastBlock = TftpBlock;
|
TftpLastBlock = TftpBlock;
|
||||||
NetSetTimeout (TIMEOUT, TftpTimeout);
|
TftpTimeoutMSecs = TIMEOUT;
|
||||||
|
TftpTimeoutCountMax = TIMEOUT_COUNT;
|
||||||
|
NetSetTimeout (TftpTimeoutMSecs, TftpTimeout);
|
||||||
|
|
||||||
store_block (TftpBlock - 1, pkt + 2, len);
|
store_block (TftpBlock - 1, pkt + 2, len);
|
||||||
|
|
||||||
|
@ -441,7 +458,7 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
|
||||||
static void
|
static void
|
||||||
TftpTimeout (void)
|
TftpTimeout (void)
|
||||||
{
|
{
|
||||||
if (++TftpTimeoutCount > TIMEOUT_COUNT) {
|
if (++TftpTimeoutCount > TftpTimeoutCountMax) {
|
||||||
puts ("\nRetry count exceeded; starting again\n");
|
puts ("\nRetry count exceeded; starting again\n");
|
||||||
#ifdef CONFIG_MCAST_TFTP
|
#ifdef CONFIG_MCAST_TFTP
|
||||||
mcast_cleanup();
|
mcast_cleanup();
|
||||||
|
@ -449,7 +466,7 @@ TftpTimeout (void)
|
||||||
NetStartAgain ();
|
NetStartAgain ();
|
||||||
} else {
|
} else {
|
||||||
puts ("T ");
|
puts ("T ");
|
||||||
NetSetTimeout (TIMEOUT, TftpTimeout);
|
NetSetTimeout (TftpTimeoutMSecs, TftpTimeout);
|
||||||
TftpSend ();
|
TftpSend ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -520,7 +537,10 @@ TftpStart (void)
|
||||||
|
|
||||||
puts ("Loading: *\b");
|
puts ("Loading: *\b");
|
||||||
|
|
||||||
NetSetTimeout (TIMEOUT, TftpTimeout);
|
TftpTimeoutMSecs = TftpRRQTimeoutMSecs;
|
||||||
|
TftpTimeoutCountMax = TftpRRQTimeoutCountMax;
|
||||||
|
|
||||||
|
NetSetTimeout (TftpTimeoutMSecs, TftpTimeout);
|
||||||
NetSetHandler (TftpHandler);
|
NetSetHandler (TftpHandler);
|
||||||
|
|
||||||
TftpServerPort = WELL_KNOWN_PORT;
|
TftpServerPort = WELL_KNOWN_PORT;
|
||||||
|
|
Loading…
Add table
Reference in a new issue