2018-04-16 19:03:33 +02:00
|
|
|
# Target architecture for the build.
|
2020-09-07 22:21:42 +02:00
|
|
|
|
2020-11-06 09:54:45 +01:00
|
|
|
# The correct triple for 32 bit embedded RISC-V targets is "riscv32-none-elf".
|
|
|
|
# However, is unknown is used as sys (in place of none), it will also fall back
|
|
|
|
# to none. Finally, if the GCC RISC-V cross compiler is compiled with full
|
|
|
|
# multilib support, it can create both 32 bit and 64 bit binaries. Often this is
|
|
|
|
# indicated with "riscv" being used instead of "riscv32/riscv64", but e.g.
|
|
|
|
# Ubuntu uses "riscv64-unknown-elf" despite being able to produce both 32 and
|
|
|
|
# 64 bit binaries. We'll test all possible combinations from the most correct
|
|
|
|
# triple to the least correct triple all that might be able to produce our
|
2024-02-12 20:11:03 +01:00
|
|
|
# binaries.
|
2020-11-06 09:54:45 +01:00
|
|
|
|
|
|
|
_TRIPLES_TO_TEST := \
|
|
|
|
riscv32-none-elf \
|
|
|
|
riscv32-unknown-elf \
|
2022-04-14 17:03:16 +02:00
|
|
|
riscv32-elf \
|
|
|
|
riscv-none-elf \
|
2020-11-06 09:54:45 +01:00
|
|
|
riscv-unknown-elf \
|
2022-04-14 17:03:16 +02:00
|
|
|
riscv-elf \
|
2020-11-06 09:54:45 +01:00
|
|
|
riscv64-none-elf \
|
2022-04-14 17:03:16 +02:00
|
|
|
riscv64-unknown-elf \
|
|
|
|
riscv64-elf
|
2020-11-06 09:54:45 +01:00
|
|
|
|
2022-09-27 10:43:39 +02:00
|
|
|
# Do not test at run time if building with docker: The host may have no
|
|
|
|
# RISC-V toolchain installed or a different one
|
|
|
|
ifeq (1,$(BUILD_IN_DOCKER))
|
2024-02-12 20:11:03 +01:00
|
|
|
TARGET_ARCH_RISCV := riscv-none-elf
|
2022-09-27 10:43:39 +02:00
|
|
|
endif
|
|
|
|
|
2020-11-06 09:54:45 +01:00
|
|
|
TARGET_ARCH_RISCV ?= \
|
|
|
|
$(strip \
|
|
|
|
$(subst -gcc,,\
|
|
|
|
$(notdir \
|
|
|
|
$(word 1,\
|
2023-07-03 15:20:30 +02:00
|
|
|
$(shell which $(addsuffix -gcc,$(_TRIPLES_TO_TEST)) 2> /dev/null)))))
|
2020-09-07 22:21:42 +02:00
|
|
|
|
2020-09-08 22:28:41 +02:00
|
|
|
TARGET_ARCH ?= $(TARGET_ARCH_RISCV)
|
2018-04-16 19:03:33 +02:00
|
|
|
|
2023-07-03 15:20:30 +02:00
|
|
|
# Convert to a simply expanded variable here, as a recursively expended
|
|
|
|
# variable would result in detecting the toolchain each and every time again the
|
|
|
|
# toolchain is referenced.
|
|
|
|
TARGET_ARCH := $(TARGET_ARCH)
|
|
|
|
|
2022-04-19 15:51:31 +02:00
|
|
|
ifeq (,$(TARGET_ARCH))
|
|
|
|
$(error No RISC-V toolchain detected. Make sure a RISC-V toolchain is installed.)
|
|
|
|
endif
|
|
|
|
|
2022-04-14 16:52:48 +02:00
|
|
|
ifeq ($(TOOLCHAIN),gnu)
|
2022-05-13 10:54:30 +02:00
|
|
|
GCC_DEFAULTS_TO_NEW_RISCV_ISA ?= $(shell echo "typedef int dont_be_pedantic;" | $(TARGET_ARCH)-gcc -march=rv32imac -mabi=ilp32 -misa-spec=2.2 -E - > /dev/null 2>&1 && echo 1 || echo 0)
|
2022-04-14 16:52:48 +02:00
|
|
|
endif
|
|
|
|
|
2022-05-13 10:54:30 +02:00
|
|
|
GCC_DEFAULTS_TO_NEW_RISCV_ISA ?= 0
|
|
|
|
|
|
|
|
CFLAGS_CPU := -march=rv32imac -mabi=ilp32
|
2022-04-14 16:52:48 +02:00
|
|
|
|
|
|
|
# Since RISC-V ISA specifications 20191213 instructions previously included in
|
|
|
|
# rv32imac have been moved to the ZICSR extension. See
|
|
|
|
# https://riscv.org/wp-content/uploads/2019/12/riscv-spec-20191213.pdf
|
|
|
|
#
|
2022-05-13 10:54:30 +02:00
|
|
|
# Select the oldest ISA spec in which ZICSR was not yet split out into an
|
|
|
|
# extension
|
|
|
|
ifeq (1,$(GCC_DEFAULTS_TO_NEW_RISCV_ISA))
|
|
|
|
CFLAGS_CPU += -misa-spec=2.2
|
2022-04-14 16:52:48 +02:00
|
|
|
endif
|
|
|
|
|
2023-12-05 09:17:54 +01:00
|
|
|
# Always use riscv32-none-elf as target triple for clang, as some
|
|
|
|
# autodetected gcc target triples are incompatible with clang
|
|
|
|
TARGET_ARCH_LLVM := riscv32-none-elf
|
|
|
|
ifneq ($(TOOLCHAIN),llvm)
|
2020-10-07 09:37:52 +02:00
|
|
|
CFLAGS_CPU += -mcmodel=medlow -msmall-data-limit=8
|
2022-09-27 10:43:39 +02:00
|
|
|
# We cannot invoke the compiler on the host system if build in docker.
|
|
|
|
# Instead, hard-code the required flags for the docker toolchain here
|
|
|
|
ifeq (1,$(BUILD_IN_DOCKER))
|
2021-02-09 10:45:51 +01:00
|
|
|
CFLAGS_CPU += -malign-data=natural
|
2022-09-27 10:43:39 +02:00
|
|
|
else
|
|
|
|
ifneq (,$(shell $(TARGET_ARCH)-gcc --help=target | grep '\-malign-data='))
|
|
|
|
CFLAGS_CPU += -malign-data=natural
|
|
|
|
endif
|
2021-02-09 10:45:51 +01:00
|
|
|
endif
|
2020-10-07 09:37:52 +02:00
|
|
|
endif
|
|
|
|
CFLAGS_LINK = -ffunction-sections -fdata-sections
|
2019-10-21 11:27:21 +02:00
|
|
|
CFLAGS_DBG ?= -g3
|
|
|
|
CFLAGS_OPT ?= -Os
|
2018-04-16 19:03:33 +02:00
|
|
|
|
2020-09-09 21:37:15 +02:00
|
|
|
LINKFLAGS += -L$(RIOTCPU)/$(CPU)/ldscripts -L$(RIOTCPU)/riscv_common/ldscripts
|
2020-01-02 09:51:20 +01:00
|
|
|
LINKER_SCRIPT ?= $(CPU_MODEL).ld
|
|
|
|
LINKFLAGS += -T$(LINKER_SCRIPT)
|
2018-04-16 19:03:33 +02:00
|
|
|
|
2019-08-27 16:06:41 +02:00
|
|
|
CFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) $(CFLAGS_LINK)
|
|
|
|
ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG)
|
2018-04-16 19:03:33 +02:00
|
|
|
# export linker flags
|
2022-05-13 10:54:30 +02:00
|
|
|
LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT) -nostartfiles -Wl,--gc-sections -static -lgcc
|
2021-04-02 18:42:34 +02:00
|
|
|
|
|
|
|
# Platform triple as used by Rust
|
|
|
|
RUST_TARGET = riscv32imac-unknown-none-elf
|