1a0509109SArd Biesheuvel# SPDX-License-Identifier: GPL-2.0 2a0509109SArd Biesheuvel 3a0509109SArd Biesheuvel# to be include'd by arch/$(ARCH)/boot/Makefile after setting 4538bc0f4SArd Biesheuvel# EFI_ZBOOT_PAYLOAD, EFI_ZBOOT_BFD_TARGET, EFI_ZBOOT_MACH_TYPE and 5538bc0f4SArd Biesheuvel# EFI_ZBOOT_FORWARD_CFI 6a0509109SArd Biesheuvel 7bca2f3a9SArd Biesheuvelquiet_cmd_copy_and_pad = PAD $@ 8bca2f3a9SArd Biesheuvel cmd_copy_and_pad = cp $< $@ && \ 9bca2f3a9SArd Biesheuvel truncate -s $(shell hexdump -s16 -n4 -e '"%u"' $<) $@ 10bca2f3a9SArd Biesheuvel 11bca2f3a9SArd Biesheuvel# Pad the file to the size of the uncompressed image in memory, including BSS 12bca2f3a9SArd Biesheuvel$(obj)/vmlinux.bin: $(obj)/$(EFI_ZBOOT_PAYLOAD) FORCE 13bca2f3a9SArd Biesheuvel $(call if_changed,copy_and_pad) 14bca2f3a9SArd Biesheuvel 15a0509109SArd Biesheuvelcomp-type-$(CONFIG_KERNEL_GZIP) := gzip 16a0509109SArd Biesheuvelcomp-type-$(CONFIG_KERNEL_LZ4) := lz4 17a0509109SArd Biesheuvelcomp-type-$(CONFIG_KERNEL_LZMA) := lzma 18a0509109SArd Biesheuvelcomp-type-$(CONFIG_KERNEL_LZO) := lzo 19a0509109SArd Biesheuvelcomp-type-$(CONFIG_KERNEL_XZ) := xzkern 20a0509109SArd Biesheuvelcomp-type-$(CONFIG_KERNEL_ZSTD) := zstd22 21a0509109SArd Biesheuvel 22bca2f3a9SArd Biesheuvel# in GZIP, the appended le32 carrying the uncompressed size is part of the 23bca2f3a9SArd Biesheuvel# format, but in other cases, we just append it at the end for convenience, 24bca2f3a9SArd Biesheuvel# causing the original tools to complain when checking image integrity. 25bca2f3a9SArd Biesheuvel# So disregard it when calculating the payload size in the zimage header. 26bca2f3a9SArd Biesheuvelzboot-method-y := $(comp-type-y)_with_size 27*026b8579SArd Biesheuvelzboot-size-len-y := 4 28a0509109SArd Biesheuvel 29bca2f3a9SArd Biesheuvelzboot-method-$(CONFIG_KERNEL_GZIP) := gzip 30*026b8579SArd Biesheuvelzboot-size-len-$(CONFIG_KERNEL_GZIP) := 0 31bca2f3a9SArd Biesheuvel 32bca2f3a9SArd Biesheuvel$(obj)/vmlinuz: $(obj)/vmlinux.bin FORCE 33*026b8579SArd Biesheuvel $(call if_changed,$(zboot-method-y)) 34a0509109SArd Biesheuvel 3545dd403dSArd BiesheuvelOBJCOPYFLAGS_vmlinuz.o := -I binary -O $(EFI_ZBOOT_BFD_TARGET) $(EFI_ZBOOT_OBJCOPY_FLAGS) \ 36a0509109SArd Biesheuvel --rename-section .data=.gzdata,load,alloc,readonly,contents 37a0509109SArd Biesheuvel$(obj)/vmlinuz.o: $(obj)/vmlinuz FORCE 38a0509109SArd Biesheuvel $(call if_changed,objcopy) 39a0509109SArd Biesheuvel 40538bc0f4SArd Biesheuvelaflags-zboot-header-$(EFI_ZBOOT_FORWARD_CFI) := \ 41538bc0f4SArd Biesheuvel -DPE_DLL_CHAR_EX=IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT 42538bc0f4SArd Biesheuvel 43a0509109SArd BiesheuvelAFLAGS_zboot-header.o += -DMACHINE_TYPE=IMAGE_FILE_MACHINE_$(EFI_ZBOOT_MACH_TYPE) \ 44a0509109SArd Biesheuvel -DZBOOT_EFI_PATH="\"$(realpath $(obj)/vmlinuz.efi.elf)\"" \ 45bca2f3a9SArd Biesheuvel -DZBOOT_SIZE_LEN=$(zboot-size-len-y) \ 46538bc0f4SArd Biesheuvel -DCOMP_TYPE="\"$(comp-type-y)\"" \ 47538bc0f4SArd Biesheuvel $(aflags-zboot-header-y) 48a0509109SArd Biesheuvel 49a0509109SArd Biesheuvel$(obj)/zboot-header.o: $(srctree)/drivers/firmware/efi/libstub/zboot-header.S FORCE 50a0509109SArd Biesheuvel $(call if_changed_rule,as_o_S) 51a0509109SArd Biesheuvel 52a0509109SArd BiesheuvelZBOOT_DEPS := $(obj)/zboot-header.o $(objtree)/drivers/firmware/efi/libstub/lib.a 53a0509109SArd Biesheuvel 54a0509109SArd BiesheuvelLDFLAGS_vmlinuz.efi.elf := -T $(srctree)/drivers/firmware/efi/libstub/zboot.lds 55a0509109SArd Biesheuvel$(obj)/vmlinuz.efi.elf: $(obj)/vmlinuz.o $(ZBOOT_DEPS) FORCE 56a0509109SArd Biesheuvel $(call if_changed,ld) 57a0509109SArd Biesheuvel 58f57fb375SArd BiesheuvelOBJCOPYFLAGS_vmlinuz.efi := -O binary 59f57fb375SArd Biesheuvel$(obj)/vmlinuz.efi: $(obj)/vmlinuz.efi.elf FORCE 60a0509109SArd Biesheuvel $(call if_changed,objcopy) 61a0509109SArd Biesheuvel 62bca2f3a9SArd Biesheuveltargets += zboot-header.o vmlinux.bin vmlinuz vmlinuz.o vmlinuz.efi.elf vmlinuz.efi 63