Skip to content

Commit b8ac98c

Browse files
lpawelczumarcor
authored andcommitted
f4pga: add f4pga utils command support and add auxDir builtin variable
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
1 parent 103ba42 commit b8ac98c

File tree

15 files changed

+211
-32
lines changed

15 files changed

+211
-32
lines changed

f4pga/flows/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from f4pga.flows.stage import Stage
4343
from f4pga.flows.common import set_verbosity_level, sfprint
4444
from f4pga.flows.argparser import setup_argparser
45-
from f4pga.flows.commands import cmd_build, cmd_show_dependencies, f4pga_done
45+
from f4pga.flows.commands import cmd_build, cmd_show_dependencies, cmd_run_util, f4pga_done
4646

4747

4848
def platform_stages(platform_flow, r_env):
@@ -78,6 +78,10 @@ def main():
7878
cmd_show_dependencies(args)
7979
f4pga_done()
8080

81+
if args.command == "utils":
82+
cmd_run_util(args)
83+
f4pga_done()
84+
8185
sfprint(0, "Please use a command.\nUse `--help` flag to learn more.")
8286
f4pga_done()
8387

f4pga/flows/argparser.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#
1818
# SPDX-License-Identifier: Apache-2.0
1919

20-
from argparse import ArgumentParser, Namespace
20+
from argparse import ArgumentParser, Namespace, REMAINDER
2121
from re import finditer as re_finditer
2222

2323

@@ -67,6 +67,14 @@ def p_setup_show_dep_parser(parser: ArgumentParser):
6767
p_add_flow_arg(parser)
6868

6969

70+
def _setup_utils_parser(parser: ArgumentParser):
71+
parser.add_argument("--function", "-f", metavar="fun_name", type=str, help="Run specific funtion from given module")
72+
73+
parser.add_argument("util", metavar="util_name", type=str, help="Name of the script to call")
74+
75+
parser.add_argument("util_args", metavar="util_args", nargs=REMAINDER, type=str, help="Arguments for called script")
76+
77+
7078
def setup_argparser():
7179
"""
7280
Set up argument parser for the program.
@@ -82,6 +90,9 @@ def setup_argparser():
8290
show_dep = subparsers.add_parser("showd", description="Show the value(s) assigned to a dependency")
8391
p_setup_show_dep_parser(show_dep)
8492

93+
run_util = subparsers.add_parser("utils", description="Run utility script")
94+
_setup_utils_parser(run_util)
95+
8596
return parser
8697

8798

f4pga/flows/commands.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from f4pga.flows.common import (
3131
bin_dir_path,
3232
share_dir_path,
33+
aux_dir_path,
3334
F4PGAException,
3435
ResolutionEnv,
3536
fatal,
@@ -50,6 +51,7 @@
5051
from f4pga.flows.flow import Flow
5152
from f4pga.flows.stage import Stage
5253
from f4pga.flows.inspector import get_module_info
54+
from f4pga.util import Util
5355

5456

5557
ROOT = Path(__file__).resolve().parent
@@ -121,7 +123,7 @@ def f4pga_done():
121123
def setup_resolution_env():
122124
"""Sets up a ResolutionEnv with default built-ins."""
123125

124-
r_env = ResolutionEnv({"shareDir": share_dir_path, "binDir": bin_dir_path})
126+
r_env = ResolutionEnv({"shareDir": share_dir_path, "binDir": bin_dir_path, "auxDir": aux_dir_path})
125127

126128
def _noisy_warnings():
127129
"""
@@ -299,3 +301,10 @@ def cmd_show_dependencies(args: Namespace):
299301
sfprint(0, prstr)
300302

301303
set_verbosity_level(-1)
304+
305+
306+
def cmd_run_util(args: Namespace):
307+
"""Run utility script"""
308+
309+
util = Util(args.util, args.function, args.util_args)
310+
util.exec()

f4pga/flows/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
bin_dir_path = str(Path(sys_argv[0]).resolve().parent.parent)
3232
share_dir_path = str(F4PGA_SHARE_DIR)
33+
aux_dir_path = str(Path(__file__).resolve().parent.parent / "aux")
3334

3435

3536
class F4PGAException(Exception):

f4pga/flows/flow.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from colorama import Fore, Style
2323

24-
from f4pga.flows.common import deep, sfprint, bin_dir_path, share_dir_path, F4PGAException
24+
from f4pga.flows.common import deep, sfprint, bin_dir_path, share_dir_path, aux_dir_path, F4PGAException
2525
from f4pga.flows.cache import F4Cache
2626
from f4pga.flows.flow_config import FlowConfig
2727
from f4pga.flows.runner import ModRunCtx, module_map, module_exec
@@ -103,7 +103,9 @@ def _config_mod_runctx(
103103
elif config_paths.get(prod.name):
104104
produces[prod.name] = config_paths[prod.name]
105105

106-
return ModRunCtx(share_dir_path, bin_dir_path, {"takes": takes, "produces": produces, "values": values})
106+
return ModRunCtx(
107+
share_dir_path, bin_dir_path, aux_dir_path, {"takes": takes, "produces": produces, "values": values}
108+
)
107109

108110
@staticmethod
109111
def _cache_deps(path: str, f4cache: F4Cache):

f4pga/flows/module.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class ModuleContext:
7474

7575
share: str # Absolute path to F4PGA's share directory
7676
bin: str # Absolute path to F4PGA's bin directory
77+
aux: str # Absolute path to F4PGA's aux directory
7778
takes: SimpleNamespace # Maps symbolic dependency names to relative paths.
7879
produces: SimpleNamespace # Contains mappings for explicitely specified dependencies.
7980
# Useful mostly for checking for on-demand optional outputs (such as logs) with
@@ -101,7 +102,7 @@ def _getreqmaybe(self, obj, deps: "list[str]", deps_cfg: "dict[str, ]"):
101102
setattr(obj, name, self.r_env.resolve(value))
102103

103104
# `config` should be a dictionary given as modules input.
104-
def __init__(self, module: Module, config: "dict[str, ]", r_env: ResolutionEnv, share: str, bin: str):
105+
def __init__(self, module: Module, config: "dict[str, ]", r_env: ResolutionEnv, share: str, bin: str, aux: str):
105106
self.module_name = module.name
106107
self.takes = SimpleNamespace()
107108
self.produces = SimpleNamespace()
@@ -110,6 +111,7 @@ def __init__(self, module: Module, config: "dict[str, ]", r_env: ResolutionEnv,
110111
self.r_env = r_env
111112
self.share = share
112113
self.bin = bin
114+
self.aux = aux
113115

114116
self._getreqmaybe(self.takes, module.takes, config["takes"])
115117
self._getreqmaybe(self.values, module.values, config["values"])

f4pga/flows/platforms.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,13 @@ ql-eos-s3:
282282
PINMAP_FILE: '${shareDir}/arch/ql-eos-s3_wlcsp/pinmap_${package}.csv'
283283
PCF_FILE: '${:pcf}'
284284
PYTHON3: '${python3}'
285-
UTILS_PATH: '${shareDir}/scripts'
285+
UTILS_PATH: '${auxDir}/utils'
286286
prepare_sdc:
287287
module: 'generic_script_wrapper'
288288
params:
289289
stage_name: prepare_sdc
290290
interpreter: '${python3}'
291-
script: ['-m', 'f4pga.utils.quicklogic.process_sdc_constraints']
291+
script: "${auxDir}/utils/quicklogic/process_sdc_constraints.py"
292292
outputs:
293293
sdc:
294294
mode: file
@@ -300,7 +300,7 @@ ql-eos-s3:
300300
sdc-out: '${:eblif[noext]}.sdc'
301301
pcf: '${:pcf}'
302302
pin-map: ''
303-
$PYTHONPATH: '${shareDir}/scripts/'
303+
$PYTHONPATH: "${auxDir}/utils/quicklogic"
304304
pack:
305305
module: 'pack'
306306
values:
@@ -342,7 +342,7 @@ ql-eos-s3:
342342
params:
343343
stage_name: ioplace
344344
interpreter: '${python3}'
345-
script: ['-m', 'f4pga.utils.quicklogic.pp3.create_ioplace']
345+
script: "${auxDir}/utils/quicklogic/pp3/create_ioplace.py"
346346
outputs:
347347
io_place:
348348
mode: stdout
@@ -352,13 +352,13 @@ ql-eos-s3:
352352
net: '${:net}'
353353
pcf: '${:pcf}'
354354
map: '${shareDir}/arch/ql-eos-s3_wlcsp/pinmap_${package}.csv'
355-
$PYTHONPATH: '${shareDir}/scripts/'
355+
$PYTHONPATH: "${auxDir}/utils/"
356356
place_constraints:
357357
module: 'generic_script_wrapper'
358358
params:
359359
stage_name: place_constraints
360360
interpreter: '${python3}'
361-
script: ['-m', 'f4pga.utils.quicklogic.pp3.create_place_constraints']
361+
script: "${auxDir}/utils/quicklogic/pp3/create_place_constraints.py"
362362
outputs:
363363
place_constraints:
364364
mode: stdout
@@ -367,15 +367,15 @@ ql-eos-s3:
367367
blif: '${:eblif}'
368368
map: '${shareDir}/arch/ql-eos-s3_wlcsp/clkmap_${package}.csv'
369369
i: '${:io_place}'
370-
$PYTHONPATH: '${shareDir}/scripts/'
370+
$PYTHONPATH: "${auxDir}/utils/"
371371
place:
372372
module: 'place'
373373
iomux_jlink:
374374
module: 'generic_script_wrapper'
375375
params:
376376
stage_name: iomux_jlink
377377
interpreter: '${python3}'
378-
script: ['-m', 'f4pga.utils.quicklogic.pp3.eos-s3.iomux_config']
378+
script: "${auxDir}/utils/quicklogic/pp3/eos-s3/iomux_config.py"
379379
outputs:
380380
iomux_jlink:
381381
mode: stdout
@@ -385,13 +385,13 @@ ql-eos-s3:
385385
pcf: '${:pcf}'
386386
map: '${shareDir}/arch/ql-eos-s3_wlcsp/pinmap_${package}.csv'
387387
output-format: jlink
388-
$PYTHONPATH: '${shareDir}/scripts/'
388+
$PYTHONPATH: "${auxDir}/utils/"
389389
iomux_openocd:
390390
module: 'generic_script_wrapper'
391391
params:
392392
stage_name: iomux_openocd
393393
interpreter: '${python3}'
394-
script: ['-m', 'f4pga.utils.quicklogic.pp3.eos-s3.iomux_config']
394+
script: "${auxDir}/utils/quicklogic/pp3/eos-s3/iomux_config.py"
395395
outputs:
396396
iomux_openocd:
397397
mode: stdout
@@ -401,13 +401,13 @@ ql-eos-s3:
401401
pcf: '${:pcf}'
402402
map: '${shareDir}/arch/ql-eos-s3_wlcsp/pinmap_${package}.csv'
403403
output-format: openocd
404-
$PYTHONPATH: '${shareDir}/scripts/'
404+
$PYTHONPATH: "${auxDir}/utils/"
405405
iomux_binary:
406406
module: 'generic_script_wrapper'
407407
params:
408408
stage_name: iomux_binary
409409
interpreter: '${python3}'
410-
script: ['-m', 'f4pga.utils.quicklogic.pp3.eos-s3.iomux_config']
410+
script: "${auxDir}/utils/quicklogic/pp3/eos-s3/iomux_config.py"
411411
outputs:
412412
iomux_binary:
413413
mode: stdout
@@ -417,7 +417,7 @@ ql-eos-s3:
417417
pcf: '${:pcf}'
418418
map: '${shareDir}/arch/ql-eos-s3_wlcsp/pinmap_${package}.csv'
419419
output-format: binary
420-
$PYTHONPATH: '${shareDir}/scripts/'
420+
$PYTHONPATH: "${auxDir}/utils/"
421421
route:
422422
module: 'route'
423423
values:
@@ -616,6 +616,7 @@ ql-eos-s3:
616616
$FPGA_FAM: eos-s3
617617
$PATH: '${shareDir}/../../conda/envs/eos-s3/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
618618
$BIN_DIR_PATH: '${binDir}'
619+
$PYTHONPATH: "${auxDir}/utils/quicklogic/pp3"
619620

620621

621622
ql-k4n8_fast: &ql-k4n8

f4pga/flows/runner.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ def get_module(path: str):
7373
class ModRunCtx:
7474
share: str
7575
bin: str
76+
aux: str
7677
config: "dict[str, ]"
7778

78-
def __init__(self, share: str, bin: str, config: "dict[str, ]"):
79+
def __init__(self, share: str, bin: str, aux: str, config: "dict[str, ]"):
7980
self.share = share
8081
self.bin = bin
82+
self.aux = aux
8183
self.config = config
8284

8385
def make_r_env(self):
@@ -110,7 +112,7 @@ def module_io(module: Module):
110112

111113
def module_map(module: Module, ctx: ModRunCtx):
112114
try:
113-
mod_ctx = ModuleContext(module, ctx.config, ctx.make_r_env(), ctx.share, ctx.bin)
115+
mod_ctx = ModuleContext(module, ctx.config, ctx.make_r_env(), ctx.share, ctx.bin, ctx.aux)
114116
except Exception as e:
115117
raise ModuleFailException(module.name, "map", e)
116118

@@ -119,7 +121,7 @@ def module_map(module: Module, ctx: ModRunCtx):
119121

120122
def module_exec(module: Module, ctx: ModRunCtx):
121123
try:
122-
mod_ctx = ModuleContext(module, ctx.config, ctx.make_r_env(), ctx.share, ctx.bin)
124+
mod_ctx = ModuleContext(module, ctx.config, ctx.make_r_env(), ctx.share, ctx.bin, ctx.aux)
123125
except Exception as e:
124126
raise ModuleFailException(module.name, "exec", e)
125127

f4pga/fpga_map.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"xc7": {
3+
"manufacturer": "xilinx"
4+
},
5+
"eos-s3": {
6+
"manufacturer": "quicklogic",
7+
"architecture": "pp3"
8+
},
9+
"qlf_k4n8": {
10+
"manufacturer": "quicklogic"
11+
}
12+
}

f4pga/setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def get_requirements(file: Path) -> List[str]:
8282
url="https://github.com/chipsalliance/f4pga",
8383
package_dir={"f4pga": "."},
8484
package_data={
85+
"f4pga": [
86+
"fpga_map.json",
87+
],
8588
"f4pga.flows": [
8689
"*.yml",
8790
],

0 commit comments

Comments
 (0)