mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* (no subject)
@ 2011-08-22 18:45 Antony Pavlov
  2011-08-22 18:45 ` [PATCH 1/5] remove LOADS_BAUD_CHANGE from broken commands/loads.c Antony Pavlov
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Antony Pavlov @ 2011-08-22 18:45 UTC (permalink / raw)
  To: barebox

The following patch series make the 'loads' and 'saves' commands work again.


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

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

* [PATCH 1/5] remove LOADS_BAUD_CHANGE from broken commands/loads.c
  2011-08-22 18:45 Antony Pavlov
@ 2011-08-22 18:45 ` Antony Pavlov
  2011-08-23  6:34   ` Sascha Hauer
  2011-08-22 18:45 ` [PATCH 2/5] commands/loads.c: make it compile again Antony Pavlov
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Antony Pavlov @ 2011-08-22 18:45 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 commands/loads.c |  109 +-----------------------------------------------------
 1 files changed, 1 insertions(+), 108 deletions(-)

diff --git a/commands/loads.c b/commands/loads.c
index c6617a4..2672c39 100644
--- a/commands/loads.c
+++ b/commands/loads.c
@@ -47,11 +47,6 @@ int do_load_serial(struct command *cmdtp, int argc, char *argv[])
 	int i;
 	char *env_echo;
 	int rcode = 0;
-#ifdef	CFG_LOADS_BAUD_CHANGE
-	int load_baudrate, current_baudrate;
-
-	load_baudrate = current_baudrate = gd->baudrate;
-#endif
 
 	if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) {
 		do_echo = 1;
@@ -59,34 +54,9 @@ int do_load_serial(struct command *cmdtp, int argc, char *argv[])
 		do_echo = 0;
 	}
 
-#ifdef	CFG_LOADS_BAUD_CHANGE
-	if (argc >= 2) {
-		offset = simple_strtoul(argv[1], NULL, 16);
-	}
-	if (argc == 3) {
-		load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
-
-		/* default to current baudrate */
-		if (load_baudrate == 0)
-			load_baudrate = current_baudrate;
-	}
-	if (load_baudrate != current_baudrate) {
-		printf ("## Switch baudrate to %d bps and press ENTER ...\n",
-			load_baudrate);
-		udelay(50000);
-		gd->baudrate = load_baudrate;
-		serial_setbrg ();
-		udelay(50000);
-		for (;;) {
-			if (getc() == '\r')
-				break;
-		}
-	}
-#else	/* ! CFG_LOADS_BAUD_CHANGE */
 	if (argc == 2) {
 		offset = simple_strtoul(argv[1], NULL, 16);
 	}
-#endif	/* CFG_LOADS_BAUD_CHANGE */
 
 	printf ("## Ready for S-Record download ...\n");
 
@@ -112,20 +82,6 @@ int do_load_serial(struct command *cmdtp, int argc, char *argv[])
 		load_addr = addr;
 	}
 
-#ifdef	CFG_LOADS_BAUD_CHANGE
-	if (load_baudrate != current_baudrate) {
-		printf ("## Switch baudrate to %d bps and press ESC ...\n",
-			current_baudrate);
-		udelay (50000);
-		gd->baudrate = current_baudrate;
-		serial_setbrg ();
-		udelay (50000);
-		for (;;) {
-			if (getc() == 0x1B) /* ESC */
-				break;
-		}
-	}
-#endif
 	return rcode;
 }
 
@@ -234,43 +190,14 @@ int do_save_serial(struct command *cmdtp, int flag, int argc, char *argv[])
 {
 	ulong offset = 0;
 	ulong size   = 0;
-#ifdef	CFG_LOADS_BAUD_CHANGE
-	int save_baudrate, current_baudrate;
-
-	save_baudrate = current_baudrate = gd->baudrate;
-#endif
 
 	if (argc >= 2) {
 		offset = simple_strtoul(argv[1], NULL, 16);
 	}
-#ifdef	CFG_LOADS_BAUD_CHANGE
-	if (argc >= 3) {
-		size = simple_strtoul(argv[2], NULL, 16);
-	}
-	if (argc == 4) {
-		save_baudrate = (int)simple_strtoul(argv[3], NULL, 10);
 
-		/* default to current baudrate */
-		if (save_baudrate == 0)
-			save_baudrate = current_baudrate;
-	}
-	if (save_baudrate != current_baudrate) {
-		printf ("## Switch baudrate to %d bps and press ENTER ...\n",
-			save_baudrate);
-		udelay(50000);
-		gd->baudrate = save_baudrate;
-		serial_setbrg ();
-		udelay(50000);
-		for (;;) {
-			if (getc() == '\r')
-				break;
-		}
-	}
-#else	/* ! CFG_LOADS_BAUD_CHANGE */
 	if (argc == 3) {
 		size = simple_strtoul(argv[2], NULL, 16);
 	}
-#endif	/* CFG_LOADS_BAUD_CHANGE */
 
 	printf ("## Ready for S-Record upload, press ENTER to proceed ...\n");
 	for (;;) {
@@ -282,20 +209,7 @@ int do_save_serial(struct command *cmdtp, int flag, int argc, char *argv[])
 	} else {
 		printf ("## S-Record upload complete\n");
 	}
-#ifdef	CFG_LOADS_BAUD_CHANGE
-	if (save_baudrate != current_baudrate) {
-		printf ("## Switch baudrate to %d bps and press ESC ...\n",
-			(int)current_baudrate);
-		udelay (50000);
-		gd->baudrate = current_baudrate;
-		serial_setbrg ();
-		udelay (50000);
-		for (;;) {
-			if (getc() == 0x1B) /* ESC */
-				break;
-		}
-	}
-#endif
+
 	return 0;
 }
 
@@ -376,23 +290,12 @@ write_record (char *buf)
 }
 # endif /* CFG_CMD_SAVES */
 
-#ifdef	CFG_LOADS_BAUD_CHANGE
-BAREBOX_CMD(
-	loads, 3, 0,	do_load_serial,
-	"loads   - load S-Record file over serial line\n",
-	"[ off ] [ baud ]\n"
-	"    - load S-Record file over serial line"
-	" with offset 'off' and baudrate 'baud'\n"
-);
-
-#else	/* ! CFG_LOADS_BAUD_CHANGE */
 BAREBOX_CMD(
 	loads, 2, 0,	do_load_serial,
 	"loads   - load S-Record file over serial line\n",
 	"[ off ]\n"
 	"    - load S-Record file over serial line with offset 'off'\n"
 );
-#endif	/* CFG_LOADS_BAUD_CHANGE */
 
 /*
  * SAVES always requires LOADS support, but not vice versa
@@ -400,21 +303,11 @@ BAREBOX_CMD(
 
 
 #if (CONFIG_COMMANDS & CFG_CMD_SAVES)
-#ifdef	CFG_LOADS_BAUD_CHANGE
-BAREBOX_CMD(
-	saves, 4, 0,	do_save_serial,
-	"saves   - save S-Record file over serial line\n",
-	"[ off ] [size] [ baud ]\n"
-	"    - save S-Record file over serial line"
-	" with offset 'off', size 'size' and baudrate 'baud'\n"
-);
-#else	/* ! CFG_LOADS_BAUD_CHANGE */
 BAREBOX_CMD(
 	saves, 3, 0,	do_save_serial,
 	"saves   - save S-Record file over serial line\n",
 	"[ off ] [size]\n"
 	"    - save S-Record file over serial line with offset 'off' and size 'size'\n"
 );
-#endif	/* CFG_LOADS_BAUD_CHANGE */
 #endif	/* CFG_CMD_SAVES */
 
-- 
1.7.5.4


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

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

* [PATCH 2/5] commands/loads.c: make it compile again
  2011-08-22 18:45 Antony Pavlov
  2011-08-22 18:45 ` [PATCH 1/5] remove LOADS_BAUD_CHANGE from broken commands/loads.c Antony Pavlov
@ 2011-08-22 18:45 ` Antony Pavlov
  2011-08-22 18:45 ` [PATCH 3/5] commands/loads.c: fix compiler's warning Antony Pavlov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2011-08-22 18:45 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 commands/Kconfig  |    2 -
 commands/Makefile |    1 -
 commands/loads.c  |   60 ++++++++++++++++++++++++----------------------------
 common/Makefile   |    1 +
 4 files changed, 29 insertions(+), 35 deletions(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index e922260..39bdb0f 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -203,12 +203,10 @@ config CMD_LOADY
 	prompt "loady"
 
 config CMD_LOADS
-	depends on BROKEN
 	tristate
 	prompt "loads"
 
 config CMD_SAVES
-	depends on BROKEN
 	tristate
 	depends on CMD_LOADS
 	prompt "saves"
diff --git a/commands/Makefile b/commands/Makefile
index 7c88b48..40fb26c 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -5,7 +5,6 @@ obj-$(CONFIG_CMD_LOADY)		+= loadb.o xyzModem.o
 obj-$(CONFIG_CMD_LOADS)		+= loads.o
 obj-$(CONFIG_CMD_ECHO)		+= echo.o
 obj-$(CONFIG_CMD_MEMORY)	+= mem.o
-obj-$(CONFIG_CMD_LOADS)		+= s_record.o
 obj-$(CONFIG_CMD_MTEST)		+= memtest.o
 obj-$(CONFIG_CMD_EDIT)		+= edit.o
 obj-$(CONFIG_CMD_EXEC)		+= exec.o
diff --git a/commands/loads.c b/commands/loads.c
index 2672c39..71fdeba 100644
--- a/commands/loads.c
+++ b/commands/loads.c
@@ -26,19 +26,19 @@
  */
 #include <common.h>
 #include <command.h>
+#include <environment.h>
 #include <s_record.h>
 #include <net.h>
-#include <exports.h>
 #include <xyzModem.h>
 
 static ulong load_serial (ulong offset);
 static int read_record (char *buf, ulong len);
 static int do_echo = 1;
 
-# if (CONFIG_COMMANDS & CFG_CMD_SAVES)
+#ifdef CONFIG_CMD_SAVES
 static int save_serial (ulong offset, ulong size);
 static int write_record (char *buf);
-# endif /* CFG_CMD_SAVES */
+#endif /* CONFIG_CMD_SAVES */
 
 int do_load_serial(struct command *cmdtp, int argc, char *argv[])
 {
@@ -79,7 +79,6 @@ int do_load_serial(struct command *cmdtp, int argc, char *argv[])
 		rcode = 1;
 	} else {
 		printf ("## Start Addr      = 0x%08lX\n", addr);
-		load_addr = addr;
 	}
 
 	return rcode;
@@ -139,7 +138,7 @@ load_serial (ulong offset)
 		}
 		if (!do_echo) {	/* print a '.' every 100 lines */
 			if ((++line_count % 100) == 0)
-				putc ('.');
+				console_putc(CONSOLE_STDOUT, '.');
 		}
 	}
 
@@ -157,7 +156,7 @@ read_record (char *buf, ulong len)
 	for (p=buf; p < buf+len; ++p) {
 		c = getc();		/* read character		*/
 		if (do_echo)
-			putc (c);	/* ... and echo it		*/
+			console_putc(CONSOLE_STDOUT, c);
 
 		switch (c) {
 		case '\r':
@@ -170,13 +169,6 @@ read_record (char *buf, ulong len)
 		default:
 			*p = c;
 		}
-
-	    /* Check for the console hangup (if any different from serial) */
-	    if (gd->jt[XF_getc] != getc) {
-		if (ctrlc()) {
-		    return (-1);
-		}
-	    }
 	}
 
 	/* line too long - truncate */
@@ -184,9 +176,8 @@ read_record (char *buf, ulong len)
 	return (p - buf);
 }
 
-#if (CONFIG_COMMANDS & CFG_CMD_SAVES)
-
-int do_save_serial(struct command *cmdtp, int flag, int argc, char *argv[])
+#ifdef CONFIG_CMD_SAVES
+int do_save_serial(struct command *cmdtp, int argc, char *argv[])
 {
 	ulong offset = 0;
 	ulong size   = 0;
@@ -279,7 +270,7 @@ write_record (char *buf)
 	char c;
 
 	while((c = *buf++))
-		putc(c);
+		console_putc(CONSOLE_STDOUT, c);
 
 	/* Check for the console hangup (if any different from serial) */
 
@@ -288,26 +279,31 @@ write_record (char *buf)
 	}
 	return (0);
 }
-# endif /* CFG_CMD_SAVES */
+#endif /* CONFIG_CMD_SAVES */
 
-BAREBOX_CMD(
-	loads, 2, 0,	do_load_serial,
-	"loads   - load S-Record file over serial line\n",
+static const __maybe_unused char cmd_loads_help[] =
 	"[ off ]\n"
-	"    - load S-Record file over serial line with offset 'off'\n"
-);
+	"    - load S-Record file over serial line with offset 'off'\n";
+
+BAREBOX_CMD_START(loads)
+	.cmd		= do_load_serial,
+	.usage		= "load S-Record file over serial line",
+	BAREBOX_CMD_HELP(cmd_loads_help)
+BAREBOX_CMD_END
 
 /*
  * SAVES always requires LOADS support, but not vice versa
  */
 
-
-#if (CONFIG_COMMANDS & CFG_CMD_SAVES)
-BAREBOX_CMD(
-	saves, 3, 0,	do_save_serial,
-	"saves   - save S-Record file over serial line\n",
+#ifdef CONFIG_CMD_SAVES
+static const __maybe_unused char cmd_saves_help[] =
 	"[ off ] [size]\n"
-	"    - save S-Record file over serial line with offset 'off' and size 'size'\n"
-);
-#endif	/* CFG_CMD_SAVES */
-
+	"    - save S-Record file over serial line with offset 'off' "
+	"and size 'size'\n";
+
+BAREBOX_CMD_START(saves)
+	.cmd		= do_save_serial,
+	.usage		= "save S-Record file over serial line",
+	BAREBOX_CMD_HELP(cmd_saves_help)
+BAREBOX_CMD_END
+#endif	/* CONFIG_CMD_SAVES */
diff --git a/common/Makefile b/common/Makefile
index 9fed2ae..74946e9 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_ENV_HANDLING)	+= environment.o
 obj-$(CONFIG_AUTO_COMPLETE)	+= complete.o
 obj-$(CONFIG_POLLER)		+= poller.o
 obj-$(CONFIG_BLOCK)		+= block.o
+obj-$(CONFIG_CMD_LOADS)		+= s_record.o
 
 obj-y += memory.o
 obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
-- 
1.7.5.4


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

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

* [PATCH 3/5] commands/loads.c: fix compiler's warning
  2011-08-22 18:45 Antony Pavlov
  2011-08-22 18:45 ` [PATCH 1/5] remove LOADS_BAUD_CHANGE from broken commands/loads.c Antony Pavlov
  2011-08-22 18:45 ` [PATCH 2/5] commands/loads.c: make it compile again Antony Pavlov
@ 2011-08-22 18:45 ` Antony Pavlov
  2011-08-22 18:45 ` [PATCH 4/5] commands/loads.c: make do_* functions static Antony Pavlov
  2011-08-22 18:45 ` [PATCH 5/5] commands/loads.c: fix whitespace errors & formatting Antony Pavlov
  4 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2011-08-22 18:45 UTC (permalink / raw)
  To: barebox

Fix 'assignment discards qualifiers from pointer target type' warning.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 commands/loads.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/commands/loads.c b/commands/loads.c
index 71fdeba..6aef557 100644
--- a/commands/loads.c
+++ b/commands/loads.c
@@ -45,7 +45,7 @@ int do_load_serial(struct command *cmdtp, int argc, char *argv[])
 	ulong offset = 0;
 	ulong addr;
 	int i;
-	char *env_echo;
+	const char *env_echo;
 	int rcode = 0;
 
 	if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) {
-- 
1.7.5.4


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

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

* [PATCH 4/5] commands/loads.c: make do_* functions static
  2011-08-22 18:45 Antony Pavlov
                   ` (2 preceding siblings ...)
  2011-08-22 18:45 ` [PATCH 3/5] commands/loads.c: fix compiler's warning Antony Pavlov
@ 2011-08-22 18:45 ` Antony Pavlov
  2011-08-22 18:45 ` [PATCH 5/5] commands/loads.c: fix whitespace errors & formatting Antony Pavlov
  4 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2011-08-22 18:45 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 commands/loads.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/commands/loads.c b/commands/loads.c
index 6aef557..396406c 100644
--- a/commands/loads.c
+++ b/commands/loads.c
@@ -40,7 +40,7 @@ static int save_serial (ulong offset, ulong size);
 static int write_record (char *buf);
 #endif /* CONFIG_CMD_SAVES */
 
-int do_load_serial(struct command *cmdtp, int argc, char *argv[])
+static int do_load_serial(struct command *cmdtp, int argc, char *argv[])
 {
 	ulong offset = 0;
 	ulong addr;
@@ -177,7 +177,7 @@ read_record (char *buf, ulong len)
 }
 
 #ifdef CONFIG_CMD_SAVES
-int do_save_serial(struct command *cmdtp, int argc, char *argv[])
+static int do_save_serial(struct command *cmdtp, int argc, char *argv[])
 {
 	ulong offset = 0;
 	ulong size   = 0;
-- 
1.7.5.4


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

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

* [PATCH 5/5] commands/loads.c: fix whitespace errors & formatting
  2011-08-22 18:45 Antony Pavlov
                   ` (3 preceding siblings ...)
  2011-08-22 18:45 ` [PATCH 4/5] commands/loads.c: make do_* functions static Antony Pavlov
@ 2011-08-22 18:45 ` Antony Pavlov
  4 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2011-08-22 18:45 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 commands/loads.c |  119 +++++++++++++++++++++++++++---------------------------
 1 files changed, 59 insertions(+), 60 deletions(-)

diff --git a/commands/loads.c b/commands/loads.c
index 396406c..68a44d4 100644
--- a/commands/loads.c
+++ b/commands/loads.c
@@ -31,13 +31,13 @@
 #include <net.h>
 #include <xyzModem.h>
 
-static ulong load_serial (ulong offset);
-static int read_record (char *buf, ulong len);
+static ulong load_serial(ulong offset);
+static int read_record(char *buf, ulong len);
 static int do_echo = 1;
 
 #ifdef CONFIG_CMD_SAVES
-static int save_serial (ulong offset, ulong size);
-static int write_record (char *buf);
+static int save_serial(ulong offset, ulong size);
+static int write_record(char *buf);
 #endif /* CONFIG_CMD_SAVES */
 
 static int do_load_serial(struct command *cmdtp, int argc, char *argv[])
@@ -60,7 +60,7 @@ static int do_load_serial(struct command *cmdtp, int argc, char *argv[])
 
 	printf ("## Ready for S-Record download ...\n");
 
-	addr = load_serial (offset);
+	addr = load_serial(offset);
 
 	/*
 	 * Gather any trailing characters (for instance, the ^D which
@@ -75,17 +75,16 @@ static int do_load_serial(struct command *cmdtp, int argc, char *argv[])
 	}
 
 	if (addr == ~0) {
-		printf ("## S-Record download aborted\n");
+		printf("## S-Record download aborted\n");
 		rcode = 1;
 	} else {
-		printf ("## Start Addr      = 0x%08lX\n", addr);
+		printf("## Start Addr      = 0x%08lX\n", addr);
 	}
 
 	return rcode;
 }
 
-static ulong
-load_serial (ulong offset)
+static ulong load_serial(ulong offset)
 {
 	char	record[SREC_MAXRECLEN + 1];	/* buffer for one S-Record	*/
 	char	binbuf[SREC_MAXBINLEN];		/* buffer for binary data	*/
@@ -100,41 +99,41 @@ load_serial (ulong offset)
 	int	line_count =  0;
 
 	while (read_record(record, SREC_MAXRECLEN + 1) >= 0) {
-		type = srec_decode (record, &binlen, &addr, binbuf);
+		type = srec_decode(record, &binlen, &addr, binbuf);
 
 		if (type < 0) {
-			return (~0);		/* Invalid S-Record		*/
+			return ~0;	/* Invalid S-Record		*/
 		}
 
 		switch (type) {
 		case SREC_DATA2:
 		case SREC_DATA3:
 		case SREC_DATA4:
-		    store_addr = addr + offset;
-		    memcpy ((char *)(store_addr), binbuf, binlen);
-		    if ((store_addr) < start_addr)
-			start_addr = store_addr;
-		    if ((store_addr + binlen - 1) > end_addr)
-			end_addr = store_addr + binlen - 1;
-		    break;
+			store_addr = addr + offset;
+			memcpy((char *)(store_addr), binbuf, binlen);
+			if ((store_addr) < start_addr)
+				start_addr = store_addr;
+			if ((store_addr + binlen - 1) > end_addr)
+				end_addr = store_addr + binlen - 1;
+		break;
 		case SREC_END2:
 		case SREC_END3:
 		case SREC_END4:
-		    udelay (10000);
-		    size = end_addr - start_addr + 1;
-		    printf ("\n"
+			udelay(10000);
+			size = end_addr - start_addr + 1;
+			printf("\n"
 			    "## First Load Addr = 0x%08lX\n"
 			    "## Last  Load Addr = 0x%08lX\n"
 			    "## Total Size      = 0x%08lX = %ld Bytes\n",
 			    start_addr, end_addr, size, size
-		    );
-		    sprintf(buf, "%lX", size);
-		    setenv("filesize", buf);
-		    return (addr);
+			    );
+			sprintf(buf, "%lX", size);
+			setenv("filesize", buf);
+			return addr;
 		case SREC_START:
-		    break;
+			break;
 		default:
-		    break;
+			break;
 		}
 		if (!do_echo) {	/* print a '.' every 100 lines */
 			if ((++line_count % 100) == 0)
@@ -142,11 +141,10 @@ load_serial (ulong offset)
 		}
 	}
 
-	return (~0);			/* Download aborted		*/
+	return ~0;			/* Download aborted		*/
 }
 
-static int
-read_record (char *buf, ulong len)
+static int read_record(char *buf, ulong len)
 {
 	char *p;
 	char c;
@@ -162,10 +160,10 @@ read_record (char *buf, ulong len)
 		case '\r':
 		case '\n':
 			*p = '\0';
-			return (p - buf);
+			return p - buf;
 		case '\0':
 		case 0x03:			/* ^C - Control C		*/
-			return (-1);
+			return -1;
 		default:
 			*p = c;
 		}
@@ -173,7 +171,7 @@ read_record (char *buf, ulong len)
 
 	/* line too long - truncate */
 	*p = '\0';
-	return (p - buf);
+	return p - buf;
 }
 
 #ifdef CONFIG_CMD_SAVES
@@ -195,10 +193,10 @@ static int do_save_serial(struct command *cmdtp, int argc, char *argv[])
 		if (getc() == '\r')
 			break;
 	}
-	if(save_serial (offset, size)) {
-		printf ("## S-Record upload aborted\n");
+	if (save_serial(offset, size)) {
+		printf("## S-Record upload aborted\n");
 	} else {
-		printf ("## S-Record upload complete\n");
+		printf("## S-Record upload complete\n");
 	}
 
 	return 0;
@@ -209,40 +207,42 @@ static int do_save_serial(struct command *cmdtp, int argc, char *argv[])
 #define SREC3_END				"S70500000000FA\n"
 #define SREC_BYTES_PER_RECORD	16
 
-static int save_serial (ulong address, ulong count)
+static int save_serial(ulong address, ulong count)
 {
 	int i, c, reclen, checksum, length;
 	char *hex = "0123456789ABCDEF";
-	char	record[2*SREC_BYTES_PER_RECORD+16];	/* buffer for one S-Record	*/
-	char	data[2*SREC_BYTES_PER_RECORD+1];	/* buffer for hex data	*/
+	char record[2*SREC_BYTES_PER_RECORD+16]; /* buffer for one S-Record */
+	char data[2*SREC_BYTES_PER_RECORD+1];	/* buffer for hex data	*/
 
 	reclen = 0;
-	checksum  = 0;
+	checksum = 0;
+
+	if (write_record(SREC3_START))	/* write the header */
+		return -1;
 
-	if(write_record(SREC3_START))			/* write the header */
-		return (-1);
 	do {
-		if(count) {						/* collect hex data in the buffer  */
+		if (count) {		/* collect hex data in the buffer  */
 			c = *(volatile uchar*)(address + reclen);	/* get one byte    */
-			checksum += c;							/* accumulate checksum */
+			checksum += c;	/* accumulate checksum */
 			data[2*reclen]   = hex[(c>>4)&0x0f];
 			data[2*reclen+1] = hex[c & 0x0f];
 			data[2*reclen+2] = '\0';
 			++reclen;
 			--count;
 		}
-		if(reclen == SREC_BYTES_PER_RECORD || count == 0) {
+
+		if (reclen == SREC_BYTES_PER_RECORD || count == 0) {
 			/* enough data collected for one record: dump it */
-			if(reclen) {	/* build & write a data record: */
+			if (reclen) {	/* build & write a data record: */
 				/* address + data + checksum */
 				length = 4 + reclen + 1;
 
 				/* accumulate length bytes into checksum */
-				for(i = 0; i < 2; i++)
+				for (i = 0; i < 2; i++)
 					checksum += (length >> (8*i)) & 0xff;
 
 				/* accumulate address bytes into checksum: */
-				for(i = 0; i < 4; i++)
+				for (i = 0; i < 4; i++)
 					checksum += (address >> (8*i)) & 0xff;
 
 				/* make proper checksum byte: */
@@ -250,34 +250,33 @@ static int save_serial (ulong address, ulong count)
 
 				/* output one record: */
 				sprintf(record, SREC3_FORMAT, length, address, data, checksum);
-				if(write_record(record))
-					return (-1);
+				if (write_record(record))
+					return -1;
 			}
 			address  += reclen;  /* increment address */
 			checksum  = 0;
 			reclen    = 0;
 		}
-	}
-	while(count);
-	if(write_record(SREC3_END))	/* write the final record */
-		return (-1);
-	return(0);
+	} while (count);
+
+	if (write_record(SREC3_END))	/* write the final record */
+		return -1;
+	return 0;
 }
 
-static int
-write_record (char *buf)
+static int write_record(char *buf)
 {
 	char c;
 
-	while((c = *buf++))
+	while ((c = *buf++))
 		console_putc(CONSOLE_STDOUT, c);
 
 	/* Check for the console hangup (if any different from serial) */
 
 	if (ctrlc()) {
-	    return (-1);
+		return -1;
 	}
-	return (0);
+	return 0;
 }
 #endif /* CONFIG_CMD_SAVES */
 
-- 
1.7.5.4


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

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

* Re: [PATCH 1/5] remove LOADS_BAUD_CHANGE from broken commands/loads.c
  2011-08-22 18:45 ` [PATCH 1/5] remove LOADS_BAUD_CHANGE from broken commands/loads.c Antony Pavlov
@ 2011-08-23  6:34   ` Sascha Hauer
  0 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2011-08-23  6:34 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

Hi Antony,

I applied this series to next. Definately a step in the right direction.

Sascha

On Mon, Aug 22, 2011 at 10:45:34PM +0400, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---
>  commands/loads.c |  109 +-----------------------------------------------------
>  1 files changed, 1 insertions(+), 108 deletions(-)
> 
> diff --git a/commands/loads.c b/commands/loads.c
> index c6617a4..2672c39 100644
> --- a/commands/loads.c
> +++ b/commands/loads.c
> @@ -47,11 +47,6 @@ int do_load_serial(struct command *cmdtp, int argc, char *argv[])
>  	int i;
>  	char *env_echo;
>  	int rcode = 0;
> -#ifdef	CFG_LOADS_BAUD_CHANGE
> -	int load_baudrate, current_baudrate;
> -
> -	load_baudrate = current_baudrate = gd->baudrate;
> -#endif
>  
>  	if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) {
>  		do_echo = 1;
> @@ -59,34 +54,9 @@ int do_load_serial(struct command *cmdtp, int argc, char *argv[])
>  		do_echo = 0;
>  	}
>  
> -#ifdef	CFG_LOADS_BAUD_CHANGE
> -	if (argc >= 2) {
> -		offset = simple_strtoul(argv[1], NULL, 16);
> -	}
> -	if (argc == 3) {
> -		load_baudrate = (int)simple_strtoul(argv[2], NULL, 10);
> -
> -		/* default to current baudrate */
> -		if (load_baudrate == 0)
> -			load_baudrate = current_baudrate;
> -	}
> -	if (load_baudrate != current_baudrate) {
> -		printf ("## Switch baudrate to %d bps and press ENTER ...\n",
> -			load_baudrate);
> -		udelay(50000);
> -		gd->baudrate = load_baudrate;
> -		serial_setbrg ();
> -		udelay(50000);
> -		for (;;) {
> -			if (getc() == '\r')
> -				break;
> -		}
> -	}
> -#else	/* ! CFG_LOADS_BAUD_CHANGE */
>  	if (argc == 2) {
>  		offset = simple_strtoul(argv[1], NULL, 16);
>  	}
> -#endif	/* CFG_LOADS_BAUD_CHANGE */
>  
>  	printf ("## Ready for S-Record download ...\n");
>  
> @@ -112,20 +82,6 @@ int do_load_serial(struct command *cmdtp, int argc, char *argv[])
>  		load_addr = addr;
>  	}
>  
> -#ifdef	CFG_LOADS_BAUD_CHANGE
> -	if (load_baudrate != current_baudrate) {
> -		printf ("## Switch baudrate to %d bps and press ESC ...\n",
> -			current_baudrate);
> -		udelay (50000);
> -		gd->baudrate = current_baudrate;
> -		serial_setbrg ();
> -		udelay (50000);
> -		for (;;) {
> -			if (getc() == 0x1B) /* ESC */
> -				break;
> -		}
> -	}
> -#endif
>  	return rcode;
>  }
>  
> @@ -234,43 +190,14 @@ int do_save_serial(struct command *cmdtp, int flag, int argc, char *argv[])
>  {
>  	ulong offset = 0;
>  	ulong size   = 0;
> -#ifdef	CFG_LOADS_BAUD_CHANGE
> -	int save_baudrate, current_baudrate;
> -
> -	save_baudrate = current_baudrate = gd->baudrate;
> -#endif
>  
>  	if (argc >= 2) {
>  		offset = simple_strtoul(argv[1], NULL, 16);
>  	}
> -#ifdef	CFG_LOADS_BAUD_CHANGE
> -	if (argc >= 3) {
> -		size = simple_strtoul(argv[2], NULL, 16);
> -	}
> -	if (argc == 4) {
> -		save_baudrate = (int)simple_strtoul(argv[3], NULL, 10);
>  
> -		/* default to current baudrate */
> -		if (save_baudrate == 0)
> -			save_baudrate = current_baudrate;
> -	}
> -	if (save_baudrate != current_baudrate) {
> -		printf ("## Switch baudrate to %d bps and press ENTER ...\n",
> -			save_baudrate);
> -		udelay(50000);
> -		gd->baudrate = save_baudrate;
> -		serial_setbrg ();
> -		udelay(50000);
> -		for (;;) {
> -			if (getc() == '\r')
> -				break;
> -		}
> -	}
> -#else	/* ! CFG_LOADS_BAUD_CHANGE */
>  	if (argc == 3) {
>  		size = simple_strtoul(argv[2], NULL, 16);
>  	}
> -#endif	/* CFG_LOADS_BAUD_CHANGE */
>  
>  	printf ("## Ready for S-Record upload, press ENTER to proceed ...\n");
>  	for (;;) {
> @@ -282,20 +209,7 @@ int do_save_serial(struct command *cmdtp, int flag, int argc, char *argv[])
>  	} else {
>  		printf ("## S-Record upload complete\n");
>  	}
> -#ifdef	CFG_LOADS_BAUD_CHANGE
> -	if (save_baudrate != current_baudrate) {
> -		printf ("## Switch baudrate to %d bps and press ESC ...\n",
> -			(int)current_baudrate);
> -		udelay (50000);
> -		gd->baudrate = current_baudrate;
> -		serial_setbrg ();
> -		udelay (50000);
> -		for (;;) {
> -			if (getc() == 0x1B) /* ESC */
> -				break;
> -		}
> -	}
> -#endif
> +
>  	return 0;
>  }
>  
> @@ -376,23 +290,12 @@ write_record (char *buf)
>  }
>  # endif /* CFG_CMD_SAVES */
>  
> -#ifdef	CFG_LOADS_BAUD_CHANGE
> -BAREBOX_CMD(
> -	loads, 3, 0,	do_load_serial,
> -	"loads   - load S-Record file over serial line\n",
> -	"[ off ] [ baud ]\n"
> -	"    - load S-Record file over serial line"
> -	" with offset 'off' and baudrate 'baud'\n"
> -);
> -
> -#else	/* ! CFG_LOADS_BAUD_CHANGE */
>  BAREBOX_CMD(
>  	loads, 2, 0,	do_load_serial,
>  	"loads   - load S-Record file over serial line\n",
>  	"[ off ]\n"
>  	"    - load S-Record file over serial line with offset 'off'\n"
>  );
> -#endif	/* CFG_LOADS_BAUD_CHANGE */
>  
>  /*
>   * SAVES always requires LOADS support, but not vice versa
> @@ -400,21 +303,11 @@ BAREBOX_CMD(
>  
>  
>  #if (CONFIG_COMMANDS & CFG_CMD_SAVES)
> -#ifdef	CFG_LOADS_BAUD_CHANGE
> -BAREBOX_CMD(
> -	saves, 4, 0,	do_save_serial,
> -	"saves   - save S-Record file over serial line\n",
> -	"[ off ] [size] [ baud ]\n"
> -	"    - save S-Record file over serial line"
> -	" with offset 'off', size 'size' and baudrate 'baud'\n"
> -);
> -#else	/* ! CFG_LOADS_BAUD_CHANGE */
>  BAREBOX_CMD(
>  	saves, 3, 0,	do_save_serial,
>  	"saves   - save S-Record file over serial line\n",
>  	"[ off ] [size]\n"
>  	"    - save S-Record file over serial line with offset 'off' and size 'size'\n"
>  );
> -#endif	/* CFG_LOADS_BAUD_CHANGE */
>  #endif	/* CFG_CMD_SAVES */
>  
> -- 
> 1.7.5.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

end of thread, other threads:[~2011-08-23  6:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-22 18:45 Antony Pavlov
2011-08-22 18:45 ` [PATCH 1/5] remove LOADS_BAUD_CHANGE from broken commands/loads.c Antony Pavlov
2011-08-23  6:34   ` Sascha Hauer
2011-08-22 18:45 ` [PATCH 2/5] commands/loads.c: make it compile again Antony Pavlov
2011-08-22 18:45 ` [PATCH 3/5] commands/loads.c: fix compiler's warning Antony Pavlov
2011-08-22 18:45 ` [PATCH 4/5] commands/loads.c: make do_* functions static Antony Pavlov
2011-08-22 18:45 ` [PATCH 5/5] commands/loads.c: fix whitespace errors & formatting Antony Pavlov

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