flash_extra: use new programmer
authorSebastien Bourdeauducq <sb@m-labs.hk>
Sat, 9 Aug 2014 06:39:38 +0000 (14:39 +0800)
committerSebastien Bourdeauducq <sb@m-labs.hk>
Sat, 9 Aug 2014 06:39:38 +0000 (14:39 +0800)
flash_extra.py
make.py
misoc_import.py [new file with mode: 0644]

index 6acb6eca209181ecfddee97a8a73e130d8e398dd..34ee8c6b8f6aa2df7f726a1cbff6be68b970d88c 100755 (executable)
@@ -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 19abebe75732089773478baf206dd3ce5986cad2..91991da4fcab1f470d616fec7bad908fb54c5a7c 100755 (executable)
--- 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 (file)
index 0000000..cba769c
--- /dev/null
@@ -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)