diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/Kconfig | 8 | ||||
-rw-r--r-- | common/Kconfig.boot | 5 | ||||
-rw-r--r-- | common/Makefile | 1 | ||||
-rw-r--r-- | common/autoboot.c | 12 | ||||
-rw-r--r-- | common/board_f.c | 78 | ||||
-rw-r--r-- | common/board_r.c | 134 | ||||
-rw-r--r-- | common/cli_readline.c | 6 | ||||
-rw-r--r-- | common/command.c | 6 | ||||
-rw-r--r-- | common/console.c | 413 | ||||
-rw-r--r-- | common/exports.c | 4 | ||||
-rw-r--r-- | common/iomux.c | 49 | ||||
-rw-r--r-- | common/log.c | 40 | ||||
-rw-r--r-- | common/spl/Kconfig | 2 | ||||
-rw-r--r-- | common/spl/spl_fit.c | 7 | ||||
-rw-r--r-- | common/stdio.c | 4 |
15 files changed, 394 insertions, 375 deletions
diff --git a/common/Kconfig b/common/Kconfig index 2bce8c9ba1..d8982ba377 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -17,6 +17,14 @@ config CONSOLE_RECORD To enable console recording, call console_record_reset_enable() from your code. +config CONSOLE_RECORD_INIT_F + bool "Enable console recording during pre-relocation init" + depends on CONSOLE_RECORD && SYS_MALLOC_F + default y + help + This option enables console recording during pre-relocation init. + CONFIG_SYS_MALLOC_F must be enabled to use this feature. + config CONSOLE_RECORD_OUT_SIZE hex "Output buffer size" depends on CONSOLE_RECORD diff --git a/common/Kconfig.boot b/common/Kconfig.boot index 58e98548de..4525a12ab4 100644 --- a/common/Kconfig.boot +++ b/common/Kconfig.boot @@ -819,7 +819,10 @@ config AUTOBOOT_STOP_STR_SHA256 This option adds the feature to only stop the autobooting, and therefore boot into the U-Boot prompt, when the input string / password matches a values that is encypted via - a SHA256 hash and saved in the environment. + a SHA256 hash and saved in the environment variable + "bootstopkeysha256". If the value in that variable + includes a ":", the portion prior to the ":" will be treated + as a salt value. config AUTOBOOT_USE_MENUKEY bool "Allow a specify key to run a menu from the environment" diff --git a/common/Makefile b/common/Makefile index bcf352d016..daeea67cf2 100644 --- a/common/Makefile +++ b/common/Makefile @@ -68,7 +68,6 @@ obj-$(CONFIG_DFU_OVER_USB) += dfu.o endif obj-$(CONFIG_SPL_HASH_SUPPORT) += hash.o obj-$(CONFIG_TPL_HASH_SUPPORT) += hash.o -obj-$(CONFIG_SPL_YMODEM_SUPPORT) += xyzModem.o obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o obj-$(CONFIG_SPL_NET_SUPPORT) += miiphyutil.o obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += fdt_support.o diff --git a/common/autoboot.c b/common/autoboot.c index e628baffb8..ddb6246be3 100644 --- a/common/autoboot.c +++ b/common/autoboot.c @@ -25,7 +25,7 @@ DECLARE_GLOBAL_DATA_PTR; -#define MAX_DELAY_STOP_STR 32 +#define MAX_DELAY_STOP_STR 64 #ifndef DEBUG_BOOTKEYS #define DEBUG_BOOTKEYS 0 @@ -80,6 +80,7 @@ static int passwd_abort_sha256(uint64_t etime) u8 sha_env[SHA256_SUM_LEN]; u8 *sha; char *presskey; + char *c; const char *algo_name = "sha256"; u_int presskey_len = 0; int abort = 0; @@ -89,6 +90,14 @@ static int passwd_abort_sha256(uint64_t etime) if (sha_env_str == NULL) sha_env_str = AUTOBOOT_STOP_STR_SHA256; + presskey = malloc_cache_aligned(MAX_DELAY_STOP_STR); + c = strstr(sha_env_str, ":"); + if (c && (c - sha_env_str < MAX_DELAY_STOP_STR)) { + /* preload presskey with salt */ + memcpy(presskey, sha_env_str, c - sha_env_str); + presskey_len = c - sha_env_str; + sha_env_str = c + 1; + } /* * Generate the binary value from the environment hash value * so that we can compare this value with the computed hash @@ -100,7 +109,6 @@ static int passwd_abort_sha256(uint64_t etime) return 0; } - presskey = malloc_cache_aligned(MAX_DELAY_STOP_STR); sha = malloc_cache_aligned(SHA256_SUM_LEN); size = SHA256_SUM_LEN; /* diff --git a/common/board_f.c b/common/board_f.c index 9f441c44f1..ae3001bed1 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -503,14 +503,6 @@ static int reserve_board(void) return 0; } -static int setup_machine(void) -{ -#ifdef CONFIG_MACH_TYPE - gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */ -#endif - return 0; -} - static int reserve_global_data(void) { gd->start_addr_sp = reserve_stack_aligned(sizeof(gd_t)); @@ -522,21 +514,21 @@ static int reserve_global_data(void) static int reserve_fdt(void) { -#ifndef CONFIG_OF_EMBED - /* - * If the device tree is sitting immediately above our image then we - * must relocate it. If it is embedded in the data section, then it - * will be relocated with other data. - */ - if (gd->fdt_blob) { - gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob), 32); + if (!IS_ENABLED(CONFIG_OF_EMBED)) { + /* + * If the device tree is sitting immediately above our image + * then we must relocate it. If it is embedded in the data + * section, then it will be relocated with other data. + */ + if (gd->fdt_blob) { + gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob), 32); - gd->start_addr_sp = reserve_stack_aligned(gd->fdt_size); - gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size); - debug("Reserving %lu Bytes for FDT at: %08lx\n", - gd->fdt_size, gd->start_addr_sp); + gd->start_addr_sp = reserve_stack_aligned(gd->fdt_size); + gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size); + debug("Reserving %lu Bytes for FDT at: %08lx\n", + gd->fdt_size, gd->start_addr_sp); + } } -#endif return 0; } @@ -605,6 +597,10 @@ int setup_bdinfo(void) bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; /* size of SRAM */ } +#ifdef CONFIG_MACH_TYPE + bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */ +#endif + return arch_setup_bdinfo(); } @@ -620,14 +616,15 @@ static int init_post(void) static int reloc_fdt(void) { -#ifndef CONFIG_OF_EMBED - if (gd->flags & GD_FLG_SKIP_RELOC) - return 0; - if (gd->new_fdt) { - memcpy(gd->new_fdt, gd->fdt_blob, fdt_totalsize(gd->fdt_blob)); - gd->fdt_blob = gd->new_fdt; + if (!IS_ENABLED(CONFIG_OF_EMBED)) { + if (gd->flags & GD_FLG_SKIP_RELOC) + return 0; + if (gd->new_fdt) { + memcpy(gd->new_fdt, gd->fdt_blob, + fdt_totalsize(gd->fdt_blob)); + gd->fdt_blob = gd->new_fdt; + } } -#endif return 0; } @@ -765,15 +762,6 @@ static int initf_bootstage(void) return 0; } -static int initf_console_record(void) -{ -#if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN) - return console_record_init(); -#else - return 0; -#endif -} - static int initf_dm(void) { #if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN) @@ -784,11 +772,12 @@ static int initf_dm(void) bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_F); if (ret) return ret; -#endif -#ifdef CONFIG_TIMER_EARLY - ret = dm_timer_init(); - if (ret) - return ret; + + if (IS_ENABLED(CONFIG_TIMER_EARLY)) { + ret = dm_timer_init(); + if (ret) + return ret; + } #endif return 0; @@ -830,7 +819,9 @@ static const init_fnc_t init_sequence_f[] = { bloblist_init, #endif setup_spl_handoff, - initf_console_record, +#if defined(CONFIG_CONSOLE_RECORD_INIT_F) + console_record_init, +#endif #if defined(CONFIG_HAVE_FSP) arch_fsp_init, #endif @@ -922,7 +913,6 @@ static const init_fnc_t init_sequence_f[] = { reserve_uboot, reserve_malloc, reserve_board, - setup_machine, reserve_global_data, reserve_fdt, reserve_bootstage, diff --git a/common/board_r.c b/common/board_r.c index 29dd7d26d9..9fa4d4b42e 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -91,21 +91,8 @@ __weak int board_flash_wp_on(void) return 0; } -__weak void cpu_secondary_init_r(void) +__weak int cpu_secondary_init_r(void) { -} - -static int initr_secondary_cpu(void) -{ - /* - * after non-volatile devices & environment is setup and cpu code have - * another round to deal with any initialization that might require - * full access to the environment or loading of some image (firmware) - * from a non-volatile device - */ - /* TODO: maybe define this for all archs? */ - cpu_secondary_init_r(); - return 0; } @@ -195,20 +182,10 @@ static int initr_reloc_global_data(void) return 0; } -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) -static int initr_trap(void) +__weak int arch_initr_trap(void) { - /* - * Setup trap handlers - */ -#if defined(CONFIG_PPC) - trap_init(gd->relocaddr); -#else - trap_init(CONFIG_SYS_SDRAM_BASE); -#endif return 0; } -#endif #ifdef CONFIG_ADDR_MAP static int initr_addr_map(void) @@ -219,14 +196,6 @@ static int initr_addr_map(void) } #endif -#ifdef CONFIG_POST -static int initr_post_backlog(void) -{ - post_output_backlog(); - return 0; -} -#endif - #if defined(CONFIG_SYS_INIT_RAM_LOCK) && defined(CONFIG_E500) static int initr_unlock_ram_in_cache(void) { @@ -235,25 +204,6 @@ static int initr_unlock_ram_in_cache(void) } #endif -#ifdef CONFIG_PCI_ENDPOINT -static int initr_pci_ep(void) -{ - pci_ep_init(); - - return 0; -} -#endif - -#ifdef CONFIG_PCI -static int initr_pci(void) -{ - if (IS_ENABLED(CONFIG_PCI_INIT_R)) - pci_init(); - - return 0; -} -#endif - static int initr_barrier(void) { #ifdef CONFIG_PPC @@ -282,23 +232,6 @@ static int initr_malloc(void) return 0; } -static int initr_console_record(void) -{ -#if defined(CONFIG_CONSOLE_RECORD) - return console_record_init(); -#else - return 0; -#endif -} - -#ifdef CONFIG_SYS_NONCACHED_MEMORY -static int initr_noncached(void) -{ - noncached_init(); - return 0; -} -#endif - static int initr_of_live(void) { if (CONFIG_IS_ENABLED(OF_LIVE)) { @@ -485,14 +418,6 @@ static int initr_mmc(void) } #endif -#ifdef CONFIG_XEN -static int initr_xen(void) -{ - xen_init(); - return 0; -} -#endif - #ifdef CONFIG_PVBLOCK static int initr_pvblock(void) { @@ -555,21 +480,6 @@ static int initr_malloc_bootparams(void) } #endif -static int initr_jumptable(void) -{ - jumptable_init(); - return 0; -} - -#if defined(CONFIG_API) -static int initr_api(void) -{ - /* Initialize API */ - api_init(); - return 0; -} -#endif - #ifdef CONFIG_CMD_NET static int initr_ethaddr(void) { @@ -614,14 +524,6 @@ static int initr_scsi(void) } #endif -#ifdef CONFIG_BITBANGMII -static int initr_bbmii(void) -{ - bb_miiphy_init(); - return 0; -} -#endif - #ifdef CONFIG_CMD_NET static int initr_net(void) { @@ -713,9 +615,11 @@ static init_fnc_t init_sequence_r[] = { initr_malloc, log_init, initr_bootstage, /* Needs malloc() but has its own timer */ - initr_console_record, +#if defined(CONFIG_CONSOLE_RECORD) + console_record_init, +#endif #ifdef CONFIG_SYS_NONCACHED_MEMORY - initr_noncached, + noncached_init, #endif initr_of_live, #ifdef CONFIG_DM @@ -755,9 +659,7 @@ static init_fnc_t init_sequence_r[] = { #ifdef CONFIG_NEEDS_MANUAL_RELOC initr_manual_reloc_cmdtable, #endif -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) - initr_trap, -#endif + arch_initr_trap, #ifdef CONFIG_ADDR_MAP initr_addr_map, #endif @@ -766,15 +668,15 @@ static init_fnc_t init_sequence_r[] = { #endif INIT_FUNC_WATCHDOG_RESET #ifdef CONFIG_POST - initr_post_backlog, + post_output_backlog, #endif INIT_FUNC_WATCHDOG_RESET -#if defined(CONFIG_PCI) && defined(CONFIG_SYS_EARLY_PCI_INIT) +#if defined(CONFIG_PCI_INIT_R) && defined(CONFIG_SYS_EARLY_PCI_INIT) /* * Do early PCI configuration _before_ the flash gets initialised, * because PCU resources are crucial for flash access on some boards. */ - initr_pci, + pci_init, #endif #ifdef CONFIG_ARCH_EARLY_INIT_R arch_early_init_r, @@ -798,7 +700,7 @@ static init_fnc_t init_sequence_r[] = { initr_mmc, #endif #ifdef CONFIG_XEN - initr_xen, + xen_init, #endif #ifdef CONFIG_PVBLOCK initr_pvblock, @@ -808,21 +710,21 @@ static init_fnc_t init_sequence_r[] = { initr_malloc_bootparams, #endif INIT_FUNC_WATCHDOG_RESET - initr_secondary_cpu, + cpu_secondary_init_r, #if defined(CONFIG_ID_EEPROM) || defined(CONFIG_SYS_I2C_MAC_OFFSET) mac_read_from_eeprom, #endif INIT_FUNC_WATCHDOG_RESET -#if defined(CONFIG_PCI) && !defined(CONFIG_SYS_EARLY_PCI_INIT) +#if defined(CONFIG_PCI_INIT_R) && !defined(CONFIG_SYS_EARLY_PCI_INIT) /* * Do pci configuration */ - initr_pci, + pci_init, #endif stdio_add_devices, - initr_jumptable, + jumptable_init, #ifdef CONFIG_API - initr_api, + api_init, #endif console_init_r, /* fully init console as a device */ #ifdef CONFIG_DISPLAY_BOARDINFO_LATE @@ -861,10 +763,10 @@ static init_fnc_t init_sequence_r[] = { initr_scsi, #endif #ifdef CONFIG_BITBANGMII - initr_bbmii, + bb_miiphy_init, #endif #ifdef CONFIG_PCI_ENDPOINT - initr_pci_ep, + pci_ep_init, #endif #ifdef CONFIG_CMD_NET INIT_FUNC_WATCHDOG_RESET diff --git a/common/cli_readline.c b/common/cli_readline.c index 47b876285c..5c158d03b4 100644 --- a/common/cli_readline.c +++ b/common/cli_readline.c @@ -493,8 +493,10 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len, } #endif default: - cread_add_char(ichar, insert, &num, &eol_num, buf, - *len); + if (ichar >= ' ' && ichar <= '~') { + cread_add_char(ichar, insert, &num, &eol_num, + buf, *len); + } break; } } diff --git a/common/command.c b/common/command.c index 068cb55b4c..3fe6791eda 100644 --- a/common/command.c +++ b/common/command.c @@ -16,6 +16,8 @@ #include <log.h> #include <linux/ctype.h> +DECLARE_GLOBAL_DATA_PTR; + /* * Use puts() instead of printf() to avoid printf buffer overflow * for long help messages @@ -488,9 +490,6 @@ int cmd_get_data_size(char* arg, int default_size) } #endif -#if defined(CONFIG_NEEDS_MANUAL_RELOC) -DECLARE_GLOBAL_DATA_PTR; - void fixup_cmdtable(struct cmd_tbl *cmdtp, int size) { int i; @@ -535,7 +534,6 @@ void fixup_cmdtable(struct cmd_tbl *cmdtp, int size) cmdtp++; } } -#endif int cmd_always_repeatable(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], int *repeatable) diff --git a/common/console.c b/common/console.c index 3348436da6..f3cc45cab5 100644 --- a/common/console.c +++ b/common/console.c @@ -44,14 +44,15 @@ static int on_console(const char *name, const char *value, enum env_op op, case env_op_create: case env_op_overwrite: -#if CONFIG_IS_ENABLED(CONSOLE_MUX) - if (iomux_doenv(console, value)) - return 1; -#else - /* Try assigning specified device */ - if (console_assign(console, value) < 0) - return 1; -#endif + if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { + if (iomux_doenv(console, value)) + return 1; + } else { + /* Try assigning specified device */ + if (console_assign(console, value) < 0) + return 1; + } + return 0; case env_op_delete: @@ -69,14 +70,13 @@ U_BOOT_ENV_CALLBACK(console, on_console); static int on_silent(const char *name, const char *value, enum env_op op, int flags) { -#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET) - if (flags & H_INTERACTIVE) - return 0; -#endif -#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC) - if ((flags & H_INTERACTIVE) == 0) - return 0; -#endif + if (!CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET)) + if (flags & H_INTERACTIVE) + return 0; + + if (!CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC)) + if ((flags & H_INTERACTIVE) == 0) + return 0; if (value != NULL) gd->flags |= GD_FLG_SILENT; @@ -88,6 +88,64 @@ static int on_silent(const char *name, const char *value, enum env_op op, U_BOOT_ENV_CALLBACK(silent, on_silent); #endif +#ifdef CONFIG_CONSOLE_RECORD +/* helper function: access to gd->console_out and gd->console_in */ +static void console_record_putc(const char c) +{ + if (!(gd->flags & GD_FLG_RECORD)) + return; + if (gd->console_out.start) + membuff_putbyte((struct membuff *)&gd->console_out, c); +} + +static void console_record_puts(const char *s) +{ + if (!(gd->flags & GD_FLG_RECORD)) + return; + if (gd->console_out.start) + membuff_put((struct membuff *)&gd->console_out, s, strlen(s)); +} + +static int console_record_getc(void) +{ + if (!(gd->flags & GD_FLG_RECORD)) + return -1; + if (!gd->console_in.start) + return -1; + + return membuff_getbyte((struct membuff *)&gd->console_in); +} + +static int console_record_tstc(void) +{ + if (!(gd->flags & GD_FLG_RECORD)) + return 0; + if (gd->console_in.start) { + if (membuff_peekbyte((struct membuff *)&gd->console_in) != -1) + return 1; + } + return 0; +} +#else +static void console_record_putc(char c) +{ +} + +static void console_record_puts(const char *s) +{ +} + +static int console_record_getc(void) +{ + return -1; +} + +static int console_record_tstc(void) +{ + return 0; +} +#endif + #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV) /* * if overwrite_console returns 1, the stdin, stderr and stdout @@ -114,13 +172,9 @@ static int console_setfile(int file, struct stdio_dev * dev) case stdin: case stdout: case stderr: - /* Start new device */ - if (dev->start) { - error = dev->start(dev); - /* If it's not started dont use it */ - if (error < 0) - break; - } + error = console_start(file, dev); + if (error) + break; /* Assign the new device (leaving the existing one started) */ stdio_devices[file] = dev; @@ -159,14 +213,13 @@ static bool console_dev_is_serial(struct stdio_dev *sdev) { bool is_serial; -#ifdef CONFIG_DM_SERIAL - if (sdev->flags & DEV_FLAGS_DM) { + if (IS_ENABLED(CONFIG_DM_SERIAL) && (sdev->flags & DEV_FLAGS_DM)) { struct udevice *dev = sdev->priv; is_serial = device_get_uclass_id(dev) == UCLASS_SERIAL; - } else -#endif - is_serial = !strcmp(sdev->name, "serial"); + } else { + is_serial = !strcmp(sdev->name, "serial"); + } return is_serial; } @@ -174,10 +227,42 @@ static bool console_dev_is_serial(struct stdio_dev *sdev) #if CONFIG_IS_ENABLED(CONSOLE_MUX) /** Console I/O multiplexing *******************************************/ +/* tstcdev: save the last stdio device with pending characters, with tstc != 0 */ static struct stdio_dev *tstcdev; struct stdio_dev **console_devices[MAX_FILES]; int cd_count[MAX_FILES]; +static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev) +{ + console_devices[file][0] = dev; +} + +/** + * console_needs_start_stop() - check if we need to start or stop the STDIO device + * @file: STDIO file + * @sdev: STDIO device in question + * + * This function checks if we need to start or stop the stdio device used for + * a console. For IOMUX case it simply enforces one time start and one time + * stop of the device independently of how many STDIO files are using it. In + * other words, we start console once before first STDIO device wants it and + * stop after the last is gone. + */ +static bool console_needs_start_stop(int file, struct stdio_dev *sdev) +{ + int i, j; + + for (i = 0; i < ARRAY_SIZE(cd_count); i++) { + if (i == file) + continue; + + for (j = 0; j < cd_count[i]; j++) + if (console_devices[i][j] == sdev) + return false; + } + return true; +} + /* * This depends on tstc() always being called before getchar(). * This is guaranteed to be true because this routine is called @@ -194,6 +279,12 @@ static int console_getc(int file) return ret; } +/* Upper layer may have already called tstc(): check the saved result */ +static bool console_has_tstc(void) +{ + return !!tstcdev; +} + static int console_tstc(int file) { int i, ret; @@ -276,11 +367,26 @@ static inline void console_doenv(int file, struct stdio_dev *dev) } #endif #else + +static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev) +{ +} + +static inline bool console_needs_start_stop(int file, struct stdio_dev *sdev) +{ + return true; +} + static inline int console_getc(int file) { return stdio_devices[file]->getc(stdio_devices[file]); } +static bool console_has_tstc(void) +{ + return false; +} + static inline int console_tstc(int file) { return stdio_devices[file]->tstc(stdio_devices[file]); @@ -310,6 +416,32 @@ static inline void console_doenv(int file, struct stdio_dev *dev) #endif #endif /* CONIFIG_IS_ENABLED(CONSOLE_MUX) */ +int console_start(int file, struct stdio_dev *sdev) +{ + int error; + + if (!console_needs_start_stop(file, sdev)) + return 0; + + /* Start new device */ + if (sdev->start) { + error = sdev->start(sdev); + /* If it's not started don't use it */ + if (error < 0) + return error; + } + return 0; +} + +void console_stop(int file, struct stdio_dev *sdev) +{ + if (!console_needs_start_stop(file, sdev)) + return; + + if (sdev->stop) + sdev->stop(sdev); +} + /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/ int serial_printf(const char *fmt, ...) @@ -338,25 +470,25 @@ int fgetc(int file) */ for (;;) { WATCHDOG_RESET(); -#if CONFIG_IS_ENABLED(CONSOLE_MUX) - /* - * Upper layer may have already called tstc() so - * check for that first. - */ - if (tstcdev != NULL) - return console_getc(file); - console_tstc(file); -#else - if (console_tstc(file)) - return console_getc(file); -#endif -#ifdef CONFIG_WATCHDOG + if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { + /* + * Upper layer may have already called tstc() so + * check for that first. + */ + if (console_has_tstc()) + return console_getc(file); + console_tstc(file); + } else { + if (console_tstc(file)) + return console_getc(file); + } + /* * If the watchdog must be rate-limited then it should * already be handled in board-specific code. */ - udelay(1); -#endif + if (IS_ENABLED(CONFIG_WATCHDOG)) + udelay(1); } } @@ -406,23 +538,18 @@ int fprintf(int file, const char *fmt, ...) int getchar(void) { -#ifdef CONFIG_DISABLE_CONSOLE - if (gd->flags & GD_FLG_DISABLE_CONSOLE) + int ch; + + if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE)) return 0; -#endif if (!gd->have_console) return 0; -#ifdef CONFIG_CONSOLE_RECORD - if (gd->console_in.start) { - int ch; + ch = console_record_getc(); + if (ch != -1) + return ch; - ch = membuff_getbyte((struct membuff *)&gd->console_in); - if (ch != -1) - return 1; - } -#endif if (gd->flags & GD_FLG_DEVINIT) { /* Get from the standard input */ return fgetc(stdin); @@ -434,19 +561,15 @@ int getchar(void) int tstc(void) { -#ifdef CONFIG_DISABLE_CONSOLE - if (gd->flags & GD_FLG_DISABLE_CONSOLE) + if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE)) return 0; -#endif if (!gd->have_console) return 0; -#ifdef CONFIG_CONSOLE_RECORD - if (gd->console_in.start) { - if (membuff_peekbyte((struct membuff *)&gd->console_in) != -1) - return 1; - } -#endif + + if (console_record_tstc()) + return 1; + if (gd->flags & GD_FLG_DEVINIT) { /* Test the standard input */ return ftstc(stdin); @@ -485,10 +608,8 @@ static void print_pre_console_buffer(int flushpoint) char buf_out[CONFIG_PRE_CON_BUF_SZ + 1]; char *buf_in; -#ifdef CONFIG_SILENT_CONSOLE - if (gd->flags & GD_FLG_SILENT) + if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) return; -#endif buf_in = map_sysmem(CONFIG_PRE_CON_BUF_ADDR, CONFIG_PRE_CON_BUF_SZ); if (gd->precon_buf_idx > CONFIG_PRE_CON_BUF_SZ) @@ -517,38 +638,31 @@ static inline void print_pre_console_buffer(int flushpoint) {} void putc(const char c) { -#ifdef CONFIG_SANDBOX + if (!gd) + return; + + console_record_putc(c); + /* sandbox can send characters to stdout before it has a console */ - if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { + if (IS_ENABLED(CONFIG_SANDBOX) && !(gd->flags & GD_FLG_SERIAL_READY)) { os_putc(c); return; } -#endif -#ifdef CONFIG_DEBUG_UART + /* if we don't have a console yet, use the debug UART */ - if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { + if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY)) { printch(c); return; } -#endif - if (!gd) - return; -#ifdef CONFIG_CONSOLE_RECORD - if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start) - membuff_putbyte((struct membuff *)&gd->console_out, c); -#endif -#ifdef CONFIG_SILENT_CONSOLE - if (gd->flags & GD_FLG_SILENT) { + + if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) { if (!(gd->flags & GD_FLG_DEVINIT)) pre_console_putc(c); return; } -#endif -#ifdef CONFIG_DISABLE_CONSOLE - if (gd->flags & GD_FLG_DISABLE_CONSOLE) + if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE)) return; -#endif if (!gd->have_console) return pre_console_putc(c); @@ -565,15 +679,18 @@ void putc(const char c) void puts(const char *s) { -#ifdef CONFIG_SANDBOX + if (!gd) + return; + + console_record_puts(s); + /* sandbox can send characters to stdout before it has a console */ - if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { + if (IS_ENABLED(CONFIG_SANDBOX) && !(gd->flags & GD_FLG_SERIAL_READY)) { os_puts(s); return; } -#endif -#ifdef CONFIG_DEBUG_UART - if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) { + + if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY)) { while (*s) { int ch = *s++; @@ -581,25 +698,15 @@ void puts(const char *s) } return; } -#endif - if (!gd) - return; -#ifdef CONFIG_CONSOLE_RECORD - if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start) - membuff_put((struct membuff *)&gd->console_out, s, strlen(s)); -#endif -#ifdef CONFIG_SILENT_CONSOLE - if (gd->flags & GD_FLG_SILENT) { + + if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT)) { if (!(gd->flags & GD_FLG_DEVINIT)) pre_console_puts(s); return; } -#endif -#ifdef CONFIG_DISABLE_CONSOLE - if (gd->flags & GD_FLG_DISABLE_CONSOLE) + if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE)) return; -#endif if (!gd->have_console) return pre_console_puts(s); @@ -725,7 +832,7 @@ void clear_ctrlc(void) /** U-Boot INIT FUNCTIONS *************************************************/ -struct stdio_dev *search_device(int flags, const char *name) +struct stdio_dev *console_search_dev(int flags, const char *name) { struct stdio_dev *dev; @@ -761,7 +868,7 @@ int console_assign(int file, const char *devname) /* Check for valid device name */ - dev = search_device(flag, devname); + dev = console_search_dev(flag, devname); if (dev) return console_setfile(file, dev); @@ -772,19 +879,19 @@ int console_assign(int file, const char *devname) /* return true if the 'silent' flag is removed */ static bool console_update_silent(void) { -#ifdef CONFIG_SILENT_CONSOLE - if (env_get("silent")) { - gd->flags |= GD_FLG_SILENT; - } else { - unsigned long flags = gd->flags; + unsigned long flags = gd->flags; - gd->flags &= ~GD_FLG_SILENT; + if (!IS_ENABLED(CONFIG_SILENT_CONSOLE)) + return false; - return !!(flags & GD_FLG_SILENT); + if (env_get("silent")) { + gd->flags |= GD_FLG_SILENT; + return false; } -#endif - return false; + gd->flags &= ~GD_FLG_SILENT; + + return !!(flags & GD_FLG_SILENT); } int console_announce_r(void) @@ -843,12 +950,8 @@ int console_init_r(void) { char *stdinname, *stdoutname, *stderrname; struct stdio_dev *inputdev = NULL, *outputdev = NULL, *errdev = NULL; -#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE int i; -#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ -#if CONFIG_IS_ENABLED(CONSOLE_MUX) int iomux_err = 0; -#endif int flushpoint; /* update silent for env loaded from flash (initr_env) */ @@ -871,27 +974,27 @@ int console_init_r(void) stderrname = env_get("stderr"); if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */ - inputdev = search_device(DEV_FLAGS_INPUT, stdinname); - outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname); - errdev = search_device(DEV_FLAGS_OUTPUT, stderrname); -#if CONFIG_IS_ENABLED(CONSOLE_MUX) - iomux_err = iomux_doenv(stdin, stdinname); - iomux_err += iomux_doenv(stdout, stdoutname); - iomux_err += iomux_doenv(stderr, stderrname); - if (!iomux_err) - /* Successful, so skip all the code below. */ - goto done; -#endif + inputdev = console_search_dev(DEV_FLAGS_INPUT, stdinname); + outputdev = console_search_dev(DEV_FLAGS_OUTPUT, stdoutname); + errdev = console_search_dev(DEV_FLAGS_OUTPUT, stderrname); + if (CONFIG_IS_ENABLED(CONSOLE_MUX)) { + iomux_err = iomux_doenv(stdin, stdinname); + iomux_err += iomux_doenv(stdout, stdoutname); + iomux_err += iomux_doenv(stderr, stderrname); + if (!iomux_err) + /* Successful, so skip all the code below. */ + goto done; + } } /* if the devices are overwritten or not found, use default device */ if (inputdev == NULL) { - inputdev = search_device(DEV_FLAGS_INPUT, "serial"); + inputdev = console_search_dev(DEV_FLAGS_INPUT, "serial"); } if (outputdev == NULL) { - outputdev = search_device(DEV_FLAGS_OUTPUT, "serial"); + outputdev = console_search_dev(DEV_FLAGS_OUTPUT, "serial"); } if (errdev == NULL) { - errdev = search_device(DEV_FLAGS_OUTPUT, "serial"); + errdev = console_search_dev(DEV_FLAGS_OUTPUT, "serial"); } /* Initializes output console first */ if (outputdev != NULL) { @@ -907,33 +1010,25 @@ int console_init_r(void) console_doenv(stdin, inputdev); } -#if CONFIG_IS_ENABLED(CONSOLE_MUX) done: -#endif -#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET - stdio_print_current_devices(); -#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ + if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET)) + stdio_print_current_devices(); + #ifdef CONFIG_VIDCONSOLE_AS_LCD if (strstr(stdoutname, CONFIG_VIDCONSOLE_AS_NAME)) printf("Warning: Please change '%s' to 'vidconsole' in stdout/stderr environment vars\n", CONFIG_VIDCONSOLE_AS_NAME); #endif -#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE - /* set the environment variables (will overwrite previous env settings) */ - for (i = 0; i < MAX_FILES; i++) { - env_set(stdio_names[i], stdio_devices[i]->name); + if (IS_ENABLED(CONFIG_SYS_CONSOLE_ENV_OVERWRITE)) { + /* set the environment variables (will overwrite previous env settings) */ + for (i = 0; i < MAX_FILES; i++) + env_set(stdio_names[i], stdio_devices[i]->name); } -#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */ gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ -#if 0 - /* If nothing usable installed, use only the initial console */ - if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) - return 0; -#endif print_pre_console_buffer(flushpoint); return 0; } @@ -956,18 +1051,16 @@ int console_init_r(void) else flushpoint = PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL; -#ifdef CONFIG_SPLASH_SCREEN /* * suppress all output if splash screen is enabled and we have * a bmp to display. We redirect the output from frame buffer * console to serial console in this case or suppress it if * "silent" mode was requested. */ - if (env_get("splashimage") != NULL) { + if (IS_ENABLED(CONFIG_SPLASH_SCREEN) && env_get("splashimage")) { if (!(gd->flags & GD_FLG_SILENT)) - outputdev = search_device (DEV_FLAGS_OUTPUT, "serial"); + outputdev = console_search_dev (DEV_FLAGS_OUTPUT, "serial"); } -#endif /* Scan devices looking for input and output devices */ list_for_each(pos, list) { @@ -987,23 +1080,18 @@ int console_init_r(void) if (outputdev != NULL) { console_setfile(stdout, outputdev); console_setfile(stderr, outputdev); -#if CONFIG_IS_ENABLED(CONSOLE_MUX) - console_devices[stdout][0] = outputdev; - console_devices[stderr][0] = outputdev; -#endif + console_devices_set(stdout, outputdev); + console_devices_set(stderr, outputdev); } /* Initializes input console */ if (inputdev != NULL) { console_setfile(stdin, inputdev); -#if CONFIG_IS_ENABLED(CONSOLE_MUX) - console_devices[stdin][0] = inputdev; -#endif + console_devices_set(stdin, inputdev); } -#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET - stdio_print_current_devices(); -#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */ + if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET)) + stdio_print_current_devices(); /* Setting environment variables */ for (i = 0; i < MAX_FILES; i++) { @@ -1012,11 +1100,6 @@ int console_init_r(void) gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */ -#if 0 - /* If nothing usable installed, use only the initial console */ - if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL)) - return 0; -#endif print_pre_console_buffer(flushpoint); return 0; } diff --git a/common/exports.c b/common/exports.c index 6253b55694..4578f07021 100644 --- a/common/exports.c +++ b/common/exports.c @@ -25,8 +25,10 @@ unsigned long get_version(void) # define miiphy_set_current_dev dummy #endif -void jumptable_init(void) +int jumptable_init(void) { gd->jt = malloc(sizeof(struct jt_funcs)); #include <_exports.h> + + return 0; } diff --git a/common/iomux.c b/common/iomux.c index 7cfd9f2e91..15bf533885 100644 --- a/common/iomux.c +++ b/common/iomux.c @@ -27,8 +27,8 @@ int iomux_doenv(const int console, const char *arg) { char *console_args, *temp, **start; int i, j, k, io_flag, cs_idx, repeat; + struct stdio_dev **cons_set, **old_set; struct stdio_dev *dev; - struct stdio_dev **cons_set; console_args = strdup(arg); if (console_args == NULL) @@ -45,15 +45,14 @@ int iomux_doenv(const int console, const char *arg) i = 0; temp = console_args; for (;;) { - temp = strchr(temp, ','); - if (temp != NULL) { - i++; - temp++; - continue; - } /* There's always one entry more than the number of commas. */ i++; - break; + + temp = strchr(temp, ','); + if (temp == NULL) + break; + + temp++; } start = (char **)malloc(i * sizeof(char *)); if (start == NULL) { @@ -95,10 +94,10 @@ int iomux_doenv(const int console, const char *arg) for (j = 0; j < i; j++) { /* * Check whether the device exists and is valid. - * console_assign() also calls search_device(), + * console_assign() also calls console_search_dev(), * but I need the pointer to the device. */ - dev = search_device(io_flag, start[j]); + dev = console_search_dev(io_flag, start[j]); if (dev == NULL) continue; /* @@ -127,21 +126,25 @@ int iomux_doenv(const int console, const char *arg) if (cs_idx == 0) { free(cons_set); return 1; - } else { - /* Works even if console_devices[console] is NULL. */ - console_devices[console] = - (struct stdio_dev **)realloc(console_devices[console], - cs_idx * sizeof(struct stdio_dev *)); - if (console_devices[console] == NULL) { - free(cons_set); - return 1; - } - memcpy(console_devices[console], cons_set, cs_idx * - sizeof(struct stdio_dev *)); + } + + old_set = console_devices[console]; + repeat = cd_count[console]; - cd_count[console] = cs_idx; + console_devices[console] = cons_set; + cd_count[console] = cs_idx; + + /* Stop dropped consoles */ + for (i = 0; i < repeat; i++) { + for (j = 0; j < cs_idx; j++) { + if (old_set[i] == cons_set[j]) + break; + } + if (j == cs_idx) + console_stop(console, old_set[i]); } - free(cons_set); + + free(old_set); return 0; } #endif /* CONSOLE_MUX */ diff --git a/common/log.c b/common/log.c index ce39918e04..767f0febc5 100644 --- a/common/log.c +++ b/common/log.c @@ -198,9 +198,10 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec) * @rec: log record to dispatch * Return: 0 msg sent, 1 msg not sent while already dispatching another msg */ -static int log_dispatch(struct log_rec *rec) +static int log_dispatch(struct log_rec *rec, const char *fmt, va_list args) { struct log_device *ldev; + char buf[CONFIG_SYS_CBSIZE]; /* * When a log driver writes messages (e.g. via the network stack) this @@ -214,8 +215,13 @@ static int log_dispatch(struct log_rec *rec) gd->processing_msg = true; list_for_each_entry(ldev, &gd->log_head, sibling_node) { if ((ldev->flags & LOGDF_ENABLE) && - log_passes_filters(ldev, rec)) + log_passes_filters(ldev, rec)) { + if (!rec->msg) { + vsnprintf(buf, sizeof(buf), fmt, args); + rec->msg = buf; + } ldev->drv->emit(ldev, rec); + } } gd->processing_msg = false; return 0; @@ -224,10 +230,12 @@ static int log_dispatch(struct log_rec *rec) int _log(enum log_category_t cat, enum log_level_t level, const char *file, int line, const char *func, const char *fmt, ...) { - char buf[CONFIG_SYS_CBSIZE]; struct log_rec rec; va_list args; + if (!gd) + return -ENOSYS; + /* Check for message continuation */ if (cat == LOGC_CONT) cat = gd->logc_prev; @@ -240,19 +248,29 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, rec.file = file; rec.line = line; rec.func = func; - va_start(args, fmt); - vsnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - rec.msg = buf; - if (!gd || !(gd->flags & GD_FLG_LOG_READY)) { - if (gd) - gd->log_drop_count++; + rec.msg = NULL; + + if (!(gd->flags & GD_FLG_LOG_READY)) { + gd->log_drop_count++; + + /* display dropped traces with console puts and DEBUG_UART */ + if (rec.level <= CONFIG_LOG_DEFAULT_LEVEL || rec.force_debug) { + char buf[CONFIG_SYS_CBSIZE]; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + puts(buf); + va_end(args); + } + return -ENOSYS; } - if (!log_dispatch(&rec)) { + va_start(args, fmt); + if (!log_dispatch(&rec, fmt, args)) { gd->logc_prev = cat; gd->logl_prev = level; } + va_end(args); return 0; } diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 6b0186763b..7561335bfd 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -126,7 +126,7 @@ endmenu config HANDOFF bool "Pass hand-off information from SPL to U-Boot proper" - depends on BLOBLIST + depends on SPL && BLOBLIST help It is useful to be able to pass information from SPL to U-Boot proper to preserve state that is known in SPL and is needed in U-Boot. diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 795e2922ce..a6ad094e91 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -684,8 +684,11 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, ret = spl_load_fit_image(info, sector, fit, base_offset, node, &image_info); - if (ret < 0) - continue; + if (ret < 0) { + printf("%s: can't load image loadables index %d (ret = %d)\n", + __func__, index, ret); + return ret; + } if (!spl_fit_image_get_os(fit, node, &os_type)) debug("Loadable is %s\n", genimg_get_os_name(os_type)); diff --git a/common/stdio.c b/common/stdio.c index a15f30804b..abf9b1e915 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -181,7 +181,7 @@ struct stdio_dev *stdio_get_by_name(const char *name) * 'stdout', which may include a list of devices separate by * commas. Obviously this is not going to work, so we ignore * that case. The call path in that case is - * console_init_r() -> search_device() -> stdio_get_by_name() + * console_init_r() -> console_search_dev() -> stdio_get_by_name() */ if (!strncmp(name, "vidconsole", 10) && !strchr(name, ',') && !stdio_probe_device(name, UCLASS_VIDEO, &sdev)) @@ -332,7 +332,7 @@ int stdio_add_devices(void) /* * If the console setting is not in environment variables then * console_init_r() will not be calling iomux_doenv() (which - * calls search_device()). So we will not dynamically add + * calls console_search_dev()). So we will not dynamically add * devices by calling stdio_probe_device(). * * So just probe all video devices now so that whichever one is |