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