[PATCH 0/2] sandbox: error output

U-Boot's printf() cannot write to the console before the serial console driver is set up. We need a function writing to the OS console.
Provide a new function os_printf() to print to the OS console.
Use the funciton to implement the error messages related to loading the device-tree.
For sure there are more places where we need os_printf() instead of printf() for error messages.
We also could use it to provide a debug console for the sandbox.
Heinrich Schuchardt (2): sandbox: add function os_printf() sandbox: show error if the device-tree cannot be loaded
arch/sandbox/cpu/cpu.c | 8 ++++---- arch/sandbox/cpu/os.c | 13 +++++++++++++ include/os.h | 7 +++++++ 3 files changed, 24 insertions(+), 4 deletions(-)

Before setting up the devices U-Boot's printf() function cannot be used for console output. Provide function os_printf() to print to stderr.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- arch/sandbox/cpu/os.c | 13 +++++++++++++ include/os.h | 7 +++++++ 2 files changed, 20 insertions(+)
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index d83c862182..ec1836f8f6 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -11,6 +11,7 @@ #include <getopt.h> #include <setjmp.h> #include <signal.h> +#include <stdarg.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> @@ -51,6 +52,18 @@ ssize_t os_write(int fd, const void *buf, size_t count) return write(fd, buf, count); }
+int os_printf(const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i = vfprintf(stdout, fmt, args); + va_end(args); + + return i; +} + off_t os_lseek(int fd, off_t offset, int whence) { if (whence == OS_SEEK_SET) diff --git a/include/os.h b/include/os.h index 10e198cf50..148178787b 100644 --- a/include/os.h +++ b/include/os.h @@ -16,6 +16,13 @@ struct rtc_time; struct sandbox_state;
+/** + * os_printf() - print directly to OS console + * + * @format: format string + */ +int os_printf(const char *format, ...); + /** * Access to the OS read() system call *

Before setting up the devices U-Boot's printf() function cannot be used for console output. Provide function os_printf() to print to stderr.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- arch/sandbox/cpu/os.c | 13 +++++++++++++ include/os.h | 7 +++++++ 2 files changed, 20 insertions(+)
Applied to u-boot-dm, thanks!

U-Boot's printf() used before setting up U-Boot's serial driver does not create any output. Use os_printf() for error messages related to loading the device-tree.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- arch/sandbox/cpu/cpu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index ff0fa8a685..9e379da17a 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -306,27 +306,27 @@ void *board_fdt_blob_setup(int *ret) err = fdt_create_empty_tree(blob, 256); if (!err) goto done; - printf("Unable to create empty FDT: %s\n", fdt_strerror(err)); + os_printf("Unable to create empty FDT: %s\n", fdt_strerror(err)); *ret = -EINVAL; goto fail; }
err = os_get_filesize(fname, &size); if (err < 0) { - printf("Failed to find FDT file '%s'\n", fname); + os_printf("Failed to find FDT file '%s'\n", fname); *ret = err; goto fail; } fd = os_open(fname, OS_O_RDONLY); if (fd < 0) { - printf("Failed to open FDT file '%s'\n", fname); + os_printf("Failed to open FDT file '%s'\n", fname); *ret = -EACCES; goto fail; }
if (os_read(fd, blob, size) != size) { os_close(fd); - printf("Failed to read FDT file '%s'\n", fname); + os_printf("Failed to read FDT file '%s'\n", fname); *ret = -EIO; goto fail; }

U-Boot's printf() used before setting up U-Boot's serial driver does not create any output. Use os_printf() for error messages related to loading the device-tree.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- arch/sandbox/cpu/cpu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Applied to u-boot-dm, thanks!
participants (2)
-
Heinrich Schuchardt
-
Simon Glass