
From: Simon Glass <sjg@chromium.org> There is some duplicated code across x86 and ARM even though they have slightly different implementations. They both call efi_stub_exit_boot_services() and this function does not relate to the app, so belongs better outside the general-purpose efi.c file. Create a new efi_stub C file containing this function. Leave out the efi_ prefix since this is obvious from the directory name. Signed-off-by: Simon Glass <sjg@chromium.org> --- Makefile | 1 + include/efi.h | 4 ++-- lib/efi_client/Makefile | 6 +++++- lib/efi_client/efi.c | 24 ------------------------ lib/efi_client/stub.c | 37 +++++++++++++++++++++++++++++++++++++ lib/efi_client/stub_arm64.c | 2 +- lib/efi_client/stub_x86.c | 2 +- 7 files changed, 47 insertions(+), 29 deletions(-) create mode 100644 lib/efi_client/stub.c diff --git a/Makefile b/Makefile index f70f6ab3d44..c256b4094fc 100644 --- a/Makefile +++ b/Makefile @@ -1697,6 +1697,7 @@ quiet_cmd_u-boot_payload ?= LD $@ cmd_u-boot_payload ?= $(LD) $(LDFLAGS_EFI_PAYLOAD) -o $@ \ -T u-boot-payload.lds $(if $(CONFIG_X86),arch/x86/cpu/call32.o,) \ lib/efi_client/efi.o lib/efi_client/stub_$(EFI_STUB_ARCH).o \ + lib/efi_client/stub.o \ u-boot.bin.o $(addprefix arch/$(ARCH)/lib/,$(EFISTUB)) quiet_cmd_u-boot_payload_arm64.efi ?= OBJCOPY $@ diff --git a/include/efi.h b/include/efi.h index 6ba2f2b7c85..99a209e86c6 100644 --- a/include/efi.h +++ b/include/efi.h @@ -664,13 +664,13 @@ void efi_putc(struct efi_priv *priv, const char ch); int efi_store_memory_map(struct efi_priv *priv); /** - * efi_call_exit_boot_services() - Handle the exit-boot-service procedure + * efi_stub_exit_boot_services() - Handle the exit-boot-service procedure * * Tell EFI we don't want their boot services anymore * * Return: 0 if OK, non-zero on error */ -int efi_call_exit_boot_services(void); +int efi_stub_exit_boot_services(void); /** * efi_get_mmap() - Get the memory map from EFI diff --git a/lib/efi_client/Makefile b/lib/efi_client/Makefile index 5a11ca58018..d7a3232c6bb 100644 --- a/lib/efi_client/Makefile +++ b/lib/efi_client/Makefile @@ -14,6 +14,8 @@ stub_obj := stub_x86.o ifeq ($(CONFIG_EFI_STUB_64BIT),y) # && !CONFIG_ARM64 CFLAGS_REMOVE_$(stub_obj) := -march=i386 -m32 CFLAGS_$(stub_obj) := -m64 +CFLAGS_REMOVE_stub.o := -march=i386 -m32 +CFLAGS_stub.o := -m64 CFLAGS_REMOVE_efi.o := -march=i386 -m32 CFLAGS_efi.o := -fpic -m64 endif @@ -21,8 +23,10 @@ endif CFLAGS_REMOVE_$(stub_obj) += -mregparm=3 CFLAGS_$(stub_obj) += -fpic -fshort-wchar +CFLAGS_REMOVE_stub.o += -mregparm=3 +CFLAGS_stub.o += -fpic -fshort-wchar CFLAGS_REMOVE_efi.o += -mregparm=3 CFLAGS_efi.o += -fpic -fshort-wchar $(info removing flags $(CFLAGS_REMOVE_$(stub_obj))) -extra-$(CONFIG_EFI_STUB) += $(stub_obj) efi.o +extra-$(CONFIG_EFI_STUB) += $(stub_obj) stub.o efi.o diff --git a/lib/efi_client/efi.c b/lib/efi_client/efi.c index 8b825c7a66e..6b1b6b10e2a 100644 --- a/lib/efi_client/efi.c +++ b/lib/efi_client/efi.c @@ -219,27 +219,3 @@ int efi_store_memory_map(struct efi_priv *priv) return 0; } - -int efi_call_exit_boot_services(void) -{ - struct efi_priv *priv = efi_get_priv(); - const struct efi_boot_services *boot = priv->boot; - efi_uintn_t size; - u32 version; - efi_status_t ret; - - size = priv->memmap_alloc; - ret = boot->get_memory_map(&size, priv->memmap_desc, - &priv->memmap_key, - &priv->memmap_desc_size, &version); - if (ret) { - printhex2(ret); - puts(" Can't get memory map\n"); - return ret; - } - ret = boot->exit_boot_services(priv->parent_image, priv->memmap_key); - if (ret) - return ret; - - return 0; -} diff --git a/lib/efi_client/stub.c b/lib/efi_client/stub.c new file mode 100644 index 00000000000..fed256e68ee --- /dev/null +++ b/lib/efi_client/stub.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2015 Google, Inc + * + * EFI information obtained here: + * http://wiki.phoenix.com/wiki/index.php/EFI_BOOT_SERVICES + * + * Provides helper functions for use with the stub + */ + +#include <debug_uart.h> +#include <efi.h> +#include <efi_api.h> + +int efi_stub_exit_boot_services(void) +{ + struct efi_priv *priv = efi_get_priv(); + const struct efi_boot_services *boot = priv->boot; + efi_uintn_t size; + u32 version; + efi_status_t ret; + + size = priv->memmap_alloc; + ret = boot->get_memory_map(&size, priv->memmap_desc, + &priv->memmap_key, + &priv->memmap_desc_size, &version); + if (ret) { + printhex2(ret); + puts(" Can't get memory map\n"); + return ret; + } + ret = boot->exit_boot_services(priv->parent_image, priv->memmap_key); + if (ret) + return ret; + + return 0; +} diff --git a/lib/efi_client/stub_arm64.c b/lib/efi_client/stub_arm64.c index 2cabb16f241..47b9705acca 100644 --- a/lib/efi_client/stub_arm64.c +++ b/lib/efi_client/stub_arm64.c @@ -203,7 +203,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image, table.sys_table = (ulong)sys_table; add_entry_addr(priv, EFIET_SYS_TABLE, &table, sizeof(table), NULL, 0); - ret = efi_call_exit_boot_services(); + ret = efi_stub_exit_boot_services(); if (ret) return ret; diff --git a/lib/efi_client/stub_x86.c b/lib/efi_client/stub_x86.c index ea1993f745d..25c9159f320 100644 --- a/lib/efi_client/stub_x86.c +++ b/lib/efi_client/stub_x86.c @@ -347,7 +347,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image, table.sys_table = (ulong)sys_table; add_entry_addr(priv, EFIET_SYS_TABLE, &table, sizeof(table), NULL, 0); - ret = efi_call_exit_boot_services(); + ret = efi_stub_exit_boot_services(); if (ret) return ret; -- 2.43.0