9
0
Fork 0

Add PBL console support

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>
This commit is contained in:
Sascha Hauer 2014-12-08 10:28:59 +01:00
parent 017da2273a
commit a9d7b3d00e
7 changed files with 79 additions and 14 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -4,3 +4,4 @@
pbl-y += misc.o
pbl-y += string.o
pbl-y += decomp.o
pbl-$(CONFIG_PBL_CONSOLE) += console.o

32
pbl/console.c Normal file
View File

@ -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;
}