summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/efi_driver/efi_block_device.c29
-rw-r--r--lib/efi_loader/efi_disk.c3
-rw-r--r--lib/efi_loader/efi_memory.c28
-rw-r--r--lib/efi_loader/efi_var_mem.c3
-rw-r--r--lib/efi_loader/efi_variable_tee.c3
-rw-r--r--lib/lmb.c52
-rw-r--r--lib/lwip/lwip/src/apps/tftp/tftp.c54
-rw-r--r--lib/lwip/u-boot/arch/cc.h2
m---------lib/mbedtls/external/mbedtls/framework0
-rw-r--r--lib/string.c51
-rw-r--r--lib/uuid.c16
11 files changed, 168 insertions, 73 deletions
diff --git a/lib/efi_driver/efi_block_device.c b/lib/efi_driver/efi_block_device.c
index d3c668dc183..070747de515 100644
--- a/lib/efi_driver/efi_block_device.c
+++ b/lib/efi_driver/efi_block_device.c
@@ -35,8 +35,10 @@
#include <efi_driver.h>
#include <malloc.h>
#include <dm/device-internal.h>
+#include <dm/lists.h>
#include <dm/root.h>
#include <dm/tag.h>
+#include <dm/uclass-internal.h>
/**
* struct efi_blk_plat - attributes of a block device
@@ -118,13 +120,18 @@ static ulong efi_bl_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
static efi_status_t
efi_bl_create_block_device(efi_handle_t handle, void *interface)
{
- struct udevice *bdev = NULL, *parent = dm_root();
+ struct udevice *bdev = NULL, *parent;
efi_status_t ret;
+ int r;
int devnum;
char *name;
struct efi_block_io *io = interface;
struct efi_blk_plat *plat;
+ r = uclass_find_first_device(UCLASS_EFI_LOADER, &parent);
+ if (r)
+ return EFI_OUT_OF_RESOURCES;
+
devnum = blk_next_free_devnum(UCLASS_EFI_LOADER);
if (devnum < 0)
return EFI_OUT_OF_RESOURCES;
@@ -221,6 +228,24 @@ efi_bl_init(struct efi_driver_binding_extended_protocol *this)
return EFI_SUCCESS;
}
+/**
+ * efi_block_device_create() - create parent for EFI block devices
+ *
+ * Create a device that serves as parent for all block devices created via
+ * ConnectController().
+ *
+ * Return: 0 for success
+ */
+static int efi_block_device_create(void)
+{
+ int ret;
+ struct udevice *dev;
+
+ ret = device_bind_driver(gd->dm_root, "EFI block driver", "efi", &dev);
+
+ return ret;
+}
+
/* Block device driver operators */
static const struct blk_ops efi_blk_ops = {
.read = efi_bl_read,
@@ -249,3 +274,5 @@ U_BOOT_DRIVER(efi_block) = {
.id = UCLASS_EFI_LOADER,
.ops = &driver_ops,
};
+
+EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, efi_block_device_create);
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 1f3de0a2339..5452640354e 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -531,7 +531,8 @@ static efi_status_t efi_disk_add_dev(
/* Store first EFI system partition */
if (part && efi_system_partition.uclass_id == UCLASS_INVALID) {
- if (part_info->bootable & PART_EFI_SYSTEM_PARTITION) {
+ if (part_info &&
+ part_info->bootable & PART_EFI_SYSTEM_PARTITION) {
efi_system_partition.uclass_id = desc->uclass_id;
efi_system_partition.devnum = desc->devnum;
efi_system_partition.part = part;
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 1212772471e..6d00b186250 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -268,6 +268,7 @@ static s64 efi_mem_carve_out(struct efi_mem_list *map,
* memory
* Return: status code
*/
+static
efi_status_t efi_add_memory_map_pg(u64 start, u64 pages,
int memory_type,
bool overlap_conventional)
@@ -865,3 +866,30 @@ int efi_memory_init(void)
return 0;
}
+
+int efi_map_update_notify(phys_addr_t addr, phys_size_t size,
+ enum lmb_map_op op)
+{
+ u64 efi_addr;
+ u64 pages;
+ efi_status_t status;
+
+ efi_addr = (uintptr_t)map_sysmem(addr, 0);
+ pages = efi_size_in_pages(size + (efi_addr & EFI_PAGE_MASK));
+ efi_addr &= ~EFI_PAGE_MASK;
+
+ status = efi_add_memory_map_pg(efi_addr, pages,
+ op == LMB_MAP_OP_RESERVE ?
+ EFI_BOOT_SERVICES_DATA :
+ EFI_CONVENTIONAL_MEMORY,
+ false);
+ if (status != EFI_SUCCESS) {
+ log_err("LMB Map notify failure %lu\n",
+ status & ~EFI_ERROR_MASK);
+ return -1;
+ }
+ unmap_sysmem((void *)(uintptr_t)efi_addr);
+
+ return 0;
+}
+
diff --git a/lib/efi_loader/efi_var_mem.c b/lib/efi_loader/efi_var_mem.c
index b265d95dd6b..31180df9e3a 100644
--- a/lib/efi_loader/efi_var_mem.c
+++ b/lib/efi_loader/efi_var_mem.c
@@ -19,6 +19,7 @@
*/
static struct efi_var_file __efi_runtime_data *efi_var_buf;
static struct efi_var_entry __efi_runtime_data *efi_current_var;
+static const u16 __efi_runtime_rodata vtf[] = u"VarToFile";
/**
* efi_var_mem_compare() - compare GUID and name with a variable
@@ -331,7 +332,7 @@ efi_get_variable_mem(const u16 *variable_name, const efi_guid_t *vendor,
if (timep)
*timep = var->time;
- if (!u16_strcmp(variable_name, u"VarToFile"))
+ if (!u16_strcmp(variable_name, vtf))
return efi_var_collect_mem(data, data_size, EFI_VARIABLE_NON_VOLATILE);
old_size = *data_size;
diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c
index 0d090d051dd..6a1fa39bb6f 100644
--- a/lib/efi_loader/efi_variable_tee.c
+++ b/lib/efi_loader/efi_variable_tee.c
@@ -41,6 +41,7 @@ static u16 mm_sp_id;
extern struct efi_var_file __efi_runtime_data *efi_var_buf;
static efi_uintn_t max_buffer_size; /* comm + var + func + data */
static efi_uintn_t max_payload_size; /* func + data */
+static const u16 __efi_runtime_rodata pk[] = u"PK";
struct mm_connection {
struct udevice *tee;
@@ -858,7 +859,7 @@ efi_status_t efi_set_variable_int(const u16 *variable_name,
if (alt_ret != EFI_SUCCESS)
goto out;
- if (!u16_strcmp(variable_name, u"PK"))
+ if (!u16_strcmp(variable_name, pk))
alt_ret = efi_init_secure_state();
out:
free(comm_buf);
diff --git a/lib/lmb.c b/lib/lmb.c
index 7ca44591e1d..93fc1bea07c 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -23,10 +23,6 @@
DECLARE_GLOBAL_DATA_PTR;
-#define MAP_OP_RESERVE (u8)0x1
-#define MAP_OP_FREE (u8)0x2
-#define MAP_OP_ADD (u8)0x3
-
/*
* The following low level LMB functions must not access the global LMB memory
* map since they are also used to manage IOVA memory maps in iommu drivers like
@@ -430,42 +426,12 @@ long io_lmb_free(struct lmb *io_lmb, phys_addr_t base, phys_size_t size)
static struct lmb lmb;
-static bool lmb_should_notify(u32 flags)
-{
- return !lmb.test && !(flags & LMB_NONOTIFY) &&
- CONFIG_IS_ENABLED(EFI_LOADER);
-}
-
-static int lmb_map_update_notify(phys_addr_t addr, phys_size_t size, u8 op,
- u32 flags)
+static int lmb_map_update_notify(phys_addr_t addr, phys_size_t size,
+ enum lmb_map_op op, u32 flags)
{
- u64 efi_addr;
- u64 pages;
- efi_status_t status;
-
- if (op != MAP_OP_RESERVE && op != MAP_OP_FREE && op != MAP_OP_ADD) {
- log_err("Invalid map update op received (%d)\n", op);
- return -1;
- }
-
- if (!lmb_should_notify(flags))
- return 0;
-
- efi_addr = (uintptr_t)map_sysmem(addr, 0);
- pages = efi_size_in_pages(size + (efi_addr & EFI_PAGE_MASK));
- efi_addr &= ~EFI_PAGE_MASK;
-
- status = efi_add_memory_map_pg(efi_addr, pages,
- op == MAP_OP_RESERVE ?
- EFI_BOOT_SERVICES_DATA :
- EFI_CONVENTIONAL_MEMORY,
- false);
- if (status != EFI_SUCCESS) {
- log_err("%s: LMB Map notify failure %lu\n", __func__,
- status & ~EFI_ERROR_MASK);
- return -1;
- }
- unmap_sysmem((void *)(uintptr_t)efi_addr);
+ if (CONFIG_IS_ENABLED(EFI_LOADER) &&
+ !lmb.test && !(flags & LMB_NONOTIFY))
+ return efi_map_update_notify(addr, size, op);
return 0;
}
@@ -642,7 +608,7 @@ long lmb_add(phys_addr_t base, phys_size_t size)
if (ret)
return ret;
- return lmb_map_update_notify(base, size, MAP_OP_ADD, LMB_NONE);
+ return lmb_map_update_notify(base, size, LMB_MAP_OP_ADD, LMB_NONE);
}
long lmb_free_flags(phys_addr_t base, phys_size_t size,
@@ -654,7 +620,7 @@ long lmb_free_flags(phys_addr_t base, phys_size_t size,
if (ret < 0)
return ret;
- return lmb_map_update_notify(base, size, MAP_OP_FREE, flags);
+ return lmb_map_update_notify(base, size, LMB_MAP_OP_FREE, flags);
}
long lmb_free(phys_addr_t base, phys_size_t size)
@@ -671,7 +637,7 @@ long lmb_reserve(phys_addr_t base, phys_size_t size, u32 flags)
if (ret)
return ret;
- return lmb_map_update_notify(base, size, MAP_OP_RESERVE, flags);
+ return lmb_map_update_notify(base, size, LMB_MAP_OP_RESERVE, flags);
}
static phys_addr_t _lmb_alloc_base(phys_size_t size, ulong align,
@@ -712,7 +678,7 @@ static phys_addr_t _lmb_alloc_base(phys_size_t size, ulong align,
return 0;
ret = lmb_map_update_notify(base, size,
- MAP_OP_RESERVE,
+ LMB_MAP_OP_RESERVE,
flags);
if (ret)
return ret;
diff --git a/lib/lwip/lwip/src/apps/tftp/tftp.c b/lib/lwip/lwip/src/apps/tftp/tftp.c
index 56aeabc4d73..63b1e0e0e20 100644
--- a/lib/lwip/lwip/src/apps/tftp/tftp.c
+++ b/lib/lwip/lwip/src/apps/tftp/tftp.c
@@ -264,19 +264,55 @@ static u16_t payload_size(void)
return TFTP_DEFAULT_BLOCK_SIZE;
}
+/**
+ * find_option() - check if OACK message contains option
+ *
+ * @p: message buffer
+ * @option: option key
+ * Return: option value
+ */
static const char *
find_option(struct pbuf *p, const char *option)
{
- int i;
- u16_t optlen = strlen(option);
- const char *b = p->payload;
-
- for (i = 0; i + optlen + 1 < p->len; i++) {
- if (lwip_strnstr(b + i, option, optlen))
- return b + i + optlen + 2;
- }
+ const char *pos = p->payload;
+ int rem = p->len;
+
+ /*
+ * According to RFC 2347 the OACK packet has the following format:
+ *
+ * +-------+---~~---+---+---~~---+---+---~~---+---+---~~---+---+
+ * | opc | opt1 | 0 | value1 | 0 | optN | 0 | valueN | 0 |
+ * +-------+---~~---+---+---~~---+---+---~~---+---+---~~---+---+
+ */
+
+ /* Skip opc */
+ pos += 2;
+ rem -= 2;
+ if (rem <= 0)
+ return NULL;
+
+ for (;;) {
+ int len;
+ int diff;
+
+ len = strnlen(pos, rem) + 1;
+ if (rem < len)
+ break;
+ diff = strcmp(pos, option);
+ /* Skip option */
+ pos += len;
+ rem -= len;
+ len = strnlen(pos, rem) + 1;
+ if (rem < len)
+ break;
+ if (!diff)
+ return pos;
+ /* Skip value */
+ pos += len;
+ rem -= len;
+ }
- return NULL;
+ return NULL;
}
static void
diff --git a/lib/lwip/u-boot/arch/cc.h b/lib/lwip/u-boot/arch/cc.h
index de138846358..6104c296f6f 100644
--- a/lib/lwip/u-boot/arch/cc.h
+++ b/lib/lwip/u-boot/arch/cc.h
@@ -34,7 +34,7 @@
x, __LINE__, __FILE__); } while (0)
#define atoi(str) (int)dectoul(str, NULL)
-#define lwip_strnstr(a, b, c) strstr(a, b)
+#define lwip_strnstr(a, b, c) strnstr(a, b, c)
#define LWIP_ERR_T int
#define LWIP_CONST_CAST(target_type, val) ((target_type)((uintptr_t)val))
diff --git a/lib/mbedtls/external/mbedtls/framework b/lib/mbedtls/external/mbedtls/framework
deleted file mode 160000
-Subproject 750634d3a51eb9d61b59fd5d801546927c94658
diff --git a/lib/string.c b/lib/string.c
index 0e0900de8bf..d56f88d4a84 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -15,13 +15,14 @@
* reentrant and should be faster). Use only strsep() in new code, please.
*/
+#include <asm/sections.h>
#include <config.h>
+#include <limits.h>
#include <linux/compiler.h>
-#include <linux/types.h>
-#include <linux/string.h>
#include <linux/ctype.h>
+#include <linux/string.h>
+#include <linux/types.h>
#include <malloc.h>
-#include <asm/sections.h>
/**
* strncasecmp - Case insensitive, length-limited string comparison
@@ -679,30 +680,48 @@ char *memdup(const void *src, size_t len)
return p;
}
-#ifndef __HAVE_ARCH_STRSTR
+#ifndef __HAVE_ARCH_STRNSTR
/**
- * strstr - Find the first substring in a %NUL terminated string
- * @s1: The string to be searched
- * @s2: The string to search for
+ * strnstr() - find the first substring occurrence in a NUL terminated string
+ *
+ * @s1: string to be searched
+ * @s2: string to search for
+ * @len: maximum number of characters in s2 to consider
+ *
+ * Return: pointer to the first occurrence or NULL
*/
-char * strstr(const char * s1,const char * s2)
+char *strnstr(const char *s1, const char *s2, size_t len)
{
- int l1, l2;
+ size_t l1, l2;
+ l1 = strnlen(s1, len);
l2 = strlen(s2);
- if (!l2)
- return (char *) s1;
- l1 = strlen(s1);
- while (l1 >= l2) {
- l1--;
- if (!memcmp(s1,s2,l2))
+
+ for (; l1 >= l2; --l1, ++s1) {
+ if (!memcmp(s1, s2, l2))
return (char *) s1;
- s1++;
}
+
return NULL;
}
#endif
+#ifndef __HAVE_ARCH_STRSTR
+/**
+ * strstr() - find the first substring occurrence in a NUL terminated string
+ *
+ * @s1: string to be searched
+ * @s2: string to search for
+ * @len: maximum number of characters in s2 to consider
+ *
+ * Return: pointer to the first occurrence or NULL
+ */
+char *strstr(const char *s1, const char *s2)
+{
+ return strnstr(s1, s2, SIZE_MAX);
+}
+#endif
+
#ifndef __HAVE_ARCH_MEMCHR
/**
* memchr - Find a character in an area of memory.
diff --git a/lib/uuid.c b/lib/uuid.c
index 97388f597a6..75658778044 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -120,6 +120,10 @@ static const struct {
EFI_BLOCK_IO_PROTOCOL_GUID,
},
{
+ "Disk IO",
+ EFI_DISK_IO_PROTOCOL_GUID,
+ },
+ {
"Simple File System",
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID,
},
@@ -128,6 +132,10 @@ static const struct {
EFI_LOADED_IMAGE_PROTOCOL_GUID,
},
{
+ "Loaded Image Device Path",
+ EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID,
+ },
+ {
"Graphics Output",
EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID,
},
@@ -140,10 +148,18 @@ static const struct {
EFI_HII_DATABASE_PROTOCOL_GUID,
},
{
+ "HII Config Access",
+ EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID,
+ },
+ {
"HII Config Routing",
EFI_HII_CONFIG_ROUTING_PROTOCOL_GUID,
},
{
+ "Load File",
+ EFI_LOAD_FILE_PROTOCOL_GUID,
+ },
+ {
"Load File2",
EFI_LOAD_FILE2_PROTOCOL_GUID,
},