mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] misc improvements
@ 2012-10-07 11:39 Sascha Hauer
  2012-10-07 11:39 ` [PATCH 1/5] driver: print error message when probe fails Sascha Hauer
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-10-07 11:39 UTC (permalink / raw)
  To: barebox

Some things that should have been changed earlier: Print error messages
when a driver probe or a initcall fails. Also some cleanups in the console
activation area.

Sascha

----------------------------------------------------------------
Sascha Hauer (5):
      driver: print error message when probe fails
      resource: statically initialize iomem resource
      console: Cleanup console activation
      console: cleanup Kconfig
      startup: Print error message when initcall fails

 common/Kconfig        |   35 ++++++++++++++++++++++++---------
 common/console.c      |   51 +++++++++++++++++++++++++------------------------
 common/resource.c     |   10 ++--------
 common/startup.c      |    4 +++-
 drivers/base/driver.c |    7 ++++++-
 5 files changed, 63 insertions(+), 44 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] driver: print error message when probe fails
  2012-10-07 11:39 [PATCH] misc improvements Sascha Hauer
@ 2012-10-07 11:39 ` Sascha Hauer
  2012-10-07 11:39 ` [PATCH 2/5] resource: statically initialize iomem resource Sascha Hauer
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-10-07 11:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/base/driver.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 6c8fd05..7bb3ab4 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -77,6 +77,8 @@ int get_free_deviceid(const char *name_template)
 
 static int match(struct driver_d *drv, struct device_d *dev)
 {
+	int ret;
+
 	if (dev->driver)
 		return -1;
 
@@ -84,8 +86,11 @@ static int match(struct driver_d *drv, struct device_d *dev)
 
 	if (dev->bus->match(dev, drv))
 		goto err_out;
-	if (dev->bus->probe(dev))
+	ret = dev->bus->probe(dev);
+	if (ret) {
+		dev_err(dev, "probe failed: %s\n", strerror(-ret));
 		goto err_out;
+	}
 
 	list_add(&dev->active, &active);
 
-- 
1.7.10.4


_______________________________________________
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] resource: statically initialize iomem resource
  2012-10-07 11:39 [PATCH] misc improvements Sascha Hauer
  2012-10-07 11:39 ` [PATCH 1/5] driver: print error message when probe fails Sascha Hauer
@ 2012-10-07 11:39 ` Sascha Hauer
  2012-10-07 11:39 ` [PATCH 3/5] console: Cleanup console activation Sascha Hauer
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-10-07 11:39 UTC (permalink / raw)
  To: barebox

This gets us rid of an initcall and also has the advantage that
request_iomem_region can be called at any time now.

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

diff --git a/common/resource.c b/common/resource.c
index da631d3..ea6abe8 100644
--- a/common/resource.c
+++ b/common/resource.c
@@ -101,6 +101,8 @@ int release_region(struct resource *res)
 struct resource iomem_resource = {
 	.start = 0,
 	.end = 0xffffffff,
+	.name = "iomem",
+	.children = LIST_HEAD_INIT(iomem_resource.children),
 };
 
 /*
@@ -111,11 +113,3 @@ struct resource *request_iomem_region(const char *name,
 {
 	return request_region(&iomem_resource, name, start, end);
 }
-
-static int iomem_init(void)
-{
-	init_resource(&iomem_resource, "iomem");
-
-	return 0;
-}
-postcore_initcall(iomem_init);
-- 
1.7.10.4


_______________________________________________
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: Cleanup console activation
  2012-10-07 11:39 [PATCH] misc improvements Sascha Hauer
  2012-10-07 11:39 ` [PATCH 1/5] driver: print error message when probe fails Sascha Hauer
  2012-10-07 11:39 ` [PATCH 2/5] resource: statically initialize iomem resource Sascha Hauer
@ 2012-10-07 11:39 ` Sascha Hauer
  2012-10-07 11:39 ` [PATCH 4/5] console: cleanup Kconfig Sascha Hauer
  2012-10-07 11:39 ` [PATCH 5/5] startup: Print error message when initcall fails Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-10-07 11:39 UTC (permalink / raw)
  To: barebox

When CONFIG_CONSOLE_ACTIVATE_ALL is set, the banner will never be printed.
Also, the console buffer is emptied when the first console is registered,
even when it's not enabled.

This patch cleans it up in a way that:

- the console buffer is emptied once the first console is activated, not
  when it's registered.
- Make sure that the banner is printed first, so that we can output things
  to the buffer before the banner is printed without ending up in having
  the banner in the middle of the other boot messages.
- Use IS_ENABLED rather than ifdefs

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

diff --git a/common/console.c b/common/console.c
index 3dd964c..069e66e 100644
--- a/common/console.c
+++ b/common/console.c
@@ -44,6 +44,16 @@ EXPORT_SYMBOL(console_list);
 
 static int initialized = 0;
 
+#define CONSOLE_BUFFER_SIZE	1024
+
+static char console_input_buffer[CONSOLE_BUFFER_SIZE];
+static char console_output_buffer[CONSOLE_BUFFER_SIZE];
+
+static struct kfifo __console_input_fifo;
+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)
 {
@@ -74,6 +84,14 @@ static int console_std_set(struct device_d *dev, struct param_d *param,
 
 	dev_param_set_generic(dev, param, active);
 
+	if (initialized < CONSOLE_INIT_FULL) {
+		char ch;
+		initialized = CONSOLE_INIT_FULL;
+		barebox_banner();
+		while (kfifo_getc(console_output_fifo, &ch) == 0)
+			console_putc(CONSOLE_STDOUT, ch);
+	}
+
 	return 0;
 }
 
@@ -108,16 +126,6 @@ static int console_baudrate_set(struct device_d *dev, struct param_d *param,
 	return 0;
 }
 
-#define CONSOLE_BUFFER_SIZE	1024
-
-static char console_input_buffer[CONSOLE_BUFFER_SIZE];
-static char console_output_buffer[CONSOLE_BUFFER_SIZE];
-
-static struct kfifo __console_input_fifo;
-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 void console_init_early(void)
 {
 	kfifo_init(console_input_fifo, console_input_buffer,
@@ -131,8 +139,7 @@ static void console_init_early(void)
 int console_register(struct console_device *newcdev)
 {
 	struct device_d *dev = &newcdev->class_dev;
-	int first = 0;
-	char ch;
+	int activate = 0;
 
 	if (initialized == CONSOLE_UNINITIALIZED)
 		console_init_early();
@@ -150,23 +157,17 @@ int console_register(struct console_device *newcdev)
 
 	dev_add_param(dev, "active", console_std_set, NULL, 0);
 
-	initialized = CONSOLE_INIT_FULL;
-#ifdef CONFIG_CONSOLE_ACTIVATE_ALL
-	dev_set_param(dev, "active", "ioe");
-#endif
-#ifdef CONFIG_CONSOLE_ACTIVATE_FIRST
-	if (list_empty(&console_list)) {
-		first = 1;
-		dev_set_param(dev, "active", "ioe");
+	if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) {
+		if (list_empty(&console_list))
+			activate = 1;
+	} else if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_ALL)) {
+		activate = 1;
 	}
-#endif
 
 	list_add_tail(&newcdev->list, &console_list);
 
-	while (kfifo_getc(console_output_fifo, &ch) == 0)
-		console_putc(CONSOLE_STDOUT, ch);
-	if (first)
-		barebox_banner();
+	if (activate)
+		dev_set_param(dev, "active", "ioe");
 
 	return 0;
 }
-- 
1.7.10.4


_______________________________________________
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] console: cleanup Kconfig
  2012-10-07 11:39 [PATCH] misc improvements Sascha Hauer
                   ` (2 preceding siblings ...)
  2012-10-07 11:39 ` [PATCH 3/5] console: Cleanup console activation Sascha Hauer
@ 2012-10-07 11:39 ` Sascha Hauer
  2012-10-07 11:39 ` [PATCH 5/5] startup: Print error message when initcall fails Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-10-07 11:39 UTC (permalink / raw)
  To: barebox

Use a choice for the CONSOLE_ACTIVATE_* variables, which is the natural
way of specifying mutually exclusive variabled in Kconfig. Also update
the help texts a bit.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/Kconfig |   35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 9210739..107774c 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -468,17 +468,19 @@ config CONSOLE_FULL
 	prompt "Enable full console support"
 	help
 	  This option enables full console support capable of
-	  handling multiple consoles.
+	  handling multiple consoles. Also the full console support
+	  is able to store the output which comes before a console
+	  is registered in a circular buffer which will be printed
+	  once the first console is registered. Recommended for most
+	  usecases.
 
-config CONSOLE_SIMPLE
-	bool
-	default y
-	depends on !CONSOLE_FULL
+choice
+	prompt "Console activation strategy"
+	depends on CONSOLE_FULL
+	default CONSOLE_ACTIVATE_FIRST
 
 config CONSOLE_ACTIVATE_FIRST
-	depends on CONSOLE_FULL
 	bool
-	default y
 	prompt "activate first console on startup"
 	help
 	  Normally on startup all consoles are disabled, so you won't
@@ -486,13 +488,28 @@ config CONSOLE_ACTIVATE_FIRST
 	  enables the first console.
 
 config CONSOLE_ACTIVATE_ALL
-	depends on CONSOLE_FULL
-	depends on !CONSOLE_ACTIVATE_FIRST
 	bool
 	prompt "activate all consoles on startup"
 	help
 	  Enabling this options activates all consoles on startup, so
 	  you will get output and a prompt on all consoles simultaneously.
+	  Only the first registered console will have the full startup
+	  log though.
+
+config CONSOLE_ACTIVATE_NONE
+	prompt "leave all consoles disabled"
+	bool
+	help
+	  Leave all consoles disabled on startup. Board code or environment
+	  is responsible for enabling a console. Otherwise you'll get a working
+	  barebox, you just won't see anything.
+
+endchoice
+
+config CONSOLE_SIMPLE
+	bool
+	default y
+	depends on !CONSOLE_FULL
 
 config PARTITION
 	bool
-- 
1.7.10.4


_______________________________________________
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] startup: Print error message when initcall fails
  2012-10-07 11:39 [PATCH] misc improvements Sascha Hauer
                   ` (3 preceding siblings ...)
  2012-10-07 11:39 ` [PATCH 4/5] console: cleanup Kconfig Sascha Hauer
@ 2012-10-07 11:39 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-10-07 11:39 UTC (permalink / raw)
  To: barebox

There was a time when we used to panic when initcalls failed. Then
it was changed to totally ignore the return value. Instead, print
an error message now so that the user can get a clue when something
bad happened. So initcalls are now recommended to actually return
negative error codes when something fails.

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

diff --git a/common/startup.c b/common/startup.c
index b53bbef..775f97c 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -100,7 +100,9 @@ void start_barebox (void)
 			initcall < __barebox_initcalls_end; initcall++) {
 		debug("initcall-> %pS\n", *initcall);
 		result = (*initcall)();
-		debug("initcall<- %pS (%d)\n", *initcall, result);
+		if (result)
+			pr_err("initcall %pS failed: %s\n", *initcall,
+					strerror(-result));
 	}
 
 	debug("initcalls done\n");
-- 
1.7.10.4


_______________________________________________
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:[~2012-10-07 11:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-07 11:39 [PATCH] misc improvements Sascha Hauer
2012-10-07 11:39 ` [PATCH 1/5] driver: print error message when probe fails Sascha Hauer
2012-10-07 11:39 ` [PATCH 2/5] resource: statically initialize iomem resource Sascha Hauer
2012-10-07 11:39 ` [PATCH 3/5] console: Cleanup console activation Sascha Hauer
2012-10-07 11:39 ` [PATCH 4/5] console: cleanup Kconfig Sascha Hauer
2012-10-07 11:39 ` [PATCH 5/5] startup: Print error message when initcall fails Sascha Hauer

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