Skip to content

Commit 8a4ea03

Browse files
AlexJones0luismarques
authored andcommitted
[ot] scripts/opentitan: cfggen.py: Load OTP scrambling keys from SV
Parse the hard-coded OTP scrambling key constants out of the relevant SV partition SV files into the generated OT configuration files, so that they can be used in the OTP. Signed-off-by: Alex Jones <[email protected]>
1 parent 42cfb1a commit 8a4ea03

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

python/qemu/ot/otp/const.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,16 @@ def get_digests(self) -> list[str]:
203203
except KeyError as exc:
204204
raise ValueError("No 'digest' enum found") from exc
205205

206+
def get_scrambling_keys(self) -> list[str]:
207+
"""Return a list of parsed scrambling keys for secret partitions."""
208+
try:
209+
return list(self._enums['key'])
210+
except KeyError as exc:
211+
raise ValueError("No 'key' enum found") from exc
212+
206213
def get_digest_pair(self, name: str, prefix: str) -> dict[str, str]:
207214
"""Return a dict of digest pair.
208-
:param name: one of the enumerated values, see #get_enums
215+
:param name: one of the enumerated values, see #get_digests
209216
:param prefix: the prefix to add to each dict key.
210217
"""
211218
try:
@@ -221,6 +228,22 @@ def get_digest_pair(self, name: str, prefix: str) -> dict[str, str]:
221228
odict[oname] = values[idx]
222229
return odict
223230

231+
def get_scrambling_key(self, name: str) -> str:
232+
"""Get the value of a scrambling key.
233+
:param name: One of the enumerated values, see #get_scrambling_keys
234+
"""
235+
try:
236+
idx = self._enums['key'][name]
237+
except KeyError as exc:
238+
raise ValueError(f'Unknown scrambling key {name}') from exc
239+
try:
240+
key_values = self._consts['key']
241+
except KeyError as exc:
242+
raise ValueError('No scrambling key constants found') from exc
243+
if len(key_values) <= idx:
244+
raise ValueError(f'No such key {name} in the key array') from exc
245+
return key_values[idx]
246+
224247
def get_partition_inv_defaults(self, partition: int) -> Optional[str]:
225248
"""Return the invalid default values for a partition, if any.
226249
Partitions with only digest defaults are considered without default

scripts/opentitan/cfggen.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ def prepare(self) -> None:
313313
continue
314314
pair = self._otpconst.get_digest_pair(digest, prefix)
315315
otp_ctrl.update(pair)
316+
for key in self._otpconst.get_scrambling_keys():
317+
key_value = self._otpconst.get_scrambling_key(key)
318+
key = key.removesuffix("key") + "_scramble_key"
319+
otp_ctrl[key] = key_value
316320
idx = 0
317321
while True:
318322
try:

0 commit comments

Comments
 (0)