#!/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)
#!/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
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="""\
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()
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:
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:
--- /dev/null
+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)