Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions docs/opentitan/romtool.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Supported input formats:
## Usage

````text
usage: romtool.py [-h] -c CFG [-o OUTPUT] [-i ROM_ID] [-z SIZE]
[-f {HEX,BIN,SVMEM,VMEM}] [-s] [-v] [-d]
usage: romtool.py [-h] -c CFG [-o OUTPUT] [-D] [-f {HEX,BIN,SVMEM,VMEM}]
[-i ROM_ID] [-s] [-z SIZE] [-v] [-d]
rom

QEMU OT tool to generate a scrambled ROM image.
Expand All @@ -27,11 +27,12 @@ Files:
-o, --output OUTPUT output ROM image file

Parameters:
-i, --rom-id ROM_ID ROM image identifier
-z, --rom-size SIZE ROM image size in bytes (accepts Ki suffix)
-D, --digest Show the ROM digest
-f, --output-format {HEX,BIN,SVMEM,VMEM}
Output file format (default: HEX)
-i, --rom-id ROM_ID ROM image identifier
-s, --subst-perm Enable legacy mode with S&P mode
-z, --rom-size SIZE ROM image size in bytes (accepts Ki suffix)

Extras:
-v, --verbose increase verbosity
Expand All @@ -43,6 +44,8 @@ Extras:
* `-c` specify a QEMU [configuration file](otcfg.md) from which to read all the cryptographic
constants. See [`cfggen.py`](cfggen.md) tool to generate such a file.

* `-D` show the loaded or computed ROM digest as an hexadecimal string

* `-d` only useful to debug the script, reports any Python traceback to the standard error stream.

* `-f` output file format. `HEX` format always output scrambled/SEC-DED data, `SVMEM` specifies a
Expand Down
12 changes: 11 additions & 1 deletion python/qemu/ot/rom/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ def digest(self) -> bytes:
self._make_digest()
return self._digest

@property
def hexdigest(self) -> str:
"""Return the current digest of the ROM image.

Digest is computed on-the-fly if not already known.

:return: the digest as a hexa string.
"""
return hexlify(self.digest).decode()

@property
def key(self) -> Optional[int]:
"""Key observer."""
Expand Down Expand Up @@ -395,7 +405,7 @@ def _load_vmem(self, rfp: BinaryIO, size: Optional[int]) -> None:
line = line.strip()
if not line.startswith(b'@'):
continue
parts = re.split(r'\s+', line[1:])
parts = re.split(rb'\s+', line[1:])
address_str = parts[0]
data_str = parts[1:]
scrambled_data = all(len(d) in (9, 10) for d in data_str)
Expand Down
15 changes: 10 additions & 5 deletions scripts/opentitan/romtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ def main():
help='output ROM image file')

params = argparser.add_argument_group(title='Parameters')
params.add_argument('-i', '--rom-id', type=int,
help='ROM image identifier')
params.add_argument('-z', '--rom-size', metavar='SIZE',
type=HexInt.xparse,
help='ROM image size in bytes (accepts Ki suffix)')
params.add_argument('-D', '--digest', action='store_true',
help='Show the ROM digest')
params.add_argument('-f', '--output-format', choices=out_formats,
default=out_formats[0],
help=f'Output file format '
f'(default: {out_formats[0]})')
params.add_argument('-i', '--rom-id', type=int,
help='ROM image identifier')
params.add_argument('-s', '--subst-perm', action='store_true',
help='Enable legacy mode with S&P mode')
params.add_argument('-z', '--rom-size', metavar='SIZE',
type=HexInt.xparse,
help='ROM image size in bytes (accepts Ki suffix)')

extra = argparser.add_argument_group(title='Extras')
extra.add_argument('-v', '--verbose', action='count',
Expand All @@ -74,6 +76,9 @@ def main():
rom_img.load_config(args.config, args.rom_id)
rom_img.load(args.rom[0], args.rom_size)

if args.digest:
print('Digest:', rom_img.hexdigest)

with open(args.output, 'wb') if args.output else \
sys.stdout.buffer as wfp:
rom_img.save(wfp, args.output_format)
Expand Down
Loading