From d2ed86d1ce568294ab9e5b307b6e1fb592b383d9 Mon Sep 17 00:00:00 2001 From: Frantisek Bohacek Date: Thu, 28 Sep 2023 21:11:46 +0200 Subject: [PATCH] feat: add Vivado wrapper --- hosts/desktop/default.nix | 10 ++-- hosts/desktop/home.nix | 6 ++- modules/programs/fpga/vivado/default.nix | 9 ++++ modules/programs/fpga/vivado/fhs.nix | 29 ++++++++++ modules/programs/fpga/vivado/home.nix | 10 ++++ .../vivado/udev/52-xilinx-digilent-usb.rules | 54 +++++++++++++++++++ .../fpga/vivado/udev/52-xilinx-ftdi-usb.rules | 47 ++++++++++++++++ .../fpga/vivado/udev/52-xilinx-pcusb.rules | 8 +++ modules/programs/fpga/vivado/vivado-pkg.nix | 21 ++++++++ 9 files changed, 189 insertions(+), 5 deletions(-) create mode 100644 modules/programs/fpga/vivado/default.nix create mode 100644 modules/programs/fpga/vivado/fhs.nix create mode 100644 modules/programs/fpga/vivado/home.nix create mode 100644 modules/programs/fpga/vivado/udev/52-xilinx-digilent-usb.rules create mode 100644 modules/programs/fpga/vivado/udev/52-xilinx-ftdi-usb.rules create mode 100644 modules/programs/fpga/vivado/udev/52-xilinx-pcusb.rules create mode 100644 modules/programs/fpga/vivado/vivado-pkg.nix diff --git a/hosts/desktop/default.nix b/hosts/desktop/default.nix index 6e81d37..3376c55 100644 --- a/hosts/desktop/default.nix +++ b/hosts/desktop/default.nix @@ -18,16 +18,18 @@ # └─ default.nix # -{ pkgs, lib, user, ... }: +{ pkgs, lib, user, config, ... }: { imports = # For now, if applying to other system, swap files [(import ./hardware-configuration.nix)] ++ # Current system hardware config @ /etc/nixos/hardware-configuration.nix - #[(import ../../modules/programs/games.nix)] ++ # Gaming [(import ../../modules/desktop/dm/sddm.nix)] ++ # Desktop manager [(import ../../modules/desktop/qtile/default.nix)] ++ # Window Manager - #(import ../../modules/desktop/virtualisation) ++ # Virtual Machines & VNC - (import ../../modules/hardware); # Hardware devices + (import ../../modules/hardware) ++ # Hardware devices + [(import ../../modules/programs/fpga/vivado { + inherit pkgs lib config; + vivadoPath = "/data/Linux/fpga/apps/xilinx/Vivado/2023.1/bin/vivado"; + })]; boot = { # Boot options kernelPackages = pkgs.linuxPackages_latest; diff --git a/hosts/desktop/home.nix b/hosts/desktop/home.nix index 1773b17..4a9ef0f 100644 --- a/hosts/desktop/home.nix +++ b/hosts/desktop/home.nix @@ -11,12 +11,16 @@ # └─ home.nix # -{ pkgs, ... }: +{ pkgs, lib, config, ... }: { imports = [ ../../modules/desktop/qtile/home.nix # Window Manager + (import ../../modules/programs/fpga/vivado/home.nix { + inherit pkgs lib config; + vivadoPath = "/data/Linux/fpga/apps/xilinx/Vivado/2023.1/bin/vivado"; + }) ]; home = { # Specific packages for desktop diff --git a/modules/programs/fpga/vivado/default.nix b/modules/programs/fpga/vivado/default.nix new file mode 100644 index 0000000..5b86cfe --- /dev/null +++ b/modules/programs/fpga/vivado/default.nix @@ -0,0 +1,9 @@ +{ config, lib, pkgs, vivadoPath, ... }: + +let + vivadoPkg = pkgs.callPackage ./vivado-pkg.nix { }; +in { + services.udev.packages = [ + vivadoPkg + ]; +} diff --git a/modules/programs/fpga/vivado/fhs.nix b/modules/programs/fpga/vivado/fhs.nix new file mode 100644 index 0000000..bb8a620 --- /dev/null +++ b/modules/programs/fpga/vivado/fhs.nix @@ -0,0 +1,29 @@ +{ stdenv, config, lib, pkgs, vivadoPath, ... }: + +pkgs.buildFHSEnv { + name = "vivado-wrapped"; + + targetPkgs = pkgs: with pkgs; [ + 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 + ]; + + runScript = "${vivadoPath}"; +} diff --git a/modules/programs/fpga/vivado/home.nix b/modules/programs/fpga/vivado/home.nix new file mode 100644 index 0000000..b5863dd --- /dev/null +++ b/modules/programs/fpga/vivado/home.nix @@ -0,0 +1,10 @@ +{ config, lib, pkgs, vivadoPath, ... }: + +let + vivadoPkg = pkgs.callPackage ./vivado-pkg.nix { inherit vivadoPath; }; + fhsPkg = pkgs.callPackage ./fhs.nix { inherit vivadoPath; }; +in { + home.packages = [ + fhsPkg + ]; +} diff --git a/modules/programs/fpga/vivado/udev/52-xilinx-digilent-usb.rules b/modules/programs/fpga/vivado/udev/52-xilinx-digilent-usb.rules new file mode 100644 index 0000000..2ef3019 --- /dev/null +++ b/modules/programs/fpga/vivado/udev/52-xilinx-digilent-usb.rules @@ -0,0 +1,54 @@ +########################################################################### +# # +# 52-digilent-usb.rules -- UDEV rules for Digilent USB Devices # +# # +########################################################################### +# Author: MTA # +# Copyright 2010 Digilent Inc. # +########################################################################### +# File Description: # +# # +# This file contains the rules used by UDEV when creating entries for # +# Digilent USB devices. In order for Digilent's shared libraries and # +# applications to access these devices without root privalages it is # +# necessary for UDEV to create entries for which all users have read # +# and write permission. # +# # +# Usage: # +# # +# Copy this file to "/etc/udev/rules.d/" and execute # +# "/censored/censored reload_rules" as root. This only needs to be done # +# immediately after installation. Each time you reboot your system the # +# rules are automatically loaded by UDEV. # +# # +########################################################################### +# Revision History: # +# # +# 04/15/2010(MTA): created # +# 02/28/2011(MTA): modified to support FTDI based devices # +# 07/10/2012(MTA): modified to work with UDEV versions 098 or newer # +# 04/19/2013(MTA): modified mode assignment to use ":=" insetead of "=" # +# so that our permission settings can't be overwritten by other # +# rules files # +# 07/28/2014(MTA): changed default application path # +# # +########################################################################### + +# Create "/dev" entries for Digilent device's with read and write +# permission granted to all users. +ATTR{idVendor}=="1443", MODE:="666" +ACTION=="add", ATTR{idVendor}=="0403", ATTR{manufacturer}=="Digilent", MODE:="666" + +# The following rules (if present) cause UDEV to ignore all UEVENTS for +# which the subsystem is "usb_endpoint" and the action is "add" or +# "remove". These rules are necessary to work around what appears to be a +# bug in the Kernel used by Red Hat Enterprise Linux 5/CentOS 5. The Kernel +# sends UEVENTS to remove and then add entries for the endpoints of a USB +# device in "/dev" each time a process releases an interface. This occurs +# each time a data transaction occurs. When an FPGA is configured or flash +# device is written a large number of transactions take place. If the +# following lines are commented out then UDEV will be overloaded for a long +# period of time while it tries to process the massive number of UEVENTS it +# receives from the kernel. Please note that this work around only applies +# to systems running RHEL5 or CentOS 5 and as a result the rules will only +# be present on those systems. diff --git a/modules/programs/fpga/vivado/udev/52-xilinx-ftdi-usb.rules b/modules/programs/fpga/vivado/udev/52-xilinx-ftdi-usb.rules new file mode 100644 index 0000000..3ff972c --- /dev/null +++ b/modules/programs/fpga/vivado/udev/52-xilinx-ftdi-usb.rules @@ -0,0 +1,47 @@ +########################################################################### +# # +# 52-xilinx-ftdi-usb.rules -- UDEV rules for Xilinx USB Devices # +# # +########################################################################### +# Author: EST # +# Copyright 2016 Xilinx Inc. # +########################################################################### +# File Description: # +# # +# This file contains the rules used by UDEV when creating entries for # +# Xilinx USB devices. In order for Xilinx's shared libraries and # +# applications to access these devices without root privalages it is # +# necessary for UDEV to create entries for which all users have read # +# and write permission. # +# # +# Usage: # +# # +# Copy this file to "/etc/udev/rules.d/" and execute # +# "/censored/censored reload_rules" as root. This only needs to be done # +# immediately after installation. Each time you reboot your system the # +# rules are automatically loaded by UDEV. # +# # +########################################################################### +# Revision History: # +# # +# 10/18/2016(EST): created # +# # +########################################################################### +# version 0001 +# Create "/dev" entries for Xilinx device's with read and write +# permission granted to all users. +ACTION=="add", ATTR{idVendor}=="0403", ATTR{manufacturer}=="Xilinx", MODE:="666" + +# The following rules (if present) cause UDEV to ignore all UEVENTS for +# which the subsystem is "usb_endpoint" and the action is "add" or +# "remove". These rules are necessary to work around what appears to be a +# bug in the Kernel used by Red Hat Enterprise Linux 6/CentOS 5. The Kernel +# sends UEVENTS to remove and then add entries for the endpoints of a USB +# device in "/dev" each time a process releases an interface. This occurs +# each time a data transaction occurs. When an FPGA is configured or flash +# device is written a large number of transactions take place. If the +# following lines are commented out then UDEV will be overloaded for a long +# period of time while it tries to process the massive number of UEVENTS it +# receives from the kernel. Please note that this work around only applies +# to systems running RHEL6 or CentOS 5 and as a result the rules will only +# be present on those systems. diff --git a/modules/programs/fpga/vivado/udev/52-xilinx-pcusb.rules b/modules/programs/fpga/vivado/udev/52-xilinx-pcusb.rules new file mode 100644 index 0000000..6d552df --- /dev/null +++ b/modules/programs/fpga/vivado/udev/52-xilinx-pcusb.rules @@ -0,0 +1,8 @@ +# version 0002 +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" diff --git a/modules/programs/fpga/vivado/vivado-pkg.nix b/modules/programs/fpga/vivado/vivado-pkg.nix new file mode 100644 index 0000000..b3da0b6 --- /dev/null +++ b/modules/programs/fpga/vivado/vivado-pkg.nix @@ -0,0 +1,21 @@ +{ stdenv, config, lib, pkgs, ... }: + +# Only udev rules... + +stdenv.mkDerivation { + name = "vivado-2023.1"; + + nativeBuildInputs = [ pkgs.zlib ]; + buildInputs = [ pkgs.patchelf pkgs.procps pkgs.ncurses5 pkgs.makeWrapper ]; + + src = ./.; + + installPhase = '' + mkdir -p $out/lib/udev/rules.d/ + cp udev/* $out/lib/udev/rules.d/ + ''; + + dontPatch = true; + dontConfigure = true; + dontBuild = true; +} -- 2.48.1