Skip to content

Commit f6f6aa8

Browse files
jaccoo01adeaarm
authored andcommitted
RSE: Re-add routing tables and rse_id to OTP
Routing tables and rse_id were removed from the provisioning bundle binary generation as part of the refactor (but the fields remained in the OTP layout structures). Use the new structure defining the routing tables for a single RSE in the OTP layout and populate it using the previously generated pickle file. This requires the generation of individual bundles for each separate RSE in the system and therefore we add the CMake logic to facilitate this. We only change the blob naming in the case unique bundles are required so this does not impact platforms that do not use this feature. Change-Id: I9082ae435114308139c48ffd3bab158f27258896 Signed-off-by: Jackson Cooper-Driver <[email protected]>
1 parent 3c18622 commit f6f6aa8

File tree

6 files changed

+109
-55
lines changed

6 files changed

+109
-55
lines changed

platform/ext/target/arm/rse/common/otp_lcm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ struct otp_mapping_t{
132132
[PLAT_OTP_ID_RSE_ID] = USER_AREA_MAPPING(cm, rse_id),
133133
#endif
134134
#ifdef RSE_OTP_HAS_ROUTING_TABLES
135-
[PLAT_OTP_ID_RSE_TO_RSE_SENDER_ROUTING_TABLE] = USER_AREA_MAPPING(dm, rse_to_rse_sender_routing_table),
136-
[PLAT_OTP_ID_RSE_TO_RSE_RECEIVER_ROUTING_TABLE] = USER_AREA_MAPPING(dm, rse_to_rse_receiver_routing_table),
135+
[PLAT_OTP_ID_RSE_TO_RSE_SENDER_ROUTING_TABLE] = USER_AREA_MAPPING(dm, routing_tables.send),
136+
[PLAT_OTP_ID_RSE_TO_RSE_RECEIVER_ROUTING_TABLE] = USER_AREA_MAPPING(dm, routing_tables.receive),
137137
#endif
138138
};
139139

platform/ext/target/arm/rse/common/provisioning/bundle/CMakeLists.txt

Lines changed: 82 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ if (TFM_DUMMY_PROVISIONING)
309309
${TFM_BL2_ENCRYPTION_KEY_PATH}
310310
)
311311

312+
set(DM_BUNDLE_SCRIPT_DEPS
313+
$<$<BOOL:${RSE_OTP_HAS_ROUTING_TABLES}>:routing_tables_pickle>
314+
$<$<BOOL:${RSE_OTP_HAS_ROUTING_TABLES}>:${CMAKE_CURRENT_BINARY_DIR}/../../config/routing_tables.pickle>
315+
)
316+
312317
set(DM_BUNDLE_SCRIPT_ARGS
313318
$<$<EQUAL:${TFM_BL1_2_SIGNER_AMOUNT},2>:--non_secret_dm:dm.rotpk_areas_0.rotpk_0=${TFM_BL1_2_DM_SIGNING_KEY_PATH}>
314319
$<$<EQUAL:${TFM_BL1_2_SIGNER_AMOUNT},2>:--non_secret_dm:dm.rotpk_areas_0.rotpk_policy_0=RSE_ROTPK_POLICY_SIG_OPTIONAL>
@@ -319,6 +324,8 @@ if (TFM_DUMMY_PROVISIONING)
319324
--non_secret_dm:dm.rotpk_areas_0.rotpk_policy_1 RSE_ROTPK_POLICY_SIG_REQUIRED
320325
--non_secret_dm:dm.rotpk_areas_0.rotpk_type_1 RSE_ROTPK_TYPE_${MCUBOOT_ROTPK_TYPE}
321326
--non_secret_dm:dm.rotpk_areas_0.rotpk_hash_alg_1 RSE_ROTPK_HASH_ALG_${MCUBOOT_ROTPK_HASH_ALG}
327+
328+
$<$<BOOL:${RSE_OTP_HAS_ROUTING_TABLES}>:--routing_tables=${CMAKE_CURRENT_BINARY_DIR}/../../config/routing_tables.pickle>
322329
)
323330

324331
if (RSE_DM_CHAINED_PROVISIONING)
@@ -331,41 +338,83 @@ if (TFM_DUMMY_PROVISIONING)
331338
endif()
332339
endif()
333340

334-
generate_provisioning_bundle(
335-
cm_provisioning # bundle type
336-
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/create_cm_provisioning_bundle.py # script
337-
cm_provisioning_code # cmake executable target
338-
"${RSE_CM_BLOB_VERSION}" # blob version
339-
"CM" # valid LCS states
340-
"${RSE_SYMMETRIC_PROVISIONING}" # symmetric provisioning enabled
341-
"${RSE_PROVISIONING_CM_SIGNATURE_CONFIG}" # signature config
342-
"${RSE_CM_PROVISIONING_SIGNING_KEY}" # signature key (if asymmetric)
343-
${CMAKE_BINARY_DIR}/bin/keys/kprov_cm.bin # encryption key
344-
"" # PK not in ROM configuration (not for CM)
345-
"" # CM ROTPK index if PK not in ROM == CM_ROTPK (not for CM)
346-
"${RSE_PROVISIONING_CM_ENCRYPT_CODE_DATA}" # encrypt code and data
347-
ON # encrypt secret values
348-
"${CM_BUNDLE_SCRIPT_ARGS}" # OTP values args
349-
"${CM_BUNDLE_SCRIPT_DEPS}" # script specific CMake dependencies
350-
)
341+
if (NOT RSE_OTP_HAS_RSE_ID AND NOT RSE_OTP_HAS_ROUTING_TABLES)
342+
set(RSE_REQUIRES_UNIQUE_BUNDLES OFF)
343+
set(RSE_AMOUNT_LOOP_RANGE 0)
344+
else()
345+
set(RSE_REQUIRES_UNIQUE_BUNDLES ON)
346+
math(EXPR RSE_AMOUNT_LOOP_RANGE "${RSE_AMOUNT} - 1")
347+
endif()
351348

352-
generate_provisioning_bundle(
353-
dm_provisioning # bundle type
354-
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/create_dm_provisioning_bundle.py # script
355-
dm_provisioning_code # cmake executable target
356-
"${RSE_DM_BLOB_VERSION}" # blob version
357-
"DM" # valid LCS states
358-
"${RSE_SYMMETRIC_PROVISIONING}" # symmetric provisioning enabled
359-
"${MAIN_DM_BUNDLE_SIGNATURE_CONFIG}" # signature config
360-
"${RSE_CM_PROVISIONING_SIGNING_KEY}" # signature key (if asymmetric)
361-
${CMAKE_BINARY_DIR}/bin/keys/kprov_dm.bin # encryption key
362-
"${MAIN_DM_BUNDLE_NOT_IN_ROM_SIGNATURE_CONFIG}" # PK not in ROM configuration
363-
"${RSE_PROVISIONING_DM_SIGN_KEY_CM_ROTPK_IDX}" # CM ROTPK index if PK not in ROM == CM_ROTPK
364-
"${RSE_PROVISIONING_DM_ENCRYPT_CODE_DATA}" # encrypt code and data
365-
ON # encrypt secret values
366-
"${DM_BUNDLE_SCRIPT_ARGS}" # OTP values args
367-
"" # No additional dependencies
349+
foreach(RSE_ID RANGE ${RSE_AMOUNT_LOOP_RANGE})
350+
if (RSE_REQUIRES_UNIQUE_BUNDLES)
351+
set(BUNDLE_SUFFIX "_${RSE_ID}")
352+
else()
353+
set(BUNDLE_SUFFIX "")
354+
endif()
355+
set(CM_BUNDLE_SCRIPT_ARGS_TEMP
356+
${CM_BUNDLE_SCRIPT_ARGS}
357+
$<$<BOOL:${RSE_OTP_HAS_RSE_ID}>:--non_secret_cm:cm.rse_id=${RSE_ID}>
358+
)
359+
set(DM_BUNDLE_SCRIPT_ARGS_TEMP
360+
${DM_BUNDLE_SCRIPT_ARGS}
361+
$<$<BOOL:${RSE_OTP_HAS_ROUTING_TABLES}>:--routing_tables_idx=${RSE_ID}>
362+
)
363+
364+
generate_provisioning_bundle(
365+
"cm_provisioning${BUNDLE_SUFFIX}" # bundle type
366+
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/create_cm_provisioning_bundle.py # script
367+
cm_provisioning_code # cmake executable target
368+
"${RSE_CM_BLOB_VERSION}" # blob version
369+
"CM" # valid LCS states
370+
"${RSE_SYMMETRIC_PROVISIONING}" # symmetric provisioning enabled
371+
"${RSE_PROVISIONING_CM_SIGNATURE_CONFIG}" # signature config
372+
"${RSE_CM_PROVISIONING_SIGNING_KEY}" # signature key (if asymmetric)
373+
${CMAKE_BINARY_DIR}/bin/keys/kprov_cm.bin # encryption key
374+
"" # PK not in ROM configuration (not for CM)
375+
"" # CM ROTPK index if PK not in ROM == CM_ROTPK (not for CM)
376+
"${RSE_PROVISIONING_CM_ENCRYPT_CODE_DATA}" # encrypt code and data
377+
ON # encrypt secret values
378+
"${CM_BUNDLE_SCRIPT_ARGS_TEMP}" # OTP values args
379+
"${CM_BUNDLE_SCRIPT_DEPS}" # script specific CMake dependencies
380+
)
381+
382+
generate_provisioning_bundle(
383+
"dm_provisioning${BUNDLE_SUFFIX}" # bundle type
384+
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/create_dm_provisioning_bundle.py # script
385+
dm_provisioning_code # cmake executable target
386+
"${RSE_DM_BLOB_VERSION}" # blob version
387+
"DM" # valid LCS states
388+
"${RSE_SYMMETRIC_PROVISIONING}" # symmetric provisioning enabled
389+
"${MAIN_DM_BUNDLE_SIGNATURE_CONFIG}" # signature config
390+
"${RSE_CM_PROVISIONING_SIGNING_KEY}" # signature key (if asymmetric)
391+
${CMAKE_BINARY_DIR}/bin/keys/kprov_dm.bin # encryption key
392+
"${MAIN_DM_BUNDLE_NOT_IN_ROM_SIGNATURE_CONFIG}" # PK not in ROM configuration
393+
"${RSE_PROVISIONING_DM_SIGN_KEY_CM_ROTPK_IDX}" # CM ROTPK index if PK not in ROM == CM_ROTPK
394+
"${RSE_PROVISIONING_DM_ENCRYPT_CODE_DATA}" # encrypt code and data
395+
ON # encrypt secret values
396+
"${DM_BUNDLE_SCRIPT_ARGS_TEMP}" # OTP values args
397+
"" # No additional dependencies
398+
)
399+
400+
generate_provisioning_bundle(
401+
"combined_provisioning${BUNDLE_SUFFIX}" # bundle type
402+
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/create_combined_provisioning_bundle.py # script
403+
combined_provisioning_code # cmake executable target
404+
"${RSE_CM_BLOB_VERSION}" # blob version
405+
"CM;DM" # valid LCS states
406+
"${RSE_SYMMETRIC_PROVISIONING}" # symmetric provisioning enabled
407+
"${RSE_PROVISIONING_DM_SIGNATURE_CONFIG}" # signature config
408+
"${RSE_CM_PROVISIONING_SIGNING_KEY}" # signature key (if asymmetric)
409+
${CMAKE_BINARY_DIR}/bin/keys/kprov_cm.bin # encryption key
410+
"CM_ROTPK" # PK not in ROM configuration
411+
"${RSE_PROVISIONING_DM_SIGN_KEY_CM_ROTPK_IDX}" # CM ROTPK index if PK not in ROM == CM_ROTPK
412+
"${RSE_PROVISIONING_CM_ENCRYPT_CODE_DATA}" # encrypt code and data
413+
ON # encrypt secret values
414+
"${CM_BUNDLE_SCRIPT_ARGS_TEMP};${DM_BUNDLE_SCRIPT_ARGS_TEMP}" # OTP values args
415+
"${CM_BUNDLE_SCRIPT_DEPS}" # script specific CMake dependencies
368416
)
417+
endforeach()
369418

370419
if (RSE_DM_CHAINED_PROVISIONING)
371420
generate_provisioning_bundle(
@@ -387,24 +436,6 @@ if (TFM_DUMMY_PROVISIONING)
387436
)
388437
endif()
389438

390-
generate_provisioning_bundle(
391-
combined_provisioning # bundle type
392-
${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/create_combined_provisioning_bundle.py # script
393-
combined_provisioning_code # cmake executable target
394-
"${RSE_CM_BLOB_VERSION}" # blob version
395-
"CM;DM" # valid LCS states
396-
"${RSE_SYMMETRIC_PROVISIONING}" # symmetric provisioning enabled
397-
"${RSE_PROVISIONING_DM_SIGNATURE_CONFIG}" # signature config
398-
"${RSE_CM_PROVISIONING_SIGNING_KEY}" # signature key (if asymmetric)
399-
${CMAKE_BINARY_DIR}/bin/keys/kprov_cm.bin # encryption key
400-
"CM_ROTPK" # PK not in ROM configuration
401-
"${RSE_PROVISIONING_DM_SIGN_KEY_CM_ROTPK_IDX}" # CM ROTPK index if PK not in ROM == CM_ROTPK
402-
"${RSE_PROVISIONING_CM_ENCRYPT_CODE_DATA}" # encrypt code and data
403-
ON # encrypt secret values
404-
"${CM_BUNDLE_SCRIPT_ARGS};${DM_BUNDLE_SCRIPT_ARGS}" # OTP values args
405-
"${CM_BUNDLE_SCRIPT_DEPS}" # script specific CMake dependencies
406-
)
407-
408439
if (RSE_NON_ENDORSED_DM_PROVISIONING)
409440
generate_provisioning_bundle(
410441
plain_data_handler_provisioning # bundle type

platform/ext/target/arm/rse/common/rse_otp_layout.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "rse_otp_config.h"
1414
#include "lcm_otp_layout.h"
15+
#include "rse_routing_tables.h"
1516

1617
#ifdef __cplusplus
1718
extern "C" {
@@ -124,8 +125,7 @@ __PACKED_STRUCT rse_otp_dm_area_t {
124125
uint32_t config_flags;
125126

126127
#ifdef RSE_OTP_HAS_ROUTING_TABLES
127-
uint32_t rse_to_rse_sender_routing_table[RSE_ROUTING_TABLES_SIZE];
128-
uint32_t rse_to_rse_receiver_routing_table[RSE_ROUTING_TABLES_SIZE];
128+
struct rse_single_node_routing_tables_t routing_tables;
129129
#endif
130130

131131
#ifdef RSE_OTP_DM_SUBPLATFORM_ITEMS

platform/ext/target/arm/rse/common/scripts/create_combined_provisioning_bundle.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import provisioning_config as pc
3030
from provisioning_config import Provisioning_config
3131

32+
from routing_tables import Routing_tables
33+
3234

3335
def add_arguments(parser : argparse.ArgumentParser,
3436
prefix : str = "",
@@ -74,6 +76,9 @@ def parse_args(args : argparse.Namespace,
7476
kwargs['otp_config'].set_cm_offsets_automatically()
7577
kwargs['otp_config'].set_dm_offsets_automatically()
7678
kwargs['provisioning_config'].set_area_infos_from_otp_config(**kwargs)
79+
if 'routing_tables_idx' in kwargs:
80+
assert 'routing_tables' in kwargs
81+
kwargs['provisioning_config'].set_routing_tables(kwargs['routing_tables_idx'],kwargs['routing_tables'])
7782

7883
logger.debug(kwargs['provisioning_config'].non_secret_cm_layout)
7984
logger.debug(kwargs['provisioning_config'].secret_cm_layout)

platform/ext/target/arm/rse/common/scripts/create_dm_provisioning_bundle.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,36 @@
2626
import provisioning_config as pc
2727
from provisioning_config import Provisioning_config
2828

29+
import routing_tables as rt
30+
from routing_tables import Routing_tables
31+
2932

3033
def add_arguments(parser : argparse.ArgumentParser,
3134
prefix : str = "",
3235
required : bool = True,
3336
) -> None:
3437
oc.add_arguments(parser, prefix, required)
38+
rt.add_arguments(parser, prefix, required=False)
3539
pc.add_arguments(parser, prefix, required, regions=["non_secret_dm", "secret_dm"])
3640
pmc.add_arguments(parser, prefix, required,
3741
message_type="RSE_PROVISIONING_MESSAGE_TYPE_BLOB")
3842

3943
arg_utils.add_prefixed_argument(parser, "provisioning_code_elf", prefix, help="provisioning code image elf file",
4044
type=arg_utils.arg_type_elf_section(["CODE", "DATA"]), required=True)
45+
arg_utils.add_prefixed_argument(parser, "routing_tables_idx", prefix,
46+
help="The index within the system wide routing table to add to the provisioning bundle",
47+
type=int, required=False)
4148

4249
def parse_args(args : argparse.Namespace,
4350
prefix : str = "",
4451
default_field_owner : str = "dm"
4552
) -> dict:
4653
out = {}
4754
out |= dict(zip(["code", "elf_data"], arg_utils.get_arg(args, "provisioning_code_elf", prefix)))
55+
out |= arg_utils.parse_args_automatically(args, ["routing_tables_idx"], prefix)
4856

4957
out |= oc.parse_args(args, prefix=prefix)
58+
out |= rt.parse_args(args, prefix=prefix)
5059
out |= pc.parse_args(args, prefix=prefix, otp_config = out["otp_config"])
5160
out |= pmc.parse_args(args, prefix=prefix)
5261

@@ -79,6 +88,9 @@ def parse_args(args : argparse.Namespace,
7988

8089
kwargs['otp_config'].set_dm_offsets_automatically()
8190
kwargs['provisioning_config'].set_area_infos_from_otp_config(**kwargs)
91+
if 'routing_tables_idx' in kwargs:
92+
assert 'routing_tables' in kwargs
93+
kwargs['provisioning_config'].set_routing_tables(kwargs['routing_tables_idx'],kwargs['routing_tables'])
8294

8395
logger.debug(kwargs['provisioning_config'].non_secret_dm_layout)
8496
logger.debug(kwargs['provisioning_config'].secret_dm_layout)

platform/ext/target/arm/rse/common/scripts/modules/provisioning_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import arg_utils
1616
import argparse
1717
from otp_config import OTP_config
18+
from routing_tables import Routing_tables
1819
from cryptography.hazmat.primitives import hashes
1920

2021
import logging
@@ -396,6 +397,11 @@ def set_area_infos_from_otp_config(self,
396397
if dm_sets_dm_and_dynamic_area_size:
397398
self.__get_layout_field_and_set(False, "dynamic_area_info", otp_config.header.dynamic_area_info.to_bytes())
398399

400+
def set_routing_tables(self,
401+
idx : int,
402+
routing_tables : Routing_tables):
403+
self.non_secret_dm_layout.dm.routing_tables.set_value_from_bytes(routing_tables.get_rse_routing_table_bytes(idx))
404+
399405
script_description = """
400406
This script takes an instance of rse_provisioning_layout.h, rse_rotpk_policy.h,
401407
and a set of definitions (extracted from compile_commands.json), and creates a

0 commit comments

Comments
 (0)