Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | {{utilities.donotedit_warning}} |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | #include <stddef.h> |
| 12 | #include "region.h" |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 13 | #include "load/irq_defs.h" |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 14 | #include "load/partition_defs.h" |
| 15 | #include "load/service_defs.h" |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 16 | #include "load/asset_defs.h" |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 17 | #include "tfm_peripherals_def.h" |
| 18 | #include "psa_manifest/pid.h" |
| 19 | #include "psa_manifest/sid.h" |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 20 | #include "psa_manifest/{{manifest_out_basename}}.h" |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 21 | |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 22 | {% set counter = namespace(dep_counter=0, service_counter=0, asset_counter=0, irq_counter=0) %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 23 | {% if manifest.dependencies %} |
| 24 | {% for dep in manifest.dependencies %} |
| 25 | {% set counter.dep_counter = counter.dep_counter + 1 %} |
| 26 | {% endfor %} |
| 27 | {% endif %} |
| 28 | {% if manifest.services %} |
| 29 | {% for service in manifest.services %} |
| 30 | {% set counter.service_counter = counter.service_counter + 1 %} |
| 31 | {% endfor %} |
| 32 | {% endif %} |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 33 | {% if manifest.mmio_regions %} |
| 34 | {% for asset in manifest.mmio_regions %} |
| 35 | {% set counter.asset_counter = counter.asset_counter + 1 %} |
| 36 | {% endfor %} |
| 37 | {% endif %} |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 38 | {% if manifest.irqs %} |
| 39 | {% for irq in manifest.irqs %} |
| 40 | {% set counter.irq_counter = counter.irq_counter + 1 %} |
| 41 | {% endfor %} |
| 42 | {% endif %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 43 | #define {{"%-55s"|format(manifest.name|upper + "_NDEPS")}} ({{"%d"|format(counter.dep_counter)}}) |
| 44 | #define {{"%-55s"|format(manifest.name|upper + "_NSERVS")}} ({{"%d"|format(counter.service_counter)}}) |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 45 | #if TFM_LVL == 3 |
| 46 | #define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}} + 1) |
| 47 | #else |
| 48 | #define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}}) |
| 49 | #endif |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 50 | #define {{"%-55s"|format(manifest.name|upper + "_NIRQS")}} ({{"%d"|format(counter.irq_counter)}}) |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 51 | |
| 52 | /* Memory region declaration */ |
| 53 | #if TFM_LVL == 3 |
| 54 | REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base); |
| 55 | REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base); |
| 56 | #endif |
| 57 | extern uint8_t {{manifest.name|lower}}_stack[]; |
| 58 | |
Shawn Shan | caefb8f | 2021-04-15 14:19:13 +0800 | [diff] [blame^] | 59 | {% if manifest.entry_init and manifest.entry_point %} |
| 60 | #error "Both manifest.entry_init and manifest.entry_point exist, unsupported!" |
| 61 | {% elif (manifest.model == "IPC" or manifest.psa_framework_version == 1.0) and (not manifest.entry_point) %} |
| 62 | #error "The entry_point attribute is required, it should not be empty!" |
| 63 | {% elif manifest.model == "SFN" and manifest.entry_point %} |
| 64 | #error "The entry_point attribute should not be exist in SFN mode!" |
| 65 | {% endif %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 66 | /* Entrypoint function declaration */ |
Shawn Shan | caefb8f | 2021-04-15 14:19:13 +0800 | [diff] [blame^] | 67 | {% if manifest.entry_point %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 68 | extern void {{manifest.entry_point}}(void); |
Shawn Shan | caefb8f | 2021-04-15 14:19:13 +0800 | [diff] [blame^] | 69 | {% elif manifest.entry_init %} |
| 70 | extern psa_status_t {{manifest.entry_init}}(void); |
| 71 | {% endif %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 72 | |
Mingyang Sun | 8d004f7 | 2021-06-01 10:46:26 +0800 | [diff] [blame] | 73 | /* partition load info type definition */ |
Ken Liu | 4520ce3 | 2021-05-11 22:49:10 +0800 | [diff] [blame] | 74 | struct partition_{{manifest.name|lower}}_load_info_t { |
Mingyang Sun | 8d004f7 | 2021-06-01 10:46:26 +0800 | [diff] [blame] | 75 | /* common length load data */ |
| 76 | struct partition_load_info_t load_info; |
| 77 | /* per-partition variable length load data */ |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 78 | uintptr_t stack_addr; |
| 79 | uintptr_t heap_addr; |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 80 | {% if manifest.dependencies %} |
| 81 | uint32_t deps[{{(manifest.name|upper + "_NDEPS")}}]; |
| 82 | {% endif %} |
| 83 | {% if manifest.services %} |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 84 | struct service_load_info_t services[{{(manifest.name|upper + "_NSERVS")}}]; |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 85 | {% endif %} |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 86 | #if TFM_LVL == 3 |
| 87 | struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}]; |
| 88 | #else |
| 89 | {% if manifest.mmio_regions %} |
| 90 | struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}]; |
| 91 | {% endif %} |
| 92 | #endif |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 93 | {% if manifest.irqs %} |
| 94 | struct irq_load_info_t irqs[{{(manifest.name|upper + "_NIRQS")}}]; |
| 95 | {% endif %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 96 | } __attribute__((aligned(4))); |
| 97 | |
Mingyang Sun | 8d004f7 | 2021-06-01 10:46:26 +0800 | [diff] [blame] | 98 | /* Partition load, deps, service load data. Put to a dedicated section. */ |
| 99 | const struct partition_{{manifest.name|lower}}_load_info_t {{manifest.name|lower}}_load |
| 100 | __attribute__((used, section(".part_load"))) = { |
| 101 | .load_info = { |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 102 | {% if manifest.psa_framework_version == 1.0 %} |
| 103 | .psa_ff_ver = 0x0100 | PARTITION_INFO_MAGIC, |
| 104 | {% elif manifest.psa_framework_version == 1.1 %} |
| 105 | .psa_ff_ver = 0x0101 | PARTITION_INFO_MAGIC, |
| 106 | {% else %} |
| 107 | #error "Unsupported ff version '{{manifest.psa_framework_version}}' for partition '{{manifest.name}}'!" |
| 108 | {% endif %} |
| 109 | .pid = {{manifest.name}}, |
| 110 | .flags = 0 |
Shawn Shan | caefb8f | 2021-04-15 14:19:13 +0800 | [diff] [blame^] | 111 | {% if (manifest.psa_framework_version == 1.1 and manifest.model == "IPC") or manifest.psa_framework_version == 1.0 %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 112 | | SPM_PART_FLAG_IPC |
| 113 | {% endif %} |
| 114 | {% if manifest.type == "PSA-ROT" %} |
| 115 | | SPM_PART_FLAG_PSA_ROT |
| 116 | {% elif manifest.type != "APPLICATION-ROT" %} |
| 117 | #error "Unsupported type '{{manifest.type}}' for partition '{{manifest.name}}'!" |
| 118 | {% endif %} |
| 119 | | PARTITION_PRI_{{manifest.priority}}, |
Shawn Shan | caefb8f | 2021-04-15 14:19:13 +0800 | [diff] [blame^] | 120 | {% if manifest.entry_point %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 121 | .entry = ENTRY_TO_POSITION({{manifest.entry_point}}), |
Shawn Shan | caefb8f | 2021-04-15 14:19:13 +0800 | [diff] [blame^] | 122 | {% elif manifest.entry_init %} |
| 123 | .entry = ENTRY_TO_POSITION({{manifest.entry_init}}), |
| 124 | {% else %} |
| 125 | .entry = NULL, |
| 126 | {% endif %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 127 | .stack_size = {{manifest.stack_size}}, |
| 128 | .heap_size = 0, |
| 129 | .ndeps = {{(manifest.name|upper + "_NDEPS")}}, |
| 130 | .nservices = {{(manifest.name|upper + "_NSERVS")}}, |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 131 | .nassets = {{(manifest.name|upper + "_NASSETS")}}, |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 132 | .nirqs = {{(manifest.name|upper + "_NIRQS")}}, |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 133 | }, |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 134 | .stack_addr = (uintptr_t){{manifest.name|lower}}_stack, |
| 135 | .heap_addr = 0, |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 136 | {% if manifest.dependencies %} |
| 137 | .deps = { |
| 138 | {% for dep in manifest.dependencies %} |
| 139 | {{dep}}_SID, |
| 140 | {% endfor %} |
| 141 | }, |
| 142 | {% endif %} |
| 143 | {% if manifest.services %} |
| 144 | .services = { |
| 145 | {% for service in manifest.services %} |
| 146 | { |
| 147 | .name_strid = STRING_PTR_TO_STRID("{{service.name}}"), |
Shawn Shan | caefb8f | 2021-04-15 14:19:13 +0800 | [diff] [blame^] | 148 | {% if manifest.psa_framework_version == 1.1 and manifest.model == "SFN" %} |
| 149 | .sfn = ENTRY_TO_POSITION({{service.name|lower}}_sfn), |
| 150 | {% else %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 151 | .signal = {{service.name}}_SIGNAL, |
Shawn Shan | caefb8f | 2021-04-15 14:19:13 +0800 | [diff] [blame^] | 152 | {% endif %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 153 | .sid = {{service.sid}}, |
| 154 | .flags = 0 |
| 155 | {% if service.non_secure_clients is sameas true %} |
| 156 | | SERVICE_FLAG_NS_ACCESSIBLE |
| 157 | {% endif %} |
| 158 | {% if manifest.psa_framework_version > 1.0 and service.connection_based is sameas false %} |
Mingyang Sun | a03ad02 | 2021-06-01 20:41:15 +0800 | [diff] [blame] | 159 | | SERVICE_FLAG_STATELESS | 0x{{"%x"|format(service.stateless_handle_index)}} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 160 | {% endif %} |
| 161 | {% if service.version_policy %} |
Ken Liu | b3b2cb6 | 2021-05-22 00:39:28 +0800 | [diff] [blame] | 162 | | SERVICE_VERSION_POLICY_{{service.version_policy}}, |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 163 | {% else %} |
Ken Liu | b3b2cb6 | 2021-05-22 00:39:28 +0800 | [diff] [blame] | 164 | | SERVICE_VERSION_POLICY_STRICT, |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 165 | {% endif %} |
| 166 | {% if service.version %} |
| 167 | .version = {{service.version}}, |
| 168 | {% else %} |
| 169 | .version = 1, |
| 170 | {% endif %} |
| 171 | }, |
| 172 | {% endfor %} |
| 173 | }, |
| 174 | {% endif %} |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 175 | #if TFM_LVL == 3 |
| 176 | .assets = { |
| 177 | { |
| 178 | .mem.addr_x = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base), |
| 179 | .mem.addr_y = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base), |
| 180 | .attr = ASSET_MEM_RD_BIT | ASSET_MEM_WR_BIT, |
| 181 | }, |
| 182 | {% for region in manifest.mmio_regions %} |
| 183 | {% if region.conditional %} |
| 184 | #ifdef {{region.conditional}} |
| 185 | {% endif %} |
| 186 | { |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 187 | .dev.addr_ref = PTR_TO_REFERENCE({{region.name}}), |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 188 | .attr = ASSET_DEV_REF_BIT, |
| 189 | }, |
| 190 | {% if region.conditional %} |
| 191 | #endif |
| 192 | {% endif %} |
| 193 | {% endfor %} |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 194 | }, |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 195 | #else |
| 196 | {% if manifest.mmio_regions %} |
| 197 | .assets = { |
| 198 | {% for region in manifest.mmio_regions %} |
| 199 | {% if region.conditional %} |
| 200 | #ifdef {{region.conditional}} |
| 201 | {% endif %} |
| 202 | { |
Ken Liu | acd2a57 | 2021-05-12 16:19:04 +0800 | [diff] [blame] | 203 | .dev.addr_ref = PTR_TO_REFERENCE({{region.name}}), |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 204 | .attr = ASSET_DEV_REF_BIT, |
| 205 | }, |
| 206 | {% if region.conditional %} |
| 207 | #endif |
| 208 | {% endif %} |
| 209 | {% endfor %} |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 210 | }, |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 211 | {% endif %} |
| 212 | #endif |
Kevin Peng | 27e4227 | 2021-05-24 17:58:53 +0800 | [diff] [blame] | 213 | {% if manifest.irqs %} |
| 214 | .irqs = { |
| 215 | {% for irq in manifest.irqs %} |
| 216 | {% set irq_info = namespace() %} |
| 217 | {% set irq_info.source = irq.source %} |
| 218 | {% if manifest.psa_framework_version == 1.1 and irq.handling == "FLIH" %} |
| 219 | {% set irq_info.flih_func = "(uint32_t)" + irq.name|lower + "_flih" %} |
| 220 | {% else %} |
| 221 | {% set irq_info.flih_func = 0 %} |
| 222 | {% endif %} |
| 223 | {% if manifest.psa_framework_version == 1.0 %} |
| 224 | {% set irq_info.signal = irq.signal %} |
| 225 | {% else %} |
| 226 | {% set irq_info.signal = irq.name + "_SIGNAL" %} |
| 227 | {% endif %} |
| 228 | { |
| 229 | .source = {{irq_info.source}}, |
| 230 | .flih_func = {{irq_info.flih_func}}, |
| 231 | .signal = {{irq_info.signal}}, |
| 232 | }, |
| 233 | {% endfor %} |
| 234 | }, |
| 235 | {% endif %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 236 | }; |