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
23$(obj)/vmlinuz: $(obj)/$(EFI_ZBOOT_PAYLOAD) FORCE
24	$(call if_changed,$(zboot-method-y))
25
26OBJCOPYFLAGS_vmlinuz.o := -I binary -O $(EFI_ZBOOT_BFD_TARGET) \
27			  --rename-section .data=.gzdata,load,alloc,readonly,contents
28$(obj)/vmlinuz.o: $(obj)/vmlinuz FORCE
29	$(call if_changed,objcopy)
30
31AFLAGS_zboot-header.o += -DMACHINE_TYPE=IMAGE_FILE_MACHINE_$(EFI_ZBOOT_MACH_TYPE) \
32			 -DZBOOT_EFI_PATH="\"$(realpath $(obj)/vmlinuz.efi.elf)\"" \
33			 -DZBOOT_SIZE_LEN=$(zboot-size-len-y) \
34			 -DCOMP_TYPE="\"$(comp-type-y)\""
35
36$(obj)/zboot-header.o: $(srctree)/drivers/firmware/efi/libstub/zboot-header.S FORCE
37	$(call if_changed_rule,as_o_S)
38
39ZBOOT_DEPS := $(obj)/zboot-header.o $(objtree)/drivers/firmware/efi/libstub/lib.a
40
41LDFLAGS_vmlinuz.efi.elf := -T $(srctree)/drivers/firmware/efi/libstub/zboot.lds
42$(obj)/vmlinuz.efi.elf: $(obj)/vmlinuz.o $(ZBOOT_DEPS) FORCE
43	$(call if_changed,ld)
44
45OBJCOPYFLAGS_vmlinuz.efi := -O binary
46$(obj)/vmlinuz.efi: $(obj)/vmlinuz.efi.elf FORCE
47	$(call if_changed,objcopy)
48
49targets += zboot-header.o vmlinuz vmlinuz.o vmlinuz.efi.elf vmlinuz.efi
50