It is useful to be able to set the default log level from the command line
when running sandbox. Add a new -L command-line flag for this. The log
level is set using the enum log_level_t in log.h. At present a number must
be specified, e.g. -L7 for debug.

Signed-off-by: Simon Glass <s...@chromium.org>
---

 arch/sandbox/cpu/start.c         | 13 +++++++++++++
 arch/sandbox/include/asm/state.h |  1 +
 common/log.c                     |  3 ++-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index 2251ec4c53f..ab5007c7b35 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -282,6 +282,16 @@ static int sandbox_cmdline_cb_show_of_platdata(struct 
sandbox_state *state,
 }
 SANDBOX_CMDLINE_OPT(show_of_platdata, 0, "Show of-platdata in SPL");
 
+static int sandbox_cmdline_cb_log_level(struct sandbox_state *state,
+                                       const char *arg)
+{
+       state->default_log_level = simple_strtol(arg, NULL, 10);
+
+       return 0;
+}
+SANDBOX_CMDLINE_OPT_SHORT(log_level, 'L', 1,
+                         "Set log level (0=panic, 7=debug)");
+
 int board_run_command(const char *cmdline)
 {
        printf("## Commands are disabled. Please enable CONFIG_CMDLINE.\n");
@@ -331,6 +341,9 @@ int main(int argc, char *argv[])
        gd = &data;
 #if CONFIG_VAL(SYS_MALLOC_F_LEN)
        gd->malloc_base = CONFIG_MALLOC_F_ADDR;
+#endif
+#if CONFIG_IS_ENABLED(LOG)
+       gd->default_log_level = state->default_log_level;
 #endif
        setup_ram_buf(state);
 
diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h
index 4e4c71b8062..d1baba1c3ae 100644
--- a/arch/sandbox/include/asm/state.h
+++ b/arch/sandbox/include/asm/state.h
@@ -90,6 +90,7 @@ struct sandbox_state {
        bool skip_delays;               /* Ignore any time delays (for test) */
        bool show_test_output;          /* Don't suppress stdout in tests */
        bool show_of_platdata;          /* Show of-platdata in SPL */
+       int default_log_level;          /* Default log level for sandbox */
 
        /* Pointer to information for each SPI bus/cs */
        struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS]
diff --git a/common/log.c b/common/log.c
index 59869cd29da..ec14644516c 100644
--- a/common/log.c
+++ b/common/log.c
@@ -315,7 +315,8 @@ int log_init(void)
                drv++;
        }
        gd->flags |= GD_FLG_LOG_READY;
-       gd->default_log_level = LOGL_INFO;
+       if (!gd->default_log_level)
+               gd->default_log_level = LOGL_INFO;
        gd->log_fmt = LOGF_DEFAULT;
 
        return 0;
-- 
2.19.0.605.g01d371f741-goog

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to