sim: run as root only when needed (ethernet module present)
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 22 Aug 2018 13:20:28 +0000 (15:20 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 22 Aug 2018 13:20:28 +0000 (15:20 +0200)
litex/build/sim/config.py
litex/build/sim/verilator.py

index 655a7bc0782e90eebdcfea4df0a5196035e11ad7..5942bea3deb458e3478726eabb9b9528cdb53619 100644 (file)
@@ -38,5 +38,11 @@ class SimConfig():
             newmod.update({"tickfirst": tickfirst})
         self.modules.append(newmod)
 
+    def has_module(self, name):
+        for module in self.modules:
+            if module["module"] == name:
+                return True
+        return False
+
     def get_json(self):
         return json.dumps(self.modules, indent=4)
index ffb89e0f62e994a4d2bc17126dde91d4f3e35ade..07840b826ccd7f79b4211c791b9019691c549177 100644 (file)
@@ -126,10 +126,9 @@ mkdir -p modules && cp obj_dir/*.so modules
         print(output)
 
 
-def _run_sim(build_name):
-    run_script_contents = """\
-sudo obj_dir/Vdut
-"""
+def _run_sim(build_name, as_root=False):
+    run_script_contents = "sudo " if as_root else ""
+    run_script_contents += "obj_dir/Vdut"
     run_script_file = "run_" + build_name + ".sh"
     tools.write_to_file(run_script_file, run_script_contents, force_unix=True)
     if sys.platform != "win32":
@@ -173,7 +172,7 @@ class SimVerilatorToolchain:
         _build_sim(platform, build_name, verbose)
 
         if run:
-            _run_sim(build_name)
+            _run_sim(build_name, as_root=sim_config.has_module("ethernet"))
 
         os.chdir("..")