Skip to content

Commit 052e871

Browse files
RcColesDavid Hu
authored and
David Hu
committed
Tools: Allow TF-M relative paths in manifest lists
After performing the search for the manifest file relative to the manifest list, additionally search for the path relative to the root TF-M directory. This allows for manifest lists files which are within platform directories, while maintaining current behaviour by default. Change-Id: I703efc37c0184f245766cc061e7aa670332dd08b Signed-off-by: Raef Coles <[email protected]>
1 parent dfe406b commit 052e871

File tree

5 files changed

+40
-20
lines changed

5 files changed

+40
-20
lines changed

platform/ext/target/arm/rss/common/manifest/tfm_manifest_list.yaml

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#
88
#-------------------------------------------------------------------------------
99

10-
# The "manifest" field must be relative path to this file or absolute path.
10+
# The "manifest" field must be a path relative to this file, a path relative to
11+
# the directory that tfm_parse_manifest_list.py is run in (which by default is
12+
# the TF-M root directory), or an absolute path.
1113
#
1214
# Files per Secure Partition are generated to:
1315
# - "output_path", if it is a absolute path - not recommended
@@ -24,7 +26,7 @@
2426
"manifest_list": [
2527
{
2628
"description": "Non-Secure Mailbox Agent",
27-
"manifest": "${CMAKE_SOURCE_DIR}/secure_fw/partitions/ns_agent_mailbox/ns_agent_mailbox.yaml",
29+
"manifest": "secure_fw/partitions/ns_agent_mailbox/ns_agent_mailbox.yaml",
2830
"output_path": "secure_fw/partitions/ns_agent_mailbox",
2931
"conditional": "TFM_MULTI_CORE_TOPOLOGY",
3032
"version_major": 0,
@@ -39,7 +41,7 @@
3941
},
4042
{
4143
"description": "TFM Crypto Service",
42-
"manifest": "${CMAKE_SOURCE_DIR}/platform/ext/target/arm/rss/common/manifest/tfm_crypto.yaml",
44+
"manifest": "platform/ext/target/arm/rss/common/manifest/tfm_crypto.yaml",
4345
"output_path": "secure_fw/partitions/crypto",
4446
"conditional": "TFM_PARTITION_CRYPTO",
4547
"version_major": 0,
@@ -53,7 +55,7 @@
5355
},
5456
{
5557
"description": "TFM Platform Service",
56-
"manifest": "${CMAKE_SOURCE_DIR}/secure_fw/partitions/platform/tfm_platform.yaml",
58+
"manifest": "secure_fw/partitions/platform/tfm_platform.yaml",
5759
"output_path": "secure_fw/partitions/platform",
5860
"conditional": "TFM_PARTITION_PLATFORM",
5961
"version_major": 0,
@@ -67,7 +69,7 @@
6769
},
6870
{
6971
"description": "TFM Initial Attestation Service",
70-
"manifest": "${CMAKE_SOURCE_DIR}/platform/ext/target/arm/rss/common/manifest/tfm_initial_attestation.yaml",
72+
"manifest": "platform/ext/target/arm/rss/common/manifest/tfm_initial_attestation.yaml",
7173
"output_path": "secure_fw/partitions/initial_attestation",
7274
"conditional": "TFM_PARTITION_INITIAL_ATTESTATION",
7375
"version_major": 0,

platform/ext/target/arm/rss/kronos/manifest/tfm_manifest_list.yaml

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#
88
#-------------------------------------------------------------------------------
99

10-
# The "manifest" field must be relative path to this file or absolute path.
10+
# The "manifest" field must be a path relative to this file, a path relative to
11+
# the directory that tfm_parse_manifest_list.py is run in (which by default is
12+
# the TF-M root directory), or an absolute path.
1113
#
1214
# Files per Secure Partition are generated to:
1315
# - "output_path", if it is a absolute path - not recommended
@@ -24,7 +26,7 @@
2426
"manifest_list": [
2527
{
2628
"description": "Non-Secure Mailbox Agent",
27-
"manifest": "${CMAKE_SOURCE_DIR}/secure_fw/partitions/ns_agent_mailbox/ns_agent_mailbox.yaml",
29+
"manifest": "secure_fw/partitions/ns_agent_mailbox/ns_agent_mailbox.yaml",
2830
"output_path": "secure_fw/partitions/ns_agent_mailbox",
2931
"conditional": "TFM_MULTI_CORE_TOPOLOGY",
3032
"version_major": 0,
@@ -39,7 +41,7 @@
3941
},
4042
{
4143
"description": "Protected Storage Partition",
42-
"manifest": "${CMAKE_SOURCE_DIR}/platform/ext/target/arm/rss/kronos/manifest/tfm_protected_storage.yaml",
44+
"manifest": "platform/ext/target/arm/rss/kronos/manifest/tfm_protected_storage.yaml",
4345
"output_path": "secure_fw/partitions/protected_storage",
4446
"conditional": "TFM_PARTITION_PROTECTED_STORAGE",
4547
"version_major": 0,
@@ -53,7 +55,7 @@
5355
},
5456
{
5557
"description": "TFM Crypto Service",
56-
"manifest": "${CMAKE_SOURCE_DIR}/platform/ext/target/arm/rss/kronos/manifest/tfm_crypto.yaml",
58+
"manifest": "platform/ext/target/arm/rss/kronos/manifest/tfm_crypto.yaml",
5759
"output_path": "secure_fw/partitions/crypto",
5860
"conditional": "TFM_PARTITION_CRYPTO",
5961
"version_major": 0,
@@ -67,7 +69,7 @@
6769
},
6870
{
6971
"description": "TFM Platform Service",
70-
"manifest": "${CMAKE_SOURCE_DIR}/secure_fw/partitions/platform/tfm_platform.yaml",
72+
"manifest": "secure_fw/partitions/platform/tfm_platform.yaml",
7173
"output_path": "secure_fw/partitions/platform",
7274
"conditional": "TFM_PARTITION_PLATFORM",
7375
"version_major": 0,
@@ -81,7 +83,7 @@
8183
},
8284
{
8385
"description": "TFM Initial Attestation Service",
84-
"manifest": "${CMAKE_SOURCE_DIR}/secure_fw/partitions/initial_attestation/tfm_initial_attestation.yaml",
86+
"manifest": "secure_fw/partitions/initial_attestation/tfm_initial_attestation.yaml",
8587
"output_path": "secure_fw/partitions/initial_attestation",
8688
"conditional": "TFM_PARTITION_INITIAL_ATTESTATION",
8789
"version_major": 0,

tools/CMakeLists.txt

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#-------------------------------------------------------------------------------
2-
# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
2+
# Copyright (c) 2020-2023, Arm Limited. All rights reserved.
33
#
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
@@ -65,7 +65,13 @@ foreach(MANIFEST_LIST ${MANIFEST_LISTS})
6565
foreach(MANIFEST ${MANIFESTS})
6666
# Convert to absolute paths
6767
if (NOT IS_ABSOLUTE ${MANIFEST})
68-
get_filename_component(MANIFEST "${MANIFEST_LIST_PATH}/${MANIFEST}" ABSOLUTE)
68+
# First try relative to the manifest
69+
if (EXISTS "${MANIFEST_LIST_PATH}/${MANIFEST}")
70+
get_filename_component(MANIFEST "${MANIFEST_LIST_PATH}/${MANIFEST}" ABSOLUTE)
71+
# Then try relative to the root TF-M source directory
72+
elseif (EXISTS "${CMAKE_SOURCE_DIR}/${MANIFEST}")
73+
get_filename_component(MANIFEST "${CMAKE_SOURCE_DIR}/${MANIFEST}" ABSOLUTE)
74+
endif()
6975
endif()
7076
list(APPEND MANIFEST_FILES ${MANIFEST})
7177
endforeach()
@@ -170,6 +176,7 @@ add_custom_target(
170176
# is to run the script at cmake-time.
171177
execute_process(
172178
COMMAND ${MANIFEST_COMMAND}
179+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
173180
RESULT_VARIABLE RET
174181
)
175182

tools/tfm_manifest_list.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#
88
#-------------------------------------------------------------------------------
99

10-
# The "manifest" field must be relative path to this file or absolute path.
10+
# The "manifest" field must be a path relative to this file, a path relative to
11+
# the directory that tfm_parse_manifest_list.py is run in (which by default is
12+
# the TF-M root directory), or an absolute path.
1113
#
1214
# Files per Secure Partition are generated to:
1315
# - "output_path", if it is a absolute path - not recommended

tools/tfm_parse_manifest_list.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#-------------------------------------------------------------------------------
2-
# Copyright (c) 2018-2022, Arm Limited. All rights reserved.
2+
# Copyright (c) 2018-2023, Arm Limited. All rights reserved.
33
# Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company)
44
# or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
55
#
@@ -294,11 +294,18 @@ def process_partition_manifests(manifest_lists, configs):
294294
with open(item) as manifest_list_yaml_file:
295295
manifest_dic = yaml.safe_load(manifest_list_yaml_file)['manifest_list']
296296
for dict in manifest_dic:
297-
# Replace environment variables in the manifest path and convert to absolute path.
298-
# If it's already abspath, the path will not be changed.
299-
manifest_path = os.path.join(os.path.dirname(item), # path of manifest list
300-
os.path.expandvars(dict['manifest']))\
301-
.replace('\\', '/')
297+
# Replace environment variables in the manifest path.
298+
expanded_path = os.path.expandvars(dict['manifest']).replace('\\', '/')
299+
300+
# If the manifest exists relative to the manifest list, then use
301+
# that. Else, either interpret it as an absolute path or one
302+
# relative to the current working directory
303+
path_relative_to_manifest_list = os.path.join(os.path.dirname(item), # path of manifest list
304+
expanded_path)
305+
if os.path.isfile(path_relative_to_manifest_list):
306+
manifest_path = path_relative_to_manifest_list
307+
else:
308+
manifest_path = expanded_path
302309
dict['manifest'] = manifest_path
303310
all_manifests.append(dict)
304311

0 commit comments

Comments
 (0)