From 06597c9e3729e0f792eac32bfec4e10f3ca6f2a0 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 31 Jan 2024 12:26:22 +0000 Subject: [PATCH] Use ibex-cosim from lowrisc-nix repository This allows us to remove the path dependency completely. --- dependencies/flake.lock | 27 ------- dependencies/flake.nix | 86 -------------------- dependencies/overlay.nix | 3 - dependencies/riscv-isa-sim.nix | 34 -------- dependencies/riscv_gcc.nix | 44 ----------- dependencies/vivado.nix | 140 --------------------------------- flake.lock | 42 +++------- flake.nix | 32 ++------ 8 files changed, 20 insertions(+), 388 deletions(-) delete mode 100644 dependencies/flake.lock delete mode 100644 dependencies/flake.nix delete mode 100644 dependencies/overlay.nix delete mode 100644 dependencies/riscv-isa-sim.nix delete mode 100644 dependencies/riscv_gcc.nix delete mode 100644 dependencies/vivado.nix diff --git a/dependencies/flake.lock b/dependencies/flake.lock deleted file mode 100644 index 5e0824ec..00000000 --- a/dependencies/flake.lock +++ /dev/null @@ -1,27 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1703068421, - "narHash": "sha256-WSw5Faqlw75McIflnl5v7qVD/B3S2sLh+968bpOGrWA=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "d65bceaee0fb1e64363f7871bc43dc1c6ecad99f", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-23.11", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/dependencies/flake.nix b/dependencies/flake.nix deleted file mode 100644 index 8a2672c1..00000000 --- a/dependencies/flake.nix +++ /dev/null @@ -1,86 +0,0 @@ -{ - description = "ibex simple_system dependencies"; - - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; - }; - - outputs = { - self, - nixpkgs, - }: let - system = "x86_64-linux"; - pkgs = import nixpkgs { - inherit system; - config = {allowUnfree = true;}; - }; - - lowRISC_spike_override = final: prev: { - riscv-isa-sim = prev.riscv-isa-sim.overrideAttrs (oldAttrs: rec { - version = "ibex-cosim-v0.3"; - src = pkgs.fetchFromGitHub { - owner = "lowrisc"; - repo = oldAttrs.pname; - rev = version; - sha256 = "sha256-pKuOpzybOI8UqWV1TSFq4hqTHf7Bft/3WL19fRpwmfU="; - }; - }); - }; - - # Using requireFile prevents rehashing each time. - # This saves much seconds during rebuilds. - vivado_bundled_installer_src = pkgs.requireFile rec { - name = "vivado_bundled.tar.gz"; - sha256 = "1yxx6crvawhzvary9js0m8bzm35vv6pzfqdkv095r84lb13fyp7b"; - # Print the following message if the name / hash are not - # found in the store. - message = '' - requireFile : - file/dir not found in /nix/store - file = ${name} - hash = ${sha256} - - This nix expression requires that ${name} is already part of the store. - - Login to xilinx.com - - Download Unified Installer from https://www.xilinx.com/support/download.html, - - Run installer, specify a 'Download Image (Install Seperately)' - - Gzip the bundled installed image directory - - Rename the file to ${name} - - Add it to the nix store with - nix-prefetch-url --type sha256 file:/path/to/${name} - - Change the sha256 key above to $HASH - ''; - }; - - vivado = pkgs.callPackage (import ./vivado.nix) { - # We need to prepare the pre-downloaded installer to - # execute within a nix build. Make use of the included java deps, - # but we still need to do a little patching to make it work. - vivado-src = pkgs.stdenv.mkDerivation rec { - pname = "vivado_src"; - version = "2022.2"; - src = vivado_bundled_installer_src; - postPatch = '' - patchShebangs . - patchelf \ - --set-interpreter $(cat ${pkgs.stdenv.cc}/nix-support/dynamic-linker) \ - tps/lnx64/jre*/bin/java - ''; - dontBuild = true; - dontFixup = true; - installPhase = '' - mkdir -p $out - cp -R * $out - ''; - }; - }; - in { - overlay_pkgs = pkgs.lib.composeManyExtensions [ - (import ./overlay.nix) - lowRISC_spike_override - (final: prev: { - inherit vivado; - }) - ]; - }; -} diff --git a/dependencies/overlay.nix b/dependencies/overlay.nix deleted file mode 100644 index aedd9b13..00000000 --- a/dependencies/overlay.nix +++ /dev/null @@ -1,3 +0,0 @@ -final: prev: { - riscv-isa-sim = prev.callPackage ./riscv-isa-sim.nix {}; -} diff --git a/dependencies/riscv-isa-sim.nix b/dependencies/riscv-isa-sim.nix deleted file mode 100644 index 36b0ea18..00000000 --- a/dependencies/riscv-isa-sim.nix +++ /dev/null @@ -1,34 +0,0 @@ -{ - lib, - stdenv, - fetchFromGitHub, - dtc, -}: -stdenv.mkDerivation rec { - name = "spike"; - pname = "riscv-isa-sim"; - version = "1.1.1-dev"; - - src = fetchFromGitHub { - owner = "riscv-software-src"; - repo = pname; - rev = "ac466a21df442c59962589ba296c702631e041b5"; - sha256 = "sha256-1OLGEdj0dGnNREKZOrkAyKET7d2L+VFebOGm2oxtkHw="; - }; - - enableParallelBuilding = true; - # buildInputs = [ ]; - nativeBuildInputs = [dtc]; - configureFlags = ["--enable-commitlog" "--enable-misaligned"]; - - doCheck = false; - dontInstall = false; - - meta = with lib; { - description = "Riscv golden-reference simulator Spike"; - homepage = "https://github.com/riscv-software-src/riscv-isa-sim"; - license = with licenses; []; - platforms = platforms.unix; - maintainers = with maintainers; []; - }; -} diff --git a/dependencies/riscv_gcc.nix b/dependencies/riscv_gcc.nix deleted file mode 100644 index 09f241ee..00000000 --- a/dependencies/riscv_gcc.nix +++ /dev/null @@ -1,44 +0,0 @@ -{ - # Chosen toolchain subarchitecture, e.g. 'rv32imc' - riscv-arch, - # Package set - pkgs, -}: -# -------------------------- -# RISC-V GCC Toolchain Setup -let - riscv-toolchain-ver = "8.2.0"; - riscv-src = pkgs.fetchFromGitHub { - owner = "lowRISC"; - repo = "lowrisc-toolchains"; - rev = "2cac2b9797d96a5c46d86d463c71e0a66926f473"; - sha256 = "sha256-DNEkdJ5G8wpN2nQbD+nzvAQixWWGCG5RbJrXg5IRteg="; - }; - # - # given an architecture like 'rv32i', this will generate the given - # toolchain derivation based on the above source code. - make-riscv-toolchain = arch: - pkgs.stdenv.mkDerivation rec { - name = "riscv-${arch}-toolchain-${version}"; - version = "${riscv-toolchain-ver}-${builtins.substring 0 7 src.rev}"; - src = riscv-src; - - configureFlags = ["--with-arch=${arch}"]; - installPhase = ":"; # 'make' installs on its own - # installPhase = '' - # mkdir -p $out - # cp -r * $out - # ''; - hardeningDisable = ["all"]; - enableParallelBuilding = true; - - # Stripping/fixups break the resulting libgcc.a archives, somehow. - # Maybe something in stdenv that does this... - dontStrip = true; - dontFixup = true; - - nativeBuildInputs = with pkgs; [curl gawk texinfo bison flex gperf]; - buildInputs = with pkgs; [libmpc mpfr gmp expat]; - }; -in - make-riscv-toolchain riscv-arch diff --git a/dependencies/vivado.nix b/dependencies/vivado.nix deleted file mode 100644 index 2750e2d3..00000000 --- a/dependencies/vivado.nix +++ /dev/null @@ -1,140 +0,0 @@ -{ - stdenv, - lib, - breakpointHook, - fetchurl, - patchelf, - makeWrapper, - vivado-src, - coreutils, - procps, - zlib, - ncurses5, - libxcrypt, - libuuid, - libSM, - libICE, - libX11, - libXrender, - libxcb, - libXext, - libXtst, - libXi, - glib, - gtk2, - freetype, -}: -stdenv.mkDerivation rec { - pname = "vivado"; - version = "2022.2"; - - # src = vivado-src; - - nativeBuildInputs = [ - vivado-src - makeWrapper - breakpointHook - ]; - - buildInputs = [ - procps - ncurses5 - libxcrypt - ]; - - dontUnpack = true; - dontBuild = true; - dontStrip = true; - - libPath = lib.makeLibraryPath [ - stdenv.cc.cc - ncurses5 - zlib - libxcrypt - libuuid - libSM - libICE - libX11 - libXrender - libxcb - libXext - libXtst - libXi - glib - gtk2 - freetype - ]; - - installPhase = '' - cat < install_config.txt - Edition=Vivado ML Standard - Product=Vivado - Destination=$out/opt - Modules=Spartan-7:1,Virtex-7:1,Artix-7:1 - InstallOptions= - CreateProgramGroupShortcuts=0 - ProgramGroupFolder=Xilinx Design Tools - CreateShortcutsForAllUsers=0 - CreateDesktopShortcuts=0 - CreateFileAssociation=0 - EOF - - mkdir -p $out/opt - export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libPath}" - export HOME=$out/userhome - - # The installer will be killed as soon as it says that post install tasks have failed. - # This is required because it tries to run the unpatched scripts to check if the installation - # has succeeded. However, these scripts will fail because they have not been patched yet, - # and the installer will proceed to delete the installation if not killed. - (${vivado-src}/xsetup \ - --agree XilinxEULA,3rdPartyEULA \ - --batch Install \ - --config install_config.txt || true) | while read line - do - [[ "''${line}" == *"Execution of Pre/Post Installation Tasks Failed"* ]] \ - && echo "killing installer!" \ - && ((pkill -9 -f "tps/lnx64/jre/bin/java") || true) - - echo ''${line} - done - ''; - - preFixup = '' - echo "Patch installed scripts" - patchShebangs $out/opt/Vivado/${version}/bin || true - - echo "Hack around lack of libtinfo in NixOS" - ln -s ${ncurses5}/lib/libncursesw.so.6 $out/opt/Vivado/${version}/lib/lnx64.o/libtinfo.so.5 || true - - echo "Patch ELFs" - for f in $out/opt/Vivado/${version}/bin/unwrapped/lnx64.o/* \ - $out/opt/Vitis_HLS/${version}/bin/unwrapped/lnx64.o/* - do - patchelf --set-interpreter "$(cat ${stdenv.cc}/nix-support/dynamic-linker)" $f || true - done - - echo "Wrapping binaries" - for f in $out/opt/Vivado/${version}/bin/vivado \ - $out/opt/Vitis_HLS/${version}/bin/vitis_hls - do - wrapProgram $f --prefix LD_LIBRARY_PATH : "${libPath}" || true - done - - # 'wrapProgram' on its own does not work - # - This is because of the way the Vivado script runs ./loader - # - Therefore, we need ---Even More Patches...--- - echo "Even More Patches..." - sed -i -- 's|`basename "\$0"`|vivado|g' $out/opt/Vivado/$version/bin/.vivado-wrapped - - echo "Adding to bin" - mkdir $out/bin - ln -s $out/opt/Vivado/${version}/bin/vivado $out/bin/vivado || true - ''; - - meta = with lib; { - description = "Xilinx Vivado"; - homepage = "https://www.xilinx.com/products/design-tools/vivado.html"; - license = licenses.unfree; - }; -} diff --git a/flake.lock b/flake.lock index 64e2cd89..27450726 100644 --- a/flake.lock +++ b/flake.lock @@ -1,32 +1,15 @@ { "nodes": { - "deps": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1, - "narHash": "sha256-5zyMPKmcAVEkmxwCAbNwTTKE7VJ7AfXjyuF5O916uVA=", - "path": "./dependencies", - "type": "path" - }, - "original": { - "path": "./dependencies", - "type": "path" - } - }, "flake-utils": { "inputs": { "systems": "systems" }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", "owner": "numtide", "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", "type": "github" }, "original": { @@ -42,11 +25,11 @@ "poetry2nix": "poetry2nix" }, "locked": { - "lastModified": 1704383370, - "narHash": "sha256-r1g68fd//ylpOodTU1eTq3AY9AIlXl2x6SMKFNQb/YQ=", + "lastModified": 1706138121, + "narHash": "sha256-S/UMWRfJDwR+Jw+saPH+Sur+Ce9lQtwgckjvEhzF6PM=", "owner": "lowRISC", "repo": "lowrisc-nix", - "rev": "09e6009e25a2d1b75c1b2612cad083275b876b3d", + "rev": "8be8c431584fac28e8629fa8b4dd67a051a9f2ad", "type": "github" }, "original": { @@ -79,11 +62,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1703992652, - "narHash": "sha256-C0o8AUyu8xYgJ36kOxJfXIroy9if/G6aJbNOpA5W0+M=", + "lastModified": 1705774713, + "narHash": "sha256-j6ADaDH9XiumUzkTPlFyCBcoWYhO83lfgiSqEJF2zcs=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "32f63574c85fbc80e4ba1fbb932cde9619bad25e", + "rev": "1b64fc1287991a9cce717a01c1973ef86cb1af0b", "type": "github" }, "original": { @@ -108,11 +91,11 @@ "treefmt-nix": "treefmt-nix" }, "locked": { - "lastModified": 1703546497, - "narHash": "sha256-CN/7HaEmHz+akXKejkRVhsxAm6HPGOmYBWMtgMkuROA=", + "lastModified": 1705060653, + "narHash": "sha256-puYyylgrBS4AFAHeyVRTjTUVD8DZdecJfymWJe7H438=", "owner": "nix-community", "repo": "poetry2nix", - "rev": "528d500ea826383cc126a9be1e633fc92b19ce5d", + "rev": "e0b44e9e2d3aa855d1dd77b06f067cd0e0c3860d", "type": "github" }, "original": { @@ -123,7 +106,6 @@ }, "root": { "inputs": { - "deps": "deps", "flake-utils": [ "lowrisc-nix", "flake-utils" diff --git a/flake.nix b/flake.nix index 746bf7e0..44115f60 100644 --- a/flake.nix +++ b/flake.nix @@ -7,11 +7,6 @@ nixpkgs.follows = "lowrisc-nix/nixpkgs"; flake-utils.follows = "lowrisc-nix/flake-utils"; poetry2nix.follows = "lowrisc-nix/poetry2nix"; - - deps = { - url = "path:./dependencies"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; outputs = inputs @ { @@ -19,18 +14,12 @@ lowrisc-nix, nixpkgs, flake-utils, - deps, ... }: let all_system_outputs = flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; config = {allowUnfree = true;}; - overlays = [ - # Add extra packages we might need - # Currently this contains spike - deps.overlay_pkgs - ]; }; pythonEnv = let @@ -53,23 +42,15 @@ # Needed when running verilator with FST support zlib ]; - nativeBuildInputs = with pkgs; [ + nativeBuildInputs = [ pythonEnv - + ] ++ (with pkgs; [ cmake openocd screen verilator - - # Currently we don't build the riscv-toolchain from src, we use a github release - # See https://github.com/lowRISC/lowrisc-nix/blob/main/pkgs/lowrisc-toolchain-gcc-rv32imcb.nix - - # riscv-toolchain (built from src) # BROKEN - # riscv-gcc-toolchain-lowrisc-src = pkgs.callPackage \ - # ./dependencies/riscv_gcc.nix { - # riscv-arch = "rv32imc"; - # }; - lowrisc-nix.packages.${system}.lowrisc-toolchain-gcc-rv32imcb + # Needed to compile verilator generated files + gcc gtkwave srecord @@ -81,7 +62,10 @@ # By default mkShell adds non-interactive bash to PATH bashInteractive - ]; + ]) ++ (with lowrisc-nix.packages.${system}; [ + ibex-cosim + lowrisc-toolchain-gcc-rv32imcb + ]); shellHook = '' # FIXME This works on Ubuntu, may not on other distros. FIXME export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive