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 | |
Kshitij Sisodia | b59ba68 | 2021-11-23 17:19:52 +0000 | [diff] [blame] | 43 | assert_defined(ETHOS_U_NPU_ID) |
| 44 | assert_defined(ETHOS_U_NPU_MEMORY_MODE) |
| 45 | assert_defined(ETHOS_U_NPU_CONFIG_ID) |
Kshitij Sisodia | 3be2623 | 2021-10-29 12:29:06 +0100 | [diff] [blame] | 46 | |
Isabella Gottardi | 118f73e | 2021-09-16 17:54:35 +0100 | [diff] [blame] | 47 | 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}") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 72 | endif () |
| 73 | |
| 74 | # Set specific flags depending on target platform and subsystem |
| 75 | if (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, " |
alexander | d580eee | 2021-05-04 21:24:22 +0100 | [diff] [blame] | 82 | "specify -DTARGET_SUBSYSTEM=<sse-300>") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 83 | endif () |
| 84 | |
alexander | d580eee | 2021-05-04 21:24:22 +0100 | [diff] [blame] | 85 | if (TARGET_SUBSYSTEM STREQUAL sse-300) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 86 | message(STATUS "target subsystem is ${TARGET_SUBSYSTEM}") |
| 87 | set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/mps3") |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 88 | set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}-${TARGET_SUBSYSTEM}") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 89 | |
| 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 Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 93 | |
| 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 Sisodia | 69a4745 | 2021-07-23 17:43:54 +0100 | [diff] [blame] | 97 | set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr") |
| 98 | set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin") |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 99 | 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] | 100 | else () |
| 101 | message(FATAL_ERROR "Non compatible target subsystem: ${TARGET_SUBSYSTEM}") |
| 102 | endif () |
| 103 | elseif (TARGET_PLATFORM STREQUAL simple_platform) |
Kshitij Sisodia | 69a4745 | 2021-07-23 17:43:54 +0100 | [diff] [blame] | 104 | set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/${TARGET_PLATFORM}") |
| 105 | set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 106 | include(${MEM_PROFILES_SRC_DIR}/${TARGET_PLATFORM}.cmake) |
Kshitij Sisodia | 69a4745 | 2021-07-23 17:43:54 +0100 | [diff] [blame] | 107 | set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS}") |
| 108 | set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr") |
| 109 | set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 110 | else () |
| 111 | message(FATAL_ERROR "Non compatible target platform ${TARGET_PLATFORM}") |
| 112 | endif () |
| 113 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 114 | # Add link options for the linker script to be used: |
| 115 | add_linker_script(${LINKER_SCRIPT_DIR} ${LINKER_SCRIPT_NAME}) |
| 116 | |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 117 | if (ETHOS_U_NPU_ENABLED) |
Isabella Gottardi | 118f73e | 2021-09-16 17:54:35 +0100 | [diff] [blame] | 118 | 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 () |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 123 | |
| 124 | # must be included after target subsystem CMake file |
Kshitij Sisodia | b59ba68 | 2021-11-23 17:19:52 +0000 | [diff] [blame] | 125 | assert_defined(TA_CONFIG_FILE) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 126 | include(${TA_CONFIG_FILE}) |
| 127 | endif() |
| 128 | |
| 129 | # Generate the memory map header file from the mem profile cmake included in one of |
| 130 | # the previous sections |
| 131 | message(STATUS "Configuring file from ${MEM_PROFILE_TEMPLATE}" |
| 132 | ", ${IRQ_PROFILE_TEMPLATE}" |
| 133 | " and ${MEM_REGIONS_TEMPLATE}") |
| 134 | |
| 135 | configure_file("${MEM_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_memmap.h") |
| 136 | configure_file("${IRQ_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_irqs.h") |
| 137 | configure_file("${MEM_REGIONS_TEMPLATE}" "${SOURCE_GEN_DIR}/mem_regions.h") |
| 138 | configure_file("${TA_SETTINGS_TEMPLATE}" "${SOURCE_GEN_DIR}/timing_adapter_settings.h") |
| 139 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 140 | message(STATUS "Using BSP package from: ${BSP_PACKAGE_DIR}") |
| 141 | |
| 142 | if (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}") |
| 145 | endif () |
| 146 | |
| 147 | if (DEFINED LOG_LEVEL) |
| 148 | message(STATUS "Setting log level to ${LOG_LEVEL}") |
| 149 | set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DLOG_LEVEL=${LOG_LEVEL}") |
| 150 | endif() |
| 151 | |
| 152 | if (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}") |
| 155 | endif() |
| 156 | |
| 157 | if (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}") |
| 160 | endif() |
| 161 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 162 | set(COMPILER_FLAGS "${TENSORFLOW_LITE_MICRO_FLAG} ${PROFILING_OPT} ${OPTIONAL_FLAGS}") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 163 | # For some reason, cmake doesn't pass the c++ standard flag, adding it manually |
ayamas01 | 15f8070 | 2021-11-18 14:22:23 +0000 | [diff] [blame] | 164 | set(CMAKE_CXX_FLAGS "${COMPILER_FLAGS}" CACHE INTERNAL "") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 165 | set(CMAKE_C_FLAGS "${COMPILER_FLAGS}" CACHE INTERNAL "") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 166 | set(CMAKE_ASM_COMPILE_OBJECT ${CMAKE_CXX_FLAGS}) |
| 167 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 168 | # Tell linker that reset interrupt handler is our entry point |
| 169 | add_link_options(--entry Reset_Handler) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 170 | |
| 171 | set(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: |
| 179 | set(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 |
| 189 | file(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 Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 203 | |
| 204 | # Special retarget source to direct stdin, stdout and stderr streams to the |
| 205 | # UART block. |
| 206 | set(PLAT_RETARGET_SOURCE "${PLAT_HAL}/bsp/bsp-core/retarget.c") |