efi: Create a common file for the stub
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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
37
lib/efi_client/stub.c
Normal file
37
lib/efi_client/stub.c
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user