blob: 90529fb2a274712a0a93db60b3042a03bc22f0fd [file] [log] [blame]
Mingyang Sunf6a78572021-04-02 16:51:05 +08001/*
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"
Mingyang Sunf6a78572021-04-02 16:51:05 +080013#include "load/partition_defs.h"
14#include "load/service_defs.h"
Ken Liu86686282021-04-27 11:11:15 +080015#include "load/asset_defs.h"
Mingyang Sunf6a78572021-04-02 16:51:05 +080016#include "tfm_peripherals_def.h"
17#include "psa_manifest/pid.h"
18#include "psa_manifest/sid.h"
Ken Liu861b0782021-05-22 13:15:08 +080019#include "psa_manifest/{{manifest_out_basename}}.h"
Mingyang Sunf6a78572021-04-02 16:51:05 +080020
Ken Liu86686282021-04-27 11:11:15 +080021{% set counter = namespace(dep_counter=0, service_counter=0, asset_counter=0) %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080022{% 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 %}
Ken Liu86686282021-04-27 11:11:15 +080032{% if manifest.mmio_regions %}
33 {% for asset in manifest.mmio_regions %}
34 {% set counter.asset_counter = counter.asset_counter + 1 %}
35 {% endfor %}
36{% endif %}
Mingyang Sunf6a78572021-04-02 16:51:05 +080037#define {{"%-55s"|format(manifest.name|upper + "_NDEPS")}} ({{"%d"|format(counter.dep_counter)}})
38#define {{"%-55s"|format(manifest.name|upper + "_NSERVS")}} ({{"%d"|format(counter.service_counter)}})
Ken Liu86686282021-04-27 11:11:15 +080039#if TFM_LVL == 3
40#define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}} + 1)
41#else
42#define {{"%-55s"|format(manifest.name|upper + "_NASSETS")}} ({{"%d"|format(counter.asset_counter)}})
43#endif
Mingyang Sunf6a78572021-04-02 16:51:05 +080044
45/* Memory region declaration */
46#if TFM_LVL == 3
47REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base);
48REGION_DECLARE(Image$$, PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base);
49#endif
50extern uint8_t {{manifest.name|lower}}_stack[];
51
52/* Entrypoint function declaration */
53extern void {{manifest.entry_point}}(void);
54
Mingyang Sunf6a78572021-04-02 16:51:05 +080055/* partition static info type definition */
Ken Liu4520ce32021-05-11 22:49:10 +080056struct partition_{{manifest.name|lower}}_load_info_t {
Mingyang Sunf6a78572021-04-02 16:51:05 +080057 /* common length data */
Ken Liu4520ce32021-05-11 22:49:10 +080058 struct partition_load_info_t cmn_info;
Mingyang Sunf6a78572021-04-02 16:51:05 +080059 /* per-partition variable length data */
Ken Liuacd2a572021-05-12 16:19:04 +080060 uintptr_t stack_addr;
61 uintptr_t heap_addr;
Mingyang Sunf6a78572021-04-02 16:51:05 +080062{% if manifest.dependencies %}
63 uint32_t deps[{{(manifest.name|upper + "_NDEPS")}}];
64{% endif %}
65{% if manifest.services %}
Ken Liuacd2a572021-05-12 16:19:04 +080066 struct service_load_info_t services[{{(manifest.name|upper + "_NSERVS")}}];
Mingyang Sunf6a78572021-04-02 16:51:05 +080067{% endif %}
Ken Liu86686282021-04-27 11:11:15 +080068#if TFM_LVL == 3
69 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}];
70#else
71{% if manifest.mmio_regions %}
72 struct asset_desc_t assets[{{(manifest.name|upper + "_NASSETS")}}];
73{% endif %}
74#endif
Mingyang Sunf6a78572021-04-02 16:51:05 +080075} __attribute__((aligned(4)));
76
77/* Partition static, deps, service static data. Put to a dedicated section. */
Ken Liu4520ce32021-05-11 22:49:10 +080078const struct partition_{{manifest.name|lower}}_load_info_t {{manifest.name|lower}}_static
Mingyang Sunf6a78572021-04-02 16:51:05 +080079 __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")}},
Ken Liu86686282021-04-27 11:11:15 +0800106 .nassets = {{(manifest.name|upper + "_NASSETS")}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800107 },
Ken Liuacd2a572021-05-12 16:19:04 +0800108 .stack_addr = (uintptr_t){{manifest.name|lower}}_stack,
109 .heap_addr = 0,
Mingyang Sunf6a78572021-04-02 16:51:05 +0800110{% if manifest.dependencies %}
111 .deps = {
112 {% for dep in manifest.dependencies %}
113 {{dep}}_SID,
114 {% endfor %}
115 },
116{% endif %}
117{% if manifest.services %}
118 .services = {
119 {% for service in manifest.services %}
120 {
121 .name_strid = STRING_PTR_TO_STRID("{{service.name}}"),
122 .signal = {{service.name}}_SIGNAL,
123 .sid = {{service.sid}},
124 .flags = 0
125 {% if service.non_secure_clients is sameas true %}
126 | SERVICE_FLAG_NS_ACCESSIBLE
127 {% endif %}
128 {% if manifest.psa_framework_version > 1.0 and service.connection_based is sameas false %}
Mingyang Suna03ad022021-06-01 20:41:15 +0800129 | SERVICE_FLAG_STATELESS | 0x{{"%x"|format(service.stateless_handle_index)}}
Mingyang Sunf6a78572021-04-02 16:51:05 +0800130 {% endif %}
131 {% if service.version_policy %}
Ken Liub3b2cb62021-05-22 00:39:28 +0800132 | SERVICE_VERSION_POLICY_{{service.version_policy}},
Mingyang Sunf6a78572021-04-02 16:51:05 +0800133 {% else %}
Ken Liub3b2cb62021-05-22 00:39:28 +0800134 | SERVICE_VERSION_POLICY_STRICT,
Mingyang Sunf6a78572021-04-02 16:51:05 +0800135 {% endif %}
136 {% if service.version %}
137 .version = {{service.version}},
138 {% else %}
139 .version = 1,
140 {% endif %}
141 },
142 {% endfor %}
143 },
144{% endif %}
Ken Liu86686282021-04-27 11:11:15 +0800145#if TFM_LVL == 3
146 .assets = {
147 {
148 .mem.addr_x = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_START$$Base),
149 .mem.addr_y = PART_REGION_ADDR(PT_{{manifest.name}}_PRIVATE, _DATA_END$$Base),
150 .attr = ASSET_MEM_RD_BIT | ASSET_MEM_WR_BIT,
151 },
152{% for region in manifest.mmio_regions %}
153 {% if region.conditional %}
154#ifdef {{region.conditional}}
155 {% endif %}
156 {
Ken Liuacd2a572021-05-12 16:19:04 +0800157 .dev.addr_ref = PTR_TO_REFERENCE({{region.name}}),
Ken Liu86686282021-04-27 11:11:15 +0800158 .attr = ASSET_DEV_REF_BIT,
159 },
160 {% if region.conditional %}
161#endif
162 {% endif %}
163{% endfor %}
164 }
165#else
166{% if manifest.mmio_regions %}
167 .assets = {
168 {% for region in manifest.mmio_regions %}
169 {% if region.conditional %}
170#ifdef {{region.conditional}}
171 {% endif %}
172 {
Ken Liuacd2a572021-05-12 16:19:04 +0800173 .dev.addr_ref = PTR_TO_REFERENCE({{region.name}}),
Ken Liu86686282021-04-27 11:11:15 +0800174 .attr = ASSET_DEV_REF_BIT,
175 },
176 {% if region.conditional %}
177#endif
178 {% endif %}
179 {% endfor %}
180 }
181{% endif %}
182#endif
Mingyang Sunf6a78572021-04-02 16:51:05 +0800183};