alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
| 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 | #---------------------------------------------------------------------------- |
| 17 | set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build_baremetal) |
| 18 | set(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 |
| 22 | if (NOT DEFINED TARGET_PLATFORM) |
| 23 | message(FATAL_ERROR "Invalid target platform, specify TARGET_PLATFORM=mps3") |
| 24 | endif () |
| 25 | message(STATUS "target platform ${TARGET_PLATFORM}") |
| 26 | |
| 27 | set(SOURCE_GEN_DIR ${CMAKE_BINARY_DIR}/generated/bsp) |
| 28 | if (NOT DEFINED MEM_PROFILES_SRC_DIR) |
| 29 | set(MEM_PROFILES_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/subsystem-profiles) |
| 30 | endif() |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 31 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 32 | set(MEM_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_memmap.h.template) |
| 33 | set(IRQ_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_irqs.h.template) |
| 34 | set(MEM_REGIONS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/mem_regions.h.template) |
| 35 | set(TA_SETTINGS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/timing_adapter_settings.template) |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 36 | set(LINKER_SCRIPT_DIR "${PLAT_HAL}/bsp/mem_layout") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 37 | set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME "libtensorflow-microlite.a") |
| 38 | set(TENSORFLOW_LITE_MICRO_FLAG "-DTF_LITE_STATIC_MEMORY") |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 39 | set(ETHOS_U_NPU_FLAG "-DARM_NPU=1") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 40 | |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 41 | if (ETHOS_U_NPU_ENABLED) |
Isabella Gottardi | 118f73e | 2021-09-16 17:54:35 +0100 | [diff] [blame] | 42 | |
| 43 | USER_OPTION(ETHOS_U_NPU_ID "Arm Ethos-U NPU IP (U55 or U65)" |
| 44 | "U55" |
| 45 | STRING) |
| 46 | |
| 47 | if ((ETHOS_U_NPU_ID STREQUAL U55) OR (ETHOS_U_NPU_ID STREQUAL U65)) |
| 48 | if (ETHOS_U_NPU_ID STREQUAL U55) |
| 49 | set(DEFAULT_NPU_MEM_MODE "Shared_Sram") |
| 50 | set(DEFAULT_NPU_CONFIG_ID "H128") |
| 51 | elseif(ETHOS_U_NPU_ID STREQUAL U65) |
| 52 | set(DEFAULT_NPU_MEM_MODE "Dedicated_Sram") |
| 53 | set(DEFAULT_NPU_CONFIG_ID "Y256") |
| 54 | endif() |
| 55 | else () |
| 56 | message(FATAL_ERROR "Non compatible Ethos-U NPU processor ${ETHOS_U_NPU_ID}") |
| 57 | endif () |
| 58 | |
| 59 | USER_OPTION(ETHOS_U_NPU_MEMORY_MODE "Specifies the memory mode used in the Vela command." |
| 60 | "${DEFAULT_NPU_MEM_MODE}" |
| 61 | STRING) |
| 62 | |
Kshitij Sisodia | 3be2623 | 2021-10-29 12:29:06 +0100 | [diff] [blame^] | 63 | USER_OPTION(ETHOS_U_NPU_CONFIG_ID "Specifies the configuration ID for the NPU." |
| 64 | "${DEFAULT_NPU_CONFIG_ID}" |
| 65 | STRING) |
| 66 | |
Isabella Gottardi | 118f73e | 2021-09-16 17:54:35 +0100 | [diff] [blame] | 67 | if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only) |
| 68 | |
| 69 | if (ETHOS_U_NPU_ID STREQUAL U55) |
| 70 | set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY") |
| 71 | else () |
| 72 | 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.") |
| 73 | endif () |
| 74 | |
| 75 | elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram) |
| 76 | # Shared Sram can be used for Ethos-U55 and Ethos-U65 |
| 77 | set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM") |
| 78 | |
| 79 | elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram) |
| 80 | # Dedicated Sram is used only for Ethos-U65 |
| 81 | if (ETHOS_U_NPU_ID STREQUAL U65) |
| 82 | set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM") |
| 83 | else () |
| 84 | 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.") |
| 85 | endif () |
| 86 | |
| 87 | else () |
| 88 | message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}") |
| 89 | endif () |
| 90 | |
| 91 | set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} ${ETHOS_U_NPU_FLAG} ${ETHOS_U_NPU_MEMORY_MODE_FLAG}") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 92 | endif () |
| 93 | |
| 94 | # Set specific flags depending on target platform and subsystem |
| 95 | if (TARGET_PLATFORM STREQUAL mps3) |
| 96 | set(MPS3_PLATFORM_FLAG "-DMPS3_PLATFORM=1") |
| 97 | |
| 98 | # If target platform is mps3 and subsystem not defined raise an error, |
| 99 | # TARGET_SUBSYSTEM either should have been defined by the user or set to a default value |
| 100 | if (NOT DEFINED TARGET_SUBSYSTEM) |
| 101 | message(FATAL_ERROR "Target subsystem for mps3 undefined, " |
alexander | d580eee | 2021-05-04 21:24:22 +0100 | [diff] [blame] | 102 | "specify -DTARGET_SUBSYSTEM=<sse-300>") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 103 | endif () |
| 104 | |
alexander | d580eee | 2021-05-04 21:24:22 +0100 | [diff] [blame] | 105 | if (TARGET_SUBSYSTEM STREQUAL sse-300) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 106 | message(STATUS "target subsystem is ${TARGET_SUBSYSTEM}") |
| 107 | set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/mps3") |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 108 | set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}-${TARGET_SUBSYSTEM}") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 109 | |
| 110 | # Include the mem profile definitions specific to our target subsystem |
| 111 | include(${MEM_PROFILES_SRC_DIR}/corstone-${TARGET_SUBSYSTEM}.cmake) |
| 112 | set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} ${MPS3_PLATFORM_FLAG}") |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 113 | |
| 114 | # For deployment on the MPS3 FPGA platform, we need to produce |
| 115 | # two bin files - one that is loaded into the ITCM, and another |
| 116 | # that is loaded into the DDR region. |
Kshitij Sisodia | 69a4745 | 2021-07-23 17:43:54 +0100 | [diff] [blame] | 117 | set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr") |
| 118 | set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin") |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 119 | set(MPS3_FPGA_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/scripts/${TARGET_PLATFORM}/${TARGET_SUBSYSTEM}/images.txt") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 120 | else () |
| 121 | message(FATAL_ERROR "Non compatible target subsystem: ${TARGET_SUBSYSTEM}") |
| 122 | endif () |
| 123 | elseif (TARGET_PLATFORM STREQUAL simple_platform) |
Kshitij Sisodia | 69a4745 | 2021-07-23 17:43:54 +0100 | [diff] [blame] | 124 | set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/${TARGET_PLATFORM}") |
| 125 | set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 126 | include(${MEM_PROFILES_SRC_DIR}/${TARGET_PLATFORM}.cmake) |
Kshitij Sisodia | 69a4745 | 2021-07-23 17:43:54 +0100 | [diff] [blame] | 127 | set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS}") |
| 128 | set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr") |
| 129 | set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 130 | else () |
| 131 | message(FATAL_ERROR "Non compatible target platform ${TARGET_PLATFORM}") |
| 132 | endif () |
| 133 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 134 | # Add link options for the linker script to be used: |
| 135 | add_linker_script(${LINKER_SCRIPT_DIR} ${LINKER_SCRIPT_NAME}) |
| 136 | |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 137 | if (ETHOS_U_NPU_ENABLED) |
Isabella Gottardi | 118f73e | 2021-09-16 17:54:35 +0100 | [diff] [blame] | 138 | if (ETHOS_U_NPU_ID STREQUAL U55) |
| 139 | set(DEFAULT_TA_CONFIG_FILE_PATH "${CMAKE_SCRIPTS_DIR}/timing_adapter/ta_config_u55_high_end.cmake") |
| 140 | else () |
| 141 | set(DEFAULT_TA_CONFIG_FILE_PATH "${CMAKE_SCRIPTS_DIR}/timing_adapter/ta_config_u65_high_end.cmake") |
| 142 | endif () |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 143 | USER_OPTION(TA_CONFIG_FILE "Path to the timing adapter configuration file" |
Isabella Gottardi | 118f73e | 2021-09-16 17:54:35 +0100 | [diff] [blame] | 144 | ${DEFAULT_TA_CONFIG_FILE_PATH} |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 145 | FILEPATH) |
| 146 | |
| 147 | # must be included after target subsystem CMake file |
| 148 | include(${TA_CONFIG_FILE}) |
| 149 | endif() |
| 150 | |
| 151 | # Generate the memory map header file from the mem profile cmake included in one of |
| 152 | # the previous sections |
| 153 | message(STATUS "Configuring file from ${MEM_PROFILE_TEMPLATE}" |
| 154 | ", ${IRQ_PROFILE_TEMPLATE}" |
| 155 | " and ${MEM_REGIONS_TEMPLATE}") |
| 156 | |
| 157 | configure_file("${MEM_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_memmap.h") |
| 158 | configure_file("${IRQ_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_irqs.h") |
| 159 | configure_file("${MEM_REGIONS_TEMPLATE}" "${SOURCE_GEN_DIR}/mem_regions.h") |
| 160 | configure_file("${TA_SETTINGS_TEMPLATE}" "${SOURCE_GEN_DIR}/timing_adapter_settings.h") |
| 161 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 162 | message(STATUS "Using BSP package from: ${BSP_PACKAGE_DIR}") |
| 163 | |
| 164 | if (DEFINED VERIFY_TEST_OUTPUT) |
| 165 | message(STATUS "Test output verification flag is: ${VERIFY_TEST_OUTPUT}") |
| 166 | set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DVERIFY_TEST_OUTPUT=${VERIFY_TEST_OUTPUT}") |
| 167 | endif () |
| 168 | |
| 169 | if (DEFINED LOG_LEVEL) |
| 170 | message(STATUS "Setting log level to ${LOG_LEVEL}") |
| 171 | set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DLOG_LEVEL=${LOG_LEVEL}") |
| 172 | endif() |
| 173 | |
| 174 | if (DEFINED ACTIVATION_BUF_SRAM_SZ) |
| 175 | message(STATUS "Maximum SRAM space for activations buffers for this system: ${ACTIVATION_BUF_SRAM_SZ}") |
| 176 | set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DACTIVATION_BUF_SRAM_SZ=${ACTIVATION_BUF_SRAM_SZ}") |
| 177 | endif() |
| 178 | |
| 179 | if (DEFINED ARMCLANG_DEBUG_DWARF_LEVEL) |
| 180 | message(STATUS "setting dwarf conformance level to gdwarf-${ARMCLANG_DEBUG_DWARF_LEVEL}") |
| 181 | set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -gdwarf-${ARMCLANG_DEBUG_DWARF_LEVEL}") |
| 182 | endif() |
| 183 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 184 | set(COMPILER_FLAGS "${TENSORFLOW_LITE_MICRO_FLAG} ${PROFILING_OPT} ${OPTIONAL_FLAGS}") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 185 | # For some reason, cmake doesn't pass the c++ standard flag, adding it manually |
| 186 | set(CMAKE_CXX_FLAGS "${COMPILER_FLAGS} -std=c++11" CACHE INTERNAL "") |
| 187 | set(CMAKE_C_FLAGS "${COMPILER_FLAGS}" CACHE INTERNAL "") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 188 | set(CMAKE_ASM_COMPILE_OBJECT ${CMAKE_CXX_FLAGS}) |
| 189 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 190 | # Tell linker that reset interrupt handler is our entry point |
| 191 | add_link_options(--entry Reset_Handler) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 192 | |
| 193 | set(PLAT_BSP_INCLUDES |
| 194 | ${PLAT_HAL}/bsp/cmsis-device/include |
| 195 | ${PLAT_HAL}/bsp/include/ |
| 196 | ${PLAT_HAL}/bsp/bsp-core/include |
| 197 | ${BSP_PACKAGE_DIR}/include |
| 198 | ) |
| 199 | |
| 200 | # Include directories: |
| 201 | set(PLAT_INCLUDE_DIRS |
| 202 | ${PLAT_BSP_INCLUDES} |
| 203 | ${PLAT_HAL}/utils/include |
| 204 | ${PLAT_HAL}/images/include |
| 205 | ${PLAT_HAL}/data_presentation/lcd/include |
| 206 | ${PLAT_HAL}/timer/include |
| 207 | ${SOURCE_GEN_DIR} |
| 208 | ) |
| 209 | |
| 210 | # Source files |
| 211 | file(GLOB_RECURSE SRC_PLAT_HAL |
| 212 | |
| 213 | # Higher level HAL sources - software logic implementations |
| 214 | "${PLAT_HAL}/data_*/*.c" |
| 215 | "${PLAT_HAL}/images/*.c" |
| 216 | "${PLAT_HAL}/timer/*.c" |
| 217 | "${PLAT_HAL}/utils/*.c" |
| 218 | |
| 219 | # Low level HAL sources - these enable interaction with |
| 220 | # the actual hardware |
| 221 | "${PLAT_HAL}/bsp/cmsis-device/*.c" |
| 222 | "${PLAT_HAL}/bsp/bsp-core/*.c" |
| 223 | "${BSP_PACKAGE_DIR}/*.c" |
| 224 | ) |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 225 | |
| 226 | # Special retarget source to direct stdin, stdout and stderr streams to the |
| 227 | # UART block. |
| 228 | set(PLAT_RETARGET_SOURCE "${PLAT_HAL}/bsp/bsp-core/retarget.c") |