mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* loadb console cleanups
@ 2015-11-17 11:10 Sascha Hauer
  2015-11-17 11:10 ` [PATCH 1/5] loadb: Use local cdev Sascha Hauer
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-11-17 11:10 UTC (permalink / raw)
  To: Barebox List

This series has some cleanups for the loadb support. With this loadb
uses a single console device directly to transfer files. This console
device is configurable on the command line is no longer necessarily the
console which outputs messages.

----------------------------------------------------------------
Sascha Hauer (5):
      loadb: Use local cdev
      loadb: deactivate console before using it for loadb
      console: Set baudrate during registration
      loadb: Allow to specify device to use
      loads: Use putchar rather than console_putc

 commands/loadb.c | 78 ++++++++++++++++++++++++++++++++++++++------------------
 commands/loads.c |  6 ++---
 common/console.c | 11 +++-----
 3 files changed, 60 insertions(+), 35 deletions(-)

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

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

* [PATCH 1/5] loadb: Use local cdev
  2015-11-17 11:10 loadb console cleanups Sascha Hauer
@ 2015-11-17 11:10 ` Sascha Hauer
  2015-11-17 11:10 ` [PATCH 2/5] loadb: deactivate console before using it for loadb Sascha Hauer
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-11-17 11:10 UTC (permalink / raw)
  To: Barebox List

We already retrieve a console_device using console_get_first_active().
Use this one also to send/receive characters instead of the combined
input/output of all console devices with putc/getc.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/loadb.c | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/commands/loadb.c b/commands/loadb.c
index aabb00a..bdf1710 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -67,13 +67,24 @@ static char his_eol;		/* character he needs at end of packet */
 static int his_pad_count;	/* number of pad chars he needs */
 static char his_pad_char;	/* pad chars he needs */
 static char his_quote;		/* quote chars he'll use */
+static struct console_device *cdev; /* The console device we are using */
+
+static void sendchar(char c)
+{
+	cdev->putc(cdev, c);
+}
+
+static int receivechar(void)
+{
+	return cdev->getc(cdev);
+}
 
 static void send_pad(void)
 {
 	int count = his_pad_count;
 
 	while (count-- > 0)
-		console_putc(CONSOLE_STDOUT, his_pad_char);
+		sendchar(his_pad_char);
 }
 
 /* converts escaped kermit char to binary char */
@@ -100,9 +111,8 @@ static int chk1(char *buffer)
 static void s1_sendpacket(char *packet)
 {
 	send_pad();
-	while (*packet) {
-		console_putc(CONSOLE_STDOUT, *packet++);
-	}
+	while (*packet)
+		sendchar(*packet++);
 }
 
 static char a_b[24];
@@ -397,7 +407,7 @@ static int k_recv(void)
 		/* get a packet */
 		/* wait for the starting character or ^C */
 		for (;;) {
-			switch (getc()) {
+			switch (receivechar()) {
 			case START_CHAR:	/* start packet */
 				goto START;
 			case ETX_CHAR:	/* ^C waiting for packet */
@@ -411,13 +421,13 @@ static int k_recv(void)
 START:
 		/* get length of packet */
 		sum = 0;
-		new_char = getc();
+		new_char = receivechar();
 		if ((new_char & 0xE0) == 0)
 			goto packet_error;
 		sum += new_char & 0xff;
 		length = untochar(new_char);
 		/* get sequence number */
-		new_char = getc();
+		new_char = receivechar();
 		if ((new_char & 0xE0) == 0)
 			goto packet_error;
 		sum += new_char & 0xff;
@@ -447,7 +457,7 @@ START:
 		/* END NEW CODE */
 
 		/* get packet type */
-		new_char = getc();
+		new_char = receivechar();
 		if ((new_char & 0xE0) == 0)
 			goto packet_error;
 		sum += new_char & 0xff;
@@ -457,19 +467,19 @@ START:
 		if (length == -2) {
 			/* (length byte was 0, decremented twice) */
 			/* get the two length bytes */
-			new_char = getc();
+			new_char = receivechar();
 			if ((new_char & 0xE0) == 0)
 				goto packet_error;
 			sum += new_char & 0xff;
 			len_hi = untochar(new_char);
-			new_char = getc();
+			new_char = receivechar();
 			if ((new_char & 0xE0) == 0)
 				goto packet_error;
 			sum += new_char & 0xff;
 			len_lo = untochar(new_char);
 			length = len_hi * 95 + len_lo;
 			/* check header checksum */
-			new_char = getc();
+			new_char = receivechar();
 			if ((new_char & 0xE0) == 0)
 				goto packet_error;
 			if (new_char !=
@@ -488,7 +498,7 @@ START:
 			}
 		}
 		while (length > 1) {
-			new_char = getc();
+			new_char = receivechar();
 			if ((new_char & 0xE0) == 0)
 				goto packet_error;
 			sum += new_char & 0xff;
@@ -505,13 +515,13 @@ START:
 			}
 		}
 		/* get and validate checksum character */
-		new_char = getc();
+		new_char = receivechar();
 		if ((new_char & 0xE0) == 0)
 			goto packet_error;
 		if (new_char != tochar((sum + ((sum >> 6) & 0x03)) & 0x3f))
 			goto packet_error;
 		/* get END_CHAR */
-		new_char = getc();
+		new_char = receivechar();
 		if (new_char != END_CHAR) {
 packet_error:
 			/* restore state machines */
@@ -566,8 +576,8 @@ static ulong load_serial_bin(void)
 	 * box some time (100 * 1 ms)
 	 */
 	for (i = 0; i < 100; ++i) {
-		if (tstc())
-			(void)getc();
+		if (cdev->tstc(cdev))
+			(void)receivechar();;
 		udelay(1000);
 	}
 
@@ -607,7 +617,6 @@ static int do_load_serial_bin(int argc, char *argv[])
 	int rcode = 0, ret;
 	int opt;
 	char *output_file = NULL;
-	struct console_device *cdev = NULL;
 
 	while ((opt = getopt(argc, argv, "f:b:o:c")) > 0) {
 		switch (opt) {
-- 
2.6.2


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

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

* [PATCH 2/5] loadb: deactivate console before using it for loadb
  2015-11-17 11:10 loadb console cleanups Sascha Hauer
  2015-11-17 11:10 ` [PATCH 1/5] loadb: Use local cdev Sascha Hauer
@ 2015-11-17 11:10 ` Sascha Hauer
  2015-11-17 11:10 ` [PATCH 3/5] console: Set baudrate during registration Sascha Hauer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-11-17 11:10 UTC (permalink / raw)
  To: Barebox List

Remove the console device we are about using for loadb from the
console layer by deactivating it. This makes sure that no printf output
disturbs the current file transfer.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/loadb.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/commands/loadb.c b/commands/loadb.c
index bdf1710..6710665 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -617,6 +617,7 @@ static int do_load_serial_bin(int argc, char *argv[])
 	int rcode = 0, ret;
 	int opt;
 	char *output_file = NULL;
+	int current_active;
 
 	while ((opt = getopt(argc, argv, "f:b:o:c")) > 0) {
 		switch (opt) {
@@ -641,6 +642,7 @@ static int do_load_serial_bin(int argc, char *argv[])
 		return -ENODEV;
 	}
 	current_baudrate = console_get_baudrate(cdev);
+	current_active = console_get_active(cdev);
 
 	/* Load Defaults */
 	if (load_baudrate == 0)
@@ -665,13 +667,15 @@ static int do_load_serial_bin(int argc, char *argv[])
 		}
 	}
 
+	printf("## Ready for binary (kermit) download "
+	       "to 0x%08lX offset on %s device at %d bps...\n", offset,
+	       output_file, load_baudrate);
+
+	console_set_active(cdev, 0);
 	ret = console_set_baudrate(cdev, load_baudrate);
 	if (ret)
 		return ret;
 
-	printf("## Ready for binary (kermit) download "
-	       "to 0x%08lX offset on %s device at %d bps...\n", offset,
-	       output_file, load_baudrate);
 	addr = load_serial_bin();
 	if (addr == 0) {
 		printf("## Binary (kermit) download aborted\n");
@@ -682,6 +686,8 @@ static int do_load_serial_bin(int argc, char *argv[])
 	if (ret)
 		return ret;
 
+	console_set_active(cdev, current_active);
+
 	close(ofd);
 	ofd = 0;
 	return rcode;
-- 
2.6.2


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

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

* [PATCH 3/5] console: Set baudrate during registration
  2015-11-17 11:10 loadb console cleanups Sascha Hauer
  2015-11-17 11:10 ` [PATCH 1/5] loadb: Use local cdev Sascha Hauer
  2015-11-17 11:10 ` [PATCH 2/5] loadb: deactivate console before using it for loadb Sascha Hauer
@ 2015-11-17 11:10 ` Sascha Hauer
  2015-11-17 11:10 ` [PATCH 4/5] loadb: Allow to specify device to use Sascha Hauer
  2015-11-17 11:10 ` [PATCH 5/5] loads: Use putchar rather than console_putc Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-11-17 11:10 UTC (permalink / raw)
  To: Barebox List

This makes sure that the cdev->baudrate field is always consistent with
the hardware state.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/console.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/common/console.c b/common/console.c
index 84d4ea7..4a1d257 100644
--- a/common/console.c
+++ b/common/console.c
@@ -67,12 +67,6 @@ int console_set_active(struct console_device *cdev, unsigned flag)
 	if (!cdev->putc)
 		flag &= ~(CONSOLE_STDOUT | CONSOLE_STDERR);
 
-	if (flag && !cdev->f_active) {
-		/* The device is being activated, set its baudrate */
-		if (cdev->setbrg)
-			cdev->setbrg(cdev, cdev->baudrate);
-	}
-
 	if (!flag && cdev->f_active && cdev->flush)
 		cdev->flush(cdev);
 
@@ -240,7 +234,7 @@ static int __console_puts(struct console_device *cdev, const char *s)
 int console_register(struct console_device *newcdev)
 {
 	struct device_d *dev = &newcdev->class_dev;
-	int activate = 0;
+	int activate = 0, ret;
 
 	if (initialized == CONSOLE_UNINITIALIZED)
 		console_init_early();
@@ -258,6 +252,9 @@ int console_register(struct console_device *newcdev)
 	platform_device_register(dev);
 
 	if (newcdev->setbrg) {
+		ret = newcdev->setbrg(newcdev, CONFIG_BAUDRATE);
+		if (ret)
+			return ret;
 		newcdev->baudrate = CONFIG_BAUDRATE;
 		dev_add_param_int(dev, "baudrate", console_baudrate_set,
 			NULL, &newcdev->baudrate_param, "%u", newcdev);
-- 
2.6.2


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

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

* [PATCH 4/5] loadb: Allow to specify device to use
  2015-11-17 11:10 loadb console cleanups Sascha Hauer
                   ` (2 preceding siblings ...)
  2015-11-17 11:10 ` [PATCH 3/5] console: Set baudrate during registration Sascha Hauer
@ 2015-11-17 11:10 ` Sascha Hauer
  2015-11-17 11:10 ` [PATCH 5/5] loads: Use putchar rather than console_putc Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-11-17 11:10 UTC (permalink / raw)
  To: Barebox List

The port we want to have the console on may not necessarily be the port
we want to transfer files on. Make the port configurable with a
commandline option.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/loadb.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/commands/loadb.c b/commands/loadb.c
index 6710665..6223512 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -618,8 +618,9 @@ static int do_load_serial_bin(int argc, char *argv[])
 	int opt;
 	char *output_file = NULL;
 	int current_active;
+	char *console_dev_name = NULL;
 
-	while ((opt = getopt(argc, argv, "f:b:o:c")) > 0) {
+	while ((opt = getopt(argc, argv, "f:b:o:c:")) > 0) {
 		switch (opt) {
 		case 'f':
 			output_file = optarg;
@@ -630,16 +631,27 @@ static int do_load_serial_bin(int argc, char *argv[])
 		case 'o':
 			offset = (int)simple_strtoul(optarg, NULL, 10);
 			break;
+		case 'c':
+			console_dev_name = optarg;
+			break;
 		default:
 			perror(argv[0]);
 			return 1;
 		}
 	}
 
-	cdev = console_get_first_active();
-	if (NULL == cdev) {
-		printf("%s:No console device with STDIN and STDOUT\n", argv[0]);
-		return -ENODEV;
+	if (console_dev_name) {
+		cdev = console_get_by_name(console_dev_name);
+		if (!cdev) {
+			printf("Console %s not found\n", console_dev_name);
+			return -ENODEV;
+		}
+	} else {
+		cdev = console_get_first_active();
+		if (!cdev) {
+			printf("No console device with STDIN and STDOUT\n");
+			return -ENODEV;
+		}
 	}
 	current_baudrate = console_get_baudrate(cdev);
 	current_active = console_get_active(cdev);
@@ -699,6 +711,7 @@ BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT("-f FILE", "download to FILE (default image.bin)")
 BAREBOX_CMD_HELP_OPT("-o OFFS", "destination file OFFSet (default 0)")
 BAREBOX_CMD_HELP_OPT("-b BAUD", "baudrate for download (default: console baudrate)")
+BAREBOX_CMD_HELP_OPT("-c CONSOLE", "Specify console (default: first active console")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(loadb)
-- 
2.6.2


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

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

* [PATCH 5/5] loads: Use putchar rather than console_putc
  2015-11-17 11:10 loadb console cleanups Sascha Hauer
                   ` (3 preceding siblings ...)
  2015-11-17 11:10 ` [PATCH 4/5] loadb: Allow to specify device to use Sascha Hauer
@ 2015-11-17 11:10 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-11-17 11:10 UTC (permalink / raw)
  To: Barebox List

'putchar' is a standard function to output a character. Use this one
instead of the lower level console_putc.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/loads.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/commands/loads.c b/commands/loads.c
index 24093e1..aa3095e 100644
--- a/commands/loads.c
+++ b/commands/loads.c
@@ -127,7 +127,7 @@ static ulong load_serial(ulong offset)
 		}
 		if (!do_echo) {	/* print a '.' every 100 lines */
 			if ((++line_count % 100) == 0)
-				console_putc(CONSOLE_STDOUT, '.');
+				putchar('.');
 		}
 	}
 
@@ -144,7 +144,7 @@ static int read_record(char *buf, ulong len)
 	for (p=buf; p < buf+len; ++p) {
 		c = getc();		/* read character		*/
 		if (do_echo)
-			console_putc(CONSOLE_STDOUT, c);
+			putchar(c);
 
 		switch (c) {
 		case '\r':
@@ -259,7 +259,7 @@ static int write_record(char *buf)
 	char c;
 
 	while ((c = *buf++))
-		console_putc(CONSOLE_STDOUT, c);
+		putchar(c);
 
 	/* Check for the console hangup (if any different from serial) */
 
-- 
2.6.2


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

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

end of thread, other threads:[~2015-11-17 11:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17 11:10 loadb console cleanups Sascha Hauer
2015-11-17 11:10 ` [PATCH 1/5] loadb: Use local cdev Sascha Hauer
2015-11-17 11:10 ` [PATCH 2/5] loadb: deactivate console before using it for loadb Sascha Hauer
2015-11-17 11:10 ` [PATCH 3/5] console: Set baudrate during registration Sascha Hauer
2015-11-17 11:10 ` [PATCH 4/5] loadb: Allow to specify device to use Sascha Hauer
2015-11-17 11:10 ` [PATCH 5/5] loads: Use putchar rather than console_putc Sascha Hauer

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