From fb830450b9b62f8c674b77eaeaa18d503961f461 Mon Sep 17 00:00:00 2001 From: Jack Leightcap Date: Fri, 29 Mar 2024 11:10:42 -0400 Subject: [PATCH] TMP: libresoc: import derivations from upstream Signed-off-by: Jack Leightcap --- flake.nix | 2 +- pkgs/by-name/default.nix | 1 + pkgs/default.nix | 6 +++++ pkgs/libresoc/pinmux.nix | 31 +++++++++++++++++++++++++ pkgs/libresoc/soc.nix | 48 +++++++++++++++++++++++++++++++++++++++ pkgs/libresoc/verilog.nix | 24 ++++++++++++++++++++ 6 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 pkgs/libresoc/pinmux.nix create mode 100644 pkgs/libresoc/soc.nix create mode 100644 pkgs/libresoc/verilog.nix diff --git a/flake.nix b/flake.nix index 31d98cf4..7cfb83e5 100644 --- a/flake.nix +++ b/flake.nix @@ -50,7 +50,7 @@ ); args = { inherit (pkgs) lib; - inherit callPackage; + inherit callPackage runCommand; }; result = (import ./pkgs/by-name args) // (import ./pkgs args); in diff --git a/pkgs/by-name/default.nix b/pkgs/by-name/default.nix index 1d15cd0d..8c715a4e 100644 --- a/pkgs/by-name/default.nix +++ b/pkgs/by-name/default.nix @@ -1,6 +1,7 @@ { lib, callPackage, + runCommand, }: let baseDirectory = ./.; diff --git a/pkgs/default.nix b/pkgs/default.nix index a2e08155..12033346 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,6 +1,7 @@ { lib, callPackage, + runCommand, }: let self = rec { # LiberaForms is intentionally disabled. @@ -28,6 +29,11 @@ pretalx-venueless pretalx-public-voting ; + + libresoc = rec { + pinmux = callPackage ./libresoc/pinmux.nix {}; + verilog = callPackage ./libresoc/verilog.nix {inherit pinmux;}; + }; }; in self diff --git a/pkgs/libresoc/pinmux.nix b/pkgs/libresoc/pinmux.nix new file mode 100644 index 00000000..03f7a929 --- /dev/null +++ b/pkgs/libresoc/pinmux.nix @@ -0,0 +1,31 @@ +{ + stdenv, + fetchgit, + python3, +}: +stdenv.mkDerivation { + name = "libresoc-pinmux"; + + src = fetchgit { + url = "https://git.libre-soc.org/git/pinmux.git"; + hash = "sha256-Tux2RvcRmlpXMsHwve/+5rOyBRSThg9MVW2NGP3ZJxs="; + }; + + nativeBuildInputs = [python3]; + + configurePhase = "true"; + + buildPhase = '' + runHook preBuild + python src/pinmux_generator.py -v -s ls180 -o ls180 + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mv ls180 $out + runHook postInstall + ''; + + fixupPhase = "true"; +} diff --git a/pkgs/libresoc/soc.nix b/pkgs/libresoc/soc.nix new file mode 100644 index 00000000..75b83eb0 --- /dev/null +++ b/pkgs/libresoc/soc.nix @@ -0,0 +1,48 @@ +{ + lib, + buildPythonPackage, + yosys, + runCommand, + c4m-jtag, + nmigen-soc, + libresoc-ieee754fpu, + libresoc-openpower-isa, + python, +}: let + # If we use ../. as source, then any change to + # any unrelated Nix file would cause a rebuild, + # since the build would have access to it. + src = runCommand "libresoc-soc-source" {} '' + mkdir $out + cp -r ${../src} -T $out/src + cp -r ${../setup.py} -T $out/setup.py + cp -r ${../README.md} -T $out/README.md + cp -r ${../NEWS.txt} -T $out/NEWS.txt + ''; +in + buildPythonPackage { + pname = "libresoc-soc"; + inherit src; + + propagatedBuildInputs = [ + c4m-jtag + nmigen-soc + python + libresoc-ieee754fpu + libresoc-openpower-isa + yosys + ]; + + doCheck = false; + + prePatch = '' + rm -r src/soc/litex + ''; + + pythonImportsCheck = ["soc"]; + + meta = with lib; { + homepage = "https://libre-soc.org/"; + license = licenses.lgpl3Plus; + }; + } diff --git a/pkgs/libresoc/verilog.nix b/pkgs/libresoc/verilog.nix new file mode 100644 index 00000000..077718c7 --- /dev/null +++ b/pkgs/libresoc/verilog.nix @@ -0,0 +1,24 @@ +{ + runCommand, + python3, + python3Packages, + pinmux, +}: let + script = '' + mkdir pinmux + ln -s ${pinmux} pinmux/ls180 + export PINMUX="$(realpath ./pinmux)" + python3 -m soc.simple.issuer_verilog \ + --debug=jtag --enable-core --enable-pll \ + --enable-xics --enable-sram4x4kblock --disable-svp64 \ + $out + ''; +in + runCommand "libresoc.v" { + nativeBuildInputs = + (with python3Packages; [ + libresoc-soc + ]) + ++ [pinmux]; + } + script