about summary refs log tree commit diff
diff options
context:
space:
mode:
authornikstur <nikstur@outlook.com>2023-11-16 13:02:06 +0100
committerGitHub <noreply@github.com>2023-11-16 13:02:06 +0100
commitdab45ad8ced499b15112d327ec6daaa9f5eb2588 (patch)
tree548226089e302e13f6e2da01d719dfe06967b7ed
parent7fb490674fbe789dafe09f018ae7470143ed5a3c (diff)
parentcc18755c080fe21accee5fb4678310d194994dce (diff)
Merge pull request #263149 from thillux/update-mstflint
mstflint: 4.17 -> 4.26
-rw-r--r--pkgs/os-specific/linux/mstflint_access/default.nix40
-rw-r--r--pkgs/tools/misc/mstflint/default.nix94
-rw-r--r--pkgs/top-level/linux-kernels.nix2
3 files changed, 131 insertions, 5 deletions
diff --git a/pkgs/os-specific/linux/mstflint_access/default.nix b/pkgs/os-specific/linux/mstflint_access/default.nix
new file mode 100644
index 0000000000000..6e29e27ccbf20
--- /dev/null
+++ b/pkgs/os-specific/linux/mstflint_access/default.nix
@@ -0,0 +1,40 @@
+{ lib, stdenv, fetchurl, kernel, kmod, mstflint }:
+
+stdenv.mkDerivation rec {
+  pname = "mstflint_access";
+  inherit (mstflint) version;
+
+  src = fetchurl {
+    url = "https://github.com/Mellanox/mstflint/releases/download/v${version}/kernel-mstflint-${version}.tar.gz";
+    hash = "sha256-rfZts0m8x6clVazpbAa2xK+dYgRU9Us5rbcWa0uHJ1M=";
+  };
+
+  nativeBuildInputs = [ kmod ] ++ kernel.moduleBuildDependencies;
+
+  makeFlags = kernel.makeFlags ++ [
+    "KVER=${kernel.modDirVersion}"
+    "KSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+  ];
+
+  enableParallelBuilding = true;
+
+  preConfigure = lib.optionals (lib.versionAtLeast kernel.version "6.4") ''
+    sed -i "s/class_create(THIS_MODULE, dev->name)/class_create(dev->name)/g" mst_main.c
+  '';
+
+  installPhase = ''
+    runHook preInstall
+
+    install -D ${pname}.ko $out/lib/modules/${kernel.modDirVersion}/extra/${pname}.ko
+
+    runHook postInstall
+  '';
+
+  meta = with lib; {
+    description = "A kernel module for Nvidia NIC firmware update";
+    homepage = "https://github.com/Mellanox/mstflint";
+    license = [ licenses.gpl2Only ];
+    maintainers = with maintainers; [ thillux ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/pkgs/tools/misc/mstflint/default.nix b/pkgs/tools/misc/mstflint/default.nix
index 51fd22b0c35e7..619858cbe3594 100644
--- a/pkgs/tools/misc/mstflint/default.nix
+++ b/pkgs/tools/misc/mstflint/default.nix
@@ -1,26 +1,109 @@
 { lib
 , stdenv
 , fetchurl
-, libibmad
+, rdma-core
 , openssl
 , zlib
+, xz
+, expat
+, boost
+, curl
+, pkg-config
+, libxml2
+, pciutils
+, busybox
+, python3
+, automake
+, autoconf
+, libtool
+, git
+# use this to shrink the package's footprint if necessary (e.g. for hardened appliances)
+, onlyFirmwareUpdater ? false
+# contains binary-only libraries
+, enableDPA ? true
 }:
 
 stdenv.mkDerivation rec {
   pname = "mstflint";
-  version = "4.17.0-1";
+  version = "4.26.0-1";
 
   src = fetchurl {
     url = "https://github.com/Mellanox/mstflint/releases/download/v${version}/mstflint-${version}.tar.gz";
-    sha256 = "030vpiv44sxmjf0dng91ziq1cggwj33yp0l4xc6cdhnrv2prjs7y";
+    hash = "sha256-P8XACcz6d8UTOhFFeTijfFOthBqnUghGlDj9K145sZ8=";
   };
 
+  nativeBuildInputs = [
+    autoconf
+    automake
+    libtool
+    pkg-config
+    libxml2
+    git
+  ];
+
   buildInputs = [
-    libibmad
-    openssl
+    rdma-core
     zlib
+    libxml2
+    openssl
+  ] ++ lib.optionals (!onlyFirmwareUpdater) [
+    boost
+    curl
+    expat
+    xz
+    python3
+  ];
+
+  preConfigure = ''
+    export CPPFLAGS="-I$(pwd)/tools_layouts -isystem ${libxml2.dev}/include/libxml2"
+    export INSTALL_BASEDIR=$out
+    ./autogen.sh
+  '';
+
+  # Cannot use wrapProgram since the python script's logic depends on the
+  # filename and will get messed up if the executable is named ".xyz-wrapped".
+  # That is why the python executable and runtime dependencies are injected
+  # this way.
+  #
+  # Remove host_cpu replacement again (see https://github.com/Mellanox/mstflint/pull/865),
+  # needs to hit master or a release. master_devel may be rebased.
+  #
+  # Remove patch for regex check, after https://github.com/Mellanox/mstflint/pull/871
+  # got merged.
+  prePatch = [
+  ''
+    patchShebangs eval_git_sha.sh
+    substituteInPlace configure.ac \
+        --replace "build_cpu" "host_cpu"
+    substituteInPlace common/compatibility.h \
+        --replace "#define ROOT_PATH \"/\"" "#define ROOT_PATH \"$out/\""
+    substituteInPlace configure.ac \
+        --replace 'Whether to use GNU C regex])' 'Whether to use GNU C regex])],[AC_MSG_RESULT([yes])'
+  ''
+  (lib.optionals (!onlyFirmwareUpdater) ''
+    substituteInPlace common/python_wrapper.sh \
+      --replace \
+      'exec $PYTHON_EXEC $SCRIPT_PATH "$@"' \
+      'export PATH=$PATH:${lib.makeBinPath [ (placeholder "out") pciutils busybox]}; exec ${python3}/bin/python3 $SCRIPT_PATH "$@"'
+  '')
   ];
 
+  configureFlags = [
+    "--enable-xml2"
+    "--datarootdir=${placeholder "out"}/share"
+  ] ++ lib.optionals (!onlyFirmwareUpdater) [
+    "--enable-adb-generic-tools"
+    "--enable-cs"
+    "--enable-dc"
+    "--enable-fw-mgr"
+    "--enable-inband"
+    "--enable-rdmem"
+  ] ++ lib.optionals enableDPA [
+    "--enable-dpa"
+  ];
+
+  enableParallelBuilding = true;
+
   hardeningDisable = [ "format" ];
 
   dontDisableStatic = true;  # the build fails without this. should probably be reported upstream
@@ -29,6 +112,7 @@ stdenv.mkDerivation rec {
     description = "Open source version of Mellanox Firmware Tools (MFT)";
     homepage = "https://github.com/Mellanox/mstflint";
     license = with licenses; [ gpl2 bsd2 ];
+    maintainers = with maintainers; [ thillux ];
     platforms = platforms.linux;
   };
 }
diff --git a/pkgs/top-level/linux-kernels.nix b/pkgs/top-level/linux-kernels.nix
index a997b12325efa..e0afcc773f0a9 100644
--- a/pkgs/top-level/linux-kernels.nix
+++ b/pkgs/top-level/linux-kernels.nix
@@ -387,6 +387,8 @@ in {
 
     lttng-modules = callPackage ../os-specific/linux/lttng-modules { };
 
+    mstflint_access = callPackage ../os-specific/linux/mstflint_access { };
+
     broadcom_sta = callPackage ../os-specific/linux/broadcom-sta { };
 
     tbs = callPackage ../os-specific/linux/tbs { };