mirror of https://github.com/ARMmbed/mbed-os.git
Update PSA code generator
Unify TF-M and Mbed-SPM code generators: - Unify SPM initialization logic: - All partitions are registered at once - Test partitions are guarded by #ifndef - Introduce single template list - Beatify template files and add "Autogen-do not modify" notice Prepare for integration with mbed-os build system: - Generate all the files in a single place Simplify tools/psa/release.py scriptpull/10447/head
parent
ab01bea46d
commit
8c5ba9154d
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2019 ARM Limited
|
/* Copyright (c) 2017-2018 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
@ -15,68 +15,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*********** WARNING: This is an auto-generated file. Do not edit! ***********/
|
#ifndef __SID_H__
|
||||||
|
#define __SID_H__
|
||||||
|
|
||||||
/******** ATTEST_SRV ********/
|
#include "autogen_sid.h"
|
||||||
#define PSA_ATTEST_GET_TOKEN_ID 0x00000F10
|
|
||||||
#define PSA_ATTEST_GET_TOKEN_SIZE_ID 0x00000F11
|
|
||||||
#define PSA_ATTEST_INJECT_KEY_ID 0x00000F12
|
|
||||||
|
|
||||||
/******** CRYPTO_SRV ********/
|
|
||||||
#define PSA_CRYPTO_INIT_ID 0x00000F00
|
|
||||||
#define PSA_MAC_ID 0x00000F01
|
|
||||||
#define PSA_HASH_ID 0x00000F02
|
|
||||||
#define PSA_ASYMMETRIC_ID 0x00000F03
|
|
||||||
#define PSA_SYMMETRIC_ID 0x00000F04
|
|
||||||
#define PSA_AEAD_ID 0x00000F05
|
|
||||||
#define PSA_KEY_MNG_ID 0x00000F06
|
|
||||||
#define PSA_RNG_ID 0x00000F07
|
|
||||||
#define PSA_CRYPTO_FREE_ID 0x00000F08
|
|
||||||
#define PSA_GENERATOR_ID 0x00000F09
|
|
||||||
#define PSA_ENTROPY_ID 0x00000F0A
|
|
||||||
|
|
||||||
/******** PLATFORM ********/
|
|
||||||
#define PSA_PLATFORM_LC_GET 0x00011000
|
|
||||||
#define PSA_PLATFORM_LC_SET 0x00011001
|
|
||||||
#define PSA_PLATFORM_SYSTEM_RESET 0x00011002
|
|
||||||
|
|
||||||
/******** ITS ********/
|
|
||||||
#define PSA_ITS_GET 0x00011A00
|
|
||||||
#define PSA_ITS_SET 0x00011A01
|
|
||||||
#define PSA_ITS_INFO 0x00011A02
|
|
||||||
#define PSA_ITS_REMOVE 0x00011A03
|
|
||||||
#define PSA_ITS_RESET 0x00011A04
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******** CRYPTO_ACL_TEST ********/
|
|
||||||
#define CRYPTO_CREATE_PERSISTENT_KEY 0x00000200
|
|
||||||
#define CRYPTO_GENERATE_KEY 0x00000201
|
|
||||||
#define CRYPTO_OPEN_PERSISTENT_KEY 0x00000202
|
|
||||||
#define CRYPTO_CLOSE_KEY 0x00000203
|
|
||||||
#define CRYPTO_SET_KEY_POLICY 0x00000204
|
|
||||||
#define CRYPTO_DESTROY_KEY 0x00000205
|
|
||||||
#define CRYPTO_GET_KEY_INFO 0x00000206
|
|
||||||
#define CRYPTO_GET_KEY_POLICY 0x00000207
|
|
||||||
#define CRYPTO_IMPORT_KEY 0x00000208
|
|
||||||
|
|
||||||
|
|
||||||
/******** CLIENT_TESTS_PART1 ********/
|
|
||||||
#define CLIENT_TESTS_PART1_ROT_SRV1 0x00001A05
|
|
||||||
#define CLIENT_TESTS_PART1_DROP_CONN 0x00001A06
|
|
||||||
#define CLIENT_TESTS_PART1_SECURE_CLIENTS_ONLY 0x00001A07
|
|
||||||
|
|
||||||
|
|
||||||
/******** SERVER_TESTS_PART1 ********/
|
|
||||||
#define SERVER_TESTS_PART1_CONTROL 0x00001A01
|
|
||||||
#define SERVER_TESTS_PART1_TEST 0x00001A02
|
|
||||||
|
|
||||||
|
|
||||||
/******** SERVER_TESTS_PART2 ********/
|
|
||||||
#define SERVER_TESTS_PART2_ROT_SRV_REVERSE 0x00001A03
|
|
||||||
#define SERVER_TESTS_PART2_ROT_SRV_DB_TST 0x00001A04
|
|
||||||
|
|
||||||
|
|
||||||
/******** SMOKE_TESTS_PART1 ********/
|
|
||||||
#define SMOKE_TESTS_PART1_ROT_SRV1 0x00001A00
|
|
||||||
|
|
||||||
|
#endif // __SID_H__
|
||||||
|
|
|
||||||
|
|
@ -15,31 +15,65 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from os.path import basename, splitext
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
from tools.resources import FileType
|
from tools.resources import FileType
|
||||||
|
from tools.settings import ROOT
|
||||||
|
from .generate_partition_code import manifests_discovery, generate_spm_code
|
||||||
|
|
||||||
|
|
||||||
def find_secure_image(notify, resources, ns_image_path, configured_s_image_filename, image_type):
|
|
||||||
|
def find_secure_image(notify, resources, ns_image_path,
|
||||||
|
configured_s_image_filename, image_type):
|
||||||
""" Find secure image. """
|
""" Find secure image. """
|
||||||
if configured_s_image_filename is None:
|
if configured_s_image_filename is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
assert ns_image_path and configured_s_image_filename, 'ns_image_path and configured_s_image_path are mandatory'
|
assert ns_image_path and configured_s_image_filename, \
|
||||||
assert image_type in [FileType.BIN, FileType.HEX], 'image_type must be of type BIN or HEX'
|
'ns_image_path and configured_s_image_path are mandatory'
|
||||||
|
assert image_type in [FileType.BIN, FileType.HEX], \
|
||||||
|
'image_type must be of type BIN or HEX'
|
||||||
|
|
||||||
image_files = resources.get_file_paths(image_type)
|
image_files = resources.get_file_paths(image_type)
|
||||||
assert image_files, 'No image files found for this target'
|
assert image_files, 'No image files found for this target'
|
||||||
|
|
||||||
secure_image = next((f for f in image_files if basename(f) == configured_s_image_filename), None)
|
|
||||||
secure_image = next(
|
secure_image = next(
|
||||||
(f for f in image_files if splitext(basename(f))[0] == splitext(basename(ns_image_path))[0]),
|
(f for f in image_files if
|
||||||
|
os.path.basename(f) == configured_s_image_filename), None)
|
||||||
|
secure_image = next(
|
||||||
|
(f for f in image_files if
|
||||||
|
os.path.splitext(os.path.basename(f))[0] ==
|
||||||
|
os.path.splitext(os.path.basename(ns_image_path))[0]),
|
||||||
secure_image
|
secure_image
|
||||||
)
|
)
|
||||||
|
|
||||||
if secure_image:
|
if secure_image:
|
||||||
notify.debug("Secure image file found: %s." % secure_image)
|
notify.debug("Secure image file found: %s." % secure_image)
|
||||||
else:
|
else:
|
||||||
notify.debug("Secure image file %s not found. Aborting." % configured_s_image_filename)
|
notify.debug("Secure image file %s not found. Aborting."
|
||||||
|
% configured_s_image_filename)
|
||||||
raise Exception("Required secure image not found.")
|
raise Exception("Required secure image not found.")
|
||||||
|
|
||||||
return secure_image
|
return secure_image
|
||||||
|
|
||||||
|
|
||||||
|
def _get_psa_autogen_dir():
|
||||||
|
return os.path.join(ROOT, 'PSA_AUTOGEN')
|
||||||
|
|
||||||
|
|
||||||
|
def clean_psa_autogen():
|
||||||
|
psa_out_dir = _get_psa_autogen_dir()
|
||||||
|
|
||||||
|
if os.path.isdir(psa_out_dir):
|
||||||
|
shutil.rmtree(psa_out_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_psa_sources(source_dirs, ignore_paths):
|
||||||
|
services, apps = manifests_discovery(root_dirs=source_dirs,
|
||||||
|
ignore_paths=ignore_paths + ['.git'])
|
||||||
|
assert len(services + apps), 'PSA manifest discovery failed'
|
||||||
|
psa_out_dir = _get_psa_autogen_dir()
|
||||||
|
|
||||||
|
generate_spm_code(services, apps, psa_out_dir)
|
||||||
|
return psa_out_dir
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
import argparse
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
@ -27,149 +27,102 @@ sys.path.insert(0, ROOT)
|
||||||
|
|
||||||
from tools.psa.mbed_spm_tfm_common import validate_partition_manifests, \
|
from tools.psa.mbed_spm_tfm_common import validate_partition_manifests, \
|
||||||
manifests_discovery, parse_manifests, generate_source_files, \
|
manifests_discovery, parse_manifests, generate_source_files, \
|
||||||
MBED_OS_ROOT, SERVICES_DIR, TESTS_DIR
|
MBED_OS_ROOT
|
||||||
|
|
||||||
__version__ = '1.0'
|
__version__ = '1.1'
|
||||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
MANIFEST_FILE_PATTERN = '*_psa.json'
|
MANIFEST_FILE_PATTERN = '*_psa.json'
|
||||||
PSA_CORE_ROOT = path_join(MBED_OS_ROOT, 'components', 'TARGET_PSA')
|
PSA_CORE_ROOT = path_join(MBED_OS_ROOT, 'components', 'TARGET_PSA')
|
||||||
TFM_TEMPLATES_DESC = path_join(SCRIPT_DIR, 'tfm', 'tfm_generated_file_list.json')
|
TEMPLATES_DESC = path_join(SCRIPT_DIR, 'spm_template_file_list.json')
|
||||||
MBED_SPM_TEMPLATES_DESC = path_join(SCRIPT_DIR, 'mbed_spm', 'mbed_spm_generated_file_list.json')
|
|
||||||
MBED_SPM_TEMPLATES_DIR = path_join(SCRIPT_DIR, 'mbed_spm', 'templates')
|
|
||||||
|
|
||||||
|
|
||||||
def generate_partitions_sources(manifest_files, extra_filters=None):
|
def _get_timestamp(f):
|
||||||
"""
|
return os.path.getmtime(f) if os.path.isfile(f) else 0
|
||||||
Process all the given manifest files and generate C code from them
|
|
||||||
|
|
||||||
:param manifest_files: List of manifest files
|
|
||||||
:param extra_filters: Dictionary of extra filters to use in the rendering
|
|
||||||
process
|
|
||||||
:return: List of paths to the generated files
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Construct a list of all the manifests and sids.
|
|
||||||
manifests, _ = parse_manifests(manifest_files, 'MBED_SPM')
|
|
||||||
|
|
||||||
with open(MBED_SPM_TEMPLATES_DESC, 'r') as fh:
|
|
||||||
template_data = json.load(fh)
|
|
||||||
manifest_template_list = [path_join(MBED_OS_ROOT, t['template'])
|
|
||||||
for t in template_data['partition']]
|
|
||||||
|
|
||||||
generated_folders = set()
|
|
||||||
for manifest in manifests:
|
|
||||||
manifest_output_folder = manifest.autogen_folder
|
|
||||||
render_args = {
|
|
||||||
'partition': manifest,
|
|
||||||
'dependent_partitions': manifest.find_dependencies(manifests),
|
|
||||||
'script_ver': __version__
|
|
||||||
}
|
|
||||||
|
|
||||||
manifest_output_folder = generate_source_files(
|
|
||||||
manifest.templates_to_files(manifest_template_list,
|
|
||||||
MBED_SPM_TEMPLATES_DIR,
|
|
||||||
manifest_output_folder),
|
|
||||||
render_args,
|
|
||||||
manifest_output_folder,
|
|
||||||
extra_filters=extra_filters
|
|
||||||
)
|
|
||||||
|
|
||||||
generated_folders.add(manifest_output_folder)
|
|
||||||
|
|
||||||
return list(generated_folders)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_psa_setup(manifest_files, output_dir, weak_setup, extra_filters=None):
|
def is_up_to_date(manifest_files, out_files):
|
||||||
"""
|
manifest_timestamp = max(_get_timestamp(f) for f in manifest_files)
|
||||||
Process all the given manifest files and generate C setup code from them
|
out_timestamps = min(_get_timestamp(f) for f in out_files)
|
||||||
:param manifest_files: List of manifest files
|
return manifest_timestamp <= out_timestamps
|
||||||
:param output_dir: Output directory for the generated files
|
|
||||||
:param weak_setup: Is the functions/data in the setup file weak
|
|
||||||
(can be overridden by another setup file)
|
def generate_spm_code(service_files, app_files, output_dir):
|
||||||
:param extra_filters: Dictionary of extra filters to use in the rendering
|
with open(TEMPLATES_DESC, 'r') as fh:
|
||||||
process
|
templates_data = json.load(fh)
|
||||||
:return: path to the setup generated files
|
|
||||||
"""
|
|
||||||
with open(MBED_SPM_TEMPLATES_DESC, 'r') as fh:
|
|
||||||
template_data = json.load(fh)
|
|
||||||
templates_dict = {
|
templates_dict = {
|
||||||
path_join(MBED_OS_ROOT, t['template']):
|
path_join(MBED_OS_ROOT, t['template']):
|
||||||
path_join(output_dir, t['target'])
|
path_join(output_dir, t['output']) for t in templates_data
|
||||||
for t in template_data['common']
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_up_to_date(service_files + app_files, list(templates_dict.values())):
|
||||||
|
return
|
||||||
|
|
||||||
# Construct lists of all the manifests and mmio_regions.
|
# Construct lists of all the manifests and mmio_regions.
|
||||||
manifests, region_list = parse_manifests(manifest_files, 'MBED_SPM')
|
service_manifests, service_region_list = parse_manifests(service_files)
|
||||||
|
test_manifests, test_region_list = parse_manifests(app_files)
|
||||||
# Validate the correctness of the manifest collection.
|
|
||||||
validate_partition_manifests(manifests)
|
|
||||||
|
|
||||||
render_args = {
|
|
||||||
'partitions': manifests,
|
|
||||||
'regions': region_list,
|
|
||||||
'region_pair_list': list(itertools.combinations(region_list, 2)),
|
|
||||||
'weak': weak_setup,
|
|
||||||
'script_ver': __version__
|
|
||||||
}
|
|
||||||
|
|
||||||
return generate_source_files(
|
|
||||||
templates_dict,
|
|
||||||
render_args,
|
|
||||||
output_dir,
|
|
||||||
extra_filters=extra_filters
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_psa_code(service_files, test_files):
|
|
||||||
# Generate partition code for each manifest file
|
|
||||||
generate_partitions_sources(service_files + test_files)
|
|
||||||
|
|
||||||
# Generate default system psa setup file (only system partitions)
|
|
||||||
generate_psa_setup(service_files, PSA_CORE_ROOT, weak_setup=True)
|
|
||||||
|
|
||||||
tests_dict = {}
|
|
||||||
for test_manifest in test_files:
|
|
||||||
test_dir = os.path.dirname(test_manifest)
|
|
||||||
if test_dir not in tests_dict:
|
|
||||||
tests_dict[test_dir] = [test_manifest]
|
|
||||||
else:
|
|
||||||
tests_dict[test_dir].append(test_manifest)
|
|
||||||
|
|
||||||
for test_dir in tests_dict:
|
|
||||||
generate_psa_setup(service_files + tests_dict[test_dir],
|
|
||||||
test_dir, weak_setup=False)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_tfm_code(service_files, test_files):
|
|
||||||
# Construct lists of all the manifests and mmio_regions.
|
|
||||||
service_manifests, service_region_list = parse_manifests(
|
|
||||||
service_files, 'TFM')
|
|
||||||
test_manifests, test_region_list = parse_manifests(
|
|
||||||
test_files, 'TFM')
|
|
||||||
|
|
||||||
# Validate the correctness of the manifest collection.
|
# Validate the correctness of the manifest collection.
|
||||||
validate_partition_manifests(service_manifests + test_manifests)
|
validate_partition_manifests(service_manifests + test_manifests)
|
||||||
|
|
||||||
|
region_list = service_region_list + test_region_list
|
||||||
|
|
||||||
render_args = {
|
render_args = {
|
||||||
'service_partitions': service_manifests,
|
'service_partitions': service_manifests,
|
||||||
'test_partitions': test_manifests
|
'test_partitions': test_manifests,
|
||||||
|
'script_ver': __version__,
|
||||||
|
'regions': region_list,
|
||||||
|
'region_pair_list': list(itertools.combinations(region_list, 2)),
|
||||||
}
|
}
|
||||||
|
|
||||||
with open(TFM_TEMPLATES_DESC, 'r') as fh:
|
generate_source_files(templates_dict, render_args)
|
||||||
templates_data = json.load(fh)
|
|
||||||
templates_dict = {
|
|
||||||
path_join(MBED_OS_ROOT, t['template']):
|
|
||||||
path_join(MBED_OS_ROOT, t['output']) for t in templates_data
|
|
||||||
}
|
|
||||||
|
|
||||||
generate_source_files(templates_dict, render_args, MBED_OS_ROOT)
|
|
||||||
|
class AppendReadableDir(argparse.Action):
|
||||||
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
|
prosp_dir = os.path.abspath(values)
|
||||||
|
if not os.path.isdir(prosp_dir):
|
||||||
|
raise argparse.ArgumentTypeError("{} is missing".format(prosp_dir))
|
||||||
|
if not os.access(prosp_dir, os.R_OK):
|
||||||
|
raise argparse.ArgumentTypeError(
|
||||||
|
"{} is not a accessible for read".format(prosp_dir))
|
||||||
|
if not getattr(namespace, self.dest):
|
||||||
|
setattr(namespace, self.dest, [])
|
||||||
|
getattr(namespace, self.dest).append(prosp_dir)
|
||||||
|
|
||||||
|
|
||||||
|
def get_parser():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description='PSA SPM code generator',
|
||||||
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-u', '--user-app',
|
||||||
|
action=AppendReadableDir,
|
||||||
|
default=[ROOT],
|
||||||
|
help='Root directory for recursive PSA manifest scan. Use for adding '
|
||||||
|
'application specific secure partitions. Can be supplied more '
|
||||||
|
'than once',
|
||||||
|
metavar='DIR'
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'-o', '--output-dir',
|
||||||
|
default=ROOT,
|
||||||
|
help='Root directory for generating the sources',
|
||||||
|
metavar='DIR'
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
services, _ = manifests_discovery(root_dir=SERVICES_DIR)
|
parser = get_parser()
|
||||||
_, tests = manifests_discovery(root_dir=TESTS_DIR)
|
args = parser.parse_args()
|
||||||
generate_psa_code(services, tests)
|
|
||||||
generate_tfm_code(services, tests)
|
services, apps = manifests_discovery(root_dirs=args.user_app,
|
||||||
|
ignore_paths=['BUILD', '.git'])
|
||||||
|
|
||||||
|
generate_spm_code(services, apps, args.output_dir)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
{
|
|
||||||
"common": [
|
|
||||||
{
|
|
||||||
"name": "mbed-SPM database",
|
|
||||||
"template": "tools/psa/mbed_spm/templates/TARGET_MBED_SPM/COMPONENT_SPE/psa_setup.c.tpl",
|
|
||||||
"target": "TARGET_MBED_SPM/COMPONENT_SPE/psa_setup.c"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"partition": [
|
|
||||||
{
|
|
||||||
"name": "Details partition defines and structures",
|
|
||||||
"template": "tools/psa/mbed_spm/templates/COMPONENT_SPE/psa_NAME_partition.h.tpl",
|
|
||||||
"target": "COMPONENT_SPE/psa_NAME_partition.h"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Details partition structures and init functions",
|
|
||||||
"template": "tools/psa/mbed_spm/templates/TARGET_MBED_SPM/COMPONENT_SPE/psa_NAME_partition.c.tpl",
|
|
||||||
"target": "TARGET_MBED_SPM/COMPONENT_SPE/psa_NAME_partition.c"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Secure Service signals list",
|
|
||||||
"template": "tools/psa/mbed_spm/templates/psa_NAME_ifs.h.tpl",
|
|
||||||
"target": "psa_NAME_ifs.h"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1,144 +0,0 @@
|
||||||
/* Copyright (c) 2017-2019 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/***********************************************************************************************************************
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* Template Version 1.0
|
|
||||||
* Generated by tools/spm/generate_partition_code.py Version {{script_ver}}
|
|
||||||
**********************************************************************************************************************/
|
|
||||||
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "mbed_toolchain.h" /* For using MBED_ALIGN macro */
|
|
||||||
#include "rtx_os.h"
|
|
||||||
#include "spm_panic.h"
|
|
||||||
#include "spm_internal.h"
|
|
||||||
#include "psa_{{partition.name|lower}}_partition.h"
|
|
||||||
#include "psa_manifest/sid.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Threads stacks */
|
|
||||||
MBED_ALIGN(8) uint8_t {{partition.name|lower}}_thread_stack[{{partition.stack_size}}] = {0};
|
|
||||||
|
|
||||||
/* Threads control blocks */
|
|
||||||
osRtxThread_t {{partition.name|lower}}_thread_cb = {0};
|
|
||||||
|
|
||||||
/* Thread attributes - for thread initialization */
|
|
||||||
osThreadAttr_t {{partition.name|lower}}_thread_attr = {
|
|
||||||
.name = "{{partition.name|lower}}",
|
|
||||||
.attr_bits = 0,
|
|
||||||
.cb_mem = &{{partition.name|lower}}_thread_cb,
|
|
||||||
.cb_size = sizeof({{partition.name|lower}}_thread_cb),
|
|
||||||
.stack_mem = {{partition.name|lower}}_thread_stack,
|
|
||||||
.stack_size = {{partition.stack_size}},
|
|
||||||
.priority = {{partition.priority}},
|
|
||||||
.tz_module = 0,
|
|
||||||
.reserved = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
{% if partition.rot_services|count > 0 %}
|
|
||||||
spm_rot_service_t {{partition.name|lower}}_rot_services[{{partition.name|upper}}_ROT_SRV_COUNT] = {
|
|
||||||
{% for rot_srv in partition.rot_services %}
|
|
||||||
{
|
|
||||||
.sid = {{rot_srv.name|upper}},
|
|
||||||
.mask = {{rot_srv.signal|upper}},
|
|
||||||
.partition = NULL,
|
|
||||||
.min_version = {{rot_srv.minor_version}},
|
|
||||||
.min_version_policy = PSA_MINOR_VERSION_POLICY_{{rot_srv.minor_policy|upper}},
|
|
||||||
{% if rot_srv.nspe_callable %}
|
|
||||||
.allow_nspe = true,
|
|
||||||
{% else %}
|
|
||||||
.allow_nspe = false,
|
|
||||||
{% endif %}
|
|
||||||
.queue = {
|
|
||||||
.head = NULL,
|
|
||||||
.tail = NULL
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{% endfor %}
|
|
||||||
};
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if partition.extern_sids|count > 0 %}
|
|
||||||
/* External SIDs used by {{partition.name}} */
|
|
||||||
const uint32_t {{partition.name|lower}}_external_sids[{{partition.extern_sids|count}}] = {
|
|
||||||
{% for sid in partition.extern_sids %}
|
|
||||||
{{sid|upper}},
|
|
||||||
{% endfor %}
|
|
||||||
};
|
|
||||||
{% endif %}
|
|
||||||
{% for rot_srv in partition.rot_services %}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
static osRtxMutex_t {{partition.name|lower}}_mutex = {0};
|
|
||||||
static const osMutexAttr_t {{partition.name|lower}}_mutex_attr = {
|
|
||||||
.name = "{{partition.name|lower}}_mutex",
|
|
||||||
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
|
|
||||||
.cb_mem = &{{partition.name|lower}}_mutex,
|
|
||||||
.cb_size = sizeof({{partition.name|lower}}_mutex),
|
|
||||||
};
|
|
||||||
|
|
||||||
{% if partition.irqs|count > 0 %}
|
|
||||||
// Mapper function from irq signal to interupts number
|
|
||||||
IRQn_Type spm_{{partition.name|lower}}_signal_to_irq_mapper(uint32_t signal)
|
|
||||||
{
|
|
||||||
SPM_ASSERT({{partition.name|upper}}_WAIT_ANY_IRQ_MSK & signal);
|
|
||||||
switch(signal){
|
|
||||||
{% for irq in partition.irqs %}
|
|
||||||
case {{ irq.signal }}:
|
|
||||||
return (IRQn_Type){{irq.line_num}};
|
|
||||||
break;
|
|
||||||
{% endfor %}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
SPM_PANIC("Unknown signal number %lu", signal);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
extern void {{partition.entry_point}}(void *ptr);
|
|
||||||
|
|
||||||
void {{partition.name|lower}}_init(spm_partition_t *partition)
|
|
||||||
{
|
|
||||||
if (NULL == partition) {
|
|
||||||
SPM_PANIC("partition is NULL!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
partition->mutex = osMutexNew(&{{partition.name|lower}}_mutex_attr);
|
|
||||||
if (NULL == partition->mutex) {
|
|
||||||
SPM_PANIC("Failed to create mutex for secure partition {{partition.name|lower}}!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
{% if partition.rot_services|count > 0 %}
|
|
||||||
for (uint32_t i = 0; i < {{partition.name|upper}}_ROT_SRV_COUNT; ++i) {
|
|
||||||
{{partition.name|lower}}_rot_services[i].partition = partition;
|
|
||||||
}
|
|
||||||
partition->rot_services = {{partition.name|lower}}_rot_services;
|
|
||||||
{% else %}
|
|
||||||
partition->rot_services = NULL;
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
partition->thread_id = osThreadNew({{partition.entry_point}}, NULL, &{{partition.name|lower}}_thread_attr);
|
|
||||||
if (NULL == partition->thread_id) {
|
|
||||||
SPM_PANIC("Failed to create start main thread of partition {{partition.name|lower}}!\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{# End of file #}
|
|
||||||
|
|
@ -1,144 +0,0 @@
|
||||||
/* Copyright (c) 2017-2019 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/***********************************************************************************************************************
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
* Template Version 1.0
|
|
||||||
* Generated by tools/spm/generate_partition_code.py Version {{script_ver}}
|
|
||||||
**********************************************************************************************************************/
|
|
||||||
|
|
||||||
#include "spm_panic.h"
|
|
||||||
#include "spm_internal.h"
|
|
||||||
#include "handles_manager.h"
|
|
||||||
#include "cmsis.h"
|
|
||||||
{% for partition in partitions %}
|
|
||||||
#include "psa_{{partition.name|lower}}_partition.h"
|
|
||||||
{% endfor %}{# partition in partitions #}
|
|
||||||
|
|
||||||
{% for partition in partitions %}
|
|
||||||
{% if partition.extern_sids|count > 0 %}
|
|
||||||
extern const uint32_t {{partition.name|lower}}_external_sids[{{partition.extern_sids|count}}];
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}{# partition in partitions #}
|
|
||||||
|
|
||||||
{% if partitions|count > 0 %}
|
|
||||||
{% if weak %}
|
|
||||||
__attribute__((weak))
|
|
||||||
{% endif %}
|
|
||||||
spm_partition_t g_partitions[{{partitions|count}}] = {
|
|
||||||
{% for partition in partitions %}
|
|
||||||
{
|
|
||||||
.partition_id = {{partition.name|upper}}_ID,
|
|
||||||
.thread_id = 0,
|
|
||||||
.flags = {{partition.name|upper}}_WAIT_ANY_SID_MSK | {{partition.name|upper}}_WAIT_ANY_IRQ_MSK,
|
|
||||||
.rot_services = NULL,
|
|
||||||
{% if partition.rot_services|count > 0 %}
|
|
||||||
.rot_services_count = {{partition.name|upper}}_ROT_SRV_COUNT,
|
|
||||||
{% else %}
|
|
||||||
.rot_services_count = 0,
|
|
||||||
{% endif %}
|
|
||||||
{% if partition.extern_sids|count > 0 %}
|
|
||||||
.extern_sids = {{partition.name|lower}}_external_sids,
|
|
||||||
{% else %}
|
|
||||||
.extern_sids = NULL,
|
|
||||||
{% endif %}
|
|
||||||
.extern_sids_count = {{partition.name|upper}}_EXT_ROT_SRV_COUNT,
|
|
||||||
{% if partition.irqs|count > 0 %}
|
|
||||||
.irq_mapper = spm_{{partition.name|lower}}_signal_to_irq_mapper,
|
|
||||||
{% else %}
|
|
||||||
.irq_mapper = NULL,
|
|
||||||
{% endif %}
|
|
||||||
},
|
|
||||||
{% endfor %}
|
|
||||||
};
|
|
||||||
{% else %}
|
|
||||||
{% if weak %}
|
|
||||||
__attribute__((weak))
|
|
||||||
{% endif %}
|
|
||||||
spm_partition_t *g_partitions = NULL;
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
/* Check all the defined memory regions for overlapping. */
|
|
||||||
{% for region_pair in region_pair_list %}
|
|
||||||
MBED_STATIC_ASSERT(
|
|
||||||
((uintptr_t)({{region_pair[0].base}}) + {{region_pair[0].size}} - 1 < (uintptr_t)({{region_pair[1].base}})) ||
|
|
||||||
((uintptr_t)({{region_pair[1].base}}) + {{region_pair[1].size}} - 1 < (uintptr_t)({{region_pair[0].base}})),
|
|
||||||
"The region with base {{region_pair[0].base}} and size {{region_pair[0].size}} overlaps with the region with base {{region_pair[1].base}} and size {{region_pair[1].size}}!");
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
/* A list of all the memory regions. */
|
|
||||||
{% if regions|count > 0 %}
|
|
||||||
{% if weak %}
|
|
||||||
__attribute__((weak))
|
|
||||||
{% endif %}
|
|
||||||
const mem_region_t mem_regions[] = {
|
|
||||||
{% for region in regions %}
|
|
||||||
{ (uint32_t)({{region.base}}), {{region.size}}, {{region.permission}}, {{region.partition_id}} },
|
|
||||||
{% endfor %}
|
|
||||||
};
|
|
||||||
{% else %}
|
|
||||||
{% if weak %}
|
|
||||||
__attribute__((weak))
|
|
||||||
{% endif %}
|
|
||||||
const mem_region_t *mem_regions = NULL;
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if weak %}
|
|
||||||
__attribute__((weak))
|
|
||||||
{% endif %}
|
|
||||||
const uint32_t mem_region_count = {{regions|count}};
|
|
||||||
|
|
||||||
// forward declaration of partition initializers
|
|
||||||
{% for partition in partitions %}
|
|
||||||
void {{partition.name|lower}}_init(spm_partition_t *partition);
|
|
||||||
{% endfor %}{# partition in partitions #}
|
|
||||||
|
|
||||||
{% if weak %}
|
|
||||||
__attribute__((weak))
|
|
||||||
{% endif %}
|
|
||||||
uint32_t init_partitions(spm_partition_t **partitions)
|
|
||||||
{
|
|
||||||
if (NULL == partitions) {
|
|
||||||
SPM_PANIC("partitions is NULL!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
{% for partition in partitions %}
|
|
||||||
{{partition.name|lower}}_init(&(g_partitions[{{loop.index0}}]));
|
|
||||||
{% endfor %}{# partition in partitions #}
|
|
||||||
|
|
||||||
*partitions = g_partitions;
|
|
||||||
return {{partitions|count}};
|
|
||||||
}
|
|
||||||
|
|
||||||
{% for partition in partitions %}
|
|
||||||
{% set partition_loop = loop %}
|
|
||||||
{% for irq in partition.irqs %}
|
|
||||||
// ISR handler for interrupt {irq.line_num}
|
|
||||||
void spm_irq_{{irq.signal}}_{{partition.name|lower}}(void)
|
|
||||||
{
|
|
||||||
NVIC_DisableIRQ((IRQn_Type){{irq.line_num}});
|
|
||||||
osThreadFlagsSet(
|
|
||||||
g_partitions[{{ partition_loop.index0 }}].thread_id,
|
|
||||||
{{irq.signal|upper}}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
{% endfor %}
|
|
||||||
{% endfor %}
|
|
||||||
{# End of file #}
|
|
||||||
|
|
@ -183,7 +183,6 @@ class Manifest(object):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
manifest_file,
|
manifest_file,
|
||||||
psa_type,
|
|
||||||
name,
|
name,
|
||||||
partition_id,
|
partition_id,
|
||||||
partition_type,
|
partition_type,
|
||||||
|
|
@ -201,7 +200,6 @@ class Manifest(object):
|
||||||
Manifest C'tor (Aligned with json schema)
|
Manifest C'tor (Aligned with json schema)
|
||||||
|
|
||||||
:param manifest_file: Path to json manifest
|
:param manifest_file: Path to json manifest
|
||||||
:param psa_type: PSA implementation type (TFM/MBED_SPM)
|
|
||||||
:param name: Partition unique name
|
:param name: Partition unique name
|
||||||
:param partition_id: Partition identifier
|
:param partition_id: Partition identifier
|
||||||
:param partition_type: Whether the partition is unprivileged or part
|
:param partition_type: Whether the partition is unprivileged or part
|
||||||
|
|
@ -240,17 +238,14 @@ class Manifest(object):
|
||||||
assert isinstance(entry_point, string_types)
|
assert isinstance(entry_point, string_types)
|
||||||
assert partition_type in self.PARTITION_TYPES
|
assert partition_type in self.PARTITION_TYPES
|
||||||
assert partition_id > 0
|
assert partition_id > 0
|
||||||
assert psa_type in ['TFM', 'MBED_SPM']
|
|
||||||
|
|
||||||
self.file = manifest_file
|
self.file = manifest_file
|
||||||
self.name = name
|
self.name = name
|
||||||
self.psa_type = psa_type
|
|
||||||
self.id = partition_id
|
self.id = partition_id
|
||||||
self.type = partition_type
|
self.type = partition_type
|
||||||
if psa_type == 'TFM':
|
|
||||||
self.priority = priority
|
self.priority_tfm = priority
|
||||||
else:
|
self.priority_mbed = self.PRIORITY[priority]
|
||||||
self.priority = self.PRIORITY[priority]
|
|
||||||
self.heap_size = heap_size
|
self.heap_size = heap_size
|
||||||
self.stack_size = stack_size
|
self.stack_size = stack_size
|
||||||
self.entry_point = entry_point
|
self.entry_point = entry_point
|
||||||
|
|
@ -295,7 +290,8 @@ class Manifest(object):
|
||||||
(self.name == other.name) and
|
(self.name == other.name) and
|
||||||
(self.id == other.id) and
|
(self.id == other.id) and
|
||||||
(self.type == other.type) and
|
(self.type == other.type) and
|
||||||
(self.priority == other.priority) and
|
(self.priority_mbed == other.priority_mbed) and
|
||||||
|
(self.priority_tfm == other.priority_tfm) and
|
||||||
(self.heap_size == other.heap_size) and
|
(self.heap_size == other.heap_size) and
|
||||||
(self.stack_size == other.stack_size) and
|
(self.stack_size == other.stack_size) and
|
||||||
(self.entry_point == other.entry_point) and
|
(self.entry_point == other.entry_point) and
|
||||||
|
|
@ -307,13 +303,12 @@ class Manifest(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, manifest_file, skip_src=False, psa_type='MBED_SPM'):
|
def from_json(cls, manifest_file, skip_src=False):
|
||||||
"""
|
"""
|
||||||
Load a partition manifest file
|
Load a partition manifest file
|
||||||
|
|
||||||
:param manifest_file: Manifest file path
|
:param manifest_file: Manifest file path
|
||||||
:param skip_src: Ignore the `source_files` entry
|
:param skip_src: Ignore the `source_files` entry
|
||||||
:param psa_type: PSA implementation type (TFM/MBED_SPM)
|
|
||||||
:return: Manifest object
|
:return: Manifest object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -352,7 +347,6 @@ class Manifest(object):
|
||||||
|
|
||||||
return Manifest(
|
return Manifest(
|
||||||
manifest_file=manifest_file,
|
manifest_file=manifest_file,
|
||||||
psa_type=psa_type,
|
|
||||||
name=manifest['name'],
|
name=manifest['name'],
|
||||||
partition_id=_assert_int(manifest['id']),
|
partition_id=_assert_int(manifest['id']),
|
||||||
partition_type=manifest['type'],
|
partition_type=manifest['type'],
|
||||||
|
|
@ -599,31 +593,37 @@ def validate_partition_manifests(manifests):
|
||||||
|
|
||||||
|
|
||||||
def is_test_manifest(manifest):
|
def is_test_manifest(manifest):
|
||||||
return 'tests' in manifest
|
return 'TESTS' in manifest
|
||||||
|
|
||||||
|
|
||||||
def is_service_manifest(manifest):
|
def is_service_manifest(manifest):
|
||||||
return not is_test_manifest(manifest)
|
return not is_test_manifest(manifest)
|
||||||
|
|
||||||
|
|
||||||
def manifests_discovery(root_dir=SERVICES_DIR):
|
def manifests_discovery(root_dirs, ignore_paths):
|
||||||
service_manifest_files = set()
|
service_manifest_files = set()
|
||||||
test_manifest_files = set()
|
test_manifest_files = set()
|
||||||
|
for root_dir in root_dirs:
|
||||||
|
for root, dirs, files in os.walk(root_dir, followlinks=True):
|
||||||
|
# Filters paths if they are inside one of the ignore paths
|
||||||
|
if next((True for igp in ignore_paths if igp in root), False):
|
||||||
|
continue
|
||||||
|
|
||||||
for root, dirs, files in os.walk(root_dir):
|
|
||||||
to_add = [path_join(root, f) for f in
|
to_add = [path_join(root, f) for f in
|
||||||
fnmatch.filter(files, MANIFEST_FILE_PATTERN)]
|
fnmatch.filter(files, MANIFEST_FILE_PATTERN)]
|
||||||
service_manifest_files.update(filter(is_service_manifest, to_add))
|
service_manifest_files.update(filter(is_service_manifest, to_add))
|
||||||
test_manifest_files.update(filter(is_test_manifest, to_add))
|
test_manifest_files.update(filter(is_test_manifest, to_add))
|
||||||
|
|
||||||
return sorted(list(service_manifest_files)), sorted(list(test_manifest_files))
|
service_manifest_files = sorted(list(service_manifest_files))
|
||||||
|
test_manifest_files = sorted(list(test_manifest_files))
|
||||||
|
return service_manifest_files, test_manifest_files
|
||||||
|
|
||||||
|
|
||||||
def parse_manifests(manifests_files, psa_type):
|
def parse_manifests(manifests_files):
|
||||||
region_list = []
|
region_list = []
|
||||||
manifests = []
|
manifests = []
|
||||||
for manifest_file in manifests_files:
|
for manifest_file in manifests_files:
|
||||||
manifest_obj = Manifest.from_json(manifest_file, psa_type=psa_type)
|
manifest_obj = Manifest.from_json(manifest_file)
|
||||||
manifests.append(manifest_obj)
|
manifests.append(manifest_obj)
|
||||||
for region in manifest_obj.mmio_regions:
|
for region in manifest_obj.mmio_regions:
|
||||||
region_list.append(region)
|
region_list.append(region)
|
||||||
|
|
@ -634,7 +634,6 @@ def parse_manifests(manifests_files, psa_type):
|
||||||
def generate_source_files(
|
def generate_source_files(
|
||||||
templates,
|
templates,
|
||||||
render_args,
|
render_args,
|
||||||
output_folder,
|
|
||||||
extra_filters=None
|
extra_filters=None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
|
@ -642,7 +641,6 @@ def generate_source_files(
|
||||||
|
|
||||||
:param templates: Dictionary of template and their auto-generated products
|
:param templates: Dictionary of template and their auto-generated products
|
||||||
:param render_args: Dictionary of arguments that should be passed to render
|
:param render_args: Dictionary of arguments that should be passed to render
|
||||||
:param output_folder: Output directory for file generation
|
|
||||||
:param extra_filters: Dictionary of extra filters to use in the rendering
|
:param extra_filters: Dictionary of extra filters to use in the rendering
|
||||||
process
|
process
|
||||||
:return: Path to generated folder containing common generated files
|
:return: Path to generated folder containing common generated files
|
||||||
|
|
@ -672,11 +670,9 @@ def generate_source_files(
|
||||||
if not os.path.exists(rendered_file_dir):
|
if not os.path.exists(rendered_file_dir):
|
||||||
os.makedirs(rendered_file_dir)
|
os.makedirs(rendered_file_dir)
|
||||||
|
|
||||||
if not os.path.exists(output_folder):
|
|
||||||
os.makedirs(output_folder)
|
|
||||||
|
|
||||||
for fname, data in rendered_files:
|
for fname, data in rendered_files:
|
||||||
|
output_folder = os.path.dirname(fname)
|
||||||
|
if not os.path.isdir(output_folder):
|
||||||
|
os.makedirs(output_folder)
|
||||||
with open(fname, 'wt') as fh:
|
with open(fname, 'wt') as fh:
|
||||||
fh.write(data)
|
fh.write(data)
|
||||||
|
|
||||||
return output_folder
|
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,7 @@ subprocess_err = None
|
||||||
MAKE_PY_LOCATTION = os.path.join(ROOT, 'tools', 'make.py')
|
MAKE_PY_LOCATTION = os.path.join(ROOT, 'tools', 'make.py')
|
||||||
TEST_PY_LOCATTION = os.path.join(ROOT, 'tools', 'test.py')
|
TEST_PY_LOCATTION = os.path.join(ROOT, 'tools', 'test.py')
|
||||||
TFM_MBED_APP = os.path.join(ROOT, 'tools', 'psa', 'tfm', 'mbed_app.json')
|
TFM_MBED_APP = os.path.join(ROOT, 'tools', 'psa', 'tfm', 'mbed_app.json')
|
||||||
MBED_PSA_TESTS = '*psa-spm*,*psa-crypto_access_control'
|
PSA_TESTS = {
|
||||||
TFM_TESTS = {
|
|
||||||
'*psa-spm_smoke': ['USE_PSA_TEST_PARTITIONS', 'USE_SMOKE_TESTS_PART1'],
|
'*psa-spm_smoke': ['USE_PSA_TEST_PARTITIONS', 'USE_SMOKE_TESTS_PART1'],
|
||||||
'*psa-spm_client': ['USE_PSA_TEST_PARTITIONS', 'USE_CLIENT_TESTS_PART1'],
|
'*psa-spm_client': ['USE_PSA_TEST_PARTITIONS', 'USE_CLIENT_TESTS_PART1'],
|
||||||
'*psa-spm_server': ['USE_PSA_TEST_PARTITIONS', 'USE_SERVER_TESTS_PART1',
|
'*psa-spm_server': ['USE_PSA_TEST_PARTITIONS', 'USE_SERVER_TESTS_PART1',
|
||||||
|
|
@ -90,33 +89,6 @@ def _get_psa_secure_targets_list():
|
||||||
Target.get_target(t).is_PSA_secure_target]
|
Target.get_target(t).is_PSA_secure_target]
|
||||||
|
|
||||||
|
|
||||||
def _get_default_image_build_command(target, toolchain, profile, args):
|
|
||||||
"""
|
|
||||||
Creates a build command for a default image.
|
|
||||||
|
|
||||||
:param target: target to be built.
|
|
||||||
:param toolchain: toolchain to be used.
|
|
||||||
:param profile: build profile.
|
|
||||||
:param args: list of extra arguments.
|
|
||||||
:return: Build command in a list form.
|
|
||||||
"""
|
|
||||||
cmd = [
|
|
||||||
sys.executable, MAKE_PY_LOCATTION,
|
|
||||||
'-t', toolchain,
|
|
||||||
'-m', target,
|
|
||||||
'--profile', profile,
|
|
||||||
'--source', ROOT,
|
|
||||||
'--build', os.path.join(ROOT, 'BUILD', target)
|
|
||||||
]
|
|
||||||
|
|
||||||
if _psa_backend(target) is 'TFM':
|
|
||||||
cmd += ['--app-config', TFM_MBED_APP]
|
|
||||||
else:
|
|
||||||
cmd += ['--artifact-name', 'psa_release_1.0']
|
|
||||||
|
|
||||||
return cmd + args
|
|
||||||
|
|
||||||
|
|
||||||
def verbose_check_call(cmd, check_call=True):
|
def verbose_check_call(cmd, check_call=True):
|
||||||
"""
|
"""
|
||||||
Calls a shell command and logs the call.
|
Calls a shell command and logs the call.
|
||||||
|
|
@ -161,53 +133,21 @@ def create_mbed_ignore(build_dir):
|
||||||
f.write('*\n')
|
f.write('*\n')
|
||||||
|
|
||||||
|
|
||||||
def build_tests_mbed_spm_platform(target, toolchain, profile, args):
|
def build_tests(target, toolchain, profile, args):
|
||||||
"""
|
"""
|
||||||
Builds Secure images for MBED-SPM target.
|
Builds secure images for tests.
|
||||||
|
|
||||||
:param target: target to be built.
|
:param target: target to be built.
|
||||||
:param toolchain: toolchain to be used.
|
:param toolchain: toolchain to be used.
|
||||||
:param profile: build profile.
|
:param profile: build profile.
|
||||||
:param args: list of extra arguments.
|
:param args: list of extra arguments.
|
||||||
"""
|
"""
|
||||||
logger.info(
|
for test in PSA_TESTS.keys():
|
||||||
"Building tests images({}) for {} using {} with {} profile".format(
|
|
||||||
MBED_PSA_TESTS, target, toolchain, profile))
|
|
||||||
cmd = [
|
|
||||||
sys.executable, TEST_PY_LOCATTION,
|
|
||||||
'--greentea',
|
|
||||||
'--profile', profile,
|
|
||||||
'-t', toolchain,
|
|
||||||
'-m', target,
|
|
||||||
'--source', ROOT,
|
|
||||||
'--build', os.path.join(ROOT, 'BUILD', 'tests', target),
|
|
||||||
'--test-spec', os.path.join(ROOT, 'BUILD', 'tests',
|
|
||||||
target, 'test_spec.json'),
|
|
||||||
'--build-data', os.path.join(ROOT, 'BUILD', 'tests',
|
|
||||||
target, 'build_data.json'),
|
|
||||||
'-n', MBED_PSA_TESTS] + args
|
|
||||||
|
|
||||||
verbose_check_call(cmd)
|
|
||||||
logger.info(
|
|
||||||
"Finished building tests images({}) for {} successfully".format(
|
|
||||||
MBED_PSA_TESTS, target))
|
|
||||||
|
|
||||||
|
|
||||||
def build_tests_tfm_platform(target, toolchain, profile, args):
|
|
||||||
"""
|
|
||||||
Builds Secure images for TF-M target.
|
|
||||||
|
|
||||||
:param target: target to be built.
|
|
||||||
:param toolchain: toolchain to be used.
|
|
||||||
:param profile: build profile.
|
|
||||||
:param args: list of extra arguments.
|
|
||||||
"""
|
|
||||||
for test in TFM_TESTS.keys():
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Building tests image({}) for {} using {} with {} profile".format(
|
"Building tests image({}) for {} using {} with {} profile".format(
|
||||||
test, target, toolchain, profile))
|
test, target, toolchain, profile))
|
||||||
|
|
||||||
test_defines = ['-D{}'.format(define) for define in TFM_TESTS[test]]
|
test_defines = ['-D{}'.format(define) for define in PSA_TESTS[test]]
|
||||||
cmd = [
|
cmd = [
|
||||||
sys.executable, TEST_PY_LOCATTION,
|
sys.executable, TEST_PY_LOCATTION,
|
||||||
'--greentea',
|
'--greentea',
|
||||||
|
|
@ -220,14 +160,46 @@ def build_tests_tfm_platform(target, toolchain, profile, args):
|
||||||
target, 'test_spec.json'),
|
target, 'test_spec.json'),
|
||||||
'--build-data', os.path.join(ROOT, 'BUILD', 'tests',
|
'--build-data', os.path.join(ROOT, 'BUILD', 'tests',
|
||||||
target, 'build_data.json'),
|
target, 'build_data.json'),
|
||||||
'-n', test,
|
'-n', test] + test_defines + args
|
||||||
'--app-config', TFM_MBED_APP] + test_defines + args
|
|
||||||
|
if _psa_backend(target) is 'TFM':
|
||||||
|
cmd += ['--app-config', TFM_MBED_APP]
|
||||||
|
|
||||||
verbose_check_call(cmd)
|
verbose_check_call(cmd)
|
||||||
logger.info(
|
logger.info(
|
||||||
"Finished Building tests image({}) for {}".format(test, target))
|
"Finished Building tests image({}) for {}".format(test, target))
|
||||||
|
|
||||||
|
|
||||||
|
def build_default_image(target, toolchain, profile, args):
|
||||||
|
"""
|
||||||
|
Builds the default secure image.
|
||||||
|
|
||||||
|
:param target: target to be built.
|
||||||
|
:param toolchain: toolchain to be used.
|
||||||
|
:param profile: build profile.
|
||||||
|
:param args: list of extra arguments.
|
||||||
|
"""
|
||||||
|
logger.info("Building default image for {} using {} with {} profile".format(
|
||||||
|
target, toolchain, profile))
|
||||||
|
|
||||||
|
cmd = [
|
||||||
|
sys.executable, MAKE_PY_LOCATTION,
|
||||||
|
'-t', toolchain,
|
||||||
|
'-m', target,
|
||||||
|
'--profile', profile,
|
||||||
|
'--source', ROOT,
|
||||||
|
'--build', os.path.join(ROOT, 'BUILD', target)] + args
|
||||||
|
|
||||||
|
if _psa_backend(target) is 'TFM':
|
||||||
|
cmd += ['--app-config', TFM_MBED_APP]
|
||||||
|
else:
|
||||||
|
cmd += ['--artifact-name', 'psa_release_1.0']
|
||||||
|
|
||||||
|
verbose_check_call(cmd)
|
||||||
|
logger.info(
|
||||||
|
"Finished building default image for {} successfully".format(target))
|
||||||
|
|
||||||
|
|
||||||
def commit_binaries(target, delivery_dir):
|
def commit_binaries(target, delivery_dir):
|
||||||
"""
|
"""
|
||||||
Commits changes in secure binaries.
|
Commits changes in secure binaries.
|
||||||
|
|
@ -276,19 +248,9 @@ def build_psa_platform(target, toolchain, delivery_dir, debug, git_commit,
|
||||||
"""
|
"""
|
||||||
profile = 'debug' if debug else 'release'
|
profile = 'debug' if debug else 'release'
|
||||||
if not skip_tests:
|
if not skip_tests:
|
||||||
if _psa_backend(target) is 'TFM':
|
build_tests(target, toolchain, profile, args)
|
||||||
build_tests_tfm_platform(target, toolchain, profile, args)
|
|
||||||
else:
|
|
||||||
build_tests_mbed_spm_platform(target, toolchain, profile, args)
|
|
||||||
|
|
||||||
logger.info("Building default image for {} using {} with {} profile".format(
|
|
||||||
target, toolchain, profile))
|
|
||||||
|
|
||||||
cmd = _get_default_image_build_command(target, toolchain, profile, args)
|
|
||||||
verbose_check_call(cmd)
|
|
||||||
logger.info(
|
|
||||||
"Finished building default image for {} successfully".format(target))
|
|
||||||
|
|
||||||
|
build_default_image(target, toolchain, profile, args)
|
||||||
if git_commit:
|
if git_commit:
|
||||||
commit_binaries(target, delivery_dir)
|
commit_binaries(target, delivery_dir)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Secure Partition ID definitions",
|
||||||
|
"template": "tools/psa/templates/tfm_partition_defs.inc.tpl",
|
||||||
|
"output": "COMPONENT_SPE/TARGET_TFM/tfm_partition_defs.inc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Secure Partition declarations",
|
||||||
|
"template": "tools/psa/templates/tfm_partition_list.inc.tpl",
|
||||||
|
"output": "COMPONENT_SPE/TARGET_TFM/tfm_partition_list.inc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Secure Service list",
|
||||||
|
"template": "tools/psa/templates/tfm_service_list.inc.tpl",
|
||||||
|
"output": "COMPONENT_SPE/TARGET_TFM/tfm_service_list.inc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Secure Service signals list",
|
||||||
|
"template": "tools/psa/templates/tfm_spm_signal_defs.h.tpl",
|
||||||
|
"output": "COMPONENT_SPE/TARGET_TFM/tfm_spm_signal_defs.h"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "mbed-SPM database",
|
||||||
|
"template": "tools/psa/templates/psa_setup.c.tpl",
|
||||||
|
"output": "COMPONENT_SPE/TARGET_MBED_SPM/psa_setup.c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mappings from RoT Service names to SIDs",
|
||||||
|
"template": "tools/psa/templates/sid.h.tpl",
|
||||||
|
"output": "autogen_sid.h"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Details partition defines and structures",
|
||||||
|
"template": "tools/psa/templates/mbed_spm_partitions.h.tpl",
|
||||||
|
"output": "mbed_spm_partitions.h"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -15,17 +15,22 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***********************************************************************************************************************
|
/*******************************************************************************
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
* Template Version 1.0
|
* Template Version 1.0
|
||||||
* Generated by tools/spm/generate_partition_code.py Version {{script_ver}}
|
* Generated by tools/psa/generate_partition_code.py Version {{script_ver}}
|
||||||
**********************************************************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#ifndef PSA_{{partition.name|upper}}_PARTITION_H
|
#ifndef __MBED_SPM_PARTITIONS_H___
|
||||||
#define PSA_{{partition.name|upper}}_PARTITION_H
|
#define __MBED_SPM_PARTITIONS_H___
|
||||||
|
|
||||||
|
{% macro do_parition(partition) -%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* {{partition.name|upper}} defines
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
#define {{partition.name|upper}}_ID {{partition.id}}
|
#define {{partition.name|upper}}_ID {{partition.id}}
|
||||||
|
|
||||||
{% if partition.rot_services|count > 0 %}
|
{% if partition.rot_services|count > 0 %}
|
||||||
|
|
@ -33,13 +38,6 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
#define {{partition.name|upper}}_EXT_ROT_SRV_COUNT ({{partition.extern_sids|count}}UL)
|
#define {{partition.name|upper}}_EXT_ROT_SRV_COUNT ({{partition.extern_sids|count}}UL)
|
||||||
|
|
||||||
/* {{partition.name}} event flags */
|
|
||||||
#define {{partition.name|upper}}_RESERVED1_POS (1UL)
|
|
||||||
#define {{partition.name|upper}}_RESERVED1_MSK (1UL << {{partition.name|upper}}_RESERVED1_POS)
|
|
||||||
|
|
||||||
#define {{partition.name|upper}}_RESERVED2_POS (2UL)
|
|
||||||
#define {{partition.name|upper}}_RESERVED2_MSK (1UL << {{partition.name|upper}}_RESERVED2_POS)
|
|
||||||
|
|
||||||
{% for irq in partition.irqs %}
|
{% for irq in partition.irqs %}
|
||||||
#define {{irq.signal|upper}}_POS ({{loop.index + 3 }}UL)
|
#define {{irq.signal|upper}}_POS ({{loop.index + 3 }}UL)
|
||||||
#define {{irq.signal|upper}} (1UL << {{irq.signal|upper}}_POS)
|
#define {{irq.signal|upper}} (1UL << {{irq.signal|upper}}_POS)
|
||||||
|
|
@ -71,6 +69,36 @@
|
||||||
{% if partition.irqs|count > 0 %}
|
{% if partition.irqs|count > 0 %}
|
||||||
uint32_t spm_{{partition.name|lower}}_signal_to_irq_mapper(uint32_t signal);
|
uint32_t spm_{{partition.name|lower}}_signal_to_irq_mapper(uint32_t signal);
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{%- endmacro %}
|
||||||
|
{# ------------------ macro do_parition(partition) -------------------------- #}
|
||||||
|
|
||||||
#endif // PSA_{{partition.name|upper}}_PARTITION_H
|
/****************** Common definitions ****************************************/
|
||||||
|
|
||||||
|
/* PSA reserved event flags */
|
||||||
|
#define PSA_RESERVED1_POS (1UL)
|
||||||
|
#define PSA_RESERVED1_MSK (1UL << PSA_RESERVED1_POS)
|
||||||
|
|
||||||
|
#define PSA_RESERVED2_POS (2UL)
|
||||||
|
#define PSA_RESERVED2_MSK (1UL << PSA_RESERVED2_POS)
|
||||||
|
|
||||||
|
/****************** Service Partitions ****************************************/
|
||||||
|
|
||||||
|
{% for partition in service_partitions %}
|
||||||
|
{{ do_parition(partition) }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
/****************** Test Partitions *******************************************/
|
||||||
|
|
||||||
|
#ifdef USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
{% for test_partition in test_partitions %}
|
||||||
|
#ifdef USE_{{test_partition.name|upper}}
|
||||||
|
{{ do_parition(test_partition) }}
|
||||||
|
#endif // USE_{{test_partition.name|upper}}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
#endif // USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
#endif // __MBED_SPM_PARTITIONS_H___
|
||||||
{# End of file #}
|
{# End of file #}
|
||||||
|
|
@ -0,0 +1,281 @@
|
||||||
|
/* Copyright (c) 2017-2019 ARM Limited
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
||||||
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* Template Version 1.0
|
||||||
|
* Generated by tools/psa/generate_partition_code.py Version {{script_ver}}
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "cmsis.h"
|
||||||
|
#include "rtx_os.h"
|
||||||
|
|
||||||
|
#include "mbed_toolchain.h" /* For using MBED_ALIGN macro */
|
||||||
|
|
||||||
|
#include "spm_panic.h"
|
||||||
|
#include "spm_internal.h"
|
||||||
|
#include "handles_manager.h"
|
||||||
|
#include "mbed_spm_partitions.h"
|
||||||
|
|
||||||
|
#include "psa_manifest/sid.h"
|
||||||
|
|
||||||
|
extern spm_db_t g_spm;
|
||||||
|
|
||||||
|
{% macro do_parition(partition) -%}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* {{partition.name|upper}} declarations
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
MBED_ALIGN(8) static uint8_t {{partition.name|lower}}_thread_stack[{{partition.stack_size}}] = {0};
|
||||||
|
|
||||||
|
static osRtxThread_t {{partition.name|lower}}_thread_cb = {0};
|
||||||
|
static const osThreadAttr_t {{partition.name|lower}}_thread_attr = {
|
||||||
|
.name = "{{partition.name|lower}}",
|
||||||
|
.attr_bits = 0,
|
||||||
|
.cb_mem = &{{partition.name|lower}}_thread_cb,
|
||||||
|
.cb_size = sizeof({{partition.name|lower}}_thread_cb),
|
||||||
|
.stack_mem = {{partition.name|lower}}_thread_stack,
|
||||||
|
.stack_size = {{partition.stack_size}},
|
||||||
|
.priority = {{partition.priority_mbed}},
|
||||||
|
.tz_module = 0,
|
||||||
|
.reserved = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
static osRtxMutex_t {{partition.name|lower}}_mutex = {0};
|
||||||
|
static const osMutexAttr_t {{partition.name|lower}}_mutex_attr = {
|
||||||
|
.name = "{{partition.name|lower}}_mutex",
|
||||||
|
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
|
||||||
|
.cb_mem = &{{partition.name|lower}}_mutex,
|
||||||
|
.cb_size = sizeof({{partition.name|lower}}_mutex),
|
||||||
|
};
|
||||||
|
|
||||||
|
{% if partition.rot_services|count > 0 %}
|
||||||
|
spm_rot_service_t {{partition.name|lower}}_rot_services[] = {
|
||||||
|
{% for rot_srv in partition.rot_services %}
|
||||||
|
{
|
||||||
|
.sid = {{rot_srv.name|upper}},
|
||||||
|
.mask = {{rot_srv.signal|upper}},
|
||||||
|
.partition = NULL,
|
||||||
|
.min_version = {{rot_srv.minor_version}},
|
||||||
|
.min_version_policy = PSA_MINOR_VERSION_POLICY_{{rot_srv.minor_policy|upper}},
|
||||||
|
{% if rot_srv.nspe_callable %}
|
||||||
|
.allow_nspe = true,
|
||||||
|
{% else %}
|
||||||
|
.allow_nspe = false,
|
||||||
|
{% endif %}
|
||||||
|
.queue = {
|
||||||
|
.head = NULL,
|
||||||
|
.tail = NULL
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{% endfor %}
|
||||||
|
};
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if partition.extern_sids|count > 0 %}
|
||||||
|
/* External SIDs used by {{partition.name}} */
|
||||||
|
const uint32_t {{partition.name|lower}}_external_sids[{{partition.extern_sids|count}}] = {
|
||||||
|
{% for sid in partition.extern_sids %}
|
||||||
|
{{sid|upper}},
|
||||||
|
{% endfor %}
|
||||||
|
};
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if partition.irqs|count > 0 %}
|
||||||
|
// Mapper function from irq signal to interupts number
|
||||||
|
IRQn_Type spm_{{partition.name|lower}}_signal_to_irq_mapper(uint32_t signal)
|
||||||
|
{
|
||||||
|
SPM_ASSERT({{partition.name|upper}}_WAIT_ANY_IRQ_MSK & signal);
|
||||||
|
switch(signal){
|
||||||
|
{% for irq in partition.irqs %}
|
||||||
|
case {{ irq.signal }}:
|
||||||
|
return (IRQn_Type){{irq.line_num}};
|
||||||
|
break;
|
||||||
|
{% endfor %}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPM_PANIC("Unknown signal number %lu", signal);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
{% for irq in partition.irqs %}
|
||||||
|
// ISR handler for interrupt {irq.line_num}
|
||||||
|
void spm_irq_{{irq.signal}}_{{partition.name|lower}}(void)
|
||||||
|
{
|
||||||
|
spm_partition_t *partition = NULL;
|
||||||
|
for (uint32_t i = 0; i < g_spm.partition_count; ++i) {
|
||||||
|
if (g_spm.partitions[i].partition_id == {{partition.name|upper}}_ID) {
|
||||||
|
partition = &(g_spm.partitions[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SPM_ASSERT(partition);
|
||||||
|
|
||||||
|
NVIC_DisableIRQ((IRQn_Type){{irq.line_num}}); // will be enabled by psa_eoi()
|
||||||
|
osThreadFlagsSet(partition->thread_id, {{irq.signal|upper}}); // notify partition
|
||||||
|
}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
extern void {{partition.entry_point}}(void *ptr);
|
||||||
|
|
||||||
|
void {{partition.name|lower}}_init(spm_partition_t *partition)
|
||||||
|
{
|
||||||
|
if (NULL == partition) {
|
||||||
|
SPM_PANIC("partition is NULL!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
partition->mutex = osMutexNew(&{{partition.name|lower}}_mutex_attr);
|
||||||
|
if (NULL == partition->mutex) {
|
||||||
|
SPM_PANIC("Failed to create mutex for secure partition {{partition.name|lower}}!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
{% if partition.rot_services|count > 0 %}
|
||||||
|
for (uint32_t i = 0; i < {{partition.name|upper}}_ROT_SRV_COUNT; ++i) {
|
||||||
|
{{partition.name|lower}}_rot_services[i].partition = partition;
|
||||||
|
}
|
||||||
|
partition->rot_services = {{partition.name|lower}}_rot_services;
|
||||||
|
{% else %}
|
||||||
|
partition->rot_services = NULL;
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
partition->thread_id = osThreadNew({{partition.entry_point}}, NULL, &{{partition.name|lower}}_thread_attr);
|
||||||
|
if (NULL == partition->thread_id) {
|
||||||
|
SPM_PANIC("Failed to create start main thread of partition {{partition.name|lower}}!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{%- endmacro %}
|
||||||
|
{# -------------- macro do_parition(partition) ----------------------------- #}
|
||||||
|
/****************** Service Partitions ****************************************/
|
||||||
|
|
||||||
|
{% for partition in service_partitions %}
|
||||||
|
{{do_parition(partition)}}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
/****************** Test Partitions *******************************************/
|
||||||
|
#ifdef USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
{% for test_partition in test_partitions %}
|
||||||
|
#ifdef USE_{{test_partition.name|upper}}
|
||||||
|
{{ do_parition(test_partition) }}
|
||||||
|
|
||||||
|
#endif // USE_{{test_partition.name|upper}}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
#endif // USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
{# -------------- spm_db_entry(partition) ----------------------------------- #}
|
||||||
|
{% macro spm_db_entry(partition) -%}
|
||||||
|
|
||||||
|
/* {{partition.name|upper}} */
|
||||||
|
{
|
||||||
|
.partition_id = {{partition.name|upper}}_ID,
|
||||||
|
.thread_id = 0,
|
||||||
|
.flags = {{partition.name|upper}}_WAIT_ANY_SID_MSK | {{partition.name|upper}}_WAIT_ANY_IRQ_MSK,
|
||||||
|
.rot_services = NULL,
|
||||||
|
{% if partition.rot_services|count > 0 %}
|
||||||
|
.rot_services_count = {{partition.name|upper}}_ROT_SRV_COUNT,
|
||||||
|
{% else %}
|
||||||
|
.rot_services_count = 0,
|
||||||
|
{% endif %}
|
||||||
|
{% if partition.extern_sids|count > 0 %}
|
||||||
|
.extern_sids = {{partition.name|lower}}_external_sids,
|
||||||
|
{% else %}
|
||||||
|
.extern_sids = NULL,
|
||||||
|
{% endif %}
|
||||||
|
.extern_sids_count = {{partition.name|upper}}_EXT_ROT_SRV_COUNT,
|
||||||
|
{% if partition.irqs|count > 0 %}
|
||||||
|
.irq_mapper = spm_{{partition.name|lower}}_signal_to_irq_mapper,
|
||||||
|
{% else %}
|
||||||
|
.irq_mapper = NULL,
|
||||||
|
{% endif %}
|
||||||
|
},
|
||||||
|
{%- endmacro %}
|
||||||
|
{# -------------- spm_db_entry(partition) ----------------------------------- #}
|
||||||
|
/****************** SPM DB initialization *************************************/
|
||||||
|
spm_partition_t g_partitions[] = {
|
||||||
|
{% for partition in service_partitions %}
|
||||||
|
{{spm_db_entry(partition)}}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
#ifdef USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
{% for test_partition in test_partitions %}
|
||||||
|
#ifdef USE_{{test_partition.name|upper}} {{ spm_db_entry(test_partition) }}
|
||||||
|
#endif // USE_{{test_partition.name|upper}}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
#endif // USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************** MMIO regions **********************************************/
|
||||||
|
{% if regions|count > 0 %}
|
||||||
|
/****************** Sanity checks *********************************************/
|
||||||
|
/* Check all the defined memory regions for overlapping. */
|
||||||
|
{% for region_pair in region_pair_list %}
|
||||||
|
MBED_STATIC_ASSERT(
|
||||||
|
((uintptr_t)({{region_pair[0].base}}) + {{region_pair[0].size}} - 1 < (uintptr_t)({{region_pair[1].base}})) ||
|
||||||
|
((uintptr_t)({{region_pair[1].base}}) + {{region_pair[1].size}} - 1 < (uintptr_t)({{region_pair[0].base}})),
|
||||||
|
"The region with base {{region_pair[0].base}} and size {{region_pair[0].size}} overlaps with the region with base {{region_pair[1].base}} and size {{region_pair[1].size}}!");
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
/****************** MMIO regions definition ***********************************/
|
||||||
|
/* A list of all the memory regions. */
|
||||||
|
const mem_region_t mem_regions[] = {
|
||||||
|
{% for region in regions %}
|
||||||
|
{ (uint32_t)({{region.base}}), {{region.size}}, {{region.permission}}, {{region.partition_id}} },
|
||||||
|
{% endfor %}
|
||||||
|
};
|
||||||
|
{% else %}
|
||||||
|
const mem_region_t *mem_regions = NULL;
|
||||||
|
{% endif %}
|
||||||
|
const uint32_t mem_region_count = {{regions|count}};
|
||||||
|
|
||||||
|
/****************** Partitions init function *********************************/
|
||||||
|
uint32_t init_partitions(spm_partition_t **partitions)
|
||||||
|
{
|
||||||
|
uint32_t partition_idx = 0;
|
||||||
|
|
||||||
|
if (NULL == partitions) {
|
||||||
|
SPM_PANIC("partitions is NULL!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
{% for partition in service_partitions %}
|
||||||
|
{{partition.name|lower}}_init(&(g_partitions[partition_idx++]));
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
#ifdef USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
{% for test_partition in test_partitions %}
|
||||||
|
#ifdef USE_{{test_partition.name|upper}}
|
||||||
|
{{test_partition.name|lower}}_init(&(g_partitions[partition_idx++]));
|
||||||
|
#endif // USE_{{test_partition.name|upper}}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
#endif // USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
*partitions = g_partitions;
|
||||||
|
return partition_idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
{# End of file #}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (c) 2017-2019 ARM Limited
|
/* Copyright (c) 2019 ARM Limited
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
|
|
@ -15,20 +15,33 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***********************************************************************************************************************
|
/*******************************************************************************
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
||||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
* Template Version 1.0
|
* Template Version 1.0
|
||||||
* Generated by tools/spm/generate_partition_code.py Version {{script_ver}}
|
* Generated by tools/psa/generate_partition_code.py Version {{script_ver}}
|
||||||
**********************************************************************************************************************/
|
******************************************************************************/
|
||||||
|
{% macro parition_sid(partition) -%}
|
||||||
#ifndef PSA_{{partition.name|upper}}_PARTITION_ROT_SERVICES_H
|
/* -----------------------------------------------------------------------------
|
||||||
#define PSA_{{partition.name|upper}}_PARTITION_ROT_SERVICES_H
|
* {{partition.name|upper}} Service IDs
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
{% for rot_srv in partition.rot_services %}
|
{% for rot_srv in partition.rot_services %}
|
||||||
#define {{rot_srv.name|upper}} {{rot_srv.id}}
|
#define {{rot_srv.name|upper}} {{rot_srv.id}}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
#endif // PSA_{{partition.name|upper}}_PARTITION_ROT_SERVICES_H
|
{%- endmacro %}
|
||||||
|
{# -------------- macro parition_sid(partition) ---------------------------- #}
|
||||||
|
|
||||||
|
/****************** Service Partitions ****************************************/
|
||||||
|
|
||||||
|
{% for partition in service_partitions %}
|
||||||
|
{{parition_sid(partition)}}
|
||||||
|
{% endfor %}
|
||||||
|
/****************** Test Partitions *******************************************/
|
||||||
|
|
||||||
|
{% for partition in test_partitions %}
|
||||||
|
{{parition_sid(partition)}}
|
||||||
|
{% endfor %}
|
||||||
{# End of file #}
|
{# End of file #}
|
||||||
|
|
@ -15,19 +15,25 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*********** WARNING: This is an auto-generated file. Do not edit! ***********/
|
/*******************************************************************************
|
||||||
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
||||||
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* Template Version 1.0
|
||||||
|
* Generated by tools/psa/generate_partition_code.py Version {{script_ver}}
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
#ifndef __TFM_PARTITION_DEFS_INC__
|
#ifndef __TFM_PARTITION_DEFS_INC__
|
||||||
#define __TFM_PARTITION_DEFS_INC__
|
#define __TFM_PARTITION_DEFS_INC__
|
||||||
|
|
||||||
/*************************** Service Partitions ******************************/
|
/*************************** Service Partitions *******************************/
|
||||||
|
|
||||||
{% for partition in service_partitions %}
|
{% for partition in service_partitions %}
|
||||||
{% set partition_loop = loop %}
|
{% set partition_loop = loop %}
|
||||||
#define {{partition.name|upper}}_ID (TFM_SP_BASE + {{ partition_loop.index0 }})
|
#define {{partition.name|upper}}_ID (TFM_SP_BASE + {{ partition_loop.index0 }})
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
/*************************** Test Partitions *********************************/
|
/*************************** Test Partitions **********************************/
|
||||||
|
|
||||||
#ifdef USE_PSA_TEST_PARTITIONS
|
#ifdef USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2019, Arm Limited. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
||||||
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* Template Version 1.0
|
||||||
|
* Generated by tools/psa/generate_partition_code.py Version {{script_ver}}
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __TFM_PARTITION_LIST_INC__
|
||||||
|
#define __TFM_PARTITION_LIST_INC__
|
||||||
|
|
||||||
|
/*************************** Service Partitions *******************************/
|
||||||
|
{% for partition in service_partitions %}
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* {{partition.name|upper}}
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
PARTITION_DECLARE({{partition.name|upper}}, 0
|
||||||
|
| SPM_PART_FLAG_IPC
|
||||||
|
, "{{partition.type}}", {{partition.id}}, {{partition.priority_tfm}}, {{partition.stack_size}});
|
||||||
|
PARTITION_ADD_INIT_FUNC({{partition.name|upper}}, {{partition.entry_point}});
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
/*************************** Test Partitions **********************************/
|
||||||
|
#ifdef USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
{% for partition in test_partitions %}
|
||||||
|
#ifdef USE_{{partition.name|upper}}
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* {{partition.name|upper}}
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
PARTITION_DECLARE({{partition.name|upper}}, 0
|
||||||
|
| SPM_PART_FLAG_IPC
|
||||||
|
, "{{partition.type}}", {{partition.id}}, {{partition.priority_tfm}}, {{partition.stack_size}});
|
||||||
|
PARTITION_ADD_INIT_FUNC({{partition.name|upper}}, {{partition.entry_point}});
|
||||||
|
#endif // USE_{{partition.name|upper}}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
#endif // USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
#endif // __TFM_PARTITION_LIST_INC__
|
||||||
|
{# End of file #}
|
||||||
|
|
@ -5,23 +5,35 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*********** WARNING: This is an auto-generated file. Do not edit! ***********/
|
/*******************************************************************************
|
||||||
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
||||||
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* Template Version 1.0
|
||||||
|
* Generated by tools/psa/generate_partition_code.py Version {{script_ver}}
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
#ifndef __TFM_SERVICE_LIST_INC__
|
#ifndef __TFM_SERVICE_LIST_INC__
|
||||||
#define __TFM_SERVICE_LIST_INC__
|
#define __TFM_SERVICE_LIST_INC__
|
||||||
|
|
||||||
|
/*************************** Service Partitions *******************************/
|
||||||
{% for partition in service_partitions %}
|
{% for partition in service_partitions %}
|
||||||
/******** {{partition.name|upper}} ********/
|
/* -----------------------------------------------------------------------------
|
||||||
|
* {{partition.name|upper}} Services
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
{% for rot_srv in partition.rot_services %}
|
{% for rot_srv in partition.rot_services %}
|
||||||
{"{{rot_srv.name|upper}}", {{partition.name|upper}}_ID, {{rot_srv.signal|upper}}, {{rot_srv.id}}, {% if rot_srv.nspe_callable %}true{% else %}false{% endif %}, {{rot_srv.minor_version}}, TFM_VERSION_POLICY_{{rot_srv.minor_policy|upper}}},
|
{"{{rot_srv.name|upper}}", {{partition.name|upper}}_ID, {{rot_srv.signal|upper}}, {{rot_srv.id}}, {% if rot_srv.nspe_callable %}true{% else %}false{% endif %}, {{rot_srv.minor_version}}, TFM_VERSION_POLICY_{{rot_srv.minor_policy|upper}}},
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
/*************************** Test Partitions **********************************/
|
||||||
#ifdef USE_PSA_TEST_PARTITIONS
|
#ifdef USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
{% for partition in test_partitions %}
|
{% for partition in test_partitions %}
|
||||||
#ifdef USE_{{partition.name|upper}}
|
#ifdef USE_{{partition.name|upper}}
|
||||||
/******** {{partition.name|upper}} ********/
|
/* -----------------------------------------------------------------------------
|
||||||
|
* {{partition.name|upper}} Services
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
{% for rot_srv in partition.rot_services %}
|
{% for rot_srv in partition.rot_services %}
|
||||||
{"{{rot_srv.name|upper}}", {{partition.name|upper}}_ID, {{rot_srv.signal|upper}}, {{rot_srv.id}}, {% if rot_srv.nspe_callable %}true{% else %}false{% endif %}, {{rot_srv.minor_version}}, TFM_VERSION_POLICY_{{rot_srv.minor_policy|upper}}},
|
{"{{rot_srv.name|upper}}", {{partition.name|upper}}_ID, {{rot_srv.signal|upper}}, {{rot_srv.id}}, {% if rot_srv.nspe_callable %}true{% else %}false{% endif %}, {{rot_srv.minor_version}}, TFM_VERSION_POLICY_{{rot_srv.minor_policy|upper}}},
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2019, Arm Limited. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
|
||||||
|
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
* Template Version 1.0
|
||||||
|
* Generated by tools/psa/generate_partition_code.py Version {{script_ver}}
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __TFM_SPM_SIGNAL_DEFS_H__
|
||||||
|
#define __TFM_SPM_SIGNAL_DEFS_H__
|
||||||
|
|
||||||
|
/*************************** Service Partitions *******************************/
|
||||||
|
{% for partition in service_partitions %}
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* {{partition.name|upper}} Signals
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
{% for rot_srv in partition.rot_services %}
|
||||||
|
#define {{rot_srv.signal|upper}}_POS ({{loop.index + 3}}UL)
|
||||||
|
#define {{rot_srv.signal|upper}} (1UL << {{rot_srv.signal|upper}}_POS)
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
/*************************** Test Partitions **********************************/
|
||||||
|
#ifdef USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
{% for partition in test_partitions %}
|
||||||
|
#ifdef USE_{{partition.name|upper}}
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* {{partition.name|upper}} Signals
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
{% for rot_srv in partition.rot_services %}
|
||||||
|
#define {{rot_srv.signal|upper}}_POS ({{loop.index + 3}}UL)
|
||||||
|
#define {{rot_srv.signal|upper}} (1UL << {{rot_srv.signal|upper}}_POS)
|
||||||
|
{% endfor %}
|
||||||
|
#endif // USE_{{partition.name|upper}}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
#endif // USE_PSA_TEST_PARTITIONS
|
||||||
|
|
||||||
|
#endif // __TFM_SPM_SIGNAL_DEFS_H__
|
||||||
|
{# End of file #}
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
/* Copyright (c) 2019 ARM Limited
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*********** WARNING: This is an auto-generated file. Do not edit! ***********/
|
|
||||||
|
|
||||||
{% for partition in service_partitions %}
|
|
||||||
/******** {{partition.name|upper}} ********/
|
|
||||||
{% for rot_srv in partition.rot_services %}
|
|
||||||
#define {{rot_srv.name|upper}} {{rot_srv.id}}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% for partition in test_partitions %}
|
|
||||||
|
|
||||||
/******** {{partition.name|upper}} ********/
|
|
||||||
{% for rot_srv in partition.rot_services %}
|
|
||||||
#define {{rot_srv.name|upper}} {{rot_srv.id}}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% endfor %}
|
|
||||||
{# End of file #}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018-2019, Arm Limited. All rights reserved.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*********** WARNING: This is an auto-generated file. Do not edit! ***********/
|
|
||||||
|
|
||||||
#ifndef __TFM_PARTITION_LIST_INC__
|
|
||||||
#define __TFM_PARTITION_LIST_INC__
|
|
||||||
|
|
||||||
{% for partition in service_partitions %}
|
|
||||||
/******** {{partition.name|upper}} ********/
|
|
||||||
PARTITION_DECLARE({{partition.name|upper}}, 0
|
|
||||||
| SPM_PART_FLAG_IPC
|
|
||||||
, "{{partition.type}}", {{partition.id}}, {{partition.priority}}, {{partition.stack_size}});
|
|
||||||
PARTITION_ADD_INIT_FUNC({{partition.name|upper}}, {{partition.entry_point}});
|
|
||||||
|
|
||||||
{% endfor %}
|
|
||||||
#ifdef USE_PSA_TEST_PARTITIONS
|
|
||||||
|
|
||||||
{% for partition in test_partitions %}
|
|
||||||
#ifdef USE_{{partition.name|upper}}
|
|
||||||
/******** {{partition.name|upper}} ********/
|
|
||||||
PARTITION_DECLARE({{partition.name|upper}}, 0
|
|
||||||
| SPM_PART_FLAG_IPC
|
|
||||||
, "{{partition.type}}", {{partition.id}}, {{partition.priority}}, {{partition.stack_size}});
|
|
||||||
PARTITION_ADD_INIT_FUNC({{partition.name|upper}}, {{partition.entry_point}});
|
|
||||||
#endif // USE_{{partition.name|upper}}
|
|
||||||
|
|
||||||
{% endfor %}
|
|
||||||
#endif // USE_PSA_TEST_PARTITIONS
|
|
||||||
|
|
||||||
#endif // __TFM_PARTITION_LIST_INC__
|
|
||||||
{# End of file #}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018-2019, Arm Limited. All rights reserved.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*********** WARNING: This is an auto-generated file. Do not edit! ***********/
|
|
||||||
|
|
||||||
#ifndef __TFM_SPM_SIGNAL_DEFS_H__
|
|
||||||
#define __TFM_SPM_SIGNAL_DEFS_H__
|
|
||||||
|
|
||||||
{% for partition in service_partitions %}
|
|
||||||
/******** {{partition.name|upper}} ********/
|
|
||||||
{% for rot_srv in partition.rot_services %}
|
|
||||||
#define {{rot_srv.signal|upper}}_POS ({{loop.index + 3}}UL)
|
|
||||||
#define {{rot_srv.signal|upper}} (1UL << {{rot_srv.signal|upper}}_POS)
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% endfor %}
|
|
||||||
#ifdef USE_PSA_TEST_PARTITIONS
|
|
||||||
|
|
||||||
{% for partition in test_partitions %}
|
|
||||||
#ifdef USE_{{partition.name|upper}}
|
|
||||||
/******** {{partition.name|upper}} ********/
|
|
||||||
{% for rot_srv in partition.rot_services %}
|
|
||||||
#define {{rot_srv.signal|upper}}_POS ({{loop.index + 3}}UL)
|
|
||||||
#define {{rot_srv.signal|upper}} (1UL << {{rot_srv.signal|upper}}_POS)
|
|
||||||
{% endfor %}
|
|
||||||
#endif // USE_{{partition.name|upper}}
|
|
||||||
|
|
||||||
{% endfor %}
|
|
||||||
#endif // USE_PSA_TEST_PARTITIONS
|
|
||||||
|
|
||||||
#endif // __TFM_SPM_SIGNAL_DEFS_H__
|
|
||||||
{# End of file #}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
[
|
|
||||||
{
|
|
||||||
"name": "Secure Partition ID definitions",
|
|
||||||
"template": "tools/psa/tfm/templates/tfm_partition_defs.inc.tpl",
|
|
||||||
"output": "components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/autogen/tfm_partition_defs.inc"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Secure Partition declarations",
|
|
||||||
"template": "tools/psa/tfm/templates/tfm_partition_list.inc.tpl",
|
|
||||||
"output": "components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/autogen/tfm_partition_list.inc"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Secure Service list",
|
|
||||||
"template": "tools/psa/tfm/templates/tfm_service_list.inc.tpl",
|
|
||||||
"output": "components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/autogen/tfm_service_list.inc"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Secure Service signals list",
|
|
||||||
"template": "tools/psa/tfm/templates/tfm_spm_signal_defs.h.tpl",
|
|
||||||
"output": "components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/autogen/tfm_spm_signal_defs.h"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Mappings from RoT Service names to SIDs",
|
|
||||||
"template": "tools/psa/tfm/templates/sid.h.tpl",
|
|
||||||
"output": "components/TARGET_PSA/inc/psa_manifest/sid.h"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
@ -457,7 +457,7 @@ test_partition_template = '''{
|
||||||
"name": "{{partition.name}}",
|
"name": "{{partition.name}}",
|
||||||
"id": "0x{{"%0x"|format(partition.id|int)|upper}}",
|
"id": "0x{{"%0x"|format(partition.id|int)|upper}}",
|
||||||
"type": "{{partition.type}}",
|
"type": "{{partition.type}}",
|
||||||
"priority": "{{partition.priority|find_priority_key}}",
|
"priority": "{{partition.priority_mbed|find_priority_key}}",
|
||||||
"entry_point": "{{partition.entry_point}}",
|
"entry_point": "{{partition.entry_point}}",
|
||||||
"stack_size": {{partition.stack_size}},
|
"stack_size": {{partition.stack_size}},
|
||||||
"heap_size": {{partition.heap_size}},
|
"heap_size": {{partition.heap_size}},
|
||||||
|
|
@ -365,7 +365,7 @@ def test_validate_partition_manifest(request, temp_test_data, manifests, asserti
|
||||||
"""
|
"""
|
||||||
test_name = extract_test_name(request.node.name)
|
test_name = extract_test_name(request.node.name)
|
||||||
jsons = [dump_manifest_to_json(m, '%s_%d' % (test_name, i), temp_test_data['dir']) for i, m in enumerate(manifests)]
|
jsons = [dump_manifest_to_json(m, '%s_%d' % (test_name, i), temp_test_data['dir']) for i, m in enumerate(manifests)]
|
||||||
created_manifests, _ = parse_manifests(jsons, 'MBED_SPM')
|
created_manifests, _ = parse_manifests(jsons)
|
||||||
|
|
||||||
with pytest.raises(assertion[0], match=assertion[1]):
|
with pytest.raises(assertion[0], match=assertion[1]):
|
||||||
validate_partition_manifests(created_manifests)
|
validate_partition_manifests(created_manifests)
|
||||||
|
|
@ -460,7 +460,7 @@ def test_verify_json(verify_json):
|
||||||
:param verify_json: The 'verify_json' fixture.
|
:param verify_json: The 'verify_json' fixture.
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
test_manifests, _ = parse_manifests(verify_json['files_list'], 'MBED_SPM')
|
test_manifests, _ = parse_manifests(verify_json['files_list'])
|
||||||
validate_partition_manifests(test_manifests)
|
validate_partition_manifests(test_manifests)
|
||||||
assert getattr(test_manifests[0], verify_json['field']) == verify_json['expected']
|
assert getattr(test_manifests[0], verify_json['field']) == verify_json['expected']
|
||||||
|
|
||||||
|
|
@ -509,7 +509,7 @@ def test_template_setup(tmpdir_factory):
|
||||||
manifest_files = [
|
manifest_files = [
|
||||||
dump_manifest_to_json(manifest, manifest['name'], test_dir) for
|
dump_manifest_to_json(manifest, manifest['name'], test_dir) for
|
||||||
manifest in manifests]
|
manifest in manifests]
|
||||||
manifest_objects, regions = parse_manifests(manifest_files, 'MBED_SPM')
|
manifest_objects, regions = parse_manifests(manifest_files)
|
||||||
filters = {
|
filters = {
|
||||||
'basename': os.path.basename,
|
'basename': os.path.basename,
|
||||||
'find_priority_key': find_priority_key,
|
'find_priority_key': find_priority_key,
|
||||||
|
|
@ -562,7 +562,6 @@ def test_generate_source_files(test_template_setup):
|
||||||
'partition': manifest,
|
'partition': manifest,
|
||||||
'dependent_partitions': manifest.find_dependencies(test_template_setup['manifests'])
|
'dependent_partitions': manifest.find_dependencies(test_template_setup['manifests'])
|
||||||
},
|
},
|
||||||
output_folder=test_template_setup['dir'],
|
|
||||||
extra_filters=test_template_setup['filters']
|
extra_filters=test_template_setup['filters']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -572,7 +571,6 @@ def test_generate_source_files(test_template_setup):
|
||||||
'partitions': test_template_setup['manifests'],
|
'partitions': test_template_setup['manifests'],
|
||||||
'region_pair_list': region_pair_list
|
'region_pair_list': region_pair_list
|
||||||
},
|
},
|
||||||
output_folder=test_template_setup['dir'],
|
|
||||||
extra_filters=test_template_setup['filters']
|
extra_filters=test_template_setup['filters']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -611,74 +609,6 @@ def test_generate_source_files(test_template_setup):
|
||||||
assert generated == expected
|
assert generated == expected
|
||||||
|
|
||||||
|
|
||||||
def test_generate_partitions_sources(monkeypatch, test_template_setup):
|
|
||||||
"""
|
|
||||||
Test which calls generate_partitions_sources() with the data from
|
|
||||||
'test_template_setup' fixture.
|
|
||||||
Because generate_partitions_sources() is a compound of the other functions in
|
|
||||||
the module which are tested individually, this test just do the following:
|
|
||||||
1. Calls generate_partitions_sources() and checks that the autogen directory
|
|
||||||
was created.
|
|
||||||
2. Saves the modified times of the generated files.
|
|
||||||
3. Calls generate_partitions_sources() again, checks that the autogen directory
|
|
||||||
still exist and that modified times of the generated files didn't
|
|
||||||
change.
|
|
||||||
|
|
||||||
:param monkeypatch: The 'monkeypatch' fixture
|
|
||||||
(https://docs.pytest.org/en/latest/monkeypatch.html).
|
|
||||||
:param test_template_setup: The 'test_template_setup' fixture.
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
monkeypatch.setitem(DEFAULT_FILTERS, 'basename', os.path.basename)
|
|
||||||
monkeypatch.setitem(DEFAULT_FILTERS, 'find_priority_key',
|
|
||||||
find_priority_key)
|
|
||||||
monkeypatch.setitem(DEFAULT_FILTERS, 'find_permission_key',
|
|
||||||
find_permission_key)
|
|
||||||
|
|
||||||
autogen_dirs = generate_partitions_sources(test_template_setup['manifest_files'])
|
|
||||||
autogen_dirs_backup = tempfile.mkdtemp()
|
|
||||||
for directory in autogen_dirs:
|
|
||||||
assert os.path.isdir(directory)
|
|
||||||
shutil.copytree(directory, os.path.join(autogen_dirs_backup, os.path.split(directory)[1]))
|
|
||||||
|
|
||||||
autogen_dirs = generate_partitions_sources(test_template_setup['manifest_files'])
|
|
||||||
for directory in autogen_dirs:
|
|
||||||
assert os.path.isdir(directory)
|
|
||||||
dcmp = filecmp.dircmp(directory, os.path.join(autogen_dirs_backup, os.path.split(directory)[1]))
|
|
||||||
assert not dcmp.diff_files
|
|
||||||
|
|
||||||
spm_output_dir = generate_psa_setup(
|
|
||||||
test_template_setup['manifest_files'],
|
|
||||||
os.path.join(test_template_setup['dir'], 'SETUP'),
|
|
||||||
weak_setup=False,
|
|
||||||
extra_filters=test_template_setup['filters']
|
|
||||||
)
|
|
||||||
|
|
||||||
assert os.path.isdir(spm_output_dir)
|
|
||||||
shutil.copytree(spm_output_dir, os.path.join(autogen_dirs_backup, os.path.split(spm_output_dir)[1]))
|
|
||||||
|
|
||||||
for gen_file in test_template_setup['common_files']:
|
|
||||||
generated_file = os.path.join(spm_output_dir, gen_file)
|
|
||||||
expected_file = os.path.join(test_template_setup['dir'], gen_file)
|
|
||||||
assert os.path.isfile(generated_file)
|
|
||||||
assert os.path.isfile(expected_file)
|
|
||||||
|
|
||||||
with open(generated_file) as gfh:
|
|
||||||
with open(expected_file) as efh:
|
|
||||||
assert json.load(gfh) == json.load(efh)
|
|
||||||
|
|
||||||
spm_output_dir = generate_psa_setup(
|
|
||||||
test_template_setup['manifest_files'],
|
|
||||||
os.path.join(test_template_setup['dir'], 'SETUP'),
|
|
||||||
weak_setup=False,
|
|
||||||
extra_filters=test_template_setup['filters']
|
|
||||||
)
|
|
||||||
|
|
||||||
assert os.path.isdir(spm_output_dir)
|
|
||||||
dcmp = filecmp.dircmp(spm_output_dir, os.path.join(autogen_dirs_backup, os.path.split(spm_output_dir)[1]))
|
|
||||||
assert not dcmp.diff_files
|
|
||||||
|
|
||||||
|
|
||||||
circular_call_dependency_params = {
|
circular_call_dependency_params = {
|
||||||
'no manifests': {
|
'no manifests': {
|
||||||
'manifests': [],
|
'manifests': [],
|
||||||
|
|
@ -748,6 +678,6 @@ def test_check_circular_call_dependencies(circular_dependencies):
|
||||||
:param circular_dependencies: the 'circular_dependencies' fixture
|
:param circular_dependencies: the 'circular_dependencies' fixture
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
objects, _ = parse_manifests(circular_dependencies['files'], 'MBED_SPM')
|
objects, _ = parse_manifests(circular_dependencies['files'])
|
||||||
assert check_circular_call_dependencies(objects) == circular_dependencies[
|
assert check_circular_call_dependencies(objects) == circular_dependencies[
|
||||||
'result']
|
'result']
|
||||||
Loading…
Reference in New Issue