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" |
| 16 | #include "tfm_peripherals_def.h" |
| 17 | #include "psa_manifest/pid.h" |
| 18 | #include "psa_manifest/sid.h" |
| 19 | #include "psa_manifest/{{file_name}}.h" |
| 20 | |
| 21 | {% set counter = namespace(dep_counter=0, service_counter=0) %} |
| 22 | {% if manifest.dependencies %} |
| 23 | {% for dep in manifest.dependencies %} |
| 24 | {% set counter.dep_counter = counter.dep_counter + 1 %} |
| 25 | {% endfor %} |
| 26 | {% endif %} |
| 27 | {% if manifest.services %} |
| 28 | {% for service in manifest.services %} |
| 29 | {% set counter.service_counter = counter.service_counter + 1 %} |
| 30 | {% endfor %} |
| 31 | {% endif %} |
| 32 | #define {{"%-55s"|format(manifest.name|upper + "_NDEPS")}} ({{"%d"|format(counter.dep_counter)}}) |
| 33 | #define {{"%-55s"|format(manifest.name|upper + "_NSERVS")}} ({{"%d"|format(counter.service_counter)}}) |
| 34 | |
| 35 | /* Memory region declaration */ |
| 36 | #if TFM_LVL == 3 |
| 37 | REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base); |
| 38 | REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base); |
| 39 | #endif |
| 40 | extern uint8_t {{manifest.name|lower}}_stack[]; |
| 41 | |
| 42 | /* Entrypoint function declaration */ |
| 43 | extern void {{manifest.entry_point}}(void); |
| 44 | |
| 45 | {% if manifest.mmio_regions %} |
| 46 | /* Platform data declaration */ |
| 47 | const struct platform_data_t *platform_data_list_{{manifest.name|lower}}[] = |
| 48 | { |
| 49 | {% for region in manifest.mmio_regions %} |
| 50 | {% if region.conditional %} |
| 51 | #ifdef {{region.conditional}} |
| 52 | {% endif %} |
| 53 | {{region.name}}, |
| 54 | {% if region.conditional %} |
| 55 | #endif |
| 56 | {% endif %} |
| 57 | {% endfor %} |
| 58 | NULL |
| 59 | }; |
| 60 | {% endif %} |
| 61 | |
| 62 | /* partition static info type definition */ |
| 63 | struct partition_{{manifest.name|lower}}_static_info_t { |
| 64 | /* common length data */ |
| 65 | struct partition_static_info_t cmn_info; |
| 66 | /* per-partition variable length data */ |
| 67 | uintptr_t stack_pos; |
| 68 | uintptr_t heap_pos; |
| 69 | {% if manifest.dependencies %} |
| 70 | uint32_t deps[{{(manifest.name|upper + "_NDEPS")}}]; |
| 71 | {% endif %} |
| 72 | {% if manifest.services %} |
| 73 | struct service_static_info_t services[{{(manifest.name|upper + "_NSERVS")}}]; |
| 74 | {% endif %} |
| 75 | } __attribute__((aligned(4))); |
| 76 | |
| 77 | /* Partition static, deps, service static data. Put to a dedicated section. */ |
| 78 | const struct partition_{{manifest.name|lower}}_static_info_t {{manifest.name|lower}}_static |
| 79 | __attribute__((used, section(".partition_info"))) = { |
| 80 | .cmn_info = { |
| 81 | {% if manifest.psa_framework_version == 1.0 %} |
| 82 | .psa_ff_ver = 0x0100 | PARTITION_INFO_MAGIC, |
| 83 | {% elif manifest.psa_framework_version == 1.1 %} |
| 84 | .psa_ff_ver = 0x0101 | PARTITION_INFO_MAGIC, |
| 85 | {% else %} |
| 86 | #error "Unsupported ff version '{{manifest.psa_framework_version}}' for partition '{{manifest.name}}'!" |
| 87 | {% endif %} |
| 88 | .pid = {{manifest.name}}, |
| 89 | .flags = 0 |
| 90 | {% if manifest.psa_framework_version == 1.0 and attr.tfm_partition_ipc is sameas true %} |
| 91 | | SPM_PART_FLAG_IPC |
| 92 | {% elif manifest.psa_framework_version == 1.1 and manifest.model == "IPC" %} |
| 93 | | SPM_PART_FLAG_IPC |
| 94 | {% endif %} |
| 95 | {% if manifest.type == "PSA-ROT" %} |
| 96 | | SPM_PART_FLAG_PSA_ROT |
| 97 | {% elif manifest.type != "APPLICATION-ROT" %} |
| 98 | #error "Unsupported type '{{manifest.type}}' for partition '{{manifest.name}}'!" |
| 99 | {% endif %} |
| 100 | | PARTITION_PRI_{{manifest.priority}}, |
| 101 | .entry = ENTRY_TO_POSITION({{manifest.entry_point}}), |
| 102 | .stack_size = {{manifest.stack_size}}, |
| 103 | .heap_size = 0, |
| 104 | .ndeps = {{(manifest.name|upper + "_NDEPS")}}, |
| 105 | .nservices = {{(manifest.name|upper + "_NSERVS")}}, |
| 106 | {% if manifest.mmio_regions %} |
| 107 | .plat_cookie = PTR_TO_POSITION(platform_data_list_{{manifest.name|lower}}), |
| 108 | {% else %} |
| 109 | .plat_cookie = 0, |
| 110 | {% endif %} |
| 111 | #if TFM_LVL == 3 |
| 112 | .mems = { |
| 113 | .start = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base), |
| 114 | .limit = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base), |
| 115 | }, |
| 116 | #endif |
| 117 | }, |
| 118 | .stack_pos = PTR_TO_POSITION({{manifest.name|lower}}_stack), |
| 119 | .heap_pos = 0, |
| 120 | {% if manifest.dependencies %} |
| 121 | .deps = { |
| 122 | {% for dep in manifest.dependencies %} |
| 123 | {{dep}}_SID, |
| 124 | {% endfor %} |
| 125 | }, |
| 126 | {% endif %} |
| 127 | {% if manifest.services %} |
| 128 | .services = { |
| 129 | {% for service in manifest.services %} |
| 130 | { |
| 131 | .name_strid = STRING_PTR_TO_STRID("{{service.name}}"), |
| 132 | .signal = {{service.name}}_SIGNAL, |
| 133 | .sid = {{service.sid}}, |
| 134 | .flags = 0 |
| 135 | {% if service.non_secure_clients is sameas true %} |
| 136 | | SERVICE_FLAG_NS_ACCESSIBLE |
| 137 | {% endif %} |
| 138 | {% if manifest.psa_framework_version > 1.0 and service.connection_based is sameas false %} |
| 139 | | SERVICE_FLAG_STATELESS |
| 140 | {% endif %} |
| 141 | {% if service.version_policy %} |
| 142 | | TFM_VERSION_POLICY_{{service.version_policy}}, |
| 143 | {% else %} |
| 144 | | TFM_VERSION_POLICY_STRICT, |
| 145 | {% endif %} |
| 146 | {% if service.version %} |
| 147 | .version = {{service.version}}, |
| 148 | {% else %} |
| 149 | .version = 1, |
| 150 | {% endif %} |
| 151 | }, |
| 152 | {% endfor %} |
| 153 | }, |
| 154 | {% endif %} |
| 155 | }; |