summaryrefslogtreecommitdiff
path: root/drivers/firmware/efi/libstub/Makefile.zboot
blob: 2d78770236049b217a2859894439855dafe31c42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# SPDX-License-Identifier: GPL-2.0

# to be include'd by arch/$(ARCH)/boot/Makefile after setting
# EFI_ZBOOT_PAYLOAD, EFI_ZBOOT_BFD_TARGET and EFI_ZBOOT_MACH_TYPE

quiet_cmd_copy_and_pad = PAD     $@
      cmd_copy_and_pad = cp $< $@ && \
			 truncate -s $(shell hexdump -s16 -n4 -e '"%u"' $<) $@

# Pad the file to the size of the uncompressed image in memory, including BSS
$(obj)/vmlinux.bin: $(obj)/$(EFI_ZBOOT_PAYLOAD) FORCE
	$(call if_changed,copy_and_pad)

comp-type-$(CONFIG_KERNEL_GZIP)		:= gzip
comp-type-$(CONFIG_KERNEL_LZ4)		:= lz4
comp-type-$(CONFIG_KERNEL_LZMA)		:= lzma
comp-type-$(CONFIG_KERNEL_LZO)		:= lzo
comp-type-$(CONFIG_KERNEL_XZ)		:= xzkern
comp-type-$(CONFIG_KERNEL_ZSTD)		:= zstd22

# in GZIP, the appended le32 carrying the uncompressed size is part of the
# format, but in other cases, we just append it at the end for convenience,
# causing the original tools to complain when checking image integrity.
# So disregard it when calculating the payload size in the zimage header.
zboot-method-y                         := $(comp-type-y)_with_size
zboot-size-len-y                       := 12

zboot-method-$(CONFIG_KERNEL_GZIP)     := gzip
zboot-size-len-$(CONFIG_KERNEL_GZIP)   := 8

# Copy the SizeOfHeaders and SizeOfCode fields from the payload to the end of
# the compressed image. Note that this presupposes a PE header offset of 64
# bytes, which is what arm64, RISC-V and LoongArch use.
quiet_cmd_compwithsize = $(quiet_cmd_$(zboot-method-y))
      cmd_compwithsize = $(cmd_$(zboot-method-y)) && ( \
			   dd status=none if=$< bs=4 count=1 skip=37 ; \
			   dd status=none if=$< bs=4 count=1 skip=23 ) >> $@

$(obj)/vmlinuz: $(obj)/vmlinux.bin FORCE
	$(call if_changed,compwithsize)

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

AFLAGS_zboot-header.o += -DMACHINE_TYPE=IMAGE_FILE_MACHINE_$(EFI_ZBOOT_MACH_TYPE) \
			 -DZBOOT_EFI_PATH="\"$(realpath $(obj)/vmlinuz.efi.elf)\"" \
			 -DZBOOT_SIZE_LEN=$(zboot-size-len-y) \
			 -DCOMP_TYPE="\"$(comp-type-y)\""

$(obj)/zboot-header.o: $(srctree)/drivers/firmware/efi/libstub/zboot-header.S FORCE
	$(call if_changed_rule,as_o_S)

ZBOOT_DEPS := $(obj)/zboot-header.o $(objtree)/drivers/firmware/efi/libstub/lib.a

LDFLAGS_vmlinuz.efi.elf := -T $(srctree)/drivers/firmware/efi/libstub/zboot.lds
$(obj)/vmlinuz.efi.elf: $(obj)/vmlinuz.o $(ZBOOT_DEPS) FORCE
	$(call if_changed,ld)

OBJCOPYFLAGS_vmlinuz.efi := -O binary
$(obj)/vmlinuz.efi: $(obj)/vmlinuz.efi.elf FORCE
	$(call if_changed,objcopy)

targets += zboot-header.o vmlinux.bin vmlinuz vmlinuz.o vmlinuz.efi.elf vmlinuz.efi