Skip to content

Commit 45dd403

Browse files
committed
efi/zboot: arm64: Inject kernel code size symbol into the zboot payload
The EFI zboot code is not built as part of the kernel proper, like the ordinary EFI stub, but still needs access to symbols that are defined only internally in the kernel, and are left unexposed deliberately to avoid creating ABI inadvertently that we're stuck with later. So capture the kernel code size of the kernel image, and inject it as an ELF symbol into the object that contains the compressed payload, where it will be accessible to zboot code that needs it. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Acked-by: Mark Rutland <mark.rutland@arm.com>
1 parent 538bc0f commit 45dd403

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

arch/arm64/boot/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ EFI_ZBOOT_BFD_TARGET := elf64-littleaarch64
4444
EFI_ZBOOT_MACH_TYPE := ARM64
4545
EFI_ZBOOT_FORWARD_CFI := $(CONFIG_ARM64_BTI_KERNEL)
4646

47+
EFI_ZBOOT_OBJCOPY_FLAGS = --add-symbol zboot_code_size=0x$(shell \
48+
$(NM) vmlinux|grep _kernel_codesize|cut -d' ' -f1)
49+
4750
include $(srctree)/drivers/firmware/efi/libstub/Makefile.zboot

arch/arm64/kernel/image-vars.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,8 @@ KVM_NVHE_ALIAS(kvm_protected_mode_initialized);
108108

109109
#endif /* CONFIG_KVM */
110110

111+
#ifdef CONFIG_EFI_ZBOOT
112+
_kernel_codesize = ABSOLUTE(__inittext_end - _text);
113+
#endif
114+
111115
#endif /* __ARM64_KERNEL_IMAGE_VARS_H */

drivers/firmware/efi/libstub/Makefile.zboot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ quiet_cmd_compwithsize = $(quiet_cmd_$(zboot-method-y))
4040
$(obj)/vmlinuz: $(obj)/vmlinux.bin FORCE
4141
$(call if_changed,compwithsize)
4242

43-
OBJCOPYFLAGS_vmlinuz.o := -I binary -O $(EFI_ZBOOT_BFD_TARGET) \
43+
OBJCOPYFLAGS_vmlinuz.o := -I binary -O $(EFI_ZBOOT_BFD_TARGET) $(EFI_ZBOOT_OBJCOPY_FLAGS) \
4444
--rename-section .data=.gzdata,load,alloc,readonly,contents
4545
$(obj)/vmlinuz.o: $(obj)/vmlinuz FORCE
4646
$(call if_changed,objcopy)

drivers/firmware/efi/libstub/zboot.lds

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
ENTRY(__efistub_efi_zboot_header);
44

5+
PROVIDE(zboot_code_size = ABSOLUTE(0));
6+
57
SECTIONS
68
{
79
.head : ALIGN(4096) {
@@ -17,6 +19,11 @@ SECTIONS
1719
*(.gzdata)
1820
__efistub__gzdata_end = .;
1921
*(.rodata* .init.rodata* .srodata*)
22+
23+
. = ALIGN(4);
24+
__efistub_code_size = .;
25+
LONG(zboot_code_size);
26+
2027
_etext = ALIGN(4096);
2128
. = _etext;
2229
}

0 commit comments

Comments
 (0)