Skip to content

Commit f4f75ad

Browse files
Ard BiesheuvelMatt Fleming
authored andcommitted
efi: efistub: Convert into static library
This patch changes both x86 and arm64 efistub implementations from #including shared .c files under drivers/firmware/efi to building shared code as a static library. The x86 code uses a stub built into the boot executable which uncompresses the kernel at boot time. In this case, the library is linked into the decompressor. In the arm64 case, the stub is part of the kernel proper so the library is linked into the kernel proper as well. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
1 parent bd66947 commit f4f75ad

13 files changed

Lines changed: 39 additions & 11 deletions

File tree

‎arch/arm64/Kconfig‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,18 @@ config CMDLINE_FORCE
292292
This is useful if you cannot or don't want to change the
293293
command-line options your boot loader passes to the kernel.
294294

295+
config EFI_STUB
296+
bool
297+
295298
config EFI
296299
bool "UEFI runtime support"
297300
depends on OF && !CPU_BIG_ENDIAN
298301
select LIBFDT
299302
select UCS2_STRING
300303
select EFI_PARAMS_FROM_FDT
301304
select EFI_RUNTIME_WRAPPERS
305+
select EFI_STUB
306+
select EFI_ARMSTUB
302307
default y
303308
help
304309
This option provides support for runtime services provided

‎arch/arm64/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ core-$(CONFIG_XEN) += arch/arm64/xen/
4848
core-$(CONFIG_CRYPTO) += arch/arm64/crypto/
4949
libs-y := arch/arm64/lib/ $(libs-y)
5050
libs-y += $(LIBGCC)
51+
libs-$(CONFIG_EFI_STUB) += drivers/firmware/efi/libstub/
5152

5253
# Default target when executing plain make
5354
KBUILD_IMAGE := Image.gz

‎arch/arm64/kernel/Makefile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
CPPFLAGS_vmlinux.lds := -DTEXT_OFFSET=$(TEXT_OFFSET)
66
AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
7-
CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) \
8-
-I$(src)/../../../scripts/dtc/libfdt
7+
CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
98

109
CFLAGS_REMOVE_ftrace.o = -pg
1110
CFLAGS_REMOVE_insn.o = -pg

‎arch/arm64/kernel/efi-stub.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
#include <asm/efi.h>
1414
#include <asm/sections.h>
1515

16-
/* Include shared EFI stub code */
17-
#include "../../../drivers/firmware/efi/efi-stub-helper.c"
18-
#include "../../../drivers/firmware/efi/fdt.c"
19-
#include "../../../drivers/firmware/efi/arm-stub.c"
20-
21-
2216
efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
2317
unsigned long *image_addr,
2418
unsigned long *image_size,

‎arch/x86/boot/compressed/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
3333
$(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
3434

3535
ifeq ($(CONFIG_EFI_STUB), y)
36-
VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o
36+
VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \
37+
$(objtree)/drivers/firmware/efi/libstub/lib.a
3738
endif
3839

3940
$(obj)/vmlinux: $(VMLINUX_OBJS) FORCE

‎arch/x86/boot/compressed/eboot.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,6 @@ void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str)
280280
}
281281
}
282282

283-
#include "../../../../drivers/firmware/efi/efi-stub-helper.c"
284-
285283
static void find_bits(unsigned long mask, u8 *pos, u8 *size)
286284
{
287285
u8 first, len;

‎drivers/firmware/efi/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ config EFI_PARAMS_FROM_FDT
5757
config EFI_RUNTIME_WRAPPERS
5858
bool
5959

60+
config EFI_ARMSTUB
61+
bool
62+
6063
endmenu
6164

6265
config UEFI_CPER

‎drivers/firmware/efi/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ obj-$(CONFIG_EFI_VARS_PSTORE) += efi-pstore.o
77
obj-$(CONFIG_UEFI_CPER) += cper.o
88
obj-$(CONFIG_EFI_RUNTIME_MAP) += runtime-map.o
99
obj-$(CONFIG_EFI_RUNTIME_WRAPPERS) += runtime-wrappers.o
10+
obj-$(CONFIG_EFI_STUB) += libstub/
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# The stub may be linked into the kernel proper or into a separate boot binary,
3+
# but in either case, it executes before the kernel does (with MMU disabled) so
4+
# things like ftrace and stack-protector are likely to cause trouble if left
5+
# enabled, even if doing so doesn't break the build.
6+
#
7+
cflags-$(CONFIG_X86_32) := -march=i386
8+
cflags-$(CONFIG_X86_64) := -mcmodel=small
9+
cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 \
10+
-fPIC -fno-strict-aliasing -mno-red-zone \
11+
-mno-mmx -mno-sse -DDISABLE_BRANCH_PROFILING
12+
13+
cflags-$(CONFIG_ARM64) := $(subst -pg,,$(KBUILD_CFLAGS))
14+
cflags-$(CONFIG_ARM) := $(subst -pg,,$(KBUILD_CFLAGS)) \
15+
-fno-builtin -fpic -mno-single-pic-base
16+
17+
KBUILD_CFLAGS := $(cflags-y) \
18+
$(call cc-option,-ffreestanding) \
19+
$(call cc-option,-fno-stack-protector)
20+
21+
GCOV_PROFILE := n
22+
23+
lib-y := efi-stub-helper.o
24+
lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o
25+
26+
CFLAGS_fdt.o += -I$(srctree)/scripts/dtc/libfdt/

0 commit comments

Comments
 (0)