20
20
import json
21
21
import os
22
22
from os .path import join as path_join
23
+ from six import integer_types , string_types
23
24
24
25
from jinja2 import Environment , FileSystemLoader , StrictUndefined
25
26
from jsonschema import validate
27
+
26
28
__version__ = '1.0'
27
29
SCRIPT_DIR = os .path .dirname (os .path .abspath (__file__ ))
28
30
TEMPLATES_DIR = path_join (SCRIPT_DIR , 'templates' )
29
- MANIFEST_TEMPLATES = filter (
30
- lambda filename : '_NAME_' in filename ,
31
- [ os . path . join ( dp , f ) for dp , dn , fn in os .walk (TEMPLATES_DIR ) for f in fn if f .endswith ('.tpl' )]
32
- )
33
- COMMON_TEMPLATES = filter (
34
- lambda filename : '_NAME_' not in filename ,
35
- [ os . path . join ( dp , f ) for dp , dn , fn in os .walk (TEMPLATES_DIR ) for f in fn if f .endswith ('.tpl' )]
36
- )
31
+ MANIFEST_TEMPLATES = [ filename for filename in
32
+ [ os . path . join ( dp , f ) for dp , dn , fn in
33
+ os .walk (TEMPLATES_DIR ) for f in fn if f .endswith ('.tpl' )]
34
+ if '_NAME_' in filename ]
35
+ COMMON_TEMPLATES = [ filename for filename in
36
+ [ os . path . join ( dp , f ) for dp , dn , fn in
37
+ os .walk (TEMPLATES_DIR ) for f in fn if f .endswith ('.tpl' )]
38
+ if '_NAME_' not in filename ]
37
39
MANIFEST_FILE_PATTERN = '*_psa.json'
38
40
MBED_OS_ROOT = os .path .abspath (path_join (SCRIPT_DIR , os .pardir , os .pardir ))
39
41
SPM_CORE_ROOT = path_join (MBED_OS_ROOT , 'components' , 'TARGET_PSA' , 'spm' )
@@ -169,7 +171,7 @@ def __init__(self, line_num, signal):
169
171
:param signal: IRQ line identifier inside the partition
170
172
"""
171
173
self .line_num = assert_int (line_num )
172
- assert isinstance (signal , basestring )
174
+ assert isinstance (signal , string_types )
173
175
self .signal = signal
174
176
175
177
def __eq__ (self , other ):
@@ -242,10 +244,10 @@ def __init__(
242
244
irqs = [] if irqs is None else irqs
243
245
244
246
assert os .path .isfile (manifest_file )
245
- assert isinstance (partition_id , ( int , long ) )
247
+ assert isinstance (partition_id , integer_types )
246
248
assert isinstance (heap_size , int )
247
249
assert isinstance (stack_size , int )
248
- assert isinstance (entry_point , basestring )
250
+ assert isinstance (entry_point , string_types )
249
251
assert partition_type in self .PARTITION_TYPES
250
252
assert partition_id > 0
251
253
@@ -277,7 +279,7 @@ def __init__(
277
279
assert isinstance (rot_srv , RotService )
278
280
279
281
for extern_sid in self .extern_sids :
280
- assert isinstance (extern_sid , basestring )
282
+ assert isinstance (extern_sid , string_types )
281
283
282
284
assert len (self .extern_sids ) == len (set (self .extern_sids )), \
283
285
'Detected duplicates external SIDs in {}' .format (self .file )
@@ -341,7 +343,8 @@ def from_json(cls, manifest_file, skip_src=False):
341
343
342
344
mmio_regions = []
343
345
for mmio_region in manifest .get ('mmio_regions' , []):
344
- mmio_regions .append (MmioRegion (partition_id = manifest ['id' ], ** mmio_region ))
346
+ mmio_regions .append (
347
+ MmioRegion (partition_id = manifest ['id' ], ** mmio_region ))
345
348
346
349
rot_services = []
347
350
for rot_srv in manifest .get ('services' , []):
@@ -385,7 +388,7 @@ def find_dependencies(self, manifests):
385
388
extern Root of Trust Services
386
389
"""
387
390
388
- manifests = filter ( lambda man : man != self , manifests )
391
+ manifests = [ man for man in manifests if man != self ]
389
392
extern_sids_set = set (self .extern_sids )
390
393
return [manifest .name for manifest in manifests
391
394
if extern_sids_set .intersection (set (manifest .sids ))]
@@ -414,9 +417,12 @@ def templates_to_files(self, templates, templates_base, output_dir):
414
417
415
418
def check_circular_call_dependencies (manifests ):
416
419
"""
417
- Check if there is a circular dependency between the partitions described by the manifests.
418
- A circular dependency might happen if there is a scenario in which a partition calls a Root of Trust Service in
419
- another partition which than calls another Root of Trust Service which resides in the originating partition.
420
+ Check if there is a circular dependency between the partitions
421
+ described by the manifests.
422
+ A circular dependency might happen if there is a scenario in which a
423
+ partition calls a Root of Trust Service in another partition which than
424
+ calls another Root of Trust Service which resides in the
425
+ originating partition.
420
426
For example: Partition A has a Root of Trust Service A1 and extern sid B1,
421
427
partition B has a Root of Trust Service B1 and extern sid A1.
422
428
@@ -439,8 +445,8 @@ def check_circular_call_dependencies(manifests):
439
445
while len (call_graph ) > 0 :
440
446
# Find all the nodes that aren't called by anyone and
441
447
# therefore can be removed.
442
- nodes_to_remove = filter ( lambda x : len (call_graph [ x ][ 'called_by' ]) == 0 ,
443
- call_graph . keys ())
448
+ nodes_to_remove = [ x for x in list (call_graph . keys ()) if
449
+ len ( call_graph [ x ][ 'called_by' ]) == 0 ]
444
450
445
451
# If no node can be removed we have a circle.
446
452
if not nodes_to_remove :
@@ -683,23 +689,26 @@ def generate_partitions_sources(manifest_files, extra_filters=None):
683
689
return list (generated_folders )
684
690
685
691
686
- def generate_psa_setup (manifest_files , output_dir , weak_setup , extra_filters = None ):
692
+ def generate_psa_setup (manifest_files , output_dir , weak_setup ,
693
+ extra_filters = None ):
687
694
"""
688
695
Process all the given manifest files and generate C setup code from them
689
696
:param manifest_files: List of manifest files
690
697
:param output_dir: Output directory for the generated files
691
- :param weak_setup: Is the functions/data in the setup file weak (can be overridden by another setup file)
698
+ :param weak_setup: Is the functions/data in the setup file weak
699
+ (can be overridden by another setup file)
692
700
:param extra_filters: Dictionary of extra filters to use in the rendering
693
701
process
694
702
:return: path to the setup generated files
695
703
"""
696
704
autogen_folder = output_dir
697
705
templates_dict = {
698
- t : path_join (autogen_folder , os .path .relpath (os .path .splitext (t )[0 ], TEMPLATES_DIR ))
706
+ t : path_join (autogen_folder ,
707
+ os .path .relpath (os .path .splitext (t )[0 ], TEMPLATES_DIR ))
699
708
for t in COMMON_TEMPLATES
700
709
}
701
710
702
- complete_source_list = templates_dict .values ()
711
+ complete_source_list = list ( templates_dict .values () )
703
712
704
713
# Construct lists of all the manifests and mmio_regions.
705
714
region_list = []
@@ -710,10 +719,10 @@ def generate_psa_setup(manifest_files, output_dir, weak_setup, extra_filters=Non
710
719
for region in manifest_obj .mmio_regions :
711
720
region_list .append (region )
712
721
complete_source_list .extend (
713
- manifest_obj .templates_to_files (
722
+ list ( manifest_obj .templates_to_files (
714
723
MANIFEST_TEMPLATES ,
715
724
TEMPLATES_DIR ,
716
- manifest_obj .autogen_folder ).values ()
725
+ manifest_obj .autogen_folder ).values ())
717
726
)
718
727
719
728
# Validate the correctness of the manifest collection.
@@ -739,7 +748,9 @@ def manifests_discovery(root_dir):
739
748
manifest_files = set ()
740
749
741
750
for root , dirs , files in os .walk (root_dir ):
742
- to_add = [path_join (root , f ) for f in fnmatch .filter (files , MANIFEST_FILE_PATTERN ) if 'TARGET_IGNORE' not in root ]
751
+ to_add = [path_join (root , f ) for f in
752
+ fnmatch .filter (files , MANIFEST_FILE_PATTERN ) if
753
+ 'TARGET_IGNORE' not in root ]
743
754
manifest_files .update (to_add )
744
755
745
756
return list (manifest_files )
@@ -752,22 +763,29 @@ def generate_psa_code():
752
763
# Generate partition code for each manifest file
753
764
generate_partitions_sources (manifest_files )
754
765
755
- test_manifest_files = sorted ([path for path in manifest_files if 'TESTS' in path ])
756
- system_manifest_files = sorted (list (set (manifest_files ) - set (test_manifest_files )))
766
+ test_manifest_files = sorted (
767
+ [path for path in manifest_files if 'TESTS' in path ])
768
+ system_manifest_files = sorted (
769
+ list (set (manifest_files ) - set (test_manifest_files )))
757
770
758
771
# Generate default system psa setup file (only system partitions)
759
772
generate_psa_setup (system_manifest_files , SPM_CORE_ROOT , weak_setup = True )
760
773
761
- tests_dir_content = [path_join (SPM_TESTS_ROOT , f ) for f in os .listdir (SPM_TESTS_ROOT )]
774
+ tests_dir_content = [path_join (SPM_TESTS_ROOT , f ) for f in
775
+ os .listdir (SPM_TESTS_ROOT )]
762
776
spm_tests = [path for path in tests_dir_content if os .path .isdir (path )]
763
777
764
- # Build a dictionary for test partition in the form of { test_root: manifest_list }
778
+ # Build a dictionary for test partition in the form of:
779
+ # { test_root: manifest_list }
765
780
# For each test generate specific psa setup file (system + test partitions)
766
781
tests_dict = {test_root : [] for test_root in spm_tests }
767
782
for test_root in spm_tests :
768
- tests_dict [test_root ] = filter (lambda manifest_path : test_root in manifest_path , test_manifest_files )
783
+ tests_dict [test_root ] = [manifest_path for manifest_path in
784
+ test_manifest_files if
785
+ test_root in manifest_path ]
769
786
tests_dict [test_root ] += system_manifest_files
770
- generate_psa_setup (sorted (tests_dict [test_root ]), test_root , weak_setup = False )
787
+ generate_psa_setup (sorted (tests_dict [test_root ]), test_root ,
788
+ weak_setup = False )
771
789
772
790
773
791
if __name__ == '__main__' :
0 commit comments