Skip to content

Commit 926faf1

Browse files
committed
[ot] scripts/opentitan: cfggen.py: define a list of supported tops
QEMU only supports a known list of OT machine, ensure the specified top matches one of the supported machine. Signed-off-by: Emmanuel Blot <eblot@rivosinc.com>
1 parent 2ce9880 commit 926faf1

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

docs/opentitan/cfggen.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ the QEMU binary.
1111
## Usage
1212

1313
````text
14-
usage: cfggen.py [-h] [-o CFG] [-T TOP] [-c SV] [-l SV] [-t HJSON] [-s SOCID]
15-
[-C COUNT] [-v] [-d]
14+
usage: cfggen.py [-h] -T {Darjeeling,EarlGrey} [-o CFG] [-c SV] [-l SV]
15+
[-t HJSON] [-s SOCID] [-C COUNT] [-v] [-d]
1616
TOPDIR
1717
1818
OpenTitan QEMU configuration file generator.
@@ -22,26 +22,22 @@ options:
2222
2323
Files:
2424
TOPDIR OpenTitan top directory
25-
-o CFG, --out CFG Filename of the config file to generate
26-
-T TOP, --top TOP OpenTitan Top name (default: darjeeling)
27-
-c SV, --otpconst SV OTP Constant SV file (default: auto)
28-
-l SV, --lifecycle SV
29-
LifeCycle SV file (default: auto)
30-
-t HJSON, --topcfg HJSON
31-
OpenTitan top HJSON config file (default: auto)
25+
-T, --top {Darjeeling,EarlGrey}
26+
OpenTitan top name
27+
-o, --out CFG Filename of the config file to generate
28+
-c, --otpconst SV OTP Constant SV file (default: auto)
29+
-l, --lifecycle SV LifeCycle SV file (default: auto)
30+
-t, --topcfg HJSON OpenTitan top HJSON config file (default: auto)
3231
3332
Modifiers:
34-
-s SOCID, --socid SOCID
35-
SoC identifier, if any
36-
-C COUNT, --count COUNT
37-
SoC count (default: 1)
33+
-s, --socid SOCID SoC identifier, if any
34+
-C, --count COUNT SoC count (default: 1)
3835
3936
Extras:
4037
-v, --verbose increase verbosity
4138
-d, --debug enable debug mode
4239
````
4340

44-
4541
### Arguments
4642

4743
`TOPDIR` is a required positional argument which should point to the top-level directory of the
@@ -62,7 +58,7 @@ parse, each of which can be overidden with options `-c`, `-l` and `-t`.
6258
* `-s` specify a SoC identifier for OT platforms with mulitple SoCs
6359

6460
* `-T` specify the OpenTitan _top_ name, such as `Darjeeling`, `EarlGrey`, ... This option is
65-
case-insensitive.
61+
mandatory.
6662

6763
* `-t` alternative path to the `top_<top>.gen.hjson` file
6864

@@ -72,5 +68,5 @@ parse, each of which can be overidden with options `-c`, `-l` and `-t`.
7268
### Examples
7369

7470
````sh
75-
./scripts/opentitan/cfggen.py ../opentitan-integrated -o opentitan.cfg
71+
./scripts/opentitan/cfggen.py ../opentitan -T EarlGrey -o opentitan.cfg
7672
````

scripts/opentitan/cfggen.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
# Copyright (c) 2024 Rivos, Inc.
4+
# Copyright (c) 2025 lowRISC contributors.
45
# SPDX-License-Identifier: Apache2
56

67
"""OpenTitan QEMU configuration file generator.
@@ -223,17 +224,20 @@ def _generate_life_cycle(self, cfg: ConfigParser,
223224
def main():
224225
"""Main routine"""
225226
debug = True
226-
default_top = 'Darjeeling'
227+
top_map = {
228+
'Darjeeling': 'dj',
229+
'EarlGrey': 'eg',
230+
}
227231
try:
228232
desc = sys.modules[__name__].__doc__.split('.', 1)[0].strip()
229233
argparser = ArgumentParser(description=f'{desc}.')
230234
files = argparser.add_argument_group(title='Files')
231235
files.add_argument('opentitan', nargs=1, metavar='TOPDIR',
232236
help='OpenTitan top directory')
237+
files.add_argument('-T', '--top', choices=top_map.keys(), required=True,
238+
help='OpenTitan top name')
233239
files.add_argument('-o', '--out', metavar='CFG',
234240
help='Filename of the config file to generate')
235-
files.add_argument('-T', '--top', default=default_top,
236-
help=f'OpenTitan Top name (default: {default_top})')
237241
files.add_argument('-c', '--otpconst', metavar='SV',
238242
help='OTP Constant SV file (default: auto)')
239243
files.add_argument('-l', '--lifecycle', metavar='SV',
@@ -263,13 +267,9 @@ def main():
263267
if not isdir(topdir):
264268
argparser.error('Invalid OpenTitan top directory')
265269
ot_dir = normpath(topdir)
266-
top = f'top_{args.top.lower()}'
267-
if args.top.lower() != default_top.lower():
268-
var = ''.join(w[0]
269-
for w in camel_to_snake_case(args.top).split('_'))
270-
else:
271-
var = 'dj'
272-
270+
ltop = args.top.lower()
271+
top = f'top_{ltop}'
272+
var = top_map[args.top]
273273
if not args.topcfg:
274274
cfgpath = joinpath(ot_dir, f'hw/{top}/data/autogen/{top}.gen.hjson')
275275
else:

0 commit comments

Comments
 (0)