|
| 1 | +{ |
| 2 | + description = "Environment for developing and simulating the ibex core."; |
| 3 | + |
| 4 | + inputs = { |
| 5 | + # The input 'lowrisc-nix' contains some common dependencies that can be used |
| 6 | + # by lowRISC projects. There is also an associated public binary cache. |
| 7 | + lowrisc-nix.url = "github:lowRISC/lowrisc-nix"; |
| 8 | + |
| 9 | + nixpkgs.follows = "lowrisc-nix/nixpkgs"; |
| 10 | + flake-utils.follows = "lowrisc-nix/flake-utils"; |
| 11 | + poetry2nix.follows = "lowrisc-nix/poetry2nix"; |
| 12 | + sv2v = { |
| 13 | + url = "github:zachjs/sv2v"; |
| 14 | + flake = false; |
| 15 | + }; |
| 16 | + }; |
| 17 | + |
| 18 | + outputs = inputs: let |
| 19 | + |
| 20 | + # Only tested with the following systems: |
| 21 | + # - x86_64-linux |
| 22 | + system = inputs.flake-utils.lib.system.x86_64-linux; |
| 23 | + |
| 24 | + pkgs = import inputs.nixpkgs { |
| 25 | + inherit system; |
| 26 | + config = { |
| 27 | + allowUnfree = true; |
| 28 | + allowBroken = true; # sv2v marked as broken. |
| 29 | + }; |
| 30 | + }; |
| 31 | + |
| 32 | + ################ |
| 33 | + # DEPENDENCIES # |
| 34 | + ################ |
| 35 | + |
| 36 | + # Python environment, defined in ./nix/env/pyproject.toml |
| 37 | + pythonEnv = import ./nix/env {inherit inputs pkgs;}; |
| 38 | + |
| 39 | + # lowRISC fork of Spike used as a cosimulation model for Ibex Verification |
| 40 | + spike = inputs.lowrisc-nix.packages.${system}.spike-ibex-cosim; |
| 41 | + |
| 42 | + # Currently we don't build the riscv-toolchain from src, we use a github release |
| 43 | + # See https://github.com/lowRISC/lowrisc-nix/blob/main/pkgs/lowrisc-toolchain-gcc-rv32imcb.nix |
| 44 | + rv32imcb_toolchain = inputs.lowrisc-nix.packages.${system}.lowrisc-toolchain-gcc-rv32imcb; |
| 45 | + |
| 46 | + ibex_runtime_deps = with pkgs; [ |
| 47 | + libelf # Used in DPI code |
| 48 | + zlib # Verilator run-time dep |
| 49 | + ]; |
| 50 | + |
| 51 | + sim_shared_lib_deps = with pkgs; [ |
| 52 | + elfutils |
| 53 | + openssl |
| 54 | + ]; |
| 55 | + |
| 56 | + ibex_project_deps = |
| 57 | + [ |
| 58 | + pythonEnv |
| 59 | + spike |
| 60 | + rv32imcb_toolchain |
| 61 | + ] ++ |
| 62 | + sim_shared_lib_deps ++ |
| 63 | + (with pkgs; [ |
| 64 | + # Tools |
| 65 | + cmake |
| 66 | + pkg-config |
| 67 | + |
| 68 | + # Applications |
| 69 | + verilator |
| 70 | + gtkwave |
| 71 | + |
| 72 | + # Libraries |
| 73 | + srecord |
| 74 | + ]); |
| 75 | + |
| 76 | + ibex_syn = import ./nix/syn.nix {inherit inputs pkgs;}; |
| 77 | + |
| 78 | + ################ |
| 79 | + # ENVIRONMENTS # |
| 80 | + ################ |
| 81 | + |
| 82 | + # These exports are required by scripts within the Ibex DV flow. |
| 83 | + ibex_profile_common = '' |
| 84 | + export SPIKE_PATH=${spike}/bin |
| 85 | +
|
| 86 | + export RISCV_TOOLCHAIN=${rv32imcb_toolchain} |
| 87 | + export RISCV_GCC=${rv32imcb_toolchain}/bin/riscv32-unknown-elf-gcc |
| 88 | + export RISCV_OBJCOPY=${rv32imcb_toolchain}/bin/riscv32-unknown-elf-objcopy |
| 89 | + ''; |
| 90 | + |
| 91 | + shell = pkgs.lib.makeOverridable pkgs.mkShell { |
| 92 | + name = "ibex-devshell"; |
| 93 | + buildInputs = ibex_runtime_deps; |
| 94 | + nativeBuildInputs = ibex_project_deps; |
| 95 | + shellHook = '' |
| 96 | + # Unset these environment variables provided by stdenv, as the SS makefiles will not |
| 97 | + # be able to discover the riscv toolchain versions otherwise. |
| 98 | + unset CC OBJCOPY OBJDUMP |
| 99 | +
|
| 100 | + ${ibex_profile_common} |
| 101 | + ''; |
| 102 | + }; |
| 103 | + |
| 104 | + in { |
| 105 | + devShells.${system} = { |
| 106 | + default = inputs.self.devShells.${system}.shell; |
| 107 | + |
| 108 | + inherit shell; |
| 109 | + }; |
| 110 | + }; |
| 111 | +} |
0 commit comments