Skip to content

Commit

Permalink
f4pga: add f4pga utils command support and add auxDir builtin variable
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
  • Loading branch information
lpawelcz authored and umarcor committed Sep 6, 2022
1 parent 021796a commit c5b336a
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 32 deletions.
6 changes: 5 additions & 1 deletion f4pga/flows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from f4pga.flows.stage import Stage
from f4pga.flows.common import set_verbosity_level, sfprint
from f4pga.flows.argparser import setup_argparser
from f4pga.flows.commands import cmd_build, cmd_show_dependencies, f4pga_done
from f4pga.flows.commands import cmd_build, cmd_show_dependencies, cmd_run_util, f4pga_done


def platform_stages(platform_flow, r_env):
Expand Down Expand Up @@ -78,6 +78,10 @@ def main():
cmd_show_dependencies(args)
f4pga_done()

if args.command == "utils":
cmd_run_util(args)
f4pga_done()

sfprint(0, "Please use a command.\nUse `--help` flag to learn more.")
f4pga_done()

Expand Down
13 changes: 12 additions & 1 deletion f4pga/flows/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
# SPDX-License-Identifier: Apache-2.0

from argparse import ArgumentParser, Namespace
from argparse import ArgumentParser, Namespace, REMAINDER
from re import finditer as re_finditer


Expand Down Expand Up @@ -67,6 +67,14 @@ def p_setup_show_dep_parser(parser: ArgumentParser):
p_add_flow_arg(parser)


def _setup_utils_parser(parser: ArgumentParser):
parser.add_argument("--function", "-f", metavar="fun_name", type=str, help="Run specific funtion from given module")

parser.add_argument("util", metavar="util_name", type=str, help="Name of the script to call")

parser.add_argument("util_args", metavar="util_args", nargs=REMAINDER, type=str, help="Arguments for called script")


def setup_argparser():
"""
Set up argument parser for the program.
Expand All @@ -82,6 +90,9 @@ def setup_argparser():
show_dep = subparsers.add_parser("showd", description="Show the value(s) assigned to a dependency")
p_setup_show_dep_parser(show_dep)

run_util = subparsers.add_parser("utils", description="Run utility script")
_setup_utils_parser(run_util)

return parser


Expand Down
11 changes: 10 additions & 1 deletion f4pga/flows/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from f4pga.flows.common import (
bin_dir_path,
share_dir_path,
aux_dir_path,
F4PGAException,
ResolutionEnv,
fatal,
Expand All @@ -50,6 +51,7 @@
from f4pga.flows.flow import Flow
from f4pga.flows.stage import Stage
from f4pga.flows.inspector import get_module_info
from f4pga.util import Util


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

r_env = ResolutionEnv({"shareDir": share_dir_path, "binDir": bin_dir_path})
r_env = ResolutionEnv({"shareDir": share_dir_path, "binDir": bin_dir_path, "auxDir": aux_dir_path})

def _noisy_warnings():
"""
Expand Down Expand Up @@ -301,3 +303,10 @@ def cmd_show_dependencies(args: Namespace):
sfprint(0, prstr)

set_verbosity_level(-1)


def cmd_run_util(args: Namespace):
"""Run utility script"""

util = Util(args.util, args.function, args.util_args)
util.exec()
1 change: 1 addition & 0 deletions f4pga/flows/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

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


class F4PGAException(Exception):
Expand Down
6 changes: 4 additions & 2 deletions f4pga/flows/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from colorama import Fore, Style

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

return ModRunCtx(share_dir_path, bin_dir_path, {"takes": takes, "produces": produces, "values": values})
return ModRunCtx(
share_dir_path, bin_dir_path, aux_dir_path, {"takes": takes, "produces": produces, "values": values}
)

@staticmethod
def _cache_deps(path: str, f4cache: F4Cache):
Expand Down
4 changes: 3 additions & 1 deletion f4pga/flows/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ModuleContext:

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

# `config` should be a dictionary given as modules input.
def __init__(self, module: Module, config: "dict[str, ]", r_env: ResolutionEnv, share: str, bin: str):
def __init__(self, module: Module, config: "dict[str, ]", r_env: ResolutionEnv, share: str, bin: str, aux: str):
self.module_name = module.name
self.takes = SimpleNamespace()
self.produces = SimpleNamespace()
Expand All @@ -110,6 +111,7 @@ def __init__(self, module: Module, config: "dict[str, ]", r_env: ResolutionEnv,
self.r_env = r_env
self.share = share
self.bin = bin
self.aux = aux

self._getreqmaybe(self.takes, module.takes, config["takes"])
self._getreqmaybe(self.values, module.values, config["values"])
Expand Down
27 changes: 14 additions & 13 deletions f4pga/flows/platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ ql-eos-s3:
PINMAP_FILE: '${shareDir}/arch/ql-eos-s3_wlcsp/pinmap_${package}.csv'
PCF_FILE: '${:pcf}'
PYTHON3: '${python3}'
UTILS_PATH: '${shareDir}/scripts'
UTILS_PATH: '${auxDir}/utils'
prepare_sdc:
module: 'common:generic_script_wrapper'
params:
stage_name: prepare_sdc
interpreter: '${python3}'
script: ['-m', 'f4pga.utils.quicklogic.process_sdc_constraints']
script: "${auxDir}/utils/quicklogic/process_sdc_constraints.py"
outputs:
sdc:
mode: file
Expand All @@ -259,7 +259,7 @@ ql-eos-s3:
sdc-out: '${:eblif[noext]}.sdc'
pcf: '${:pcf}'
pin-map: ''
$PYTHONPATH: '${shareDir}/scripts/'
$PYTHONPATH: "${auxDir}/utils/quicklogic"
pack:
module: 'common:pack'
values:
Expand Down Expand Up @@ -301,7 +301,7 @@ ql-eos-s3:
params:
stage_name: ioplace
interpreter: '${python3}'
script: ['-m', 'f4pga.utils.quicklogic.pp3.create_ioplace']
script: "${auxDir}/utils/quicklogic/pp3/create_ioplace.py"
outputs:
io_place:
mode: stdout
Expand All @@ -311,13 +311,13 @@ ql-eos-s3:
net: '${:net}'
pcf: '${:pcf}'
map: '${shareDir}/arch/ql-eos-s3_wlcsp/pinmap_${package}.csv'
$PYTHONPATH: '${shareDir}/scripts/'
$PYTHONPATH: "${auxDir}/utils/"
place_constraints:
module: 'common:generic_script_wrapper'
params:
stage_name: place_constraints
interpreter: '${python3}'
script: ['-m', 'f4pga.utils.quicklogic.pp3.create_place_constraints']
script: "${auxDir}/utils/quicklogic/pp3/create_place_constraints.py"
outputs:
place_constraints:
mode: stdout
Expand All @@ -326,15 +326,15 @@ ql-eos-s3:
blif: '${:eblif}'
map: '${shareDir}/arch/ql-eos-s3_wlcsp/clkmap_${package}.csv'
i: '${:io_place}'
$PYTHONPATH: '${shareDir}/scripts/'
$PYTHONPATH: "${auxDir}/utils/"
place:
module: 'common:place'
iomux_jlink:
module: 'common:generic_script_wrapper'
params:
stage_name: iomux_jlink
interpreter: '${python3}'
script: ['-m', 'f4pga.utils.quicklogic.pp3.eos-s3.iomux_config']
script: "${auxDir}/utils/quicklogic/pp3/eos-s3/iomux_config.py"
outputs:
iomux_jlink:
mode: stdout
Expand All @@ -344,13 +344,13 @@ ql-eos-s3:
pcf: '${:pcf}'
map: '${shareDir}/arch/ql-eos-s3_wlcsp/pinmap_${package}.csv'
output-format: jlink
$PYTHONPATH: '${shareDir}/scripts/'
$PYTHONPATH: "${auxDir}/utils/"
iomux_openocd:
module: 'common:generic_script_wrapper'
params:
stage_name: iomux_openocd
interpreter: '${python3}'
script: ['-m', 'f4pga.utils.quicklogic.pp3.eos-s3.iomux_config']
script: "${auxDir}/utils/quicklogic/pp3/eos-s3/iomux_config.py"
outputs:
iomux_openocd:
mode: stdout
Expand All @@ -360,13 +360,13 @@ ql-eos-s3:
pcf: '${:pcf}'
map: '${shareDir}/arch/ql-eos-s3_wlcsp/pinmap_${package}.csv'
output-format: openocd
$PYTHONPATH: '${shareDir}/scripts/'
$PYTHONPATH: "${auxDir}/utils/"
iomux_binary:
module: 'common:generic_script_wrapper'
params:
stage_name: iomux_binary
interpreter: '${python3}'
script: ['-m', 'f4pga.utils.quicklogic.pp3.eos-s3.iomux_config']
script: "${auxDir}/utils/quicklogic/pp3/eos-s3/iomux_config.py"
outputs:
iomux_binary:
mode: stdout
Expand All @@ -376,7 +376,7 @@ ql-eos-s3:
pcf: '${:pcf}'
map: '${shareDir}/arch/ql-eos-s3_wlcsp/pinmap_${package}.csv'
output-format: binary
$PYTHONPATH: '${shareDir}/scripts/'
$PYTHONPATH: "${auxDir}/utils/"
route:
module: 'common:route'
values:
Expand Down Expand Up @@ -575,6 +575,7 @@ ql-eos-s3:
$FPGA_FAM: eos-s3
$PATH: '${shareDir}/../../conda/envs/eos-s3/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
$BIN_DIR_PATH: '${binDir}'
$PYTHONPATH: "${auxDir}/utils/quicklogic/pp3"


ql-k4n8_fast: &ql-k4n8
Expand Down
8 changes: 5 additions & 3 deletions f4pga/flows/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ def get_module(path: str):
class ModRunCtx:
share: str
bin: str
aux: str
config: "dict[str, ]"

def __init__(self, share: str, bin: str, config: "dict[str, ]"):
def __init__(self, share: str, bin: str, aux: str, config: "dict[str, ]"):
self.share = share
self.bin = bin
self.aux = aux
self.config = config

def make_r_env(self):
Expand Down Expand Up @@ -110,7 +112,7 @@ def module_io(module: Module):

def module_map(module: Module, ctx: ModRunCtx):
try:
mod_ctx = ModuleContext(module, ctx.config, ctx.make_r_env(), ctx.share, ctx.bin)
mod_ctx = ModuleContext(module, ctx.config, ctx.make_r_env(), ctx.share, ctx.bin, ctx.aux)
except Exception as e:
raise ModuleFailException(module.name, "map", e)

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

def module_exec(module: Module, ctx: ModRunCtx):
try:
mod_ctx = ModuleContext(module, ctx.config, ctx.make_r_env(), ctx.share, ctx.bin)
mod_ctx = ModuleContext(module, ctx.config, ctx.make_r_env(), ctx.share, ctx.bin, ctx.aux)
except Exception as e:
raise ModuleFailException(module.name, "exec", e)

Expand Down
12 changes: 12 additions & 0 deletions f4pga/fpga_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"xc7": {
"manufacturer": "xilinx"
},
"eos-s3": {
"manufacturer": "quicklogic",
"architecture": "pp3"
},
"qlf_k4n8": {
"manufacturer": "quicklogic"
}
}
3 changes: 3 additions & 0 deletions f4pga/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def get_requirements(file: Path) -> List[str]:
url="https://github.com/chipsalliance/f4pga",
package_dir={"f4pga": "."},
package_data={
"f4pga": [
"fpga_map.json",
],
"f4pga.flows": [
"*.yml",
],
Expand Down
Loading

0 comments on commit c5b336a

Please sign in to comment.