Skip to content

Commit c607b33

Browse files
michalek-norlubos
authored andcommitted
cmake: provision: Change provision_hex to account for larger LCS
Changed the provisioning script to account for larger Life Cycle State structures. Since we can only do word writes in nRF54LX life cycle states needs to be stored in words. This increased the LCS struct by 1 word requiring us to change the way the provisioning script works. This change adds the LCS size as a value to the CMake file which uses the SOC to decide which size the LCS struct is which is then passed to the python script through the `--lcs-state-size` argument. Ref. NCSDK-25306 Signed-off-by: Mateusz Michalek <[email protected]> Signed-off-by: Sigurd Hellesvik <[email protected]>
1 parent 817d645 commit c607b33

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

cmake/sysbuild/provision_hex.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ function(provision application prefix_name)
1818
set(PROVISION_HEX_NAME ${prefix_name}provision.hex)
1919
set(PROVISION_HEX ${CMAKE_BINARY_DIR}/${PROVISION_HEX_NAME})
2020

21+
# This calculation is based on the LCS cycle state datacycle state data struct in bl_storage.h
22+
if(CONFIG_SOC_SERIES_NRF54LX)
23+
set(lcs_state_struct_size 0x10) # 4 * 4 bytes
24+
else()
25+
set(lcs_state_struct_size 0x8) # 4 * 2 bytes
26+
endif()
27+
2128
if(CONFIG_SECURE_BOOT)
2229
if(DEFINED CONFIG_SB_MONOTONIC_COUNTER)
2330
set(monotonic_counter_arg
@@ -96,6 +103,7 @@ function(provision application prefix_name)
96103
${monotonic_counter_arg}
97104
${no_verify_hashes_arg}
98105
${mcuboot_counters_slots}
106+
--lcs-state-size ${lcs_state_struct_size}
99107
DEPENDS
100108
${PROVISION_KEY_DEPENDS}
101109
${PROVISION_DEPENDS}
@@ -118,6 +126,7 @@ function(provision application prefix_name)
118126
--max-size ${CONFIG_PM_PARTITION_SIZE_PROVISION}
119127
${mcuboot_counters_num}
120128
${mcuboot_counters_slots}
129+
--lcs-state-size ${lcs_state_struct_size}
121130
DEPENDS
122131
${PROVISION_KEY_DEPENDS}
123132
WORKING_DIRECTORY

scripts/bootloader/provision.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
from hashlib import sha256
1414
import os
1515

16-
# Size of LCS storage and implementation ID in OTP in bytes
17-
LCS_STATE_SIZE = 0x8
16+
# Size of implementation ID in OTP in bytes
1817
IMPLEMENTATION_ID_SIZE = 0x20
19-
NUM_BYTES_PROVISIONED_ELSEWHERE = LCS_STATE_SIZE + IMPLEMENTATION_ID_SIZE
2018

2119
# These variable names and values are copied from bl_storage.h and
2220
# should be kept in sync
@@ -57,7 +55,7 @@ def add_hw_counters(provision_data, num_counter_slots_version, mcuboot_counters_
5755
return provision_data
5856

5957

60-
def generate_mcuboot_only_provision_hex_file(provision_address, output, max_size, mcuboot_counters_slots):
58+
def generate_mcuboot_only_provision_hex_file(provision_address, output, max_size, mcuboot_counters_slots, lcs_state_sz):
6159
# This function generates a .hex file with the provisioned data
6260
# for the uncommon use-case where MCUBoot is present, but NSIB is
6361
# not.
@@ -72,7 +70,7 @@ def generate_mcuboot_only_provision_hex_file(provision_address, output, max_size
7270
# which we set to 0 and which will be used by MCUBoot at runtime
7371
# to calculate where the counter are located.
7472

75-
num_bytes_in_lcs = LCS_STATE_SIZE
73+
num_bytes_in_lcs = lcs_state_sz
7674
num_bytes_in_implementation_id = IMPLEMENTATION_ID_SIZE
7775
num_bytes_in_s0_address = 4
7876
num_bytes_in_s1_address = 4
@@ -132,6 +130,8 @@ def parse_args():
132130
help="The MCUBOOT bootloader is used without the NSIB bootloader. Only the provision address, the MCUBOOT counters and the MCUBOOT counters slots arguments will be used.")
133131
parser.add_argument('--mcuboot-counters-slots', required=False, type=int, default=0,
134132
help='Number of monotonic counter slots for every MCUBOOT counter.')
133+
parser.add_argument('--lcs-state-size', required=False, type=lambda x: int(x, 0), default=0x8,
134+
help='Size of life cycle state data structure in bytes.')
135135
return parser.parse_args()
136136

137137

@@ -155,6 +155,9 @@ def get_hashes(public_key_files, verify_hashes):
155155
def main():
156156
args = parse_args()
157157

158+
lcs_state_size = args.lcs_state_size
159+
num_bytes_provisioned_elsewhere = lcs_state_size + IMPLEMENTATION_ID_SIZE
160+
158161
if not args.mcuboot_only and args.s0_addr is None:
159162
raise RuntimeError("Either --mcuboot-only or --s0-addr must be specified")
160163

@@ -163,7 +166,8 @@ def main():
163166
provision_address=args.provision_addr,
164167
output=args.output,
165168
max_size=args.max_size,
166-
mcuboot_counters_slots=args.mcuboot_counters_slots
169+
mcuboot_counters_slots=args.mcuboot_counters_slots,
170+
lcs_state_sz=lcs_state_size
167171
)
168172
return
169173

@@ -174,8 +178,8 @@ def main():
174178
# The LCS and implementation ID is stored in the OTP before the
175179
# rest of the provisioning data so add it to the given base
176180
# address
177-
provision_address = args.provision_addr + NUM_BYTES_PROVISIONED_ELSEWHERE
178-
max_size = args.max_size - NUM_BYTES_PROVISIONED_ELSEWHERE
181+
provision_address = args.provision_addr + num_bytes_provisioned_elsewhere
182+
max_size = args.max_size - num_bytes_provisioned_elsewhere
179183

180184
hashes = []
181185
if args.public_key_files:

0 commit comments

Comments
 (0)