From: Jean-François Nguyen Date: Fri, 29 Oct 2021 18:24:11 +0000 (+0200) Subject: cores.litedram: add device to generated YAML configuration. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=02221f431e635be91aa507b8c1e0965b6dc1fe0e;p=lambdasoc.git cores.litedram: add device to generated YAML configuration. Also, fix wrong build product path. --- diff --git a/lambdasoc/cores/litedram.py b/lambdasoc/cores/litedram.py index 227cdda..c7effdc 100644 --- a/lambdasoc/cores/litedram.py +++ b/lambdasoc/cores/litedram.py @@ -491,11 +491,11 @@ class Core(Elaboratable): raise TypeError("Platform must be an instance of nmigen.build.Platform, not {!r}" .format(platform)) - plan = builder.prepare(self, sim=sim, name_force=name_force) + plan = builder.prepare(self, platform, sim=sim, name_force=name_force) if not do_build: return plan - products = plan.execute_local(f"{build_dir}/{__package__}") + products = plan.execute_local(f"{build_dir}/{__name__}") self._populate_ctrl_map(products) core_src = f"{self.name}/{self.name}.v" @@ -584,11 +584,15 @@ class Builder: # {{autogenerated}} { # General ------------------------------------------------------------------ + {% if top.config.phy_name == "ECP5DDRPHY" %} + "device": "{{platform.device}}-{{platform.speed}}{{platform.package}}", + {% endif %} "cpu": "None", {% if top.config.phy_name == "A7DDRPHY" %} "speedgrade": {{top.config.speedgrade}}, {% endif %} "memtype": "{{top.config.memtype}}", + "uart": "rs232", # PHY ---------------------------------------------------------------------- {% if top.config.phy_name == "A7DDRPHY" %} @@ -685,13 +689,15 @@ class Builder: def __init__(self): self.namespace = set() - def prepare(self, core, *, sim=False, name_force=False): + def prepare(self, core, platform, *, sim=False, name_force=False): """Prepare a build plan. Arguments --------- core : :class:`litedram.Core` The LiteDRAM instance to be built. + platform : :class:`nmigen.build.plat.Platform` + Target platform. sim : bool Do the build in simulation mode (i.e. by replacing the PHY with a model). name_force : bool @@ -710,6 +716,10 @@ class Builder: if not isinstance(core, Core): raise TypeError("LiteDRAM core must be an instance of litedram.Core, not {!r}" .format(core)) + if not isinstance(platform, Platform): + raise TypeError("Target platform must be an instance of nmigen.build.plat.Platform, " + "not {!r}" + .format(platform)) if core.name in self.namespace and not name_force: raise ValueError( @@ -741,6 +751,7 @@ class Builder: "emit_commands": emit_commands, "sim": sim, "top": core, + "platform": platform, }) plan = BuildPlan(script=f"build_{core.name}") diff --git a/lambdasoc/test/test_cores_litedram.py b/lambdasoc/test/test_cores_litedram.py index 64b6464..448be76 100644 --- a/lambdasoc/test/test_cores_litedram.py +++ b/lambdasoc/test/test_cores_litedram.py @@ -3,6 +3,7 @@ import unittest from nmigen_soc.memory import MemoryMap +from nmigen_boards.ecpix5 import ECPIX585Platform from litedram.modules import SDRAMModule @@ -458,27 +459,34 @@ class BuilderTestCase(unittest.TestCase): def test_prepare(self): core = litedram.Core(self._cfg) builder = litedram.Builder() - builder.prepare(core) + builder.prepare(core, ECPIX585Platform()) self.assertEqual(list(builder.namespace), ["core"]) def test_prepare_name_conflict(self): core = litedram.Core(self._cfg) builder = litedram.Builder() - builder.prepare(core) + builder.prepare(core, ECPIX585Platform()) with self.assertRaisesRegex(ValueError, r"LiteDRAM core name 'core' has already been used for a previous build\. Building " r"this instance may overwrite previous build products\. Passing `name_force=True` " r"will disable this check"): - builder.prepare(core) + builder.prepare(core, ECPIX585Platform()) def test_prepare_name_force(self): core = litedram.Core(self._cfg) builder = litedram.Builder() - builder.prepare(core) - builder.prepare(core, name_force=True) + builder.prepare(core, ECPIX585Platform()) + builder.prepare(core, ECPIX585Platform(), name_force=True) def test_prepare_wrong_core(self): builder = litedram.Builder() with self.assertRaisesRegex(TypeError, r"LiteDRAM core must be an instance of litedram.Core, not 'foo'"): - builder.prepare("foo") + builder.prepare("foo", ECPIX585Platform()) + + def test_prepare_wrong_platform(self): + core = litedram.Core(self._cfg) + builder = litedram.Builder() + with self.assertRaisesRegex(TypeError, + r"Target platform must be an instance of nmigen.build.plat.Platform, not 'foo'"): + builder.prepare(core, "foo")