|
| 1 | +# |
| 2 | +# Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | +# |
| 6 | + |
| 7 | +set(SUIT_GENERATOR_CLI_SCRIPT "${ZEPHYR_SUIT_GENERATOR_MODULE_DIR}/suit_generator/cli.py") |
| 8 | +sysbuild_get(DEFAULT_BINARY_DIR IMAGE ${DEFAULT_IMAGE} VAR APPLICATION_BINARY_DIR CACHE) |
| 9 | +set(MPI_BINARY_DIR ${DEFAULT_BINARY_DIR}/zephyr) |
| 10 | + |
| 11 | +# Usage: |
| 12 | +# configure_storage_address_cache() |
| 13 | +# |
| 14 | +# Store the absolute address of the SUIT storage inside CMake cache. |
| 15 | +# |
| 16 | +function(configure_storage_address_cache) |
| 17 | + sysbuild_dt_nodelabel( |
| 18 | + suit_storage_dev |
| 19 | + IMAGE |
| 20 | + ${DEFAULT_IMAGE} |
| 21 | + NODELABEL |
| 22 | + "suit_storage_partition" |
| 23 | + ) |
| 24 | + |
| 25 | + if(NOT DEFINED suit_storage_dev) |
| 26 | + message(WARNING "Unable to read SUIT storage address from DTS - nodes undefined") |
| 27 | + return() |
| 28 | + endif() |
| 29 | + |
| 30 | + # Calculate SUIT storage address, based on the DTS |
| 31 | + sysbuild_dt_reg_addr( |
| 32 | + suit_storage_address |
| 33 | + IMAGE |
| 34 | + ${DEFAULT_IMAGE} |
| 35 | + PATH |
| 36 | + "${suit_storage_dev}" |
| 37 | + ) |
| 38 | + |
| 39 | + set(SUIT_STORAGE_ADDRESS ${suit_storage_address} CACHE STRING "SUIT storage address") |
| 40 | +endfunction() |
| 41 | + |
| 42 | +# Usage: |
| 43 | +# generate_mpi_hex(<manifest_role>) |
| 44 | +# |
| 45 | +# Will generate HEX file for a single manifest role, based on Kconfigs defined by the template. |
| 46 | +# |
| 47 | +# <manifest_role>: The role that was used to generate a set of Kconfigs, defined by the |
| 48 | +# Kconfig.template.manifest_config. |
| 49 | +# |
| 50 | +# Required Kconfigs: |
| 51 | +# - SUIT_MPI_<manifest_role>_VENDOR_NAME |
| 52 | +# - SUIT_MPI_<manifest_role>_CLASS_NAME |
| 53 | +# - SUIT_MPI_<manifest_role>_OFFSET |
| 54 | +# - SUIT_MPI_<manifest_role>_PATH |
| 55 | +# - SUIT_MPI_SLOT_SIZE |
| 56 | +# |
| 57 | +function(generate_mpi_hex manifest_role) |
| 58 | + set(generate_args "") |
| 59 | + set(descr_args "") |
| 60 | + |
| 61 | + if(NOT DEFINED SB_CONFIG_SUIT_MPI_${manifest_role}) |
| 62 | + return() |
| 63 | + endif() |
| 64 | + |
| 65 | + if((NOT DEFINED SB_CONFIG_SUIT_MPI_${manifest_role}_VENDOR_NAME) OR |
| 66 | + (NOT DEFINED SB_CONFIG_SUIT_MPI_${manifest_role}_CLASS_NAME) OR |
| 67 | + (NOT DEFINED SB_CONFIG_SUIT_MPI_${manifest_role}_OFFSET) OR |
| 68 | + (NOT DEFINED SB_CONFIG_SUIT_MPI_${manifest_role}_PATH) OR |
| 69 | + (NOT DEFINED SB_CONFIG_SUIT_MPI_SLOT_SIZE) |
| 70 | + ) |
| 71 | + message(FATAL_ERROR "Malformed configuration for: ${manifest_role}") |
| 72 | + return() |
| 73 | + endif() |
| 74 | + |
| 75 | + MATH( |
| 76 | + EXPR |
| 77 | + SUIT_MPI_${manifest_role}_ADDRESS |
| 78 | + "${SUIT_STORAGE_ADDRESS} |
| 79 | + + ${SB_CONFIG_SUIT_MPI_${manifest_role}_OFFSET}" |
| 80 | + OUTPUT_FORMAT HEXADECIMAL |
| 81 | + ) |
| 82 | + |
| 83 | + list(APPEND generate_args |
| 84 | + --vendor-name ${SB_CONFIG_SUIT_MPI_${manifest_role}_VENDOR_NAME} |
| 85 | + --class-name ${SB_CONFIG_SUIT_MPI_${manifest_role}_CLASS_NAME} |
| 86 | + --address ${SUIT_MPI_${manifest_role}_ADDRESS} |
| 87 | + --size ${SB_CONFIG_SUIT_MPI_SLOT_SIZE} |
| 88 | + --output-file ${SB_CONFIG_SUIT_MPI_${manifest_role}_PATH} |
| 89 | + ) |
| 90 | + |
| 91 | + list(APPEND descr_args |
| 92 | + ${SB_CONFIG_SUIT_MPI_${manifest_role}_PATH} |
| 93 | + ${SB_CONFIG_SUIT_MPI_${manifest_role}_VENDOR_NAME} |
| 94 | + ${SB_CONFIG_SUIT_MPI_${manifest_role}_CLASS_NAME} |
| 95 | + "address=${SUIT_MPI_${manifest_role}_ADDRESS}" |
| 96 | + ) |
| 97 | + |
| 98 | + if(DEFINED SB_CONFIG_SUIT_MPI_${manifest_role}_DOWNGRADE_PREVENTION) |
| 99 | + list(APPEND generate_args |
| 100 | + --downgrade-prevention-enabled |
| 101 | + ) |
| 102 | + list(APPEND descr_args |
| 103 | + downgrade-prevention-enabled |
| 104 | + ) |
| 105 | + endif() |
| 106 | + |
| 107 | + if(DEFINED SB_CONFIG_SUIT_MPI_${manifest_role}_INDEPENDENT_UPDATE) |
| 108 | + list(APPEND generate_args |
| 109 | + --independent-updates |
| 110 | + ) |
| 111 | + list(APPEND descr_args |
| 112 | + "independent updates" |
| 113 | + ) |
| 114 | + endif() |
| 115 | + |
| 116 | + if(DEFINED SB_CONFIG_SUIT_MPI_${manifest_role}_SIGNATURE_CHECK_ENABLED_ON_UPDATE) |
| 117 | + list(APPEND generate_args |
| 118 | + --signature-verification update |
| 119 | + ) |
| 120 | + list(APPEND descr_args |
| 121 | + "signed updates" |
| 122 | + ) |
| 123 | + elseif(DEFINED SB_CONFIG_SUIT_MPI_${manifest_role}_SIGNATURE_CHECK_ENABLED_ON_UPDATE_AND_BOOT) |
| 124 | + list(APPEND generate_args |
| 125 | + --signature-verification update-and-boot |
| 126 | + ) |
| 127 | + list(APPEND descr_args |
| 128 | + "signed updates" |
| 129 | + "signed boot" |
| 130 | + ) |
| 131 | + endif() |
| 132 | + |
| 133 | + add_custom_target( |
| 134 | + create_suit_mpi_${manifest_role} |
| 135 | + COMMAND ${PYTHON_EXECUTABLE} ${SUIT_GENERATOR_CLI_SCRIPT} |
| 136 | + mpi |
| 137 | + generate |
| 138 | + ${generate_args} |
| 139 | + BYPRODUCTS ${SB_CONFIG_SUIT_MPI_${manifest_role}_PATH} |
| 140 | + COMMENT "Create SUIT artifacts" |
| 141 | + ) |
| 142 | + message(INFO " Generate MPI for ${manifest_role} manifest (${descr_args})") |
| 143 | +endfunction() |
| 144 | + |
| 145 | +# Usage: |
| 146 | +# generate_mpi_area(<area_name> [<manifest_role>...]) |
| 147 | +# |
| 148 | +# Will generate HEX file for an MPI area attached to a single domain. |
| 149 | +# At the end of the merging process, a digest of the resulting binary will be |
| 150 | +# calculated and appended at the end of it. |
| 151 | +# |
| 152 | +# <area_name>: Name of the area. A valid area must define output file path, address and size. |
| 153 | +# <manifest_role>: The role that was used to generate a set of Kconfigs, defined by the |
| 154 | +# Kconfig.template.manifest_config. |
| 155 | +# Used to extract the HEX file path containing the MPI configuration. |
| 156 | +# |
| 157 | +# Required Kconfigs: |
| 158 | +# - SUIT_MPI_<area_name>_PATH |
| 159 | +# - SUIT_MPI_<area_name>_OFFSET |
| 160 | +# - SUIT_MPI_<area_name>_SIZE |
| 161 | +# - SUIT_MPI_<manifest_role>_PATH |
| 162 | +# |
| 163 | +function (generate_mpi_area area) |
| 164 | + set(merge_args "") |
| 165 | + set(dependencies "") |
| 166 | + |
| 167 | + if((NOT DEFINED SB_CONFIG_SUIT_MPI_${area}_PATH) OR |
| 168 | + (NOT DEFINED SB_CONFIG_SUIT_MPI_${area}_OFFSET) OR |
| 169 | + (NOT DEFINED SB_CONFIG_SUIT_MPI_${area}_SIZE) |
| 170 | + ) |
| 171 | + message(FATAL_ERROR "Malformed configuration for: ${area}") |
| 172 | + return() |
| 173 | + endif() |
| 174 | + |
| 175 | + # Calculate the absolute address of the MPI area. |
| 176 | + MATH( |
| 177 | + EXPR |
| 178 | + SUIT_MPI_${area}_ADDRESS |
| 179 | + "${SUIT_STORAGE_ADDRESS} |
| 180 | + + ${SB_CONFIG_SUIT_MPI_${area}_OFFSET}" |
| 181 | + OUTPUT_FORMAT HEXADECIMAL |
| 182 | + ) |
| 183 | + |
| 184 | + set(output ${MPI_BINARY_DIR}/${SB_CONFIG_SUIT_MPI_${area}_PATH}) |
| 185 | + set(address ${SUIT_MPI_${area}_ADDRESS}) |
| 186 | + set(size ${SB_CONFIG_SUIT_MPI_${area}_SIZE}) |
| 187 | + |
| 188 | + list(APPEND merge_args |
| 189 | + --output-file ${output} |
| 190 | + --address ${address} |
| 191 | + --size ${size} |
| 192 | + ) |
| 193 | + |
| 194 | + foreach(role ${ARGN}) |
| 195 | + if(NOT DEFINED SB_CONFIG_SUIT_MPI_${role}_PATH) |
| 196 | + continue() |
| 197 | + endif() |
| 198 | + |
| 199 | + list(APPEND merge_args "--file" "${SB_CONFIG_SUIT_MPI_${role}_PATH}") |
| 200 | + list(APPEND dependencies "${SB_CONFIG_SUIT_MPI_${role}_PATH}") |
| 201 | + endforeach() |
| 202 | + |
| 203 | + add_custom_target( |
| 204 | + create_suit_mpi_area_${area} |
| 205 | + ALL |
| 206 | + COMMAND ${PYTHON_EXECUTABLE} ${SUIT_GENERATOR_CLI_SCRIPT} |
| 207 | + mpi |
| 208 | + merge |
| 209 | + ${merge_args} |
| 210 | + DEPENDS ${dependencies} |
| 211 | + BYPRODUCTS ${output} |
| 212 | + COMMENT "Create SUIT artifacts" |
| 213 | + ) |
| 214 | + |
| 215 | + message(INFO " Generate merged MPI for ${area} (${output})") |
| 216 | +endfunction() |
| 217 | + |
| 218 | +if(DEFINED SB_CONFIG_SOC_SERIES_NRF54HX) |
| 219 | + configure_storage_address_cache() |
| 220 | +endif() # SB_CONFIG_SOC_SERIES_NRF54HX |
| 221 | + |
| 222 | +if(DEFINED SB_CONFIG_SUIT_MPI_GENERATE) |
| 223 | + if(DEFINED SB_CONFIG_SUIT_MPI_SOC_NRF54H20) |
| 224 | + include(${CMAKE_CURRENT_LIST_DIR}/suit_provisioning_nrf54h20.cmake) |
| 225 | + endif() # SB_CONFIG_SUIT_MPI_SOC_NRF54H20 |
| 226 | +endif() # SB_CONFIG_SUIT_MPI_GENERATE |
0 commit comments