
From: Simon Glass <sjg@chromium.org> Pull in several functions which are identical in the ARM and x86 files. Signed-off-by: Simon Glass <sjg@chromium.org> --- include/efi_stub.h | 36 +++++++++++++++ lib/efi_client/stub.c | 75 ++++++++++++++++++++++++++++++ lib/efi_client/stub_arm64.c | 91 ------------------------------------- lib/efi_client/stub_x86.c | 90 ------------------------------------ 4 files changed, 111 insertions(+), 181 deletions(-) diff --git a/include/efi_stub.h b/include/efi_stub.h index 343c8443597..eb2da6a76d3 100644 --- a/include/efi_stub.h +++ b/include/efi_stub.h @@ -10,6 +10,8 @@ #include <linux/types.h> +struct efi_priv; + enum efi_entry_t { EFIET_END, /* Signals this is the last (empty) entry */ EFIET_MEMORY_MAP, @@ -64,4 +66,38 @@ int dram_init_banksize_from_efi(void); */ void efi_add_known_memory_from_efi(void); +/** + * 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 + */ +int setup_info_table(struct efi_priv *priv, int size); + +/** + * 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) + */ +void add_entry_addr(struct efi_priv *priv, enum efi_entry_t type, void *ptr1, + int size1, void *ptr2, int size2); + #endif /* _EFI_STUB_H */ diff --git a/lib/efi_client/stub.c b/lib/efi_client/stub.c index fed256e68ee..cf0314ba6a6 100644 --- a/lib/efi_client/stub.c +++ b/lib/efi_client/stub.c @@ -11,6 +11,7 @@ #include <debug_uart.h> #include <efi.h> #include <efi_api.h> +#include <efi_stub.h> int efi_stub_exit_boot_services(void) { @@ -35,3 +36,77 @@ int efi_stub_exit_boot_services(void) return 0; } + +void *memcpy(void *dest, const void *src, size_t size) +{ + unsigned char *dptr = dest; + const unsigned char *ptr = src; + const unsigned char *end = src + size; + + while (ptr < end) + *dptr++ = *ptr++; + + return dest; +} + +void *memset(void *inptr, int ch, size_t size) +{ + char *ptr = inptr; + char *end = ptr + size; + + while (ptr < end) + *ptr++ = ch; + + return ptr; +} + +int setup_info_table(struct efi_priv *priv, int size) +{ + struct efi_info_hdr *info; + efi_status_t ret; + + /* Get some memory for our info table */ + priv->info_size = size; + info = efi_malloc(priv, priv->info_size, &ret); + if (ret) { + printhex2(ret); + puts(" No memory for info table: "); + return ret; + } + + memset(info, '\0', sizeof(*info)); + info->version = EFI_TABLE_VERSION; + info->hdr_size = sizeof(*info); + priv->info = info; + priv->next_hdr = (char *)info + info->hdr_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) + */ +void add_entry_addr(struct efi_priv *priv, enum efi_entry_t type, void *ptr1, + int size1, void *ptr2, int size2) +{ + struct efi_entry_hdr *hdr = priv->next_hdr; + + hdr->type = type; + hdr->size = size1 + size2; + hdr->addr = 0; + hdr->link = ALIGN(sizeof(*hdr) + hdr->size, 16); + priv->next_hdr += hdr->link; + memcpy(hdr + 1, ptr1, size1); + memcpy((void *)(hdr + 1) + size1, ptr2, size2); + priv->info->total_size = (ulong)priv->next_hdr - (ulong)priv->info; +} diff --git a/lib/efi_client/stub_arm64.c b/lib/efi_client/stub_arm64.c index 47b9705acca..22c5f23865d 100644 --- a/lib/efi_client/stub_arm64.c +++ b/lib/efi_client/stub_arm64.c @@ -50,97 +50,6 @@ void puts(const char *str) putc(*str++); } - -void *memcpy(void *dest, const void *src, size_t size) -{ - unsigned char *dptr = dest; - const unsigned char *ptr = src; - const unsigned char *end = src + size; - - while (ptr < end) - *dptr++ = *ptr++; - - return dest; -} - -void *memset(void *inptr, int ch, size_t size) -{ - char *ptr = inptr; - char *end = ptr + size; - - while (ptr < end) - *ptr++ = ch; - - return ptr; -} - -/** - * 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; - efi_status_t ret; - - /* Get some memory for our info table */ - priv->info_size = size; - info = efi_malloc(priv, priv->info_size, &ret); - if (ret) { - printhex2(ret); - puts(" No memory for info table: "); - return ret; - } - - memset(info, '\0', sizeof(*info)); - info->version = EFI_TABLE_VERSION; - info->hdr_size = sizeof(*info); - priv->info = info; - priv->next_hdr = (char *)info + info->hdr_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) -{ - struct efi_entry_hdr *hdr = priv->next_hdr; - - hdr->type = type; - hdr->size = size1 + size2; - hdr->addr = 0; - hdr->link = ALIGN(sizeof(*hdr) + hdr->size, 16); - priv->next_hdr += hdr->link; - memcpy(hdr + 1, ptr1, size1); - memcpy((void *)(hdr + 1) + size1, ptr2, size2); - priv->info->total_size = (ulong)priv->next_hdr - (ulong)priv->info; -} - /** * efi_main() - Start an EFI image * diff --git a/lib/efi_client/stub_x86.c b/lib/efi_client/stub_x86.c index 25c9159f320..a7b48eb7c09 100644 --- a/lib/efi_client/stub_x86.c +++ b/lib/efi_client/stub_x86.c @@ -91,29 +91,6 @@ static void _debug_uart_putc(int ch) DEBUG_UART_FUNCS -void *memcpy(void *dest, const void *src, size_t size) -{ - unsigned char *dptr = dest; - const unsigned char *ptr = src; - const unsigned char *end = src + size; - - while (ptr < end) - *dptr++ = *ptr++; - - return dest; -} - -void *memset(void *inptr, int ch, size_t size) -{ - char *ptr = inptr; - char *end = ptr + size; - - while (ptr < end) - *ptr++ = ch; - - return ptr; -} - static void jump_to_uboot(ulong cs32, ulong addr, ulong info) { #ifdef CONFIG_EFI_STUB_32BIT @@ -226,73 +203,6 @@ 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; - efi_status_t ret; - - /* Get some memory for our info table */ - priv->info_size = size; - info = efi_malloc(priv, priv->info_size, &ret); - if (ret) { - printhex2(ret); - puts(" No memory for info table: "); - return ret; - } - - memset(info, '\0', sizeof(*info)); - info->version = EFI_TABLE_VERSION; - info->hdr_size = sizeof(*info); - priv->info = info; - priv->next_hdr = (char *)info + info->hdr_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) -{ - struct efi_entry_hdr *hdr = priv->next_hdr; - - hdr->type = type; - hdr->size = size1 + size2; - hdr->addr = 0; - hdr->link = ALIGN(sizeof(*hdr) + hdr->size, 16); - priv->next_hdr += hdr->link; - memcpy(hdr + 1, ptr1, size1); - memcpy((void *)(hdr + 1) + size1, ptr2, size2); - priv->info->total_size = (ulong)priv->next_hdr - (ulong)priv->info; -} - /** * efi_main() - Start an EFI image * -- 2.43.0