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" |
| 13 | #include "load/partition_static_load.h" |
| 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 | |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 22 | {% set counter = namespace(dep_counter=0, service_counter=0, asset_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 %} |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 38 | #define {{"%-55s"|format(manifest.name|upper + "_NDEPS")}} ({{"%d"|format(counter.dep_counter)}}) |
| 39 | #define {{"%-55s"|format(manifest.name|upper + "_NSERVS")}} ({{"%d"|format(counter.service_counter)}}) |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 40 | #if TFM_LVL == 3 |
| 41 | #define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}} + 1) |
| 42 | #else |
| 43 | #define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}}) |
| 44 | #endif |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 45 | |
| 46 | /* Memory region declaration */ |
| 47 | #if TFM_LVL == 3 |
| 48 | REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base); |
| 49 | REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base); |
| 50 | #endif |
| 51 | extern uint8_t {{manifest.name|lower}}_stack[]; |
| 52 | |
| 53 | /* Entrypoint function declaration */ |
| 54 | extern void {{manifest.entry_point}}(void); |
| 55 | |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 56 | /* partition static info type definition */ |
Ken Liu | 4520ce3 | 2021-05-11 22:49:10 +0800 | [diff] [blame] | 57 | struct partition_{{manifest.name|lower}}_load_info_t { |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 58 | /* common length data */ |
Ken Liu | 4520ce3 | 2021-05-11 22:49:10 +0800 | [diff] [blame] | 59 | struct partition_load_info_t cmn_info; |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 60 | /* per-partition variable length data */ |
| 61 | uintptr_t stack_pos; |
| 62 | uintptr_t heap_pos; |
| 63 | {% if manifest.dependencies %} |
| 64 | uint32_t deps[{{(manifest.name|upper + "_NDEPS")}}]; |
| 65 | {% endif %} |
| 66 | {% if manifest.services %} |
Ken Liu | 4520ce3 | 2021-05-11 22:49:10 +0800 | [diff] [blame] | 67 | struct service_load_info_t services[{{(manifest.name|upper + "_NSERVS")}}]; |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 68 | {% endif %} |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 69 | #if TFM_LVL == 3 |
| 70 | struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}]; |
| 71 | #else |
| 72 | {% if manifest.mmio_regions %} |
| 73 | struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}]; |
| 74 | {% endif %} |
| 75 | #endif |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 76 | } __attribute__((aligned(4))); |
| 77 | |
| 78 | /* Partition static, deps, service static data. Put to a dedicated section. */ |
Ken Liu | 4520ce3 | 2021-05-11 22:49:10 +0800 | [diff] [blame] | 79 | const struct partition_{{manifest.name|lower}}_load_info_t {{manifest.name|lower}}_static |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 80 | __attribute__((used, section(".partition_info"))) = { |
| 81 | .cmn_info = { |
| 82 | {% if manifest.psa_framework_version == 1.0 %} |
| 83 | .psa_ff_ver = 0x0100 | PARTITION_INFO_MAGIC, |
| 84 | {% elif manifest.psa_framework_version == 1.1 %} |
| 85 | .psa_ff_ver = 0x0101 | PARTITION_INFO_MAGIC, |
| 86 | {% else %} |
| 87 | #error "Unsupported ff version '{{manifest.psa_framework_version}}' for partition '{{manifest.name}}'!" |
| 88 | {% endif %} |
| 89 | .pid = {{manifest.name}}, |
| 90 | .flags = 0 |
| 91 | {% if manifest.psa_framework_version == 1.0 and attr.tfm_partition_ipc is sameas true %} |
| 92 | | SPM_PART_FLAG_IPC |
| 93 | {% elif manifest.psa_framework_version == 1.1 and manifest.model == "IPC" %} |
| 94 | | SPM_PART_FLAG_IPC |
| 95 | {% endif %} |
| 96 | {% if manifest.type == "PSA-ROT" %} |
| 97 | | SPM_PART_FLAG_PSA_ROT |
| 98 | {% elif manifest.type != "APPLICATION-ROT" %} |
| 99 | #error "Unsupported type '{{manifest.type}}' for partition '{{manifest.name}}'!" |
| 100 | {% endif %} |
| 101 | | PARTITION_PRI_{{manifest.priority}}, |
| 102 | .entry = ENTRY_TO_POSITION({{manifest.entry_point}}), |
| 103 | .stack_size = {{manifest.stack_size}}, |
| 104 | .heap_size = 0, |
| 105 | .ndeps = {{(manifest.name|upper + "_NDEPS")}}, |
| 106 | .nservices = {{(manifest.name|upper + "_NSERVS")}}, |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 107 | .nassets = {{(manifest.name|upper + "_NASSETS")}}, |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 108 | }, |
| 109 | .stack_pos = PTR_TO_POSITION({{manifest.name|lower}}_stack), |
| 110 | .heap_pos = 0, |
| 111 | {% if manifest.dependencies %} |
| 112 | .deps = { |
| 113 | {% for dep in manifest.dependencies %} |
| 114 | {{dep}}_SID, |
| 115 | {% endfor %} |
| 116 | }, |
| 117 | {% endif %} |
| 118 | {% if manifest.services %} |
| 119 | .services = { |
| 120 | {% for service in manifest.services %} |
| 121 | { |
| 122 | .name_strid = STRING_PTR_TO_STRID("{{service.name}}"), |
| 123 | .signal = {{service.name}}_SIGNAL, |
| 124 | .sid = {{service.sid}}, |
| 125 | .flags = 0 |
| 126 | {% if service.non_secure_clients is sameas true %} |
| 127 | | SERVICE_FLAG_NS_ACCESSIBLE |
| 128 | {% endif %} |
| 129 | {% if manifest.psa_framework_version > 1.0 and service.connection_based is sameas false %} |
| 130 | | SERVICE_FLAG_STATELESS |
| 131 | {% endif %} |
| 132 | {% if service.version_policy %} |
| 133 | | TFM_VERSION_POLICY_{{service.version_policy}}, |
| 134 | {% else %} |
| 135 | | TFM_VERSION_POLICY_STRICT, |
| 136 | {% endif %} |
| 137 | {% if service.version %} |
| 138 | .version = {{service.version}}, |
| 139 | {% else %} |
| 140 | .version = 1, |
| 141 | {% endif %} |
| 142 | }, |
| 143 | {% endfor %} |
| 144 | }, |
| 145 | {% endif %} |
Ken Liu | 8668628 | 2021-04-27 11:11:15 +0800 | [diff] [blame] | 146 | #if TFM_LVL == 3 |
| 147 | .assets = { |
| 148 | { |
| 149 | .mem.addr_x = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base), |
| 150 | .mem.addr_y = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base), |
| 151 | .attr = ASSET_MEM_RD_BIT | ASSET_MEM_WR_BIT, |
| 152 | }, |
| 153 | {% for region in manifest.mmio_regions %} |
| 154 | {% if region.conditional %} |
| 155 | #ifdef {{region.conditional}} |
| 156 | {% endif %} |
| 157 | { |
| 158 | .dev.addr_ref = PTR_TO_POSITION({{region.name}}), |
| 159 | .attr = ASSET_DEV_REF_BIT, |
| 160 | }, |
| 161 | {% if region.conditional %} |
| 162 | #endif |
| 163 | {% endif %} |
| 164 | {% endfor %} |
| 165 | } |
| 166 | #else |
| 167 | {% if manifest.mmio_regions %} |
| 168 | .assets = { |
| 169 | {% for region in manifest.mmio_regions %} |
| 170 | {% if region.conditional %} |
| 171 | #ifdef {{region.conditional}} |
| 172 | {% endif %} |
| 173 | { |
| 174 | .dev.addr_ref = PTR_TO_POSITION({{region.name}}), |
| 175 | .attr = ASSET_DEV_REF_BIT, |
| 176 | }, |
| 177 | {% if region.conditional %} |
| 178 | #endif |
| 179 | {% endif %} |
| 180 | {% endfor %} |
| 181 | } |
| 182 | {% endif %} |
| 183 | #endif |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 184 | }; |