blob: 1743253f3b79ed1e8d4f084a8393503a0ab09307 [file] [log] [blame]
alexander31ae9f02022-02-10 16:15:54 +00001#----------------------------------------------------------------------------
Kshitij Sisodia26bc9232023-03-10 16:33:23 +00002# SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
alexander31ae9f02022-02-10 16:15:54 +00003# 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
18function(set_platform_global_defaults)
19 message(STATUS "Platform: MPS3 FPGA Prototyping Board or FVP")
Kshitij Sisodia8c61c0a2022-05-17 11:16:22 +010020
21 if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
22 if (TARGET_SUBSYSTEM STREQUAL sse-300)
23 set(CMAKE_SYSTEM_PROCESSOR cortex-m55 CACHE STRING "Cortex-M CPU to use")
24 elseif(TARGET_SUBSYSTEM STREQUAL sse-310)
Kshitij Sisodia9c6f9f82022-05-20 14:30:02 +010025 set(CMAKE_SYSTEM_PROCESSOR cortex-m85 CACHE STRING "Cortex-M CPU to use")
Kshitij Sisodia8c61c0a2022-05-17 11:16:22 +010026 endif()
27 endif()
28
alexander31ae9f02022-02-10 16:15:54 +000029 if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
30 set(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake
31 CACHE FILEPATH "Toolchain file")
32 endif()
33
Kshitij Sisodia01334f92022-08-12 11:53:45 +010034 # Arm Corstone-310's timing adapter behaviour is very different to Arm Corstone-300 and cannot
35 # be used for bandwidth/latency related performance sweeps for the Arm Ethos-U NPU. Read
36 # docs/sections/timing_adapters.md for more details.
Nina Drozd27c5e302022-09-20 10:58:19 +010037 if ((TARGET_SUBSYSTEM STREQUAL "sse-310") AND (DEFINED ETHOS_U_NPU_TIMING_ADAPTER_ENABLED))
Kshitij Sisodia01334f92022-08-12 11:53:45 +010038 message(STATUS "Timing adapter will NOT be used for target subsystem ${TARGET_SUBSYSTEM}")
39 set(ETHOS_U_NPU_TIMING_ADAPTER_ENABLED OFF CACHE BOOL "Use of TA" FORCE)
Kshitij Sisodia8c61c0a2022-05-17 11:16:22 +010040 endif()
41
alexander31ae9f02022-02-10 16:15:54 +000042 set(LINKER_SCRIPT_NAME "mps3-${TARGET_SUBSYSTEM}" PARENT_SCOPE)
43 set(PLATFORM_DRIVERS_DIR "${HAL_PLATFORM_DIR}/mps3" PARENT_SCOPE)
44
45endfunction()
46
47function(platform_custom_post_build)
48 set(oneValueArgs TARGET_NAME)
49 cmake_parse_arguments(PARSED "" "${oneValueArgs}" "" ${ARGN} )
50
51 set_target_properties(${PARSED_TARGET_NAME} PROPERTIES SUFFIX ".axf")
Kshitij Sisodia26bc9232023-03-10 16:33:23 +000052
53 # For GNU toolchain, we have different linker scripts for Debug and Release
54 # as the code footprint difference between the two is quite big. We do it
55 # only for SSE-300 as the main code memory is the ITCM which is limited to
56 # 512kiB.
57 if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (TARGET_SUBSYSTEM STREQUAL "sse-300"))
58 string(TOLOWER ${CMAKE_BUILD_TYPE} LINKER_SCRIPT_SUFFIX)
59 set(LINKER_SCRIPT_NAME "${LINKER_SCRIPT_NAME}-${LINKER_SCRIPT_SUFFIX}" PARENT_SCOPE FORCE)
60 endif()
61
alexander31ae9f02022-02-10 16:15:54 +000062 # Add link options for the linker script to be used:
63 add_linker_script(
64 ${PARSED_TARGET_NAME} # Target
Kshitij Sisodia8c61c0a2022-05-17 11:16:22 +010065 ${CMAKE_SCRIPTS_DIR}/platforms/mps3/${TARGET_SUBSYSTEM} # Directory path
alexander31ae9f02022-02-10 16:15:54 +000066 ${LINKER_SCRIPT_NAME}) # Name of the file without suffix
67
68 add_target_map_file(
69 ${PARSED_TARGET_NAME}
70 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.map)
71
72 set(SECTORS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sectors)
73 set(SECTORS_BIN_DIR ${SECTORS_DIR}/${use_case})
74
75 file(REMOVE_RECURSE ${SECTORS_BIN_DIR})
76 file(MAKE_DIRECTORY ${SECTORS_BIN_DIR})
77
Kshitij Sisodia8c61c0a2022-05-17 11:16:22 +010078 if (TARGET_SUBSYSTEM STREQUAL sse-310)
79 set(LINKER_SECTION_TAGS "*.at_bram" "*.at_ddr")
80 set(LINKER_OUTPUT_BIN_TAGS "bram.bin" "ddr.bin")
81 else()
82 set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr")
83 set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin")
84 endif()
alexander31ae9f02022-02-10 16:15:54 +000085
86 add_bin_generation_command(
87 TARGET_NAME ${PARSED_TARGET_NAME}
88 OUTPUT_DIR ${SECTORS_BIN_DIR}
89 AXF_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.axf
90 SECTION_PATTERNS "${LINKER_SECTION_TAGS}"
91 OUTPUT_BIN_NAMES "${LINKER_OUTPUT_BIN_TAGS}")
92
93 set(MPS3_FPGA_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/scripts/mps3/${TARGET_SUBSYSTEM}/images.txt")
94
95 add_custom_command(TARGET ${PARSED_TARGET_NAME}
96 POST_BUILD
97 COMMAND ${CMAKE_COMMAND} -E copy ${MPS3_FPGA_CONFIG} ${SECTORS_DIR})
98
Sarah Blades00481442022-10-03 16:38:23 +010099 # Add tests for application on FVP if FVP path specified
100 if (BUILD_FVP_TESTS)
101
102 # Build for all use cases if USE_SINGLE_INPUT as no telnet interaction required
103 # otherwise only build for inference runner
104 if ((USE_SINGLE_INPUT) OR (${use_case} STREQUAL "inference_runner"))
105 set(AXF_PATH "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.axf")
106 set(TEST_TARGET_NAME "${use_case}_fvp_test")
107
108 message(STATUS "Adding FVP test for ${use_case}")
109
110 add_test(
111 NAME "${TEST_TARGET_NAME}"
112 COMMAND ${FVP_PATH} -a ${AXF_PATH}
113 -C mps3_board.telnetterminal0.start_telnet=0
114 -C mps3_board.uart0.out_file='-'
115 -C mps3_board.uart0.shutdown_on_eot=1
116 -C mps3_board.visualisation.disable-visualisation=1
117 --stat)
118 endif()
119 endif ()
120
Kshitij Sisodia8c61c0a2022-05-17 11:16:22 +0100121endfunction()