Skip to content

Commit 7b44834

Browse files
author
Oren Cohen
committed
Secure binaries release script
This script will find all the PSA targets and compile their secure binaries Including test secure binaries
1 parent 5c24ffe commit 7b44834

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

tools/psa/release.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/python
2+
# Copyright (c) 2017-2018 ARM Limited
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
import os
19+
import subprocess
20+
import sys
21+
import shutil
22+
23+
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
24+
sys.path.insert(0, ROOT)
25+
from tools.targets import Target, TARGET_MAP, TARGET_NAMES
26+
27+
MAKE_PY_LOCATTION = os.path.join(ROOT, 'tools', 'make.py')
28+
TEST_PY_LOCATTION = os.path.join(ROOT, 'tools', 'test.py')
29+
MBED_PSA_TESTS = '*psa-spm*,*psa-crypto_access_control'
30+
TFM_MBED_APP = os.path.join(ROOT, 'tools', 'psa', 'tfm', 'mbed_app.json')
31+
TFM_TESTS = {
32+
'*psa-spm_smoke': ['USE_PSA_TEST_PARTITIONS', 'USE_SMOKE_TESTS_PART1'],
33+
'*psa-spm_client': ['USE_PSA_TEST_PARTITIONS', 'USE_CLIENT_TESTS_PART1'],
34+
'*psa-spm_server': ['USE_PSA_TEST_PARTITIONS', 'USE_SERVER_TESTS_PART1', 'USE_SERVER_TESTS_PART2'],
35+
'*psa-crypto_access_control': ['USE_PSA_TEST_PARTITIONS', 'USE_CRYPTO_ACL_TEST']
36+
}
37+
38+
39+
def _psa_backend(target_name):
40+
return 'TFM' if 'TFM' in Target.get_target(target_name).labels else 'MBED_SPM'
41+
42+
43+
def get_mbed_official_psa_release():
44+
psa_targets_release_dict = {
45+
'TFM': [],
46+
'MBED_SPM': []
47+
}
48+
49+
psa_secure_targets = [t for t in TARGET_NAMES if Target.get_target(t).is_PSA_secure_target]
50+
for t in psa_secure_targets:
51+
psa_targets_release_dict[_psa_backend(t)].append(
52+
tuple(
53+
[
54+
TARGET_MAP[t].name,
55+
TARGET_MAP[t].default_toolchain
56+
]
57+
)
58+
)
59+
60+
return psa_targets_release_dict
61+
62+
63+
def create_mbed_ignore(build_dir):
64+
with open(os.path.join(build_dir, '.mbedignore'), 'w') as f:
65+
f.write('*\n')
66+
67+
68+
def build_mbed_spm_platform(target, toolchain):
69+
subprocess.call([
70+
sys.executable, '-u', TEST_PY_LOCATTION,
71+
'--greentea',
72+
'--profile', 'debug',
73+
'-t', toolchain,
74+
'-m', target,
75+
'--source', ROOT,
76+
'--build', os.path.join(ROOT, 'BUILD', 'tests', target),
77+
'--test-spec', os.path.join(ROOT, 'BUILD', 'tests', target, 'test_spec.json'),
78+
'--build-data', os.path.join(ROOT, 'BUILD', 'tests', target, 'build_data.json'),
79+
'-n', MBED_PSA_TESTS
80+
])
81+
82+
subprocess.call([
83+
sys.executable, '-u', MAKE_PY_LOCATTION,
84+
'-t', toolchain,
85+
'-m', target,
86+
'--profile', 'release',
87+
'--source', ROOT,
88+
'--build', os.path.join(ROOT, 'BUILD', target),
89+
'--artifact-name', 'psa_release_1.0'
90+
])
91+
92+
93+
def _tfm_test_defines(test):
94+
return ['-D{}'.format(define) for define in TFM_TESTS[test]]
95+
96+
97+
def build_tfm_platform(target, toolchain):
98+
for test in TFM_TESTS.keys():
99+
subprocess.call([
100+
sys.executable, '-u', TEST_PY_LOCATTION,
101+
'--greentea',
102+
'--profile', 'debug',
103+
'-t', toolchain,
104+
'-m', target,
105+
'--source', ROOT,
106+
'--build', os.path.join(ROOT, 'BUILD', 'tests', target),
107+
'--test-spec', os.path.join(ROOT, 'BUILD', 'tests', target, 'test_spec.json'),
108+
'--build-data', os.path.join(ROOT, 'BUILD', 'tests', target, 'build_data.json'),
109+
'--app-config', TFM_MBED_APP, '-n', test] + _tfm_test_defines(test))
110+
111+
subprocess.call([
112+
sys.executable, '-u', MAKE_PY_LOCATTION,
113+
'-t', toolchain,
114+
'-m', target,
115+
'--profile', 'release',
116+
'--source', ROOT,
117+
'--build', os.path.join(ROOT, 'BUILD', target),
118+
'--app-config', TFM_MBED_APP
119+
])
120+
121+
122+
def main():
123+
build_dir = os.path.join(ROOT, 'BUILD')
124+
if os.path.exists(build_dir):
125+
shutil.rmtree(build_dir)
126+
127+
os.makedirs(build_dir)
128+
create_mbed_ignore(build_dir)
129+
130+
psa_platforms_dict = get_mbed_official_psa_release()
131+
for target, toolchain in psa_platforms_dict['MBED_SPM']:
132+
build_mbed_spm_platform(target, toolchain)
133+
134+
for target, toolchain in psa_platforms_dict['TFM']:
135+
build_tfm_platform(target, toolchain)
136+
137+
138+
if __name__ == '__main__':
139+
main()

0 commit comments

Comments
 (0)