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