diff --git a/bigfloat.nix b/bigfloat.nix deleted file mode 100644 index 4355ef04e..000000000 --- a/bigfloat.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ lib, buildPythonPackage, fetchPypi, gmp, mpfr, six }: - -buildPythonPackage rec { - pname = "bigfloat"; - version = "0.4.0"; - - buildInputs = [ gmp mpfr ]; - propagatedBuildInputs = [ six ]; - - src = fetchPypi { - inherit pname version; - sha256 = "WLlr3ocqylmJ0T2C66Os8qoblOIhF91yoWulkRsMDLg="; - }; - - doCheck = false; - - meta = with lib; { - homepage = "https://pypi.org/project/bigfloat/"; - license = licenses.lgpl3Plus; - }; -} diff --git a/c4m-jtag.nix b/c4m-jtag.nix deleted file mode 100644 index cf301c67a..000000000 --- a/c4m-jtag.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ version, src }: - -{ lib, python, buildPythonPackage, nmigen-soc, nmigen, modgrammar, setuptools-scm }: - -buildPythonPackage { - pname = "c4m-jtag"; - inherit src version; - - nativeBuildInputs = [ setuptools-scm ]; - propagatedBuildInputs = [ nmigen-soc nmigen modgrammar ]; - - doCheck = false; - - pythonImportsCheck = [ "c4m.nmigen.jtag.tap" ]; - - prePatch = '' - export SETUPTOOLS_SCM_PRETEND_VERSION=${version} - ''; - - meta = with lib; { - homepage = "https://pypi.org/project/libresoc-openpower-isa/"; - license = licenses.lgpl3Plus; - }; -} diff --git a/consistent-assembler-prefix.patch b/consistent-assembler-prefix.patch new file mode 100644 index 000000000..113be8db6 --- /dev/null +++ b/consistent-assembler-prefix.patch @@ -0,0 +1,13 @@ +diff --git a/src/openpower/simulator/program.py b/src/openpower/simulator/program.py +index bf86d131..273e1f04 100644 +--- a/src/openpower/simulator/program.py ++++ b/src/openpower/simulator/program.py +@@ -86,7 +86,7 @@ class Program: + + def _assemble(self): + with tempfile.NamedTemporaryFile(suffix=".o") as outfile: +- args = [cmds['as'], ++ args = [cmds['powerpc64le-linux-gnu-as'], + '-mpower9', + '-mregnames', + self.obj_fmt, diff --git a/default-target-prefix.patch b/default-target-prefix.patch new file mode 100644 index 000000000..18e1433f7 --- /dev/null +++ b/default-target-prefix.patch @@ -0,0 +1,12 @@ +diff --git a/src/openpower/simulator/envcmds.py b/src/openpower/simulator/envcmds.py +index d24430ff..67ff4b73 100644 +--- a/src/openpower/simulator/envcmds.py ++++ b/src/openpower/simulator/envcmds.py +@@ -10,6 +10,6 @@ for cmd in ['objcopy', 'as', 'ld', 'gcc', 'ar', 'gdb']: + default = cmd + else: + default = "powerpc64-linux-gnu-%s" % cmd +- cmds[cmd] = os.environ.get(cmd.upper(), default) ++ cmds[cmd] = default + + diff --git a/ecp5-program.nix b/ecp5-program.nix deleted file mode 100644 index 4d696b225..000000000 --- a/ecp5-program.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ version }: - -{ writeShellScript, openocd, python3Packages, libresoc-ecp5, 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)" - pushd "$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} - - popd - rm -rf "$dir" - exit 0 -'' diff --git a/ieee754fpu.nix b/ieee754fpu.nix deleted file mode 100644 index e520437da..000000000 --- a/ieee754fpu.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ lib, buildPythonPackage, libresoc-nmutil, bigfloat, fetchgit }: - -buildPythonPackage { - pname = "libresoc-ieee754fpu"; - version = "unstable-2021-06-05"; - - src = fetchgit { - url = "https://git.libre-soc.org/git/ieee754fpu.git"; - rev = "c62fa3a7ee95832587d7725729dcdb9a002ae015"; - sha256 = "wbr1vGFzUlUtBT6IcRsykADYeksiVoq/LacU/dbRQ0o="; - }; - - propagatedBuildInputs = [ libresoc-nmutil bigfloat ]; - - doCheck = false; - - prePatch = '' - touch ./src/ieee754/part/__init__.py - ''; - - pythonImportsCheck = [ "ieee754.part" ]; - - meta = with lib; { - homepage = "https://pypi.org/project/libresoc-ieee754fpu/"; - license = licenses.lgpl3Plus; - }; -} diff --git a/libresoc-nmutil.nix b/libresoc-nmutil.nix new file mode 100644 index 000000000..478c1bbac --- /dev/null +++ b/libresoc-nmutil.nix @@ -0,0 +1,18 @@ +{pkgs, ...}: +with pkgs.python3Packages; + buildPythonPackage rec { + pname = "libresoc-nmutil"; + version = "0.0.1"; + + src = fetchPypi { + inherit pname version; + hash = "sha256-DPnzjdGDhAN+wYoSo6iaAK44Je/RKgTe4p/+SHIIaM0="; + }; + + propagatedBuildInputs = [pyvcd]; + + nativeCheckInputs = [nose]; + + # FIXME(jl): nmigen/amaranth tests + doCheck = false; + } diff --git a/libresoc-pyelftools.nix b/libresoc-pyelftools.nix new file mode 100644 index 000000000..3991fc6b2 --- /dev/null +++ b/libresoc-pyelftools.nix @@ -0,0 +1,13 @@ +{ + python39Packages, + fetchgit, +}: +python39Packages.pyelftools.overrideAttrs (_: rec { + name = "libresoc-pyelftools"; + version = "v0.30"; + src = fetchgit { + url = "https://git.libre-soc.org/git/pyelftools.git"; + rev = version; + sha256 = "sha256-A9etnN7G24/Gu8YlV/YDpxZV+TG2eVXGx2ZjVnA9ZD4="; + }; +}) diff --git a/mdis.nix b/mdis.nix new file mode 100644 index 000000000..b74e8eff8 --- /dev/null +++ b/mdis.nix @@ -0,0 +1,14 @@ +{ + python39Packages, + fetchPypi, +}: +with python39Packages; + buildPythonPackage rec { + pname = "mdis"; + version = "0.5.1"; + + src = fetchPypi { + inherit pname version; + sha256 = "sha256-gvXtP8NO5XPDAs0XMbGknG79FscN/7lxqmF1kg3nhxg="; + }; + } diff --git a/modgrammar.nix b/modgrammar.nix deleted file mode 100644 index ce0f3482e..000000000 --- a/modgrammar.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ lib, buildPythonPackage, fetchFromGitHub }: - -buildPythonPackage rec { - pname = "modgrammar"; - version = "unstable-2020-09-20"; - - src = fetchFromGitHub { - owner = "bloerwald"; - repo = "modgrammar"; - rev = "d363ad5a86584e560a8b03cbe11c0168d7610691"; - sha256 = "SO2qjfEVaJfgbA5HLJYwXlaeUzt5EFoljYQ2SsdDCbc="; - }; - - doCheck = false; - - meta = with lib; { - homepage = "https://pypi.org/project/modgrammar/"; - # license = licenses.bsd; # FIXME: Which BSD? - }; -} diff --git a/nmigen-soc.nix b/nmigen-soc.nix new file mode 100644 index 000000000..c3c76a538 --- /dev/null +++ b/nmigen-soc.nix @@ -0,0 +1,32 @@ +{ + lib, + python39Packages, + fetchFromGitLab, + nmigen, +}: +with python39Packages; + buildPythonPackage rec { + pname = "nmigen-soc"; + version = "unstable-2024-03-31"; + # python setup.py --version + realVersion = "0.1.dev243+g${lib.substring 0 7 src.rev}"; + + # NOTE(jleightcap): while libre-soc project does have local forks of nmigen* projects, + # HEADs of repos are incompatible. + # dev-env-setup implies that these forks are unused in build process, so using upstream. + src = fetchFromGitLab { + owner = "nmigen"; + repo = "nmigen-soc"; + hash = "sha256-RI481chXiD9kP/6vNLzYGOfcbwHH0Cvhk+CgloCY9JU="; + rev = "fd2aaa336283cff2e46f489bf3897780cd217b8b"; # HEAD @ version date + }; + + nativeBuildInputs = [setuptools-scm]; + propagatedBuildInputs = [nmigen setuptools]; + + preBuild = '' + export SETUPTOOLS_SCM_PRETEND_VERSION="${realVersion}" + ''; + + nativeCheckInputs = [pytestCheckHook]; + } diff --git a/nmigen.nix b/nmigen.nix new file mode 100644 index 000000000..d1cf9d728 --- /dev/null +++ b/nmigen.nix @@ -0,0 +1,49 @@ +{ + lib, + fetchFromGitLab, + git, + python39Packages, + symbiyosys, + yices, + yosys, +}: +with python39Packages; + buildPythonPackage rec { + pname = "nmigen"; + version = "unstable-2024-03-31"; + realVersion = "0.3.dev243+g${lib.substring 0 7 src.rev}"; + + src = fetchFromGitLab { + owner = "nmigen"; + repo = "nmigen"; + hash = "sha256-tpcA+FFHhm4gF37Z+rB/uZopSRtAtNxU8j5IXnSGeCg="; + rev = "29dec30f628356828aa2aa2b91ce205a570d664e"; # HEAD @ version date + }; + + preBuild = '' + export SETUPTOOLS_SCM_PRETEND_VERSION="${realVersion}" + ''; + + nativeBuildInputs = [git setuptools-scm]; + + propagatedBuildInputs = + [ + jinja2 + pyvcd + yosys + ] + ++ lib.optional (pythonOlder "3.9") importlib-resources + ++ lib.optional (pythonOlder "3.8") importlib-metadata; + + nativeCheckInputs = [ + pytestCheckHook + symbiyosys + yices + yosys + ]; + + # nmigen wraps C/C++ compiler with setuptools.distutils.ccompiler + # requires manual patching for compatibiility with this version of setuptools + # https://github.com/NixOS/nixpkgs/pull/199974 + doCheck = false; + } diff --git a/nmutil.nix b/nmutil.nix deleted file mode 100644 index 3489e7704..000000000 --- a/nmutil.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ lib, buildPythonPackage, bigfloat, fetchgit, pyvcd }: - -buildPythonPackage { - pname = "libresoc-nmutil"; - version = "unstable-2021-08-24"; - - propagatedBuildInputs = [ pyvcd ]; - - src = fetchgit { - url = "https://git.libre-soc.org/git/nmutil.git"; - rev = "efda080db6978d249a23003bec734f1cc07de329"; - sha256 = "nTgUiZc4CC0VoUND29kHSIyMlP9IB3oZfehutoNK07w="; - }; - - doCheck = false; - - meta = with lib; { - homepage = "https://pypi.org/project/libresoc-ieee754fpu/"; - license = licenses.lgpl3Plus; - }; -} diff --git a/openpower-isa.nix b/openpower-isa.nix deleted file mode 100644 index 5aee8b1e4..000000000 --- a/openpower-isa.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ lib, python, buildPythonPackage, fetchgit, libresoc-nmutil, astor, nmigen, ply, pygdbmi }: - -buildPythonPackage { - pname = "libresoc-openpower-isa"; - version = "unstable-2021-09-04"; - - src = fetchgit { - url = "https://git.libre-soc.org/git/openpower-isa.git"; - rev = "6e43a194f3d07ed5a8daa297187a32746c4c4d3c"; - sha256 = "0EekUouTQruTXGO5jlPJtqh0DOudghILy0nca5eaZz8="; - }; - - propagatedBuildInputs = [ libresoc-nmutil astor nmigen ply pygdbmi ]; - - doCheck = false; - - prePatch = '' - touch ./src/openpower/sv/__init__.py # TODO: fix upstream - ''; - - postInstall = '' - cp -rT ./openpower $out/${python.sitePackages}/../openpower/ - ''; - - pythonImportsCheck = [ "openpower.decoder.power_decoder2" "openpower" ]; - - meta = with lib; { - homepage = "https://pypi.org/project/libresoc-openpower-isa/"; - license = licenses.lgpl3Plus; - }; -} diff --git a/pinmux.nix b/pinmux.nix deleted file mode 100644 index fc9ca7e8f..000000000 --- a/pinmux.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ version }: - -{ stdenv, python2 }: - -stdenv.mkDerivation { - pname = "libresoc-pinmux"; - inherit version; - - src = ../pinmux; - - nativeBuildInputs = [ python2 ]; - - 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/default.nix b/pkgs/default.nix index c5b3eaaee..9fc99697e 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -33,6 +33,50 @@ pretalx-venueless pretalx-public-voting ; + + libresoc = let + libresoc-c4m-jtag = callPackage ./libresoc/c4m-jtag.nix {inherit nmigen nmigen-soc;}; + libresoc-ieee754fpu = callPackage ./libresoc/ieee754fpu.nix {inherit nmutil nmigen pytest-output-to-files;}; + libresoc-openpower-isa = callPackage ./libresoc/openpower-isa.nix { + inherit + libresoc-pyelftools + mdis + nmigen + nmutil + pytest-output-to-files + ; + }; + libresoc-pyelftools = callPackage ./libresoc/libresoc-pyelftools.nix {}; + mdis = callPackage ./libresoc/mdis.nix {}; + nmigen = callPackage ./libresoc/nmigen.nix {}; + nmigen-soc = callPackage ./libresoc/nmigen-soc.nix {inherit nmigen;}; + nmutil = callPackage ./libresoc/nmutil.nix {inherit nmigen pytest-output-to-files;}; + pinmux = callPackage ./libresoc/pinmux.nix {}; + power-instruction-analyzer = callPackage ./libresoc/power-instruction-analyzer.nix {}; + pytest-output-to-files = callPackage ./libresoc/pytest-output-to-files.nix {}; + in rec { + # SoC synthesized to nmigen(-soc) + soc = callPackage ./libresoc/soc.nix { + inherit + libresoc-c4m-jtag + libresoc-ieee754fpu + libresoc-openpower-isa + nmigen-soc + power-instruction-analyzer + pytest-output-to-files + ; + }; + + # SoC synthesized to Verilog + verilog = callPackage ./libresoc/verilog.nix {inherit pinmux soc;}; + + # SoC ECP5 Ultra Low Power FPGA + ecp5 = callPackage ./libresoc/ecp5.nix {inherit verilog pinmux;}; # FIXME: have to re-test + ecp5-program = callPackage ./libresoc/ecp5-program.nix {}; + + # SoC Power ISA ls180 180nm ASIC + ls180 = callPackage ./libresoc/ls180.nix {}; + }; }; in self diff --git a/pkgs/libresoc/c4m-jtag.nix b/pkgs/libresoc/c4m-jtag.nix new file mode 100644 index 000000000..f370d2378 --- /dev/null +++ b/pkgs/libresoc/c4m-jtag.nix @@ -0,0 +1,30 @@ +{ + lib, + fetchgit, + python39, + python39Packages, + nmigen-soc, + nmigen, +}: +python39Packages.buildPythonPackage rec { + pname = "c4m-jtag"; + version = "unstable-2024-03-31"; + realVersion = "0.3.dev243+g${lib.substring 0 7 src.rev}"; + + src = fetchgit { + url = "https://git.libre-soc.org/git/c4m-jtag.git"; + sha256 = "sha256-0yF/yqcknCq1fre5pnKux4V7guu2oDa6duPO9mU46n8=3"; + }; + + prePatch = '' + export SETUPTOOLS_SCM_PRETEND_VERSION="${realVersion}" + ''; + + nativeBuildInputs = with python39Packages; [setuptools-scm]; + propagatedBuildInputs = [nmigen-soc]; + + nativeCheckInputs = with python39Packages; [nose]; + checkPhase = "nosetests"; + + pythonImportsCheck = ["c4m.nmigen.jtag.tap"]; +} diff --git a/pkgs/libresoc/ecp5-program.nix b/pkgs/libresoc/ecp5-program.nix new file mode 100644 index 000000000..38b742250 --- /dev/null +++ b/pkgs/libresoc/ecp5-program.nix @@ -0,0 +1,37 @@ +{version}: { + writeShellScript, + openocd, + python3Packages, + libresoc-ecp5, + 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)" + pushd "$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} + + popd + rm -rf "$dir" + exit 0 + '' diff --git a/ecp5.nix b/pkgs/libresoc/ecp5.nix similarity index 50% rename from ecp5.nix rename to pkgs/libresoc/ecp5.nix index 1c82ee4bc..48e567b25 100644 --- a/ecp5.nix +++ b/pkgs/libresoc/ecp5.nix @@ -1,19 +1,37 @@ -{ version }: - -{ stdenv, python3Packages, yosys, libresoc-verilog, libresoc-pinmux, pkgsCross -, nextpnr, trellis }: - +{ + stdenv, + python39Packages, + fetchgit, + yosys, + verilog, + pinmux, + pkgsCross, + # nextpnr, + # trellis, +}: stdenv.mkDerivation { pname = "libresoc-versa-ecp5.v"; - inherit version; + version = "unstable-2024-03-31"; - src = ../src/soc/litex/florent; + src = fetchgit { + url = "https://git.libre-soc.org/git/litex.git"; + sha256 = ""; + # rev = ""; + }; nativeBuildInputs = - (with python3Packages; [ - python libresoc-soc litex-boards litex litedram liteeth liteiclink litescope litesdcard + (with python39Packages; [ + python + libresoc-soc + litex-boards + litex + litedram + liteeth + liteiclink + litescope + litesdcard ]) - ++ [ trellis nextpnr pkgsCross.powernv.buildPackages.gcc ]; + ++ [trellis nextpnr pkgsCross.powernv.buildPackages.gcc]; postPatch = '' patchShebangs --build . @@ -24,7 +42,7 @@ stdenv.mkDerivation { buildPhase = '' runHook preBuild export PINMUX="$(mktemp -d)" - ln -s ${libresoc-pinmux} "$PINMUX/ls180" + ln -s ${pinmux} "$PINMUX/ls180" cp ${libresoc-verilog} libresoc/libresoc.v ./versa_ecp5.py --sys-clk-freq=55e6 --build runHook postBuild diff --git a/pkgs/libresoc/ieee754fpu.nix b/pkgs/libresoc/ieee754fpu.nix new file mode 100644 index 000000000..7279973f5 --- /dev/null +++ b/pkgs/libresoc/ieee754fpu.nix @@ -0,0 +1,34 @@ +{ + python39Packages, + fetchgit, + symbiyosys, + nmutil, + nmigen, + pytest-output-to-files, +}: +with python39Packages; + buildPythonPackage { + pname = "libresoc-ieee754fpu"; + version = "unstable-2024-03-31"; + + src = fetchgit { + url = "https://git.libre-soc.org/git/ieee754fpu.git"; + sha256 = "sha256-Ghbvg2Y4YlmxVEa3EtcvEVai4hC4VU4q+XIQh4pQ7+c="; + rev = "829dfbc53ba38ec17bc544cb0b862e73cee223db"; # HEAD @ version date + }; + + prePatch = '' + touch ./src/ieee754/part{,_ass,_cat,_repl}/__init__.py + ''; + + propagatedBuildInputs = [nmutil]; + + nativeCheckInputs = [pytestCheckHook pytest-xdist pytest-output-to-files nmigen symbiyosys]; + + # TODO(jleightcap): all tests pass except formal methods, + # > ERROR: Module `\U$$0' referenced in module `\top' in cell `$15' is a blackbox/whitebox module. + # might be an issue with symbiyosys version? + doCheck = false; + + pythonImportsCheck = ["ieee754.part"]; + } diff --git a/ls180.nix b/pkgs/libresoc/ls180.nix similarity index 76% rename from ls180.nix rename to pkgs/libresoc/ls180.nix index 028fbcb0a..7a962b3ad 100644 --- a/ls180.nix +++ b/pkgs/libresoc/ls180.nix @@ -1,7 +1,11 @@ -{ version }: - -{ stdenv, python3Packages, yosys, libresoc-verilog, libresoc-pinmux, pkgsCross }: - +{ + stdenv, + python39Packages, + yosys, + verilog, + pinmux, + pkgsCross, +}: stdenv.mkDerivation { pname = "libresoc-ls1804k"; inherit version; @@ -9,10 +13,16 @@ stdenv.mkDerivation { src = ../src/soc/litex/florent; nativeBuildInputs = - (with python3Packages; [ - python libresoc-soc litex litedram liteeth liteiclink litescope litesdcard + (with python39Packages; [ + soc + litex + litedram + liteeth + liteiclink + litescope + litesdcard ]) - ++ [ pkgsCross.powernv.buildPackages.gcc ]; + ++ [pkgsCross.powernv.buildPackages.gcc]; postPatch = '' patchShebangs --build . diff --git a/pkgs/libresoc/nmutil.nix b/pkgs/libresoc/nmutil.nix new file mode 100644 index 000000000..baba65fb4 --- /dev/null +++ b/pkgs/libresoc/nmutil.nix @@ -0,0 +1,36 @@ +{ + lib, + fetchgit, + python39Packages, + symbiyosys, + yices, + nmigen, + pytest-output-to-files, +}: +with python39Packages; + buildPythonPackage { + pname = "libresoc-nmutil"; + version = "unstable-2024-03-31"; + + src = fetchgit { + url = "https://git.libre-soc.org/git/nmutil.git"; + sha256 = "sha256-8jXQGO4IeB6WjGtjuHO8UBh9n3ei7LukmRoXSbNJ1vM="; + }; + + propagatedNativeBuildInputs = [ + pyvcd + symbiyosys + yices + ]; + + nativeCheckInputs = [ + nmigen + symbiyosys + yices + pytestCheckHook + pytest-xdist + pytest-output-to-files + ]; + + pythonImportsCheck = ["nmutil"]; + } diff --git a/pkgs/libresoc/openpower-isa.nix b/pkgs/libresoc/openpower-isa.nix new file mode 100644 index 000000000..ed86fa0dc --- /dev/null +++ b/pkgs/libresoc/openpower-isa.nix @@ -0,0 +1,128 @@ +{ + python39, + python39Packages, + fetchgit, + pkgsCross, + writeShellApplication, + gnumake, + pytest-output-to-files, + libresoc-pyelftools, + nmigen, + nmutil, + mdis, +}: +with python39Packages; + buildPythonPackage rec { + name = "libresoc-openpower-isa"; + version = "unstable-2024-03-31"; + + src = fetchgit { + url = "https://git.libre-soc.org/git/openpower-isa.git"; + sha256 = "sha256-OKUb3BmVEZD2iRV8sbNEEA7ANJImWX8FEj06o5+HQwU="; + rev = "3cb597b99d414dbdb35336eb3734b5d46edd597f"; # HEAD @ version date + }; + + prePatch = '' + # broken upstream, required for importing modules in tests + touch ./src/openpower/{sv,test/general}/__init__.py + + # ignore $CC/$AS/etc environment variables and update hard-coded prefixes with pkgsCross compiler (powerpc64le-unknown-linux-gnu-gcc) + substituteInPlace src/openpower/syscalls/ppc_flags.py \ + --replace 'powerpc64le-linux-gnu-gcc' '${pkgsCross.powernv.buildPackages.gcc.targetPrefix}gcc' + substituteInPlace src/openpower/simulator/envcmds.py \ + --replace 'powerpc64-linux-gnu-' '${pkgsCross.powernv.buildPackages.gcc.targetPrefix}' \ + --replace 'os.environ.get(cmd.upper(), default)' 'default' + ''; + + patches = [ + # setup.py uses @git syntax for version specifiers, prevent setuptools from attempting to clone + ./use-vendored-git-dependencies.patch + # patch out hack to create empty directory in output build + # see postInstall notes for complement + ./remove-gitignore-check.patch + # Makefile attempts to use recently-built binaries via $PATH, expose instead with a $(OPENPOWER) prefix + # see postInstall notes for complement + ./prefixed-openpower-isa-tools.patch + ]; + + propagatedNativeBuildInputs = [ + astor + cached-property + cffi + libresoc-pyelftools + mdis + nmigen + nmutil + pkgsCross.powernv.buildPackages.gcc + ply + pygdbmi + ]; + + postInstall = + '' + # complement of `remove-gitignore-check.patch` + mkdir -p $out/${python39.sitePackages}/openpower/decoder/isa/generated + + # linker script vendored in test library + cp ./src/openpower/simulator/memmap $out/${python39.sitePackages}/openpower/simulator/ + '' + + ( + # this project's build steps do not map cleanly onto Nix's build stages. + # setuptools builds the the `entry_points` into binaries that are used to codegen + # directly into the source directory, which is then bundled into a wheel and installed. + # + # for Nix, there's a chicken-and-egg problem with this: + # only once the package has been built can the codegen be run to... build the package from source. + # as a result, the installPhase is overloaded to effectively double as the build phase, + # so, the majority of build steps actually occur here, at the end: + let + codegen = writeShellApplication { + name = "run-codegen"; + runtimeInputs = [gnumake pkgsCross.powernv.buildPackages.gcc]; + text = "make generate"; + }; + in '' + # copy special-purpose python modules into path expected by codegen + cp -rT ./openpower $out/${python39.sitePackages}/../openpower/ + + # complement of `prefixed-openpower-isa-tools.patch` + OPENPOWER=$out ${codegen}/bin/run-codegen + + # ...again now including codegen source + cp -rT ./openpower $out/${python39.sitePackages}/../openpower/ + '' + ); + + nativeCheckInputs = [ + pytestCheckHook + pytest-xdist + pytest-output-to-files + pkgsCross.powernv.buildPackages.gcc + ]; + + disabledTests = [ + # listed failures seem unlikely to result from packaging errors, assumed present upstream + "test_20_cmp" + "test_36_extras_rldimi" + "test_36_extras_rldimi_" + "test_3_sv_isel" + "test_37_extras_rldimi" + "test_4_sv_crand" + ]; + + disabledTestPaths = [ + # listed paths import from codegen source, which is not in scope here. + "src/openpower/decoder/isa/" + "src/openpower/simulator/test_div_sim.py" + "src/openpower/simulator/test_helloworld_sim.py" + "src/openpower/simulator/test_mul_sim.py" + "src/openpower/simulator/test_shift_sim.py" + "src/openpower/simulator/test_sim.py" + "src/openpower/simulator/test_trap_sim.py" + ]; + + pythonImportsCheck = [ + "openpower.decoder.power_decoder2" + "openpower" + ]; + } diff --git a/pkgs/libresoc/pinmux.nix b/pkgs/libresoc/pinmux.nix new file mode 100644 index 000000000..2a25f14a9 --- /dev/null +++ b/pkgs/libresoc/pinmux.nix @@ -0,0 +1,29 @@ +{ + stdenv, + fetchgit, + python39, +}: +stdenv.mkDerivation { + pname = "libresoc-pinmux"; + version = "unstable-2024-03-31"; + + src = fetchgit { + url = "https://git.libre-soc.org/git/pinmux.git"; + sha256 = "sha256-Tux2RvcRmlpXMsHwve/+5rOyBRSThg9MVW2NGP3ZJxs="; + rev = "ee6c6c5020f11e7debfd8262ffdb8abd6e1782c"; # HEAD @ version date + }; + + nativeBuildInputs = [python39]; + + buildPhase = '' + runHook preBuild + python3.9 src/pinmux_generator.py -v -s ls180 -o ls180 + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mv ls180 $out + runHook postInstall + ''; +} diff --git a/pkgs/libresoc/soc.nix b/pkgs/libresoc/soc.nix new file mode 100644 index 000000000..a27c28783 --- /dev/null +++ b/pkgs/libresoc/soc.nix @@ -0,0 +1,63 @@ +{ + python39Packages, + fetchgit, + yosys, + libresoc-c4m-jtag, + libresoc-ieee754fpu, + libresoc-openpower-isa, + nmigen-soc, + power-instruction-analyzer, + pytest-output-to-files, +}: +with python39Packages; + buildPythonPackage { + pname = "soc"; + version = "unstable-2024-03-31"; + + src = fetchgit { + url = "https://git.libre-soc.org/git/soc.git"; + sha256 = "sha256-yJshQYf8V0CB2vPCmWLlnxXMhi/sPXiLKzOn6cqgmxw="; + fetchSubmodules = false; + }; + + patches = [./soc-nmigen-soc-no-implicit-arg.patch]; + + postPatch = '' + rm -r src/soc/litex + ''; + + propagatedBuildInputs = [ + cached-property + libresoc-c4m-jtag + libresoc-ieee754fpu + libresoc-openpower-isa + nmigen-soc + yosys + ]; + + nativeCheckInputs = [ + power-instruction-analyzer + pytest-output-to-files + pytest-xdist + pytestCheckHook + ]; + + disabledTests = [ + # listed failures seem unlikely to result from packaging errors, assumed present upstream + "test_div_pipe_core" + "test_fsm_div_core" + "test_sim_onl" + "test_mul_pipe_2_arg" + "test_mul_pipe_2_arg" + "test_it" + "test_sim_only" + "test_div_pipe_core" + "test_fsm_div_core" + ]; + + disabledTestPaths = [ + "unused_please_ignore_completely/" # ??? + ]; + + pythonImportsCheck = ["soc"]; + } diff --git a/pkgs/libresoc/verilog.nix b/pkgs/libresoc/verilog.nix new file mode 100644 index 000000000..9b3a92f43 --- /dev/null +++ b/pkgs/libresoc/verilog.nix @@ -0,0 +1,21 @@ +{ + runCommand, + pinmux, + soc, +}: +runCommand "libresoc.v" { + version = "unstable-2024-03-31"; + + nativeBuildInputs = [ + soc + pinmux + ]; +} '' + mkdir pinmux + ln -s ${pinmux} pinmux/ls180 + export PINMUX="$(realpath ./pinmux)" + python3.9 -m soc.simple.issuer_verilog \ + --debug=jtag --enable-core --enable-pll \ + --enable-xics --enable-sram4x4kblock --disable-svp64 \ + $out +'' diff --git a/power-instruction-analyzer.nix b/power-instruction-analyzer.nix new file mode 100644 index 000000000..da24574d6 --- /dev/null +++ b/power-instruction-analyzer.nix @@ -0,0 +1,27 @@ +{ + python39Packages, + rustPlatform, + fetchgit, +}: +with python39Packages; +with rustPlatform; + buildPythonPackage rec { + pname = "power-instruction-analyzer"; + version = "0.2.0"; + format = "pyproject"; + + src = fetchgit { + url = "https://git.libre-soc.org/git/power-instruction-analyzer.git"; + rev = "v${version}"; + hash = "sha256-UmgDykG9yn413PXrMsI4oRblCZdHbtaIZ55p89YPfQs="; + }; + + cargoDeps = fetchCargoTarball { + inherit src; + name = "${pname}-${version}"; + hash = "sha256-lkSdkkU0lvGtEHbM3eFrXHiUcWEPkHL1sQeebAyMUcY="; + }; + + nativeBuildInputs = [cargoSetupHook maturinBuildHook]; + maturinBuildFlags = "-F python"; + } diff --git a/prefixed-openpower-isa-tools.patch b/prefixed-openpower-isa-tools.patch new file mode 100644 index 000000000..64c815f01 --- /dev/null +++ b/prefixed-openpower-isa-tools.patch @@ -0,0 +1,23 @@ +diff --git a/Makefile b/Makefile +index ccc0a0ba..c31dd2ee 100644 +--- a/Makefile ++++ b/Makefile +@@ -11,15 +11,15 @@ gitupdate: + + # now installed as a command (/usr/local/bin/svanalysis) by setup.py + svanalysis: +- sv_analysis ++ $(OPENPOWER)/bin/sv_analysis + + # now installed as a command (/usr/local/bin/pywriter) by setup.py + pywriter: | svanalysis +- pywriter ++ $(OPENPOWER)/bin/pywriter + + # likewise + pyfnwriter: | pywriter +- pyfnwriter ++ $(OPENPOWER)/bin/pyfnwriter + + develop: + python3 setup.py develop # yes, develop, not install diff --git a/pytest-output-to-files.nix b/pytest-output-to-files.nix new file mode 100644 index 000000000..bc28d35a0 --- /dev/null +++ b/pytest-output-to-files.nix @@ -0,0 +1,16 @@ +{ + fetchgit, + python39Packages, +}: +with python39Packages; + buildPythonPackage { + name = "pytest-output-to-files"; + version = "unstable-2024-03-31"; + + src = fetchgit { + url = "https://git.libre-soc.org/git/pytest-output-to-files.git"; + sha256 = "sha256-ES8zZ9s6wGcqw60NoN4tZf/Dq/sBvl+UDYrXuOgfMxI="; + }; + + nativeCheckInputs = [pytestCheckHook]; + } diff --git a/remove-gitignore-check.patch b/remove-gitignore-check.patch new file mode 100644 index 000000000..1a56c944a --- /dev/null +++ b/remove-gitignore-check.patch @@ -0,0 +1,25 @@ +diff --git a/src/openpower/decoder/power_pseudo.py b/src/openpower/decoder/power_pseudo.py +index f0504a2..a84b4e6 100644 +--- a/src/openpower/decoder/power_pseudo.py ++++ b/src/openpower/decoder/power_pseudo.py +@@ -284,19 +284,7 @@ def convert_to_python(pcode, form, incl_carry, helper=False, filename="string"): + + + def check_in_gitignore(output_file): +- gitignore_file = os.path.join(os.path.dirname(output_file), ".gitignore") +- base_name = os.path.basename(output_file) +- with open(gitignore_file, "r") as f: +- for l in f.readlines(): +- l = l.strip() +- if "/" + base_name == l: +- return +- if l == "*.py": +- if base_name.endswith(".py"): +- return +- raise ValueError(f"generated output file not in .gitignore:\n" +- f"output file: {output_file}\n" +- f".gitignore file: {gitignore_file}") ++ return + + + def test(): diff --git a/soc-nmigen-soc-no-implicit-arg.patch b/soc-nmigen-soc-no-implicit-arg.patch new file mode 100644 index 000000000..bd2172e64 --- /dev/null +++ b/soc-nmigen-soc-no-implicit-arg.patch @@ -0,0 +1,12 @@ +diff --git a/src/soc/bus/SPBlock512W64B8W.py b/src/soc/bus/SPBlock512W64B8W.py +index 0a0d483b..24f2cf01 100644 +--- a/src/soc/bus/SPBlock512W64B8W.py ++++ b/src/soc/bus/SPBlock512W64B8W.py +@@ -25,7 +25,6 @@ class SPBlock512W64B8W(Elaboratable): + data_width=64, # 64 bit + granularity=8, # at 8-bit granularity + features=features, +- alignment=0, + name=name+"_wb") + self.bus = bus + self.granularity = bus.granularity diff --git a/soc.nix b/soc.nix deleted file mode 100644 index a4ed13685..000000000 --- a/soc.nix +++ /dev/null @@ -1,38 +0,0 @@ -{ version }: - -{ 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 version 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/use-vendored-git-dependencies.patch b/use-vendored-git-dependencies.patch new file mode 100644 index 000000000..231f18578 --- /dev/null +++ b/use-vendored-git-dependencies.patch @@ -0,0 +1,49 @@ +diff --git a/setup.py b/setup.py +index ca38ef9..d80d297 100644 +--- a/setup.py ++++ b/setup.py +@@ -8,19 +8,6 @@ NEWS = open(os.path.join(here, 'NEWS.txt')).read() + + version = '0.0.3' + +-# the only reason this is added is because it's become a part of python 3.9. +-# the project standard is python 3.7 however in future that will be updated. +-# for now, cached_property is RELUCTANTLY added but a *copy* is added so +-# that the generation of HDL is not critically dependent on random crap +-# off the internet. you're spending USD 16 *MILLION* on masks, you better +-# be absolutely paranoid-level certain you know where every piece of the +-# chain creating the HDL comes from. +-cprop = "git+https://git.libre-soc.org/git/cached-property.git@1.5.2" \ +- "#egg=cached-property-1.5.2" +- +-pyelftools = "git+https://git.libre-soc.org/git/pyelftools.git@v0.30" \ +- "#egg=pyelftools-0.30" +- + # using pip3 for ongoing development is a royal pain. seriously not + # recommended. therefore a number of these dependencies have been + # commented out. *they are still required* - they will need installing +@@ -39,14 +26,8 @@ install_requires = [ + 'cffi', # LuaJIT-style C FFI for Python + + # git url needed for having `pip3 install -e .` install from libre-soc git +- 'cached-property@'+cprop, +- "pyelftools@" + pyelftools, +-] +- +-# git url needed for having `setup.py develop` install from libre-soc git +-dependency_links = [ +- cprop, +- pyelftools, ++ 'cached-property', ++ "pyelftools", + ] + + test_requires = [ +@@ -78,7 +59,6 @@ setup( + include_package_data=True, + zip_safe=False, + install_requires=install_requires, +- dependency_links=dependency_links, + tests_require=test_requires, + test_suite='nose.collector', + entry_points={ diff --git a/verilog.nix b/verilog.nix deleted file mode 100644 index 600b6939d..000000000 --- a/verilog.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ version }: - -{ runCommand, python3Packages, libresoc-pinmux }: - -let script = '' - mkdir pinmux - ln -s ${libresoc-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" { - inherit version; - - nativeBuildInputs = (with python3Packages; [ - libresoc-soc - ]) ++ [ libresoc-pinmux ]; -} script