Skip to content

Commit cdb9166

Browse files
dcpleungmmahadevan108
authored andcommitted
cmake: toolchain/xcc,xt-clang: env vars for multiple cores
To use Xtensa toolchain, various environment variables must be set so the executables can find necessary files and what core to compile for. This becomes an annoyance when you have to test multiple boards with different cores. You have to use one set of environment variables per core. Twister cannot test them all in one setting, and it is especially annoying doing west builds. So enhance the environment variables handling so that TOOLCHAIN_VER and XTENSA_CORE can be replaced by TOOLCHAIN_VAR_<board> and XTENSA_CORE_<board> where <board> is the normalized board target (think <board>.yaml). CMake will then figure out the core ID for the toolchain to use. Signed-off-by: Daniel Leung <[email protected]>
1 parent 59b2163 commit cdb9166

File tree

4 files changed

+62
-15
lines changed

4 files changed

+62
-15
lines changed

arch/xtensa/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ set(CORE_ISA_DM ${CMAKE_BINARY_DIR}/zephyr/include/generated/zephyr/core-isa-dM.
5353
set(CORE_ISA_IN ${CMAKE_BINARY_DIR}/zephyr/include/generated/core-isa-dM.c)
5454
file(WRITE ${CORE_ISA_IN} "#include <xtensa/config/core-isa.h>\n")
5555
add_custom_command(OUTPUT ${CORE_ISA_DM}
56-
COMMAND ${CMAKE_C_COMPILER} -E -dM -U__XCC__
56+
COMMAND ${CMAKE_C_COMPILER} -E -dM -U__XCC__ ${XTENSA_CORE_LOCAL_C_FLAG}
5757
-I${ZEPHYR_XTENSA_MODULE_DIR}/zephyr/soc/${CONFIG_SOC}
5858
-I${SOC_FULL_DIR}
5959
${CORE_ISA_IN} -o ${CORE_ISA_DM})

cmake/compiler/xcc/generic.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ TOOLCHAIN_VER: ${TOOLCHAIN_VER}
1717
endif()
1818

1919
execute_process(
20-
COMMAND ${CMAKE_C_COMPILER} --version
20+
COMMAND ${CMAKE_C_COMPILER} --version ${XTENSA_CORE_LOCAL_C_FLAG}
2121
RESULT_VARIABLE ret
2222
OUTPUT_VARIABLE stdoutput
2323
)
2424
if(ret)
2525
message(FATAL_ERROR "Executing the below command failed. Are permissions set correctly?
26-
${CMAKE_C_COMPILER} --version
26+
${CMAKE_C_COMPILER} --version ${XTENSA_CORE_LOCAL_C_FLAG}
2727
${stdoutput}
2828
"
2929
)

cmake/toolchain/xcc/common.cmake

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,29 @@ if(NOT EXISTS ${XTENSA_TOOLCHAIN_PATH})
77
message(FATAL_ERROR "Nothing found at XTENSA_TOOLCHAIN_PATH: '${XTENSA_TOOLCHAIN_PATH}'")
88
endif()
99

10-
set(TOOLCHAIN_HOME ${XTENSA_TOOLCHAIN_PATH}/$ENV{TOOLCHAIN_VER}/XtensaTools)
10+
zephyr_get(TOOLCHAIN_VER)
11+
if(DEFINED TOOLCHAIN_VER)
12+
set(XTENSA_TOOLCHAIN_VER ${TOOLCHAIN_VER})
13+
else()
14+
zephyr_get(TOOLCHAIN_VER_${NORMALIZED_BOARD_TARGET})
15+
if(DEFINED TOOLCHAIN_VER_${NORMALIZED_BOARD_TARGET})
16+
set(XTENSA_TOOLCHAIN_VER ${TOOLCHAIN_VER_${NORMALIZED_BOARD_TARGET}})
17+
else()
18+
message(FATAL "Environment variable TOOLCHAIN_VER must be set or given as -DTOOLCHAIN_VER=<var>")
19+
endif()
20+
endif()
21+
22+
zephyr_get(XTENSA_CORE_${NORMALIZED_BOARD_TARGET})
23+
if(DEFINED XTENSA_CORE_${NORMALIZED_BOARD_TARGET})
24+
set(XTENSA_CORE_LOCAL_C_FLAG "--xtensa-core=${XTENSA_CORE_${NORMALIZED_BOARD_TARGET}}")
25+
list(APPEND TOOLCHAIN_C_FLAGS "--xtensa-core=${XTENSA_CORE_${NORMALIZED_BOARD_TARGET}}")
26+
else()
27+
# Not having XTENSA_CORE is not necessarily fatal as
28+
# the toolchain can have a default core configuration to use.
29+
set(XTENSA_CORE_LOCAL_C_FLAG)
30+
endif()
31+
32+
set(TOOLCHAIN_HOME ${XTENSA_TOOLCHAIN_PATH}/${XTENSA_TOOLCHAIN_VER}/XtensaTools)
1133

1234
set(LINKER ld)
1335
set(BINTOOLS gnu)

doc/develop/toolchains/cadence_xcc.rst

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,46 @@ Cadence Tensilica Xtensa C/C++ Compiler (XCC)
3131
* Set :envvar:`ZEPHYR_TOOLCHAIN_VARIANT` to ``xcc`` or ``xt-clang``.
3232
* Set :envvar:`XTENSA_TOOLCHAIN_PATH` to the toolchain installation
3333
directory.
34-
* Set :envvar:`XTENSA_CORE` to the SoC ID where application is being
35-
targeting.
36-
* Set :envvar:`TOOLCHAIN_VER` to the Xtensa SDK version.
34+
35+
* There are two ways to specify the SoC ID and the SDK version to use.
36+
They are mutually exclusive, and cannot be used together.
37+
38+
#. When building for a single SoC:
39+
40+
* Set :envvar:`XTENSA_CORE` to the SoC ID where application is being
41+
targeted.
42+
* Set :envvar:`TOOLCHAIN_VER` to the Xtensa SDK version.
43+
44+
#. When building for multiple SoCs, for each SoC and board combination:
45+
46+
* Set :envvar:`XTENSA_CORE_{normalized_board_target}`
47+
to the SoC ID where application is being targeted.
48+
* Set :envvar:`TOOLCHAIN_VAR_{normalized_board_target}`
49+
to the Xtensa SDK version.
3750

3851
#. For example, assuming the SDK is installed in ``/opt/xtensa``, and
39-
using the SDK for application development on ``intel_adsp_cavs15``,
40-
setup the environment using:
52+
using the SDK for application development on ``intel_adsp/ace15_mtpm``,
53+
setup the environment using the two above mentioned ways:
54+
55+
#. Single SoC:
56+
57+
.. code-block:: console
58+
59+
# Linux
60+
export ZEPHYR_TOOLCHAIN_VARIANT=xt-clang
61+
export XTENSA_TOOLCHAIN_PATH=/opt/xtensa/XtDevTools/install/tools/
62+
export XTENSA_CORE=ace10_LX7HiFi4_2022_10
63+
export TOOLCHAIN_VER=RI-2022.10-linux
64+
65+
#. Muiltiple SoCs:
4166

42-
.. code-block:: console
67+
.. code-block:: console
4368
44-
# Linux
45-
export ZEPHYR_TOOLCHAIN_VARIANT=xcc
46-
export XTENSA_TOOLCHAIN_PATH=/opt/xtensa/XtDevTools/install/tools/
47-
export XTENSA_CORE=X6H3SUE_RI_2018_0
48-
export TOOLCHAIN_VER=RI-2018.0-linux
69+
# Linux
70+
export ZEPHYR_TOOLCHAIN_VARIANT=xt-clang
71+
export XTENSA_TOOLCHAIN_PATH=/opt/xtensa/XtDevTools/install/tools/
72+
export TOOLCHAIN_VER_intel_adsp_ace15_mtpm=RI-2022.10-linux
73+
export XTENSA_CORE_intel_adsp_ace15_mtpm=ace10_LX7HiFi4_2022_10
4974
5075
#. To use Clang-based compiler:
5176

0 commit comments

Comments
 (0)