~ruther/nix-fpga

ref: ac8eb230e0a2476a7bb3d6f6d7e8bdacd220a3a7 nix-fpga/flake.nix -rw-r--r-- 7.9 KiB
ac8eb230 — Rutherther feat: add Quartus 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
{
  description = "A very basic flake";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        inherit system;
      };
      runScriptPrefix = package: required: ''
        # Search for an imperative declaration of the installation directory of ${package}
        error=0
        if [[ -f ~/.config/${package}/nix.sh ]]; then
          source ~/.config/${package}/nix.sh
        else
          echo "nix-${package}-error: Did not find ~/.config/${package}/nix.sh" >&2
          error=1
        fi
        if [[ ! -d "$INSTALL_DIR" ]]; then
          echo "nix-${package}-error: INSTALL_DIR $INSTALL_DIR isn't a directory" >&2
          error=2
      '' + ''
        fi

        if [[ $error -ne 0 ]]; then
          exit $error
        fi
      '';

      # pkgs for Xilinx tools
      xilinxTargetPkgs = pkgs: with pkgs; [
        gnumake
        coreutils
        stdenv.cc.cc
        ncurses5
        ncurses
        zlib
        xorg.libX11
        xorg.libXrender
        xorg.libxcb
        xorg.libXext
        xorg.libXtst
        xorg.libXi
        freetype
        gtk2
        glib
        libxcrypt-legacy
        gperftools
        glibc.dev
        fontconfig
        liberation_ttf

        # Xilinx ISE
        glib
        iproute2
        libstdcxx5
        libusb-compat-0_1
        libuuid
        motif
        motif3-compat
        xorg.libXcursor
        xorg.libXft
        xorg.libXmu
        xorg.libXp
        xorg.libXt
        xorg.libXrandr
        xorg.libSM
        xorg.libICE
      ];

      quartusTargetPkgs = pkgs: with pkgs; [
        stdenv.cc.cc.lib
        zlib
        glib
        libxcrypt-legacy
        libpng12
        freetype
        fontconfig.lib
        xorg.libSM
        xorg.libICE
        xorg.libXrender
        xorg.libXext
        xorg.libX11
        xorg.libXtst
        xorg.libXi
        xorg.libXft
        xorg.libxcb.out
        xorg.xcbutilrenderutil.out
        xorg.libXau
        xorg.libXdmcp
        gtk2
        libelf
        expat
        dbus.lib
        brotli.lib
        libpng
        bzip2.out
      ];

    in {
      packages.${system} = {
        quartus-shell = pkgs.buildFHSEnv {
          targetPkgs = quartusTargetPkgs;
          name = "quartus-shell";
          runScript = pkgs.writeScript "quartus-shell" ''
            ${runScriptPrefix "quartus" false}
            if [[ ! -z $INSTALL_DIR ]]; then
              export PATH=$INSTALL_DIR/quartus/bin:$INSTALL_DIR/questa_fse/bin:$PATH
            fi
            export LD_LIBRARY_PATH=/lib:$LD_LIBRARY_PATH
            exec bash
          '';
        };

        quartus = pkgs.buildFHSEnv {
          targetPkgs = quartusTargetPkgs;
          name = "quartus";
          runScript = pkgs.writeScript "quartus" ''
            ${runScriptPrefix "quartus" true}
            export LD_LIBRARY_PATH=/lib:$LD_LIBRARY_PATH
            exec $INSTALL_DIR/quartus/bin/quartus
          '';
        };

        quartus-udev-rules = pkgs.writeTextFile {
          name = "quartus-usbblaster";
          destination = "/etc/udev/rules.d/51-usbblaster.rules";
          text = ''
            # Intel FPGA Download Cable
            SUBSYSTEM=="usb", ATTR{idVendor}=="09fb", ATTR{idProduct}=="6001", MODE="0666"
            SUBSYSTEM=="usb", ATTR{idVendor}=="09fb", ATTR{idProduct}=="6002", MODE="0666"
            SUBSYSTEM=="usb", ATTR{idVendor}=="09fb", ATTR{idProduct}=="6003", MODE="0666"

            # Intel FPGA Download Cable II
            SUBSYSTEM=="usb", ATTR{idVendor}=="09fb", ATTR{idProduct}=="6010", MODE="0666"
            SUBSYSTEM=="usb", ATTR{idVendor}=="09fb", ATTR{idProduct}=="6810", MODE="0666"
          '';
        };

        vivado-shell = pkgs.buildFHSEnv {
          targetPkgs = xilinxTargetPkgs;

          name = "vivado-shell";
          runScript = pkgs.writeScript "vivado-shell" ''
            ${runScriptPrefix "ise" false}
            if [[ ! -z $INSTALL_DIR ]]; then
              source $INSTALL_DIR/Vivado/2023.1/settings64.sh
            fi
            export LD_LIBRARY_PATH=/lib:$LD_LIBRARY_PATH
            exec bash
          '';
        };
        vivado = pkgs.buildFHSEnv {
          targetPkgs = xilinxTargetPkgs;

          name = "vivado-runner";
          runScript = pkgs.writeScript "vivado-runner" ''
            ${runScriptPrefix "vivado" true}
            export LD_LIBRARY_PATH=/lib:$LD_LIBRARY_PATH
            exec $INSTALL_DIR/Vivado/2023.1/bin/vivado "$@"
          '';
        };

        ise-shell = pkgs.buildFHSEnv {
          targetPkgs = pkgs: xilinxTargetPkgs pkgs ++ [
            self.packages.${system}.ise-fw
          ];

          name = "ise-shell";
          runScript = pkgs.writeScript "ise-shell" ''
            ${runScriptPrefix "ise" false}
            if [[ ! -z $INSTALL_DIR ]]; then
              source $INSTALL_DIR/14.7/ISE_DS/settings64.sh $INSTALL_DIR/14.7/ISE_DS
            fi
            exec bash
          '';
        };

        ise = pkgs.buildFHSEnv {
          targetPkgs = xilinxTargetPkgs;
          name = "xilinx-runner";

          runScript = ''
            ${runScriptPrefix "ise" true}
            source $INSTALL_DIR/14.7/ISE_DS/settings64.sh $INSTALL_DIR/14.7/ISE_DS
            $INSTALL_DIR/14.7/ISE_DS/ISE/bin/lin64/ise
          '';
        };

        ise-fw = pkgs.stdenv.mkDerivation {
          name = "xilinx-jtag-fw";
          phases = ["unpackPhase" "installPhase"];
          src = ./xilinx/ise/fw;
          installPhase = ''
            mkdir -p $out/share
            cp * $out/share/
          '';
        };

        ise-udev-rules = pkgs.writeTextFile (let
          ise-fw = self.packages.${system}.ise-fw;
        in {
          name = "ise-udev-rules";
          destination = "/etc/udev/rules.d/05-xilinx-ise.rules";
          text = ''
            # version 0003
            SYSFS{idVendor}=="03fd", SYSFS{idProduct}=="0008", MODE="666"
            BUS=="usb", ACTION=="add", SYSFS{idVendor}=="03fd", SYSFS{idProduct}=="0007", RUN+="${pkgs.fxload} -v -t fx2 -I ${ise-fw}/share/xusbdfwu.hex -D $tempnode"
            BUS=="usb", ACTION=="add", SYSFS{idVendor}=="03fd", SYSFS{idProduct}=="0009", RUN+="${pkgs.fxload} -v -t fx2 -I ${ise-fw}/share/xusb_xup.hex -D $tempnode"
            BUS=="usb", ACTION=="add", SYSFS{idVendor}=="03fd", SYSFS{idProduct}=="000d", RUN+="${pkgs.fxload} -v -t fx2 -I ${ise-fw}/share/xusb_emb.hex -D $tempnode"
            BUS=="usb", ACTION=="add", SYSFS{idVendor}=="03fd", SYSFS{idProduct}=="000f", RUN+="${pkgs.fxload} -v -t fx2 -I ${ise-fw}/share/xusb_xlp.hex -D $tempnode"
            BUS=="usb", ACTION=="add", SYSFS{idVendor}=="03fd", SYSFS{idProduct}=="0013", RUN+="${pkgs.fxload} -v -t fx2 -I ${ise-fw}/share/xusb_xp2.hex -D $tempnode"
            BUS=="usb", ACTION=="add", SYSFS{idVendor}=="03fd", SYSFS{idProduct}=="0015", RUN+="${pkgs.fxload} -v -t fx2 -I ${ise-fw}/share/xusb_xse.hex -D $tempnode"
          '';
        });

        vivado-udev-rules = pkgs.writeTextFile {
          name = "vivado-udev-rules";
          destination = "/etc/udev/rules.d/10-xilinx-vivado.rules";
          text = ''
            # xilinx-ftdi-usb.rules
            ACTION=="add", ATTR{idVendor}=="0403", ATTR{manufacturer}=="Xilinx", MODE:="666"

            # xilinx-digilent-usb.rules
            ATTR{idVendor}=="1443", MODE:="666"
            ACTION=="add", ATTR{idVendor}=="0403", ATTR{manufacturer}=="Digilent", MODE:="666"

            # xilinx-pcusb.rules
            ATTR{idVendor}=="03fd", ATTR{idProduct}=="0008", MODE="666"
            ATTR{idVendor}=="03fd", ATTR{idProduct}=="0007", MODE="666"
            ATTR{idVendor}=="03fd", ATTR{idProduct}=="0009", MODE="666"
            ATTR{idVendor}=="03fd", ATTR{idProduct}=="000d", MODE="666"
            ATTR{idVendor}=="03fd", ATTR{idProduct}=="000f", MODE="666"
            ATTR{idVendor}=="03fd", ATTR{idProduct}=="0013", MODE="666"
            ATTR{idVendor}=="03fd", ATTR{idProduct}=="0015", MODE="666"
          '';
        };
      };
    };
}
Do not follow this link