diff options
Diffstat (limited to 'common')
| -rw-r--r-- | common/Kconfig | 8 | ||||
| -rw-r--r-- | common/bloblist.c | 142 | ||||
| -rw-r--r-- | common/board_f.c | 82 | ||||
| -rw-r--r-- | common/cli.c | 4 | ||||
| -rw-r--r-- | common/command.c | 14 | ||||
| -rw-r--r-- | common/cyclic.c | 10 | ||||
| -rw-r--r-- | common/init/handoff.c | 10 | ||||
| -rw-r--r-- | common/spl/Kconfig | 40 | ||||
| -rw-r--r-- | common/spl/spl_fit.c | 98 | ||||
| -rw-r--r-- | common/spl/spl_imx_container.c | 13 | ||||
| -rw-r--r-- | common/splash_source.c | 7 | ||||
| -rw-r--r-- | common/stdio.c | 18 | ||||
| -rw-r--r-- | common/usb_onboard_hub.c | 14 |
13 files changed, 268 insertions, 192 deletions
diff --git a/common/Kconfig b/common/Kconfig index 8e8c733aa29..345be4b8ca1 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -78,7 +78,7 @@ config SYS_PBSIZE config DISABLE_CONSOLE bool "Add functionality to disable console completely" help - Disable console (in & out). + Disable console (in & out). config IDENT_STRING string "Board specific string to be added to uboot version string" @@ -884,9 +884,9 @@ config AVB_VERIFY help This option enables compilation of bootloader-dependent operations, used by Android Verified Boot 2.0 library (libavb). Includes: - * Helpers to process strings in order to build OS bootargs. - * Helpers to access MMC, similar to drivers/fastboot/fb_mmc.c. - * Helpers to alloc/init/free avb ops. + * Helpers to process strings in order to build OS bootargs. + * Helpers to access MMC, similar to drivers/fastboot/fb_mmc.c. + * Helpers to alloc/init/free avb ops. if AVB_VERIFY diff --git a/common/bloblist.c b/common/bloblist.c index d084be89958..846c8047f74 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -448,6 +448,7 @@ int bloblist_new(ulong addr, uint size, uint flags, uint align_log2) hdr->align_log2 = align_log2 ? align_log2 : BLOBLIST_BLOB_ALIGN_LOG2; hdr->chksum = 0; gd->bloblist = hdr; + gd->flags |= GD_FLG_BLOBLIST_HANDOFF; return 0; } @@ -475,6 +476,7 @@ int bloblist_check(ulong addr, uint size) return log_msg_ret("Bad checksum", -EIO); } gd->bloblist = hdr; + gd->flags |= GD_FLG_BLOBLIST_HANDOFF; return 0; } @@ -576,90 +578,88 @@ int __weak xferlist_from_boot_arg(ulong __always_unused *addr) return -ENOENT; } -int bloblist_init(void) +bool bloblist_exists(void) { - bool fixed = IS_ENABLED(CONFIG_BLOBLIST_FIXED); - int ret = 0; - ulong addr = 0, size; + int ret; + ulong addr = 0; /* Check if a valid transfer list passed in */ - if (!xferlist_from_boot_arg(&addr)) { - size = bloblist_get_total_size(); - } else { - /* - * If U-Boot is not in the first phase, an existing bloblist must - * be at a fixed address. - */ - bool from_addr = fixed && !xpl_is_first_phase(); - - /* - * If Firmware Handoff is mandatory but no transfer list is - * observed, report it as an error. - */ - if (IS_ENABLED(CONFIG_BLOBLIST_PASSAGE_MANDATORY)) - return -ENOENT; - - ret = -ENOENT; + if (!xferlist_from_boot_arg(&addr)) + goto found; - if (xpl_prev_phase() == PHASE_TPL && - !IS_ENABLED(CONFIG_TPL_BLOBLIST)) - from_addr = false; - if (fixed) - addr = IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED, - CONFIG_BLOBLIST_ADDR); - size = CONFIG_BLOBLIST_SIZE; - - if (from_addr) - ret = bloblist_check(addr, size); - - if (ret) - log_warning("Bloblist at %lx not found (err=%d)\n", - addr, ret); - else - /* Get the real size */ - size = gd->bloblist->total_size; - } + /* + * If Firmware Handoff is mandatory but no transfer list is + * observed, report it as an error. + */ + if (IS_ENABLED(CONFIG_BLOBLIST_PASSAGE_MANDATORY)) + return false; - if (ret) { - /* - * If we don't have a bloblist from a fixed address, or the one - * in the fixed address is not valid. we must allocate the - * memory for it now. - */ - if (CONFIG_IS_ENABLED(BLOBLIST_ALLOC)) { - void *ptr = memalign(BLOBLIST_ALIGN, size); + /* + * We have checked for a valid transfer list being passed. At this + * point, if we do not have a fixed address for the bloblist, we cannot + * be provided with one. + */ + if (xpl_is_first_phase() || !IS_ENABLED(CONFIG_BLOBLIST_FIXED)) + return false; - if (!ptr) - return log_msg_ret("alloc", -ENOMEM); - addr = map_to_sysmem(ptr); - } else if (!fixed) { - return log_msg_ret("BLOBLIST_FIXED is not enabled", - ret); - } - log_debug("Creating new bloblist size %lx at %lx\n", size, - addr); - ret = bloblist_new(addr, size, 0, 0); - } else { - log_debug("Found existing bloblist size %lx at %lx\n", size, - addr); - } + /* + * Check for a valid list as the configured address. + */ + addr = IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED, + CONFIG_BLOBLIST_ADDR); + ret = bloblist_check(addr, CONFIG_BLOBLIST_SIZE); + if (!ret) + goto found; - if (ret) - return log_msg_ret("ini", ret); - gd->flags |= GD_FLG_BLOBLIST_READY; + log_debug("Bloblist at %lx not found (err=%d)\n", addr, ret); + return false; +found: #ifdef DEBUG bloblist_show_stats(); bloblist_show_list(); #endif - - return 0; + return true; } -int bloblist_maybe_init(void) +int bloblist_init(void) { - if (CONFIG_IS_ENABLED(BLOBLIST) && !(gd->flags & GD_FLG_BLOBLIST_READY)) - return bloblist_init(); + int ret; + ulong addr = 0, size = CONFIG_BLOBLIST_SIZE; + + if (gd->flags & GD_FLG_BLOBLIST_HANDOFF) { + log_debug("Found existing bloblist size %x at %p\n", + gd->bloblist->total_size, gd->bloblist); + return 0; + } + + /* + * If Firmware Handoff is mandatory but no transfer list has been + * observed by fdtdec_setup, report it as an error. + */ + if (IS_ENABLED(CONFIG_BLOBLIST_PASSAGE_MANDATORY)) + return -ENOENT; + + /* + * If we don't have an existing bloblist, we either need + * to allocate one now, or initialize the fixed address + * space as a bloblist. + */ + if (CONFIG_IS_ENABLED(BLOBLIST_ALLOC)) { + void *ptr = memalign(BLOBLIST_ALIGN, size); + + if (!ptr) + return log_msg_ret("alloc", -ENOMEM); + addr = map_to_sysmem(ptr); + } else + addr = IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED, + CONFIG_BLOBLIST_ADDR); + + log_debug("Creating new bloblist size %lx at %lx\n", size, + addr); + ret = bloblist_new(addr, size, 0, 0); + if (ret) + return log_msg_ret("ini", ret); return 0; } @@ -687,7 +687,9 @@ int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig, ulong xlist) return ret; if (rfdt != (ulong)bloblist_find(BLOBLISTT_CONTROL_FDT, 0)) { - gd->bloblist = NULL; /* Reset the gd bloblist pointer */ + /* Remove this bloblist from gd */ + gd->bloblist = NULL; + gd->flags &= ~GD_FLG_BLOBLIST_HANDOFF; return -EIO; } diff --git a/common/board_f.c b/common/board_f.c index ce87c619e68..85b888d4bb8 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -31,6 +31,7 @@ #include <log.h> #include <malloc.h> #include <mapmem.h> +#include <memtop.h> #include <os.h> #include <post.h> #include <relocate.h> @@ -50,6 +51,7 @@ #include <dm/root.h> #include <linux/errno.h> #include <linux/log2.h> +#include <linux/sizes.h> DECLARE_GLOBAL_DATA_PTR; @@ -222,11 +224,11 @@ static int show_dram_config(void) debug("\nRAM Configuration:\n"); for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) { - size += gd->bd->bi_dram[i].size; + size += gd->dram[i].size; debug("Bank #%d: %llx ", i, - (unsigned long long)(gd->bd->bi_dram[i].start)); + (unsigned long long)(gd->dram[i].start)); #ifdef DEBUG - print_size(gd->bd->bi_dram[i].size, "\n"); + print_size(gd->dram[i].size, "\n"); #endif } debug("\nDRAM: "); @@ -244,8 +246,8 @@ static int show_dram_config(void) __weak int dram_init_banksize(void) { - gd->bd->bi_dram[0].start = gd->ram_base; - gd->bd->bi_dram[0].size = get_effective_memsize(); + gd->dram[0].start = gd->ram_base; + gd->dram[0].size = get_effective_memsize(); return 0; } @@ -308,6 +310,9 @@ __weak int mach_cpu_init(void) /* Get the top of usable RAM */ __weak phys_addr_t board_get_usable_ram_top(phys_size_t total_size) { + if (CONFIG_IS_ENABLED(RELOC_ADDR_TOP)) + return gd->ram_top; + #if defined(CFG_SYS_SDRAM_BASE) && CFG_SYS_SDRAM_BASE > 0 /* * Detect whether we have so much RAM that it goes past the end of our @@ -328,14 +333,34 @@ __weak int arch_setup_dest_addr(void) return 0; } -static int setup_dest_addr(void) +static int setup_ram_base(void) +{ +#ifdef CFG_SYS_SDRAM_BASE + gd->ram_base = CFG_SYS_SDRAM_BASE; +#endif + return 0; +} + +static int setup_ram_config(void) { debug("Monitor len: %08x\n", gd->mon_len); - /* - * Ram is setup, size stored in gd !! - */ - debug("Ram size: %08llX\n", (unsigned long long)gd->ram_size); -#if CONFIG_VAL(SYS_MEM_TOP_HIDE) + + if (CONFIG_IS_ENABLED(RELOC_ADDR_TOP)) { + int i; + phys_addr_t top; + + gd->ram_size = 0; + for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { + top = get_mem_top(gd->dram[i].start, gd->dram[i].size, + ALIGN(gd->mon_len, SZ_1M), + (void *)gd->fdt_blob); + gd->ram_top = max(top, gd->ram_top); + gd->ram_size += gd->dram[i].size; + } + } else { + gd->ram_top = gd->ram_base + get_effective_memsize(); + } + gd->ram_top = board_get_usable_ram_top(gd->mon_len); /* * Subtract specified amount of memory to hide so that it won't * get "touched" at all by U-Boot. By fixing up gd->ram_size @@ -346,17 +371,30 @@ static int setup_dest_addr(void) * memory size from the SDRAM controller setup will have to * get fixed. */ +#if CONFIG_VAL(SYS_MEM_TOP_HIDE) + gd->ram_top -= CONFIG_SYS_MEM_TOP_HIDE; gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE; #endif -#ifdef CFG_SYS_SDRAM_BASE - gd->ram_base = CFG_SYS_SDRAM_BASE; -#endif - gd->ram_top = gd->ram_base + get_effective_memsize(); - gd->ram_top = board_get_usable_ram_top(gd->mon_len); + + debug("Ram top: %08llx\n", (unsigned long long)gd->ram_top); + debug("Ram size: %08llx\n", (unsigned long long)gd->ram_size); + + return 0; +} + +static int setup_dest_addr(void) +{ + int ret; + gd->relocaddr = gd->ram_top; - debug("Ram top: %08llX\n", (unsigned long long)gd->ram_top); + debug("Reloc addr: %08llX\n", (unsigned long long)gd->relocaddr); + + ret = arch_setup_dest_addr(); + if (ret) + return ret; - return arch_setup_dest_addr(); + gd->initial_relocaddr = gd->relocaddr; + return 0; } #ifdef CFG_PRAM @@ -894,7 +932,9 @@ static void initcall_run_f(void) INITCALL(log_init); INITCALL(initf_bootstage); /* uses its own timer, so does not need DM */ INITCALL(event_init); - INITCALL(bloblist_maybe_init); +#if CONFIG_IS_ENABLED(BLOBLIST) + INITCALL(bloblist_init); +#endif INITCALL(setup_spl_handoff); #if CONFIG_IS_ENABLED(CONSOLE_RECORD_INIT_F) INITCALL(console_record_init); @@ -968,6 +1008,9 @@ static void initcall_run_f(void) * - monitor code * - board info struct */ + INITCALL(setup_ram_base); + INITCALL(dram_init_banksize); + INITCALL(setup_ram_config); INITCALL(setup_dest_addr); #if CONFIG_IS_ENABLED(OF_BOARD_FIXUP) && \ !CONFIG_IS_ENABLED(OF_INITIAL_DTB_READONLY) @@ -995,7 +1038,6 @@ static void initcall_run_f(void) INITCALL(reserve_bloblist); INITCALL(reserve_arch); INITCALL(reserve_stacks); - INITCALL(dram_init_banksize); INITCALL(show_dram_config); WATCHDOG_RESET(); INITCALL(setup_bdinfo); diff --git a/common/cli.c b/common/cli.c index bcc7264d51a..87ce0e4d144 100644 --- a/common/cli.c +++ b/common/cli.c @@ -138,11 +138,9 @@ int run_command_list(const char *cmd, int len, int flag) #endif } if (need_buff) { - buff = malloc(len + 1); + buff = memdup_nul(cmd, len); if (!buff) return 1; - memcpy(buff, cmd, len); - buff[len] = '\0'; } #ifdef CONFIG_HUSH_PARSER if (use_hush_old()) { diff --git a/common/command.c b/common/command.c index 0f9dd06d72b..eb2c2123534 100644 --- a/common/command.c +++ b/common/command.c @@ -367,11 +367,15 @@ int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp) int i, j, k, len, seplen, argc; int cnt; char last_char; -#ifdef CONFIG_CMDLINE_PS_SUPPORT - const char *ps_prompt = env_get("PS1"); -#else - const char *ps_prompt = CONFIG_SYS_PROMPT; -#endif + const char *ps_prompt; + + if (IS_ENABLED(CONFIG_CMDLINE_PS_SUPPORT)) { + ps_prompt = env_get("PS1"); + + if (!ps_prompt) + ps_prompt = CONFIG_SYS_PROMPT; + } else + ps_prompt = CONFIG_SYS_PROMPT; if (strcmp(prompt, ps_prompt) != 0) return 0; /* not in normal console */ diff --git a/common/cyclic.c b/common/cyclic.c index ec952a01ee1..573e715587d 100644 --- a/common/cyclic.c +++ b/common/cyclic.c @@ -41,7 +41,7 @@ static bool cyclic_is_registered(const struct cyclic_info *cyclic) } void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func, - uint64_t delay_us, const char *name) + u64 delay_us, const char *name) { cyclic_unregister(cyclic); @@ -67,26 +67,28 @@ static void cyclic_run(void) { struct cyclic_info *cyclic; struct hlist_node *tmp; - uint64_t now, cpu_time; + u64 now, after, cpu_time; /* Prevent recursion */ if (gd->flags & GD_FLG_CYCLIC_RUNNING) return; gd->flags |= GD_FLG_CYCLIC_RUNNING; + now = get_timer_us(0); hlist_for_each_entry_safe(cyclic, tmp, cyclic_get_list(), list) { /* * Check if this cyclic function needs to get called, e.g. * do not call the cyclic func too often */ - now = get_timer_us(0); if (time_after_eq64(now, cyclic->next_call)) { /* Call cyclic function and account it's cpu-time */ cyclic->next_call = now + cyclic->delay_us; cyclic->func(cyclic); + after = get_timer_us(0); cyclic->run_cnt++; - cpu_time = get_timer_us(0) - now; + cpu_time = after - now; cyclic->cpu_time_us += cpu_time; + now = after; /* Check if cpu-time exceeds max allowed time */ if ((cpu_time > CONFIG_CYCLIC_MAX_CPU_TIME_US) && diff --git a/common/init/handoff.c b/common/init/handoff.c index a7cd065fb38..a4d9d14393b 100644 --- a/common/init/handoff.c +++ b/common/init/handoff.c @@ -12,14 +12,13 @@ DECLARE_GLOBAL_DATA_PTR; void handoff_save_dram(struct spl_handoff *ho) { - struct bd_info *bd = gd->bd; int i; ho->ram_size = gd->ram_size; for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { - ho->ram_bank[i].start = bd->bi_dram[i].start; - ho->ram_bank[i].size = bd->bi_dram[i].size; + ho->ram_bank[i].start = gd->dram[i].start; + ho->ram_bank[i].size = gd->dram[i].size; } } @@ -30,11 +29,10 @@ void handoff_load_dram_size(struct spl_handoff *ho) void handoff_load_dram_banks(struct spl_handoff *ho) { - struct bd_info *bd = gd->bd; int i; for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { - bd->bi_dram[i].start = ho->ram_bank[i].start; - bd->bi_dram[i].size = ho->ram_bank[i].size; + gd->dram[i].start = ho->ram_bank[i].start; + gd->dram[i].size = ho->ram_bank[i].size; } } diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 5fa94098e49..0618f42c941 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -220,7 +220,7 @@ source "common/spl/Kconfig.nxp" config HANDOFF bool "Pass hand-off information from SPL to U-Boot proper" - depends on BLOBLIST + depends on BLOBLIST_FIXED 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. @@ -541,7 +541,7 @@ config SPL_SYS_MMCSD_RAW_MODE ARCH_MX6 || ARCH_MX7 || \ ARCH_ROCKCHIP || ARCH_MVEBU || ARCH_SOCFPGA_GEN5 || \ ARCH_AT91 || ARCH_ZYNQ || ARCH_KEYSTONE || OMAP34XX || \ - OMAP54XX || AM33XX || AM43XX || \ + OMAP44XX || OMAP54XX || AM33XX || AM43XX || \ TARGET_SIFIVE_UNLEASHED || TARGET_SIFIVE_UNMATCHED help Support booting from an MMC without a filesystem. @@ -585,7 +585,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR default 0x100 if ARCH_UNIPHIER default 0x0 if ARCH_MVEBU default 0x200 if ARCH_SOCFPGA_GEN5 || ARCH_AT91 - default 0x300 if ARCH_ZYNQ || ARCH_KEYSTONE || OMAP34XX || \ + default 0x300 if ARCH_ZYNQ || ARCH_KEYSTONE || OMAP34XX || OMAP44XX || \ OMAP54XX || AM33XX || AM43XX || ARCH_K3 default 0x4000 if ARCH_ROCKCHIP default 0x822 if TARGET_SIFIVE_UNLEASHED || TARGET_SIFIVE_UNMATCHED @@ -1321,10 +1321,10 @@ config SPL_PCI config SPL_PCI_ENDPOINT bool "Support for PCI endpoint drivers" help - Enable this configuration option to support configurable PCI - endpoints at SPL. This should be enabled if the platform has - a PCI controllers that can operate in endpoint mode (as a device - connected to PCI host or bridge). + Enable this configuration option to support configurable PCI + endpoints at SPL. This should be enabled if the platform has + a PCI controllers that can operate in endpoint mode (as a device + connected to PCI host or bridge). config SPL_PCH bool "Support PCH drivers" @@ -1552,18 +1552,18 @@ config SPL_SPI_FLASH_TINY depends on !SPI_FLASH_BAR default y if SPI_FLASH help - Enable lightweight SPL SPI Flash support that supports just reading - data/images from flash. No support to write/erase flash. Enable - this if you have SPL size limitations and don't need full - fledged SPI flash support. + Enable lightweight SPL SPI Flash support that supports just reading + data/images from flash. No support to write/erase flash. Enable + this if you have SPL size limitations and don't need full + fledged SPI flash support. config SPL_SPI_FLASH_SFDP_SUPPORT bool "SFDP table parsing support for SPI NOR flashes" depends on !SPI_FLASH_BAR && !SPL_SPI_FLASH_TINY help - Enable support for parsing and auto discovery of parameters for - SPI NOR flashes using Serial Flash Discoverable Parameters (SFDP) - tables as per JESD216 standard in SPL. + Enable support for parsing and auto discovery of parameters for + SPI NOR flashes using Serial Flash Discoverable Parameters (SFDP) + tables as per JESD216 standard in SPL. config SPL_SPI_FLASH_MTD bool "Support for SPI flash MTD drivers in SPL" @@ -1584,22 +1584,22 @@ config SYS_SPI_U_BOOT_OFFS default 0x0 depends on SPL_SPI_LOAD || SPL_SPI_SUNXI help - Address within SPI-Flash from where the u-boot payload is fetched - from. + Address within SPI-Flash from where the u-boot payload is fetched + from. config SYS_SPI_KERNEL_OFFS hex "Falcon mode: address of kernel payload in SPI flash" depends on SPL_SPI_FLASH_SUPPORT && SPL_OS_BOOT help - Address within SPI-Flash from where the kernel payload is fetched - in falcon boot. + Address within SPI-Flash from where the kernel payload is fetched + in falcon boot. config SYS_SPI_ARGS_OFFS hex "Falcon mode: address of args payload in SPI flash" depends on SPL_SPI_FLASH_SUPPORT && SPL_OS_BOOT_ARGS help - Address within SPI-Flash from where the args payload (usually the - dtb) is fetched in falcon boot. + Address within SPI-Flash from where the args payload (usually the + dtb) is fetched in falcon boot. config SYS_SPI_ARGS_SIZE hex "Falcon mode: size of args payload in SPI flash" diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 46ebcabe56a..18bff7b8d4a 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -204,6 +204,9 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size, * If the FIT node does not contain a "load" (address) property, * the image gets loaded to the address pointed to by the * load_addr member in this struct, if load_addr is not 0 + * @max_size: maximum number of bytes that may be written to the + * destination; an image whose data exceeds this is rejected + * before it is read from the device * * Return: 0 on success, -EBADSLT if this image is not the correct phase * (for CONFIG_BOOTMETH_VBE_SIMPLE_FW), or another negative error number on @@ -211,7 +214,7 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size, */ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, const struct spl_fit_info *ctx, int node, - struct spl_image_info *image_info) + struct spl_image_info *image_info, ulong max_size) { int offset; size_t length; @@ -291,6 +294,23 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, return 0; } + /* + * data-size is excluded from the configuration signature (it + * is in exc_prop[] in image-fit-sig.c), so it stays attacker + * controlled even after fit_config_verify() succeeds. The + * image hash is only verified after the device read below, so + * an oversized value has to be rejected here. + * + * Bail out before get_aligned_image_size() runs on a hostile + * len: that helper does its arithmetic in int and would + * invoke signed-integer overflow on a value close to or above + * INT_MAX. The block-aligned check further down is the + * mathematically binding one, since size is len rounded up to + * the device block length. + */ + if ((ulong)len > max_size) + goto too_big; + if (spl_decompression_enabled() && (image_comp == IH_COMP_GZIP || image_comp == IH_COMP_LZMA)) src_ptr = map_sysmem(ALIGN(CONFIG_SYS_LOAD_ADDR, ARCH_DMA_MINALIGN), len); @@ -302,6 +322,15 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, size = get_aligned_image_size(info, length, offset); read_offset = fit_offset + get_aligned_image_offset(info, offset); + + /* + * info->read() transfers the block-aligned size into the + * destination, so this is the bound that actually matters; + * len was rejected above only to keep this computation safe. + */ + if (size > max_size) + goto too_big; + log_debug("reading from offset %x / %lx size %lx to %p: ", offset, read_offset, size, src_ptr); @@ -372,6 +401,11 @@ static int load_simple_fit(struct spl_load_info *info, ulong fit_offset, upl_add_image(fit, node, load_addr, length); return 0; + +too_big: + printf("%s: FIT image too large (data-size %u, max %lu)\n", + __func__, (u32)len, max_size); + return -EFBIG; } static bool os_takes_devicetree(uint8_t os) @@ -427,7 +461,8 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image, spl_image->fdt_addr = map_sysmem(image_info.load_addr, size); memcpy(spl_image->fdt_addr, gd->fdt_blob, size); } else { - ret = load_simple_fit(info, offset, ctx, node, &image_info); + ret = load_simple_fit(info, offset, ctx, node, &image_info, + CONFIG_SYS_BOOTM_LEN); if (ret < 0) return ret; @@ -479,7 +514,8 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image, } image_info.load_addr = (ulong)tmpbuffer; ret = load_simple_fit(info, offset, ctx, node, - &image_info); + &image_info, + CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY_BUF_SZ); if (ret == -EBADSLT) continue; else if (ret < 0) @@ -687,7 +723,8 @@ static int spl_fit_load_fpga(struct spl_fit_info *ctx, warn_deprecated("'fpga' property in config node. Use 'loadables'"); /* Load the image and set up the fpga_image structure */ - ret = load_simple_fit(info, offset, ctx, node, &fpga_image); + ret = load_simple_fit(info, offset, ctx, node, &fpga_image, + CONFIG_SYS_BOOTM_LEN); if (ret) { printf("%s: Cannot load the FPGA: %i\n", __func__, ret); return ret; @@ -775,7 +812,7 @@ static int spl_simple_fit_parse(struct spl_fit_info *ctx) if (ctx->conf_node < 0) return -EINVAL; - if (IS_ENABLED(CONFIG_SPL_FIT_SIGNATURE)) { + if (CONFIG_IS_ENABLED(FIT_SIGNATURE)) { printf("## Checking hash(es) for config %s ... ", fit_get_name(ctx->fit, ctx->conf_node, NULL)); if (fit_config_verify(ctx->fit, ctx->conf_node)) @@ -849,7 +886,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, } /* Load the image and set up the spl_image structure */ - ret = load_simple_fit(info, offset, &ctx, node, spl_image); + ret = load_simple_fit(info, offset, &ctx, node, spl_image, + CONFIG_SYS_BOOTM_LEN); if (ret) return ret; @@ -890,7 +928,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, continue; image_info.load_addr = 0; - ret = load_simple_fit(info, offset, &ctx, node, &image_info); + ret = load_simple_fit(info, offset, &ctx, node, &image_info, + CONFIG_SYS_BOOTM_LEN); if (ret < 0 && ret != -EBADSLT) { printf("%s: can't load image loadables index %d (ret = %d)\n", __func__, index, ret); @@ -955,22 +994,12 @@ int spl_load_fit_image(struct spl_image_info *spl_image, int idx, conf_noffset; int ret; -#ifdef CONFIG_SPL_FIT_SIGNATURE - images.verify = 1; -#endif + images.verify = CONFIG_IS_ENABLED(FIT_SIGNATURE); + ret = fit_image_load(&images, virt_to_phys((void *)header), - NULL, &fit_uname_config, - IH_ARCH_DEFAULT, IH_TYPE_STANDALONE, -1, - FIT_LOAD_OPTIONAL, &fw_data, &fw_len); - if (ret >= 0) { - printf("DEPRECATED: 'standalone = ' property."); - printf("Please use either 'firmware =' or 'kernel ='\n"); - } else { - ret = fit_image_load(&images, virt_to_phys((void *)header), - NULL, &fit_uname_config, IH_ARCH_DEFAULT, - IH_TYPE_FIRMWARE, -1, FIT_LOAD_OPTIONAL, - &fw_data, &fw_len); - } + NULL, &fit_uname_config, IH_ARCH_DEFAULT, + IH_TYPE_FIRMWARE, -1, FIT_LOAD_OPTIONAL, + &fw_data, &fw_len); if (ret < 0) { ret = fit_image_load(&images, virt_to_phys((void *)header), @@ -993,21 +1022,21 @@ int spl_load_fit_image(struct spl_image_info *spl_image, debug(PHASE_PROMPT "payload image: %32s load addr: 0x%lx size: %d\n", spl_image->name, spl_image->load_addr, spl_image->size); -#ifdef CONFIG_SPL_FIT_SIGNATURE - images.verify = 1; -#endif + images.verify = CONFIG_IS_ENABLED(FIT_SIGNATURE); + ret = fit_image_load(&images, virt_to_phys((void *)header), NULL, &fit_uname_config, IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1, FIT_LOAD_OPTIONAL, &dt_data, &dt_len); if (ret >= 0) { - spl_image->fdt_addr = (void *)dt_data; - if (spl_image->os == IH_OS_U_BOOT) { /* HACK: U-Boot expects FDT at a specific address */ - fdt_hack = spl_image->load_addr + spl_image->size; - fdt_hack = (fdt_hack + 3) & ~3; - debug("Relocating FDT to %p\n", spl_image->fdt_addr); - memcpy((void *)fdt_hack, spl_image->fdt_addr, dt_len); + fdt_hack = ALIGN(spl_image->load_addr + spl_image->size, 8); + debug("Relocating FDT to %p\n", (void *)fdt_hack); + memcpy(map_sysmem(fdt_hack, dt_len), + map_sysmem(dt_data, 0), dt_len); + spl_image->fdt_addr = (void *)fdt_hack; + } else { + spl_image->fdt_addr = (void *)dt_data; } } @@ -1021,10 +1050,9 @@ int spl_load_fit_image(struct spl_image_info *spl_image, FIT_LOADABLE_PROP, idx, NULL), uname; idx++) { -#ifdef CONFIG_SPL_FIT_SIGNATURE - images.verify = 1; -#endif - ret = fit_image_load(&images, (ulong)header, + images.verify = CONFIG_IS_ENABLED(FIT_SIGNATURE); + + ret = fit_image_load(&images, virt_to_phys((void *)header), &uname, &fit_uname_config, IH_ARCH_DEFAULT, IH_TYPE_LOADABLE, -1, FIT_LOAD_OPTIONAL_NON_ZERO, diff --git a/common/spl/spl_imx_container.c b/common/spl/spl_imx_container.c index 79d021f81dc..57cd75b9b5e 100644 --- a/common/spl/spl_imx_container.c +++ b/common/spl/spl_imx_container.c @@ -88,6 +88,7 @@ static int read_auth_container(struct spl_image_info *spl_image, struct spl_load_info *info, ulong offset) { struct container_hdr *container = NULL; + struct container_hdr *authhdr; u16 length; int i, size, ret = 0; @@ -140,15 +141,19 @@ static int read_auth_container(struct spl_image_info *spl_image, } } + authhdr = container; + #ifdef CONFIG_AHAB_BOOT - ret = ahab_auth_cntr_hdr(container, length); - if (ret) + authhdr = ahab_auth_cntr_hdr(authhdr, length); + if (!authhdr) { + ret = -EINVAL; goto end_auth; + } #endif - for (i = 0; i < container->num_images; i++) { + for (i = 0; i < authhdr->num_images; i++) { struct boot_img_t *image = read_auth_image(spl_image, info, - container, i, + authhdr, i, offset); if (!image) { diff --git a/common/splash_source.c b/common/splash_source.c index 0710e302ba1..e02f9be05e4 100644 --- a/common/splash_source.c +++ b/common/splash_source.c @@ -159,12 +159,12 @@ static int splash_select_fs_dev(struct splash_location *location) res = -ENODEV; break; default: - printf("Error: unsupported location storage.\n"); + printf("Error: %s: unsupported location storage.\n", __func__); return -ENODEV; } if (res) - printf("Error: could not access storage.\n"); + printf("Error: %s: could not access storage.\n", __func__); return res; } @@ -284,7 +284,8 @@ static int splash_load_fs(struct splash_location *location, ulong bmp_load_addr) res = fs_size(splash_file, &bmp_size); if (res) { - printf("Error (%d): cannot determine file size\n", res); + printf("Error: %s: cannot determine file size (%d)\n", + __func__, res); goto out; } diff --git a/common/stdio.c b/common/stdio.c index fc965944209..038e576147b 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -217,27 +217,11 @@ struct stdio_dev *stdio_get_by_name(const char *name) return NULL; } -struct stdio_dev *stdio_clone(struct stdio_dev *dev) -{ - struct stdio_dev *_dev; - - if (!dev) - return NULL; - - _dev = calloc(1, sizeof(struct stdio_dev)); - if (!_dev) - return NULL; - - memcpy(_dev, dev, sizeof(struct stdio_dev)); - - return _dev; -} - int stdio_register_dev(struct stdio_dev *dev, struct stdio_dev **devp) { struct stdio_dev *_dev; - _dev = stdio_clone(dev); + _dev = memdup(dev, sizeof(*dev)); if (!_dev) return -ENODEV; list_add_tail(&_dev->list, &devs.list); diff --git a/common/usb_onboard_hub.c b/common/usb_onboard_hub.c index 6fc34489a98..0684f7bfd47 100644 --- a/common/usb_onboard_hub.c +++ b/common/usb_onboard_hub.c @@ -262,6 +262,12 @@ static int usb_onboard_hub_remove(struct udevice *dev) return ret; } +static const struct onboard_hub_data corechips_sl6341_data = { + .reset_us = 10000, + .num_supplies = 2, + .supply_names = { "vdd1v1-supply", "vdd3v3-supply" }, +}; + static const struct onboard_hub_data usb2514_data = { .power_on_delay_us = 500, .reset_us = 1, @@ -285,7 +291,13 @@ static const struct onboard_hub_data usbhx3_data = { static const struct udevice_id usb_onboard_hub_ids[] = { /* Use generic usbVID,PID dt-bindings (usb-device.yaml) */ - { .compatible = "usb424,2514", /* USB2514B USB 2.0 */ + { .compatible = "usb3431,6241", /* Corechips SL6341 USB 2.0 */ + .data = (ulong)&corechips_sl6341_data, + }, { + .compatible = "usb3431,6341", /* Corechips SL6341 USB 3.0 */ + .data = (ulong)&corechips_sl6341_data, + }, { + .compatible = "usb424,2514", /* USB2514B USB 2.0 */ .data = (ulong)&usb2514_data, }, { .compatible = "usb424,2744", /* USB2744 USB 2.0 */ |
