Created
January 8, 2021 10:51
-
-
Save yorickvP/2f2d2ce5ba54791bce1b2587fea16746 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ stdenv, fetchFromGitHub, cmake, pkgconfig }: | |
let | |
inherit (stdenv.lib) optionals; | |
isCross = stdenv.buildPlatform != stdenv.hostPlatform; | |
in | |
stdenv.mkDerivation { | |
pname = "raspberrypi-armstubs"; | |
version = "2020-10-08"; | |
src = fetchFromGitHub { | |
owner = "raspberrypi"; | |
repo = "tools"; | |
rev = "fc0e73c13865450e95edd046200e42a6e52d8256"; | |
sha256 = "1g6ikpjcrm5x0rk5aiwjdd8grf997qkvgamcrdxy6k9ln746h25s"; | |
}; | |
NIX_CFLAGS_COMPILE = [ | |
"-march=armv8-a+crc" | |
]; | |
preConfigure = '' | |
cd armstubs | |
''; | |
makeFlags = [ | |
"CC8=${stdenv.cc.targetPrefix}cc" | |
"LD8=${stdenv.cc.targetPrefix}ld" | |
"OBJCOPY8=${stdenv.cc.targetPrefix}objcopy" | |
"OBJDUMP8=${stdenv.cc.targetPrefix}objdump" | |
"CC7=${stdenv.cc.targetPrefix}cc" | |
"LD7=${stdenv.cc.targetPrefix}ld" | |
"OBJCOPY7=${stdenv.cc.targetPrefix}objcopy" | |
"OBJDUMP7=${stdenv.cc.targetPrefix}objdump" | |
] | |
++ optionals (stdenv.isAarch64) [ "armstub8.bin" "armstub8-gic.bin" ] | |
++ optionals (stdenv.isAarch32) [ "armstub7.bin" "armstub8-32.bin" "armstub8-32-gic.bin" ] | |
; | |
installPhase = '' | |
mkdir -vp $out/ | |
cp -v *.bin $out/ | |
''; | |
meta = with stdenv.lib; { | |
description = "Firmware related ARM stubs for the Raspberry Pi"; | |
homepage = https://github.com/raspberrypi/tools; | |
license = licenses.bsd3; | |
platforms = [ "armv6l-linux" "armv7l-linux" "aarch64-linux" ]; | |
maintainers = with maintainers; [ samueldr ]; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs, lib, modulesPath, }: { | |
imports = [ | |
./configuration.nix | |
(modulesPath + "/installer/cd-dvd/sd-image-armv7l-multiplatform.nix") | |
]; | |
nixpkgs.overlays = [ (super: self: { | |
ubootRaspberryPi3_32bit = self.buildUBoot { | |
defconfig = "rpi_3_32b_defconfig"; | |
extraMeta.platforms = ["armv7l-linux"]; | |
filesToInstall = ["u-boot.bin"]; | |
}; | |
ubootRaspberryPi4_32bit = self.buildUBoot { | |
defconfig = "rpi_4_32b_defconfig"; | |
extraMeta.platforms = ["armv7l-linux"]; | |
filesToInstall = ["u-boot.bin"]; | |
}; | |
raspberrypi-armstubs = super.callPackage ./raspberrypi-armstubs.nix {}; | |
}) ]; | |
boot.kernelPackages = lib.mkForce pkgs.linuxPackages_rpi4; | |
# see https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/installer/cd-dvd/sd-image-aarch64.nix#L35 | |
# see https://leiradel.github.io/2019/01/20/Raspberry-Pi-Stubs.html | |
sdImage = { | |
populateFirmwareCommands = let | |
configTxt = pkgs.writeText "config.txt" '' | |
[pi3] | |
kernel=u-boot-rpi3.bin | |
[pi4] | |
kernel=u-boot-rpi4.bin | |
armstub=armstub8-32.bin | |
# Otherwise the resolution will be weird in most cases, compared to | |
# what the pi3 firmware does by default. | |
disable_overscan=1 | |
[all] | |
# U-Boot needs this to work, regardless of whether UART is actually used or not. | |
# Look in arch/arm/mach-bcm283x/Kconfig in the U-Boot tree to see if this is still | |
# a requirement in the future. | |
enable_uart=1 | |
# Prevent the firmware from smashing the framebuffer setup done by the mainline kernel | |
# when attempting to show low-voltage or overtemperature warnings. | |
avoid_warnings=1 | |
''; | |
in lib.mkForce '' | |
(cd ${pkgs.raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf $NIX_BUILD_TOP/firmware/) | |
# Add the config | |
cp ${configTxt} firmware/config.txt | |
# Add pi3 specific files | |
cp ${pkgs.ubootRaspberryPi3_32bit}/u-boot.bin firmware/u-boot-rpi3.bin | |
# Add pi4 specific files | |
cp ${pkgs.ubootRaspberryPi4_32bit}/u-boot.bin firmware/u-boot-rpi4.bin | |
cp ${pkgs.raspberrypi-armstubs}/armstub8-32.bin firmware/armstub8-32.bin | |
cp ${pkgs.raspberrypi-armstubs}/armstub8-32-gic.bin firmware/armstub8-32-gic.bin | |
cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-4-b.dtb firmware/ | |
''; | |
}; | |
nixpkgs.localSystem = { | |
system = "armv7l-linux"; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, pkgs, lib, modulesPath, ... }: | |
{ | |
imports = [ | |
(modulesPath + "/profiles/minimal.nix") | |
(modulesPath + "/profiles/installation-device.nix") | |
(modulesPath + "/installer/cd-dvd/sd-image.nix") | |
]; | |
nixpkgs.overlays = [(self: super: { | |
# Does not cross-compile... | |
alsa-firmware = pkgs.runCommandNoCC "neutered-firmware" {} "mkdir -p $out"; | |
# A "regression" in nixpkgs, where python3 pycryptodome does not cross-compile. | |
crda = pkgs.runCommandNoCC "neutered-firmware" {} "mkdir -p $out"; | |
# Regression caused by including a new package in the closure | |
# Added in f1922cdbdc608b1f1f85a1d80310b54e89d0e9f3 | |
smartmontools = super.smartmontools.overrideAttrs(old: { | |
configureFlags = []; | |
}); | |
e2fsprogs = super.e2fsprogs.overrideAttrs (old: { | |
postPatch = old.postPatch + '' | |
rm -r tests/m_hugefile | |
''; | |
}); | |
})]; | |
# (Failing build in a dep to be investigated) | |
security.polkit.enable = false; | |
# cifs-utils fails to cross-compile | |
# Let's simplify this by removing all unneeded filesystems from the image. | |
boot.supportedFilesystems = lib.mkForce [ "vfat" ]; | |
# texinfoInteractive has trouble cross-compiling | |
documentation.info.enable = lib.mkForce false; | |
# `xterm` is being included even though this is GUI-less. | |
# → https://github.com/NixOS/nixpkgs/pull/62852 | |
services.xserver.desktopManager.xterm.enable = lib.mkForce false; | |
# ec6224b6cd147943eee685ef671811b3683cb2ce re-introduced udisks in the installer | |
# udisks fails due to gobject-introspection being not cross-compilation friendly. | |
services.udisks2.enable = lib.mkForce false; | |
services.openssh.enable = true; | |
users.users.root.openssh.authorizedKeys.keys = [ | |
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDo1N5E6qkb3McJOvv0PqI7E8iYLAcjil5RWc+zeTtN/" | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
# nixos-20.09 | |
nixpkgs = fetchTarball http://github.com/nixos/nixpkgs/archive/4a75ca4a4e7d14e7b0b0230b3ea57b5bd7c16218.tar.gz; | |
in | |
(import "${nixpkgs}/nixos/lib/eval-config.nix" { | |
modules = [ ./armv7l-rpi4-linux.nix ./configuration.nix ]; | |
}).config.system.build.sdImage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment