From ebf199b92f81d4c1228200bfc138aa32928bf373 Mon Sep 17 00:00:00 2001 From: "xypron.glpk@gmx.de" Date: Wed, 9 Aug 2017 20:55:00 +0200 Subject: [PATCH 1/6] efi_loader: attribute EFIAPI of efi_locate handle() efi_locate_handle is called internally so it should not be marked as EFIAPI. The external function is efi_locate_handle_ext. Signed-off-by: Heinrich Schuchardt Reviewed-by: Rob Clark Signed-off-by: Alexander Graf --- lib/efi_loader/efi_boottime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 59479ed..58cd6d0 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -611,7 +611,7 @@ static int efi_search(enum efi_locate_search_type search_type, return -1; } -static efi_status_t EFIAPI efi_locate_handle( +static efi_status_t efi_locate_handle( enum efi_locate_search_type search_type, efi_guid_t *protocol, void *search_key, unsigned long *buffer_size, efi_handle_t *buffer) From 796a78cbe5676fc7562b50c7a0191fa56c8c4772 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Sun, 6 Aug 2017 14:10:07 -0400 Subject: [PATCH 2/6] efi_loader: LocateHandle should return EFI_NOT_FOUND if none found Spotted this debugging OpenBSD's bootloader in qemu. (Wouldn't really fix anything, the problem was not having any disks, but we should probably return the correct error code.) Signed-off-by: Rob Clark Reviewed-by: Heinrich Schuchardt Signed-off-by: Alexander Graf --- lib/efi_loader/efi_boottime.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 58cd6d0..43f3238 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -633,6 +633,10 @@ static efi_status_t efi_locate_handle( return EFI_BUFFER_TOO_SMALL; } + *buffer_size = size; + if (size == 0) + return EFI_NOT_FOUND; + /* Then fill the array */ list_for_each(lhandle, &efi_obj_list) { struct efi_object *efiobj; @@ -642,7 +646,6 @@ static efi_status_t efi_locate_handle( } } - *buffer_size = size; return EFI_SUCCESS; } From 3d9880784ed5cd503b0d69128ea1841102ff522e Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Fri, 4 Aug 2017 07:52:03 -0400 Subject: [PATCH 3/6] efi_loader: GOP fix for no display uclass_first_device() returns 0 if there is no device, but error if there is a device that failed to probe. Signed-off-by: Rob Clark Signed-off-by: Alexander Graf --- lib/efi_loader/efi_gop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index e063e0c..411a8c9 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -137,7 +137,7 @@ int efi_gop_register(void) struct udevice *vdev; /* We only support a single video output device for now */ - if (uclass_first_device(UCLASS_VIDEO, &vdev)) + if (uclass_first_device(UCLASS_VIDEO, &vdev) || !vdev) return -1; struct video_priv *priv = dev_get_uclass_priv(vdev); From aee4f06dff36261433d90c94a5def2c90be8407c Mon Sep 17 00:00:00 2001 From: "xypron.glpk@gmx.de" Date: Fri, 11 Aug 2017 21:19:37 +0200 Subject: [PATCH 4/6] efi_loader: use EFI_PAGE_MASK instead of EFI_PAGE_SIZE - 1 We should be consistent in the way we calculate page sizes. Signed-off-by: Heinrich Schuchardt Signed-off-by: Alexander Graf --- lib/efi_loader/efi_runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index dd52755..ad7f375 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -325,7 +325,7 @@ void efi_add_runtime_mmio(void *mmio_ptr, u64 len) { struct efi_runtime_mmio_list *newmmio; - u64 pages = (len + EFI_PAGE_SIZE - 1) >> EFI_PAGE_SHIFT; + u64 pages = (len + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT; efi_add_memory_map(*(uintptr_t *)mmio_ptr, pages, EFI_MMAP_IO, false); newmmio = calloc(1, sizeof(*newmmio)); From a44bffcc9557cf5f761a43bce44a59fa85feab2a Mon Sep 17 00:00:00 2001 From: "xypron.glpk@gmx.de" Date: Fri, 11 Aug 2017 21:19:25 +0200 Subject: [PATCH 5/6] efi_loader: use EFI_PAGE_SIZE instead of 4096 We should use constant EFI_PAGE_SIZE instead of 4096 where the coding relies on 4096 being EFI_PAGE_SIZE. Signed-off-by: Heinrich Schuchardt Signed-off-by: Alexander Graf --- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index d20775e..3196d86 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -158,7 +158,7 @@ static void *copy_fdt(void *fdt) } /* Give us at least 4kb breathing room */ - fdt_size = ALIGN(fdt_size + 4096, 4096); + fdt_size = ALIGN(fdt_size + 4096, EFI_PAGE_SIZE); fdt_pages = fdt_size >> EFI_PAGE_SHIFT; /* Safe fdt location is at 128MB */ @@ -166,7 +166,7 @@ static void *copy_fdt(void *fdt) if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages, &new_fdt_addr) != EFI_SUCCESS) { /* If we can't put it there, put it somewhere */ - new_fdt_addr = (ulong)memalign(4096, fdt_size); + new_fdt_addr = (ulong)memalign(EFI_PAGE_SIZE, fdt_size); if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages, &new_fdt_addr) != EFI_SUCCESS) { printf("ERROR: Failed to reserve space for FDT\n"); From c81883dfce7360148c72922b93bfa16b399ee3ee Mon Sep 17 00:00:00 2001 From: "xypron.glpk@gmx.de" Date: Thu, 17 Aug 2017 18:57:36 +0200 Subject: [PATCH 6/6] efi_loader: do not cast return value in EFI_EXIT UEFI API functions have different return types. Some return a value of type EFI_STATUS other don't. We therefore should not cast the return value of EFI_EXIT to another type than the expression passed to EFI_EXIT. Signed-off-by: Heinrich Schuchardt Signed-off-by: Alexander Graf --- include/efi_loader.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 037cc7c..1179234 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -33,9 +33,9 @@ const char *__efi_nesting_dec(void); * Exit the u-boot world back to UEFI: */ #define EFI_EXIT(ret) ({ \ - efi_status_t _r = ret; \ + typeof(ret) _r = ret; \ debug("%sEFI: Exit: %s: %u\n", __efi_nesting_dec(), \ - __func__, (u32)(_r & ~EFI_ERROR_MASK)); \ + __func__, (u32)((uintptr_t) _r & ~EFI_ERROR_MASK)); \ assert(__efi_exit_check()); \ _r; \ })