blob: 56bf4697f169692c256de3bd5c514185fb9efb29 [file] [log] [blame]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +01001#!/usr/bin/env python3
2
3""" tfm_build_manager.py:
4
5 Controlling class managing multiple build configruations for tfm """
6
7from __future__ import print_function
8
9__copyright__ = """
10/*
11 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
12 *
13 * SPDX-License-Identifier: BSD-3-Clause
14 *
15 */
16 """
17__author__ = "Minos Galanakis"
18__email__ = "minos.galanakis@linaro.org"
19__project__ = "Trusted Firmware-M Open CI"
20__status__ = "stable"
Minos Galanakisea421232019-06-20 17:11:28 +010021__version__ = "1.1"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010022
23import os
24import sys
Karl Zhangaff558a2020-05-15 14:28:23 +010025from .utils import *
Minos Galanakisea421232019-06-20 17:11:28 +010026from time import time
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010027from copy import deepcopy
28from .utils import gen_cfg_combinations, list_chunks, load_json,\
Minos Galanakisea421232019-06-20 17:11:28 +010029 save_json, print_test, show_progress, \
30 resolve_rel_path
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010031from .structured_task import structuredTask
32from .tfm_builder import TFM_Builder
33
34
35class TFM_Build_Manager(structuredTask):
36 """ Class that will load a configuration out of a json file, schedule
37 the builds, and produce a report """
38
39 def __init__(self,
40 tfm_dir, # TFM root directory
41 work_dir, # Current working directory(ie logs)
42 cfg_dict, # Input config dictionary of the following form
43 # input_dict = {"PROJ_CONFIG": "ConfigRegression",
44 # "TARGET_PLATFORM": "MUSCA_A",
45 # "COMPILER": "ARMCLANG",
46 # "CMAKE_BUILD_TYPE": "Debug"}
47 report=None, # File to produce report
48 parallel_builds=3, # Number of builds to run in parallel
Minos Galanakisea421232019-06-20 17:11:28 +010049 build_threads=3, # Number of threads used per build
50 install=False, # Install libraries after build
51 img_sizes=False, # Use arm-none-eabi-size for size info
52 relative_paths=False): # Store relative paths in report
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010053 self._tbm_build_threads = build_threads
54 self._tbm_conc_builds = parallel_builds
55 self._tbm_install = install
Minos Galanakisea421232019-06-20 17:11:28 +010056 self._tbm_img_sizes = img_sizes
57 self._tbm_relative_paths = relative_paths
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010058
59 # Required by other methods, always set working directory first
60 self._tbm_work_dir = os.path.abspath(os.path.expanduser(work_dir))
61
62 self._tbm_tfm_dir = os.path.abspath(os.path.expanduser(tfm_dir))
63
Karl Zhangaff558a2020-05-15 14:28:23 +010064 print("bm param tfm_dir %s" % tfm_dir)
65 print("bm %s %s %s" % (work_dir, cfg_dict, self._tbm_work_dir))
Minos Galanakisea421232019-06-20 17:11:28 +010066 # Internal flag to tag simple (non combination formatted configs)
67 self.simple_config = False
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010068 self._tbm_report = report
69
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010070 self._tbm_cfg = self.load_config(cfg_dict, self._tbm_work_dir)
Minos Galanakisea421232019-06-20 17:11:28 +010071 self._tbm_build_cfg, \
72 self.tbm_common_cfg = self.parse_config(self._tbm_cfg)
Karl Zhangaff558a2020-05-15 14:28:23 +010073 self._tfb_code_base_updated = False
74 self._tfb_log_f = "CodeBasePrepare.log"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010075
76 super(TFM_Build_Manager, self).__init__(name="TFM_Build_Manager")
77
Dean Birch5cb5a882020-01-24 11:37:13 +000078 def print_config(self):
79 """Prints a list of available build configurations"""
80 print("\n".join(list(self._tbm_build_cfg.keys())))
81
82 def print_config_environment(self, config):
83 """
84 For a given build configuration from output of print_config
85 method, print environment variables to build.
86 """
87 if config not in self._tbm_build_cfg:
88 print("Error: no such config {}".format(config), file=sys.stderr)
89 sys.exit(1)
90 config_details = self._tbm_build_cfg[config]
91 argument_list = [
92 "TARGET_PLATFORM={}",
93 "COMPILER={}",
94 "PROJ_CONFIG={}",
95 "CMAKE_BUILD_TYPE={}",
96 "BL2={}",
97 ]
98 print(
99 "\n".join(argument_list)
100 .format(
101 config_details.target_platform,
102 config_details.compiler,
103 config_details.proj_config,
104 config_details.cmake_build_type,
105 config_details.with_mcuboot,
106 )
107 .strip()
108 )
109
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100110 def pre_eval(self):
111 """ Tests that need to be run in set-up state """
112 return True
113
114 def pre_exec(self, eval_ret):
115 """ """
116
Minos Galanakisea421232019-06-20 17:11:28 +0100117 def override_tbm_cfg_params(self, config, override_keys, **params):
118 """ Using a dictionay as input, for each key defined in
119 override_keys it will replace the config[key] entries with
120 the key=value parameters provided """
121
122 for key in override_keys:
123 if isinstance(config[key], list):
124 config[key] = [n % params for n in config[key]]
125 elif isinstance(config[key], str):
126 config[key] = config[key] % params
127 else:
128 raise Exception("Config does not contain key %s "
129 "of type %s" % (key, config[key]))
130 return config
131
Karl Zhangaff558a2020-05-15 14:28:23 +0100132 def pre_build(self, build_cfg):
133 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
134 (self, build_cfg))
135
136 try:
137 if self._tfb_code_base_updated:
138 print("Code base has been updated")
139 return True
140
141 self._tfb_code_base_updated = True
142
143 if "build_psa_api" in build_cfg:
144 # FF IPC build needs repo manifest update for TFM and PSA arch test
145 if "build_ff_ipc" in build_cfg:
146 print("Checkout to FF IPC code base")
147 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
148 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
149 if subprocess_log(_api_test_manifest,
150 self._tfb_log_f,
151 append=True,
152 prefix=_api_test_manifest):
153
154 raise Exception("Python Failed please check log: %s" %
155 self._tfb_log_f)
156
157 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
158 os.chdir(build_cfg["codebase_root_dir"])
159 if subprocess_log(_api_test_manifest_tfm,
160 self._tfb_log_f,
161 append=True,
162 prefix=_api_test_manifest_tfm):
163
164 raise Exception("Python TFM Failed please check log: %s" %
165 self._tfb_log_f)
166 return True
167
168 print("Checkout to default code base")
169 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
170 _api_test_manifest = "git checkout ."
171 if subprocess_log(_api_test_manifest,
172 self._tfb_log_f,
173 append=True,
174 prefix=_api_test_manifest):
175
176 raise Exception("Python Failed please check log: %s" %
177 self._tfb_log_f)
178
179 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
180 os.chdir(build_cfg["codebase_root_dir"])
181 if subprocess_log(_api_test_manifest_tfm,
182 self._tfb_log_f,
183 append=True,
184 prefix=_api_test_manifest_tfm):
185
186 raise Exception("Python TFM Failed please check log: %s" %
187 self._tfb_log_f)
188 finally:
189 print("python pass after builder prepare")
190 os.chdir(build_cfg["codebase_root_dir"] + "/../")
191
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100192 def task_exec(self):
193 """ Create a build pool and execute them in parallel """
194
195 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100196
Minos Galanakisea421232019-06-20 17:11:28 +0100197 # When a config is flagged as a single build config.
198 # Name is evaluated by config type
199 if self.simple_config:
200
201 build_cfg = deepcopy(self.tbm_common_cfg)
202
203 # Extract the common for all elements of config
204 for key in ["build_cmds", "required_artefacts"]:
205 try:
206 build_cfg[key] = build_cfg[key]["all"]
207 except KeyError:
208 build_cfg[key] = []
209 name = build_cfg["config_type"]
210
211 # Override _tbm_xxx paths in commands
212 # plafrom in not guaranteed without seeds so _tbm_target_platform
213 # is ignored
214 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
215 name),
216 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
217
218 build_cfg = self.override_tbm_cfg_params(build_cfg,
219 ["build_cmds",
220 "required_artefacts",
221 "artifact_capture_rex"],
222 **over_dict)
223
224 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100225 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100226
227 build_pool.append(TFM_Builder(
228 name=name,
229 work_dir=self._tbm_work_dir,
230 cfg_dict=build_cfg,
231 build_threads=self._tbm_build_threads,
232 img_sizes=self._tbm_img_sizes,
233 relative_paths=self._tbm_relative_paths))
234 # When a seed pool is provided iterate through the entries
235 # and update platform spefific parameters
236 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100237 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
238 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100239 for name, i in self._tbm_build_cfg.items():
240 # Do not modify the original config
241 build_cfg = deepcopy(self.tbm_common_cfg)
242
243 # Extract the common for all elements of config
244 for key in ["build_cmds", "required_artefacts"]:
245 try:
246 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
247 ["all"])
248 except KeyError as E:
249 build_cfg[key] = []
250
251 # Extract the platform specific elements of config
252 for key in ["build_cmds", "required_artefacts"]:
253 try:
254 if i.target_platform in self.tbm_common_cfg[key].keys():
255 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
256 [i.target_platform])
257 except Exception as E:
258 pass
259
260 # Merge the two dictionaries since the template may contain
261 # fixed and combinations seed parameters
Karl Zhangaff558a2020-05-15 14:28:23 +0100262 if i.proj_config.startswith("ConfigPsaApiTest"):
263 #PSA API tests only
264 #TODO i._asdict()["tfm_build_dir"] = self._tbm_work_dir
265 cmd0 = build_cfg["config_template_psa_api"] % \
266 {**dict(i._asdict()), **build_cfg}
267 cmd0 += " -DPSA_API_TEST_BUILD_PATH=" + self._tbm_work_dir + \
268 "/" + name + "/BUILD"
Minos Galanakisea421232019-06-20 17:11:28 +0100269
Karl Zhangaff558a2020-05-15 14:28:23 +0100270 if i.psa_api_suit == "FF":
271 cmd0 += " -DPSA_API_TEST_IPC=ON"
272 cmd2 = "cmake " + build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests/ " + \
273 "-G\"Unix Makefiles\" -DTARGET=tgt_ff_tfm_" + \
274 i.target_platform.lower() +" -DCPU_ARCH=armv8m_ml -DTOOLCHAIN=" + \
275 i.compiler + " -DSUITE=IPC -DPSA_INCLUDE_PATHS=\"" + \
276 build_cfg["codebase_root_dir"] + "/interface/include/"
277
278 cmd2 += ";" + build_cfg["codebase_root_dir"] + \
279 "/../psa-arch-tests/api-tests/platform/manifests\"" + \
280 " -DINCLUDE_PANIC_TESTS=1 -DPLATFORM_PSA_ISOLATION_LEVEL=" + \
281 (("2") if i.proj_config.find("TfmLevel2") > 0 else "1") + \
282 " -DSP_HEAP_MEM_SUPP=0"
283 if i.target_platform == "MUSCA_B1":
284 cmd0 += " -DSST_RAM_FS=ON"
285 build_cfg["build_ff_ipc"] = "IPC"
286 else:
287 cmd0 += " -DPSA_API_TEST_" + i.psa_api_suit + "=ON"
288 cmd2 = "cmake " + build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests/ " + \
289 "-G\"Unix Makefiles\" -DTARGET=tgt_dev_apis_tfm_" + \
290 i.target_platform.lower() +" -DCPU_ARCH=armv8m_ml -DTOOLCHAIN=" + \
291 i.compiler + " -DSUITE=" + i.psa_api_suit +" -DPSA_INCLUDE_PATHS=\"" + \
292 build_cfg["codebase_root_dir"] + "/interface/include/\""
293
294 cmd2 += " -DCMAKE_BUILD_TYPE=" + i.cmake_build_type
295
296 cmd3 = "cmake --build ."
297 build_cfg["build_psa_api"] = cmd2 + " ; " + cmd3
298
299 else:
300 cmd0 = build_cfg["config_template"] % \
301 {**dict(i._asdict()), **build_cfg}
302
303 try:
304 if i.__str__().find("with_OTP") > 0:
305 cmd0 += " -DCRYPTO_HW_ACCELERATOR_OTP_STATE=ENABLED"
306 else:
307 build_cfg["build_cmds"][0] += " -j 2"
308 if cmd0.find("SST_RAM_FS=ON") < 0 and i.target_platform == "MUSCA_B1":
309 cmd0 += " -DSST_RAM_FS=OFF -DITS_RAM_FS=OFF"
310 except Exception as E:
311 pass
312
313 # Prepend configuration commoand as the first cmd [cmd1] + [cmd2] + [cmd3] +
Minos Galanakisea421232019-06-20 17:11:28 +0100314 build_cfg["build_cmds"] = [cmd0] + build_cfg["build_cmds"]
Karl Zhangaff558a2020-05-15 14:28:23 +0100315 print("cmd0 %s\r\n" % (build_cfg["build_cmds"]))
316 if "build_psa_api" in build_cfg:
317 print("cmd build_psa_api %s\r\n" % build_cfg["build_psa_api"])
Minos Galanakisea421232019-06-20 17:11:28 +0100318
319 # Set the overrid params
320 over_dict = {"_tbm_build_dir_": os.path.join(
321 self._tbm_work_dir, name),
322 "_tbm_code_dir_": build_cfg["codebase_root_dir"],
323 "_tbm_target_platform_": i.target_platform}
324
325 over_params = ["build_cmds",
326 "required_artefacts",
327 "artifact_capture_rex"]
328 build_cfg = self.override_tbm_cfg_params(build_cfg,
329 over_params,
330 **over_dict)
Karl Zhangaff558a2020-05-15 14:28:23 +0100331 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100332 # Overrides path in expected artefacts
333 print("Loading config %s" % name)
334
335 build_pool.append(TFM_Builder(
336 name=name,
337 work_dir=self._tbm_work_dir,
338 cfg_dict=build_cfg,
339 build_threads=self._tbm_build_threads,
340 img_sizes=self._tbm_img_sizes,
341 relative_paths=self._tbm_relative_paths))
342 else:
343 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100344
345 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100346 build_rep = {}
347 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100348 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
349 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
350
351 # Start the builds
352 for build in build_pool_slice:
353 # Only produce output for the first build
354 if build_pool_slice.index(build) != 0:
355 build.mute()
356 print("Build: Starting %s" % build.get_name())
357 build.start()
358
359 # Wait for the builds to complete
360 for build in build_pool_slice:
361 # Wait for build to finish
362 build.join()
363 # Similarly print the logs of the other builds as they complete
364 if build_pool_slice.index(build) != 0:
365 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100366 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100367 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100368 print("Build Progress:")
369 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100370
371 # Store status in report
372 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100373 build_rep[build.get_name()] = build.report()
374
375 # Include the original input configuration in the report
376
377 metadata = {"input_build_cfg": self._tbm_cfg,
378 "build_dir": self._tbm_work_dir
379 if not self._tbm_relative_paths
380 else resolve_rel_path(self._tbm_work_dir),
381 "time": time()}
382
383 full_rep = {"report": build_rep,
384 "_metadata_": metadata}
385
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100386 # Store the report
387 self.stash("Build Status", status_rep)
388 self.stash("Build Report", full_rep)
389
390 if self._tbm_report:
391 print("Exported build report to file:", self._tbm_report)
392 save_json(self._tbm_report, full_rep)
393
394 def post_eval(self):
395 """ If a single build failed fail the test """
396 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100397 status_dict = self.unstash("Build Status")
398 if not status_dict:
399 raise Exception()
400 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100401 if retcode_sum != 0:
402 raise Exception()
403 return True
404 except Exception as e:
405 return False
406
407 def post_exec(self, eval_ret):
408 """ Generate a report and fail the script if build == unsuccessfull"""
409
410 self.print_summary()
411 if not eval_ret:
412 print("ERROR: ====> Build Failed! %s" % self.get_name())
413 self.set_status(1)
414 else:
415 print("SUCCESS: ====> Build Complete!")
416 self.set_status(0)
417
418 def get_report(self):
419 """ Expose the internal report to a new object for external classes """
420 return deepcopy(self.unstash("Build Report"))
421
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100422 def load_config(self, config, work_dir):
423 try:
424 # passing config_name param supersseeds fileparam
425 if isinstance(config, dict):
426 ret_cfg = deepcopy(config)
427 elif isinstance(config, str):
428 # If the string does not descrive a file try to look for it in
429 # work directory
430 if not os.path.isfile(config):
431 # remove path from file
432 config_2 = os.path.split(config)[-1]
433 # look in the current working directory
434 config_2 = os.path.join(work_dir, config_2)
435 if not os.path.isfile(config_2):
436 m = "Could not find cfg in %s or %s " % (config,
437 config_2)
438 raise Exception(m)
439 # If fille exists in working directory
440 else:
441 config = config_2
442 ret_cfg = load_json(config)
443
444 else:
445 raise Exception("Need to provide a valid config name or file."
446 "Please use --config/--config-file parameter.")
447 except Exception as e:
448 print("Error:%s \nCould not load a valid config" % e)
449 sys.exit(1)
450
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100451 return ret_cfg
452
453 def parse_config(self, cfg):
454 """ Parse a valid configuration file into a set of build dicts """
455
Minos Galanakisea421232019-06-20 17:11:28 +0100456 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100457
Minos Galanakisea421232019-06-20 17:11:28 +0100458 # Config entries which are not subject to changes during combinations
459 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100460
Minos Galanakisea421232019-06-20 17:11:28 +0100461 # Converth the code path to absolute path
462 abs_code_dir = static_cfg["codebase_root_dir"]
463 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
464 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100465
Minos Galanakisea421232019-06-20 17:11:28 +0100466 # seed_params is an optional field. Do not proccess if it is missing
467 if "seed_params" in cfg:
468 comb_cfg = cfg["seed_params"]
469 # Generate a list of all possible confugration combinations
470 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
471 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100472
Minos Galanakisea421232019-06-20 17:11:28 +0100473 # invalid is an optional field. Do not proccess if it is missing
474 if "invalid" in cfg:
475 # Invalid configurations(Do not build)
476 invalid_cfg = cfg["invalid"]
477 # Remove the rejected entries from the test list
478 rejection_cfg = TFM_Build_Manager.generate_rejection_list(
479 comb_cfg,
480 static_cfg,
481 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100482
Minos Galanakisea421232019-06-20 17:11:28 +0100483 # Subtract the two configurations
484 ret_cfg = {k: v for k, v in ret_cfg.items()
485 if k not in rejection_cfg}
486 self.simple_config = False
487 else:
488 self.simple_config = True
489 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100490
Minos Galanakisea421232019-06-20 17:11:28 +0100491 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100492
Minos Galanakisea421232019-06-20 17:11:28 +0100493 def print_summary(self):
494 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100495
Minos Galanakisea421232019-06-20 17:11:28 +0100496 try:
497 full_rep = self.unstash("Build Report")["report"]
498 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
499 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
500 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100501 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100502 return
503 if fl:
504 print_test(t_list=fl, status="failed", tname="Builds")
505 if ps:
506 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100507
Minos Galanakisea421232019-06-20 17:11:28 +0100508 @staticmethod
509 def generate_config_list(seed_config, static_config):
510 """ Generate all possible configuration combinations from a group of
511 lists of compiler options"""
512 config_list = []
513
514 if static_config["config_type"] == "tf-m":
515 cfg_name = "TFM_Build_CFG"
516 # Ensure the fieds are sorted in the desired order
517 # seed_config can be a subset of sort order for configurations with
518 # optional parameters.
519 tags = [n for n in static_config["sort_order"]
520 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100521 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100522
523 data = []
524 for key in tags:
525 data.append(seed_config[key])
526 config_list = gen_cfg_combinations(cfg_name,
527 " ".join(tags),
528 *data)
529 else:
530 print("Not information for project type: %s."
531 " Please check config" % static_config["config_type"])
532
533 ret_cfg = {}
534 # Notify the user for the rejected configuations
535 for i in config_list:
536 # Convert named tuples to string with boolean support
537 i_str = "_".join(map(lambda x: repr(x)
538 if isinstance(x, bool) else x, list(i)))
539
540 # Replace bollean vaiables with more BL2/NOBL2 and use it as"
541 # configuration name.
Karl Zhangaff558a2020-05-15 14:28:23 +0100542 i_str = i_str.replace("True", "BL2").replace("False", "NOBL2")
543 i_str = i_str.replace("CRYPTO", "Crypto")
544 i_str = i_str.replace("PROTECTED_STORAGE", "PS")
545 i_str = i_str.replace("INITIAL_ATTESTATION", "Attest")
546 i_str = i_str.replace("INTERNAL_TRUSTED_STORAGE", "ITS")
547 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100548
549 return ret_cfg
550
551 @staticmethod
552 def generate_rejection_list(seed_config,
553 static_config,
554 rejection_list):
555 rejection_cfg = {}
556
557 if static_config["config_type"] == "tf-m":
558
559 # If rejection list is empty do nothing
560 if not rejection_list:
561 return rejection_cfg
562
563 tags = [n for n in static_config["sort_order"]
564 if n in seed_config.keys()]
565 sorted_default_lst = [seed_config[k] for k in tags]
566
567 # If tags are not alligned with rejection list entries quit
568 if len(tags) != len(rejection_list[0]):
569 print(len(tags), len(rejection_list[0]))
570 print("Error, tags should be assigned to each "
571 "of the rejection inputs")
572 return []
573
574 # Replace wildcard ( "*") entries with every
575 # inluded in cfg variant
576 for k in rejection_list:
577 # Pad the omitted values with wildcard char *
578 res_list = list(k) + ["*"] * (5 - len(k))
579 print("Working on rejection input: %s" % (res_list))
580
581 for n in range(len(res_list)):
582
583 res_list[n] = [res_list[n]] if res_list[n] != "*" \
584 else sorted_default_lst[n]
585
586 # Generate a configuration and a name for the completed array
587 rj_cfg = TFM_Build_Manager.generate_config_list(
588 dict(zip(tags, res_list)),
589 static_config)
590
591 # Append the configuration to the existing ones
Dean Birchf6aa3da2020-01-24 12:29:38 +0000592 rejection_cfg = dict(rejection_cfg, **rj_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100593
594 # Notfy the user for the rejected configuations
595 for i in rejection_cfg.keys():
596 print("Rejecting config %s" % i)
597 else:
598 print("Not information for project type: %s."
599 " Please check config" % static_config["config_type"])
600 return rejection_cfg