blob: 43fca1f5d84f599707d1aecd772666108fc4efb4 [file] [log] [blame]
Miklos Balint470919c2018-05-22 17:51:29 +02001#-------------------------------------------------------------------------------
Kevin Peng578a8492020-12-31 10:22:59 +08002# Copyright (c) 2018-2021, Arm Limited. All rights reserved.
Miklos Balint470919c2018-05-22 17:51:29 +02003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8import os
Mate Toth-Pal36f21842018-11-08 16:12:51 +01009import io
Shawn Shana9ad1e02019-08-07 15:49:48 +080010import sys
11import argparse
Ken Liu1f345b02020-05-30 21:11:05 +080012from jinja2 import Environment, BaseLoader, select_autoescape, TemplateNotFound
Miklos Balint470919c2018-05-22 17:51:29 +020013
14try:
15 import yaml
16except ImportError as e:
Mate Toth-Pala99ec6b2019-05-07 11:00:56 +020017 print (str(e) + " To install it, type:")
Mate Toth-Pal36f21842018-11-08 16:12:51 +010018 print ("pip install PyYAML")
Miklos Balint470919c2018-05-22 17:51:29 +020019 exit(1)
20
Edison Ai48b2d9e2019-06-24 14:39:45 +080021donotedit_warning = \
22 "/*********** " + \
23 "WARNING: This is an auto-generated file. Do not edit!" + \
24 " ***********/"
Kevin Peng655f2392019-11-27 16:33:02 +080025
Kevin Peng655f2392019-11-27 16:33:02 +080026OUT_DIR = None # The root directory that files are generated to
Edison Ai48b2d9e2019-06-24 14:39:45 +080027
Mate Toth-Pal36f21842018-11-08 16:12:51 +010028class TemplateLoader(BaseLoader):
29 """
30 Template loader class.
Miklos Balint470919c2018-05-22 17:51:29 +020031
Mate Toth-Pal36f21842018-11-08 16:12:51 +010032 An instance of this class is passed to the template engine. It is
33 responsible for reading the template file
34 """
35 def __init__(self):
36 pass
Miklos Balint470919c2018-05-22 17:51:29 +020037
Mate Toth-Pal36f21842018-11-08 16:12:51 +010038 def get_source(self, environment, template):
39 """
40 This function reads the template files.
41 For detailed documentation see:
42 http://jinja.pocoo.org/docs/2.10/api/#jinja2.BaseLoader.get_source
43
44 Please note that this function always return 'false' as 'uptodate'
45 value, so the output file will always be generated.
46 """
47 if not os.path.isfile(template):
48 raise TemplateNotFound(template)
49 with open(template) as f:
50 source = f.read()
51 return source, template, False
52
Mingyang Sun294ce2e2021-06-11 11:58:24 +080053def manifest_validation(partition_manifest):
54 """
55 This function validates FF-M compliance for partition manifest, and sets
56 default values for optional attributes.
57 More validation items will be added.
58 """
59 # Service FF-M manifest validation
60 if 'services' not in partition_manifest.keys():
61 return partition_manifest
62
63 for service in partition_manifest['services']:
64 if 'version' not in service.keys():
65 service['version'] = 1
66 if 'version_policy' not in service.keys():
67 service['version_policy'] = "STRICT"
68
69 return partition_manifest
70
Ken Liu861b0782021-05-22 13:15:08 +080071def process_partition_manifests(manifest_list_files):
Mate Toth-Pal36f21842018-11-08 16:12:51 +010072 """
Kevin Peng655f2392019-11-27 16:33:02 +080073 Parse the input manifest, generate the data base for genereated files
74 and generate manifest header files.
Mate Toth-Pal36f21842018-11-08 16:12:51 +010075
76 Parameters
77 ----------
Raef Colesf42f0882020-07-10 10:01:58 +010078 manifest_list_files:
79 The manifest lists to parse.
Mate Toth-Pal36f21842018-11-08 16:12:51 +010080
81 Returns
82 -------
Kevin Peng578a8492020-12-31 10:22:59 +080083 The partition data base.
Edison Ai48b2d9e2019-06-24 14:39:45 +080084 """
Kevin Peng655f2392019-11-27 16:33:02 +080085
Ken Liu861b0782021-05-22 13:15:08 +080086 partition_list = []
Kevin Peng655f2392019-11-27 16:33:02 +080087 manifest_list = []
88
Raef Colesf42f0882020-07-10 10:01:58 +010089 for f in manifest_list_files:
90 with open(f) as manifest_list_yaml_file:
91 manifest_dic = yaml.safe_load(manifest_list_yaml_file)
Kevin Peng655f2392019-11-27 16:33:02 +080092 manifest_list.extend(manifest_dic["manifest_list"])
Ken Liu861b0782021-05-22 13:15:08 +080093 manifest_list_yaml_file.close()
Kevin Peng655f2392019-11-27 16:33:02 +080094
Xinyu Zhang19504a52021-03-31 16:26:20 +080095 pid_list = []
Xinyu Zhangc46ee1f2021-04-01 10:10:43 +080096 no_pid_manifest_idx = []
97 for i, manifest_item in enumerate(manifest_list):
98 # Check if partition ID is manually set
99 if 'pid' not in manifest_item.keys():
100 no_pid_manifest_idx.append(i)
101 continue
Xinyu Zhang19504a52021-03-31 16:26:20 +0800102 # Check if partition ID is duplicated
103 if manifest_item['pid'] in pid_list:
104 raise Exception("PID No. {pid} has already been used!".format(pid=manifest_item['pid']))
105 pid_list.append(manifest_item['pid'])
Xinyu Zhangc46ee1f2021-04-01 10:10:43 +0800106 # Automatically generate PIDs for partitions without PID
107 pid = 256
108 for idx in no_pid_manifest_idx:
109 while pid in pid_list:
110 pid += 1
111 manifest_list[idx]['pid'] = pid
112 pid_list.append(pid)
Xinyu Zhang19504a52021-03-31 16:26:20 +0800113
Xinyu Zhangc46ee1f2021-04-01 10:10:43 +0800114 for manifest_item in manifest_list:
Raef Coles558487a2020-10-29 13:09:44 +0000115 # Replace environment variables in the manifest path
Kevin Peng655f2392019-11-27 16:33:02 +0800116 manifest_path = os.path.expandvars(manifest_item['manifest'])
117 file = open(manifest_path)
Mingyang Sun294ce2e2021-06-11 11:58:24 +0800118 manifest = manifest_validation(yaml.safe_load(file))
Ken Liu861b0782021-05-22 13:15:08 +0800119 file.close()
Kevin Peng655f2392019-11-27 16:33:02 +0800120
121 manifest_dir, manifest_name = os.path.split(manifest_path)
Ken Liu861b0782021-05-22 13:15:08 +0800122 manifest_out_basename = manifest_name.replace('.yaml', '').replace('.json', '')
123 manifest_head_file = os.path.join(manifest_dir, "psa_manifest", manifest_out_basename + '.h').replace('\\', '/')
124 intermedia_file = os.path.join(manifest_dir, "auto_generated", 'intermedia_' + manifest_out_basename + '.c').replace('\\', '/')
125 load_info_file = os.path.join(manifest_dir, "auto_generated", 'load_info_' + manifest_out_basename + '.c').replace('\\', '/')
Kevin Peng655f2392019-11-27 16:33:02 +0800126
Mingyang Sun4f012692020-10-16 14:04:49 +0800127 """
128 Remove the `source_path` portion of the filepaths, so that it can be
129 interpreted as a relative path from the OUT_DIR.
130 """
131 if 'source_path' in manifest_item:
Raef Coles558487a2020-10-29 13:09:44 +0000132 # Replace environment variables in the source path
133 source_path = os.path.expandvars(manifest_item['source_path'])
Ken Liu861b0782021-05-22 13:15:08 +0800134 manifest_head_file = os.path.relpath(manifest_head_file, start = source_path)
135 intermedia_file = os.path.relpath(intermedia_file, start = source_path)
136 load_info_file = os.path.relpath(load_info_file, start = source_path)
Kevin Peng655f2392019-11-27 16:33:02 +0800137
138 if OUT_DIR is not None:
Ken Liu861b0782021-05-22 13:15:08 +0800139 manifest_head_file = os.path.join(OUT_DIR, manifest_head_file)
140 intermedia_file = os.path.join(OUT_DIR, intermedia_file)
141 load_info_file = os.path.join(OUT_DIR, load_info_file)
Kevin Peng655f2392019-11-27 16:33:02 +0800142
Ken Liu861b0782021-05-22 13:15:08 +0800143 partition_list.append({"manifest": manifest, "attr": manifest_item,
144 "manifest_out_basename": manifest_out_basename,
145 "header_file": manifest_head_file,
146 "intermedia_file": intermedia_file,
147 "loadinfo_file": load_info_file})
148
149 return partition_list
150
151def gen_per_partition_files(context):
152 """
153 Generate per-partition files
154
155 Parameters
156 ----------
157 context:
158 context contains partition infos
159 """
160
161 subutilities = {}
162 subutilities['donotedit_warning'] = donotedit_warning
163
164 subcontext = {}
165 subcontext['utilities'] = subutilities
166
167 manifesttemplate = ENV.get_template('secure_fw/partitions/manifestfilename.template')
168 memorytemplate = ENV.get_template('secure_fw/partitions/partition_intermedia.template')
169 infotemplate = ENV.get_template('secure_fw/partitions/partition_load_info.template')
170
171 print ("Start to generate partition files:")
172
173 for one_partition in context['partitions']:
174 subcontext['manifest'] = one_partition['manifest']
175 subcontext['attr'] = one_partition['attr']
176 subcontext['manifest_out_basename'] = one_partition['manifest_out_basename']
177
178 print ("Generating Header: " + one_partition['header_file'])
179 outfile_path = os.path.dirname(one_partition['header_file'])
Kevin Peng655f2392019-11-27 16:33:02 +0800180 if not os.path.exists(outfile_path):
181 os.makedirs(outfile_path)
182
Ken Liu861b0782021-05-22 13:15:08 +0800183 headerfile = io.open(one_partition['header_file'], "w", newline=None)
184 headerfile.write(manifesttemplate.render(subcontext))
185 headerfile.close()
Kevin Peng655f2392019-11-27 16:33:02 +0800186
Ken Liu861b0782021-05-22 13:15:08 +0800187 print ("Generating Intermedia: " + one_partition['intermedia_file'])
188 intermediafile_path = os.path.dirname(one_partition['intermedia_file'])
Mingyang Sund20999f2020-10-15 14:53:12 +0800189 if not os.path.exists(intermediafile_path):
190 os.makedirs(intermediafile_path)
Ken Liu861b0782021-05-22 13:15:08 +0800191 intermediafile = io.open(one_partition['intermedia_file'], "w", newline=None)
192 intermediafile.write(memorytemplate.render(subcontext))
193 intermediafile.close()
Mingyang Sund20999f2020-10-15 14:53:12 +0800194
Ken Liu861b0782021-05-22 13:15:08 +0800195 print ("Generating Loadinfo: " + one_partition['loadinfo_file'])
196 infofile_path = os.path.dirname(one_partition['loadinfo_file'])
Mingyang Sunf6a78572021-04-02 16:51:05 +0800197 if not os.path.exists(infofile_path):
198 os.makedirs(infofile_path)
Ken Liu861b0782021-05-22 13:15:08 +0800199 infooutfile = io.open(one_partition['loadinfo_file'], "w", newline=None)
200 infooutfile.write(infotemplate.render(subcontext))
201 infooutfile.close()
Mingyang Sunf6a78572021-04-02 16:51:05 +0800202
Ken Liu861b0782021-05-22 13:15:08 +0800203 print ("Per-partition files done:")
Mingyang Sunf6a78572021-04-02 16:51:05 +0800204
Ken Liu861b0782021-05-22 13:15:08 +0800205def gen_summary_files(context, gen_file_lists):
Kevin Peng655f2392019-11-27 16:33:02 +0800206 """
207 Generate files according to the gen_file_list
Edison Ai48b2d9e2019-06-24 14:39:45 +0800208
209 Parameters
210 ----------
Raef Colesf42f0882020-07-10 10:01:58 +0100211 gen_file_lists:
212 The lists of files to generate
Edison Ai48b2d9e2019-06-24 14:39:45 +0800213 """
Kevin Peng655f2392019-11-27 16:33:02 +0800214 file_list = []
Shawn Shana9ad1e02019-08-07 15:49:48 +0800215
Raef Colesf42f0882020-07-10 10:01:58 +0100216 for f in gen_file_lists:
217 with open(f) as file_list_yaml_file:
Kevin Peng655f2392019-11-27 16:33:02 +0800218 file_list_yaml = yaml.safe_load(file_list_yaml_file)
219 file_list.extend(file_list_yaml["file_list"])
Edison Ai48b2d9e2019-06-24 14:39:45 +0800220
edison.ai7b299f52020-07-16 15:44:18 +0800221 print("Start to generate file from the generated list:")
Kevin Peng655f2392019-11-27 16:33:02 +0800222 for file in file_list:
Raef Coles558487a2020-10-29 13:09:44 +0000223 # Replace environment variables in the output filepath
Ken Liu861b0782021-05-22 13:15:08 +0800224 manifest_out_file = os.path.expandvars(file["output"])
Raef Coles558487a2020-10-29 13:09:44 +0000225 # Replace environment variables in the template filepath
Kevin Peng1ec5e7c2019-11-29 10:52:00 +0800226 templatefile_name = os.path.expandvars(file["template"])
Edison Ai48b2d9e2019-06-24 14:39:45 +0800227
Kevin Peng655f2392019-11-27 16:33:02 +0800228 if OUT_DIR is not None:
Ken Liu861b0782021-05-22 13:15:08 +0800229 manifest_out_file = os.path.join(OUT_DIR, manifest_out_file)
Edison Ai48b2d9e2019-06-24 14:39:45 +0800230
Ken Liu861b0782021-05-22 13:15:08 +0800231 print ("Generating " + manifest_out_file)
edison.ai7b299f52020-07-16 15:44:18 +0800232
Ken Liu861b0782021-05-22 13:15:08 +0800233 outfile_path = os.path.dirname(manifest_out_file)
Kevin Peng655f2392019-11-27 16:33:02 +0800234 if not os.path.exists(outfile_path):
235 os.makedirs(outfile_path)
Edison Ai48b2d9e2019-06-24 14:39:45 +0800236
Kevin Peng655f2392019-11-27 16:33:02 +0800237 template = ENV.get_template(templatefile_name)
Edison Ai6e3f2a32019-06-11 15:29:05 +0800238
Ken Liu861b0782021-05-22 13:15:08 +0800239 outfile = io.open(manifest_out_file, "w", newline=None)
Kevin Peng655f2392019-11-27 16:33:02 +0800240 outfile.write(template.render(context))
241 outfile.close()
Edison Ai48b2d9e2019-06-24 14:39:45 +0800242
Kevin Peng655f2392019-11-27 16:33:02 +0800243 print ("Generation of files done")
Edison Ai48b2d9e2019-06-24 14:39:45 +0800244
Ken Liu861b0782021-05-22 13:15:08 +0800245def process_stateless_services(partitions, stateless_index_max_num):
Mingyang Suna1ca6112021-01-11 11:34:59 +0800246 """
247 This function collects all stateless services together, and allocates
Mingyang Sun4ecea992021-03-30 17:56:26 +0800248 stateless handles for them.
Kevin Pengc05319d2021-04-22 22:59:35 +0800249 Valid stateless handle in service will be converted to an index. If the
250 stateless handle is set as "auto", or not set, framework will allocate a
251 valid index for the service.
252 Framework puts each service into a reordered stateless service list at
253 position of "index". Other unused positions are left None.
Mingyang Suna1ca6112021-01-11 11:34:59 +0800254 """
Kevin Pengc05319d2021-04-22 22:59:35 +0800255 collected_stateless_services = []
Mingyang Suna1ca6112021-01-11 11:34:59 +0800256
257 # Collect all stateless services first.
258 for partition in partitions:
259 # Skip the FF-M 1.0 partitions
260 if partition['manifest']['psa_framework_version'] < 1.1:
261 continue
262 # Skip the Non-IPC partitions
263 if partition['attr']['tfm_partition_ipc'] is not True:
264 continue
265 for service in partition['manifest']['services']:
266 if 'connection_based' not in service:
267 raise Exception("'connection_based' is mandatory in FF-M 1.1 service!")
268 if service['connection_based'] is False:
Kevin Pengc05319d2021-04-22 22:59:35 +0800269 collected_stateless_services.append(service)
Mingyang Suna1ca6112021-01-11 11:34:59 +0800270
Kevin Pengc05319d2021-04-22 22:59:35 +0800271 if len(collected_stateless_services) == 0:
Mingyang Suna1ca6112021-01-11 11:34:59 +0800272 return []
273
Ken Liu861b0782021-05-22 13:15:08 +0800274 if len(collected_stateless_services) > stateless_index_max_num:
275 raise Exception("Stateless service numbers range exceed {number}.".format(number=stateless_index_max_num))
Mingyang Suna1ca6112021-01-11 11:34:59 +0800276
277 """
Kevin Pengc05319d2021-04-22 22:59:35 +0800278 Allocate an empty stateless service list to store services.
279 Use "handle - 1" as the index for service, since handle value starts from
280 1 and list index starts from 0.
Mingyang Suna1ca6112021-01-11 11:34:59 +0800281 """
Ken Liu861b0782021-05-22 13:15:08 +0800282 reordered_stateless_services = [None] * stateless_index_max_num
Kevin Pengc05319d2021-04-22 22:59:35 +0800283 auto_alloc_services = []
Mingyang Suna1ca6112021-01-11 11:34:59 +0800284
Kevin Pengc05319d2021-04-22 22:59:35 +0800285 for service in collected_stateless_services:
286 # If not set, it is "auto" by default
287 if 'stateless_handle' not in service:
288 auto_alloc_services.append(service)
289 continue
290
Mingyang Sun4ecea992021-03-30 17:56:26 +0800291 service_handle = service['stateless_handle']
Mingyang Suna1ca6112021-01-11 11:34:59 +0800292
Mingyang Sun4ecea992021-03-30 17:56:26 +0800293 # Fill in service list with specified stateless handle, otherwise skip
294 if isinstance(service_handle, int):
Ken Liu861b0782021-05-22 13:15:08 +0800295 if service_handle < 1 or service_handle > stateless_index_max_num:
Kevin Pengc05319d2021-04-22 22:59:35 +0800296 raise Exception("Invalid stateless_handle setting: {handle}.".format(handle=service['stateless_handle']))
Mingyang Sun4ecea992021-03-30 17:56:26 +0800297 # Convert handle index to reordered service list index
298 service_handle = service_handle - 1
299
300 if reordered_stateless_services[service_handle] is not None:
Kevin Pengc05319d2021-04-22 22:59:35 +0800301 raise Exception("Duplicated stateless_handle setting: {handle}.".format(handle=service['stateless_handle']))
Mingyang Sun4ecea992021-03-30 17:56:26 +0800302 reordered_stateless_services[service_handle] = service
Kevin Pengc05319d2021-04-22 22:59:35 +0800303 elif service_handle == 'auto':
304 auto_alloc_services.append(service)
305 else:
306 raise Exception("Invalid stateless_handle setting: {handle}.".format(handle=service['stateless_handle']))
Mingyang Sun4ecea992021-03-30 17:56:26 +0800307
308 # Auto-allocate stateless handle and encode the stateless handle
Ken Liu861b0782021-05-22 13:15:08 +0800309 for i in range(0, stateless_index_max_num):
Mingyang Sun4ecea992021-03-30 17:56:26 +0800310 service = reordered_stateless_services[i]
311
Kevin Pengc05319d2021-04-22 22:59:35 +0800312 if service == None and len(auto_alloc_services) > 0:
313 service = auto_alloc_services.pop(0)
Mingyang Sun4ecea992021-03-30 17:56:26 +0800314
Mingyang Sun453ad402021-03-17 17:58:33 +0800315 """
316 Encode stateless flag and version into stateless handle
317 bit 30: stateless handle indicator
318 bit 15-8: stateless service version
319 bit 7-0: stateless handle index
320 """
Mingyang Sun4ecea992021-03-30 17:56:26 +0800321 stateless_handle_value = 0
322 if service != None:
323 stateless_index = (i & 0xFF)
324 stateless_handle_value |= stateless_index
Mingyang Sun453ad402021-03-17 17:58:33 +0800325 stateless_flag = 1 << 30
326 stateless_handle_value |= stateless_flag
Mingyang Sun4ecea992021-03-30 17:56:26 +0800327 stateless_version = (service['version'] & 0xFF) << 8
Mingyang Sun453ad402021-03-17 17:58:33 +0800328 stateless_handle_value |= stateless_version
Mingyang Sun4ecea992021-03-30 17:56:26 +0800329 service['stateless_handle_value'] = '0x{0:08x}'.format(stateless_handle_value)
Ken Liu861b0782021-05-22 13:15:08 +0800330 service['stateless_handle_index'] = stateless_index
Mingyang Suna1ca6112021-01-11 11:34:59 +0800331
Mingyang Sun4ecea992021-03-30 17:56:26 +0800332 reordered_stateless_services[i] = service
333
334 return reordered_stateless_services
Mingyang Suna1ca6112021-01-11 11:34:59 +0800335
Kevin Peng655f2392019-11-27 16:33:02 +0800336def parse_args():
Raef Coles558487a2020-10-29 13:09:44 +0000337 parser = argparse.ArgumentParser(description='Parse secure partition manifest list and generate files listed by the file list',
338 epilog='Note that environment variables in template files will be replaced with their values')
339
Kevin Peng655f2392019-11-27 16:33:02 +0800340 parser.add_argument('-o', '--outdir'
341 , dest='outdir'
342 , required=False
343 , default=None
344 , metavar='out_dir'
345 , help='The root directory for generated files, the default is TF-M root folder.')
Shawn Shana9ad1e02019-08-07 15:49:48 +0800346
Kevin Peng655f2392019-11-27 16:33:02 +0800347 parser.add_argument('-m', '--manifest'
Raef Colesf42f0882020-07-10 10:01:58 +0100348 , nargs='+'
Kevin Peng655f2392019-11-27 16:33:02 +0800349 , dest='manifest_args'
Raef Colesf42f0882020-07-10 10:01:58 +0100350 , required=True
Kevin Peng655f2392019-11-27 16:33:02 +0800351 , metavar='manifest'
Raef Colesf42f0882020-07-10 10:01:58 +0100352 , help='A set of secure partition manifest lists to parse')
Kevin Peng655f2392019-11-27 16:33:02 +0800353
354 parser.add_argument('-f', '--file-list'
Raef Colesf42f0882020-07-10 10:01:58 +0100355 , nargs='+'
Kevin Peng655f2392019-11-27 16:33:02 +0800356 , dest='gen_file_args'
Raef Colesf42f0882020-07-10 10:01:58 +0100357 , required=True
Kevin Peng655f2392019-11-27 16:33:02 +0800358 , metavar='file-list'
Raef Colesf42f0882020-07-10 10:01:58 +0100359 , help='These files descripe the file list to generate')
Kevin Peng655f2392019-11-27 16:33:02 +0800360
361 args = parser.parse_args()
362 manifest_args = args.manifest_args
363 gen_file_args = args.gen_file_args
364
Kevin Peng655f2392019-11-27 16:33:02 +0800365 return args
366
367ENV = Environment(
368 loader = TemplateLoader(),
369 autoescape = select_autoescape(['html', 'xml']),
370 lstrip_blocks = True,
371 trim_blocks = True,
372 keep_trailing_newline = True
373 )
Mate Toth-Pal36f21842018-11-08 16:12:51 +0100374
Miklos Balint470919c2018-05-22 17:51:29 +0200375def main():
Mate Toth-Pal36f21842018-11-08 16:12:51 +0100376 """
377 The entry point of the script.
378
379 Generates the output files based on the templates and the manifests.
380 """
Shawn Shana9ad1e02019-08-07 15:49:48 +0800381
Kevin Peng655f2392019-11-27 16:33:02 +0800382 global OUT_DIR
Shawn Shana9ad1e02019-08-07 15:49:48 +0800383
Kevin Peng655f2392019-11-27 16:33:02 +0800384 args = parse_args()
Shawn Shana9ad1e02019-08-07 15:49:48 +0800385
Kevin Peng655f2392019-11-27 16:33:02 +0800386 manifest_args = args.manifest_args
387 gen_file_args = args.gen_file_args
388 OUT_DIR = args.outdir
Kevin Peng655f2392019-11-27 16:33:02 +0800389
Raef Coles558487a2020-10-29 13:09:44 +0000390 manifest_list = [os.path.abspath(x) for x in args.manifest_args]
391 gen_file_list = [os.path.abspath(x) for x in args.gen_file_args]
Shawn Shana9ad1e02019-08-07 15:49:48 +0800392
393 # Arguments could be relative path.
Kevin Peng655f2392019-11-27 16:33:02 +0800394 # Convert to absolute path as we are going to change diretory later
395 if OUT_DIR is not None:
396 OUT_DIR = os.path.abspath(OUT_DIR)
397
Shawn Shana9ad1e02019-08-07 15:49:48 +0800398 """
Kevin Peng655f2392019-11-27 16:33:02 +0800399 Relative path to TF-M root folder is supported in the manifests
400 and default value of manifest list and generated file list are relative to TF-M root folder as well,
401 so first change directory to TF-M root folder.
Shawn Shana9ad1e02019-08-07 15:49:48 +0800402 By doing this, the script can be executed anywhere
Kevin Peng655f2392019-11-27 16:33:02 +0800403 The script is located in <TF-M root folder>/tools, so sys.path[0]<location of the script>/.. is TF-M root folder.
Shawn Shana9ad1e02019-08-07 15:49:48 +0800404 """
405 os.chdir(os.path.join(sys.path[0], ".."))
406
Ken Liu861b0782021-05-22 13:15:08 +0800407 partition_list = process_partition_manifests(manifest_list)
Mate Toth-Pal36f21842018-11-08 16:12:51 +0100408
Edison Ai6e3f2a32019-06-11 15:29:05 +0800409 utilities = {}
Mingyang Suna1ca6112021-01-11 11:34:59 +0800410 utilities['donotedit_warning'] = donotedit_warning
Miklos Balint470919c2018-05-22 17:51:29 +0200411
Ken Liu861b0782021-05-22 13:15:08 +0800412 context = {}
413 context['partitions'] = partition_list
Kevin Peng655f2392019-11-27 16:33:02 +0800414 context['utilities'] = utilities
Ken Liu861b0782021-05-22 13:15:08 +0800415 context['stateless_services'] = process_stateless_services(partition_list, 32)
Mate Toth-Pal36f21842018-11-08 16:12:51 +0100416
Ken Liu861b0782021-05-22 13:15:08 +0800417 gen_per_partition_files(context)
418 gen_summary_files(context, gen_file_list)
Miklos Balint470919c2018-05-22 17:51:29 +0200419
420if __name__ == "__main__":
421 main()