public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Bartlomiej Sieka <tur@semihalf.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/3] net: Make TFTP server timeout configurable
Date: Thu, 18 Sep 2008 17:03:27 +0200	[thread overview]
Message-ID: <12217502101894-git-send-email-tur@semihalf.com> (raw)
In-Reply-To: <12217502093845-git-send-email-tur@semihalf.com>

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:

TftpRRQTimeoutSecs
TftpRRQTimeoutCountMax

TftpRRQTimeoutSecs 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 TftpRRQTimeoutSecs x TftpRRQTimeoutCountMax seconds.

Timeouts during file transfers (2.) are unaffected.

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
---
 net/tftp.c |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 9aeecb8..fe6a204 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -34,6 +34,21 @@
 #define TFTP_ERROR	5
 #define TFTP_OACK	6
 
+static ulong TftpTimeoutSecs = TIMEOUT;
+static int TftpTimeoutCountMax = TIMEOUT_COUNT;
+
+/*
+ * These globals govern the timeout behavior when attempting a connection to a
+ * TFTP server. TftpRRQTimeoutSecs specifies the number of seconds to wait for
+ * the server to respond to initial connection, and TftpRRQTimeoutCountMax
+ * gives the number of such connection retries. TftpRRQTimeoutCountMax must be
+ * non-negative and TftpRRQTimeoutSecs 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 TftpRRQTimeoutSecs = TIMEOUT;
+int TftpRRQTimeoutCountMax = TIMEOUT_COUNT;
+
 static IPaddr_t TftpServerIP;
 static int	TftpServerPort;		/* The UDP port at their end		*/
 static int	TftpOurPort;		/* The UDP port at our end		*/
@@ -180,7 +195,7 @@ TftpSend (void)
 		pkt += 5 /*strlen("octet")*/ + 1;
 		strcpy ((char *)pkt, "timeout");
 		pkt += 7 /*strlen("timeout")*/ + 1;
-		sprintf((char *)pkt, "%lu", TIMEOUT);
+		sprintf((char *)pkt, "%lu", TftpTimeoutSecs);
 #ifdef ET_DEBUG
 		printf("send option \"timeout %s\"\n", (char *)pkt);
 #endif
@@ -370,7 +385,9 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
 		}
 
 		TftpLastBlock = TftpBlock;
-		NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout);
+		TftpTimeoutSecs = TIMEOUT;
+		TftpTimeoutCountMax = TIMEOUT_COUNT;
+		NetSetTimeout (TftpTimeoutSecs * CFG_HZ, TftpTimeout);
 
 		store_block (TftpBlock - 1, pkt + 2, len);
 
@@ -441,7 +458,7 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
 static void
 TftpTimeout (void)
 {
-	if (++TftpTimeoutCount > TIMEOUT_COUNT) {
+	if (++TftpTimeoutCount > TftpTimeoutCountMax) {
 		puts ("\nRetry count exceeded; starting again\n");
 #ifdef CONFIG_MCAST_TFTP
 		mcast_cleanup();
@@ -449,7 +466,7 @@ TftpTimeout (void)
 		NetStartAgain ();
 	} else {
 		puts ("T ");
-		NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout);
+		NetSetTimeout (TftpTimeoutSecs * CFG_HZ, TftpTimeout);
 		TftpSend ();
 	}
 }
@@ -520,7 +537,10 @@ TftpStart (void)
 
 	puts ("Loading: *\b");
 
-	NetSetTimeout (TIMEOUT * CFG_HZ, TftpTimeout);
+	TftpTimeoutSecs = TftpRRQTimeoutSecs;
+	TftpTimeoutCountMax = TftpRRQTimeoutCountMax;
+
+	NetSetTimeout (TftpTimeoutSecs * CFG_HZ, TftpTimeout);
 	NetSetHandler (TftpHandler);
 
 	TftpServerPort = WELL_KNOWN_PORT;
-- 
1.5.3.4

  reply	other threads:[~2008-09-18 15:03 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-18 15:03 [U-Boot] Automatic software updates in U-Boot Bartlomiej Sieka
2008-09-18 15:03 ` Bartlomiej Sieka [this message]
2008-09-18 15:17   ` [U-Boot] [PATCH 1/3] net: Make TFTP server timeout configurable Jerry Van Baren
2008-09-18 21:54     ` Graeme Russ
2008-09-19  1:37       ` Jerry Van Baren
2008-09-19  5:52     ` Bartlomiej Sieka
2008-09-22 20:42       ` Wolfgang Denk
2008-09-25  6:17         ` Bartlomiej Sieka
2008-09-18 15:03 ` [U-Boot] [PATCH 2/3] Automatic software update from TFTP server Bartlomiej Sieka
2008-09-22 21:03   ` Wolfgang Denk
2008-09-25  8:16     ` Bartlomiej Sieka
2008-09-25  8:55       ` Wolfgang Denk
2008-09-25  9:49         ` Bartlomiej Sieka
2008-09-25 10:01           ` Wolfgang Denk
2008-09-26  8:46             ` Detlev Zundel
2008-09-25 15:33       ` Andrew Dyer
2008-09-25 16:28         ` Kim Phillips
2008-09-25 16:24           ` Jerry Van Baren
2008-09-25 18:17           ` Wolfgang Denk
2008-09-25 19:21             ` Kim Phillips
2008-09-26  8:08               ` Bartlomiej Sieka
2008-09-26  8:29                 ` Wolfgang Denk
2008-09-26  8:29                   ` Bartlomiej Sieka
2008-09-18 15:03 ` [U-Boot] [PATCH 3/3] FIT: output image load address for type 'firmware', fix debug msg while there Bartlomiej Sieka
2008-10-01 13:26 ` [U-Boot] Automatic software updates in U-Boot -- version 2 Bartlomiej Sieka
2008-10-13 22:57   ` Wolfgang Denk
2008-10-14 12:42     ` Bartlomiej Sieka
2008-10-14 13:47       ` Wolfgang Denk
2008-10-14 20:07       ` Wolfgang Denk
2008-10-15  9:45         ` Bartlomiej Sieka
2008-10-01 13:26 ` [U-Boot] [PATCH v2 1/6] flash: factor out adjusting of Flash address to the end of sector Bartlomiej Sieka
2008-10-08  7:39   ` Bartlomiej Sieka
2008-10-08  7:47     ` Stefan Roese
2008-10-08  8:05       ` Bartlomiej Sieka
2008-10-08  8:16         ` Wolfgang Denk
2008-10-08 12:02           ` Stefan Roese
2008-10-13 22:28             ` Wolfgang Denk
2008-10-08 17:38           ` Ben Warren
2008-10-13 22:30             ` Wolfgang Denk
2008-10-01 13:26 ` [U-Boot] [PATCH v2 2/6] net: express the first argument to NetSetTimeout() in milliseconds Bartlomiej Sieka
2008-10-06  5:13   ` Ben Warren
2008-10-01 13:26 ` [U-Boot] [PATCH v2 3/6] net: Make TFTP server timeout configurable Bartlomiej Sieka
2008-10-06  5:13   ` Ben Warren
2008-10-01 13:26 ` [U-Boot] [PATCH v2 4/6] Restore alphabetic ordering in common/Makefile Bartlomiej Sieka
2008-10-08 12:29   ` Jean-Christophe PLAGNIOL-VILLARD
2008-10-08 12:58     ` Bartlomiej Sieka
2008-10-08 14:50       ` Jean-Christophe PLAGNIOL-VILLARD
2008-10-09  8:40         ` Bartlomiej Sieka
2008-10-01 13:26 ` [U-Boot] [PATCH v2 5/6] Automatic software update from TFTP server Bartlomiej Sieka
2008-10-13 22:37   ` Wolfgang Denk
2008-10-01 13:26 ` [U-Boot] [PATCH v2 6/6] FIT: output image load address for type 'firmware', fix message while there Bartlomiej Sieka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12217502101894-git-send-email-tur@semihalf.com \
    --to=tur@semihalf.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox