From 09776b77e649ebc7138baa9a355fb42931fe915a Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 22 Aug 2018 15:20:28 +0200 Subject: [PATCH] sim: run as root only when needed (ethernet module present) --- litex/build/sim/config.py | 6 ++++++ litex/build/sim/verilator.py | 9 ++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/litex/build/sim/config.py b/litex/build/sim/config.py index 655a7bc0..5942bea3 100644 --- a/litex/build/sim/config.py +++ b/litex/build/sim/config.py @@ -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) diff --git a/litex/build/sim/verilator.py b/litex/build/sim/verilator.py index ffb89e0f..07840b82 100644 --- a/litex/build/sim/verilator.py +++ b/litex/build/sim/verilator.py @@ -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("..") -- 2.30.2