Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Xinyu Zhang | 90f08dc | 2022-01-12 15:55:17 +0800 | [diff] [blame^] | 2 | # Copyright (c) 2018-2022, Arm Limited. All rights reserved. |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | import os |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 9 | import io |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 10 | import re |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 11 | import sys |
| 12 | import argparse |
Ken Liu | 1f345b0 | 2020-05-30 21:11:05 +0800 | [diff] [blame] | 13 | from jinja2 import Environment, BaseLoader, select_autoescape, TemplateNotFound |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 14 | |
| 15 | try: |
| 16 | import yaml |
| 17 | except ImportError as e: |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 18 | print (str(e) + ' To install it, type:') |
| 19 | print ('pip install PyYAML') |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 20 | exit(1) |
| 21 | |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 22 | donotedit_warning = \ |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 23 | '/*********** ' + \ |
| 24 | 'WARNING: This is an auto-generated file. Do not edit!' + \ |
| 25 | ' ***********/' |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 26 | |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 27 | TFM_ROOT_DIR = os.path.join(sys.path[0], '..') |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 28 | OUT_DIR = None # The root directory that files are generated to |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 29 | |
Sherry Zhang | 87e6d2e | 2021-12-27 14:48:59 +0800 | [diff] [blame] | 30 | # 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] | 31 | TFM_PID_BASE = 256 |
| 32 | |
Ruiqi Jiang | 71d361c | 2021-06-23 17:45:55 +0100 | [diff] [blame] | 33 | # variable for checking for duplicated sid |
| 34 | sid_list = [] |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 35 | class TemplateLoader(BaseLoader): |
| 36 | """ |
| 37 | Template loader class. |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 38 | |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 39 | An instance of this class is passed to the template engine. It is |
| 40 | responsible for reading the template file |
| 41 | """ |
| 42 | def __init__(self): |
| 43 | pass |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 44 | |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 45 | def get_source(self, environment, template): |
| 46 | """ |
| 47 | This function reads the template files. |
| 48 | For detailed documentation see: |
| 49 | http://jinja.pocoo.org/docs/2.10/api/#jinja2.BaseLoader.get_source |
| 50 | |
| 51 | Please note that this function always return 'false' as 'uptodate' |
| 52 | value, so the output file will always be generated. |
| 53 | """ |
| 54 | if not os.path.isfile(template): |
| 55 | raise TemplateNotFound(template) |
| 56 | with open(template) as f: |
| 57 | source = f.read() |
| 58 | return source, template, False |
| 59 | |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 60 | def get_single_macro_def_from_file(file_name, macro_name): |
| 61 | """ |
| 62 | This function parses the given file_name to get the definition of the given |
| 63 | C Macro (macro_name). |
| 64 | |
| 65 | It assumes that the target Macro has no multiple definitions in different |
| 66 | build configurations. |
| 67 | |
| 68 | It supports Macros defined in multi-line, for example: |
| 69 | #define SOME_MACRO \ |
| 70 | the_macro_value |
| 71 | |
| 72 | Inputs: |
| 73 | - file_name: the file to get the Macro from |
| 74 | - macro_name: the name of the Macro to get |
| 75 | Returns: |
| 76 | - The Macro definition with '()' stripped, or Exception if not found |
| 77 | """ |
| 78 | |
| 79 | with open(file_name, 'r') as f: |
| 80 | pattern = re.compile(r'#define\s+{}[\\\s]+.*'.format(macro_name)) |
| 81 | result = pattern.findall(f.read()) |
| 82 | |
| 83 | if len(result) != 1: |
| 84 | raise Exception('{} not defined or has multiple definitions'.format(macro_name)) |
| 85 | |
| 86 | macro_def = result[0].split()[-1].strip('()') |
| 87 | |
| 88 | return macro_def |
| 89 | |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 90 | def manifest_validation(partition_manifest, pid): |
Mingyang Sun | 294ce2e | 2021-06-11 11:58:24 +0800 | [diff] [blame] | 91 | """ |
| 92 | This function validates FF-M compliance for partition manifest, and sets |
| 93 | default values for optional attributes. |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 94 | 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] | 95 | More validation items will be added. |
| 96 | """ |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 97 | |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 98 | service_list = partition_manifest.get('services', []) |
| 99 | irq_list = partition_manifest.get('irqs', []) |
Mingyang Sun | 294ce2e | 2021-06-11 11:58:24 +0800 | [diff] [blame] | 100 | |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 101 | if (pid == None or pid >= TFM_PID_BASE) \ |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 102 | and len(service_list) == 0 and len(irq_list) == 0: |
| 103 | raise Exception('{} must declare at least either a secure service or an IRQ!' |
| 104 | .format(partition_manifest['name'])) |
| 105 | |
| 106 | # Service FF-M manifest validation |
| 107 | for service in service_list: |
Mingyang Sun | 294ce2e | 2021-06-11 11:58:24 +0800 | [diff] [blame] | 108 | if 'version' not in service.keys(): |
| 109 | service['version'] = 1 |
| 110 | if 'version_policy' not in service.keys(): |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 111 | service['version_policy'] = 'STRICT' |
Mingyang Sun | 294ce2e | 2021-06-11 11:58:24 +0800 | [diff] [blame] | 112 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 113 | # SID duplication check |
| 114 | if service['sid'] in sid_list: |
| 115 | raise Exception('Service ID: {} has duplications!'.format(service['sid'])) |
| 116 | else: |
| 117 | sid_list.append(service['sid']) |
Ruiqi Jiang | 71d361c | 2021-06-23 17:45:55 +0100 | [diff] [blame] | 118 | |
Mingyang Sun | 294ce2e | 2021-06-11 11:58:24 +0800 | [diff] [blame] | 119 | return partition_manifest |
| 120 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 121 | def process_partition_manifests(manifest_lists): |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 122 | """ |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 123 | Parse the input manifest lists, generate the data base for genereated files |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 124 | and generate manifest header files. |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 125 | |
| 126 | Parameters |
| 127 | ---------- |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 128 | manifest_lists: |
| 129 | A list of Secure Partition manifest lists and their original paths. |
| 130 | The manifest lists might be processed by CMake and the paths might be |
| 131 | different to the original ones. Original paths are needed to handle |
| 132 | relative paths in the lists. |
| 133 | The format must be [list A, orignal path A, list B, orignal path B, ...] |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 134 | |
| 135 | Returns |
| 136 | ------- |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 137 | The manifest data base. |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 138 | """ |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 139 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 140 | context = {} |
| 141 | |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 142 | partition_list = [] |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 143 | all_manifests = [] |
Kevin Peng | 56b0ea6 | 2021-10-18 11:32:57 +0800 | [diff] [blame] | 144 | pid_list = [] |
| 145 | no_pid_manifest_idx = [] |
Xinyu Zhang | 90f08dc | 2022-01-12 15:55:17 +0800 | [diff] [blame^] | 146 | partition_statistics = { |
| 147 | 'ipc_partition_num': 0, |
| 148 | 'sfn_partition_num': 0 |
| 149 | } |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 150 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 151 | # Get all the manifests information as a dictionary |
| 152 | for i, item in enumerate(manifest_lists): |
| 153 | if i % 2 == 0 and not os.path.isfile(item): |
| 154 | print('Manifest list item [{}] must be a file'.format(i)) |
| 155 | exit(1) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 156 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 157 | if i % 2 == 1: |
| 158 | if not os.path.isdir(item): |
| 159 | print('Manifest list item [{}] must be a directory'.format(i)) |
| 160 | exit(1) |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 161 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 162 | # Skip original manifest paths |
| 163 | continue |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 164 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 165 | # The manifest list file generated by configure_file() |
| 166 | with open(item) as manifest_list_yaml_file: |
| 167 | manifest_dic = yaml.safe_load(manifest_list_yaml_file)['manifest_list'] |
| 168 | for dict in manifest_dic: |
| 169 | # Add original path of manifest list. |
| 170 | # The validation will be done in the next loop. |
| 171 | dict['list_path'] = manifest_lists[i + 1] |
| 172 | all_manifests.append(dict) |
| 173 | |
| 174 | # Parse the manifests |
| 175 | for i, manifest_item in enumerate(all_manifests): |
Kevin Peng | 68d9a3a | 2021-10-18 11:39:54 +0800 | [diff] [blame] | 176 | valid_enabled_conditions = ['on', 'true', 'enabled'] |
Kevin Peng | 50f413c | 2021-11-12 10:31:45 +0800 | [diff] [blame] | 177 | valid_disabled_conditions = ['off', 'false', 'disabled', ''] |
Kevin Peng | 68d9a3a | 2021-10-18 11:39:54 +0800 | [diff] [blame] | 178 | is_enabled = '' |
| 179 | |
| 180 | if 'conditional' in manifest_item.keys(): |
Kevin Peng | 50f413c | 2021-11-12 10:31:45 +0800 | [diff] [blame] | 181 | is_enabled = str(manifest_item['conditional']).lower() |
Kevin Peng | 68d9a3a | 2021-10-18 11:39:54 +0800 | [diff] [blame] | 182 | else: |
| 183 | # Partitions without 'conditional' is alwasy on |
| 184 | is_enabled = 'on' |
| 185 | |
| 186 | if is_enabled in valid_disabled_conditions: |
| 187 | continue |
| 188 | elif is_enabled not in valid_enabled_conditions: |
| 189 | raise Exception('Invalid "conditional" attribute: "{}" for {}. ' |
| 190 | 'Please set to one of {} or {}, case-insensitive.'\ |
| 191 | .format(manifest_item['conditional'], |
| 192 | manifest_item['name'], |
| 193 | valid_enabled_conditions, valid_disabled_conditions)) |
| 194 | |
Xinyu Zhang | c46ee1f | 2021-04-01 10:10:43 +0800 | [diff] [blame] | 195 | # Check if partition ID is manually set |
| 196 | if 'pid' not in manifest_item.keys(): |
| 197 | no_pid_manifest_idx.append(i) |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 198 | pid = None |
Kevin Peng | 56b0ea6 | 2021-10-18 11:32:57 +0800 | [diff] [blame] | 199 | else: |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 200 | pid = manifest_item['pid'] |
| 201 | |
| 202 | # Check if partition ID is duplicated |
| 203 | if pid in pid_list: |
| 204 | raise Exception('PID No. {pid} has already been used!'.format(pid)) |
| 205 | else: |
| 206 | pid_list.append(pid) |
Xinyu Zhang | 19504a5 | 2021-03-31 16:26:20 +0800 | [diff] [blame] | 207 | |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 208 | # Replace environment variables in the manifest path |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 209 | manifest_path = os.path.expandvars(manifest_item['manifest']) |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 210 | # Convert to absolute path. If it's already abspath, the path will not be changed. |
| 211 | manifest_path = os.path.join(manifest_item['list_path'], manifest_path).replace('\\', '/') |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 212 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 213 | with open(manifest_path) as manifest_file: |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 214 | manifest = manifest_validation(yaml.safe_load(manifest_file), pid) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 215 | |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 216 | if pid == None or pid >= TFM_PID_BASE: |
Kevin Peng | d08f3ba | 2021-11-18 15:18:56 +0800 | [diff] [blame] | 217 | # Count the number of IPC/SFN partitions |
| 218 | if manifest['psa_framework_version'] == 1.1 and manifest['model'] == 'SFN': |
Xinyu Zhang | 90f08dc | 2022-01-12 15:55:17 +0800 | [diff] [blame^] | 219 | partition_statistics['sfn_partition_num'] += 1 |
Kevin Peng | d08f3ba | 2021-11-18 15:18:56 +0800 | [diff] [blame] | 220 | else: |
Xinyu Zhang | 90f08dc | 2022-01-12 15:55:17 +0800 | [diff] [blame^] | 221 | partition_statistics['ipc_partition_num'] += 1 |
Mingyang Sun | eab7eae | 2021-09-30 13:06:52 +0800 | [diff] [blame] | 222 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 223 | manifest_out_basename = os.path.splitext(os.path.basename(manifest_path))[0] |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 224 | |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 225 | if 'output_path' in manifest_item: |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 226 | output_path = os.path.expandvars(manifest_item['output_path']) |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 227 | else: |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 228 | output_path = '' |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 229 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 230 | manifest_head_file = os.path.join(OUT_DIR, output_path, 'psa_manifest', |
| 231 | '{}.h'.format(manifest_out_basename))\ |
| 232 | .replace('\\', '/') |
| 233 | intermedia_file = os.path.join(OUT_DIR, output_path, 'auto_generated', |
| 234 | 'intermedia_{}.c'.format(manifest_out_basename))\ |
| 235 | .replace('\\', '/') |
| 236 | load_info_file = os.path.join(OUT_DIR, output_path, 'auto_generated', |
| 237 | 'load_info_{}.c'.format(manifest_out_basename))\ |
| 238 | .replace('\\', '/') |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 239 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 240 | partition_list.append({'manifest': manifest, 'attr': manifest_item, |
| 241 | 'manifest_out_basename': manifest_out_basename, |
| 242 | 'header_file': manifest_head_file, |
| 243 | 'intermedia_file': intermedia_file, |
| 244 | 'loadinfo_file': load_info_file}) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 245 | |
Kevin Peng | 56b0ea6 | 2021-10-18 11:32:57 +0800 | [diff] [blame] | 246 | # Automatically assign PIDs for partitions without 'pid' attribute |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 247 | pid = max(pid_list, default = TFM_PID_BASE - 1) |
Kevin Peng | 56b0ea6 | 2021-10-18 11:32:57 +0800 | [diff] [blame] | 248 | for idx in no_pid_manifest_idx: |
Kevin Peng | c424eec | 2021-06-25 17:26:11 +0800 | [diff] [blame] | 249 | pid += 1 |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 250 | all_manifests[idx]['pid'] = pid |
Kevin Peng | 56b0ea6 | 2021-10-18 11:32:57 +0800 | [diff] [blame] | 251 | pid_list.append(pid) |
| 252 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 253 | context['partitions'] = partition_list |
Xinyu Zhang | 90f08dc | 2022-01-12 15:55:17 +0800 | [diff] [blame^] | 254 | context['partition_statistics'] = partition_statistics |
Ruiqi Jiang | 71d361c | 2021-06-23 17:45:55 +0100 | [diff] [blame] | 255 | |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 256 | context['stateless_services'] = process_stateless_services(partition_list) |
Ruiqi Jiang | 71d361c | 2021-06-23 17:45:55 +0100 | [diff] [blame] | 257 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 258 | return context |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 259 | |
| 260 | def gen_per_partition_files(context): |
| 261 | """ |
| 262 | Generate per-partition files |
| 263 | |
| 264 | Parameters |
| 265 | ---------- |
| 266 | context: |
| 267 | context contains partition infos |
| 268 | """ |
| 269 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 270 | utilities = {} |
| 271 | utilities['donotedit_warning'] = donotedit_warning |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 272 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 273 | partition_context = {} |
| 274 | partition_context['utilities'] = utilities |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 275 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 276 | manifesttemplate = ENV.get_template(os.path.join(sys.path[0], 'templates/manifestfilename.template')) |
| 277 | memorytemplate = ENV.get_template(os.path.join(sys.path[0], 'templates/partition_intermedia.template')) |
| 278 | 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] | 279 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 280 | print ('Start to generate partition files:') |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 281 | |
| 282 | for one_partition in context['partitions']: |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 283 | partition_context['manifest'] = one_partition['manifest'] |
| 284 | partition_context['attr'] = one_partition['attr'] |
| 285 | partition_context['manifest_out_basename'] = one_partition['manifest_out_basename'] |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 286 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 287 | print ('Generating Header: ' + one_partition['header_file']) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 288 | outfile_path = os.path.dirname(one_partition['header_file']) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 289 | if not os.path.exists(outfile_path): |
| 290 | os.makedirs(outfile_path) |
| 291 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 292 | headerfile = io.open(one_partition['header_file'], 'w', newline=None) |
| 293 | headerfile.write(manifesttemplate.render(partition_context)) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 294 | headerfile.close() |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 295 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 296 | print ('Generating Intermedia: ' + one_partition['intermedia_file']) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 297 | intermediafile_path = os.path.dirname(one_partition['intermedia_file']) |
Mingyang Sun | d20999f | 2020-10-15 14:53:12 +0800 | [diff] [blame] | 298 | if not os.path.exists(intermediafile_path): |
| 299 | os.makedirs(intermediafile_path) |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 300 | intermediafile = io.open(one_partition['intermedia_file'], 'w', newline=None) |
| 301 | intermediafile.write(memorytemplate.render(partition_context)) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 302 | intermediafile.close() |
Mingyang Sun | d20999f | 2020-10-15 14:53:12 +0800 | [diff] [blame] | 303 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 304 | print ('Generating Loadinfo: ' + one_partition['loadinfo_file']) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 305 | infofile_path = os.path.dirname(one_partition['loadinfo_file']) |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 306 | if not os.path.exists(infofile_path): |
| 307 | os.makedirs(infofile_path) |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 308 | infooutfile = io.open(one_partition['loadinfo_file'], 'w', newline=None) |
| 309 | infooutfile.write(infotemplate.render(partition_context)) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 310 | infooutfile.close() |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 311 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 312 | print ('Per-partition files done:') |
Mingyang Sun | f6a7857 | 2021-04-02 16:51:05 +0800 | [diff] [blame] | 313 | |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 314 | def gen_summary_files(context, gen_file_lists): |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 315 | """ |
| 316 | Generate files according to the gen_file_list |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 317 | |
| 318 | Parameters |
| 319 | ---------- |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 320 | gen_file_lists: |
| 321 | The lists of files to generate |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 322 | """ |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 323 | file_list = [] |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 324 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 325 | for f in gen_file_lists: |
| 326 | with open(f) as file_list_yaml_file: |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 327 | file_list_yaml = yaml.safe_load(file_list_yaml_file) |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 328 | file_list.extend(file_list_yaml['file_list']) |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 329 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 330 | print('Start to generate file from the generated list:') |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 331 | for file in file_list: |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 332 | # Replace environment variables in the output filepath |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 333 | manifest_out_file = os.path.expandvars(file['output']) |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 334 | # Replace environment variables in the template filepath |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 335 | templatefile_name = os.path.expandvars(file['template']) |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 336 | |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 337 | manifest_out_file = os.path.join(OUT_DIR, manifest_out_file) |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 338 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 339 | print ('Generating ' + manifest_out_file) |
edison.ai | 7b299f5 | 2020-07-16 15:44:18 +0800 | [diff] [blame] | 340 | |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 341 | outfile_path = os.path.dirname(manifest_out_file) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 342 | if not os.path.exists(outfile_path): |
| 343 | os.makedirs(outfile_path) |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 344 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 345 | template = ENV.get_template(templatefile_name) |
Edison Ai | 6e3f2a3 | 2019-06-11 15:29:05 +0800 | [diff] [blame] | 346 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 347 | outfile = io.open(manifest_out_file, 'w', newline=None) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 348 | outfile.write(template.render(context)) |
| 349 | outfile.close() |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 350 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 351 | print ('Generation of files done') |
Edison Ai | 48b2d9e | 2019-06-24 14:39:45 +0800 | [diff] [blame] | 352 | |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 353 | def process_stateless_services(partitions): |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 354 | """ |
| 355 | This function collects all stateless services together, and allocates |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 356 | stateless handles for them. |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 357 | Valid stateless handle in service will be converted to an index. If the |
| 358 | stateless handle is set as "auto", or not set, framework will allocate a |
| 359 | valid index for the service. |
| 360 | Framework puts each service into a reordered stateless service list at |
| 361 | position of "index". Other unused positions are left None. |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 362 | """ |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 363 | |
| 364 | STATIC_HANDLE_CONFIG_FILE = 'secure_fw/spm/cmsis_psa/spm_ipc.h' |
| 365 | |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 366 | collected_stateless_services = [] |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 367 | stateless_index_max_num = \ |
| 368 | int(get_single_macro_def_from_file(STATIC_HANDLE_CONFIG_FILE, 'STATIC_HANDLE_NUM_LIMIT'), base = 10) |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 369 | |
| 370 | # Collect all stateless services first. |
| 371 | for partition in partitions: |
| 372 | # Skip the FF-M 1.0 partitions |
| 373 | if partition['manifest']['psa_framework_version'] < 1.1: |
| 374 | continue |
Kevin Peng | 8849b6a | 2021-11-09 14:17:35 +0800 | [diff] [blame] | 375 | |
| 376 | service_list = partition['manifest'].get('services', []) |
| 377 | |
| 378 | for service in service_list: |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 379 | if 'connection_based' not in service: |
| 380 | raise Exception("'connection_based' is mandatory in FF-M 1.1 service!") |
| 381 | if service['connection_based'] is False: |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 382 | collected_stateless_services.append(service) |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 383 | |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 384 | if len(collected_stateless_services) == 0: |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 385 | return [] |
| 386 | |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 387 | if len(collected_stateless_services) > stateless_index_max_num: |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 388 | raise Exception('Stateless service numbers range exceed {number}.'.format(number=stateless_index_max_num)) |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 389 | |
| 390 | """ |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 391 | Allocate an empty stateless service list to store services. |
| 392 | Use "handle - 1" as the index for service, since handle value starts from |
| 393 | 1 and list index starts from 0. |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 394 | """ |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 395 | reordered_stateless_services = [None] * stateless_index_max_num |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 396 | auto_alloc_services = [] |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 397 | |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 398 | for service in collected_stateless_services: |
| 399 | # If not set, it is "auto" by default |
| 400 | if 'stateless_handle' not in service: |
| 401 | auto_alloc_services.append(service) |
| 402 | continue |
| 403 | |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 404 | service_handle = service['stateless_handle'] |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 405 | |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 406 | # Fill in service list with specified stateless handle, otherwise skip |
| 407 | if isinstance(service_handle, int): |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 408 | if service_handle < 1 or service_handle > stateless_index_max_num: |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 409 | raise Exception('Invalid stateless_handle setting: {handle}.'.format(handle=service['stateless_handle'])) |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 410 | # Convert handle index to reordered service list index |
| 411 | service_handle = service_handle - 1 |
| 412 | |
| 413 | if reordered_stateless_services[service_handle] is not None: |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 414 | raise Exception('Duplicated stateless_handle setting: {handle}.'.format(handle=service['stateless_handle'])) |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 415 | reordered_stateless_services[service_handle] = service |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 416 | elif service_handle == 'auto': |
| 417 | auto_alloc_services.append(service) |
| 418 | else: |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 419 | raise Exception('Invalid stateless_handle setting: {handle}.'.format(handle=service['stateless_handle'])) |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 420 | |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 421 | STATIC_HANDLE_IDX_BIT_WIDTH = \ |
| 422 | int(get_single_macro_def_from_file(STATIC_HANDLE_CONFIG_FILE, 'STATIC_HANDLE_IDX_BIT_WIDTH'), base = 10) |
| 423 | STATIC_HANDLE_IDX_MASK = (1 << STATIC_HANDLE_IDX_BIT_WIDTH) - 1 |
| 424 | |
| 425 | STATIC_HANDLE_INDICATOR_OFFSET = \ |
| 426 | int(get_single_macro_def_from_file(STATIC_HANDLE_CONFIG_FILE, 'STATIC_HANDLE_INDICATOR_OFFSET'), base = 10) |
| 427 | |
| 428 | STATIC_HANDLE_VER_OFFSET = \ |
| 429 | int(get_single_macro_def_from_file(STATIC_HANDLE_CONFIG_FILE, 'STATIC_HANDLE_VER_OFFSET'), base = 10) |
| 430 | |
| 431 | STATIC_HANDLE_VER_BIT_WIDTH = \ |
| 432 | int(get_single_macro_def_from_file(STATIC_HANDLE_CONFIG_FILE, 'STATIC_HANDLE_VER_BIT_WIDTH'), base = 10) |
| 433 | STATIC_HANDLE_VER_MASK = (1 << STATIC_HANDLE_VER_BIT_WIDTH) - 1 |
| 434 | |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 435 | # Auto-allocate stateless handle and encode the stateless handle |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 436 | for i in range(0, stateless_index_max_num): |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 437 | service = reordered_stateless_services[i] |
| 438 | |
Kevin Peng | c05319d | 2021-04-22 22:59:35 +0800 | [diff] [blame] | 439 | if service == None and len(auto_alloc_services) > 0: |
| 440 | service = auto_alloc_services.pop(0) |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 441 | |
Mingyang Sun | 453ad40 | 2021-03-17 17:58:33 +0800 | [diff] [blame] | 442 | """ |
| 443 | Encode stateless flag and version into stateless handle |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 444 | Check STATIC_HANDLE_CONFIG_FILE for details |
Mingyang Sun | 453ad40 | 2021-03-17 17:58:33 +0800 | [diff] [blame] | 445 | """ |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 446 | stateless_handle_value = 0 |
| 447 | if service != None: |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 448 | stateless_index = (i & STATIC_HANDLE_IDX_MASK) |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 449 | stateless_handle_value |= stateless_index |
Kevin Peng | ce99e5d | 2021-11-09 18:06:53 +0800 | [diff] [blame] | 450 | stateless_handle_value |= (1 << STATIC_HANDLE_INDICATOR_OFFSET) |
| 451 | stateless_version = (service['version'] & STATIC_HANDLE_VER_MASK) << STATIC_HANDLE_VER_OFFSET |
Mingyang Sun | 453ad40 | 2021-03-17 17:58:33 +0800 | [diff] [blame] | 452 | stateless_handle_value |= stateless_version |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 453 | service['stateless_handle_value'] = '0x{0:08x}'.format(stateless_handle_value) |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 454 | service['stateless_handle_index'] = stateless_index |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 455 | |
Mingyang Sun | 4ecea99 | 2021-03-30 17:56:26 +0800 | [diff] [blame] | 456 | reordered_stateless_services[i] = service |
| 457 | |
| 458 | return reordered_stateless_services |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 459 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 460 | def parse_args(): |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 461 | parser = argparse.ArgumentParser(description='Parse secure partition manifest list and generate files listed by the file list', |
| 462 | epilog='Note that environment variables in template files will be replaced with their values') |
| 463 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 464 | parser.add_argument('-o', '--outdir' |
| 465 | , dest='outdir' |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 466 | , required=True |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 467 | , metavar='out_dir' |
Kevin Peng | 4fade07 | 2021-10-26 17:57:50 +0800 | [diff] [blame] | 468 | , help='The root directory for generated files') |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 469 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 470 | parser.add_argument('-m', '--manifest-lists' |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 471 | , nargs='+' |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 472 | , dest='manifest_lists' |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 473 | , required=True |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 474 | , metavar='manifest list' |
| 475 | , help='A list of Secure Partition manifest lists and their original paths.\n\ |
| 476 | The manifest lists might be processed by CMake and\n\ |
| 477 | the path might be different to the original one\n\ |
| 478 | 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] | 479 | |
| 480 | parser.add_argument('-f', '--file-list' |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 481 | , nargs='+' |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 482 | , dest='gen_file_args' |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 483 | , required=True |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 484 | , metavar='file-list' |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 485 | , help='These files descripe the file list to generate') |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 486 | |
| 487 | args = parser.parse_args() |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 488 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 489 | if len(args.manifest_lists) % 2 != 0: |
| 490 | print('Invalid structure in manifest lists.\n' |
| 491 | 'Each element shall consist of a manifest list and its original path') |
| 492 | exit(1) |
| 493 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 494 | return args |
| 495 | |
| 496 | ENV = Environment( |
| 497 | loader = TemplateLoader(), |
| 498 | autoescape = select_autoescape(['html', 'xml']), |
| 499 | lstrip_blocks = True, |
| 500 | trim_blocks = True, |
| 501 | keep_trailing_newline = True |
| 502 | ) |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 503 | |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 504 | def main(): |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 505 | """ |
| 506 | The entry point of the script. |
| 507 | |
| 508 | Generates the output files based on the templates and the manifests. |
| 509 | """ |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 510 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 511 | global OUT_DIR |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 512 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 513 | args = parse_args() |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 514 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 515 | OUT_DIR = os.path.abspath(args.outdir) |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 516 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 517 | manifest_lists = [os.path.abspath(x) for x in args.manifest_lists] |
| 518 | 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] | 519 | |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 520 | """ |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 521 | Relative path to TF-M root folder is supported in the manifests |
| 522 | and default value of manifest list and generated file list are relative to TF-M root folder as well, |
| 523 | so first change directory to TF-M root folder. |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 524 | By doing this, the script can be executed anywhere |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 525 | 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] | 526 | """ |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 527 | os.chdir(os.path.join(sys.path[0], '..')) |
Shawn Shan | a9ad1e0 | 2019-08-07 15:49:48 +0800 | [diff] [blame] | 528 | |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 529 | context = process_partition_manifests(manifest_lists) |
Mate Toth-Pal | 36f2184 | 2018-11-08 16:12:51 +0100 | [diff] [blame] | 530 | |
Edison Ai | 6e3f2a3 | 2019-06-11 15:29:05 +0800 | [diff] [blame] | 531 | utilities = {} |
Mingyang Sun | a1ca611 | 2021-01-11 11:34:59 +0800 | [diff] [blame] | 532 | utilities['donotedit_warning'] = donotedit_warning |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 533 | |
Kevin Peng | 655f239 | 2019-11-27 16:33:02 +0800 | [diff] [blame] | 534 | context['utilities'] = utilities |
Mingyang Sun | eab7eae | 2021-09-30 13:06:52 +0800 | [diff] [blame] | 535 | |
Ken Liu | 861b078 | 2021-05-22 13:15:08 +0800 | [diff] [blame] | 536 | gen_per_partition_files(context) |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 537 | gen_summary_files(context, gen_file_lists) |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 538 | |
Kevin Peng | 5bc82d2 | 2021-10-19 11:18:40 +0800 | [diff] [blame] | 539 | if __name__ == '__main__': |
Miklos Balint | 470919c | 2018-05-22 17:51:29 +0200 | [diff] [blame] | 540 | main() |