From: Florent Kermarrec Date: Wed, 22 Aug 2018 13:20:28 +0000 (+0200) Subject: sim: run as root only when needed (ethernet module present) X-Git-Tag: 24jan2021_ls180~1636 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=09776b77e649ebc7138baa9a355fb42931fe915a;p=litex.git sim: run as root only when needed (ethernet module present) --- 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("..")