cores.litedram: add device to generated YAML configuration.
authorJean-François Nguyen <jf@lambdaconcept.com>
Fri, 29 Oct 2021 18:24:11 +0000 (20:24 +0200)
committerJean-François Nguyen <jf@lambdaconcept.com>
Fri, 29 Oct 2021 18:24:22 +0000 (20:24 +0200)
Also, fix wrong build product path.

lambdasoc/cores/litedram.py
lambdasoc/test/test_cores_litedram.py

index 227cddafe28d8ca7a887b940b4c12c9d12aae752..c7effdc2a281e9b741d631f7c9ad6c60040d23ff 100644 (file)
@@ -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}")
index 64b646471f62c8b2ab18ff115773d4526d61a09a..448be76da21df74186087f41a776b47e7d6881eb 100644 (file)
@@ -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")