blob: abca62238a43a297a055b9a77a1a356bea4fe00c [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001#----------------------------------------------------------------------------
2# Copyright (c) 2021 Arm Limited. All rights reserved.
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#----------------------------------------------------------------------------
17set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build_baremetal)
18set(PLAT_HAL ${CMAKE_CURRENT_SOURCE_DIR}/source/application/hal/platforms/bare-metal)
19
20# If target platform not defined raise an error
21# TARGET_PLATFORM either should have been defined by the user or set to default value mps3
22if (NOT DEFINED TARGET_PLATFORM)
23 message(FATAL_ERROR "Invalid target platform, specify TARGET_PLATFORM=mps3")
24endif ()
25message(STATUS "target platform ${TARGET_PLATFORM}")
26
27set(SOURCE_GEN_DIR ${CMAKE_BINARY_DIR}/generated/bsp)
28if (NOT DEFINED MEM_PROFILES_SRC_DIR)
29 set(MEM_PROFILES_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/subsystem-profiles)
30endif()
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010031
alexander3c798932021-03-26 21:42:19 +000032set(MEM_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_memmap.h.template)
33set(IRQ_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_irqs.h.template)
34set(MEM_REGIONS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/mem_regions.h.template)
35set(TA_SETTINGS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/timing_adapter_settings.template)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010036set(LINKER_SCRIPT_DIR "${PLAT_HAL}/bsp/mem_layout")
alexander3c798932021-03-26 21:42:19 +000037set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME "libtensorflow-microlite.a")
38set(TENSORFLOW_LITE_MICRO_FLAG "-DTF_LITE_STATIC_MEMORY")
Cisco Cervelleraf085fa52021-08-02 09:32:07 +010039set(ETHOS_U_NPU_FLAG "-DARM_NPU=1")
alexander3c798932021-03-26 21:42:19 +000040
Cisco Cervelleraf085fa52021-08-02 09:32:07 +010041if (ETHOS_U_NPU_ENABLED)
Isabella Gottardi118f73e2021-09-16 17:54:35 +010042
Kshitij Sisodiab59ba682021-11-23 17:19:52 +000043 assert_defined(ETHOS_U_NPU_ID)
44 assert_defined(ETHOS_U_NPU_MEMORY_MODE)
45 assert_defined(ETHOS_U_NPU_CONFIG_ID)
Kshitij Sisodia3be26232021-10-29 12:29:06 +010046
Isabella Gottardi118f73e2021-09-16 17:54:35 +010047 if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only)
48
49 if (ETHOS_U_NPU_ID STREQUAL U55)
50 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY")
51 else ()
52 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `sram_only` can be used only for Ethos-U55.")
53 endif ()
54
55 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram)
56 # Shared Sram can be used for Ethos-U55 and Ethos-U65
57 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM")
58
59 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram)
60 # Dedicated Sram is used only for Ethos-U65
61 if (ETHOS_U_NPU_ID STREQUAL U65)
62 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM")
63 else ()
64 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `dedicated_sram` can be used only for Ethos-U65.")
65 endif ()
66
67 else ()
68 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}")
69 endif ()
70
71 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} ${ETHOS_U_NPU_FLAG} ${ETHOS_U_NPU_MEMORY_MODE_FLAG}")
alexander3c798932021-03-26 21:42:19 +000072endif ()
73
74# Set specific flags depending on target platform and subsystem
75if (TARGET_PLATFORM STREQUAL mps3)
76 set(MPS3_PLATFORM_FLAG "-DMPS3_PLATFORM=1")
77
78 # If target platform is mps3 and subsystem not defined raise an error,
79 # TARGET_SUBSYSTEM either should have been defined by the user or set to a default value
80 if (NOT DEFINED TARGET_SUBSYSTEM)
81 message(FATAL_ERROR "Target subsystem for mps3 undefined, "
alexanderd580eee2021-05-04 21:24:22 +010082 "specify -DTARGET_SUBSYSTEM=<sse-300>")
alexander3c798932021-03-26 21:42:19 +000083 endif ()
84
alexanderd580eee2021-05-04 21:24:22 +010085 if (TARGET_SUBSYSTEM STREQUAL sse-300)
alexander3c798932021-03-26 21:42:19 +000086 message(STATUS "target subsystem is ${TARGET_SUBSYSTEM}")
87 set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/mps3")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010088 set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}-${TARGET_SUBSYSTEM}")
alexander3c798932021-03-26 21:42:19 +000089
90 # Include the mem profile definitions specific to our target subsystem
91 include(${MEM_PROFILES_SRC_DIR}/corstone-${TARGET_SUBSYSTEM}.cmake)
92 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} ${MPS3_PLATFORM_FLAG}")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010093
94 # For deployment on the MPS3 FPGA platform, we need to produce
95 # two bin files - one that is loaded into the ITCM, and another
96 # that is loaded into the DDR region.
Kshitij Sisodia69a47452021-07-23 17:43:54 +010097 set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr")
98 set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010099 set(MPS3_FPGA_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/scripts/${TARGET_PLATFORM}/${TARGET_SUBSYSTEM}/images.txt")
alexander3c798932021-03-26 21:42:19 +0000100 else ()
101 message(FATAL_ERROR "Non compatible target subsystem: ${TARGET_SUBSYSTEM}")
102 endif ()
103elseif (TARGET_PLATFORM STREQUAL simple_platform)
Kshitij Sisodia69a47452021-07-23 17:43:54 +0100104 set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/${TARGET_PLATFORM}")
105 set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}")
alexander3c798932021-03-26 21:42:19 +0000106 include(${MEM_PROFILES_SRC_DIR}/${TARGET_PLATFORM}.cmake)
Kshitij Sisodia69a47452021-07-23 17:43:54 +0100107 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS}")
108 set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr")
109 set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin")
alexander3c798932021-03-26 21:42:19 +0000110else ()
111 message(FATAL_ERROR "Non compatible target platform ${TARGET_PLATFORM}")
112endif ()
113
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100114# Add link options for the linker script to be used:
115add_linker_script(${LINKER_SCRIPT_DIR} ${LINKER_SCRIPT_NAME})
116
Cisco Cervelleraf085fa52021-08-02 09:32:07 +0100117if (ETHOS_U_NPU_ENABLED)
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100118 if (ETHOS_U_NPU_ID STREQUAL U55)
119 set(DEFAULT_TA_CONFIG_FILE_PATH "${CMAKE_SCRIPTS_DIR}/timing_adapter/ta_config_u55_high_end.cmake")
120 else ()
121 set(DEFAULT_TA_CONFIG_FILE_PATH "${CMAKE_SCRIPTS_DIR}/timing_adapter/ta_config_u65_high_end.cmake")
122 endif ()
alexander3c798932021-03-26 21:42:19 +0000123
124 # must be included after target subsystem CMake file
Kshitij Sisodiab59ba682021-11-23 17:19:52 +0000125 assert_defined(TA_CONFIG_FILE)
alexander3c798932021-03-26 21:42:19 +0000126 include(${TA_CONFIG_FILE})
127endif()
128
129# Generate the memory map header file from the mem profile cmake included in one of
130# the previous sections
131message(STATUS "Configuring file from ${MEM_PROFILE_TEMPLATE}"
132 ", ${IRQ_PROFILE_TEMPLATE}"
133 " and ${MEM_REGIONS_TEMPLATE}")
134
135configure_file("${MEM_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_memmap.h")
136configure_file("${IRQ_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_irqs.h")
137configure_file("${MEM_REGIONS_TEMPLATE}" "${SOURCE_GEN_DIR}/mem_regions.h")
138configure_file("${TA_SETTINGS_TEMPLATE}" "${SOURCE_GEN_DIR}/timing_adapter_settings.h")
139
alexander3c798932021-03-26 21:42:19 +0000140message(STATUS "Using BSP package from: ${BSP_PACKAGE_DIR}")
141
142if (DEFINED VERIFY_TEST_OUTPUT)
143 message(STATUS "Test output verification flag is: ${VERIFY_TEST_OUTPUT}")
144 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DVERIFY_TEST_OUTPUT=${VERIFY_TEST_OUTPUT}")
145endif ()
146
147if (DEFINED LOG_LEVEL)
148 message(STATUS "Setting log level to ${LOG_LEVEL}")
149 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DLOG_LEVEL=${LOG_LEVEL}")
150endif()
151
152if (DEFINED ACTIVATION_BUF_SRAM_SZ)
153 message(STATUS "Maximum SRAM space for activations buffers for this system: ${ACTIVATION_BUF_SRAM_SZ}")
154 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DACTIVATION_BUF_SRAM_SZ=${ACTIVATION_BUF_SRAM_SZ}")
155endif()
156
157if (DEFINED ARMCLANG_DEBUG_DWARF_LEVEL)
158 message(STATUS "setting dwarf conformance level to gdwarf-${ARMCLANG_DEBUG_DWARF_LEVEL}")
159 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -gdwarf-${ARMCLANG_DEBUG_DWARF_LEVEL}")
160endif()
161
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100162set(COMPILER_FLAGS "${TENSORFLOW_LITE_MICRO_FLAG} ${PROFILING_OPT} ${OPTIONAL_FLAGS}")
alexander3c798932021-03-26 21:42:19 +0000163# For some reason, cmake doesn't pass the c++ standard flag, adding it manually
ayamas0115f80702021-11-18 14:22:23 +0000164set(CMAKE_CXX_FLAGS "${COMPILER_FLAGS}" CACHE INTERNAL "")
alexander3c798932021-03-26 21:42:19 +0000165set(CMAKE_C_FLAGS "${COMPILER_FLAGS}" CACHE INTERNAL "")
alexander3c798932021-03-26 21:42:19 +0000166set(CMAKE_ASM_COMPILE_OBJECT ${CMAKE_CXX_FLAGS})
167
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100168# Tell linker that reset interrupt handler is our entry point
169add_link_options(--entry Reset_Handler)
alexander3c798932021-03-26 21:42:19 +0000170
171set(PLAT_BSP_INCLUDES
172 ${PLAT_HAL}/bsp/cmsis-device/include
173 ${PLAT_HAL}/bsp/include/
174 ${PLAT_HAL}/bsp/bsp-core/include
175 ${BSP_PACKAGE_DIR}/include
176)
177
178# Include directories:
179set(PLAT_INCLUDE_DIRS
180 ${PLAT_BSP_INCLUDES}
181 ${PLAT_HAL}/utils/include
182 ${PLAT_HAL}/images/include
183 ${PLAT_HAL}/data_presentation/lcd/include
184 ${PLAT_HAL}/timer/include
185 ${SOURCE_GEN_DIR}
186 )
187
188# Source files
189file(GLOB_RECURSE SRC_PLAT_HAL
190
191 # Higher level HAL sources - software logic implementations
192 "${PLAT_HAL}/data_*/*.c"
193 "${PLAT_HAL}/images/*.c"
194 "${PLAT_HAL}/timer/*.c"
195 "${PLAT_HAL}/utils/*.c"
196
197 # Low level HAL sources - these enable interaction with
198 # the actual hardware
199 "${PLAT_HAL}/bsp/cmsis-device/*.c"
200 "${PLAT_HAL}/bsp/bsp-core/*.c"
201 "${BSP_PACKAGE_DIR}/*.c"
202 )
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100203
204# Special retarget source to direct stdin, stdout and stderr streams to the
205# UART block.
206set(PLAT_RETARGET_SOURCE "${PLAT_HAL}/bsp/bsp-core/retarget.c")