alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2022 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 | |
| 18 | function(set_platform_global_defaults) |
| 19 | message(STATUS "Platform: MPS3 FPGA Prototyping Board or FVP") |
Kshitij Sisodia | 8c61c0a | 2022-05-17 11:16:22 +0100 | [diff] [blame^] | 20 | |
| 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) |
| 25 | # For CMake versions older than 3.21, the compiler and linker flags for |
| 26 | # ArmClang are added by CMake automatically which makes it mandatory to |
| 27 | # define the system processor. For CMake versions 3.21 or later (that |
| 28 | # implement policy CMP0123) we use armv8.1-m as the arch until the |
| 29 | # toolchain officially supports Cortex-M85. For older version of CMake |
| 30 | # we revert to using Cortex-M55 as the processor (as this will work |
| 31 | # for M85 too). |
| 32 | if(POLICY CMP0123) |
| 33 | set(CMAKE_SYSTEM_ARCH armv8.1-m.main CACHE STRING "System arch to use") |
| 34 | else() |
| 35 | set(CMAKE_SYSTEM_PROCESSOR cortex-m55) |
| 36 | endif() |
| 37 | endif() |
| 38 | endif() |
| 39 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 40 | if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) |
| 41 | set(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake |
| 42 | CACHE FILEPATH "Toolchain file") |
| 43 | endif() |
| 44 | |
Kshitij Sisodia | 8c61c0a | 2022-05-17 11:16:22 +0100 | [diff] [blame^] | 45 | if ((ETHOS_U_NPU_ID STREQUAL U65) AND (TARGET_SUBSYSTEM STREQUAL sse-310)) |
| 46 | message(FATAL_ERROR "Non compatible Ethos-U NPU processor ${ETHOS_U_NPU_ID} and target subsystem ${TARGET_SUBSYSTEM}") |
| 47 | endif() |
| 48 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 49 | set(LINKER_SCRIPT_NAME "mps3-${TARGET_SUBSYSTEM}" PARENT_SCOPE) |
| 50 | set(PLATFORM_DRIVERS_DIR "${HAL_PLATFORM_DIR}/mps3" PARENT_SCOPE) |
| 51 | |
| 52 | endfunction() |
| 53 | |
| 54 | function(platform_custom_post_build) |
| 55 | set(oneValueArgs TARGET_NAME) |
| 56 | cmake_parse_arguments(PARSED "" "${oneValueArgs}" "" ${ARGN} ) |
| 57 | |
| 58 | set_target_properties(${PARSED_TARGET_NAME} PROPERTIES SUFFIX ".axf") |
| 59 | # Add link options for the linker script to be used: |
| 60 | add_linker_script( |
| 61 | ${PARSED_TARGET_NAME} # Target |
Kshitij Sisodia | 8c61c0a | 2022-05-17 11:16:22 +0100 | [diff] [blame^] | 62 | ${CMAKE_SCRIPTS_DIR}/platforms/mps3/${TARGET_SUBSYSTEM} # Directory path |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 63 | ${LINKER_SCRIPT_NAME}) # Name of the file without suffix |
| 64 | |
| 65 | add_target_map_file( |
| 66 | ${PARSED_TARGET_NAME} |
| 67 | ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.map) |
| 68 | |
| 69 | set(SECTORS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sectors) |
| 70 | set(SECTORS_BIN_DIR ${SECTORS_DIR}/${use_case}) |
| 71 | |
| 72 | file(REMOVE_RECURSE ${SECTORS_BIN_DIR}) |
| 73 | file(MAKE_DIRECTORY ${SECTORS_BIN_DIR}) |
| 74 | |
Kshitij Sisodia | 8c61c0a | 2022-05-17 11:16:22 +0100 | [diff] [blame^] | 75 | if (TARGET_SUBSYSTEM STREQUAL sse-310) |
| 76 | set(LINKER_SECTION_TAGS "*.at_bram" "*.at_ddr") |
| 77 | set(LINKER_OUTPUT_BIN_TAGS "bram.bin" "ddr.bin") |
| 78 | else() |
| 79 | set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr") |
| 80 | set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin") |
| 81 | endif() |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 82 | |
| 83 | add_bin_generation_command( |
| 84 | TARGET_NAME ${PARSED_TARGET_NAME} |
| 85 | OUTPUT_DIR ${SECTORS_BIN_DIR} |
| 86 | AXF_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.axf |
| 87 | SECTION_PATTERNS "${LINKER_SECTION_TAGS}" |
| 88 | OUTPUT_BIN_NAMES "${LINKER_OUTPUT_BIN_TAGS}") |
| 89 | |
| 90 | set(MPS3_FPGA_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/scripts/mps3/${TARGET_SUBSYSTEM}/images.txt") |
| 91 | |
| 92 | add_custom_command(TARGET ${PARSED_TARGET_NAME} |
| 93 | POST_BUILD |
| 94 | COMMAND ${CMAKE_COMMAND} -E copy ${MPS3_FPGA_CONFIG} ${SECTORS_DIR}) |
| 95 | |
Kshitij Sisodia | 8c61c0a | 2022-05-17 11:16:22 +0100 | [diff] [blame^] | 96 | endfunction() |