summaryrefslogtreecommitdiff
path: root/scripts/cmake/bare-metal-sources.cmake
blob: 3e24d7b4d7ba15fe7a838b7e8bbb437329ec4db8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#----------------------------------------------------------------------------
#  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_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build_baremetal)
set(PLAT_HAL ${CMAKE_CURRENT_SOURCE_DIR}/source/application/hal/platforms/bare-metal)

# If target platform not defined raise an error
# TARGET_PLATFORM either should have been defined by the user or set to default value mps3
if (NOT DEFINED TARGET_PLATFORM)
    message(FATAL_ERROR "Invalid target platform, specify TARGET_PLATFORM=mps3")
endif ()
message(STATUS "target platform ${TARGET_PLATFORM}")

set(SOURCE_GEN_DIR          ${CMAKE_BINARY_DIR}/generated/bsp)
if (NOT DEFINED MEM_PROFILES_SRC_DIR)
    set(MEM_PROFILES_SRC_DIR    ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/subsystem-profiles)
endif()
set(MEM_PROFILE_TEMPLATE    ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_memmap.h.template)
set(IRQ_PROFILE_TEMPLATE    ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_irqs.h.template)
set(MEM_REGIONS_TEMPLATE    ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/mem_regions.h.template)
set(TA_SETTINGS_TEMPLATE    ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/timing_adapter_settings.template)
set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME  "libtensorflow-microlite.a")
set(TENSORFLOW_LITE_MICRO_FLAG               "-DTF_LITE_STATIC_MEMORY")
set(ETHOS_U55_FLAG          "-DARM_NPU=1")

if (ETHOS_U55_ENABLED)
    set(OPTIONAL_FLAGS      "${OPTIONAL_FLAGS} ${ETHOS_U55_FLAG}")
endif ()

# Set specific flags depending on target platform and subsystem
if (TARGET_PLATFORM STREQUAL mps3)
    set(MPS3_PLATFORM_FLAG          "-DMPS3_PLATFORM=1")

    # If target platform is mps3 and subsystem not defined raise an error,
    # TARGET_SUBSYSTEM either should have been defined by the user or set to a default value
    if (NOT DEFINED TARGET_SUBSYSTEM)
        message(FATAL_ERROR "Target subsystem for mps3 undefined, "
                            "specify -DTARGET_SUBSYSTEM=<sse-200 or sse-300>")
    endif ()

    if (TARGET_SUBSYSTEM STREQUAL sse-200 OR TARGET_SUBSYSTEM STREQUAL sse-300)
        message(STATUS          "target subsystem is ${TARGET_SUBSYSTEM}")
        set(BSP_PACKAGE_DIR     "${PLAT_HAL}/bsp/bsp-packs/mps3")
        set(SCAT_FILE           "${PLAT_HAL}/bsp/mem_layout/mps3-${TARGET_SUBSYSTEM}.sct")

        # Include the mem profile definitions specific to our target subsystem
        include(${MEM_PROFILES_SRC_DIR}/corstone-${TARGET_SUBSYSTEM}.cmake)
        set(OPTIONAL_FLAGS      "${OPTIONAL_FLAGS} ${MPS3_PLATFORM_FLAG}")
    else ()
        message(FATAL_ERROR "Non compatible target subsystem: ${TARGET_SUBSYSTEM}")
    endif ()
elseif (TARGET_PLATFORM STREQUAL simple_platform)
    set(BSP_PACKAGE_DIR     "${PLAT_HAL}/bsp/bsp-packs/${TARGET_PLATFORM}")
    set(SCAT_FILE           "${PLAT_HAL}/bsp/mem_layout/${TARGET_PLATFORM}.sct")
    include(${MEM_PROFILES_SRC_DIR}/${TARGET_PLATFORM}.cmake)
    set(OPTIONAL_FLAGS      "${OPTIONAL_FLAGS}")
else ()
    message(FATAL_ERROR "Non compatible target platform ${TARGET_PLATFORM}")
endif ()

if (ETHOS_U55_ENABLED)
    USER_OPTION(TA_CONFIG_FILE "Path to the timing adapter configuration file"
            "${CMAKE_SCRIPTS_DIR}/ta_config.cmake"
            FILEPATH)

    # must be included after target subsystem CMake file
    include(${TA_CONFIG_FILE})
endif()

# Generate the memory map header file from the mem profile cmake included in one of
# the previous sections
message(STATUS "Configuring file from ${MEM_PROFILE_TEMPLATE}"
                                   ", ${IRQ_PROFILE_TEMPLATE}"
                                " and ${MEM_REGIONS_TEMPLATE}")

configure_file("${MEM_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_memmap.h")
configure_file("${IRQ_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_irqs.h")
configure_file("${MEM_REGIONS_TEMPLATE}" "${SOURCE_GEN_DIR}/mem_regions.h")
configure_file("${TA_SETTINGS_TEMPLATE}" "${SOURCE_GEN_DIR}/timing_adapter_settings.h")

message(STATUS "Scatter file: ${SCAT_FILE}")
message(STATUS "Using BSP package from: ${BSP_PACKAGE_DIR}")

if (DEFINED VERIFY_TEST_OUTPUT)
    message(STATUS "Test output verification flag is: ${VERIFY_TEST_OUTPUT}")
    set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DVERIFY_TEST_OUTPUT=${VERIFY_TEST_OUTPUT}")
endif ()

if (DEFINED LOG_LEVEL)
    message(STATUS "Setting log level to ${LOG_LEVEL}")
    set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DLOG_LEVEL=${LOG_LEVEL}")
endif()

if (DEFINED ACTIVATION_BUF_SRAM_SZ)
    message(STATUS "Maximum SRAM space for activations buffers for this system: ${ACTIVATION_BUF_SRAM_SZ}")
    set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DACTIVATION_BUF_SRAM_SZ=${ACTIVATION_BUF_SRAM_SZ}")
endif()

if (DEFINED ARMCLANG_DEBUG_DWARF_LEVEL)
    message(STATUS "setting dwarf conformance level to gdwarf-${ARMCLANG_DEBUG_DWARF_LEVEL}")
    set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -gdwarf-${ARMCLANG_DEBUG_DWARF_LEVEL}")
endif()

set(COMPILER_FLAGS              "${ALL_COMMON_FLAGS} ${TENSORFLOW_LITE_MICRO_FLAG} ${PROFILING_OPT} ${OPTIONAL_FLAGS}")
# For some reason, cmake doesn't pass the c++ standard flag, adding it manually
set(CMAKE_CXX_FLAGS             "${COMPILER_FLAGS} -std=c++11" CACHE INTERNAL "")
set(CMAKE_C_FLAGS               "${COMPILER_FLAGS}" CACHE INTERNAL "")
set(CMAKE_ASM_FLAGS             "${CPU_LD}")
set(CMAKE_ASM_COMPILE_OBJECT    ${CMAKE_CXX_FLAGS})

add_link_options(--strict --callgraph --load_addr_map_info --map)
add_link_options(--symbols --xref --scatter=${SCAT_FILE})

# Warnings to be ignored:
# L6314W = No section matches pattern
# L6439W = Multiply defined Global Symbol
add_link_options(--diag_suppress=L6439W,L6314W)
add_link_options(--info sizes,totals,unused,veneers --entry Reset_Handler)

if (CMAKE_BUILD_TYPE STREQUAL Release)
    add_link_options(--no_debug)
endif ()

set(CMAKE_EXE_LINKER_FLAGS "${CPU_LD}")

set(PLAT_BSP_INCLUDES
    ${PLAT_HAL}/bsp/cmsis-device/include
    ${PLAT_HAL}/bsp/include/
    ${PLAT_HAL}/bsp/bsp-core/include
    ${BSP_PACKAGE_DIR}/include
)

# Include directories:
set(PLAT_INCLUDE_DIRS
    ${PLAT_BSP_INCLUDES}
    ${PLAT_HAL}/utils/include
    ${PLAT_HAL}/images/include
    ${PLAT_HAL}/data_presentation/lcd/include
    ${PLAT_HAL}/timer/include
    ${SOURCE_GEN_DIR}
    )

# Source files
file(GLOB_RECURSE SRC_PLAT_HAL

    # Higher level HAL sources - software logic implementations
    "${PLAT_HAL}/data_*/*.c"
    "${PLAT_HAL}/images/*.c"
    "${PLAT_HAL}/timer/*.c"
    "${PLAT_HAL}/utils/*.c"

    # Low level HAL sources - these enable interaction with
    # the actual hardware
    "${PLAT_HAL}/bsp/cmsis-device/*.c"
    "${PLAT_HAL}/bsp/bsp-core/*.c"
    "${BSP_PACKAGE_DIR}/*.c"
    )