Merge branch 'next'

Signed-off-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
Tom Rini
2022-01-10 14:01:57 -05:00
1624 changed files with 25243 additions and 10873 deletions

View File

@@ -15,6 +15,16 @@ config SYS_NUM_ADDR_MAP
help
Sets the number of entries in the virtual-physical mapping table.
config PHYSMEM
bool "Access to physical memory region (> 4G)"
help
Some basic support is provided for operations on memory not
normally accessible to 32-bit U-Boot - e.g. some architectures
support access to more than 4G of memory on 32-bit
machines using physical address extension or similar.
Enable this to access this basic support, which only supports clearing
the memory.
config BCH
bool "Enable Software based BCH ECC"
help
@@ -42,7 +52,7 @@ config CC_OPTIMIZE_LIBS_FOR_SPEED
config CHARSET
bool
default y if UT_UNICODE || EFI_LOADER || UFS
default y if UT_UNICODE || EFI_LOADER || UFS || EFI_APP
help
Enables support for various conversions between different
character sets, such as between unicode representations and

View File

@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Functions shared by the app and stub
*
* Copyright (c) 2015 Google, Inc
*
* EFI information obtained here:
@@ -17,6 +19,33 @@
#include <efi.h>
#include <efi_api.h>
static struct efi_priv *global_priv;
struct efi_priv *efi_get_priv(void)
{
return global_priv;
}
void efi_set_priv(struct efi_priv *priv)
{
global_priv = priv;
}
struct efi_system_table *efi_get_sys_table(void)
{
return global_priv->sys_table;
}
struct efi_boot_services *efi_get_boot(void)
{
return global_priv->boot;
}
unsigned long efi_get_ram_base(void)
{
return global_priv->ram_base;
}
/*
* Global declaration of gd.
*

View File

@@ -21,31 +21,60 @@
#include <efi.h>
#include <efi_api.h>
#include <sysreset.h>
#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dm/root.h>
DECLARE_GLOBAL_DATA_PTR;
static struct efi_priv *global_priv;
struct efi_system_table *efi_get_sys_table(void)
{
return global_priv->sys_table;
}
struct efi_boot_services *efi_get_boot(void)
{
return global_priv->boot;
}
unsigned long efi_get_ram_base(void)
{
return global_priv->ram_base;
}
int efi_info_get(enum efi_entry_t type, void **datap, int *sizep)
{
return -ENOSYS;
}
/**
* efi_bind_block() - bind a new block device to an EFI device
*
* Binds a new top-level EFI_MEDIA device as well as a child block device so
* that the block device can be accessed in U-Boot.
*
* The device can then be accessed using 'part list efi 0', 'fat ls efi 0:1',
* for example, just like any other interface type.
*
* @handle: handle of the controller on which this driver is installed
* @blkio: block io protocol proxied by this driver
* @device_path: EFI device path structure for this
* @len: Length of @device_path in bytes
* @devp: Returns the bound device
* @return 0 if OK, -ve on error
*/
int efi_bind_block(efi_handle_t handle, struct efi_block_io *blkio,
struct efi_device_path *device_path, int len,
struct udevice **devp)
{
struct efi_media_plat plat;
struct udevice *dev;
char name[18];
int ret;
plat.handle = handle;
plat.blkio = blkio;
plat.device_path = malloc(device_path->length);
if (!plat.device_path)
return log_msg_ret("path", -ENOMEM);
memcpy(plat.device_path, device_path, device_path->length);
ret = device_bind(dm_root(), DM_DRIVER_GET(efi_media), "efi_media",
&plat, ofnode_null(), &dev);
if (ret)
return log_msg_ret("bind", ret);
snprintf(name, sizeof(name), "efi_media_%x", dev_seq(dev));
device_set_name(dev, name);
*devp = dev;
return 0;
}
static efi_status_t setup_memory(struct efi_priv *priv)
{
struct efi_boot_services *boot = priv->boot;
@@ -77,13 +106,14 @@ static efi_status_t setup_memory(struct efi_priv *priv)
ret = boot->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
priv->image_data_type, pages, &addr);
if (ret) {
printf("(using pool %lx) ", ret);
log_info("(using pool %lx) ", ret);
priv->ram_base = (ulong)efi_malloc(priv, CONFIG_EFI_RAM_SIZE,
&ret);
if (!priv->ram_base)
return ret;
priv->use_pool_for_malloc = true;
} else {
log_info("(using allocated RAM address %lx) ", (ulong)addr);
priv->ram_base = addr;
}
gd->ram_size = pages << 12;
@@ -91,6 +121,14 @@ static efi_status_t setup_memory(struct efi_priv *priv)
return 0;
}
/**
* free_memory() - Free memory used by the U-Boot app
*
* This frees memory allocated in setup_memory(), in preparation for returning
* to UEFI. It also zeroes the global_data pointer.
*
* @priv: Private EFI data
*/
static void free_memory(struct efi_priv *priv)
{
struct efi_boot_services *boot = priv->boot;
@@ -105,6 +143,150 @@ static void free_memory(struct efi_priv *priv)
global_data_ptr = NULL;
}
/**
* devpath_is_partition() - Figure out if a device path is a partition
*
* Checks if a device path refers to a partition on some media device. This
* works by checking for a valid partition number in a hard-driver media device
* as the final component of the device path.
*
* @path: device path
* Return: true if a partition, false if not
* (e.g. it might be media which contains partitions)
*/
static bool devpath_is_partition(const struct efi_device_path *path)
{
const struct efi_device_path *p;
bool was_part;
for (p = path; p->type != DEVICE_PATH_TYPE_END;
p = (void *)p + p->length) {
was_part = false;
if (p->type == DEVICE_PATH_TYPE_MEDIA_DEVICE &&
p->sub_type == DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH) {
struct efi_device_path_hard_drive_path *hd =
(void *)path;
if (hd->partition_number)
was_part = true;
}
}
return was_part;
}
/**
* setup_block() - Find all block devices and setup EFI devices for them
*
* Partitions are ignored, since U-Boot has partition handling. Errors with
* particular devices produce a warning but execution continues to try to
* find others.
*
* Return: 0 if found, -ENOSYS if there is no boot-services table, -ENOTSUPP
* if a required protocol is not supported
*/
static int setup_block(void)
{
efi_guid_t efi_blkio_guid = EFI_BLOCK_IO_PROTOCOL_GUID;
efi_guid_t efi_devpath_guid = EFI_DEVICE_PATH_PROTOCOL_GUID;
efi_guid_t efi_pathutil_guid = EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID;
efi_guid_t efi_pathtext_guid = EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;
struct efi_boot_services *boot = efi_get_boot();
struct efi_device_path_utilities_protocol *util;
struct efi_device_path_to_text_protocol *text;
struct efi_device_path *path;
struct efi_block_io *blkio;
efi_uintn_t num_handles;
efi_handle_t *handle;
int ret, i;
if (!boot)
return log_msg_ret("sys", -ENOSYS);
/* Find all devices which support the block I/O protocol */
ret = boot->locate_handle_buffer(BY_PROTOCOL, &efi_blkio_guid, NULL,
&num_handles, &handle);
if (ret)
return log_msg_ret("loc", -ENOTSUPP);
log_debug("Found %d handles:\n", (int)num_handles);
/* We need to look up the path size and convert it to text */
ret = boot->locate_protocol(&efi_pathutil_guid, NULL, (void **)&util);
if (ret)
return log_msg_ret("util", -ENOTSUPP);
ret = boot->locate_protocol(&efi_pathtext_guid, NULL, (void **)&text);
if (ret)
return log_msg_ret("text", -ENOTSUPP);
for (i = 0; i < num_handles; i++) {
struct udevice *dev;
const u16 *name;
bool is_part;
int len;
ret = boot->handle_protocol(handle[i], &efi_devpath_guid,
(void **)&path);
if (ret) {
log_warning("- devpath %d failed (ret=%d)\n", i, ret);
continue;
}
ret = boot->handle_protocol(handle[i], &efi_blkio_guid,
(void **)&blkio);
if (ret) {
log_warning("- blkio %d failed (ret=%d)\n", i, ret);
continue;
}
name = text->convert_device_path_to_text(path, true, false);
is_part = devpath_is_partition(path);
if (!is_part) {
len = util->get_device_path_size(path);
ret = efi_bind_block(handle[i], blkio, path, len, &dev);
if (ret) {
log_warning("- blkio bind %d failed (ret=%d)\n",
i, ret);
continue;
}
} else {
dev = NULL;
}
/*
* Show the device name if we created one. Otherwise indicate
* that it is a partition.
*/
printf("%2d: %-12s %ls\n", i, dev ? dev->name : "<partition>",
name);
}
boot->free_pool(handle);
return 0;
}
/**
* dm_scan_other() - Scan for UEFI devices that should be available to U-Boot
*
* This sets up block devices within U-Boot for those found in UEFI. With this,
* U-Boot can access those devices
*
* @pre_reloc_only: true to only bind pre-relocation devices (ignored)
* Returns: 0 on success, -ve on error
*/
int dm_scan_other(bool pre_reloc_only)
{
if (gd->flags & GD_FLG_RELOC) {
int ret;
ret = setup_block();
if (ret)
return ret;
}
return 0;
}
/**
* efi_main() - Start an EFI image
*
@@ -119,9 +301,12 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
efi_status_t ret;
/* Set up access to EFI data structures */
efi_init(priv, "App", image, sys_table);
global_priv = priv;
ret = efi_init(priv, "App", image, sys_table);
if (ret) {
printf("Failed to set up U-Boot: err=%lx\n", ret);
return ret;
}
efi_set_priv(priv);
/*
* Set up the EFI debug UART so that printf() works. This is
@@ -147,7 +332,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
static void efi_exit(void)
{
struct efi_priv *priv = global_priv;
struct efi_priv *priv = efi_get_priv();
free_memory(priv);
printf("U-Boot EFI exiting\n");

View File

@@ -31,7 +31,6 @@
#error "This file needs to be ported for use on architectures"
#endif
static struct efi_priv *global_priv;
static bool use_uart;
struct __packed desctab_info {
@@ -63,6 +62,8 @@ void _debug_uart_init(void)
void putc(const char ch)
{
struct efi_priv *priv = efi_get_priv();
if (ch == '\n')
putc('\r');
@@ -73,7 +74,7 @@ void putc(const char ch)
;
outb(ch, (ulong)&com_port->thr);
} else {
efi_putc(global_priv, ch);
efi_putc(priv, ch);
}
}
@@ -225,6 +226,22 @@ static int get_codeseg32(void)
return cs32;
}
/**
* setup_info_table() - sets up a table containing information from EFI
*
* We must call exit_boot_services() before jumping out of the stub into U-Boot
* proper, so that U-Boot has full control of peripherals, memory, etc.
*
* Once we do this, we cannot call any boot-services functions so we must find
* out everything we need to before doing that.
*
* Set up a struct efi_info_hdr table which can hold various records (e.g.
* struct efi_entry_memmap) with information obtained from EFI.
*
* @priv: Pointer to our private information which contains the list
* @size: Size of the table to allocate
* Return: 0 if OK, non-zero on error
*/
static int setup_info_table(struct efi_priv *priv, int size)
{
struct efi_info_hdr *info;
@@ -248,6 +265,19 @@ static int setup_info_table(struct efi_priv *priv, int size)
return 0;
}
/**
* add_entry_addr() - Add a new entry to the efi_info list
*
* This adds an entry, consisting of a tag and two lots of data. This avoids the
* caller having to coalesce the data first
*
* @priv: Pointer to our private information which contains the list
* @type: Type of the entry to add
* @ptr1: Pointer to first data block to add
* @size1: Size of first data block in bytes (can be 0)
* @ptr2: Pointer to second data block to add
* @size2: Size of second data block in bytes (can be 0)
*/
static void add_entry_addr(struct efi_priv *priv, enum efi_entry_t type,
void *ptr1, int size1, void *ptr2, int size2)
{
@@ -291,7 +321,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
puts(" efi_init() failed\n");
return ret;
}
global_priv = priv;
efi_set_priv(priv);
cs32 = get_codeseg32();
if (cs32 < 0)

View File

@@ -76,6 +76,19 @@ static const char * const compat_names[COMPAT_COUNT] = {
COMPAT(ALTERA_SOCFPGA_CLK_INIT, "altr,socfpga-a10-clk-init")
};
static const char *const fdt_src_name[] = {
[FDTSRC_SEPARATE] = "separate",
[FDTSRC_FIT] = "fit",
[FDTSRC_BOARD] = "board",
[FDTSRC_EMBED] = "embed",
[FDTSRC_ENV] = "env",
};
const char *fdtdec_get_srcname(void)
{
return fdt_src_name[gd->fdt_src];
}
const char *fdtdec_get_compatible(enum fdt_compat_id id)
{
/* We allow reading of the 'unknown' ID for testing purposes */
@@ -1146,11 +1159,10 @@ int fdtdec_setup_mem_size_base_lowest(void)
return 0;
}
#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
# if CONFIG_IS_ENABLED(MULTI_DTB_FIT_GZIP) ||\
CONFIG_IS_ENABLED(MULTI_DTB_FIT_LZO)
static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
{
#if CONFIG_IS_ENABLED(MULTI_DTB_FIT_GZIP) ||\
CONFIG_IS_ENABLED(MULTI_DTB_FIT_LZO)
size_t sz_out = CONFIG_VAL(MULTI_DTB_FIT_UNCOMPRESS_SZ);
bool gzip = 0, lzo = 0;
ulong sz_in = sz_src;
@@ -1175,11 +1187,11 @@ static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
return -ENOMEM;
}
} else {
# if CONFIG_IS_ENABLED(MULTI_DTB_FIT_USER_DEFINED_AREA)
# if CONFIG_IS_ENABLED(MULTI_DTB_FIT_USER_DEFINED_AREA)
dst = (void *)CONFIG_VAL(MULTI_DTB_FIT_USER_DEF_ADDR);
# else
# else
return -ENOTSUPP;
# endif
# endif
}
if (CONFIG_IS_ENABLED(GZIP) && gzip)
@@ -1197,27 +1209,22 @@ static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
return -EBADMSG;
}
*dstp = dst;
return 0;
}
# else
static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
{
#else
*dstp = (void *)src;
*dstp = (void *)src;
#endif
return 0;
}
# endif
#endif
#if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
/*
* For CONFIG_OF_SEPARATE, the board may optionally implement this to
* provide and/or fixup the fdt.
/**
* fdt_find_separate() - Find a devicetree at the end of the image
*
* @return pointer to FDT blob
*/
__weak void *board_fdt_blob_setup(int *err)
static void *fdt_find_separate(void)
{
void *fdt_blob = NULL;
*err = 0;
#ifdef CONFIG_SPL_BUILD
/* FDT is at end of BSS unless it is in a different memory region */
if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
@@ -1231,7 +1238,6 @@ __weak void *board_fdt_blob_setup(int *err)
return fdt_blob;
}
#endif
int fdtdec_set_ethernet_mac_address(void *fdt, const u8 *mac, size_t size)
{
@@ -1589,60 +1595,81 @@ int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name,
return 0;
}
/* TODO(sjg@chromium.org): This function should not be weak */
__weak int fdtdec_board_setup(const void *fdt_blob)
{
return 0;
}
int fdtdec_setup(void)
/**
* setup_multi_dtb_fit() - locate the correct dtb from a FIT
*
* This supports the CONFIG_MULTI_DTB_FIT feature, looking for the dtb in a
* supplied FIT
*
* It accepts the current value of gd->fdt_blob, which points to the FIT, then
* updates that gd->fdt_blob, to point to the chosen dtb so that U-Boot uses the
* correct one
*/
static void setup_multi_dtb_fit(void)
{
int ret;
#if CONFIG_IS_ENABLED(OF_CONTROL)
# if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
void *fdt_blob;
# endif
# ifdef CONFIG_OF_EMBED
/* Get a pointer to the FDT */
# ifdef CONFIG_SPL_BUILD
gd->fdt_blob = __dtb_dt_spl_begin;
# else
gd->fdt_blob = __dtb_dt_begin;
# endif
# elif defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
/* Allow the board to override the fdt address. */
gd->fdt_blob = board_fdt_blob_setup(&ret);
if (ret)
return ret;
# endif
# ifndef CONFIG_SPL_BUILD
/* Allow the early environment to override the fdt address */
gd->fdt_blob = map_sysmem
(env_get_ulong("fdtcontroladdr", 16,
(unsigned long)map_to_sysmem(gd->fdt_blob)), 0);
# endif
void *blob;
# if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
/*
* Try and uncompress the blob.
* Unfortunately there is no way to know how big the input blob really
* is. So let us set the maximum input size arbitrarily high. 16MB
* ought to be more than enough for packed DTBs.
*/
if (uncompress_blob(gd->fdt_blob, 0x1000000, &fdt_blob) == 0)
gd->fdt_blob = fdt_blob;
if (uncompress_blob(gd->fdt_blob, 0x1000000, &blob) == 0)
gd->fdt_blob = blob;
/*
* Check if blob is a FIT images containings DTBs.
* If so, pick the most relevant
*/
fdt_blob = locate_dtb_in_fit(gd->fdt_blob);
if (fdt_blob) {
gd->multi_dtb_fit = gd->fdt_blob;
gd->fdt_blob = fdt_blob;
blob = locate_dtb_in_fit(gd->fdt_blob);
if (blob) {
gd_set_multi_dtb_fit(gd->fdt_blob);
gd->fdt_blob = blob;
gd->fdt_src = FDTSRC_FIT;
}
}
int fdtdec_setup(void)
{
int ret;
/* The devicetree is typically appended to U-Boot */
if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
gd->fdt_blob = fdt_find_separate();
gd->fdt_src = FDTSRC_SEPARATE;
} else { /* embed dtb in ELF file for testing / development */
gd->fdt_blob = dtb_dt_embedded();
gd->fdt_src = FDTSRC_EMBED;
}
# endif
#endif
/* Allow the board to override the fdt address. */
if (IS_ENABLED(CONFIG_OF_BOARD)) {
gd->fdt_blob = board_fdt_blob_setup(&ret);
if (ret)
return ret;
gd->fdt_src = FDTSRC_BOARD;
}
/* Allow the early environment to override the fdt address */
if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
ulong addr;
addr = env_get_hex("fdtcontroladdr", 0);
if (addr) {
gd->fdt_blob = map_sysmem(addr, 0);
gd->fdt_src = FDTSRC_ENV;
}
}
if (CONFIG_IS_ENABLED(MULTI_DTB_FIT))
setup_multi_dtb_fit();
ret = fdtdec_prepare_fdt();
if (!ret)
@@ -1650,7 +1677,6 @@ int fdtdec_setup(void)
return ret;
}
#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
int fdtdec_resetup(int *rescan)
{
void *fdt_blob;
@@ -1661,8 +1687,8 @@ int fdtdec_resetup(int *rescan)
* FIT image stillpresent there. Save the time and space
* required to uncompress it again.
*/
if (gd->multi_dtb_fit) {
fdt_blob = locate_dtb_in_fit(gd->multi_dtb_fit);
if (gd_multi_dtb_fit()) {
fdt_blob = locate_dtb_in_fit(gd_multi_dtb_fit());
if (fdt_blob == gd->fdt_blob) {
/*
@@ -1686,7 +1712,6 @@ int fdtdec_resetup(int *rescan)
*rescan = 0;
return 0;
}
#endif
int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
phys_addr_t *basep, phys_size_t *sizep,

View File

@@ -1,7 +1,8 @@
config RSA
bool "Use RSA Library"
select RSA_FREESCALE_EXP if FSL_CAAM && !ARCH_MX7 && !ARCH_MX7ULP && !ARCH_MX6 && !ARCH_MX5
select RSA_SOFTWARE_EXP if !RSA_FREESCALE_EXP
select RSA_ASPEED_EXP if ASPEED_ACRY
select RSA_SOFTWARE_EXP if !RSA_FREESCALE_EXP && !RSA_ASPEED_EXP
help
RSA support. This enables the RSA algorithm used for FIT image
verification in U-Boot.
@@ -62,4 +63,11 @@ config RSA_FREESCALE_EXP
Enables driver for RSA modular exponentiation using Freescale cryptographic
accelerator - CAAM.
config RSA_ASPEED_EXP
bool "Enable RSA Modular Exponentiation with ASPEED crypto accelerator"
depends on DM && ASPEED_ACRY
help
Enables driver for RSA modular exponentiation using ASPEED cryptographic
accelerator - ACRY
endif

View File

@@ -5,6 +5,7 @@
*/
#include <common.h>
#include <clock_legacy.h>
#include <bootstage.h>
#include <dm.h>
#include <errno.h>

View File

@@ -276,9 +276,8 @@ static char *string(char *buf, char *end, char *s, int field_width,
}
/* U-Boot uses UTF-16 strings in the EFI context only. */
#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
static char *string16(char *buf, char *end, u16 *s, int field_width,
int precision, int flags)
static __maybe_unused char *string16(char *buf, char *end, u16 *s,
int field_width, int precision, int flags)
{
const u16 *str = s ? s : L"<NULL>";
ssize_t i, len = utf16_strnlen(str, precision);
@@ -317,7 +316,6 @@ static char *device_path_string(char *buf, char *end, void *dp, int field_width,
return buf;
}
#endif
#endif
static char *mac_address_string(char *buf, char *end, u8 *addr, int field_width,
int precision, int flags)
@@ -616,7 +614,8 @@ repeat:
case 's':
/* U-Boot uses UTF-16 strings in the EFI context only. */
#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
#if (CONFIG_IS_ENABLED(EFI_LOADER) || CONFIG_IS_ENABLED(EFI_APP)) && \
!defined(API_BUILD)
if (qualifier == 'l') {
str = string16(str, end, va_arg(args, u16 *),
field_width, precision, flags);