This patch contains what is required to enable efistub-as-a-static-lib on ARM.
Baseline is Leif's topic-leg-uefi branch c4881777cb4d, with the following patches applied (all sent to the linux-efi and linux-arm-kernel lists over the past couple of days). They should all apply cleanly.
efi: efistub: convert into static library efi: efistub: refactor stub components efi/arm64: efistub: move shared dependencies to <asm/efi.h> efi/x86: efistub: move shared dependencies to <asm/efi.h> efi/arm64: efistub: remove local copy of linux_banner ARM: use linux_banner from init/version.o --- arch/arm/Kconfig | 1 + arch/arm/boot/compressed/Makefile | 2 +- arch/arm/boot/compressed/efi-stub.c | 67 +++++---------------------------- arch/arm/include/asm/efi.h | 21 +++++++++++ drivers/firmware/efi/libstub/arm-stub.c | 14 +++---- 5 files changed, 40 insertions(+), 65 deletions(-) create mode 100644 arch/arm/include/asm/efi.h
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index fa1f3e7c8499..5adc84b66be7 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1903,6 +1903,7 @@ config EFI select UCS2_STRING select EARLY_IOREMAP select EFI_PARAMS_FROM_FDT + select EFI_ARMSTUB ---help--- This enables the kernel to use UEFI runtime services that are available (such as the UEFI variable services). diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile index 37abdc31cc3f..364ddfd5da26 100644 --- a/arch/arm/boot/compressed/Makefile +++ b/arch/arm/boot/compressed/Makefile @@ -109,7 +109,7 @@ endif
ifeq ($(CONFIG_EFI_STUB),y) CFLAGS_efi-stub.o += -DTEXT_OFFSET=$(TEXT_OFFSET) -OBJS += efi-stub.o banner.o +OBJS += efi-stub.o banner.o ../../../../drivers/firmware/efi/libstub/lib.a USE_LIBFDT = y
$(obj)/banner.o: OBJCOPYFLAGS = -j .rodata diff --git a/arch/arm/boot/compressed/efi-stub.c b/arch/arm/boot/compressed/efi-stub.c index 3b029d7eb5a8..4e8082508eb2 100644 --- a/arch/arm/boot/compressed/efi-stub.c +++ b/arch/arm/boot/compressed/efi-stub.c @@ -11,62 +11,15 @@ * */ #include <linux/efi.h> -#include <libfdt.h> -#include <generated/compile.h> -#include <generated/utsrelease.h> -#include "efi-stub.h" +#include <asm/efi.h>
- -/* Wrapper macro for compatability with x86 mixed mode shared code. */ -#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__) - - -/* - * The maximum uncompressed kernel size is 32 MBytes, so we will reserve - * that for the decompressed kernel. We have no easy way to tell what - * the actuall size of code + data the uncompressed kernel will use. - */ -#define MAX_UNCOMP_KERNEL_SIZE 0x02000000 - -/* - * The kernel zImage should be located between 32 Mbytes - * and 128 MBytes from the base of DRAM. The min - * address leaves space for a maximal size uncompressed image, - * and the max address is due to how the zImage decompressor - * picks a destination address. - */ -#define ZIMAGE_OFFSET_LIMIT 0x08000000 -#define MIN_ZIMAGE_OFFSET MAX_UNCOMP_KERNEL_SIZE -#define MAX_FDT_OFFSET ZIMAGE_OFFSET_LIMIT - -/* - * Prototypes for shared code used in efi-stub-helper.c, but - * provided in arm-stub.c - */ -static void efi_char16_printk(efi_system_table_t *sys_table_arg, - efi_char16_t *str); -static efi_status_t efi_open_volume(efi_system_table_t *sys_table, - void *__image, void **__fh); -static efi_status_t efi_file_close(void *handle); -static efi_status_t -efi_file_read(void *handle, unsigned long *size, void *addr); -static efi_status_t -efi_file_size(efi_system_table_t *sys_table, void *__fh, - efi_char16_t *filename_16, void **handle, u64 *file_sz); - - -/* Include shared EFI stub code, and required headers. */ -#include "../../../../drivers/firmware/efi/efi-stub-helper.c" -#include "../../../../drivers/firmware/efi/fdt.c" -#include "../../../drivers/firmware/efi/arm-stub.c" - -static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, - unsigned long *image_addr, - unsigned long *image_size, - unsigned long *reserve_addr, - unsigned long *reserve_size, - unsigned long dram_base, - efi_loaded_image_t *image) +efi_status_t handle_kernel_image(efi_system_table_t *sys_table, + unsigned long *image_addr, + unsigned long *image_size, + unsigned long *reserve_addr, + unsigned long *reserve_size, + unsigned long dram_base, + efi_loaded_image_t *image) { unsigned long nr_pages; efi_status_t status; @@ -82,7 +35,7 @@ static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, */ if (dram_base & (ZIMAGE_OFFSET_LIMIT - 1)) { pr_efi_err(sys_table, "Invalid DRAM base address alignment.\n"); - return EFI_ERROR; + return EFI_LOAD_ERROR; }
/* @@ -133,7 +86,7 @@ static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, *reserve_size = 0; efi_free(sys_table, *image_size, *image_addr); *image_size = 0; - return EFI_ERROR; + return EFI_LOAD_ERROR; } return EFI_SUCCESS; } diff --git a/arch/arm/include/asm/efi.h b/arch/arm/include/asm/efi.h new file mode 100644 index 000000000000..9171f9a1c14a --- /dev/null +++ b/arch/arm/include/asm/efi.h @@ -0,0 +1,21 @@ + +#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__) + +/* + * The maximum uncompressed kernel size is 32 MBytes, so we will reserve + * that for the decompressed kernel. We have no easy way to tell what + * the actuall size of code + data the uncompressed kernel will use. + */ +#define MAX_UNCOMP_KERNEL_SIZE 0x02000000 + +/* + * The kernel zImage should be located between 32 Mbytes + * and 128 MBytes from the base of DRAM. The min + * address leaves space for a maximal size uncompressed image, + * and the max address is due to how the zImage decompressor + * picks a destination address. + */ +#define ZIMAGE_OFFSET_LIMIT 0x08000000 +#define MIN_ZIMAGE_OFFSET MAX_UNCOMP_KERNEL_SIZE +#define MAX_FDT_OFFSET ZIMAGE_OFFSET_LIMIT + diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 34614d6f9698..480339b6b110 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -151,13 +151,13 @@ void efi_char16_printk(efi_system_table_t *sys_table_arg, * must be reserved. On failure it is required to free all * all allocations it has made. */ -static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, - unsigned long *image_addr, - unsigned long *image_size, - unsigned long *reserve_addr, - unsigned long *reserve_size, - unsigned long dram_base, - efi_loaded_image_t *image); +efi_status_t handle_kernel_image(efi_system_table_t *sys_table, + unsigned long *image_addr, + unsigned long *image_size, + unsigned long *reserve_addr, + unsigned long *reserve_size, + unsigned long dram_base, + efi_loaded_image_t *image); /* * EFI entry point for the arm/arm64 EFI stubs. This is the entrypoint * that is described in the PE/COFF header. Most of the code is the same
On Mon, Jun 16, 2014 at 9:49 AM, Ard Biesheuvel ard.biesheuvel@linaro.org wrote:
This patch contains what is required to enable efistub-as-a-static-lib on ARM.
Baseline is Leif's topic-leg-uefi branch c4881777cb4d, with the following patches applied (all sent to the linux-efi and linux-arm-kernel lists over the past couple of days). They should all apply cleanly.
This looks good. I wasn't really happy about the #include stuff, so I'm glad to see this getting taken care of.
Roy
efi: efistub: convert into static library efi: efistub: refactor stub components efi/arm64: efistub: move shared dependencies to <asm/efi.h> efi/x86: efistub: move shared dependencies to <asm/efi.h> efi/arm64: efistub: remove local copy of linux_banner ARM: use linux_banner from init/version.o
arch/arm/Kconfig | 1 + arch/arm/boot/compressed/Makefile | 2 +- arch/arm/boot/compressed/efi-stub.c | 67 +++++---------------------------- arch/arm/include/asm/efi.h | 21 +++++++++++ drivers/firmware/efi/libstub/arm-stub.c | 14 +++---- 5 files changed, 40 insertions(+), 65 deletions(-) create mode 100644 arch/arm/include/asm/efi.h
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index fa1f3e7c8499..5adc84b66be7 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1903,6 +1903,7 @@ config EFI select UCS2_STRING select EARLY_IOREMAP select EFI_PARAMS_FROM_FDT
select EFI_ARMSTUB ---help--- This enables the kernel to use UEFI runtime services that are available (such as the UEFI variable services).
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile index 37abdc31cc3f..364ddfd5da26 100644 --- a/arch/arm/boot/compressed/Makefile +++ b/arch/arm/boot/compressed/Makefile @@ -109,7 +109,7 @@ endif
ifeq ($(CONFIG_EFI_STUB),y) CFLAGS_efi-stub.o += -DTEXT_OFFSET=$(TEXT_OFFSET) -OBJS += efi-stub.o banner.o +OBJS += efi-stub.o banner.o ../../../../drivers/firmware/efi/libstub/lib.a USE_LIBFDT = y
$(obj)/banner.o: OBJCOPYFLAGS = -j .rodata diff --git a/arch/arm/boot/compressed/efi-stub.c b/arch/arm/boot/compressed/efi-stub.c index 3b029d7eb5a8..4e8082508eb2 100644 --- a/arch/arm/boot/compressed/efi-stub.c +++ b/arch/arm/boot/compressed/efi-stub.c @@ -11,62 +11,15 @@
*/ #include <linux/efi.h> -#include <libfdt.h> -#include <generated/compile.h> -#include <generated/utsrelease.h> -#include "efi-stub.h" +#include <asm/efi.h>
-/* Wrapper macro for compatability with x86 mixed mode shared code. */ -#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
-/*
- The maximum uncompressed kernel size is 32 MBytes, so we will reserve
- that for the decompressed kernel. We have no easy way to tell what
- the actuall size of code + data the uncompressed kernel will use.
- */
-#define MAX_UNCOMP_KERNEL_SIZE 0x02000000
-/*
- The kernel zImage should be located between 32 Mbytes
- and 128 MBytes from the base of DRAM. The min
- address leaves space for a maximal size uncompressed image,
- and the max address is due to how the zImage decompressor
- picks a destination address.
- */
-#define ZIMAGE_OFFSET_LIMIT 0x08000000 -#define MIN_ZIMAGE_OFFSET MAX_UNCOMP_KERNEL_SIZE -#define MAX_FDT_OFFSET ZIMAGE_OFFSET_LIMIT
-/*
- Prototypes for shared code used in efi-stub-helper.c, but
- provided in arm-stub.c
- */
-static void efi_char16_printk(efi_system_table_t *sys_table_arg,
efi_char16_t *str);
-static efi_status_t efi_open_volume(efi_system_table_t *sys_table,
void *__image, void **__fh);
-static efi_status_t efi_file_close(void *handle); -static efi_status_t -efi_file_read(void *handle, unsigned long *size, void *addr); -static efi_status_t -efi_file_size(efi_system_table_t *sys_table, void *__fh,
efi_char16_t *filename_16, void **handle, u64 *file_sz);
-/* Include shared EFI stub code, and required headers. */ -#include "../../../../drivers/firmware/efi/efi-stub-helper.c" -#include "../../../../drivers/firmware/efi/fdt.c" -#include "../../../drivers/firmware/efi/arm-stub.c"
-static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
unsigned long *image_addr,
unsigned long *image_size,
unsigned long *reserve_addr,
unsigned long *reserve_size,
unsigned long dram_base,
efi_loaded_image_t *image)
+efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
unsigned long *image_addr,
unsigned long *image_size,
unsigned long *reserve_addr,
unsigned long *reserve_size,
unsigned long dram_base,
efi_loaded_image_t *image)
{ unsigned long nr_pages; efi_status_t status; @@ -82,7 +35,7 @@ static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, */ if (dram_base & (ZIMAGE_OFFSET_LIMIT - 1)) { pr_efi_err(sys_table, "Invalid DRAM base address alignment.\n");
return EFI_ERROR;
return EFI_LOAD_ERROR; } /*
@@ -133,7 +86,7 @@ static efi_status_t handle_kernel_image(efi_system_table_t *sys_table, *reserve_size = 0; efi_free(sys_table, *image_size, *image_addr); *image_size = 0;
return EFI_ERROR;
return EFI_LOAD_ERROR; } return EFI_SUCCESS;
} diff --git a/arch/arm/include/asm/efi.h b/arch/arm/include/asm/efi.h new file mode 100644 index 000000000000..9171f9a1c14a --- /dev/null +++ b/arch/arm/include/asm/efi.h @@ -0,0 +1,21 @@
+#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
+/*
- The maximum uncompressed kernel size is 32 MBytes, so we will reserve
- that for the decompressed kernel. We have no easy way to tell what
- the actuall size of code + data the uncompressed kernel will use.
- */
+#define MAX_UNCOMP_KERNEL_SIZE 0x02000000
+/*
- The kernel zImage should be located between 32 Mbytes
- and 128 MBytes from the base of DRAM. The min
- address leaves space for a maximal size uncompressed image,
- and the max address is due to how the zImage decompressor
- picks a destination address.
- */
+#define ZIMAGE_OFFSET_LIMIT 0x08000000 +#define MIN_ZIMAGE_OFFSET MAX_UNCOMP_KERNEL_SIZE +#define MAX_FDT_OFFSET ZIMAGE_OFFSET_LIMIT
diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 34614d6f9698..480339b6b110 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -151,13 +151,13 @@ void efi_char16_printk(efi_system_table_t *sys_table_arg,
- must be reserved. On failure it is required to free all
- all allocations it has made.
*/ -static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
unsigned long *image_addr,
unsigned long *image_size,
unsigned long *reserve_addr,
unsigned long *reserve_size,
unsigned long dram_base,
efi_loaded_image_t *image);
+efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
unsigned long *image_addr,
unsigned long *image_size,
unsigned long *reserve_addr,
unsigned long *reserve_size,
unsigned long dram_base,
efi_loaded_image_t *image);
/*
- EFI entry point for the arm/arm64 EFI stubs. This is the entrypoint
- that is described in the PE/COFF header. Most of the code is the same
-- 1.8.3.2