mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Add functions for (de)activating consoles and for setting baudrate
@ 2015-06-09  6:21 Sascha Hauer
  2015-06-09  6:21 ` [PATCH 01/12] console: Add functions to get/set active state of console Sascha Hauer
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

We have some console users like load[bxy] which fiddle with device
parameters to control console activation and baudrate settings. This
series introduces functions for doing this and makes use of them where
possible. The serial download stuff is untested as I have been unable
to get that to work with any of the three protocols and kermit or minicom
as terminal programs. If anyone has a hint how this works I'd be grateful.

Sascha

----------------------------------------------------------------
Sascha Hauer (12):
      console: Add functions to get/set active state of console
      console: Add functions to get/set baudrate
      console: Add console_get_by_name
      console: When switching baudrate print console name
      usb: gadget: serial: Use console_set_active to activate console
      loadxy: Use console_get_by_name
      loadxy: use console_get_baudrate
      loadx: ignore -c option
      loadxy: use console_set_baudrate
      loadb: use console_get_baudrate
      loadb: Use console_set_baudrate
      loadb: ignore -c option

 commands/loadb.c              |  39 ++++----------
 commands/loadxy.c             |  81 ++++++++++------------------
 common/console.c              | 123 ++++++++++++++++++++++++++++--------------
 common/console_common.c       |  13 +++++
 drivers/usb/gadget/u_serial.c |   3 +-
 include/console.h             |   7 +++
 6 files changed, 144 insertions(+), 122 deletions(-)

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

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

* [PATCH 01/12] console: Add functions to get/set active state of console
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  6:21 ` [PATCH 02/12] console: Add functions to get/set baudrate Sascha Hauer
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

Currently code needs to fiddle with the active parameter of a console
device directly to enable/disable consoles. Add console_set_active()
to set the status and console_get_active() to get the current status.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/console.c  | 87 +++++++++++++++++++++++++++++++++----------------------
 include/console.h |  4 +++
 2 files changed, 57 insertions(+), 34 deletions(-)

diff --git a/common/console.c b/common/console.c
index 0c32f06..53030b5 100644
--- a/common/console.c
+++ b/common/console.c
@@ -58,32 +58,14 @@ static struct kfifo __console_output_fifo;
 static struct kfifo *console_input_fifo = &__console_input_fifo;
 static struct kfifo *console_output_fifo = &__console_output_fifo;
 
-static int console_std_set(struct device_d *dev, struct param_d *param,
-		const char *val)
+int console_set_active(struct console_device *cdev, unsigned flag)
 {
-	struct console_device *cdev = to_console_dev(dev);
-	char active[4];
-	unsigned int flag = 0, i = 0;
-	int ret;
-
-	if (val) {
-		if (strchr(val, 'i') && cdev->getc) {
-			active[i++] = 'i';
-			flag |= CONSOLE_STDIN;
-		}
-
-		if (cdev->putc) {
-			if (strchr(val, 'o')) {
-				active[i++] = 'o';
-				flag |= CONSOLE_STDOUT;
-			}
+	int ret, i;
 
-			if (strchr(val, 'e')) {
-				active[i++] = 'e';
-				flag |= CONSOLE_STDERR;
-			}
-		}
-	}
+	if (!cdev->getc)
+		flag &= ~CONSOLE_STDIN;
+	if (!cdev->putc)
+		flag &= ~(CONSOLE_STDOUT | CONSOLE_STDERR);
 
 	if (flag && !cdev->f_active) {
 		/* The device is being activated, set its baudrate */
@@ -97,16 +79,25 @@ static int console_std_set(struct device_d *dev, struct param_d *param,
 			return ret;
 	}
 
-	active[i] = 0;
 	cdev->f_active = flag;
 
-	dev_param_set_generic(dev, param, active);
+	if (IS_ENABLED(CONFIG_PARAMETER)) {
+		i = 0;
+
+		if (flag & CONSOLE_STDIN)
+			cdev->active[i++] = 'i';
+		if (flag & CONSOLE_STDOUT)
+			cdev->active[i++] = 'o';
+		if (flag & CONSOLE_STDERR)
+			cdev->active[i++] = 'e';
+		cdev->active[i] = 0;
+	}
 
 	if (initialized < CONSOLE_INIT_FULL) {
 		char ch;
 		initialized = CONSOLE_INIT_FULL;
 		puts_ll("Switch to console [");
-		puts_ll(dev_name(dev));
+		puts_ll(dev_name(&cdev->class_dev));
 		puts_ll("]\n");
 		barebox_banner();
 		while (kfifo_getc(console_output_fifo, &ch) == 0)
@@ -116,6 +107,37 @@ static int console_std_set(struct device_d *dev, struct param_d *param,
 	return 0;
 }
 
+unsigned console_get_active(struct console_device *cdev)
+{
+	return cdev->f_active;
+}
+
+static int console_active_set(struct device_d *dev, struct param_d *param,
+		const char *val)
+{
+	struct console_device *cdev = to_console_dev(dev);
+	unsigned int flag = 0;
+
+	if (val) {
+		if (strchr(val, 'i'))
+			flag |= CONSOLE_STDIN;
+		if (strchr(val, 'o'))
+			flag |= CONSOLE_STDOUT;
+		if (strchr(val, 'e'))
+			flag |= CONSOLE_STDERR;
+	}
+
+	return console_set_active(cdev, flag);
+}
+
+static const char *console_active_get(struct device_d *dev,
+		struct param_d *param)
+{
+	struct console_device *cdev = to_console_dev(dev);
+
+	return cdev->active;
+}
+
 static int console_baudrate_set(struct param_d *param, void *priv)
 {
 	struct console_device *cdev = priv;
@@ -214,7 +236,7 @@ int console_register(struct console_device *newcdev)
 	if (newcdev->putc && !newcdev->puts)
 		newcdev->puts = __console_puts;
 
-	dev_add_param(dev, "active", console_std_set, NULL, 0);
+	dev_add_param(dev, "active", console_active_set, console_active_get, 0);
 
 	if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) {
 		if (list_empty(&console_list))
@@ -230,12 +252,9 @@ int console_register(struct console_device *newcdev)
 
 	list_add_tail(&newcdev->list, &console_list);
 
-	if (activate) {
-		if (IS_ENABLED(CONFIG_PARAMETER))
-			dev_set_param(dev, "active", "ioe");
-		else
-			console_std_set(dev, NULL, "ioe");
-	}
+	if (activate)
+		console_set_active(newcdev, CONSOLE_STDIN |
+				CONSOLE_STDOUT | CONSOLE_STDERR);
 
 	return 0;
 }
diff --git a/include/console.h b/include/console.h
index 72b4a44..f7055e6 100644
--- a/include/console.h
+++ b/include/console.h
@@ -52,6 +52,7 @@ struct console_device {
 	struct list_head list;
 
 	unsigned char f_active;
+	char active[4];
 
 	unsigned int baudrate;
 
@@ -75,4 +76,7 @@ extern int barebox_loglevel;
 
 struct console_device *console_get_first_active(void);
 
+int console_set_active(struct console_device *cdev, unsigned active);
+unsigned console_get_active(struct console_device *cdev);
+
 #endif
-- 
2.1.4


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

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

* [PATCH 02/12] console: Add functions to get/set baudrate
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
  2015-06-09  6:21 ` [PATCH 01/12] console: Add functions to get/set active state of console Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  6:21 ` [PATCH 03/12] console: Add console_get_by_name Sascha Hauer
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

So C code can call a function rather than fiddling with device parameters.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/console.c  | 34 ++++++++++++++++++++++++++++++----
 include/console.h |  2 ++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/common/console.c b/common/console.c
index 53030b5..957f539 100644
--- a/common/console.c
+++ b/common/console.c
@@ -138,29 +138,55 @@ static const char *console_active_get(struct device_d *dev,
 	return cdev->active;
 }
 
-static int console_baudrate_set(struct param_d *param, void *priv)
+int console_set_baudrate(struct console_device *cdev, unsigned baudrate)
 {
-	struct console_device *cdev = priv;
+	int ret;
 	unsigned char c;
 
+	if (!cdev->setbrg)
+		return -ENOSYS;
+
+	if (cdev->baudrate == baudrate)
+		return 0;
+
 	/*
 	 * If the device is already active, change its baudrate.
 	 * The baudrate of an inactive device will be set at activation time.
 	 */
 	if (cdev->f_active) {
 		printf("## Switch baudrate to %d bps and press ENTER ...\n",
-			cdev->baudrate);
+			baudrate);
 		mdelay(50);
-		cdev->setbrg(cdev, cdev->baudrate);
+	}
+
+	ret = cdev->setbrg(cdev, baudrate);
+	if (ret)
+		return ret;
+
+	if (cdev->f_active) {
 		mdelay(50);
 		do {
 			c = getc();
 		} while (c != '\r' && c != '\n');
 	}
 
+	cdev->baudrate = baudrate;
+
 	return 0;
 }
 
+unsigned console_get_baudrate(struct console_device *cdev)
+{
+	return cdev->baudrate;
+}
+
+static int console_baudrate_set(struct param_d *param, void *priv)
+{
+	struct console_device *cdev = priv;
+
+	return console_set_baudrate(cdev, cdev->baudrate);
+}
+
 static void console_init_early(void)
 {
 	kfifo_init(console_input_fifo, console_input_buffer,
diff --git a/include/console.h b/include/console.h
index f7055e6..945bdcb 100644
--- a/include/console.h
+++ b/include/console.h
@@ -78,5 +78,7 @@ struct console_device *console_get_first_active(void);
 
 int console_set_active(struct console_device *cdev, unsigned active);
 unsigned console_get_active(struct console_device *cdev);
+int console_set_baudrate(struct console_device *cdev, unsigned baudrate);
+unsigned console_get_baudrate(struct console_device *cdev);
 
 #endif
-- 
2.1.4


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

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

* [PATCH 03/12] console: Add console_get_by_name
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
  2015-06-09  6:21 ` [PATCH 01/12] console: Add functions to get/set active state of console Sascha Hauer
  2015-06-09  6:21 ` [PATCH 02/12] console: Add functions to get/set baudrate Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  6:21 ` [PATCH 04/12] console: When switching baudrate print console name Sascha Hauer
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

Commands like loadx/loady wish to find a console device by its name. Add
a function for this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/console_common.c | 13 +++++++++++++
 include/console.h       |  1 +
 2 files changed, 14 insertions(+)

diff --git a/common/console_common.c b/common/console_common.c
index 41a6929..1e362ab 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -260,6 +260,19 @@ struct console_device *console_get_by_dev(struct device_d *dev)
 }
 EXPORT_SYMBOL(console_get_by_dev);
 
+struct console_device *console_get_by_name(const char *name)
+{
+	struct console_device *cdev;
+
+	for_each_console(cdev) {
+		if (!strcmp(cdev->devname, name))
+			return cdev;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL(console_get_by_name);
+
 /*
  * @brief returns current used console device
  *
diff --git a/include/console.h b/include/console.h
index 945bdcb..c2622c9 100644
--- a/include/console.h
+++ b/include/console.h
@@ -63,6 +63,7 @@ int console_register(struct console_device *cdev);
 int console_unregister(struct console_device *cdev);
 
 struct console_device *console_get_by_dev(struct device_d *dev);
+struct console_device *console_get_by_name(const char *name);
 
 extern struct list_head console_list;
 #define for_each_console(console) list_for_each_entry(console, &console_list, list)
-- 
2.1.4


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

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

* [PATCH 04/12] console: When switching baudrate print console name
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
                   ` (2 preceding siblings ...)
  2015-06-09  6:21 ` [PATCH 03/12] console: Add console_get_by_name Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  6:21 ` [PATCH 05/12] usb: gadget: serial: Use console_set_active to activate console Sascha Hauer
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

Since there may be multiple consoles print the name of the console
whose baudrate shall be switched.

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

diff --git a/common/console.c b/common/console.c
index 957f539..8585cd6 100644
--- a/common/console.c
+++ b/common/console.c
@@ -154,8 +154,8 @@ int console_set_baudrate(struct console_device *cdev, unsigned baudrate)
 	 * The baudrate of an inactive device will be set at activation time.
 	 */
 	if (cdev->f_active) {
-		printf("## Switch baudrate to %d bps and press ENTER ...\n",
-			baudrate);
+		printf("## Switch baudrate on console %s to %d bps and press ENTER ...\n",
+			dev_name(&cdev->class_dev), baudrate);
 		mdelay(50);
 	}
 
-- 
2.1.4


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

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

* [PATCH 05/12] usb: gadget: serial: Use console_set_active to activate console
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
                   ` (3 preceding siblings ...)
  2015-06-09  6:21 ` [PATCH 04/12] console: When switching baudrate print console name Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  6:21 ` [PATCH 06/12] loadxy: Use console_get_by_name Sascha Hauer
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/gadget/u_serial.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 1e5e809..2b0faf3 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -536,7 +536,8 @@ int gserial_connect(struct gserial *gser, u8 port_num)
 	if (status)
 		goto fail_out;
 
-	dev_set_param(&cdev->class_dev, "active", "ioe");
+	console_set_active(cdev, CONSOLE_STDIN | CONSOLE_STDOUT |
+		CONSOLE_STDERR);
 
 	/* REVISIT if waiting on "carrier detect", signal. */
 
-- 
2.1.4


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

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

* [PATCH 06/12] loadxy: Use console_get_by_name
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
                   ` (4 preceding siblings ...)
  2015-06-09  6:21 ` [PATCH 05/12] usb: gadget: serial: Use console_set_active to activate console Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  6:21 ` [PATCH 07/12] loadxy: use console_get_baudrate Sascha Hauer
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

Use console_get_by_name rather than iterating over the console list in the
loadxy code. The code in loadxy.c used to test whether a console is active
before using it. This check is dropped along the way since there's no reason
to not being able to use a disabled console for loadxy.

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

diff --git a/commands/loadxy.c b/commands/loadxy.c
index 1e65cb6..62b3956 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -57,28 +57,6 @@ static int console_change_speed(struct console_device *cdev, int baudrate)
 	return current_baudrate;
 }
 
-static struct console_device *get_named_console(const char *cname)
-{
-	struct console_device *cdev;
-	const char *target;
-
-	/*
-	 * Assumption to have BOTH CONSOLE_STDIN AND STDOUT in the
-	 * same output console
-	 */
-	for_each_console(cdev) {
-		target = dev_id(&cdev->class_dev);
-		if (strlen(target) != strlen(cname))
-			continue;
-		printf("RJK: looking for %s in console name %s\n",
-		       cname, target);
-		if ((cdev->f_active & (CONSOLE_STDIN | CONSOLE_STDOUT))
-		    && !strcmp(cname, target))
-			return cdev;
-	}
-	return NULL;
-}
-
 /**
  * @brief provide the loady(Y-Modem or Y-Modem/G) support
  *
@@ -112,7 +90,7 @@ static int do_loady(int argc, char *argv[])
 	}
 
 	if (cname)
-		cdev = get_named_console(cname);
+		cdev = console_get_by_name(cname);
 	else
 		cdev = console_get_first_active();
 	if (!cdev) {
@@ -196,7 +174,7 @@ static int do_loadx(int argc, char *argv[])
 	}
 
 	if (cname)
-		cdev = get_named_console(cname);
+		cdev = console_get_by_name(cname);
 	else
 		cdev = console_get_first_active();
 	if (!cdev) {
-- 
2.1.4


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

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

* [PATCH 07/12] loadxy: use console_get_baudrate
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
                   ` (5 preceding siblings ...)
  2015-06-09  6:21 ` [PATCH 06/12] loadxy: Use console_get_by_name Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  6:21 ` [PATCH 08/12] loadx: ignore -c option Sascha Hauer
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

No need to fiddle with device parameters anymore.

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

diff --git a/commands/loadxy.c b/commands/loadxy.c
index 62b3956..b475edf 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -43,10 +43,8 @@
 static int console_change_speed(struct console_device *cdev, int baudrate)
 {
 	int current_baudrate;
-	const char *bstr;
 
-	bstr = dev_get_param(&cdev->class_dev, "baudrate");
-	current_baudrate = bstr ? (int)simple_strtoul(bstr, NULL, 10) : 0;
+	current_baudrate = console_get_baudrate(cdev);
 	if (baudrate && baudrate != current_baudrate) {
 		printf("## Switch baudrate from %d to %d bps and press ENTER ...\n",
 		       current_baudrate, baudrate);
-- 
2.1.4


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

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

* [PATCH 08/12] loadx: ignore -c option
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
                   ` (6 preceding siblings ...)
  2015-06-09  6:21 ` [PATCH 07/12] loadxy: use console_get_baudrate Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  6:21 ` [PATCH 09/12] loadxy: use console_set_baudrate Sascha Hauer
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

And always create the file if necessary. No need to have an extra flag for
this.

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

diff --git a/commands/loadxy.c b/commands/loadxy.c
index b475edf..d5cc588 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -144,7 +144,6 @@ static int do_loadx(int argc, char *argv[])
 {
 	ulong offset = 0;
 	int load_baudrate = 0, current_baudrate, ofd, opt, rcode = 0;
-	int open_mode = O_WRONLY;
 	char *output_file = NULL, *cname = NULL;
 	struct console_device *cdev = NULL;
 
@@ -159,9 +158,6 @@ static int do_loadx(int argc, char *argv[])
 		case 'o':
 			offset = (int)simple_strtoul(optarg, NULL, 10);
 			break;
-		case 'c':
-			open_mode |= O_CREAT;
-			break;
 		case 't':
 			cname = optarg;
 			break;
@@ -186,7 +182,7 @@ static int do_loadx(int argc, char *argv[])
 		output_file = DEF_FILE;
 
 	/* File should exist */
-	ofd = open(output_file, open_mode);
+	ofd = open(output_file, O_WRONLY | O_CREAT);
 	if (ofd < 0) {
 		perror(argv[0]);
 		return 3;
@@ -222,7 +218,6 @@ 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("-t NAME", "console name to use (default: current)")
-BAREBOX_CMD_HELP_OPT("-c",      "create file if not present")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(loadx)
-- 
2.1.4


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

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

* [PATCH 09/12] loadxy: use console_set_baudrate
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
                   ` (7 preceding siblings ...)
  2015-06-09  6:21 ` [PATCH 08/12] loadx: ignore -c option Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  6:21 ` [PATCH 10/12] loadb: use console_get_baudrate Sascha Hauer
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

No need to do this manually

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/loadb.c  |  2 +-
 commands/loadxy.c | 46 ++++++++++++++++++++++++++--------------------
 2 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/commands/loadb.c b/commands/loadb.c
index 7424bcc..66934c4 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -604,7 +604,7 @@ static int do_load_serial_bin(int argc, char *argv[])
 	ulong offset = 0;
 	ulong addr;
 	int load_baudrate = 0, current_baudrate;
-	int rcode = 0;
+	int rcode = 0, ret;
 	int opt;
 	int open_mode = O_WRONLY;
 	char *output_file = NULL;
diff --git a/commands/loadxy.c b/commands/loadxy.c
index d5cc588..a4b1bec 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -40,21 +40,6 @@
 
 #define DEF_FILE	"image.bin"
 
-static int console_change_speed(struct console_device *cdev, int baudrate)
-{
-	int current_baudrate;
-
-	current_baudrate = console_get_baudrate(cdev);
-	if (baudrate && baudrate != current_baudrate) {
-		printf("## Switch baudrate from %d to %d bps and press ENTER ...\n",
-		       current_baudrate, baudrate);
-		mdelay(50);
-		cdev->setbrg(cdev, baudrate);
-		mdelay(50);
-	}
-	return current_baudrate;
-}
-
 /**
  * @brief provide the loady(Y-Modem or Y-Modem/G) support
  *
@@ -97,7 +82,15 @@ static int do_loady(int argc, char *argv[])
 		return -ENODEV;
 	}
 
-	current_baudrate = console_change_speed(cdev, load_baudrate);
+	current_baudrate = console_get_baudrate(cdev);
+
+	if (!load_baudrate)
+		load_baudrate = current_baudrate;
+
+	rc = console_set_baudrate(cdev, load_baudrate);
+	if (rc)
+		return rc;
+
 	printf("## Ready for binary (ymodem) download at %d bps...\n",
 	       load_baudrate ? load_baudrate : current_baudrate);
 
@@ -111,7 +104,9 @@ static int do_loady(int argc, char *argv[])
 		rcode = 1;
 	}
 
-	console_change_speed(cdev, current_baudrate);
+	rc = console_set_baudrate(cdev, current_baudrate);
+	if (rc)
+		return rc;
 
 	return rcode;
 }
@@ -143,7 +138,7 @@ BAREBOX_CMD_END
 static int do_loadx(int argc, char *argv[])
 {
 	ulong offset = 0;
-	int load_baudrate = 0, current_baudrate, ofd, opt, rcode = 0;
+	int load_baudrate = 0, current_baudrate, rc, ofd, opt, rcode = 0;
 	char *output_file = NULL, *cname = NULL;
 	struct console_device *cdev = NULL;
 
@@ -198,7 +193,15 @@ static int do_loadx(int argc, char *argv[])
 		}
 	}
 
-	current_baudrate = console_change_speed(cdev, load_baudrate);
+	current_baudrate = console_get_baudrate(cdev);
+
+	if (!load_baudrate)
+		load_baudrate = current_baudrate;
+
+	rc = console_set_baudrate(cdev, load_baudrate);
+	if (rc)
+		return rc;
+
 	printf("## Ready for binary (xmodem) download "
 	       "to 0x%08lX offset on %s device at %d bps...\n", offset,
 	       output_file, load_baudrate ? load_baudrate : current_baudrate);
@@ -207,7 +210,10 @@ static int do_loadx(int argc, char *argv[])
 		printf("## Binary (xmodem) download aborted (%d)\n", rcode);
 		rcode = 1;
 	}
-	console_change_speed(cdev, current_baudrate);
+
+	rc = console_set_baudrate(cdev, current_baudrate);
+	if (rc)
+		return rc;
 
 	return rcode;
 }
-- 
2.1.4


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

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

* [PATCH 10/12] loadb: use console_get_baudrate
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
                   ` (8 preceding siblings ...)
  2015-06-09  6:21 ` [PATCH 09/12] loadxy: use console_set_baudrate Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  6:21 ` [PATCH 11/12] loadb: Use console_set_baudrate Sascha Hauer
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

No need to fiddle with device parameters anymore.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/loadb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/loadb.c b/commands/loadb.c
index 66934c4..8294f39 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -635,7 +635,7 @@ static int do_load_serial_bin(int argc, char *argv[])
 		printf("%s:No console device with STDIN and STDOUT\n", argv[0]);
 		return -ENODEV;
 	}
-	current_baudrate = (int)simple_strtoul(dev_get_param(&cdev->class_dev, "baudrate"), NULL, 10);
+	current_baudrate = console_get_baudrate(cdev);
 
 	/* Load Defaults */
 	if (load_baudrate == 0)
-- 
2.1.4


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

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

* [PATCH 11/12] loadb: Use console_set_baudrate
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
                   ` (9 preceding siblings ...)
  2015-06-09  6:21 ` [PATCH 10/12] loadb: use console_get_baudrate Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  6:21 ` [PATCH 12/12] loadb: ignore -c option Sascha Hauer
  2015-06-09  7:26 ` Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

No Need to do this manually

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

diff --git a/commands/loadb.c b/commands/loadb.c
index 8294f39..acc3cd4 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -660,17 +660,9 @@ static int do_load_serial_bin(int argc, char *argv[])
 		}
 	}
 
-	if (load_baudrate != current_baudrate) {
-		printf("## Switch baudrate to %d bps and press ENTER ...\n",
-		       load_baudrate);
-		udelay(50000);
-		cdev->setbrg(cdev, load_baudrate);
-		udelay(50000);
-		for (;;) {
-			if (getc() == '\r')
-				break;
-		}
-	}
+	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,
@@ -681,17 +673,9 @@ static int do_load_serial_bin(int argc, char *argv[])
 		rcode = 1;
 	}
 
-	if (load_baudrate != current_baudrate) {
-		printf("## Switch baudrate to %d bps and press ESC ...\n",
-		       current_baudrate);
-		udelay(50000);
-		cdev->setbrg(cdev, current_baudrate);
-		udelay(50000);
-		for (;;) {
-			if (getc() == 0x1B)	/* ESC */
-				break;
-		}
-	}
+	ret = console_set_baudrate(cdev, current_baudrate);
+	if (ret)
+		return ret;
 
 	close(ofd);
 	ofd = 0;
-- 
2.1.4


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

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

* [PATCH 12/12] loadb: ignore -c option
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
                   ` (10 preceding siblings ...)
  2015-06-09  6:21 ` [PATCH 11/12] loadb: Use console_set_baudrate Sascha Hauer
@ 2015-06-09  6:21 ` Sascha Hauer
  2015-06-09  7:26 ` Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  6:21 UTC (permalink / raw)
  To: Barebox List

And always create the file if necessary. No need to have an extra flag for
this.

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

diff --git a/commands/loadb.c b/commands/loadb.c
index acc3cd4..be5830d 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -606,7 +606,6 @@ static int do_load_serial_bin(int argc, char *argv[])
 	int load_baudrate = 0, current_baudrate;
 	int rcode = 0, ret;
 	int opt;
-	int open_mode = O_WRONLY;
 	char *output_file = NULL;
 	struct console_device *cdev = NULL;
 
@@ -621,9 +620,6 @@ static int do_load_serial_bin(int argc, char *argv[])
 		case 'o':
 			offset = (int)simple_strtoul(optarg, NULL, 10);
 			break;
-		case 'c':
-			open_mode |= O_CREAT;
-			break;
 		default:
 			perror(argv[0]);
 			return 1;
@@ -644,7 +640,7 @@ static int do_load_serial_bin(int argc, char *argv[])
 		output_file = DEF_FILE;
 
 	/* File should exist */
-	ofd = open(output_file, open_mode);
+	ofd = open(output_file, O_WRONLY | O_CREAT);
 	if (ofd < 0) {
 		perror(argv[0]);
 		return 3;
@@ -688,7 +684,6 @@ 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",      "create file if not present")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(loadb)
-- 
2.1.4


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

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

* Re: Add functions for (de)activating consoles and for setting baudrate
  2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
                   ` (11 preceding siblings ...)
  2015-06-09  6:21 ` [PATCH 12/12] loadb: ignore -c option Sascha Hauer
@ 2015-06-09  7:26 ` Sascha Hauer
  12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2015-06-09  7:26 UTC (permalink / raw)
  To: Barebox List

On Tue, Jun 09, 2015 at 08:21:03AM +0200, Sascha Hauer wrote:
> We have some console users like load[bxy] which fiddle with device
> parameters to control console activation and baudrate settings. This
> series introduces functions for doing this and makes use of them where
> possible. The serial download stuff is untested as I have been unable
> to get that to work with any of the three protocols and kermit or minicom
> as terminal programs. If anyone has a hint how this works I'd be grateful.

The hint came from Uwe. He uses sx/sz directly and with this it works
together with the barebox commands like this:

barebox> loadx
host> sx -kb -vvvv FILE < /dev/ttyUSB2 > /dev/ttyUSB2

barebox> loady
host> sz -kb -vvvv FILE < /dev/ttyUSB2 > /dev/ttyUSB2

Sascha

-- 
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] 14+ messages in thread

end of thread, other threads:[~2015-06-09  7:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
2015-06-09  6:21 ` [PATCH 01/12] console: Add functions to get/set active state of console Sascha Hauer
2015-06-09  6:21 ` [PATCH 02/12] console: Add functions to get/set baudrate Sascha Hauer
2015-06-09  6:21 ` [PATCH 03/12] console: Add console_get_by_name Sascha Hauer
2015-06-09  6:21 ` [PATCH 04/12] console: When switching baudrate print console name Sascha Hauer
2015-06-09  6:21 ` [PATCH 05/12] usb: gadget: serial: Use console_set_active to activate console Sascha Hauer
2015-06-09  6:21 ` [PATCH 06/12] loadxy: Use console_get_by_name Sascha Hauer
2015-06-09  6:21 ` [PATCH 07/12] loadxy: use console_get_baudrate Sascha Hauer
2015-06-09  6:21 ` [PATCH 08/12] loadx: ignore -c option Sascha Hauer
2015-06-09  6:21 ` [PATCH 09/12] loadxy: use console_set_baudrate Sascha Hauer
2015-06-09  6:21 ` [PATCH 10/12] loadb: use console_get_baudrate Sascha Hauer
2015-06-09  6:21 ` [PATCH 11/12] loadb: Use console_set_baudrate Sascha Hauer
2015-06-09  6:21 ` [PATCH 12/12] loadb: ignore -c option Sascha Hauer
2015-06-09  7:26 ` Add functions for (de)activating consoles and for setting baudrate Sascha Hauer

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