mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] pbl: console: Make it work with multiple setup_c()
@ 2016-09-14  8:21 Sascha Hauer
  2016-09-14  8:21 ` [PATCH 2/2] ARM: i.MX6: Sabrelite: Add PBL console support Sascha Hauer
  2016-09-14 17:41 ` [PATCH 1/2] pbl: console: Make it work with multiple setup_c() Trent Piepho
  0 siblings, 2 replies; 4+ messages in thread
From: Sascha Hauer @ 2016-09-14  8:21 UTC (permalink / raw)
  To: Barebox List

setup_c() may be called multiple times. When we store the pointer
to the console in bss, then it's zeroed during setup_c() and the
pointer to the console is lost. Initialize the pointer explicitly
to a non zero value to force storing it in the data section.

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

diff --git a/pbl/console.c b/pbl/console.c
index 4cefe748..0607a31 100644
--- a/pbl/console.c
+++ b/pbl/console.c
@@ -1,8 +1,10 @@
 #include <common.h>
 #include <debug_ll.h>
 
-static void (*__putc)(void *ctx, int c);
-static void *putc_ctx;
+#define INVALID_PTR ((void *)-1)
+
+static void (*__putc)(void *ctx, int c) = INVALID_PTR;
+static void *putc_ctx = INVALID_PTR;
 
 /**
  * pbl_set_putc() - setup UART used for PBL console
@@ -20,10 +22,10 @@ void pbl_set_putc(void (*putcf)(void *ctx, int c), void *ctx)
 
 void console_putc(unsigned int ch, char c)
 {
-	if (!__putc)
-		putc_ll(c);
-	else
+	if (__putc != INVALID_PTR)
 		__putc(putc_ctx, c);
+	else
+		putc_ll(c);
 }
 
 int console_puts(unsigned int ch, const char *str)
-- 
2.8.1


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

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-14  8:21 [PATCH 1/2] pbl: console: Make it work with multiple setup_c() Sascha Hauer
2016-09-14  8:21 ` [PATCH 2/2] ARM: i.MX6: Sabrelite: Add PBL console support Sascha Hauer
2016-09-14 17:41 ` [PATCH 1/2] pbl: console: Make it work with multiple setup_c() Trent Piepho
2016-09-15  7:25   ` Sascha Hauer

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