Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Jamie Fox | b15418a | 2024-01-18 11:10:20 +0000 | [diff] [blame] | 2 | # Copyright (c) 2018-2024, Arm Limited. All rights reserved. |
Chris Brand | f1d6b6f | 2022-07-22 11:49:01 -0700 | [diff] [blame] | 3 | # Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company) |
| 4 | # or an affiliate of Cypress Semiconductor Corporation. All rights reserved. |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 5 | # |
| 6 | # SPDX-License-Identifier: BSD-3-Clause |
| 7 | # |
| 8 | #------------------------------------------------------------------------------- |
| 9 | |
| 10 | import os |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 11 | import io |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 12 | import re |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 13 | import sys |
| 14 | import argparse |
Jimmy Brisson | 89d4f8d | 2021-06-23 10:17:36 -0500 | [diff] [blame] | 15 | import logging |
Ken Liu | 1f345b0 | 2020-05-30 21:11:05 +0800 | [diff] [blame] | 16 | from jinja2 import Environment, BaseLoader, select_autoescape, TemplateNotFound |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 17 | |
| 18 | try: |
| 19 | import yaml |
| 20 | except ImportError as e: |
Jimmy Brisson | 89d4f8d | 2021-06-23 10:17:36 -0500 | [diff] [blame] | 21 | logging.error (str(e) + " To install it, type:") |
| 22 | logging.error ("pip install PyYAML") |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 23 | exit(1) |
| 24 | |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 25 | donotedit_warning = \ |
Sherry Zhang | f58f2bd | 2022-01-10 17:21:11 +0800 | [diff] [blame] | 26 | ' WARNING: This is an auto-generated file. Do not edit! ' |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 27 | |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 28 | TFM_ROOT_DIR = os.path.join(sys.path[0], '..') |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 29 | OUT_DIR = None # The root directory that files are generated to |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 30 | |
Sherry Zhang | 87e6d2e | 2021-12-27 14:48:59 +0800 | [diff] [blame] | 31 | # PID[0, TFM_PID_BASE - 1] are reserved for TF-M SPM and test usages |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 32 | TFM_PID_BASE = 256 |
| 33 | |
Ruiqi Jiang | 71d361c | 2021-06-23 17:45:55 +0100 | [diff] [blame] | 34 | # variable for checking for duplicated sid |
| 35 | sid_list = [] |
chesun01 | 2345aa5 | 2023-04-18 17:31:53 +0800 | [diff] [blame] | 36 | |
Jason Guo | 8a45a68 | 2023-08-23 11:22:37 +0800 | [diff] [blame^] | 37 | # Manifest attributes defined by FF-M |
| 38 | ffm_manifest_attributes = \ |
| 39 | ['psa_framework_version', 'name', 'type', 'priority', 'model', 'entry_point', 'stack_size', \ |
| 40 | 'description', 'entry_init', 'heap_size', 'mmio_regions', 'services', 'irqs', 'dependencies',\ |
| 41 | # TF-M extension of PSA attributes for mailbox client support. |
| 42 | 'client_id_base', 'client_id_limit'] |
| 43 | |
| 44 | # Manifest attributes defined by FF-M within "service" attribute |
| 45 | ffm_manifest_services_attributes = \ |
| 46 | ['name', 'sid', 'non_secure_clients', 'description', 'version', 'version_policy', \ |
| 47 | 'connection_based', 'stateless_handle', 'mm_iovec'] |
| 48 | |
| 49 | # Manifest attributes defined by FF-M within "mmio_regions" attribute |
| 50 | ffm_manifest_mmio_regions_attributes = ['name', 'base', 'size', 'permission'] |
| 51 | |
| 52 | # Manifest attributes defined by FF-M within "irqs" attribute |
| 53 | ffm_manifest_irqs_attributes = ['source', 'signal', 'name', 'handling', 'description',\ |
| 54 | # TF-M extension of PSA attributes for mailbox client support. |
| 55 | 'client_id_base', 'client_id_limit'] |
chesun01 | 2345aa5 | 2023-04-18 17:31:53 +0800 | [diff] [blame] | 56 | |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 57 | class TemplateLoader(BaseLoader): |
| 58 | """ |
| 59 | Template loader class. |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 60 | |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 61 | An instance of this class is passed to the template engine. It is |
| 62 | responsible for reading the template file |
| 63 | """ |
| 64 | def __init__(self): |
| 65 | pass |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 66 | |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 67 | def get_source(self, environment, template): |
| 68 | """ |
| 69 | This function reads the template files. |
| 70 | For detailed documentation see: |
| 71 | http://jinja.pocoo.org/docs/2.10/api/#jinja2.BaseLoader.get_source |
| 72 | |
| 73 | Please note that this function always return 'false' as 'uptodate' |
| 74 | value, so the output file will always be generated. |
| 75 | """ |
| 76 | if not os.path.isfile(template): |
| 77 | raise TemplateNotFound(template) |
| 78 | with open(template) as f: |
| 79 | source = f.read() |
| 80 | return source, template, False |
| 81 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 82 | def parse_configurations(file_paths): |
| 83 | """ |
| 84 | Parses the given config files and return a dict whose key-values are build |
| 85 | configurations and their values. |
| 86 | |
| 87 | Valid configurations should be in the format of: |
| 88 | "#define VAR [...]" in a single line. |
| 89 | The value of the config is optional. |
| 90 | """ |
| 91 | configurations = {} |
| 92 | |
| 93 | lines = [] |
| 94 | for file in file_paths: |
| 95 | with open(file, 'r') as config_file: |
| 96 | lines += config_file.readlines() |
| 97 | |
| 98 | for line in lines: |
| 99 | if not line.startswith('#define'): |
| 100 | continue |
| 101 | |
| 102 | line = line.rstrip('\r\n') |
| 103 | line_items = line.split(maxsplit=2) |
| 104 | if len(line_items) == 3: |
| 105 | configurations[line_items[1]] = line_items[2] |
| 106 | elif len(line_items) == 2: |
| 107 | configurations[line_items[1]] = '' |
| 108 | |
| 109 | logging.debug(configurations) |
| 110 | |
| 111 | return configurations |
| 112 | |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 113 | def manifest_validation(manifest, pid): |
Mingyang Sun | 294ce2e | 2021-06-11 11:58:24 +0800 | [diff] [blame] | 114 | """ |
| 115 | This function validates FF-M compliance for partition manifest, and sets |
| 116 | default values for optional attributes. |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 117 | The validation is skipped for TF-M specific Partitions (PID < TFM_PID_BASE). |
Mingyang Sun | 294ce2e | 2021-06-11 11:58:24 +0800 | [diff] [blame] | 118 | """ |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 119 | |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 120 | service_list = manifest.get('services', []) |
| 121 | irq_list = manifest.get('irqs', []) |
Mingyang Sun | 294ce2e | 2021-06-11 11:58:24 +0800 | [diff] [blame] | 122 | |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 123 | # "psa_framework_version" validation |
| 124 | if manifest['psa_framework_version'] not in [1.0, 1.1]: |
| 125 | raise Exception('Invalid psa_framework_version of {}'.format(manifest['name'])) |
| 126 | |
Chris Brand | f1d6b6f | 2022-07-22 11:49:01 -0700 | [diff] [blame] | 127 | # "type" validation |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 128 | if manifest['type'] not in ['PSA-ROT', 'APPLICATION-ROT']: |
| 129 | raise Exception('Invalid type of {}'.format(manifest['name'])) |
| 130 | |
Chris Brand | f1d6b6f | 2022-07-22 11:49:01 -0700 | [diff] [blame] | 131 | # "priority" validation |
| 132 | if manifest['priority'] not in ['HIGH', 'NORMAL', 'LOW']: |
| 133 | raise Exception('Invalid priority of {}'.format(manifest['name'])) |
| 134 | |
Chris Brand | c422cdd | 2022-07-21 13:32:47 -0700 | [diff] [blame] | 135 | if 'ns_agent' not in manifest: |
| 136 | manifest['ns_agent'] = False |
| 137 | |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 138 | # Every PSA Partition must have at least either a secure service or an IRQ |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 139 | if (pid == None or pid >= TFM_PID_BASE) \ |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 140 | and len(service_list) == 0 and len(irq_list) == 0: |
| 141 | raise Exception('{} must declare at least either a secure service or an IRQ!' |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 142 | .format(manifest['name'])) |
| 143 | |
| 144 | if manifest['psa_framework_version'] == 1.0: |
| 145 | # For 1.0 Partition, the model is IPC |
| 146 | manifest['model'] = 'IPC' |
| 147 | |
| 148 | # "model" validation: |
| 149 | model = manifest.get('model', None) |
| 150 | if model == None: |
| 151 | raise Exception('{} is missing the "model" attribute'.format(manifest['name'])) |
| 152 | |
| 153 | # Assign a unified 'entry' for templates |
| 154 | if model == 'IPC': |
| 155 | # entry_point is mandatory for IPC Partitions |
| 156 | if 'entry_point' not in manifest.keys(): |
| 157 | raise Exception('{} is missing the "entry_point" attribute'.format(manifest['name'])) |
| 158 | manifest['entry'] = manifest['entry_point'] |
| 159 | elif model == 'SFN': |
| 160 | if 'entry_init' in manifest.keys(): |
| 161 | manifest['entry'] = manifest['entry_init'] |
| 162 | else: |
| 163 | manifest['entry'] = 0 |
| 164 | else: |
| 165 | raise Exception('Invalid "model" of {}'.format(manifest['name'])) |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 166 | |
| 167 | # Service FF-M manifest validation |
| 168 | for service in service_list: |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 169 | if manifest['psa_framework_version'] == 1.0: |
| 170 | service['connection_based'] = True |
| 171 | elif 'connection_based' not in service: |
| 172 | raise Exception("'connection_based' is mandatory in FF-M 1.1 service!") |
| 173 | |
Mingyang Sun | 294ce2e | 2021-06-11 11:58:24 +0800 | [diff] [blame] | 174 | if 'version' not in service.keys(): |
| 175 | service['version'] = 1 |
| 176 | if 'version_policy' not in service.keys(): |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 177 | service['version_policy'] = 'STRICT' |
Mingyang Sun | 294ce2e | 2021-06-11 11:58:24 +0800 | [diff] [blame] | 178 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 179 | # SID duplication check |
| 180 | if service['sid'] in sid_list: |
| 181 | raise Exception('Service ID: {} has duplications!'.format(service['sid'])) |
| 182 | else: |
| 183 | sid_list.append(service['sid']) |
Ruiqi Jiang | 71d361c | 2021-06-23 17:45:55 +0100 | [diff] [blame] | 184 | |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 185 | return manifest |
Mingyang Sun | 294ce2e | 2021-06-11 11:58:24 +0800 | [diff] [blame] | 186 | |
Xinyu Zhang | 7d0a5c8 | 2022-05-16 18:15:11 +0800 | [diff] [blame] | 187 | def check_circular_dependency(partitions, service_partition_map): |
| 188 | """ |
| 189 | This function detects if there is any circular partition dependency chain. |
| 190 | If a circular dependency is detected, the script exits with error. |
| 191 | |
| 192 | Inputs: |
| 193 | - partitions: dict of partition manifests |
| 194 | - service_partition_map: map between services and their owner Partitions |
| 195 | """ |
| 196 | |
| 197 | dependency_table = {} |
| 198 | for partition in partitions: |
| 199 | manifest = partition['manifest'] |
| 200 | dependencies = manifest['dependencies'].copy() \ |
| 201 | if 'dependencies' in manifest else [] |
| 202 | dependencies += manifest['weak_dependencies'].copy() \ |
| 203 | if 'weak_dependencies' in manifest else [] |
| 204 | dependency_table[manifest['name']] = { |
| 205 | 'dependencies': [service_partition_map[dependency] |
| 206 | for dependency in dependencies |
| 207 | if dependency in service_partition_map], |
| 208 | 'validated': False |
| 209 | } |
| 210 | |
| 211 | for partition in dependency_table.keys(): |
| 212 | validate_dependency_chain(partition, dependency_table, []) |
| 213 | |
| 214 | def validate_dependency_chain(partition, |
| 215 | dependency_table, |
| 216 | dependency_chain): |
| 217 | """ |
| 218 | Recursively validate if the given partition and its dependencies |
| 219 | have a circular dependency with the given dependency_chain. |
| 220 | Exit with error code once any circular is detected. |
| 221 | |
| 222 | Inputs: |
| 223 | - partition: next partition to be checked |
| 224 | - dependency_table: dict of partitions and their dependencies |
| 225 | - dependency_chain: list of dependencies in current chain |
| 226 | """ |
| 227 | |
| 228 | dependency_chain.append(partition) |
| 229 | if partition in dependency_chain[:-1]: |
| 230 | logging.error( |
| 231 | 'Circular dependency exists in chain: {}'.format( |
| 232 | ', '.join(dependency_chain))) |
| 233 | exit(1) |
| 234 | for dependency in dependency_table[partition]['dependencies']: |
| 235 | if dependency_table[dependency]['validated']: |
| 236 | continue |
| 237 | validate_dependency_chain(dependency, dependency_table, dependency_chain) |
| 238 | dependency_table[partition]['validated'] = True |
| 239 | |
chesun01 | 2345aa5 | 2023-04-18 17:31:53 +0800 | [diff] [blame] | 240 | def manifest_attribute_check(manifest, manifest_item): |
| 241 | """ |
Jason Guo | 8a45a68 | 2023-08-23 11:22:37 +0800 | [diff] [blame^] | 242 | Check whether there is any invalid attribute in manifests. |
| 243 | Non-FF-M compliant attributes are allowed provided that they are explicitly registered in |
| 244 | manifest lists. And they are only allowed in the top-level attributes. |
| 245 | |
| 246 | Note: |
| 247 | This method only checks the existence of invalid attributes. |
| 248 | It does not validate the values. |
| 249 | Those are done in manifest_validation(). |
| 250 | |
| 251 | The main purposes of this method are: |
| 252 | 1. Make sure developers are aware of using Non-FF-M attributes. |
| 253 | 2. Detect typos on optional attributes. |
chesun01 | 2345aa5 | 2023-04-18 17:31:53 +0800 | [diff] [blame] | 254 | |
| 255 | Inputs: |
| 256 | - manifest: next manifest to be checked |
| 257 | - manifest_item: the manifest items in manifest lists |
| 258 | """ |
Jason Guo | 8a45a68 | 2023-08-23 11:22:37 +0800 | [diff] [blame^] | 259 | |
| 260 | # Top-level attributes check |
chesun01 | 2345aa5 | 2023-04-18 17:31:53 +0800 | [diff] [blame] | 261 | allowed_attributes = ffm_manifest_attributes + manifest_item.get('non_ffm_attributes', []) |
| 262 | for keyword in manifest.keys(): |
| 263 | if keyword not in allowed_attributes: |
Jason Guo | 8a45a68 | 2023-08-23 11:22:37 +0800 | [diff] [blame^] | 264 | logging.error('The Non-FFM attribute "{}" is used by "{}" without registration.' |
| 265 | .format(keyword, manifest['name'])) |
chesun01 | 2345aa5 | 2023-04-18 17:31:53 +0800 | [diff] [blame] | 266 | exit(1) |
| 267 | |
Jason Guo | 8a45a68 | 2023-08-23 11:22:37 +0800 | [diff] [blame^] | 268 | # "services" attribute check |
| 269 | services = manifest.get('services', []) |
| 270 | for srv in services: |
| 271 | for attr in srv.keys(): |
| 272 | if attr not in ffm_manifest_services_attributes: |
| 273 | logging.error('Invalid attribute "{}" used by "{}" in "services".' |
| 274 | .format(attr, manifest['name'])) |
| 275 | exit(1) |
| 276 | |
| 277 | # "mmio_regions" attribute check |
| 278 | mmio_regions = manifest.get('mmio_regions', []) |
| 279 | for reg in mmio_regions: |
| 280 | for attr in reg.keys(): |
| 281 | if attr not in ffm_manifest_mmio_regions_attributes: |
| 282 | logging.error('Invalid attribute "{}" used by "{}" in "mmio_regions".' |
| 283 | .format(attr, manifest['name'])) |
| 284 | exit(1) |
| 285 | |
| 286 | # "irqs" attribute check |
| 287 | irqs = manifest.get('irqs', []) |
| 288 | for irq in irqs: |
| 289 | for attr in irq.keys(): |
| 290 | if attr not in ffm_manifest_irqs_attributes: |
| 291 | logging.error('Invalid attribute "{}" used by "{}" in "irqs".' |
| 292 | .format(attr, manifest['name'])) |
| 293 | exit(1) |
| 294 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 295 | def process_partition_manifests(manifest_lists, configs): |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 296 | """ |
Xinyu Zhang | 7d0a5c8 | 2022-05-16 18:15:11 +0800 | [diff] [blame] | 297 | Parse the input manifest lists, check if manifest settings are valid, |
Chris Brand | f1d6b6f | 2022-07-22 11:49:01 -0700 | [diff] [blame] | 298 | generate the data base for generated files |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 299 | and generate manifest header files. |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 300 | |
| 301 | Parameters |
| 302 | ---------- |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 303 | manifest_lists: |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 304 | A list of Secure Partition manifest lists |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 305 | |
| 306 | Returns |
| 307 | ------- |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 308 | The manifest data base. |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 309 | """ |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 310 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 311 | context = {} |
| 312 | |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 313 | partition_list = [] |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 314 | all_manifests = [] |
Kevin Peng | 56b0ea6 | 2021-10-18 11:32:57 +0800 | [diff] [blame] | 315 | pid_list = [] |
| 316 | no_pid_manifest_idx = [] |
Xinyu Zhang | 7d0a5c8 | 2022-05-16 18:15:11 +0800 | [diff] [blame] | 317 | service_partition_map = {} |
Xinyu Zhang | 90f08dc | 2022-01-12 15:55:17 +0800 | [diff] [blame] | 318 | partition_statistics = { |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame] | 319 | 'connection_based_srv_num': 0, |
Kevin Peng | 47c26ec | 2022-03-11 11:49:52 +0800 | [diff] [blame] | 320 | 'ipc_partitions': [], |
Sherry Zhang | 2ed48fd | 2022-09-06 11:33:22 +0800 | [diff] [blame] | 321 | 'mmio_region_num': 0, |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 322 | 'flih_num': 0, |
| 323 | 'slih_num': 0 |
Xinyu Zhang | 90f08dc | 2022-01-12 15:55:17 +0800 | [diff] [blame] | 324 | } |
Kevin Peng | 9f1a754 | 2022-02-07 16:32:27 +0800 | [diff] [blame] | 325 | config_impl = { |
| 326 | 'CONFIG_TFM_SPM_BACKEND_SFN' : '0', |
| 327 | 'CONFIG_TFM_SPM_BACKEND_IPC' : '0', |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 328 | 'CONFIG_TFM_CONNECTION_BASED_SERVICE_API' : '0', |
Sherry Zhang | 2ed48fd | 2022-09-06 11:33:22 +0800 | [diff] [blame] | 329 | 'CONFIG_TFM_MMIO_REGION_ENABLE' : '0', |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 330 | 'CONFIG_TFM_FLIH_API' : '0', |
| 331 | 'CONFIG_TFM_SLIH_API' : '0' |
Kevin Peng | 9f1a754 | 2022-02-07 16:32:27 +0800 | [diff] [blame] | 332 | } |
chesun01 | 22abf0a | 2023-10-17 13:42:16 +0800 | [diff] [blame] | 333 | priority_map = { |
| 334 | 'LOWEST' : '00', |
| 335 | 'LOW' : '01', |
| 336 | 'NORMAL' : '02', |
| 337 | 'HIGH' : '03', |
| 338 | 'HIGHEST' : '04' |
| 339 | } |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 340 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 341 | isolation_level = int(configs['TFM_ISOLATION_LEVEL'], base = 10) |
| 342 | backend = configs['CONFIG_TFM_SPM_BACKEND'] |
| 343 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 344 | # Get all the manifests information as a dictionary |
| 345 | for i, item in enumerate(manifest_lists): |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 346 | if not os.path.isfile(item): |
Jimmy Brisson | 89d4f8d | 2021-06-23 10:17:36 -0500 | [diff] [blame] | 347 | logging.error('Manifest list item [{}] must be a file'.format(i)) |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 348 | exit(1) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 349 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 350 | # The manifest list file generated by configure_file() |
| 351 | with open(item) as manifest_list_yaml_file: |
| 352 | manifest_dic = yaml.safe_load(manifest_list_yaml_file)['manifest_list'] |
| 353 | for dict in manifest_dic: |
Raef Coles | 052e871 | 2023-11-02 15:29:40 +0000 | [diff] [blame] | 354 | # Replace environment variables in the manifest path. |
| 355 | expanded_path = os.path.expandvars(dict['manifest']).replace('\\', '/') |
| 356 | |
| 357 | # If the manifest exists relative to the manifest list, then use |
| 358 | # that. Else, either interpret it as an absolute path or one |
| 359 | # relative to the current working directory |
| 360 | path_relative_to_manifest_list = os.path.join(os.path.dirname(item), # path of manifest list |
| 361 | expanded_path) |
| 362 | if os.path.isfile(path_relative_to_manifest_list): |
| 363 | manifest_path = path_relative_to_manifest_list |
| 364 | else: |
| 365 | manifest_path = expanded_path |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 366 | dict['manifest'] = manifest_path |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 367 | all_manifests.append(dict) |
| 368 | |
Anton Komlev | 5292071 | 2024-05-16 13:45:46 +0100 | [diff] [blame] | 369 | logging.info("----------- Secure Partitions ------------------------") |
Chris Brand | 4b69fcf | 2022-06-06 09:37:49 -0700 | [diff] [blame] | 370 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 371 | # Parse the manifests |
| 372 | for i, manifest_item in enumerate(all_manifests): |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 373 | valid_enabled_conditions = ['1', 'on', 'true', 'enabled'] |
| 374 | valid_disabled_conditions = ['0', 'off', 'false', 'disabled', ''] |
Kevin Peng | 68d9a3a | 2021-10-18 11:39:54 +0800 | [diff] [blame] | 375 | is_enabled = '' |
| 376 | |
| 377 | if 'conditional' in manifest_item.keys(): |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 378 | if manifest_item['conditional'] not in configs.keys(): |
| 379 | logging.error('Configuration "{}" is not defined!'.format(manifest_item['conditional'])) |
| 380 | exit(1) |
| 381 | is_enabled = configs[manifest_item['conditional']].lower() |
Kevin Peng | 68d9a3a | 2021-10-18 11:39:54 +0800 | [diff] [blame] | 382 | else: |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 383 | # Partitions without 'conditional' is always on |
| 384 | is_enabled = '1' |
Kevin Peng | 68d9a3a | 2021-10-18 11:39:54 +0800 | [diff] [blame] | 385 | |
| 386 | if is_enabled in valid_disabled_conditions: |
BohdanHunko | 6cea95d | 2022-08-16 15:33:51 +0300 | [diff] [blame] | 387 | logging.info(" {:40s} OFF".format(manifest_item['description'])) |
Kevin Peng | 68d9a3a | 2021-10-18 11:39:54 +0800 | [diff] [blame] | 388 | continue |
Chris Brand | 4b69fcf | 2022-06-06 09:37:49 -0700 | [diff] [blame] | 389 | elif is_enabled in valid_enabled_conditions: |
BohdanHunko | 6cea95d | 2022-08-16 15:33:51 +0300 | [diff] [blame] | 390 | logging.info(" {:40s} ON".format(manifest_item['description'])) |
Chris Brand | 4b69fcf | 2022-06-06 09:37:49 -0700 | [diff] [blame] | 391 | else: |
Kevin Peng | 68d9a3a | 2021-10-18 11:39:54 +0800 | [diff] [blame] | 392 | raise Exception('Invalid "conditional" attribute: "{}" for {}. ' |
| 393 | 'Please set to one of {} or {}, case-insensitive.'\ |
| 394 | .format(manifest_item['conditional'], |
BohdanHunko | 6cea95d | 2022-08-16 15:33:51 +0300 | [diff] [blame] | 395 | manifest_item['description'], |
Kevin Peng | 68d9a3a | 2021-10-18 11:39:54 +0800 | [diff] [blame] | 396 | valid_enabled_conditions, valid_disabled_conditions)) |
| 397 | |
Xinyu Zhang | c46ee1f | 2021-04-01 10:10:43 +0800 | [diff] [blame] | 398 | # Check if partition ID is manually set |
| 399 | if 'pid' not in manifest_item.keys(): |
| 400 | no_pid_manifest_idx.append(i) |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 401 | pid = None |
Kevin Peng | 56b0ea6 | 2021-10-18 11:32:57 +0800 | [diff] [blame] | 402 | else: |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 403 | pid = manifest_item['pid'] |
| 404 | |
| 405 | # Check if partition ID is duplicated |
| 406 | if pid in pid_list: |
Antonio de Angelis | baa2764 | 2022-05-25 11:07:12 +0100 | [diff] [blame] | 407 | raise Exception('PID No. {} has already been used!'.format(pid)) |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 408 | else: |
| 409 | pid_list.append(pid) |
Xinyu Zhang | 19504a5 | 2021-03-31 16:26:20 +0800 | [diff] [blame] | 410 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 411 | manifest_path = manifest_item['manifest'] |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 412 | with open(manifest_path) as manifest_file: |
Kevin Peng | ec0e5ce | 2022-02-17 13:48:51 +0800 | [diff] [blame] | 413 | manifest = yaml.safe_load(manifest_file) |
chesun01 | 22abf0a | 2023-10-17 13:42:16 +0800 | [diff] [blame] | 414 | # Check manifest attribute validity |
chesun01 | 2345aa5 | 2023-04-18 17:31:53 +0800 | [diff] [blame] | 415 | manifest_attribute_check(manifest, manifest_item) |
| 416 | |
Kevin Peng | ec0e5ce | 2022-02-17 13:48:51 +0800 | [diff] [blame] | 417 | if manifest.get('model', None) == 'dual': |
| 418 | # If a Partition supports both models, it can set the "model" to "backend". |
| 419 | # The actual model used follows the backend being used. |
| 420 | manifest['model'] = backend |
| 421 | manifest = manifest_validation(manifest, pid) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 422 | |
chesun01 | 22abf0a | 2023-10-17 13:42:16 +0800 | [diff] [blame] | 423 | # Priority mapping |
| 424 | numbered_priority = priority_map[manifest['priority']] |
| 425 | |
Jamie Fox | b15418a | 2024-01-18 11:10:20 +0000 | [diff] [blame] | 426 | if (pid == None or pid >= TFM_PID_BASE) and not manifest['ns_agent']: |
| 427 | # Count the number of IPC/SFN partitions (excluding TF-M internal |
| 428 | # and agent partitions) |
Kevin Peng | 47c26ec | 2022-03-11 11:49:52 +0800 | [diff] [blame] | 429 | if manifest['model'] == 'IPC': |
| 430 | partition_statistics['ipc_partitions'].append(manifest['name']) |
Mingyang Sun | eab7eae | 2021-09-30 13:06:52 +0800 | [diff] [blame] | 431 | |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 432 | # Set initial value to -1 to make (srv_idx + 1) reflect the correct |
| 433 | # number (0) when there are no services. |
| 434 | srv_idx = -1 |
| 435 | for srv_idx, service in enumerate(manifest.get('services', [])): |
Xinyu Zhang | 7d0a5c8 | 2022-05-16 18:15:11 +0800 | [diff] [blame] | 436 | service_partition_map[service['name']] = manifest['name'] |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 437 | if manifest['model'] == 'IPC': |
| 438 | # Assign signal value, the first 4 bits are reserved by FF-M |
| 439 | service['signal_value'] = (1 << (srv_idx + 4)) |
| 440 | else: |
| 441 | # Signals of SFN Partitions are SPM internal only, does not |
| 442 | # need to reserve 4 bits. |
| 443 | service['signal_value'] = (1 << srv_idx) |
| 444 | if service['connection_based']: |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame] | 445 | partition_statistics['connection_based_srv_num'] += 1 |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 446 | logging.debug('{} has {} services'.format(manifest['name'], srv_idx +1)) |
Xinyu Zhang | 2bc4d57 | 2021-12-27 16:37:46 +0800 | [diff] [blame] | 447 | |
Sherry Zhang | 2ed48fd | 2022-09-06 11:33:22 +0800 | [diff] [blame] | 448 | # Calculate the number of mmio region |
| 449 | mmio_region_list = manifest.get('mmio_regions', []) |
| 450 | partition_statistics['mmio_region_num'] += len(mmio_region_list) |
| 451 | |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 452 | # Set initial value to -1 to make (irq + 1) reflect the correct |
| 453 | # number (0) when there are no irqs. |
| 454 | irq_idx = -1 |
| 455 | for irq_idx, irq in enumerate(manifest.get('irqs', [])): |
| 456 | # Assign signal value, from the most significant bit |
| 457 | irq['signal_value'] = (1 << (31 - irq_idx)) |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 458 | if irq.get('handling', None) == 'FLIH': |
| 459 | partition_statistics['flih_num'] += 1 |
| 460 | else: |
| 461 | partition_statistics['slih_num'] += 1 |
Kevin Peng | 5c3fee7 | 2022-02-16 22:25:22 +0800 | [diff] [blame] | 462 | logging.debug('{} has {} IRQS'.format(manifest['name'], irq_idx +1)) |
| 463 | |
| 464 | if ((srv_idx + 1) + (irq_idx + 1)) > 28: |
| 465 | raise Exception('Total number of Services and IRQs of {} exceeds the limit (28)' |
| 466 | .format(manifest['name'])) |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 467 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 468 | manifest_out_basename = os.path.splitext(os.path.basename(manifest_path))[0] |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 469 | |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 470 | if 'output_path' in manifest_item: |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 471 | output_path = os.path.expandvars(manifest_item['output_path']) |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 472 | else: |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 473 | output_path = '' |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 474 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 475 | manifest_head_file = os.path.join(OUT_DIR, output_path, 'psa_manifest', |
| 476 | '{}.h'.format(manifest_out_basename))\ |
| 477 | .replace('\\', '/') |
| 478 | intermedia_file = os.path.join(OUT_DIR, output_path, 'auto_generated', |
| 479 | 'intermedia_{}.c'.format(manifest_out_basename))\ |
| 480 | .replace('\\', '/') |
| 481 | load_info_file = os.path.join(OUT_DIR, output_path, 'auto_generated', |
| 482 | 'load_info_{}.c'.format(manifest_out_basename))\ |
| 483 | .replace('\\', '/') |
Jianliang Shen | 785ed5e | 2022-02-08 14:16:06 +0800 | [diff] [blame] | 484 | output_dir = os.path.join(OUT_DIR, output_path).replace('\\', '/') |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 485 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 486 | partition_list.append({'manifest': manifest, 'attr': manifest_item, |
| 487 | 'manifest_out_basename': manifest_out_basename, |
| 488 | 'header_file': manifest_head_file, |
| 489 | 'intermedia_file': intermedia_file, |
Jianliang Shen | 785ed5e | 2022-02-08 14:16:06 +0800 | [diff] [blame] | 490 | 'loadinfo_file': load_info_file, |
chesun01 | 22abf0a | 2023-10-17 13:42:16 +0800 | [diff] [blame] | 491 | 'output_dir': output_dir, |
| 492 | 'numbered_priority': numbered_priority}) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 493 | |
Anton Komlev | 5292071 | 2024-05-16 13:45:46 +0100 | [diff] [blame] | 494 | logging.info("------------------------------------------------------") |
Chris Brand | 4b69fcf | 2022-06-06 09:37:49 -0700 | [diff] [blame] | 495 | |
Xinyu Zhang | 7d0a5c8 | 2022-05-16 18:15:11 +0800 | [diff] [blame] | 496 | check_circular_dependency(partition_list, service_partition_map) |
| 497 | |
Kevin Peng | 56b0ea6 | 2021-10-18 11:32:57 +0800 | [diff] [blame] | 498 | # Automatically assign PIDs for partitions without 'pid' attribute |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 499 | pid = max(pid_list, default = TFM_PID_BASE - 1) |
Kevin Peng | 56b0ea6 | 2021-10-18 11:32:57 +0800 | [diff] [blame] | 500 | for idx in no_pid_manifest_idx: |
Kevin Peng | c424eec | 2021-06-25 17:26:11 +0800 | [diff] [blame] | 501 | pid += 1 |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 502 | all_manifests[idx]['pid'] = pid |
Kevin Peng | 56b0ea6 | 2021-10-18 11:32:57 +0800 | [diff] [blame] | 503 | pid_list.append(pid) |
| 504 | |
Kevin Peng | 9f1a754 | 2022-02-07 16:32:27 +0800 | [diff] [blame] | 505 | # Set up configurations |
Kevin Peng | 76c0c16 | 2022-02-09 22:49:06 +0800 | [diff] [blame] | 506 | if backend == 'SFN': |
Kevin Peng | 47c26ec | 2022-03-11 11:49:52 +0800 | [diff] [blame] | 507 | if len(partition_statistics['ipc_partitions']) > 0: |
| 508 | logging.error('SFN backend does not support IPC Partitions:') |
| 509 | logging.error(partition_statistics['ipc_partitions']) |
Kevin Peng | 9f1a754 | 2022-02-07 16:32:27 +0800 | [diff] [blame] | 510 | exit(1) |
Kevin Peng | 76c0c16 | 2022-02-09 22:49:06 +0800 | [diff] [blame] | 511 | |
| 512 | if isolation_level > 1: |
| 513 | logging.error('SFN backend does not support high isolation levels.') |
| 514 | exit(1) |
| 515 | |
Kevin Peng | 9f1a754 | 2022-02-07 16:32:27 +0800 | [diff] [blame] | 516 | config_impl['CONFIG_TFM_SPM_BACKEND_SFN'] = '1' |
Kevin Peng | 76c0c16 | 2022-02-09 22:49:06 +0800 | [diff] [blame] | 517 | elif backend == 'IPC': |
Kevin Peng | 9f1a754 | 2022-02-07 16:32:27 +0800 | [diff] [blame] | 518 | config_impl['CONFIG_TFM_SPM_BACKEND_IPC'] = '1' |
Kevin Peng | 9f1a754 | 2022-02-07 16:32:27 +0800 | [diff] [blame] | 519 | |
| 520 | if partition_statistics['connection_based_srv_num'] > 0: |
| 521 | config_impl['CONFIG_TFM_CONNECTION_BASED_SERVICE_API'] = 1 |
| 522 | |
Sherry Zhang | 2ed48fd | 2022-09-06 11:33:22 +0800 | [diff] [blame] | 523 | if partition_statistics['mmio_region_num'] > 0: |
| 524 | config_impl['CONFIG_TFM_MMIO_REGION_ENABLE'] = 1 |
| 525 | |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 526 | if partition_statistics['flih_num'] > 0: |
| 527 | config_impl['CONFIG_TFM_FLIH_API'] = 1 |
Joakim Andersson | eec5cd3 | 2022-06-10 12:02:07 +0200 | [diff] [blame] | 528 | if partition_statistics['slih_num'] > 0: |
Mingyang Sun | ed5fe7b | 2022-02-10 17:33:21 +0800 | [diff] [blame] | 529 | config_impl['CONFIG_TFM_SLIH_API'] = 1 |
| 530 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 531 | context['partitions'] = partition_list |
Kevin Peng | 9f1a754 | 2022-02-07 16:32:27 +0800 | [diff] [blame] | 532 | context['config_impl'] = config_impl |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 533 | context['stateless_services'] = process_stateless_services(partition_list) |
Ruiqi Jiang | 71d361c | 2021-06-23 17:45:55 +0100 | [diff] [blame] | 534 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 535 | return context |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 536 | |
| 537 | def gen_per_partition_files(context): |
| 538 | """ |
| 539 | Generate per-partition files |
| 540 | |
| 541 | Parameters |
| 542 | ---------- |
| 543 | context: |
| 544 | context contains partition infos |
| 545 | """ |
| 546 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 547 | partition_context = {} |
Sherry Zhang | f58f2bd | 2022-01-10 17:21:11 +0800 | [diff] [blame] | 548 | partition_context['utilities'] = context['utilities'] |
Sherry Zhang | f865c4e | 2022-03-23 13:53:38 +0800 | [diff] [blame] | 549 | partition_context['config_impl'] = context['config_impl'] |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 550 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 551 | manifesttemplate = ENV.get_template(os.path.join(sys.path[0], 'templates/manifestfilename.template')) |
| 552 | memorytemplate = ENV.get_template(os.path.join(sys.path[0], 'templates/partition_intermedia.template')) |
| 553 | infotemplate = ENV.get_template(os.path.join(sys.path[0], 'templates/partition_load_info.template')) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 554 | |
Jimmy Brisson | 89d4f8d | 2021-06-23 10:17:36 -0500 | [diff] [blame] | 555 | logging.info ("Start to generate partition files:") |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 556 | |
| 557 | for one_partition in context['partitions']: |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 558 | partition_context['manifest'] = one_partition['manifest'] |
| 559 | partition_context['attr'] = one_partition['attr'] |
| 560 | partition_context['manifest_out_basename'] = one_partition['manifest_out_basename'] |
chesun01 | 22abf0a | 2023-10-17 13:42:16 +0800 | [diff] [blame] | 561 | partition_context['numbered_priority'] = one_partition['numbered_priority'] |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 562 | |
BohdanHunko | 6cea95d | 2022-08-16 15:33:51 +0300 | [diff] [blame] | 563 | logging.info ('Generating {} in {}'.format(one_partition['attr']['description'], |
Jianliang Shen | 785ed5e | 2022-02-08 14:16:06 +0800 | [diff] [blame] | 564 | one_partition['output_dir'])) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 565 | outfile_path = os.path.dirname(one_partition['header_file']) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 566 | if not os.path.exists(outfile_path): |
| 567 | os.makedirs(outfile_path) |
| 568 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 569 | headerfile = io.open(one_partition['header_file'], 'w', newline=None) |
| 570 | headerfile.write(manifesttemplate.render(partition_context)) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 571 | headerfile.close() |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 572 | |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 573 | intermediafile_path = os.path.dirname(one_partition['intermedia_file']) |
Mingyang Sun | d20999f | 2020-10-15 14:53:12 +0800 | [diff] [blame] | 574 | if not os.path.exists(intermediafile_path): |
| 575 | os.makedirs(intermediafile_path) |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 576 | intermediafile = io.open(one_partition['intermedia_file'], 'w', newline=None) |
| 577 | intermediafile.write(memorytemplate.render(partition_context)) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 578 | intermediafile.close() |
Mingyang Sun | d20999f | 2020-10-15 14:53:12 +0800 | [diff] [blame] | 579 | |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 580 | infofile_path = os.path.dirname(one_partition['loadinfo_file']) |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 581 | if not os.path.exists(infofile_path): |
| 582 | os.makedirs(infofile_path) |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 583 | infooutfile = io.open(one_partition['loadinfo_file'], 'w', newline=None) |
| 584 | infooutfile.write(infotemplate.render(partition_context)) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 585 | infooutfile.close() |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 586 | |
Jimmy Brisson | 89d4f8d | 2021-06-23 10:17:36 -0500 | [diff] [blame] | 587 | logging.info ("Per-partition files done:") |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 588 | |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 589 | def gen_summary_files(context, gen_file_lists): |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 590 | """ |
| 591 | Generate files according to the gen_file_list |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 592 | |
| 593 | Parameters |
| 594 | ---------- |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 595 | gen_file_lists: |
| 596 | The lists of files to generate |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 597 | """ |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 598 | file_list = [] |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 599 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 600 | for f in gen_file_lists: |
| 601 | with open(f) as file_list_yaml_file: |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 602 | file_list_yaml = yaml.safe_load(file_list_yaml_file) |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 603 | file_list.extend(file_list_yaml['file_list']) |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 604 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 605 | for file in file_list: |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 606 | # Replace environment variables in the output filepath |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 607 | manifest_out_file = os.path.expandvars(file['output']) |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 608 | # Replace environment variables in the template filepath |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 609 | templatefile_name = os.path.expandvars(file['template']) |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 610 | |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 611 | manifest_out_file = os.path.join(OUT_DIR, manifest_out_file) |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 612 | |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 613 | outfile_path = os.path.dirname(manifest_out_file) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 614 | if not os.path.exists(outfile_path): |
| 615 | os.makedirs(outfile_path) |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 616 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 617 | template = ENV.get_template(templatefile_name) |
Edison Ai | 6e3f2a3 | 2019-06-11 15:29:05 +0800 | [diff] [blame] | 618 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 619 | outfile = io.open(manifest_out_file, 'w', newline=None) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 620 | outfile.write(template.render(context)) |
| 621 | outfile.close() |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 622 | |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 623 | def process_stateless_services(partitions): |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 624 | """ |
| 625 | This function collects all stateless services together, and allocates |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 626 | stateless handles for them. |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 627 | Valid stateless handle in service will be converted to an index. If the |
| 628 | stateless handle is set as "auto", or not set, framework will allocate a |
| 629 | valid index for the service. |
| 630 | Framework puts each service into a reordered stateless service list at |
| 631 | position of "index". Other unused positions are left None. |
Ken Liu | 5094838 | 2022-10-27 12:45:53 +0800 | [diff] [blame] | 632 | |
| 633 | Keep the variable names start with upper case 'STATIC_HANDLE_' the same |
| 634 | as the preprocessors in C sources. This could easier the upcomping |
| 635 | modification when developer searches these definitions for modification. |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 636 | """ |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 637 | |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 638 | collected_stateless_services = [] |
Ken Liu | 5094838 | 2022-10-27 12:45:53 +0800 | [diff] [blame] | 639 | STATIC_HANDLE_NUM_LIMIT = 32 |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 640 | |
| 641 | # Collect all stateless services first. |
| 642 | for partition in partitions: |
| 643 | # Skip the FF-M 1.0 partitions |
| 644 | if partition['manifest']['psa_framework_version'] < 1.1: |
| 645 | continue |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 646 | |
| 647 | service_list = partition['manifest'].get('services', []) |
| 648 | |
| 649 | for service in service_list: |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 650 | if service['connection_based'] is False: |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 651 | collected_stateless_services.append(service) |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 652 | |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 653 | if len(collected_stateless_services) == 0: |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 654 | return [] |
| 655 | |
Ken Liu | 5094838 | 2022-10-27 12:45:53 +0800 | [diff] [blame] | 656 | if len(collected_stateless_services) > STATIC_HANDLE_NUM_LIMIT: |
| 657 | raise Exception('Stateless service numbers range exceed {number}.'.format(number=STATIC_HANDLE_NUM_LIMIT)) |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 658 | |
| 659 | """ |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 660 | Allocate an empty stateless service list to store services. |
| 661 | Use "handle - 1" as the index for service, since handle value starts from |
| 662 | 1 and list index starts from 0. |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 663 | """ |
Ken Liu | 5094838 | 2022-10-27 12:45:53 +0800 | [diff] [blame] | 664 | reordered_stateless_services = [None] * STATIC_HANDLE_NUM_LIMIT |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 665 | auto_alloc_services = [] |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 666 | |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 667 | for service in collected_stateless_services: |
| 668 | # If not set, it is "auto" by default |
| 669 | if 'stateless_handle' not in service: |
| 670 | auto_alloc_services.append(service) |
| 671 | continue |
| 672 | |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 673 | service_handle = service['stateless_handle'] |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 674 | |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 675 | # Fill in service list with specified stateless handle, otherwise skip |
| 676 | if isinstance(service_handle, int): |
Ken Liu | 5094838 | 2022-10-27 12:45:53 +0800 | [diff] [blame] | 677 | if service_handle < 1 or service_handle > STATIC_HANDLE_NUM_LIMIT: |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 678 | raise Exception('Invalid stateless_handle setting: {handle}.'.format(handle=service['stateless_handle'])) |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 679 | # Convert handle index to reordered service list index |
| 680 | service_handle = service_handle - 1 |
| 681 | |
| 682 | if reordered_stateless_services[service_handle] is not None: |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 683 | raise Exception('Duplicated stateless_handle setting: {handle}.'.format(handle=service['stateless_handle'])) |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 684 | reordered_stateless_services[service_handle] = service |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 685 | elif service_handle == 'auto': |
| 686 | auto_alloc_services.append(service) |
| 687 | else: |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 688 | raise Exception('Invalid stateless_handle setting: {handle}.'.format(handle=service['stateless_handle'])) |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 689 | |
Xinyu Zhang | b2d4ed4 | 2023-02-14 11:43:16 +0800 | [diff] [blame] | 690 | STATIC_HANDLE_IDX_BIT_WIDTH = 5 |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 691 | STATIC_HANDLE_IDX_MASK = (1 << STATIC_HANDLE_IDX_BIT_WIDTH) - 1 |
Ken Liu | 5094838 | 2022-10-27 12:45:53 +0800 | [diff] [blame] | 692 | STATIC_HANDLE_INDICATOR_OFFSET = 30 |
| 693 | STATIC_HANDLE_VER_OFFSET = 8 |
| 694 | STATIC_HANDLE_VER_BIT_WIDTH = 8 |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 695 | STATIC_HANDLE_VER_MASK = (1 << STATIC_HANDLE_VER_BIT_WIDTH) - 1 |
| 696 | |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 697 | # Auto-allocate stateless handle and encode the stateless handle |
Ken Liu | 5094838 | 2022-10-27 12:45:53 +0800 | [diff] [blame] | 698 | for i in range(0, STATIC_HANDLE_NUM_LIMIT): |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 699 | service = reordered_stateless_services[i] |
| 700 | |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 701 | if service == None and len(auto_alloc_services) > 0: |
| 702 | service = auto_alloc_services.pop(0) |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 703 | |
Mingyang Sun | 453ad40 | 2021-03-17 17:58:33 +0800 | [diff] [blame] | 704 | """ |
| 705 | Encode stateless flag and version into stateless handle |
Mingyang Sun | 453ad40 | 2021-03-17 17:58:33 +0800 | [diff] [blame] | 706 | """ |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 707 | stateless_handle_value = 0 |
| 708 | if service != None: |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 709 | stateless_index = (i & STATIC_HANDLE_IDX_MASK) |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 710 | stateless_handle_value |= stateless_index |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 711 | stateless_handle_value |= (1 << STATIC_HANDLE_INDICATOR_OFFSET) |
| 712 | stateless_version = (service['version'] & STATIC_HANDLE_VER_MASK) << STATIC_HANDLE_VER_OFFSET |
Mingyang Sun | 453ad40 | 2021-03-17 17:58:33 +0800 | [diff] [blame] | 713 | stateless_handle_value |= stateless_version |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 714 | service['stateless_handle_value'] = '0x{0:08x}'.format(stateless_handle_value) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 715 | service['stateless_handle_index'] = stateless_index |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 716 | |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 717 | reordered_stateless_services[i] = service |
| 718 | |
| 719 | return reordered_stateless_services |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 720 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 721 | def parse_args(): |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 722 | parser = argparse.ArgumentParser(description='Parse secure partition manifest list and generate files listed by the file list', |
Juha Ylinen | bc26127 | 2024-06-19 13:00:00 +0300 | [diff] [blame] | 723 | epilog='Note that environment variables in template files will be replaced with their values', |
| 724 | allow_abbrev=False) |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 725 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 726 | parser.add_argument('-o', '--outdir' |
| 727 | , dest='outdir' |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 728 | , required=True |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 729 | , metavar='out_dir' |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 730 | , help='The root directory for generated files') |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 731 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 732 | parser.add_argument('-m', '--manifest-lists' |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 733 | , nargs='+' |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 734 | , dest='manifest_lists' |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 735 | , required=True |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 736 | , metavar='manifest list' |
| 737 | , help='A list of Secure Partition manifest lists and their original paths.\n\ |
| 738 | The manifest lists might be processed by CMake and\n\ |
| 739 | the path might be different to the original one\n\ |
| 740 | The format must be [list A, orignal path A, list B, orignal path B, ...]') |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 741 | |
| 742 | parser.add_argument('-f', '--file-list' |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 743 | , nargs='+' |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 744 | , dest='gen_file_args' |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 745 | , required=True |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 746 | , metavar='file-list' |
Chris Brand | f1d6b6f | 2022-07-22 11:49:01 -0700 | [diff] [blame] | 747 | , help='These files describe the file list to generate') |
Kevin Peng | 9f1a754 | 2022-02-07 16:32:27 +0800 | [diff] [blame] | 748 | |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 749 | parser.add_argument('-c', '--config-files' |
| 750 | , nargs='+' |
| 751 | , dest='config_files' |
Kevin Peng | 9f1a754 | 2022-02-07 16:32:27 +0800 | [diff] [blame] | 752 | , required=True |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 753 | , metavar='config-files' |
| 754 | , help='A header file contains build configurations') |
Kevin Peng | 9f1a754 | 2022-02-07 16:32:27 +0800 | [diff] [blame] | 755 | |
Jimmy Brisson | 89d4f8d | 2021-06-23 10:17:36 -0500 | [diff] [blame] | 756 | parser.add_argument('-q', '--quiet' |
| 757 | , dest='quiet' |
| 758 | , required=False |
| 759 | , default=False |
| 760 | , action='store_true' |
| 761 | , help='Reduce log messages') |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 762 | |
| 763 | args = parser.parse_args() |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 764 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 765 | return args |
| 766 | |
| 767 | ENV = Environment( |
| 768 | loader = TemplateLoader(), |
| 769 | autoescape = select_autoescape(['html', 'xml']), |
| 770 | lstrip_blocks = True, |
| 771 | trim_blocks = True, |
| 772 | keep_trailing_newline = True |
| 773 | ) |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 774 | |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 775 | def main(): |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 776 | """ |
| 777 | The entry point of the script. |
| 778 | |
| 779 | Generates the output files based on the templates and the manifests. |
| 780 | """ |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 781 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 782 | global OUT_DIR |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 783 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 784 | args = parse_args() |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 785 | |
Jimmy Brisson | 89d4f8d | 2021-06-23 10:17:36 -0500 | [diff] [blame] | 786 | logging.basicConfig(format='%(message)s' |
| 787 | , level=logging.WARNING if args.quiet else logging.INFO) |
| 788 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 789 | OUT_DIR = os.path.abspath(args.outdir) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 790 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 791 | manifest_lists = [os.path.abspath(x) for x in args.manifest_lists] |
| 792 | gen_file_lists = [os.path.abspath(x) for x in args.gen_file_args] |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 793 | |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 794 | """ |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 795 | Relative path to TF-M root folder is supported in the manifests |
| 796 | and default value of manifest list and generated file list are relative to TF-M root folder as well, |
| 797 | so first change directory to TF-M root folder. |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 798 | By doing this, the script can be executed anywhere |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 799 | The script is located in <TF-M root folder>/tools, so sys.path[0]<location of the script>/.. is TF-M root folder. |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 800 | """ |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 801 | os.chdir(os.path.join(sys.path[0], '..')) |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 802 | |
Kevin Peng | 76c0c16 | 2022-02-09 22:49:06 +0800 | [diff] [blame] | 803 | context = process_partition_manifests(manifest_lists, |
Kevin Peng | fb1761b | 2022-05-12 12:11:31 +0800 | [diff] [blame] | 804 | parse_configurations(args.config_files)) |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 805 | |
Edison Ai | 6e3f2a3 | 2019-06-11 15:29:05 +0800 | [diff] [blame] | 806 | utilities = {} |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 807 | utilities['donotedit_warning'] = donotedit_warning |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 808 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 809 | context['utilities'] = utilities |
Mingyang Sun | eab7eae | 2021-09-30 13:06:52 +0800 | [diff] [blame] | 810 | |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 811 | gen_per_partition_files(context) |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 812 | gen_summary_files(context, gen_file_lists) |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 813 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 814 | if __name__ == '__main__': |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 815 | main() |