diff --git a/pkgs/os-specific/linux/firmware/ath9k/default.nix b/pkgs/os-specific/linux/firmware/ath9k/default.nix new file mode 100644 index 000000000000..63c49c0a0887 --- /dev/null +++ b/pkgs/os-specific/linux/firmware/ath9k/default.nix @@ -0,0 +1,147 @@ +{ lib +, stdenv +, fetchurl +, fetchFromGitHub +, m4 +, cmake +, perl +, writeScript +, enableUnstable ? false +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "ath9k-htc-blobless-firmware"; + version = if enableUnstable then "unstable-2022-05-22" else "1.4.0"; + + src = fetchFromGitHub ({ + owner = "qca"; + repo = "open-ath9k-htc-firmware"; + } // (if enableUnstable then { + rev = "d856466a068afe4069335257c0d28295ff777d92"; + hash = "sha256-9OE6qYGABeXjf1r/Depd+811EJ2e8I0Ni5ePHSOh9G4="; + } else { + rev = finalAttrs.version; + hash = "sha256-Q/A0ryIC5E1pt2Sh7o79gxHbe4OgdlrwflOWtxWSS5o="; + })); + + postPatch = '' + patchShebangs target_firmware/firmware-crc.pl + ''; + + nativeBuildInputs = [ m4 cmake perl ]; + + NIX_CFLAGS_COMPILE = "-w"; # old libiberty emits fatal warnings + + dontUseCmakeConfigure = true; + enableParallelBuilding = true; + + # The firmware repository builds its own toolchain, with patches + # applied to the xtensa support in both gcc and binutils. + preBuild = + let + inherit (lib) toUpper splitString last listToAttrs pipe; + inherit (builtins) map; + urls-and-hashes = import ./urls-and-hashes-${finalAttrs.version}.nix; + make-links = pipe + [ "gcc" "binutils" "gmp" "mpfr" "mpc" ] + [ (map (vname: fetchurl rec { + url = urls-and-hashes."${(toUpper vname) + "_URL"}"; + sha256 = urls-and-hashes."${(toUpper vname) + "_SUM"}" or ""; + name = last (splitString "/" url); + })) + (map (v: "ln -sT ${v} toolchain/dl/${v.name}")) + (lib.concatStringsSep "\n") + ]; + in '' + mkdir -p toolchain/dl + ${make-links} + ''; + + makeTargets = [ "toolchain" "firmware" ]; + + installPhase = '' + runHook preInstall + install -Dt $out/lib/firmware/ath9k_htc/ target_firmware/*.fw + runHook postInstall + ''; + + passthru = { + inherit (finalAttrs) src; + updateScript = writeScript "${finalAttrs.pname}-${finalAttrs.version}-updateScript" '' + nix-shell '' -A ${finalAttrs.pname}${lib.optionalString enableUnstable "-unstable"}.passthru.update \ + > pkgs/os-specific/linux/firmware/ath9k/urls-and-hashes-${finalAttrs.version}.nix + ''; + update = stdenv.mkDerivation { + name = "${finalAttrs.pname}-${finalAttrs.version}-update"; + shellHook = '' + echo 'rec {' + echo ' BASEDIR="$NIX_BUILD_TOP";' + make --dry-run --print-data-base -f ${finalAttrs.src}/Makefile download \ + | egrep '^[A-Z]+_(VER|URL|SUM|DIR) = ' \ + | sed 's_\([^ ]*\) = \(.*\)_\1 = "\2\";_' \ + | tr \( \{ \ + | tr \) \} + '' + # sha256 checksums were not added to upstream's Makefile until + # after the 1.4.0 release. The following line is needed for + # the `enableUnstable==false` build but not for the + # `enableUnstable==true` build. We can remove the lines below + # as soon as `enableUnstable==false` points to a version + # greater than 1.4.0. + + lib.optionalString (finalAttrs.version == "1.4.0") '' + echo 'GCC_SUM = "sha256-kuYcbcOgpEnmLXKjgYX9pVAWioZwLeoHEl69PsOZYoI=";' + echo 'MPFR_SUM = "sha256-e2bD8T3IOF8IJkyAWFPz4aju2rgHHVgvPmYZccms1f0=";' + echo 'MPC_SUM = "sha256-7VqBXP6lJdx3jfDLN0aLnBtVSq8w2TKLFDHKcFt0AP8=";' + echo 'GMP_SUM = "sha256-H1iKrMxBu5rtlG+f44Uhwm2LKQ0APF34B/ZWkPKq3sk=";' + echo 'BINUTILS_SUM = "sha256-KrLlsD4IbRLGKV+DGtrUaz4UEKOiNJM6Lo+sZssuehk=";' + '' + '' + echo '}' + exit + ''; + }; + }; + + meta = { + description = "Blobless, open source wifi firmware for ath9k_htc.ko"; + longDescription = '' + Firmware for Qualcomm Atheros cards which use the ath9k_htc.ko + Linux driver, supporting 802.11 abgn on both 2.4ghz and 5ghz + bands, 3x3-antenna MIMO, up to 600mbit/sec. + + Most devices which use this driver are based on the Qualcomm + Atheros AR9271 chip, which is a PCIe device. If your device + is connected via USB, it will also include a Qualcomm Atheros + AR7010, which bridges from a USB gadget interface to a PCIe + host interface. This repository includes the firmware for + both chips. + + This firmware is completely open source with no blobs, which + is quite rare in the wifi world. Wifi chips have their own + dedicated general-purpose CPUs. This source code allows you + to see what those CPUs are doing and modify their behavior. + ''; + license = with lib.licenses; [ # see NOTICE.txt for details + bsd3 # almost everything; "the ClearBSD licence" + gpl2ClasspathPlus # **/*cmnos_printf.c, only three files + mit # **/xtos, **/xtensa + ]; + + # release 1.4.0 vendors a GMP which uses an ancient version of + # autotools that does not work on aarch64 or powerpc. + # However, enableUnstable (unreleased upstream) works. + /* + # disabled until #195294 is merged + badPlatforms = + with lib.systems.inspect.patterns; + lib.optionals (!enableUnstable && lib.versionOlder finalAttrs.version "1.4.1") [ + isAarch64 + isPower64 + ]; + */ + + sourceProvenance = [ lib.sourceTypes.fromSource ]; + homepage = "http://lists.infradead.org/mailman/listinfo/ath9k_htc_fw"; + downloadPage = "https://github.com/qca/open-ath9k-htc-firmware"; + changelog = "https://github.com/qca/open-ath9k-htc-firmware/tags"; + }; +}) diff --git a/pkgs/os-specific/linux/firmware/ath9k/urls-and-hashes-1.4.0.nix b/pkgs/os-specific/linux/firmware/ath9k/urls-and-hashes-1.4.0.nix new file mode 100644 index 000000000000..d67669c93b33 --- /dev/null +++ b/pkgs/os-specific/linux/firmware/ath9k/urls-and-hashes-1.4.0.nix @@ -0,0 +1,26 @@ +rec { + BASEDIR="$NIX_BUILD_TOP"; +BINUTILS_URL = "https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.bz2"; +DL_DIR = "${TOOLCHAIN_DIR}/dl"; +GMP_URL = "https://ftp.gnu.org/gnu/gmp/gmp-${GMP_VER}.tar.bz2"; +GCC_URL = "https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-${GCC_VER}.tar.bz2"; +BINUTILS_DIR = "binutils-${BINUTILS_VER}"; +GCC_VER = "4.7.4"; +MPFR_URL = "https://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VER}.tar.bz2"; +MPC_VER = "1.0.1"; +GMP_DIR = "gmp-${GMP_VER}"; +MPC_URL = "https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VER}.tar.gz"; +GCC_DIR = "gcc-${GCC_VER}"; +MPFR_DIR = "mpfr-${MPFR_VER}"; +MPC_DIR = "mpc-${MPC_VER}"; +MPFR_VER = "3.1.1"; +GMP_VER = "5.0.5"; +BINUTILS_VER = "2.23.1"; +BUILD_DIR = "${TOOLCHAIN_DIR}/build"; +TOOLCHAIN_DIR = "${BASEDIR}/toolchain"; +GCC_SUM = "sha256-kuYcbcOgpEnmLXKjgYX9pVAWioZwLeoHEl69PsOZYoI="; +MPFR_SUM = "sha256-e2bD8T3IOF8IJkyAWFPz4aju2rgHHVgvPmYZccms1f0="; +MPC_SUM = "sha256-7VqBXP6lJdx3jfDLN0aLnBtVSq8w2TKLFDHKcFt0AP8="; +GMP_SUM = "sha256-H1iKrMxBu5rtlG+f44Uhwm2LKQ0APF34B/ZWkPKq3sk="; +BINUTILS_SUM = "sha256-KrLlsD4IbRLGKV+DGtrUaz4UEKOiNJM6Lo+sZssuehk="; +} diff --git a/pkgs/os-specific/linux/firmware/ath9k/urls-and-hashes-unstable-2022-05-22.nix b/pkgs/os-specific/linux/firmware/ath9k/urls-and-hashes-unstable-2022-05-22.nix new file mode 100644 index 000000000000..4234f91ef978 --- /dev/null +++ b/pkgs/os-specific/linux/firmware/ath9k/urls-and-hashes-unstable-2022-05-22.nix @@ -0,0 +1,26 @@ +rec { + BASEDIR="$NIX_BUILD_TOP"; +BINUTILS_URL = "https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VER}.tar.bz2"; +DL_DIR = "${TOOLCHAIN_DIR}/dl"; +GMP_SUM = "f51c99cb114deb21a60075ffb494c1a210eb9d7cb729ed042ddb7de9534451ea"; +GMP_URL = "https://ftp.gnu.org/gnu/gmp/gmp-${GMP_VER}.tar.bz2"; +GCC_URL = "https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/gcc-${GCC_VER}.tar.gz"; +BINUTILS_DIR = "binutils-${BINUTILS_VER}"; +GCC_VER = "10.2.0"; +MPFR_URL = "https://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VER}.tar.bz2"; +MPC_VER = "1.1.0"; +GMP_DIR = "gmp-${GMP_VER}"; +MPC_URL = "https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VER}.tar.gz"; +GCC_DIR = "gcc-${GCC_VER}"; +MPC_SUM = "6985c538143c1208dcb1ac42cedad6ff52e267b47e5f970183a3e75125b43c2e"; +GCC_SUM = "27e879dccc639cd7b0cc08ed575c1669492579529b53c9ff27b0b96265fa867d"; +BINUTILS_SUM = "7d24660f87093670738e58bcc7b7b06f121c0fcb0ca8fc44368d675a5ef9cff7"; +MPFR_DIR = "mpfr-${MPFR_VER}"; +MPC_DIR = "mpc-${MPC_VER}"; +MPFR_VER = "4.1.0"; +GMP_VER = "6.2.0"; +BINUTILS_VER = "2.35"; +BUILD_DIR = "${TOOLCHAIN_DIR}/build"; +MPFR_SUM = "feced2d430dd5a97805fa289fed3fc8ff2b094c02d05287fd6133e7f1f0ec926"; +TOOLCHAIN_DIR = "${BASEDIR}/toolchain"; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c980e42a9f7d..b49181de1abf 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -25151,6 +25151,10 @@ with pkgs; audit = callPackage ../os-specific/linux/audit { }; + ath9k-htc-blobless-firmware = callPackage ../os-specific/linux/firmware/ath9k { }; + ath9k-htc-blobless-firmware-unstable = + callPackage ../os-specific/linux/firmware/ath9k { enableUnstable = true; }; + b43Firmware_5_1_138 = callPackage ../os-specific/linux/firmware/b43-firmware/5.1.138.nix { }; b43Firmware_6_30_163_46 = callPackage ../os-specific/linux/firmware/b43-firmware/6.30.163.46.nix { };