From: Sebastien Bourdeauducq Date: Sat, 9 Aug 2014 06:39:38 +0000 (+0800) Subject: flash_extra: use new programmer X-Git-Tag: 24jan2021_ls180~2668 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3a960e9e6a16353fe724500dacfdcd247690f3cc;p=litex.git flash_extra: use new programmer --- diff --git a/flash_extra.py b/flash_extra.py index 6acb6eca..34ee8c6b 100755 --- a/flash_extra.py +++ b/flash_extra.py @@ -1,15 +1,30 @@ #!/usr/bin/env python3 -import sys, argparse -import programmer +import os, sys, argparse + +from migen.util.misc import autotype + +from misoc_import import misoc_import if __name__ == "__main__": parser = argparse.ArgumentParser(description="Program extra data to flash memory.") parser.add_argument("-f", "--flash-proxy-dir", default=None, help="set search directory for flash proxy bitstreams") + parser.add_argument("-X", "--external", default="", help="use external directory for platforms and imports") + parser.add_argument("-Op", "--platform-option", default=[], nargs=2, action="append", help="set platform-specific option") parser.add_argument("platform", help="target platform") parser.add_argument("file", help="file to flash") parser.add_argument("address", help="flash address to write") args = parser.parse_args() - prog = programmer.create_programmer(args.platform, args.flash_proxy_dir) + external_platform = "" + if args.external: + external_platform = os.path.join(args.external, "platforms") + sys.path.insert(1, os.path.abspath(args.external)) + + platform_module = misoc_import("mibuild.platforms", external_platform, args.platform) + platform_kwargs = dict((k, autotype(v)) for k, v in args.platform_option) + platform = platform_module.Platform(**platform_kwargs) + + prog = platform.create_programmer() + prog.set_flash_proxy_dir(args.flash_proxy_dir) prog.flash(int(args.address, 0), args.file) diff --git a/make.py b/make.py index 19abebe7..91991da4 100755 --- a/make.py +++ b/make.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import sys, os, argparse, importlib, subprocess, struct +import sys, os, argparse, subprocess, struct from mibuild.tools import write_to_file from migen.util.misc import autotype @@ -9,6 +9,8 @@ from migen.fhdl import simplify from misoclib.gensoc import cpuif from misoclib.sdramphy import initsequence +from misoc_import import misoc_import + def _get_args(): parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description="""\ @@ -49,20 +51,6 @@ Load/flash actions use the existing outputs, and do not trigger new builds. return parser.parse_args() -def _misoc_import(default, external, name): - if external: - try: - del sys.modules[name] # force external path search - except KeyError: - pass - loader = importlib.find_loader(name, [external]) - if loader is None: - # try internal import - return importlib.import_module(default + "." + name) - return loader.load_module() - else: - return importlib.import_module(default + "." + name) - if __name__ == "__main__": args = _get_args() @@ -74,7 +62,7 @@ if __name__ == "__main__": sys.path.insert(1, os.path.abspath(args.external)) # create top-level SoC object - target_module = _misoc_import("targets", external_target, args.target) + target_module = misoc_import("targets", external_target, args.target) if args.sub_target: top_class = getattr(target_module, args.sub_target) else: @@ -84,7 +72,7 @@ if __name__ == "__main__": platform_name = top_class.default_platform else: platform_name = args.platform - platform_module = _misoc_import("mibuild.platforms", external_platform, platform_name) + platform_module = misoc_import("mibuild.platforms", external_platform, platform_name) platform_kwargs = dict((k, autotype(v)) for k, v in args.platform_option) platform = platform_module.Platform(**platform_kwargs) if args.external: diff --git a/misoc_import.py b/misoc_import.py new file mode 100644 index 00000000..cba769ce --- /dev/null +++ b/misoc_import.py @@ -0,0 +1,15 @@ +import sys, importlib + +def misoc_import(default, external, name): + if external: + try: + del sys.modules[name] # force external path search + except KeyError: + pass + loader = importlib.find_loader(name, [external]) + if loader is None: + # try internal import + return importlib.import_module(default + "." + name) + return loader.load_module() + else: + return importlib.import_module(default + "." + name)