From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 5/9] Add PBL console support
Date: Tue, 9 Dec 2014 19:17:40 +0100 [thread overview]
Message-ID: <1418149064-26448-6-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1418149064-26448-1-git-send-email-s.hauer@pengutronix.de>
This adds simple console support to the PBL which makes it
possible to print more complex messages in the PBL than just
strings or hex numbers. For now puts_ll is used to print the
messages, so it depends on CONFIG_DEBUG_LL which makes it
more a debugging option. However, this could be extended later
to get regular output from the PBL if desired.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/Kconfig | 11 +++++++++++
include/printk.h | 15 ++++++++++-----
include/stdio.h | 20 +++++++++++---------
lib/Makefile | 2 ++
lib/vsprintf.c | 12 ++++++++++++
pbl/Makefile | 1 +
pbl/console.c | 32 ++++++++++++++++++++++++++++++++
7 files changed, 79 insertions(+), 14 deletions(-)
create mode 100644 pbl/console.c
diff --git a/common/Kconfig b/common/Kconfig
index 4614965..00e4f36 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -882,6 +882,17 @@ config DEBUG_INITCALLS
bool "Trace initcalls"
help
If enabled this will print initcall traces.
+
+config PBL_CONSOLE
+ depends on DEBUG_LL
+ bool "Enable console support in PBL"
+ help
+ This enables printf/pr_* support in the PBL to get more
+ informational output earlier during startup. Note that
+ printf/pr_* need a valid C environment, so the binary
+ must be running at the address it's linked at and bss must
+ be cleared. On ARM that would be after setup_c().
+
endmenu
config HAS_DEBUG_LL
diff --git a/include/printk.h b/include/printk.h
index 22c6c73..a27ad51 100644
--- a/include/printk.h
+++ b/include/printk.h
@@ -22,18 +22,23 @@
/* debugging and troubleshooting/diagnostic helpers. */
#ifndef CONFIG_CONSOLE_NONE
-int pr_print(int level, const char *format, ...)
- __attribute__ ((format(__printf__, 2, 3)));
-
int dev_printf(int level, const struct device_d *dev, const char *format, ...)
__attribute__ ((format(__printf__, 3, 4)));
#else
-static inline int pr_print(int level, const char *format, ...)
+static inline int dev_printf(int level, const struct device_d *dev, const char *format, ...)
{
return 0;
}
+#endif
-static inline int dev_printf(int level, const struct device_d *dev, const char *format, ...)
+#if (!defined(__PBL__) && !defined(CONFIG_CONSOLE_NONE)) || \
+ (defined(__PBL__) && defined(CONFIG_PBL_CONSOLE))
+int pr_print(int level, const char *format, ...)
+ __attribute__ ((format(__printf__, 2, 3)));
+#else
+static int pr_print(int level, const char *format, ...)
+ __attribute__ ((format(__printf__, 2, 3)));
+static inline int pr_print(int level, const char *format, ...)
{
return 0;
}
diff --git a/include/stdio.h b/include/stdio.h
index 71dbae3..f190911 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -29,8 +29,6 @@ int getc(void);
int console_puts(unsigned int ch, const char *s);
void console_flush(void);
-
-int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
int vprintf(const char *fmt, va_list args);
#else
static inline int tstc(void)
@@ -52,13 +50,6 @@ static inline void console_putc(unsigned int ch, char c) {}
static inline void console_flush(void) {}
-static int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
-static inline int printf(const char *fmt, ...)
-{
- return 0;
-}
-
-
static inline int vprintf(const char *fmt, va_list args)
{
return 0;
@@ -74,6 +65,17 @@ static inline int ctrlc (void)
#endif
+#if (!defined(__PBL__) && !defined(CONFIG_CONSOLE_NONE)) || \
+ (defined(__PBL__) && defined(CONFIG_PBL_CONSOLE))
+int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
+#else
+static int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
+static inline int printf(const char *fmt, ...)
+{
+ return 0;
+}
+#endif
+
static inline int puts(const char *s)
{
return console_puts(CONSOLE_STDOUT, s);
diff --git a/lib/Makefile b/lib/Makefile
index 604d934..226570a 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -6,7 +6,9 @@ obj-y += display_options.o
obj-y += string.o
obj-y += strtox.o
obj-y += vsprintf.o
+pbl-$(CONFIG_PBL_CONSOLE) += vsprintf.o
obj-y += div64.o
+pbl-y += div64.o
obj-y += misc.o
obj-$(CONFIG_PARAMETER) += parameter.o
obj-y += xfuncs.o
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 7f6b161..800ded7 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -175,6 +175,7 @@ static char *string(char *buf, char *end, char *s, int field_width, int precisio
return buf;
}
+#ifndef __PBL__
static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int precision, int flags)
{
unsigned long value = (unsigned long) ptr;
@@ -277,6 +278,17 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field
}
return number(buf, end, (unsigned long) ptr, 16, field_width, precision, flags);
}
+#else
+static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field_width, int precision, int flags)
+{
+ flags |= SMALL;
+ if (field_width == -1) {
+ field_width = 2*sizeof(void *);
+ flags |= ZEROPAD;
+ }
+ return number(buf, end, (unsigned long) ptr, 16, field_width, precision, flags);
+}
+#endif
/**
* vsnprintf - Format a string and place it in a buffer
diff --git a/pbl/Makefile b/pbl/Makefile
index a2d7468..c5a08c1 100644
--- a/pbl/Makefile
+++ b/pbl/Makefile
@@ -4,3 +4,4 @@
pbl-y += misc.o
pbl-y += string.o
pbl-y += decomp.o
+pbl-$(CONFIG_PBL_CONSOLE) += console.o
diff --git a/pbl/console.c b/pbl/console.c
new file mode 100644
index 0000000..3875e2a
--- /dev/null
+++ b/pbl/console.c
@@ -0,0 +1,32 @@
+#include <common.h>
+#include <debug_ll.h>
+
+int printf(const char *fmt, ...)
+{
+ va_list args;
+ uint i;
+ char printbuffer[CFG_PBSIZE];
+
+ va_start(args, fmt);
+ i = vsprintf(printbuffer, fmt, args);
+ va_end(args);
+
+ puts_ll(printbuffer);
+
+ return i;
+}
+
+int pr_print(int level, const char *fmt, ...)
+{
+ va_list args;
+ uint i;
+ char printbuffer[CFG_PBSIZE];
+
+ va_start(args, fmt);
+ i = vsprintf(printbuffer, fmt, args);
+ va_end(args);
+
+ puts_ll(printbuffer);
+
+ return i;
+}
--
2.1.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-12-09 18:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-09 18:17 Sascha Hauer
2014-12-09 18:17 ` [PATCH 1/9] PBL: Add strnlen, needed for printf support Sascha Hauer
2014-12-09 18:17 ` [PATCH 2/9] printf: move panic() to common/misc.c Sascha Hauer
2014-12-09 18:17 ` [PATCH 3/9] printf: move simple_strto*() functions to separate file Sascha Hauer
2014-12-09 18:17 ` [PATCH 4/9] printf: use local isdigit/isalnum implementation Sascha Hauer
2014-12-09 18:17 ` Sascha Hauer [this message]
2014-12-09 18:17 ` [PATCH 6/9] malloc: Add a function to detect if malloc pool is already initialized Sascha Hauer
2014-12-09 18:17 ` [PATCH 7/9] console: Make sure xzalloc is only used when it's available Sascha Hauer
2014-12-09 18:17 ` [PATCH 8/9] ARM: start.c: Add some debugging messages Sascha Hauer
2014-12-09 18:17 ` [PATCH 9/9] ARM: uncompress.c: " Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1418149064-26448-6-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox