Add script for loading Libre-SOC onto Versa ECP5 board!
authorLas Safin <me@las.rs>
Sun, 26 Sep 2021 21:13:19 +0000 (21:13 +0000)
committerLas Safin <me@las.rs>
Sun, 26 Sep 2021 21:13:19 +0000 (21:13 +0000)
flake.lock
flake.nix
nix/ecp5-program.nix [new file with mode: 0644]
src/soc/litex/florent

index 8193dbc8f2ba0d60c12eddcbe35f5b74f57c652d..64e72d09c62ae9edc192a864ef902d99ed525e93 100644 (file)
         "url": "https://git.libre-soc.org/git/nmigen-soc.git"
       }
     },
+    "openocd": {
+      "flake": false,
+      "locked": {
+        "allRefs": true,
+        "lastModified": 1632577048,
+        "narHash": "sha256-jL6CvgEFslg3V4WIH3irLgXQRa1HczBZowZhTztW7nM=",
+        "ref": "master",
+        "rev": "c3993d3188da5976a64f47d4cbf4d7e5b63f0c8d",
+        "revCount": 9294,
+        "submodules": true,
+        "type": "git",
+        "url": "https://github.com/openocd-org/openocd?rev=35eed36ffdd082f5abfc16d4cc93511f6e225284&allR"
+      },
+      "original": {
+        "allRefs": true,
+        "submodules": true,
+        "type": "git",
+        "url": "https://github.com/openocd-org/openocd?rev=35eed36ffdd082f5abfc16d4cc93511f6e225284&allR"
+      }
+    },
     "root": {
       "inputs": {
         "c4m-jtag": "c4m-jtag",
         "nixpkgs": "nixpkgs",
         "nmigen": "nmigen",
         "nmigen-soc": "nmigen-soc",
+        "openocd": "openocd",
         "yosys": "yosys"
       }
     },
index 3bd7f9e9730051f81e475c5a1b13624393fa4e2b..2027d9bfb91b26441d3fe790ea58fbcb3bd764d4 100644 (file)
--- a/flake.nix
+++ b/flake.nix
@@ -14,6 +14,7 @@
   inputs.migen.flake = false;
   inputs.yosys.url = "github:YosysHQ/yosys?rev=a58571d0fe8971cb7d3a619a31b2c21be6d75bac";
   inputs.yosys.flake = false;
+  # submodules needed
   inputs.nix-litex.url = "git+https://git.sr.ht/~lschuermann/nix-litex?ref=main";
   inputs.nix-litex.flake = false;
 
@@ -37,8 +38,8 @@
     in
     {
       overlay = final: prev: {
-        python37Packages = prev.python37Packages.override {
-          overrides = lib.composeExtensions (litex final).pythonOverlay (pfinal: pprev: {
+        python37 = prev.python37.override {
+          packageOverrides = lib.composeExtensions (litex final).pythonOverlay (pfinal: pprev: {
             libresoc-ieee754fpu = pfinal.callPackage ./nix/ieee754fpu.nix {};
             libresoc-openpower-isa = pfinal.callPackage ./nix/openpower-isa.nix {};
             c4m-jtag = pfinal.callPackage (import ./nix/c4m-jtag.nix { src = c4m-jtag; version = getv c4m-jtag; }) {};
         libresoc-pre-litex = final.callPackage (import ./nix/pre-litex.nix { version = getv self; }) { python3Packages = final.python37Packages; };
         libresoc-ls180 = final.callPackage (import ./nix/ls180.nix { version = getv self; }) { python3Packages = final.python37Packages; };
         libresoc-ecp5 = final.callPackage (import ./nix/ecp5.nix { version = getv self; }) { python3Packages = final.python37Packages; };
+        libresoc-ecp5-program = final.callPackage (import ./nix/ecp5-program.nix { version = getv self; }) { python3Packages = final.python37Packages; };
         libresoc-pinmux = final.callPackage (import ./nix/pinmux.nix { version = getv self; }) {};
       };
 
+      apps = forAllSystems (system: {
+        ecp5 = {
+          type = "app";
+          program = "${nixpkgsFor.${system}.libresoc-ecp5-program}";
+        };
+      });
+      defaultApp = forAllSystems (system: self.apps.${system}.ecp5);
+
       packages = forAllSystems (system: {
         soc = nixpkgsFor.${system}.python37Packages.libresoc-soc;
         pre-litex = nixpkgsFor.${system}.libresoc-pre-litex;
         pinmux = nixpkgsFor.${system}.libresoc-pinmux;
         ls180 = nixpkgsFor.${system}.libresoc-ls180;
         ecp5 = nixpkgsFor.${system}.libresoc-ecp5;
+        ecp5-program = nixpkgsFor.${system}.libresoc-ecp5-program;
         openpower-isa = nixpkgsFor.${system}.python37Packages.libresoc-openpower-isa;
         debugNixpkgs = nixpkgsFor.${system};
       });
diff --git a/nix/ecp5-program.nix b/nix/ecp5-program.nix
new file mode 100644 (file)
index 0000000..fdf6c68
--- /dev/null
@@ -0,0 +1,21 @@
+{ version }:
+
+{ writeShellScript, openocd, python3Packages, libresoc-ecp5, yosys, libresoc-pre-litex, libresoc-pinmux, pkgsCross
+, nextpnr, trellis }:
+
+let
+  pythonWithEnv = python3Packages.python.withPackages (ps: with ps; [
+    requests migen libresoc-soc litex-boards litex litedram liteeth liteiclink litescope litesdcard
+  ]);
+in
+writeShellScript "program-ecp5-libresoc" ''
+  export PATH="${openocd}/bin:${pythonWithEnv}/bin:${trellis}/bin:${nextpnr}/bin:$PATH"
+
+  dir="$(mktemp -d)"
+  cd "$dir"
+  echo "$dir"
+
+  export PYTHONPATH="${../src/soc/litex/florent}:$PYTHONPATH"
+
+  python ${../src/soc/litex/florent/versa_ecp5.py} --sys-clk-freq=55e6 --load-from ${libresoc-ecp5}
+''
index 42f7357660b245c4491297d24eebc28b4ac2c21f..b55917aafa6bbc9f16e1d97dc095e929c31aa81a 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 42f7357660b245c4491297d24eebc28b4ac2c21f
+Subproject commit b55917aafa6bbc9f16e1d97dc095e929c31aa81a