2022-05-02 01:08:16 +02:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
# to be include'd by arch/$(ARCH)/boot/Makefile after setting
|
2023-04-18 15:49:51 +02:00
|
|
|
# EFI_ZBOOT_PAYLOAD, EFI_ZBOOT_BFD_TARGET, EFI_ZBOOT_MACH_TYPE and
|
|
|
|
# EFI_ZBOOT_FORWARD_CFI
|
2022-05-02 01:08:16 +02:00
|
|
|
|
2023-04-18 15:49:50 +02:00
|
|
|
quiet_cmd_copy_and_pad = PAD $@
|
efi/libstub: zboot: do not use $(shell ...) in cmd_copy_and_pad
You do not need to use $(shell ...) in recipe lines, as they are already
executed in a shell. An alternative solution is $$(...), which is an
escaped sequence of the shell's command substituion, $(...).
For this case, there is a reason to avoid $(shell ...).
Kbuild detects command changes by using the if_changed macro, which
compares the previous command recorded in .*.cmd with the current
command from Makefile. If they differ, Kbuild re-runs the build rule.
To diff the commands, Make must expand $(shell ...) first. It means that
hexdump is executed every time, even when nothing needs rebuilding. If
Kbuild determines that vmlinux.bin needs rebuilding, hexdump will be
executed again to evaluate the 'cmd' macro, one more time to really
build vmlinux.bin, and finally yet again to record the expanded command
into .*.cmd.
Replace $(shell ...) with $$(...) to avoid multiple, unnecessay shell
evaluations. Since Make is agnostic about the shell code, $(...), the
if_changed macro compares the string "$(hexdump -s16 -n4 ...)" verbatim,
so hexdump is run only for building vmlinux.bin.
For the same reason, $(shell ...) in EFI_ZBOOT_OBJCOPY_FLAGS should be
eliminated.
While I was here, I replaced '&&' with ';' because a command for
if_changed is executed with 'set -e'.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20231218080127.907460-1-masahiroy@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
2023-12-18 17:01:27 +09:00
|
|
|
cmd_copy_and_pad = cp $< $@; \
|
|
|
|
truncate -s $$(hexdump -s16 -n4 -e '"%u"' $<) $@
|
2023-04-18 15:49:50 +02:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
# 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.
|
2024-12-06 11:41:40 +01:00
|
|
|
comp-type-y := gzip
|
|
|
|
zboot-method-y := gzip
|
|
|
|
zboot-size-len-y := 0
|
2023-04-18 15:49:50 +02:00
|
|
|
|
2024-12-06 11:41:40 +01:00
|
|
|
comp-type-$(CONFIG_KERNEL_ZSTD) := zstd
|
|
|
|
zboot-method-$(CONFIG_KERNEL_ZSTD) := zstd22_with_size
|
|
|
|
zboot-size-len-$(CONFIG_KERNEL_ZSTD) := 4
|
2022-05-02 01:08:16 +02:00
|
|
|
|
2023-04-18 15:49:50 +02:00
|
|
|
$(obj)/vmlinuz: $(obj)/vmlinux.bin FORCE
|
2023-04-18 15:49:52 +02:00
|
|
|
$(call if_changed,$(zboot-method-y))
|
2022-05-02 01:08:16 +02:00
|
|
|
|
2023-05-22 08:24:49 +02:00
|
|
|
# avoid eager evaluation to prevent references to non-existent build artifacts
|
|
|
|
OBJCOPYFLAGS_vmlinuz.o = -I binary -O $(EFI_ZBOOT_BFD_TARGET) $(EFI_ZBOOT_OBJCOPY_FLAGS) \
|
2022-10-17 12:48:46 +02:00
|
|
|
--rename-section .data=.gzdata,load,alloc,readonly,contents
|
2022-05-02 01:08:16 +02:00
|
|
|
$(obj)/vmlinuz.o: $(obj)/vmlinuz FORCE
|
|
|
|
$(call if_changed,objcopy)
|
|
|
|
|
2023-04-18 15:49:51 +02:00
|
|
|
aflags-zboot-header-$(EFI_ZBOOT_FORWARD_CFI) := \
|
|
|
|
-DPE_DLL_CHAR_EX=IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT
|
|
|
|
|
2022-05-02 01:08:16 +02:00
|
|
|
AFLAGS_zboot-header.o += -DMACHINE_TYPE=IMAGE_FILE_MACHINE_$(EFI_ZBOOT_MACH_TYPE) \
|
arm64: fix unnecessary rebuilding when CONFIG_DEBUG_EFI=y
When CONFIG_DEBUG_EFI is enabled, some objects are needlessly rebuilt.
[Steps to reproduce]
Enable CONFIG_DEBUG_EFI and run 'make' twice in a clean source tree.
On the second run, arch/arm64/kernel/head.o is rebuilt even though
no files have changed.
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- clean
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
[ snip ]
$ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
CALL scripts/checksyscalls.sh
AS arch/arm64/kernel/head.o
AR arch/arm64/kernel/built-in.a
AR arch/arm64/built-in.a
AR built-in.a
[ snip ]
The issue is caused by the use of the $(realpath ...) function.
At the time arch/arm64/kernel/Makefile is parsed on the first run,
$(objtree)/vmlinux does not exist. As a result,
$(realpath $(objtree)/vmlinux) expands to an empty string.
On the second run of Make, $(objtree)/vmlinux already exists, so
$(realpath $(objtree)/vmlinux) expands to the absolute path of vmlinux.
However, this change in the command line causes arch/arm64/kernel/head.o
to be rebuilt.
To address this issue, use $(abspath ...) instead, which does not require
the file to exist. While $(abspath ...) does not resolve symlinks, this
should be fine from a debugging perspective.
The GNU Make manual [1] clearly explains the difference between the two:
$(realpath names...)
For each file name in names return the canonical absolute name.
A canonical name does not contain any . or .. components, nor any
repeated path separators (/) or symlinks. In case of a failure the
empty string is returned. Consult the realpath(3) documentation for
a list of possible failure causes.
$(abspath namees...)
For each file name in names return an absolute name that does not
contain any . or .. components, nor any repeated path separators (/).
Note that, in contrast to realpath function, abspath does not resolve
symlinks and does not require the file names to refer to an existing
file or directory. Use the wildcard function to test for existence.
The same problem exists in drivers/firmware/efi/libstub/Makefile.zboot.
On the first run of Make, $(obj)/vmlinuz.efi.elf does not exist when the
Makefile is parsed, so -DZBOOT_EFI_PATH is set to an empty string.
Replace $(realpath ...) with $(abspath ...) there as well.
[1]: https://www.gnu.org/software/make/manual/make.html#File-Name-Functions
Fixes: 757b435aaabe ("efi: arm64: Add vmlinux debug link to the Image binary")
Fixes: a050910972bb ("efi/libstub: implement generic EFI zboot")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20250625125555.2504734-1-masahiroy@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
2025-06-25 21:55:20 +09:00
|
|
|
-DZBOOT_EFI_PATH="\"$(abspath $(obj)/vmlinuz.efi.elf)\"" \
|
2023-04-18 15:49:50 +02:00
|
|
|
-DZBOOT_SIZE_LEN=$(zboot-size-len-y) \
|
2023-04-18 15:49:51 +02:00
|
|
|
-DCOMP_TYPE="\"$(comp-type-y)\"" \
|
|
|
|
$(aflags-zboot-header-y)
|
2022-05-02 01:08:16 +02:00
|
|
|
|
|
|
|
$(obj)/zboot-header.o: $(srctree)/drivers/firmware/efi/libstub/zboot-header.S FORCE
|
|
|
|
$(call if_changed_rule,as_o_S)
|
|
|
|
|
2025-05-13 14:58:07 +02:00
|
|
|
ifneq ($(CONFIG_EFI_SBAT_FILE),)
|
|
|
|
$(obj)/zboot-header.o: $(CONFIG_EFI_SBAT_FILE)
|
|
|
|
endif
|
|
|
|
|
2022-05-02 01:08:16 +02:00
|
|
|
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)
|
|
|
|
|
2022-10-17 12:48:46 +02:00
|
|
|
OBJCOPYFLAGS_vmlinuz.efi := -O binary
|
|
|
|
$(obj)/vmlinuz.efi: $(obj)/vmlinuz.efi.elf FORCE
|
2022-05-02 01:08:16 +02:00
|
|
|
$(call if_changed,objcopy)
|
|
|
|
|
2023-04-18 15:49:50 +02:00
|
|
|
targets += zboot-header.o vmlinux.bin vmlinuz vmlinuz.o vmlinuz.efi.elf vmlinuz.efi
|