efi: Conflict efi_loader with different stub bitness
PATCH 1/2 efi: Conflict efi_loader with different stub bitness
We have 2 users of the EFI headers: efi_loader and the EFI stub. Efi_loader always expects that the bitness of the definitions it uses is identical to the execution.
The EFI stub however allows to run x86_64 U-Boot on 32bit EFI and the other way around, so it allows for different bitness of EFI definitions and U-Boot environment.
This patch explicitly requests via Kconfig that efi_loader can only be enabled if the bitness is identical. Because we can run efi_loader on x86_64 without EFI stub enabled, it also ensures that this case propagates the correct ABI constraints.
--- include/efi.h | 2 +- lib/efi_loader/Kconfig | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
include/efi.h +1 -1
@@ -19,7 +19,7 @@#include <linux/string.h> #include <linux/types.h> -#ifdef CONFIG_EFI_STUB_64BIT +#if CONFIG_EFI_STUB_64BIT || (!defined(CONFIG_EFI_STUB ) && defined(__x86_64__))/* EFI uses the Microsoft ABI which is not the default for GCC */ #define EFIAPI __attribute__((ms_abi))#else
lib/efi_loader/Kconfig +4 -0
@@ -1,6 +1,10 @@ config EFI_LOADER bool "Support running EFI Applications in U-Boot" depends on (ARM || X86) && OF_LIBFDT + # We need EFI_STUB_64BIT to be set on x86_64 with EFI_STUB + depends on !EFI_STUB || !X86_64 || EFI_STUB_64BIT + # We need EFI_STUB_32BIT to be set on x86_32 with EFI_STUB + depends on !EFI_STUB || !X86 || X86_64 || EFI_STUB_32BIT default y help Select this option if you want to run EFI applications (like grub2)
Signature · 1 line
2.12.3
PATCH 2/2 efi_loader: Always use EFIAPI instead of asmlinkage
EFI calls are usually defined as asmlinkage. That means we pass all parameters to functions via the stack x86_32.
On x86_64 however, we need to also stick to the MS ABI calling conventions, which the EFIAPI define conveniently handles for us. Most EFI functions were also marked with EFIAPI, except for the entry call.
So this patch adjusts all entry calls to use EFIAPI instead of the manual asmlinkage attribute.
While at it, we also change the prototype of the entry point to return efi_status_t instead of ulong, as this is the correct prototype definition.
--- cmd/bootefi.c | 11 ++++++----- lib/efi_loader/efi_boottime.c | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-)
cmd/bootefi.c +6 -5
@@ -126,8 +126,9 @@ static void *copy_fdt(void *fdt)static efi_status_t efi_do_enter (efi_handle_t image_handle,struct efi_system_table *st, - asmlinkage ulong (*entry)(efi_handle_t image_handle, -struct efi_system_table *st)) + EFIAPI efi_status_t (*entry)( +efi_handle_t image_handle, +struct efi_system_table *st)) {efi_status_t ret =EFI_LOAD_ERROR ;
@@ -138,7 +139,7 @@ static efi_status_t efi_do_enter( }#ifdef CONFIG_ARM64 -static efi_status_t efi_run_in_el2(asmlinkage ulong (*entry)( +static efi_status_t efi_run_in_el2(EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,struct efi_system_table *st),efi_handle_t image_handle,struct efi_system_table *st) {
@@ -162,8 +163,8 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,struct efi_device_path *memdp =NULL ;ulong ret; - ulong (*entry)(efi_handle_t image_handle, struct efi_system_table *st) - asmlinkage; + EFIAPI efi_status_t (*entry)(efi_handle_t image_handle, +struct efi_system_table *st);ulong fdt_pages, fdt_size, fdt_start, fdt_end;const efi_guid_t fdt_guid =EFI_FDT_GUID ;bootm_headers_t img = {0 };
lib/efi_loader/efi_boottime.c +2 -2
@@ -1534,8 +1534,8 @@ static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,unsigned long *exit_data_size, s16 **exit_data) { - asmlinkage ulong (*entry)(efi_handle_t image_handle, -struct efi_system_table *st); + EFIAPI ulong (*entry)(efi_handle_t image_handle, +struct efi_system_table *st);struct efi_loaded_image *info = image_handle;efi_status_t ret;
Signature · 1 line
2.12.3
PATCH v2 2/2 efi_loader: Always use EFIAPI instead of asmlinkage
EFI calls are usually defined as asmlinkage. That means we pass all parameters to functions via the stack x86_32.
On x86_64 however, we need to also stick to the MS ABI calling conventions, which the EFIAPI define conveniently handles for us. Most EFI functions were also marked with EFIAPI, except for the entry call.
So this patch adjusts all entry calls to use EFIAPI instead of the manual asmlinkage attribute.
While at it, we also change the prototype of the entry point to return efi_status_t instead of ulong, as this is the correct prototype definition.
---
v1 -> v2:
- Use efi_status_t in all occurences
--- cmd/bootefi.c | 11 ++++++----- lib/efi_loader/efi_boottime.c | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-)
cmd/bootefi.c +6 -5
@@ -126,8 +126,9 @@ static void *copy_fdt(void *fdt)static efi_status_t efi_do_enter (efi_handle_t image_handle,struct efi_system_table *st, - asmlinkage ulong (*entry)(efi_handle_t image_handle, -struct efi_system_table *st)) + EFIAPI efi_status_t (*entry)( +efi_handle_t image_handle, +struct efi_system_table *st)) {efi_status_t ret =EFI_LOAD_ERROR ;
@@ -138,7 +139,7 @@ static efi_status_t efi_do_enter( }#ifdef CONFIG_ARM64 -static efi_status_t efi_run_in_el2(asmlinkage ulong (*entry)( +static efi_status_t efi_run_in_el2(EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,struct efi_system_table *st),efi_handle_t image_handle,struct efi_system_table *st) {
@@ -162,8 +163,8 @@ static efi_status_t do_bootefi_exec(void *efi, void *fdt,struct efi_device_path *memdp =NULL ;ulong ret; - ulong (*entry)(efi_handle_t image_handle, struct efi_system_table *st) - asmlinkage; + EFIAPI efi_status_t (*entry)(efi_handle_t image_handle, +struct efi_system_table *st);ulong fdt_pages, fdt_size, fdt_start, fdt_end;const efi_guid_t fdt_guid =EFI_FDT_GUID ;bootm_headers_t img = {0 };
lib/efi_loader/efi_boottime.c +2 -2
@@ -1534,8 +1534,8 @@ static efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,unsigned long *exit_data_size, s16 **exit_data) { - asmlinkage ulong (*entry)(efi_handle_t image_handle, -struct efi_system_table *st); + EFIAPI efi_status_t (*entry)(efi_handle_t image_handle, +struct efi_system_table *st);struct efi_loaded_image *info = image_handle;efi_status_t ret;
Signature · 1 line
2.12.3