mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* more network patches
@ 2010-06-24  9:35 Sascha Hauer
  2010-06-24  9:35 ` [PATCH 1/8] tftp: remove unused variables Sascha Hauer
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Sascha Hauer @ 2010-06-24  9:35 UTC (permalink / raw)
  To: barebox

Hi All,

Here are some more network related patches. I added a generic progression
bar function for use with tftp/nfs. Further more tftp gets push support.

Sascha

The following changes since commit 334fe1dc8a1b866d1f0f4ccf82ff7b06589ec022:

  pca100: use generic default env (2010-06-22 15:44:45 +0200)

are available in the git repository at:
  git://git.pengutronix.de/git/barebox.git net-pu

Sascha Hauer (8):
      tftp: remove unused variables
      add progression bar function
      cfi flash driver: Use generic progression bar function
      tftp: use generic progression bar
      tftp: Add push support
      nfs: Use generic progression bar
      nfs: resend requests after timeout
      tftp: update doxygen information

 drivers/nor/cfi_flash.c |    5 +-
 include/progress.h      |   15 +++
 lib/Makefile            |    1 +
 lib/show_progress.c     |   62 +++++++++++++
 net/Kconfig             |    4 +
 net/nfs.c               |   26 +++---
 net/tftp.c              |  231 +++++++++++++++++++++++++++++++++--------------
 7 files changed, 262 insertions(+), 82 deletions(-)
 create mode 100644 include/progress.h
 create mode 100644 lib/show_progress.c



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/8] tftp: remove unused variables
  2010-06-24  9:35 more network patches Sascha Hauer
@ 2010-06-24  9:35 ` Sascha Hauer
  2010-06-24  9:35 ` [PATCH 2/8] add progression bar function Sascha Hauer
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2010-06-24  9:35 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/tftp.c |    9 +--------
 1 files changed, 1 insertions(+), 8 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 38d16bc..338359b 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -35,8 +35,6 @@
 static int		tftp_server_port;	/* The UDP port at their end		*/
 static unsigned int	tftp_block;		/* packet sequence number		*/
 static unsigned int	tftp_last_block;	/* last packet sequence number received */
-static unsigned int	tftp_block_wrap;	/* count of sequence number wraparounds */
-static unsigned int	tftp_block_wrap_offset;	/* memory offset due to wrapping	*/
 static int		tftp_state;
 static uint64_t		tftp_timer_start;
 static int		tftp_err;
@@ -135,10 +133,7 @@ static void tftp_handler(char *packet, unsigned len)
 		 * number of 0 this means that there was a wrap
 		 * around of the (16 bit) counter.
 		 */
-		if (tftp_block == 0) {
-			tftp_block_wrap++;
-			tftp_block_wrap_offset += TFTP_BLOCK_SIZE * TFTP_SEQUENCE_SIZE;
-		} else {
+		if (tftp_block) {
 			if (((tftp_block - 1) % 10) == 0) {
 				putchar('#');
 			} else if ((tftp_block % (10 * HASHES_PER_LINE)) == 0) {
@@ -155,8 +150,6 @@ static void tftp_handler(char *packet, unsigned len)
 			tftp_con->udp->uh_dport = udp->uh_sport;
 			tftp_server_port = ntohs(udp->uh_sport);
 			tftp_last_block = 0;
-			tftp_block_wrap = 0;
-			tftp_block_wrap_offset = 0;
 
 			if (tftp_block != 1) {	/* Assertion */
 				printf("error: First block is not block 1 (%ld)\n",
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/8] add progression bar function
  2010-06-24  9:35 more network patches Sascha Hauer
  2010-06-24  9:35 ` [PATCH 1/8] tftp: remove unused variables Sascha Hauer
@ 2010-06-24  9:35 ` Sascha Hauer
  2010-06-24  9:35 ` [PATCH 3/8] cfi flash driver: Use generic " Sascha Hauer
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2010-06-24  9:35 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/progress.h  |   15 ++++++++++++
 lib/Makefile        |    1 +
 lib/show_progress.c |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 0 deletions(-)
 create mode 100644 include/progress.h
 create mode 100644 lib/show_progress.c

diff --git a/include/progress.h b/include/progress.h
new file mode 100644
index 0000000..5c4dd1e
--- /dev/null
+++ b/include/progress.h
@@ -0,0 +1,15 @@
+#ifndef __PROGRSS_H
+#define __PROGRSS_H
+
+/* Initialize a progress bar. If max > 0 a one line progress
+ * bar is printed where 'max' corresponds to 100%. If max == 0
+ * a multi line progress bar is printed.
+ */
+void init_progression_bar(int max);
+
+/* update a progress bar to a new value. If now < 0 then a
+ * spinner is printed.
+ */
+void show_progress(int now);
+
+#endif /*  __PROGRSS_H */
diff --git a/lib/Makefile b/lib/Makefile
index 4a33aaa..5afbf13 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -30,5 +30,6 @@ obj-y			+= notifier.o
 obj-y			+= copy_file.o
 obj-y			+= random.o
 obj-y			+= lzo/
+obj-y			+= show_progress.o
 obj-$(CONFIG_LZO_DECOMPRESS)		+= decompress_unlzo.o
 obj-$(CONFIG_PROCESS_ESCAPE_SEQUENCE)	+= process_escape_sequence.o
diff --git a/lib/show_progress.c b/lib/show_progress.c
new file mode 100644
index 0000000..333f498
--- /dev/null
+++ b/lib/show_progress.c
@@ -0,0 +1,62 @@
+/*
+ * show_progress.c - simple progress bar functions
+ *
+ * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <common.h>
+#include <progress.h>
+
+#define HASHES_PER_LINE	65
+
+static int printed;
+static int progress_max;
+static int spin;
+
+void show_progress(int now)
+{
+	char spinchr[] = "\\|/-";
+
+	if (now < 0) {
+		printf("%c\b", spinchr[spin++ % (sizeof(spinchr) - 1)]);
+		return;
+	}
+
+	if (progress_max)
+		now = now * HASHES_PER_LINE / progress_max;
+
+	while (printed < now) {
+		if (!(printed % HASHES_PER_LINE) && printed)
+			printf("\n\t");
+		printf("#");
+		printed++;
+	}
+}
+
+void init_progression_bar(int max)
+{
+	printed = 0;
+	progress_max = max;
+	spin = 0;
+	if (progress_max)
+		printf("\t[%65s]\r\t[", "");
+	else
+		printf("\t");
+}
+
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/8] cfi flash driver: Use generic progression bar function
  2010-06-24  9:35 more network patches Sascha Hauer
  2010-06-24  9:35 ` [PATCH 1/8] tftp: remove unused variables Sascha Hauer
  2010-06-24  9:35 ` [PATCH 2/8] add progression bar function Sascha Hauer
@ 2010-06-24  9:35 ` Sascha Hauer
  2010-06-24  9:35 ` [PATCH 4/8] tftp: use generic progression bar Sascha Hauer
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2010-06-24  9:35 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/nor/cfi_flash.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index dbfb004..b21739b 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -42,6 +42,7 @@
 #include <malloc.h>
 #include <asm/io.h>
 #include <errno.h>
+#include <progress.h>
 #include "cfi_flash.h"
 
 /*
@@ -499,11 +500,13 @@ static int cfi_erase(struct cdev *cdev, size_t count, unsigned long offset)
         start = find_sector(finfo, cdev->dev->map_base + offset);
         end   = find_sector(finfo, cdev->dev->map_base + offset + count - 1);
 
+	init_progression_bar(end - start);
+
         for (i = start; i <= end; i++) {
                 ret = finfo->cfi_cmd_set->flash_erase_one(finfo, i);
                 if (ret)
                         goto out;
-		printf(".");
+		show_progress(i - start);
         }
 out:
         putchar('\n');
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/8] tftp: use generic progression bar
  2010-06-24  9:35 more network patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2010-06-24  9:35 ` [PATCH 3/8] cfi flash driver: Use generic " Sascha Hauer
@ 2010-06-24  9:35 ` Sascha Hauer
  2010-06-24  9:35 ` [PATCH 5/8] tftp: Add push support Sascha Hauer
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2010-06-24  9:35 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/tftp.c |   34 +++++++++++++---------------------
 1 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 338359b..4b60cc8 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -13,13 +13,11 @@
 #include <errno.h>
 #include <libgen.h>
 #include <fcntl.h>
+#include <progress.h>
 #include <linux/err.h>
 
 #define TFTP_PORT	69		/* Well known TFTP port #		*/
 #define TIMEOUT		5		/* Seconds to timeout for a lost pkt	*/
-# define TIMEOUT_COUNT	10		/* # of timeouts before giving up  */
-					/* (for checking the image size)	*/
-#define HASHES_PER_LINE	65		/* Number of "loading" hashes per line	*/
 
 /*
  *	TFTP operations.
@@ -50,6 +48,7 @@ static int		tftp_err;
 static char *tftp_filename;
 static struct net_connection *tftp_con;
 static int net_store_fd;
+static int tftp_size;
 
 static int tftp_send(void)
 {
@@ -84,6 +83,8 @@ static int tftp_send(void)
 		break;
 	}
 
+	tftp_timer_start = get_time_ns();
+	show_progress(tftp_size);
 	ret = net_udp_send(tftp_con, len);
 
 	return ret;
@@ -127,20 +128,6 @@ static void tftp_handler(char *packet, unsigned len)
 		len -= 2;
 		tftp_block = ntohs(*(uint16_t *)pkt);
 
-		/*
-		 * RFC1350 specifies that the first data packet will
-		 * have sequence number 1. If we receive a sequence
-		 * number of 0 this means that there was a wrap
-		 * around of the (16 bit) counter.
-		 */
-		if (tftp_block) {
-			if (((tftp_block - 1) % 10) == 0) {
-				putchar('#');
-			} else if ((tftp_block % (10 * HASHES_PER_LINE)) == 0) {
-				puts("\n\t ");
-			}
-		}
-
 		if (tftp_state == STATE_RRQ)
 			debug("Server did not acknowledge timeout option!\n");
 
@@ -165,7 +152,9 @@ static void tftp_handler(char *packet, unsigned len)
 			break;
 
 		tftp_last_block = tftp_block;
-		tftp_timer_start = get_time_ns();
+
+		if (!(tftp_block % 10))
+			tftp_size++;
 
 		ret = write(net_store_fd, pkt + 2, len);
 		if (ret < 0) {
@@ -205,6 +194,8 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 	char *remotefile;
 	char ip1[16];
 
+	tftp_size = 0;
+
 	if (argc < 2)
 		return COMMAND_ERROR_USAGE;
 
@@ -229,10 +220,12 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 
 	tftp_filename = remotefile;
 
-	printf("TFTP from server %s; Filename: '%s'\nLoading: ",
+	printf("TFTP from server %s; Filename: '%s'\n",
 			ip_to_string(net_get_serverip(), ip1),
 			tftp_filename);
 
+	init_progression_bar(0);
+
 	tftp_timer_start = get_time_ns();
 	tftp_state = STATE_RRQ;
 	tftp_block = 0;
@@ -248,8 +241,7 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 		}
 		net_poll();
 		if (is_timeout(tftp_timer_start, SECOND)) {
-			tftp_timer_start = get_time_ns();
-			printf("T ");
+			show_progress(-1);
 			tftp_send();
 		}
 	}
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/8] tftp: Add push support
  2010-06-24  9:35 more network patches Sascha Hauer
                   ` (3 preceding siblings ...)
  2010-06-24  9:35 ` [PATCH 4/8] tftp: use generic progression bar Sascha Hauer
@ 2010-06-24  9:35 ` Sascha Hauer
  2010-06-24  9:35 ` [PATCH 6/8] nfs: Use generic progression bar Sascha Hauer
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2010-06-24  9:35 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/Kconfig |    4 ++
 net/tftp.c  |  173 +++++++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 142 insertions(+), 35 deletions(-)

diff --git a/net/Kconfig b/net/Kconfig
index ff6e455..3169d20 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -19,6 +19,10 @@ config NET_TFTP
 	bool
 	prompt "tftp support"
 
+config NET_TFTP_PUSH
+	bool
+	prompt "tftp push support"
+
 config NET_NETCONSOLE
 	bool
 	prompt "network console support"
diff --git a/net/tftp.c b/net/tftp.c
index 4b60cc8..000d0cf 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -14,6 +14,9 @@
 #include <libgen.h>
 #include <fcntl.h>
 #include <progress.h>
+#include <getopt.h>
+#include <fs.h>
+#include <linux/stat.h>
 #include <linux/err.h>
 
 #define TFTP_PORT	69		/* Well known TFTP port #		*/
@@ -38,41 +41,89 @@ static uint64_t		tftp_timer_start;
 static int		tftp_err;
 
 #define STATE_RRQ	1
-#define STATE_DATA	2
-#define STATE_OACK	3
-#define STATE_DONE	4
+#define STATE_WRQ	2
+#define STATE_RDATA	3
+#define STATE_WDATA	4
+#define STATE_OACK	5
+#define STATE_LAST	6
+#define STATE_DONE	7
 
 #define TFTP_BLOCK_SIZE		512		    /* default TFTP block size	*/
-#define TFTP_SEQUENCE_SIZE	((unsigned long)(1<<16))    /* sequence number is 16 bit */
 
 static char *tftp_filename;
 static struct net_connection *tftp_con;
-static int net_store_fd;
+static int tftp_fd;
 static int tftp_size;
 
+#ifdef CONFIG_NET_TFTP_PUSH
+static int tftp_put;
+
+static inline void do_tftp_push(int push)
+{
+	tftp_put = push;
+}
+
+#else
+
+#define tftp_put	0
+
+static inline void do_tftp_push(int push)
+{
+}
+#endif
+
 static int tftp_send(void)
 {
-	unsigned char *pkt;
 	unsigned char *xp;
 	int len = 0;
 	uint16_t *s;
-	unsigned char *packet = net_udp_get_payload(tftp_con);
+	unsigned char *pkt = net_udp_get_payload(tftp_con);
 	int ret;
-
-	pkt = packet;
+	static int last_len;
 
 	switch (tftp_state) {
 	case STATE_RRQ:
+	case STATE_WRQ:
 		xp = pkt;
 		s = (uint16_t *)pkt;
-		*s++ = htons(TFTP_RRQ);
+		if (tftp_state == STATE_RRQ)
+			*s++ = htons(TFTP_RRQ);
+		else
+			*s++ = htons(TFTP_WRQ);
 		pkt = (unsigned char *)s;
 		pkt += sprintf((unsigned char *)pkt, "%s%coctet%ctimeout%c%d",
 				tftp_filename, 0, 0, 0, TIMEOUT) + 1;
 		len = pkt - xp;
 		break;
 
-	case STATE_DATA:
+	case STATE_WDATA:
+		if (!tftp_put)
+			break;
+
+		if (tftp_last_block == tftp_block) {
+			len = last_len;
+			break;
+		}
+
+		tftp_last_block = tftp_block;
+		s = (uint16_t *)pkt;
+		*s++ = htons(TFTP_DATA);
+		*s++ = htons(tftp_block);
+		len = read(tftp_fd, s, 512);
+		if (len < 0) {
+			perror("read");
+			tftp_err = -errno;
+			tftp_state = STATE_DONE;
+			return tftp_err;
+		}
+		tftp_size += len;
+		if (len < 512)
+			tftp_state = STATE_LAST;
+		len += 4;
+		last_len = len;
+		break;
+
+	case STATE_RDATA:
 	case STATE_OACK:
 		xp = pkt;
 		s = (uint16_t *)pkt;
@@ -103,17 +154,34 @@ static void tftp_handler(char *packet, unsigned len)
 		return;
 
 	len -= 2;
-	/* warning: don't use increment (++) in ntohs() macros!! */
+
 	s = (uint16_t *)pkt;
 	proto = *s++;
 	pkt = (unsigned char *)s;
+
 	switch (ntohs(proto)) {
 	case TFTP_RRQ:
 	case TFTP_WRQ:
-	case TFTP_ACK:
-		break;
 	default:
 		break;
+	case TFTP_ACK:
+		if (!tftp_put)
+			break;
+
+		tftp_block = ntohs(*(uint16_t *)pkt);
+		if (tftp_block != tftp_last_block) {
+			debug("ack %d != %d\n", tftp_block, tftp_last_block);
+			break;
+		}
+		tftp_block++;
+		if (tftp_state == STATE_LAST) {
+			tftp_state = STATE_DONE;
+			break;
+		}
+		tftp_con->udp->uh_dport = udp->uh_sport;
+		tftp_state = STATE_WDATA;
+		tftp_send();
+		break;
 
 	case TFTP_OACK:
 		debug("Got OACK: %s %s\n", pkt, pkt + strlen(pkt) + 1);
@@ -133,7 +201,7 @@ static void tftp_handler(char *packet, unsigned len)
 
 		if (tftp_state == STATE_RRQ || tftp_state == STATE_OACK) {
 			/* first block received */
-			tftp_state = STATE_DATA;
+			tftp_state = STATE_RDATA;
 			tftp_con->udp->uh_dport = udp->uh_sport;
 			tftp_server_port = ntohs(udp->uh_sport);
 			tftp_last_block = 0;
@@ -156,7 +224,7 @@ static void tftp_handler(char *packet, unsigned len)
 		if (!(tftp_block % 10))
 			tftp_size++;
 
-		ret = write(net_store_fd, pkt + 2, len);
+		ret = write(tftp_fd, pkt + 2, len);
 		if (ret < 0) {
 			perror("write");
 			tftp_err = -errno;
@@ -190,24 +258,47 @@ static void tftp_handler(char *packet, unsigned len)
 
 static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 {
-	char *localfile;
-	char *remotefile;
+	char *localfile, *remotefile, *file1, *file2;
 	char ip1[16];
+	int opt;
+	struct stat s;
+	unsigned long flags;
 
+	do_tftp_push(0);
+	tftp_last_block = 0;
 	tftp_size = 0;
 
-	if (argc < 2)
+	while((opt = getopt(argc, argv, "p")) > 0) {
+		switch(opt) {
+		case 'p':
+			do_tftp_push(1);
+			break;
+		}
+	}
+
+	if (argc <= optind)
 		return COMMAND_ERROR_USAGE;
 
-	remotefile = argv[1];
+	file1 = argv[optind++];
 
-	if (argc == 2)
-		localfile = basename(remotefile);
+	if (argc == optind)
+		file2 = basename(file1);
 	else
-		localfile = argv[2];
+		file2 = argv[optind];
+
+	if (tftp_put) {
+		localfile = file1;
+		remotefile = file2;
+		stat(localfile, &s);
+		flags = O_RDONLY;
+	} else {
+		localfile = file2;
+		remotefile = file1;
+		flags = O_WRONLY | O_CREAT;
+	}
 
-	net_store_fd = open(localfile, O_WRONLY | O_CREAT);
-	if (net_store_fd < 0) {
+	tftp_fd = open(localfile, flags);
+	if (tftp_fd < 0) {
 		perror("open");
 		return 1;
 	}
@@ -220,15 +311,16 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 
 	tftp_filename = remotefile;
 
-	printf("TFTP from server %s; Filename: '%s'\n",
+	printf("TFTP %s server %s ('%s' -> '%s')\n",
+			tftp_put ? "to" : "from",
 			ip_to_string(net_get_serverip(), ip1),
-			tftp_filename);
+			file1, file2);
 
-	init_progression_bar(0);
+	init_progression_bar(tftp_put ? s.st_size : 0);
 
 	tftp_timer_start = get_time_ns();
-	tftp_state = STATE_RRQ;
-	tftp_block = 0;
+	tftp_state = tftp_put ? STATE_WRQ : STATE_RRQ;
+	tftp_block = 1;
 
 	tftp_err = tftp_send();
 	if (tftp_err)
@@ -248,11 +340,12 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
 out_unreg:
 	net_unregister(tftp_con);
 out_close:
-	close(net_store_fd);
+	close(tftp_fd);
 
 	if (tftp_err) {
 		printf("\ntftp failed: %s\n", strerror(-tftp_err));
-		unlink(localfile);
+		if (!tftp_put)
+			unlink(localfile);
 	}
 
 	printf("\n");
@@ -261,12 +354,22 @@ out_close:
 }
 
 static const __maybe_unused char cmd_tftp_help[] =
-"Usage: tftp <file> [localfile]\n"
-"Load a file via network using BootP/TFTP protocol.\n";
+"Usage: tftp <remotefile> [localfile]\n"
+"Load a file from a TFTP server.\n"
+#ifdef CONFIG_NET_TFTP_PUSH
+"or\n"
+"       tftp -p <localfile> [remotefile]\n"
+"Upload a file to a TFTP server\n"
+#endif
+;
 
 BAREBOX_CMD_START(tftp)
 	.cmd		= do_tftpb,
-	.usage		= "Load file using tftp protocol",
+	.usage		=
+#ifdef CONFIG_NET_TFTP_PUSH
+			"(up-)"
+#endif
+			"Load file using tftp protocol",
 	BAREBOX_CMD_HELP(cmd_tftp_help)
 BAREBOX_CMD_END
 
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/8] nfs: Use generic progression bar
  2010-06-24  9:35 more network patches Sascha Hauer
                   ` (4 preceding siblings ...)
  2010-06-24  9:35 ` [PATCH 5/8] tftp: Add push support Sascha Hauer
@ 2010-06-24  9:35 ` Sascha Hauer
  2010-06-24  9:35 ` [PATCH 7/8] nfs: resend requests after timeout Sascha Hauer
  2010-06-24  9:35 ` [PATCH 8/8] tftp: update doxygen information Sascha Hauer
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2010-06-24  9:35 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/nfs.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/net/nfs.c b/net/nfs.c
index 51df7a3..bdf05bd 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -32,6 +32,7 @@
 #include <libgen.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <progress.h>
 #include <linux/err.h>
 
 #define SUNRPC_PORT     111
@@ -123,7 +124,6 @@ struct rpc_t {
 	} u;
 };
 
-#define HASHES_PER_LINE 65	/* Number of "loading" hashes per line	*/
 #define NFS_TIMEOUT 60
 
 static unsigned long rpc_id = 0;
@@ -540,10 +540,10 @@ static int nfs_read_reply(unsigned char *pkt, unsigned len)
 
 	data = (uint32_t *)(pkt + sizeof(struct rpc_reply));
 
-	if (nfs_offset && !((nfs_offset) % (NFS_READ_SIZE / 2 * 10 * HASHES_PER_LINE)))
-		puts ("\n\t ");
-	if (!(nfs_offset % ((NFS_READ_SIZE / 2) * 10)))
-		putchar ('#');
+	if (!nfs_offset) {
+		uint32_t filesize = ntohl(net_read_uint32(data + 6));
+		init_progression_bar(filesize);
+	}
 
 	rlen = ntohl(net_read_uint32(data + 18));
 
@@ -629,7 +629,7 @@ static void nfs_handler(char *packet, unsigned len)
 			nfs_state = STATE_READLINK_REQ;
 		else
 			goto err_umount;
-
+		show_progress(nfs_offset);
 		break;
 	}
 
@@ -659,7 +659,7 @@ static void nfs_start(char *p)
 	nfs_filename = basename (nfs_path);
 	nfs_path     = dirname (nfs_path);
 
-	printf("\nFilename '%s/%s'.\nLoading: ", nfs_path, nfs_filename);
+	printf("\nFilename '%s/%s'.\n", nfs_path, nfs_filename);
 
 	nfs_timer_start = get_time_ns();
 
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 7/8] nfs: resend requests after timeout
  2010-06-24  9:35 more network patches Sascha Hauer
                   ` (5 preceding siblings ...)
  2010-06-24  9:35 ` [PATCH 6/8] nfs: Use generic progression bar Sascha Hauer
@ 2010-06-24  9:35 ` Sascha Hauer
  2010-06-24  9:35 ` [PATCH 8/8] tftp: update doxygen information Sascha Hauer
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2010-06-24  9:35 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/nfs.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/net/nfs.c b/net/nfs.c
index bdf05bd..4ca1d6e 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -124,7 +124,7 @@ struct rpc_t {
 	} u;
 };
 
-#define NFS_TIMEOUT 60
+#define NFS_TIMEOUT 1
 
 static unsigned long rpc_id = 0;
 static int nfs_offset = -1;
@@ -399,6 +399,8 @@ static void nfs_send(void)
 		nfs_readlink_req();
 		break;
 	}
+
+	nfs_timer_start = get_time_ns();
 }
 
 static int rpc_check_reply(unsigned char *pkt, int isnfs)
@@ -661,8 +663,6 @@ static void nfs_start(char *p)
 
 	printf("\nFilename '%s/%s'.\n", nfs_path, nfs_filename);
 
-	nfs_timer_start = get_time_ns();
-
 	nfs_state = STATE_PRCLOOKUP_PROG_MOUNT_REQ;
 
 	nfs_send();
@@ -706,8 +706,10 @@ static int do_nfs(struct command *cmdtp, int argc, char *argv[])
 			break;
 		}
 		net_poll();
-		if (is_timeout(nfs_timer_start, NFS_TIMEOUT * SECOND))
-			break;
+		if (is_timeout(nfs_timer_start, NFS_TIMEOUT * SECOND)) {
+			show_progress(-1);
+			nfs_send();
+		}
 	}
 
 	net_unregister(nfs_con);
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 8/8] tftp: update doxygen information
  2010-06-24  9:35 more network patches Sascha Hauer
                   ` (6 preceding siblings ...)
  2010-06-24  9:35 ` [PATCH 7/8] nfs: resend requests after timeout Sascha Hauer
@ 2010-06-24  9:35 ` Sascha Hauer
  7 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2010-06-24  9:35 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/tftp.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/net/tftp.c b/net/tftp.c
index 000d0cf..c0d3278 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -376,16 +376,21 @@ BAREBOX_CMD_END
 /**
  * @page tftp_command tftp
  *
- * Usage is: tftp \<filename\> [\<localfilename\>]
+ * Usage:
+ *	tftp \<remotefilename\> [\<localfilename\>]
  *
- * Load a file via network using BootP/TFTP protocol. The loaded file you
- * can find after download in you current ramdisk. Refer \b ls command.
+ * or
  *
- * \<localfile> can be the local filename only, or also a device name. In the
- * case of a device name, the will gets stored there. This works also for
- * partitions of flash memory. Refer \b erase, \b unprotect for flash
- * preparation.
+ *	tftp -p \<localfilename\> [\<remotefilename\>]
  *
- * Note: This command is available only, if enabled in the menuconfig.
+ * Load a file from a tftp server or upload a file to a tftp server if
+ * the -p option is given. The second file argument can be skipped in
+ * which case the first filename is used (without the directory part).
+ *
+ * \<localfile> can be the local filename or a device file under /dev.
+ * This also works for flash memory. Refer to \b erase, \b unprotect for
+ * flash preparation.
+ *
+ * Note: This command is available only if enabled in menuconfig.
  */
 
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-06-24  9:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-24  9:35 more network patches Sascha Hauer
2010-06-24  9:35 ` [PATCH 1/8] tftp: remove unused variables Sascha Hauer
2010-06-24  9:35 ` [PATCH 2/8] add progression bar function Sascha Hauer
2010-06-24  9:35 ` [PATCH 3/8] cfi flash driver: Use generic " Sascha Hauer
2010-06-24  9:35 ` [PATCH 4/8] tftp: use generic progression bar Sascha Hauer
2010-06-24  9:35 ` [PATCH 5/8] tftp: Add push support Sascha Hauer
2010-06-24  9:35 ` [PATCH 6/8] nfs: Use generic progression bar Sascha Hauer
2010-06-24  9:35 ` [PATCH 7/8] nfs: resend requests after timeout Sascha Hauer
2010-06-24  9:35 ` [PATCH 8/8] tftp: update doxygen information Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox