This commit is contained in:
mjallen18
2025-12-26 16:20:02 -06:00
parent 4604e24ee5
commit afb60fc031
10 changed files with 573 additions and 5 deletions

View File

@@ -173,7 +173,6 @@ in
heroic
omnissa-horizon-client
jq
lutris
lzip
morph
orca-slicer

View File

@@ -41,10 +41,14 @@
"linuxPackages_cachyos-lto-server"
"linuxPackages_cachyos-lto-server-znver4"
"mesa"
"mesa_i686"
"mesa-radeonsi-jupiter"
"mesa-radv-jupiter"
"mgba"
"onnxruntime"
"opencv"
"opencv4"
"opencv4WithoutCuda"
"pipewire"
"qemu"
"qemu_kvm"
@@ -68,6 +72,8 @@
(_self: super: {
${namespace} = super.${namespace} // {
linux-rpi = super.${namespace}.linux-rpi.override { stdenv = super.ccacheStdenv; };
libraspberrypi = super.${namespace}.libraspberrypi.override { stdenv = super.ccacheStdenv; };
raspberrypi-utils = super.${namespace}.raspberrypi-utils.override { stdenv = super.ccacheStdenv; };
};
})
(_self: super: {

View File

@@ -0,0 +1,22 @@
{ inputs, self, namespace, ... }:
final: _prev:
let
pi5 = final.callPackage ../../packages/raspberrypi/linux-rpi/default.nix {
pkgs = final;
nixpkgs = inputs.nixpkgs;
inherit self;
};
pi4 = final.callPackage ../../packages/raspberrypi/linux-rpi/default.nix {
pkgs = final;
nixpkgs = inputs.nixpkgs;
rpiVersion = 4;
inherit self;
};
in
{
# ${namespace} = final.${namespace} // {
linuxPackages_rpi5 = final.linuxPackagesFor pi5;
linuxPackages_rpi4 = final.linuxPackagesFor pi4;
# };
}

View File

@@ -0,0 +1,63 @@
{
lib,
stdenvNoCC,
fetchFromGitHub,
}:
stdenvNoCC.mkDerivation {
pname = "raspberrypi-wireless-firmware";
version = "0-unstable-2025-04-08";
srcs = [
(fetchFromGitHub {
name = "bluez-firmware";
owner = "RPi-Distro";
repo = "bluez-firmware";
rev = "cdf61dc691a49ff01a124752bd04194907f0f9cd";
hash = "sha256-35pnbQV/zcikz9Vic+2a1QAS72riruKklV8JHboL9NY=";
})
(fetchFromGitHub {
name = "firmware-nonfree";
owner = "RPi-Distro";
repo = "firmware-nonfree";
rev = "40dea60e27078fac57a3fed51010e2c26865d49b";
hash = "sha256-yXKzrkr7zdw/ba8GEi0r+XjnZEsQ59LPEuXj0HaKwxU=";
})
];
sourceRoot = ".";
dontBuild = true;
# Firmware blobs do not need fixing and should not be modified
dontFixup = true;
installPhase = ''
runHook preInstall
mkdir -p "$out/lib/firmware/brcm"
# Wifi firmware
cp -rv "$NIX_BUILD_TOP/firmware-nonfree/debian/config/brcm80211/." "$out/lib/firmware/"
# Bluetooth firmware
cp -rv "$NIX_BUILD_TOP/bluez-firmware/debian/firmware/broadcom/." "$out/lib/firmware/brcm"
# brcmfmac43455-sdio.bin is a symlink to the non-existent path: ../cypress/cyfmac43455-sdio.bin.
# See https://github.com/RPi-Distro/firmware-nonfree/issues/26
ln -s "./cyfmac43455-sdio-standard.bin" "$out/lib/firmware/cypress/cyfmac43455-sdio.bin"
pushd $out/lib/firmware/brcm &>/dev/null
# Symlinks for Zero 2W
ln -s "./brcmfmac43436-sdio.clm_blob" "$out/lib/firmware/brcm/brcmfmac43430b0-sdio.clm_blob"
popd &>/dev/null
runHook postInstall
'';
meta = with lib; {
description = "Firmware for builtin Wifi/Bluetooth devices in the Raspberry Pi 3+ and Zero W";
homepage = "https://github.com/RPi-Distro/firmware-nonfree";
license = licenses.unfreeRedistributableFirmware;
platforms = platforms.linux;
maintainers = with maintainers; [ lopsided98 ];
};
}

View File

@@ -10,13 +10,13 @@
stdenv.mkDerivation (_finalAttrs: {
pname = "raspberrypi-utils";
version = "unstable-2025-11-19";
version = "unstable-2025-12-26";
src = fetchFromGitHub {
owner = "raspberrypi";
repo = "utils";
rev = "063d092c528c09b9dad5d7ed187ebf110a53303b";
hash = "sha256-vi89lzfuLS9xKHDnlpm7Aw1UCOGCcMfd0cQq0rA9yOQ=";
rev = "230d67ad28e74b17a42064453b2163991cb51a5e";
hash = "sha256-x3E8DwKKCmjxloCRB8djqNwuyrR4rok+JcNgPQ1ZH3Y=";
};
buildInputs = [

View File

@@ -0,0 +1,37 @@
{
lib,
stdenvNoCC,
fetchFromGitHub,
}:
stdenvNoCC.mkDerivation rec {
# NOTE: this should be updated with linux_rpi
pname = "raspberrypi-firmware";
version = "1.20250915";
src = fetchFromGitHub {
owner = "raspberrypi";
repo = "firmware";
rev = version;
hash = "sha256-DqVgsPhppxCsZ+H6S7XY5bBoRhOgPipKibDwikqBk08=";
};
installPhase = ''
mkdir -p $out/share/raspberrypi/
mv boot "$out/share/raspberrypi/"
'';
dontConfigure = true;
dontBuild = true;
dontFixup = true;
meta = with lib; {
description = "Firmware for the Raspberry Pi board";
homepage = "https://github.com/raspberrypi/firmware";
license = licenses.unfreeRedistributableFirmware; # See https://github.com/raspberrypi/firmware/blob/master/boot/LICENCE.broadcom
maintainers = with maintainers; [ dezgeg ];
# Hash mismatch on source, mystery.
# Maybe due to https://github.com/NixOS/nix/issues/847
broken = stdenvNoCC.hostPlatform.isDarwin;
};
}

275
packages/uboot/default.nix Normal file
View File

@@ -0,0 +1,275 @@
{
stdenv,
lib,
bc,
bison,
dtc,
fetchFromGitHub,
fetchpatch,
fetchurl,
flex,
gnutls,
installShellFiles,
libuuid,
meson-tools,
ncurses,
openssl,
rkbin,
swig,
which,
python3,
perl,
armTrustedFirmwareAllwinner,
armTrustedFirmwareAllwinnerH6,
armTrustedFirmwareAllwinnerH616,
armTrustedFirmwareRK3328,
armTrustedFirmwareRK3399,
armTrustedFirmwareRK3568,
armTrustedFirmwareRK3588,
armTrustedFirmwareS905,
opensbi,
buildPackages,
callPackages,
darwin,
}@pkgs:
let
defaultVersion = "2025.07";
defaultSrc = fetchurl {
url = "https://ftp.denx.de/pub/u-boot/u-boot-${defaultVersion}.tar.bz2";
hash = "sha256-D5M/bFpCaJW/MG6T5qxTxghw5LVM2lbZUhG+yZ5jvsc=";
};
# Dependencies for the tools need to be included as either native or cross,
# depending on which we're building
toolsDeps = [
ncurses # tools/kwboot
libuuid # tools/mkeficapsule
gnutls # tools/mkeficapsule
openssl # tools/mkimage and tools/env/fw_printenv
];
buildUBoot = lib.makeOverridable (
{
version ? null,
src ? null,
filesToInstall,
pythonScriptsToInstall ? { },
installDir ? "$out",
defconfig,
extraConfig ? "",
extraPatches ? [ ],
extraMakeFlags ? [ ],
extraMeta ? { },
crossTools ? false,
stdenv ? pkgs.stdenv,
...
}@args:
stdenv.mkDerivation (
{
pname = "uboot-${defconfig}";
version = if src == null then defaultVersion else version;
src = if src == null then defaultSrc else src;
patches = extraPatches;
postPatch = ''
${lib.concatMapStrings (script: ''
substituteInPlace ${script} \
--replace "#!/usr/bin/env python3" "#!${pythonScriptsToInstall.${script}}/bin/python3"
'') (builtins.attrNames pythonScriptsToInstall)}
patchShebangs tools
patchShebangs scripts
'';
nativeBuildInputs = [
ncurses # tools/kwboot
bc
bison
flex
installShellFiles
(buildPackages.python3.withPackages (p: [
p.libfdt
p.setuptools # for pkg_resources
p.pyelftools
]))
swig
which # for scripts/dtc-version.sh
perl # for oid build (secureboot)
]
++ lib.optionals (!crossTools) toolsDeps
++ lib.optionals stdenv.buildPlatform.isDarwin [ darwin.DarwinTools ]; # sw_vers command is needed on darwin
depsBuildBuild = [ buildPackages.gccStdenv.cc ]; # gccStdenv is needed for Darwin buildPlatform
buildInputs = lib.optionals crossTools toolsDeps;
hardeningDisable = [ "all" ];
enableParallelBuilding = true;
makeFlags = [
"DTC=${lib.getExe buildPackages.dtc}"
"CROSS_COMPILE=${stdenv.cc.targetPrefix}"
"HOSTCFLAGS=-fcommon"
]
++ extraMakeFlags;
passAsFile = [ "extraConfig" ];
configurePhase = ''
runHook preConfigure
make -j$NIX_BUILD_CORES ${defconfig}
cat $extraConfigPath >> .config
runHook postConfigure
'';
installPhase = ''
runHook preInstall
mkdir -p ${installDir}
cp ${
lib.concatStringsSep " " (filesToInstall ++ builtins.attrNames pythonScriptsToInstall)
} ${installDir}
mkdir -p "$out/nix-support"
${lib.concatMapStrings (file: ''
echo "file binary-dist ${installDir}/${baseNameOf file}" >> "$out/nix-support/hydra-build-products"
'') (filesToInstall ++ builtins.attrNames pythonScriptsToInstall)}
runHook postInstall
'';
dontStrip = true;
meta =
with lib;
{
homepage = "https://www.denx.de/wiki/U-Boot/";
description = "Boot loader for embedded systems";
license = licenses.gpl2Plus;
maintainers = with maintainers; [
dezgeg
lopsided98
];
}
// extraMeta;
}
// removeAttrs args [
"extraMeta"
"pythonScriptsToInstall"
]
)
);
in
{
inherit buildUBoot;
ubootTools = buildUBoot {
defconfig = "tools-only_defconfig";
installDir = "$out/bin";
hardeningDisable = [ ];
dontStrip = false;
extraMeta.platforms = lib.platforms.linux;
crossTools = true;
extraMakeFlags = [
"HOST_TOOLS_ALL=y"
"NO_SDL=1"
"cross_tools"
"envtools"
];
outputs = [
"out"
"man"
];
postInstall = ''
installManPage doc/*.1
# from u-boot's tools/env/README:
# "You should then create a symlink from fw_setenv to fw_printenv. They
# use the same program and its function depends on its basename."
ln -s $out/bin/fw_printenv $out/bin/fw_setenv
'';
filesToInstall = [
"tools/dumpimage"
"tools/fdt_add_pubkey"
"tools/fdtgrep"
"tools/kwboot"
"tools/mkeficapsule"
"tools/mkenvimage"
"tools/mkimage"
"tools/env/fw_printenv"
"tools/mkeficapsule"
];
pythonScriptsToInstall = {
"tools/efivar.py" = (python3.withPackages (ps: [ ps.pyopenssl ]));
};
};
ubootPythonTools = lib.recurseIntoAttrs (callPackages ./python.nix { });
ubootQemuAarch64 = buildUBoot {
defconfig = "qemu_arm64_defconfig";
extraMeta.platforms = [ "aarch64-linux" ];
filesToInstall = [ "u-boot.bin" ];
};
ubootQemuArm = buildUBoot {
defconfig = "qemu_arm_defconfig";
extraMeta.platforms = [ "armv7l-linux" ];
filesToInstall = [ "u-boot.bin" ];
};
ubootQemuRiscv64Smode = buildUBoot {
defconfig = "qemu-riscv64_smode_defconfig";
extraMeta.platforms = [ "riscv64-linux" ];
filesToInstall = [ "u-boot.bin" ];
};
ubootQemuX86 = buildUBoot {
defconfig = "qemu-x86_defconfig";
extraConfig = ''
CONFIG_USB_UHCI_HCD=y
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_EHCI_GENERIC=y
CONFIG_USB_XHCI_HCD=y
'';
extraMeta.platforms = [
"i686-linux"
"x86_64-linux"
];
filesToInstall = [ "u-boot.rom" ];
};
ubootQemuX86_64 = buildUBoot {
defconfig = "qemu-x86_64_defconfig";
extraConfig = ''
CONFIG_USB_UHCI_HCD=y
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_EHCI_GENERIC=y
CONFIG_USB_XHCI_HCD=y
'';
extraMeta.platforms = [ "x86_64-linux" ];
filesToInstall = [ "u-boot.rom" ];
};
ubootRaspberryPi4 = buildUBoot {
defconfig = "rpi_4_defconfig";
extraMeta.platforms = [ "aarch64-linux" ];
filesToInstall = [ "u-boot.bin" ];
};
ubootRaspberryPi5 = buildUBoot {
defconfig = "rpi_5_defconfig";
extraMeta.platforms = [ "aarch64-linux" ];
filesToInstall = [ "u-boot.bin" ];
};
}

160
packages/uboot/python.nix Normal file
View File

@@ -0,0 +1,160 @@
{
lib,
python3Packages,
fetchPypi,
makeWrapper,
armTrustedFirmwareTools,
bzip2,
cbfstool,
gzip,
lz4,
lzop,
openssl,
ubootTools,
vboot-utils,
xilinx-bootgen,
xz,
zstd,
}:
let
# We are fetching from PyPI because the code in the repository seems to be
# lagging behind the PyPI releases somehow...
version = "0.0.7";
in
rec {
u_boot_pylib = python3Packages.buildPythonPackage rec {
pname = "u_boot_pylib";
inherit version;
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-A5r20Y8mgxhOhaKMpd5MJN5ubzPbkodAO0Tr0RN1SRA=";
};
build-system = with python3Packages; [
setuptools
];
checkPhase = ''
${python3Packages.python.interpreter} "src/$pname/__main__.py"
# There are some tests in other files, but they are broken
'';
pythonImportsCheck = [ "u_boot_pylib" ];
};
dtoc = python3Packages.buildPythonPackage rec {
pname = "dtoc";
inherit version;
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-NA96CznIxjqpw2Ik8AJpJkJ/ei+kQTCUExwFgssV+CM=";
};
build-system = with python3Packages; [
setuptools
];
dependencies =
(with python3Packages; [
libfdt
])
++ [
u_boot_pylib
];
pythonImportsCheck = [ "dtoc" ];
};
binman =
let
btools = [
armTrustedFirmwareTools
bzip2
cbfstool
# TODO: cst
gzip
lz4
# TODO: lzma_alone
lzop
openssl
ubootTools
vboot-utils
xilinx-bootgen
xz
zstd
];
in
python3Packages.buildPythonApplication rec {
pname = "binary_manager";
inherit version;
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-llEBBhUoW5jTEQeoaTCjZN8y6Kj+PGNUSB3cKpgD06w=";
};
patches = [
./binman-resources.patch
];
patchFlags = [
"-p2"
"-d"
"src"
];
build-system = with python3Packages; [
setuptools
];
nativeBuildInputs = [ makeWrapper ];
dependencies =
(with python3Packages; [
jsonschema
pycryptodomex
pyelftools
yamllint
])
++ [
dtoc
u_boot_pylib
];
preFixup = ''
wrapProgram "$out/bin/binman" --prefix PATH : "${lib.makeBinPath btools}"
'';
};
patman = python3Packages.buildPythonApplication rec {
pname = "patch_manager";
inherit version;
pyproject = true;
src = fetchPypi {
inherit pname version;
hash = "sha256-zD9e87fpWKynpUcfxobbdk6wbM6Ja3f8hEVHS7DGIKQ=";
};
build-system = with python3Packages; [
setuptools
];
dependencies =
(with python3Packages; [
aiohttp
pygit2
])
++ [
u_boot_pylib
];
};
}

View File

@@ -8,7 +8,7 @@ in
bootloader = "kernel";
firmwarePackage = pkgs.raspberrypifw;
};
kernelPackages = pkgs.linuxPackagesFor pkgs.${namespace}.linux-rpi;
kernelPackages = pkgs.linuxPackages_rpi5;
supportedFilesystems = lib.mkForce [ ];
};

View File

@@ -3,6 +3,7 @@
# https://search.nixos.org/options and in the NixOS manual (`nixos-help`).
{
pkgs,
namespace,
...
}:
@@ -15,6 +16,11 @@
virtualisation.docker.enable = true;
environment.systemPackages = with pkgs.${namespace}; [
ubootRaspberryPi5
ubootTools
];
${namespace} = {
# ###################################################