xref: /openbmc/linux/arch/riscv/purgatory/Makefile (revision 35b288d6)
1# SPDX-License-Identifier: GPL-2.0
2OBJECT_FILES_NON_STANDARD := y
3
4purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o
5purgatory-y += strcmp.o strlen.o strncmp.o
6
7targets += $(purgatory-y)
8PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
9
10$(obj)/string.o: $(srctree)/lib/string.c FORCE
11	$(call if_changed_rule,cc_o_c)
12
13$(obj)/ctype.o: $(srctree)/lib/ctype.c FORCE
14	$(call if_changed_rule,cc_o_c)
15
16$(obj)/memcpy.o: $(srctree)/arch/riscv/lib/memcpy.S FORCE
17	$(call if_changed_rule,as_o_S)
18
19$(obj)/memset.o: $(srctree)/arch/riscv/lib/memset.S FORCE
20	$(call if_changed_rule,as_o_S)
21
22$(obj)/strcmp.o: $(srctree)/arch/riscv/lib/strcmp.S FORCE
23	$(call if_changed_rule,as_o_S)
24
25$(obj)/strlen.o: $(srctree)/arch/riscv/lib/strlen.S FORCE
26	$(call if_changed_rule,as_o_S)
27
28$(obj)/strncmp.o: $(srctree)/arch/riscv/lib/strncmp.S FORCE
29	$(call if_changed_rule,as_o_S)
30
31$(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
32	$(call if_changed_rule,cc_o_c)
33
34CFLAGS_sha256.o := -D__DISABLE_EXPORTS
35CFLAGS_string.o := -D__DISABLE_EXPORTS
36CFLAGS_ctype.o := -D__DISABLE_EXPORTS
37
38# When linking purgatory.ro with -r unresolved symbols are not checked,
39# also link a purgatory.chk binary without -r to check for unresolved symbols.
40PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib
41LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS)
42LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS)
43targets += purgatory.ro purgatory.chk
44
45# Sanitizer, etc. runtimes are unavailable and cannot be linked here.
46GCOV_PROFILE	:= n
47KASAN_SANITIZE	:= n
48UBSAN_SANITIZE	:= n
49KCSAN_SANITIZE	:= n
50KCOV_INSTRUMENT := n
51
52# These are adjustments to the compiler flags used for objects that
53# make up the standalone purgatory.ro
54
55PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
56PURGATORY_CFLAGS := -mcmodel=medany -ffreestanding -fno-zero-initialized-in-bss
57PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
58PURGATORY_CFLAGS += -fno-stack-protector -g0
59
60# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
61# in turn leaves some undefined symbols like __fentry__ in purgatory and not
62# sure how to relocate those.
63ifdef CONFIG_FUNCTION_TRACER
64PURGATORY_CFLAGS_REMOVE		+= $(CC_FLAGS_FTRACE)
65endif
66
67ifdef CONFIG_STACKPROTECTOR
68PURGATORY_CFLAGS_REMOVE		+= -fstack-protector
69endif
70
71ifdef CONFIG_STACKPROTECTOR_STRONG
72PURGATORY_CFLAGS_REMOVE		+= -fstack-protector-strong
73endif
74
75CFLAGS_REMOVE_purgatory.o	+= $(PURGATORY_CFLAGS_REMOVE)
76CFLAGS_purgatory.o		+= $(PURGATORY_CFLAGS)
77
78CFLAGS_REMOVE_sha256.o		+= $(PURGATORY_CFLAGS_REMOVE)
79CFLAGS_sha256.o			+= $(PURGATORY_CFLAGS)
80
81CFLAGS_REMOVE_string.o		+= $(PURGATORY_CFLAGS_REMOVE)
82CFLAGS_string.o			+= $(PURGATORY_CFLAGS)
83
84CFLAGS_REMOVE_ctype.o		+= $(PURGATORY_CFLAGS_REMOVE)
85CFLAGS_ctype.o			+= $(PURGATORY_CFLAGS)
86
87asflags-remove-y		+= $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x))
88
89$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
90		$(call if_changed,ld)
91
92$(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE
93		$(call if_changed,ld)
94
95$(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk
96
97obj-y += kexec-purgatory.o
98