|
| 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