1# SPDX-License-Identifier: GPL-2.0 2 3# to be include'd by arch/$(ARCH)/boot/Makefile after setting 4# EFI_ZBOOT_PAYLOAD, EFI_ZBOOT_BFD_TARGET and EFI_ZBOOT_MACH_TYPE 5 6comp-type-$(CONFIG_KERNEL_GZIP) := gzip 7comp-type-$(CONFIG_KERNEL_LZ4) := lz4 8comp-type-$(CONFIG_KERNEL_LZMA) := lzma 9comp-type-$(CONFIG_KERNEL_LZO) := lzo 10comp-type-$(CONFIG_KERNEL_XZ) := xzkern 11comp-type-$(CONFIG_KERNEL_ZSTD) := zstd22 12 13# in GZIP, the appended le32 carrying the uncompressed size is part of the 14# format, but in other cases, we just append it at the end for convenience, 15# causing the original tools to complain when checking image integrity. 16# So disregard it when calculating the payload size in the zimage header. 17zboot-method-y := $(comp-type-y)_with_size 18zboot-size-len-y := 4 19 20zboot-method-$(CONFIG_KERNEL_GZIP) := gzip 21zboot-size-len-$(CONFIG_KERNEL_GZIP) := 0 22 23quiet_cmd_sbsign = SBSIGN $@ 24 cmd_sbsign = sbsign --out $@ $< \ 25 --key $(CONFIG_EFI_ZBOOT_SIGNING_KEY) \ 26 --cert $(CONFIG_EFI_ZBOOT_SIGNING_CERT) 27 28$(obj)/$(EFI_ZBOOT_PAYLOAD).signed: $(obj)/$(EFI_ZBOOT_PAYLOAD) FORCE 29 $(call if_changed,sbsign) 30 31ZBOOT_PAYLOAD-y := $(EFI_ZBOOT_PAYLOAD) 32ZBOOT_PAYLOAD-$(CONFIG_EFI_ZBOOT_SIGNED) := $(EFI_ZBOOT_PAYLOAD).signed 33 34$(obj)/vmlinuz: $(obj)/$(ZBOOT_PAYLOAD-y) FORCE 35 $(call if_changed,$(zboot-method-y)) 36 37OBJCOPYFLAGS_vmlinuz.o := -I binary -O $(EFI_ZBOOT_BFD_TARGET) \ 38 --rename-section .data=.gzdata,load,alloc,readonly,contents 39$(obj)/vmlinuz.o: $(obj)/vmlinuz FORCE 40 $(call if_changed,objcopy) 41 42AFLAGS_zboot-header.o += -DMACHINE_TYPE=IMAGE_FILE_MACHINE_$(EFI_ZBOOT_MACH_TYPE) \ 43 -DZBOOT_EFI_PATH="\"$(realpath $(obj)/vmlinuz.efi.elf)\"" \ 44 -DZBOOT_SIZE_LEN=$(zboot-size-len-y) \ 45 -DCOMP_TYPE="\"$(comp-type-y)\"" 46 47$(obj)/zboot-header.o: $(srctree)/drivers/firmware/efi/libstub/zboot-header.S FORCE 48 $(call if_changed_rule,as_o_S) 49 50ZBOOT_DEPS := $(obj)/zboot-header.o $(objtree)/drivers/firmware/efi/libstub/lib.a 51 52LDFLAGS_vmlinuz.efi.elf := -T $(srctree)/drivers/firmware/efi/libstub/zboot.lds 53$(obj)/vmlinuz.efi.elf: $(obj)/vmlinuz.o $(ZBOOT_DEPS) FORCE 54 $(call if_changed,ld) 55 56ZBOOT_EFI-y := vmlinuz.efi 57ZBOOT_EFI-$(CONFIG_EFI_ZBOOT_SIGNED) := vmlinuz.efi.unsigned 58 59OBJCOPYFLAGS_$(ZBOOT_EFI-y) := -O binary 60$(obj)/$(ZBOOT_EFI-y): $(obj)/vmlinuz.efi.elf FORCE 61 $(call if_changed,objcopy) 62 63targets += zboot-header.o vmlinuz vmlinuz.o vmlinuz.efi.elf vmlinuz.efi 64 65ifneq ($(CONFIG_EFI_ZBOOT_SIGNED),) 66$(obj)/vmlinuz.efi: $(obj)/vmlinuz.efi.unsigned FORCE 67 $(call if_changed,sbsign) 68endif 69 70targets += $(EFI_ZBOOT_PAYLOAD).signed vmlinuz.efi.unsigned 71