xref: /linux/arch/riscv/purgatory/Makefile (revision 788177e76589e6441d43691f1a075feec2e25962)
1736e30afSLi Zhengyu# SPDX-License-Identifier: GPL-2.0
2736e30afSLi ZhengyuOBJECT_FILES_NON_STANDARD := y
3736e30afSLi Zhengyu
4736e30afSLi Zhengyupurgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o
5736e30afSLi Zhengyu
6736e30afSLi Zhengyutargets += $(purgatory-y)
7736e30afSLi ZhengyuPURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
8736e30afSLi Zhengyu
9736e30afSLi Zhengyu$(obj)/string.o: $(srctree)/lib/string.c FORCE
10736e30afSLi Zhengyu	$(call if_changed_rule,cc_o_c)
11736e30afSLi Zhengyu
12736e30afSLi Zhengyu$(obj)/ctype.o: $(srctree)/lib/ctype.c FORCE
13736e30afSLi Zhengyu	$(call if_changed_rule,cc_o_c)
14736e30afSLi Zhengyu
15736e30afSLi Zhengyu$(obj)/memcpy.o: $(srctree)/arch/riscv/lib/memcpy.S FORCE
16736e30afSLi Zhengyu	$(call if_changed_rule,as_o_S)
17736e30afSLi Zhengyu
18736e30afSLi Zhengyu$(obj)/memset.o: $(srctree)/arch/riscv/lib/memset.S FORCE
19736e30afSLi Zhengyu	$(call if_changed_rule,as_o_S)
20736e30afSLi Zhengyu
21736e30afSLi Zhengyu$(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
22736e30afSLi Zhengyu	$(call if_changed_rule,cc_o_c)
23736e30afSLi Zhengyu
24736e30afSLi ZhengyuCFLAGS_sha256.o := -D__DISABLE_EXPORTS
25736e30afSLi ZhengyuCFLAGS_string.o := -D__DISABLE_EXPORTS
26736e30afSLi ZhengyuCFLAGS_ctype.o := -D__DISABLE_EXPORTS
27736e30afSLi Zhengyu
28736e30afSLi Zhengyu# When linking purgatory.ro with -r unresolved symbols are not checked,
29736e30afSLi Zhengyu# also link a purgatory.chk binary without -r to check for unresolved symbols.
30736e30afSLi ZhengyuPURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib
31736e30afSLi ZhengyuLDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS)
32736e30afSLi ZhengyuLDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS)
33736e30afSLi Zhengyutargets += purgatory.ro purgatory.chk
34736e30afSLi Zhengyu
35736e30afSLi Zhengyu# Sanitizer, etc. runtimes are unavailable and cannot be linked here.
36736e30afSLi ZhengyuGCOV_PROFILE	:= n
37736e30afSLi ZhengyuKASAN_SANITIZE	:= n
38736e30afSLi ZhengyuUBSAN_SANITIZE	:= n
39736e30afSLi ZhengyuKCSAN_SANITIZE	:= n
40736e30afSLi ZhengyuKCOV_INSTRUMENT := n
41736e30afSLi Zhengyu
42736e30afSLi Zhengyu# These are adjustments to the compiler flags used for objects that
43736e30afSLi Zhengyu# make up the standalone purgatory.ro
44736e30afSLi Zhengyu
45736e30afSLi ZhengyuPURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
46736e30afSLi ZhengyuPURGATORY_CFLAGS := -mcmodel=medany -ffreestanding -fno-zero-initialized-in-bss
47736e30afSLi ZhengyuPURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
48736e30afSLi ZhengyuPURGATORY_CFLAGS += -fno-stack-protector -g0
49736e30afSLi Zhengyu
50736e30afSLi Zhengyu# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
51736e30afSLi Zhengyu# in turn leaves some undefined symbols like __fentry__ in purgatory and not
52736e30afSLi Zhengyu# sure how to relocate those.
53736e30afSLi Zhengyuifdef CONFIG_FUNCTION_TRACER
54736e30afSLi ZhengyuPURGATORY_CFLAGS_REMOVE		+= $(CC_FLAGS_FTRACE)
55736e30afSLi Zhengyuendif
56736e30afSLi Zhengyu
57736e30afSLi Zhengyuifdef CONFIG_STACKPROTECTOR
58736e30afSLi ZhengyuPURGATORY_CFLAGS_REMOVE		+= -fstack-protector
59736e30afSLi Zhengyuendif
60736e30afSLi Zhengyu
61736e30afSLi Zhengyuifdef CONFIG_STACKPROTECTOR_STRONG
62736e30afSLi ZhengyuPURGATORY_CFLAGS_REMOVE		+= -fstack-protector-strong
63736e30afSLi Zhengyuendif
64736e30afSLi Zhengyu
65736e30afSLi ZhengyuCFLAGS_REMOVE_purgatory.o	+= $(PURGATORY_CFLAGS_REMOVE)
66736e30afSLi ZhengyuCFLAGS_purgatory.o		+= $(PURGATORY_CFLAGS)
67736e30afSLi Zhengyu
68736e30afSLi ZhengyuCFLAGS_REMOVE_sha256.o		+= $(PURGATORY_CFLAGS_REMOVE)
69736e30afSLi ZhengyuCFLAGS_sha256.o			+= $(PURGATORY_CFLAGS)
70736e30afSLi Zhengyu
71736e30afSLi ZhengyuCFLAGS_REMOVE_string.o		+= $(PURGATORY_CFLAGS_REMOVE)
72736e30afSLi ZhengyuCFLAGS_string.o			+= $(PURGATORY_CFLAGS)
73736e30afSLi Zhengyu
74736e30afSLi ZhengyuCFLAGS_REMOVE_ctype.o		+= $(PURGATORY_CFLAGS_REMOVE)
75736e30afSLi ZhengyuCFLAGS_ctype.o			+= $(PURGATORY_CFLAGS)
76736e30afSLi Zhengyu
77736e30afSLi ZhengyuAFLAGS_REMOVE_entry.o		+= -Wa,-gdwarf-2
78736e30afSLi ZhengyuAFLAGS_REMOVE_memcpy.o		+= -Wa,-gdwarf-2
79736e30afSLi ZhengyuAFLAGS_REMOVE_memset.o		+= -Wa,-gdwarf-2
80736e30afSLi Zhengyu
81736e30afSLi Zhengyu$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
82736e30afSLi Zhengyu		$(call if_changed,ld)
83736e30afSLi Zhengyu
84736e30afSLi Zhengyu$(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE
85736e30afSLi Zhengyu		$(call if_changed,ld)
86736e30afSLi Zhengyu
87736e30afSLi Zhengyutargets += kexec-purgatory.c
88736e30afSLi Zhengyu
89736e30afSLi Zhengyuquiet_cmd_bin2c = BIN2C   $@
90736e30afSLi Zhengyu      cmd_bin2c = $(objtree)/scripts/bin2c kexec_purgatory < $< > $@
91736e30afSLi Zhengyu
92736e30afSLi Zhengyu$(obj)/kexec-purgatory.c: $(obj)/purgatory.ro $(obj)/purgatory.chk FORCE
93736e30afSLi Zhengyu	$(call if_changed,bin2c)
94736e30afSLi Zhengyu
95*788177e7SMasahiro Yamadaobj-y += kexec-purgatory.o
96