mb/starlabs/{lite_adl,byte_adl}: Don't select MAINBOARD_HAS_TPM2
[coreboot2.git] / src / arch / riscv / Makefile.mk
blob51ed016653b8ea16f606ed92cad4ad5519ce4b33
1 ## SPDX-License-Identifier: GPL-2.0-only
3 ################################################################################
4 ## RISC-V specific options
5 ################################################################################
6 ifeq ($(CONFIG_ARCH_RISCV),y)
8 ifeq ($(CONFIG_ARCH_RAMSTAGE_RISCV),y)
9 check-ramstage-overlap-regions += stack
10 endif
12 riscv_flags = -I$(src)/arch/riscv/
14 ifeq ($(CONFIG_ARCH_RISCV_RV64),y)
15 _rv_flags += -D__riscv -D__riscv_xlen=64 -D__riscv_flen=64
16 else
17 ifeq ($(CONFIG_ARCH_RISCV_RV32),y)
18 _rv_flags += -D__riscv -D__riscv_xlen=32 -D__riscv_flen=32
19 else
20 $(error "You need to select ARCH_RISCV_RV64 or ARCH_RISCV_RV32")
21 endif
22 endif
24 # Needed for -print-libgcc-file-name which gets confused about all those arch
25 # suffixes in ARCH_SUFFIX_riscv.
26 simple_riscv_flags = $(riscv_flags)
28 ifeq ($(CONFIG_COMPILER_GCC),y)
29 MARCH_SUFFIX=$(ARCH_SUFFIX_riscv)
30 else
31 MARCH_SUFFIX=
32 endif
34 ifeq ($(CCC_ANALYZER_OUTPUT_FORMAT),)
35 riscv_flags += -march=$(CONFIG_RISCV_ARCH)$(MARCH_SUFFIX) -mabi=$(CONFIG_RISCV_ABI) -mcmodel=$(CONFIG_RISCV_CODEMODEL)
36 simple_riscv_flags += -march=$(CONFIG_RISCV_ARCH) -mabi=$(CONFIG_RISCV_ABI) -mcmodel=$(CONFIG_RISCV_CODEMODEL)
37 else
38 riscv_flags += $(_rv_flags)
39 simple_riscv_flags += $(_rv_flags)
40 endif
42 riscv_asm_flags = -march=$(CONFIG_RISCV_ARCH)$(MARCH_SUFFIX) -mabi=$(CONFIG_RISCV_ABI)
44 COMPILER_RT_bootblock = $(shell $(GCC_bootblock) $(simple_riscv_flags) -print-libgcc-file-name)
46 COMPILER_RT_romstage = $(shell $(GCC_romstage) $(simple_riscv_flags) -print-libgcc-file-name)
48 COMPILER_RT_ramstage = $(shell $(GCC_ramstage) $(simple_riscv_flags) -print-libgcc-file-name)
50 ## All stages
52 all-y += trap_util.S
53 all-y += trap_handler.c
54 all-y += fp_asm.S
55 all-y += sbi.c
56 all-y += mcall.c
57 all-y += virtual_memory.c
58 all-y += boot.c
59 all-y += smp.c
60 all-y += misc.c
61 all-$(CONFIG_ARCH_RISCV_PMP) += pmp.c
62 all-y += \
63 $(top)/src/lib/memchr.c \
64 $(top)/src/lib/memcmp.c \
65 $(top)/src/lib/memcpy.c \
66 $(top)/src/lib/memmove.c \
67 $(top)/src/lib/memset.c
68 all-$(CONFIG_RISCV_USE_ARCH_TIMER) += arch_timer.c
71 ################################################################################
72 ## bootblock
73 ################################################################################
74 ifeq ($(CONFIG_ARCH_BOOTBLOCK_RISCV),y)
76 bootblock-y = bootblock.S
78 $(eval $(call link_stage,bootblock))
80 bootblock-c-ccopts += $(riscv_flags)
81 bootblock-S-ccopts += $(riscv_asm_flags)
83 ifeq ($(CONFIG_ARCH_RISCV_RV32),y)
84 LDFLAGS_bootblock += -m elf32lriscv
85 endif #CONFIG_ARCH_RISCV_RV32
87 endif #CONFIG_ARCH_BOOTBLOCK_RISCV
89 ################################################################################
90 ## romstage
91 ################################################################################
92 ifeq ($(CONFIG_ARCH_ROMSTAGE_RISCV),y)
94 romstage-$(CONFIG_SEPARATE_ROMSTAGE) += romstage.S
96 # Build the romstage
98 $(eval $(call link_stage,romstage))
100 romstage-c-ccopts += $(riscv_flags)
101 romstage-S-ccopts += $(riscv_asm_flags)
103 ifeq ($(CONFIG_ARCH_RISCV_RV32),y)
104 LDFLAGS_romstage += -m elf32lriscv
105 endif #CONFIG_ARCH_RISCV_RV32
107 endif #CONFIG_ARCH_ROMSTAGE_RISCV
109 ################################################################################
110 ## ramstage
111 ################################################################################
112 ifeq ($(CONFIG_ARCH_RAMSTAGE_RISCV),y)
114 ramstage-y =
115 ramstage-y += ramstage.S
116 ramstage-y += tables.c
117 ramstage-y += payload.c
118 ramstage-y += fit_payload.c
120 $(eval $(call create_class_compiler,rmodules,riscv))
122 ramstage-srcs += src/mainboard/$(MAINBOARDDIR)/mainboard.c
124 # Build the ramstage
126 $(eval $(call link_stage,ramstage))
128 ramstage-c-ccopts += $(riscv_flags)
129 ramstage-S-ccopts += $(riscv_asm_flags)
131 ifeq ($(CONFIG_ARCH_RISCV_RV32),y)
132 LDFLAGS_ramstage += -m elf32lriscv
133 endif #CONFIG_ARCH_RISCV_RV32
135 endif #CONFIG_ARCH_RAMSTAGE_RISCV
137 ifeq ($(CONFIG_RISCV_OPENSBI),y)
139 OPENSBI_SOURCE := $(top)/3rdparty/opensbi
140 OPENSBI_BUILD := $(abspath $(obj)/3rdparty/opensbi)
141 OPENSBI_TARGET := $(OPENSBI_BUILD)/platform/$(CONFIG_OPENSBI_PLATFORM)/firmware/fw_dynamic.elf
142 OPENSBI := $(obj)/opensbi.elf
144 # TODO: Building with clang has troubles finding the proper linker.
145 # Always use GCC for now.
146 $(OPENSBI_TARGET): $(obj)/config.h | $(OPENSBI_SOURCE)
147 printf " MAKE $(subst $(obj)/,,$(@))\n"
148 mkdir -p $(OPENSBI_BUILD)
149 $(MAKE) \
150 -C "$(OPENSBI_SOURCE)" \
151 CC="$(GCC_ramstage) -fno-builtin" \
152 LD="$(LD_ramstage)" \
153 OBJCOPY="$(OBJCOPY_ramstage)" \
154 AR="$(AR_ramstage)" \
155 PLATFORM=$(CONFIG_OPENSBI_PLATFORM) \
156 O="$(OPENSBI_BUILD)" \
157 FW_JUMP=n \
158 FW_DYNAMIC=y \
159 FW_PAYLOAD=n \
160 FW_TEXT_START=$(CONFIG_OPENSBI_TEXT_START)
162 $(OPENSBI): $(OPENSBI_TARGET)
163 cp $< $@
165 OPENSBI_CBFS := $(CONFIG_CBFS_PREFIX)/opensbi
166 $(OPENSBI_CBFS)-file := $(OPENSBI)
167 $(OPENSBI_CBFS)-type := payload
168 $(OPENSBI_CBFS)-compression := $(CBFS_COMPRESS_FLAG)
169 cbfs-files-y += $(OPENSBI_CBFS)
171 check-ramstage-overlap-files += $(OPENSBI_CBFS)
173 ramstage-y += opensbi.c
175 endif #CONFIG_RISCV_OPENSBI
177 endif #CONFIG_ARCH_RISCV