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