summaryrefslogtreecommitdiff
path: root/scripts/cmake/toolchains
diff options
context:
space:
mode:
authorKshitij Sisodia <kshitij.sisodia@arm.com>2021-05-07 16:08:14 +0100
committerKshitij Sisodia <kshitij.sisodia@arm.com>2021-05-07 17:28:51 +0100
commitf9c19eaa9ab11e4409679fc6d2862c89410493a7 (patch)
treeb791a4c03f1fe986a2ac32593a3dc817ae3f247a /scripts/cmake/toolchains
parent2181d0ac35f30202985a877950c88325ff665f6b (diff)
downloadml-embedded-evaluation-kit-f9c19eaa9ab11e4409679fc6d2862c89410493a7.tar.gz
MLECO-1860: Support for Arm GNU Embedded Toolchain
This patch enables compilation of ML use cases bare-metal applications using Arm GNU Embedded Toolchain. The GNU toolchain can be used instead of the Arm Compiler that was already supported. The GNU toolchain is also set as the default toolchain when building applications for the MPS3 target. Note: The version of GNU toolchain must be 10.2.1 or higher. Change-Id: I5fff242f0f52d2db6c75d292f9fa990df1aec978 Signed-off-by: Kshitij Sisodia <kshitij.sisodia@arm.com>
Diffstat (limited to 'scripts/cmake/toolchains')
-rw-r--r--scripts/cmake/toolchains/bare-metal-armclang.cmake134
-rw-r--r--scripts/cmake/toolchains/bare-metal-gcc.cmake145
-rw-r--r--scripts/cmake/toolchains/native-gcc.cmake52
3 files changed, 331 insertions, 0 deletions
diff --git a/scripts/cmake/toolchains/bare-metal-armclang.cmake b/scripts/cmake/toolchains/bare-metal-armclang.cmake
new file mode 100644
index 0000000..0a86eb6
--- /dev/null
+++ b/scripts/cmake/toolchains/bare-metal-armclang.cmake
@@ -0,0 +1,134 @@
+#----------------------------------------------------------------------------
+# Copyright (c) 2021 Arm Limited. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#----------------------------------------------------------------------------
+# specify the cross compiler
+set(CMAKE_C_COMPILER armclang)
+set(CMAKE_CXX_COMPILER armclang)
+set(CMAKE_C_LINKER_PREFERENCE armlink)
+set(CMAKE_ASM_LINKER_PREFERENCE armlink)
+set(CMAKE_ASM_COMPILER armasm)
+set(CMAKE_ASM_COMPILER_AR armar)
+
+set(CMAKE_CROSSCOMPILING true)
+set(CMAKE_SYSTEM_NAME Generic)
+
+set(MIN_ARM_CLANG_VERSION 6.14)
+
+# Skip compiler test execution
+set(CMAKE_C_COMPILER_WORKS 1)
+set(CMAKE_CXX_COMPILER_WORKS 1)
+set(PLATFORM_HAL 1)
+
+if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
+ set(CMAKE_SYSTEM_PROCESSOR cortex-m55)
+endif()
+
+if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m55)
+ # Flags for cortex-m55
+ set(CPU_COMPILE_DEF CPU_CORTEX_M55)
+ set(CPU_NAME ${CMAKE_SYSTEM_PROCESSOR})
+ set(FLOAT_ABI hard)
+ set(ARM_MATH_DSP 1)
+ set(ARM_MATH_LOOPUNROLL 1)
+ set(CPU_LINK_OPT "--cpu=8.1-M.Main.dsp")
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m33)
+ # Flags for cortex-m33 to go here
+endif()
+
+set(${CPU_COMPILE_DEF} 1)
+
+# Warning options
+add_compile_options(
+ -Wall
+ -Wextra
+ -Wvla)
+
+# General purpose compile options:
+add_compile_options(
+ -funsigned-char
+ -fno-function-sections
+ "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>")
+
+# Arch compile options:
+add_compile_options(
+ -mthumb
+ -mcpu=${CPU_NAME}
+ -mfloat-abi=${FLOAT_ABI}
+ --target=arm-arm-non-eabi
+ -mlittle-endian
+ -MD)
+
+# Compile definitions:
+add_compile_definitions(
+ PLATFORM_HAL=${PLATFORM_HAL}
+ ${CPU_COMPILE_DEF}=1
+ $<$<BOOL:${ARM_MATH_DSP}>:ARM_MATH_DSP>
+ $<$<BOOL:${ARM_MATH_LOOPUNROLL}>:ARM_MATH_LOOPUNROLL>)
+
+# Link options:
+add_link_options(${CPU_LINK_OPT})
+set(CMAKE_ASM_FLAGS "${CPU_LINK_OPT}")
+
+# Warnings to be ignored:
+# L6314W = No section matches pattern
+# L6439W = Multiply defined Global Symbol
+add_link_options(
+ --diag_suppress=L6439W,L6314W
+ --info sizes,totals,unused,veneers
+ --strict
+ --callgraph
+ --load_addr_map_info
+ --xref
+ "$<$<CONFIG:RELEASE>:--no_debug>")
+
+# Function to add a map file output for the linker to dump diagnostic information to.
+function(add_target_map_file TARGET_NAME MAP_FILE_PATH)
+ target_link_options(${TARGET_NAME} PUBLIC
+ --map --symbols --list=${MAP_FILE_PATH})
+endfunction()
+
+# Function to add linker option to use the chosen linker script (scatter file).
+function(add_linker_script SCRIPT_DIR SCRIPT_NAME)
+ set(LINKER_SCRIPT_PATH ${SCRIPT_DIR}/${SCRIPT_NAME}.sct
+ CACHE STRING "Linker script path")
+ if (NOT EXISTS ${LINKER_SCRIPT_PATH})
+ message(FATAL_ERROR "Scatter file not found: ${LINKER_SCRIPT_PATH}")
+ endif()
+ message(STATUS "Using linker script: ${LINKER_SCRIPT_PATH}")
+ add_link_options(--scatter=${LINKER_SCRIPT_PATH})
+endfunction()
+
+# Function to set the command to copy/extract contents from an elf
+# into a binary file.
+function(add_bin_generation_command)
+
+ set(multiValueArgs SECTION_PATTERNS OUTPUT_BIN_NAMES)
+ set(oneValueArgs TARGET_NAME OUTPUT_DIR AXF_PATH)
+ cmake_parse_arguments(PARSED "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ add_custom_command(TARGET ${PARSED_TARGET_NAME}
+ POST_BUILD
+ COMMAND fromelf --bin --output=${PARSED_OUTPUT_DIR}/
+ ${PARSED_AXF_PATH})
+
+endfunction()
+
+# Function to assert the compiler version
+function(enforce_compiler_version)
+ if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_ARM_CLANG_VERSION})
+ message( FATAL_ERROR "Arm compiler version must be ${MIN_ARM_CLANG_VERSION} or greater to support ${CMAKE_SYSTEM_PROCESSOR} architecture." )
+ endif()
+endfunction()
diff --git a/scripts/cmake/toolchains/bare-metal-gcc.cmake b/scripts/cmake/toolchains/bare-metal-gcc.cmake
new file mode 100644
index 0000000..2ffc1bb
--- /dev/null
+++ b/scripts/cmake/toolchains/bare-metal-gcc.cmake
@@ -0,0 +1,145 @@
+#----------------------------------------------------------------------------
+# Copyright (c) 2021 Arm Limited. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#----------------------------------------------------------------------------
+# specify the cross compiler
+set(TRIPLET arm-none-eabi)
+
+set(CMAKE_C_COMPILER ${TRIPLET}-gcc)
+set(CMAKE_CXX_COMPILER ${TRIPLET}-g++)
+
+set(CMAKE_CROSSCOMPILING true)
+set(CMAKE_SYSTEM_NAME Generic)
+
+set(MIN_GCC_VERSION 10.2.1)
+
+# Skip compiler test execution
+set(CMAKE_C_COMPILER_WORKS 1)
+set(CMAKE_CXX_COMPILER_WORKS 1)
+set(PLATFORM_HAL 1)
+
+if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
+ set(CMAKE_SYSTEM_PROCESSOR cortex-m55)
+endif()
+
+if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m55)
+ # Flags for cortex-m55
+ set(CPU_COMPILE_DEF CPU_CORTEX_M55)
+ set(CPU_NAME ${CMAKE_SYSTEM_PROCESSOR})
+ set(FLOAT_ABI hard)
+ set(ARM_MATH_DSP 1)
+ set(ARM_MATH_LOOPUNROLL 1)
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m33)
+ # Flags for cortex-m33 to go here
+endif()
+
+set(${CPU_COMPILE_DEF} 1)
+
+# Warning options
+add_compile_options(
+ -Wall
+ -Wextra
+ -Wvla
+ -Wno-psabi)
+
+# General purpose compile options:
+add_compile_options(
+ -funsigned-char
+ -fno-function-sections
+ "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>")
+
+# Arch compile options:
+add_compile_options(
+ -mthumb
+ -mcpu=${CPU_NAME}
+ -mfloat-abi=${FLOAT_ABI}
+ -mlittle-endian
+ -MD)
+
+# Compile definitions:
+add_compile_definitions(
+ PLATFORM_HAL=${PLATFORM_HAL}
+ ${CPU_COMPILE_DEF}=1
+ $<$<BOOL:${ARM_MATH_DSP}>:ARM_MATH_DSP>
+ $<$<BOOL:${ARM_MATH_LOOPUNROLL}>:ARM_MATH_LOOPUNROLL>)
+
+# Link options:
+add_link_options(
+ -mthumb
+ -mcpu=${CPU_NAME}
+ -mfloat-abi=${FLOAT_ABI}
+ -mlittle-endian
+ --specs=nosys.specs
+ --stats
+ "$<$<CONFIG:RELEASE>:--no-debug>")
+
+# Function to add a map file output for the linker to dump diagnostic information to.
+function(add_target_map_file TARGET_NAME MAP_FILE_PATH)
+ target_link_options(${TARGET_NAME} PUBLIC
+ -Xlinker -Map=${MAP_FILE_PATH})
+endfunction()
+
+# Function to add linker option to use the chosen linker script.
+function(add_linker_script SCRIPT_DIR SCRIPT_NAME)
+ set(LINKER_SCRIPT_PATH ${SCRIPT_DIR}/${SCRIPT_NAME}.ld
+ CACHE STRING "Linker script path")
+ if (NOT EXISTS ${LINKER_SCRIPT_PATH})
+ message(FATAL_ERROR "Linker script not found: ${LINKER_SCRIPT_PATH}")
+ endif()
+ message(STATUS "Using linker script: ${LINKER_SCRIPT_PATH}")
+ add_link_options("SHELL:-T ${LINKER_SCRIPT_PATH}")
+endfunction()
+
+# Function to set the command to copy/extract contents from an elf
+# into a binary file.
+function(add_bin_generation_command)
+
+ set(multiValueArgs SECTION_PATTERNS OUTPUT_BIN_NAMES)
+ set(oneValueArgs TARGET_NAME OUTPUT_DIR AXF_PATH)
+ cmake_parse_arguments(PARSED "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ list(LENGTH PARSED_SECTION_PATTERNS N_SECTION_PATTERNS)
+ list(LENGTH PARSED_OUTPUT_BIN_NAMES N_OUTPUT_BIN_NAMES)
+
+ if (NOT ${N_SECTION_PATTERNS} STREQUAL ${N_OUTPUT_BIN_NAMES})
+ message(FATAL_ERROR "Section patterns and the output binary names "
+ "should be of the same length")
+ endif()
+
+ message(STATUS "${TRIPLET}-objcopy requested to generate "
+ "${N_OUTPUT_BIN_NAMES} bin files.")
+
+ math(EXPR MAX_IDX "${N_SECTION_PATTERNS} - 1")
+
+ foreach(IDX RANGE ${MAX_IDX})
+
+ list(GET PARSED_OUTPUT_BIN_NAMES ${IDX} OUTPUT_BIN_NAME)
+ list(GET PARSED_SECTION_PATTERNS ${IDX} SECTION_PATTERN)
+
+ add_custom_command(TARGET ${PARSED_TARGET_NAME}
+ POST_BUILD
+ COMMAND ${TRIPLET}-objcopy -O binary
+ --only-section ${SECTION_PATTERN} ${PARSED_AXF_PATH}
+ ${PARSED_OUTPUT_DIR}/${OUTPUT_BIN_NAME})
+ endforeach()
+
+endfunction()
+
+# Function to assert the compiler version
+function(enforce_compiler_version)
+ if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_GCC_VERSION})
+ message( FATAL_ERROR "arm-none-eabi-gcc version must be ${MIN_GCC_VERSION} or greater to support ${CMAKE_SYSTEM_PROCESSOR} architecture." )
+ endif()
+endfunction()
diff --git a/scripts/cmake/toolchains/native-gcc.cmake b/scripts/cmake/toolchains/native-gcc.cmake
new file mode 100644
index 0000000..4b5a62b
--- /dev/null
+++ b/scripts/cmake/toolchains/native-gcc.cmake
@@ -0,0 +1,52 @@
+#----------------------------------------------------------------------------
+# Copyright (c) 2021 Arm Limited. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#----------------------------------------------------------------------------
+set(CMAKE_CXX_COMPILER g++)
+set(CMAKE_C_COMPILER gcc)
+set(CMAKE_C_LINKER_PREFERENCE gcc)
+set(CMAKE_CXX_LINKER_PREFERENCE gcc)
+
+# Platform specific directory:
+set(PLATFORM_HAL 3)
+
+# Warning compiler definitions:
+add_compile_options(
+ -Wsign-compare
+ -Wshadow
+ -Wextra
+ -Wall
+ -Wunused-function
+ -Wmissing-field-initializers
+ -Wswitch
+ -Wvla
+ -Wunused-parameter)
+
+# General purpose compile definitions:
+add_compile_options(
+ -fPIC
+ -pthread
+ -DPLATFORM_HAL=${PLATFORM_HAL}
+ "$<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>")
+
+# Linker options
+add_link_options(
+ -lm
+ -lc
+ -lstdc++
+ --verbose)
+
+function(enforce_compiler_version)
+endfunction()