Skip to content

Commit 2627f91

Browse files
committed
cmake: toolchain: add support for Andes GCC and Clang
Add support for the Andes GCC / Andes Clang toolchains. Enable by setting: - ZEPHYR_TOOLCHAIN_VARIANT=[andes|andes-clang] - ANDES_TOOLCHAIN_PATH=/path/to/nds32le-elf-newlib-v5 Detect Andes toolchain name using matching: nds[32|64]le-elf-[newlib|mculib]-[v5|v5e|v5f|v5d] Where ISA=nds[32|64]le, libc=[newlib|mculib], ISA/ABI=[v5|v5e|v5f|v5d]. Signed-off-by: Jimmy Zheng <jimmyzhe@andestech.com>
1 parent f1372ac commit 2627f91

File tree

13 files changed

+144
-5
lines changed

13 files changed

+144
-5
lines changed

boards/andestech/adp_xc7k_ae350/adp_xc7k_ae350.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ type: mcu
44
arch: riscv
55
toolchain:
66
- zephyr
7+
- andes
8+
- andes-clang
79
- cross-compile
810
ram: 512
911
supported:

boards/andestech/adp_xc7k_ae350/adp_xc7k_ae350_clic.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ type: mcu
44
arch: riscv
55
toolchain:
66
- zephyr
7+
- andes
8+
- andes-clang
79
- cross-compile
810
ram: 512
911
supported:

boards/telink/tlsr9518adk80d/tlsr9518adk80d.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ name: Telink TLSR9518ADK80D
33
type: mcu
44
arch: riscv
55
toolchain:
6-
- cross-compile
76
- zephyr
7+
- andes
8+
- andes-clang
9+
- cross-compile
810
ram: 128
911
flash: 1024
1012
supported:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2025 Andes Technology Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
choice LLVM_LINKER
5+
prompt "LLVM Linker"
6+
default LLVM_USE_LLD
7+
8+
config LLVM_USE_LD
9+
bool "GNU ld"
10+
help
11+
Use binutils ld linker with llvm/clang.
12+
13+
config LLVM_USE_LLD
14+
bool "LLVM lld"
15+
help
16+
Use LLVM built-in lld linker with llvm/clang.
17+
18+
endchoice
19+
20+
config TOOLCHAIN_ANDES_CLANG_SUPPORTS_THREAD_LOCAL_STORAGE
21+
def_bool y
22+
select TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE
23+
select THREAD_LOCAL_STORAGE if CPP
24+
25+
config TOOLCHAIN_ANDES_CLANG_SUPPORTS_GNU_EXTENSIONS
26+
def_bool y
27+
select TOOLCHAIN_SUPPORTS_GNU_EXTENSIONS
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2025 Andes Technology Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config PICOLIBC_SUPPORTED
5+
default n
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
include(${ZEPHYR_BASE}/cmake/toolchain/andes/common.cmake)
4+
5+
set(COMPILER andes-clang)
6+
if(CONFIG_LLVM_USE_LLD)
7+
set(LINKER lld)
8+
else()
9+
set(LINKER ld)
10+
endif()
11+
set(BINTOOLS gnu)
12+
13+
message(STATUS "Found toolchain: andes clang (${ANDES_TOOLCHAIN_PATH})")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
# This file intentionally left blank.

cmake/toolchain/andes/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2025 Andes Technology Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config TOOLCHAIN_ANDES_SUPPORTS_THREAD_LOCAL_STORAGE
5+
def_bool y
6+
select TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE
7+
select THREAD_LOCAL_STORAGE if CPP
8+
9+
config TOOLCHAIN_ANDES_SUPPORTS_GNU_EXTENSIONS
10+
def_bool y
11+
select TOOLCHAIN_SUPPORTS_GNU_EXTENSIONS
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2025 Andes Technology Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config PICOLIBC_SUPPORTED
5+
default n

cmake/toolchain/andes/common.cmake

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
zephyr_get(ANDES_TOOLCHAIN_PATH)
4+
assert(ANDES_TOOLCHAIN_PATH "ANDES_TOOLCHAIN_PATH is not set")
5+
6+
if(NOT EXISTS ${ANDES_TOOLCHAIN_PATH})
7+
message(FATAL_ERROR "Nothing found at ANDES_TOOLCHAIN_PATH: '${ANDES_TOOLCHAIN_PATH}'")
8+
endif()
9+
10+
set(TOOLCHAIN_HOME ${ANDES_TOOLCHAIN_PATH})
11+
12+
# Andes toolchain naming rule:
13+
# nds[32|64]-[elf|linux]-[mculib|newlib|glibc]-[v5e|v5|v5f|v5d]
14+
# The kernel configuration must match the toolchain for ABI
15+
cmake_path(GET ANDES_TOOLCHAIN_PATH FILENAME TOOLCHAIN_BASENAME)
16+
17+
string(REPLACE "-" ";" TOOLCHAIN_PARTS "${TOOLCHAIN_BASENAME}")
18+
list(GET TOOLCHAIN_PARTS 0 TOOLCHAIN_ARCH) # nds32le / nds64le
19+
list(GET TOOLCHAIN_PARTS 1 TOOLCHAIN_ENV) # elf / linux
20+
list(GET TOOLCHAIN_PARTS 2 TOOLCHAIN_LIBC) # mculib / newlib / glibc
21+
list(GET TOOLCHAIN_PARTS 3 TOOLCHAIN_ISA) # v5e / v5 / v5f / v5d
22+
23+
# Check toolchain architecture
24+
if(TOOLCHAIN_ARCH STREQUAL "nds32le" AND CONFIG_64BIT)
25+
message(FATAL_ERROR "'${TOOLCHAIN_BASENAME}' (riscv32) requires CONFIG_64BIT=n")
26+
elseif(TOOLCHAIN_ARCH STREQUAL "nds64le" AND NOT CONFIG_64BIT)
27+
message(FATAL_ERROR "'${TOOLCHAIN_BASENAME}' (riscv64) requires CONFIG_64BIT=y")
28+
endif()
29+
30+
# Check toolchain environment
31+
if(NOT TOOLCHAIN_ENV STREQUAL "elf")
32+
message(FATAL_ERROR "'${TOOLCHAIN_BASENAME}' uses '${TOOLCHAIN_ENV}', only 'elf' is supported")
33+
endif()
34+
35+
# Check toolchain libc
36+
if(TOOLCHAIN_LIBC STREQUAL "newlib")
37+
set(TOOLCHAIN_HAS_NEWLIB ON CACHE BOOL "True if toolchain supports newlib")
38+
endif()
39+
40+
# Check toolchain ISA
41+
if(TOOLCHAIN_ISA STREQUAL "v5e" AND NOT CONFIG_RISCV_ISA_RV32E)
42+
message(FATAL_ERROR "'${TOOLCHAIN_BASENAME}' (v5e) requires CONFIG_RISCV_ISA_RV32E=y")
43+
elseif(TOOLCHAIN_ISA STREQUAL "v5" AND CONFIG_FLOAT_HARD)
44+
message(FATAL_ERROR "'${TOOLCHAIN_BASENAME}' (v5) requires CONFIG_FLOAT_HARD=n")
45+
elseif(TOOLCHAIN_ISA STREQUAL "v5f" AND NOT (CONFIG_FLOAT_HARD AND CONFIG_RISCV_ISA_EXT_F))
46+
message(FATAL_ERROR "'${TOOLCHAIN_BASENAME}' (v5f) requires CONFIG_FLOAT_HARD=y and CONFIG_RISCV_ISA_EXT_F=y")
47+
elseif(TOOLCHAIN_ISA STREQUAL "v5d" AND NOT (CONFIG_FLOAT_HARD AND CONFIG_RISCV_ISA_EXT_D))
48+
message(FATAL_ERROR "'${TOOLCHAIN_BASENAME}' (v5d) requires CONFIG_FLOAT_HARD=y and CONFIG_RISCV_ISA_EXT_D=y")
49+
endif()
50+
51+
if(CONFIG_64BIT)
52+
set(triple riscv64-elf)
53+
else()
54+
set(triple riscv32-elf)
55+
endif()
56+
57+
set(CROSS_COMPILE_TARGET ${triple})
58+
set(SYSROOT_TARGET ${triple})
59+
60+
set(CROSS_COMPILE ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-)
61+
set(SYSROOT_DIR ${TOOLCHAIN_HOME}/${SYSROOT_TARGET})

0 commit comments

Comments
 (0)