mirror of
https://github.com/nix-community/raspberry-pi-nix.git
synced 2025-11-08 19:46:03 +01:00
use nix based config.txt generation
This commit is contained in:
parent
fdbe51e3b0
commit
67f257e524
3 changed files with 26 additions and 75 deletions
|
|
@ -22,11 +22,16 @@ let
|
||||||
args = render-dt-kvs v;
|
args = render-dt-kvs v;
|
||||||
}) overlays);
|
}) overlays);
|
||||||
render-config-section = k:
|
render-config-section = k:
|
||||||
{ options, base-dtb-params, dt-overlays }: ''
|
{ options, base-dtb-params, dt-overlays }:
|
||||||
|
let
|
||||||
|
all-config = lib.concatStringsSep "\n" (lib.filter (x: x != "") [
|
||||||
|
(render-options options)
|
||||||
|
(render-base-dt-params base-dtb-params)
|
||||||
|
(render-dt-overlays dt-overlays)
|
||||||
|
]);
|
||||||
|
in ''
|
||||||
[${k}]
|
[${k}]
|
||||||
${render-options options}
|
${all-config}
|
||||||
${render-base-dt-params base-dtb-params}
|
|
||||||
${render-dt-overlays dt-overlays}
|
|
||||||
'';
|
'';
|
||||||
in conf:
|
in conf:
|
||||||
lib.strings.concatStringsSep "\n"
|
lib.strings.concatStringsSep "\n"
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,17 @@
|
||||||
{
|
{
|
||||||
imports = [ ../sd-image ./config.nix ];
|
imports = [ ../sd-image ./config.nix ];
|
||||||
|
|
||||||
|
system.activationScripts.raspberrypi = {
|
||||||
|
text = ''
|
||||||
|
if ! grep -qs '/boot/firmware ' /proc/mounts; then
|
||||||
|
mount /dev/disk/by-label/${config.sdImage.firmwarePartitionName} /boot/firmware
|
||||||
|
fi
|
||||||
|
cp ${pkgs.uboot_rpi_arm64}/u-boot.bin /boot/firmware/u-boot-rpi-arm64.bin
|
||||||
|
cp -r ${pkgs.raspberrypifw}/share/raspberrypi/boot/{start*.elf,*.dtb,bootcode.bin,fixup*.dat,overlays} /boot/firmware
|
||||||
|
cp ${config.raspberrypi-config-output} /boot/firmware/config.txt
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
raspberrypi-config = {
|
raspberrypi-config = {
|
||||||
pi4 = {
|
pi4 = {
|
||||||
options = {
|
options = {
|
||||||
|
|
@ -17,16 +28,12 @@
|
||||||
pi02 = { dt-overlays = { vc4-kms-v3d = { cma-256 = null; }; }; };
|
pi02 = { dt-overlays = { vc4-kms-v3d = { cma-256 = null; }; }; };
|
||||||
all = {
|
all = {
|
||||||
options = {
|
options = {
|
||||||
kernel = "u-boot-rpi_arm64.bin";
|
kernel = "u-boot-rpi-arm64.bin";
|
||||||
enable_uart = true;
|
enable_uart = true;
|
||||||
avoid_warnings = true;
|
avoid_warnings = true;
|
||||||
arm_64bit = true;
|
arm_64bit = true;
|
||||||
};
|
};
|
||||||
base-dtb-params = {
|
base-dtb-params = { krnbt = "on"; };
|
||||||
i2c = "on";
|
|
||||||
audio = "on";
|
|
||||||
krnbt = "on";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [ ./sd-image.nix ];
|
imports = [ ./sd-image.nix ];
|
||||||
options.hardware.raspberry-pi = {
|
|
||||||
extra-config = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
boot.loader.grub.enable = false;
|
boot.loader.grub.enable = false;
|
||||||
|
|
@ -19,65 +13,10 @@
|
||||||
boot.kernelParams = [ "console=serial0,115200n8" "console=tty1" ];
|
boot.kernelParams = [ "console=serial0,115200n8" "console=tty1" ];
|
||||||
|
|
||||||
sdImage = {
|
sdImage = {
|
||||||
populateFirmwareCommands = let
|
populateFirmwareCommands = ''
|
||||||
inherit (pkgs) raspberrypifw;
|
cp ${pkgs.uboot_rpi_arm64}/u-boot.bin firmware/u-boot-rpi-arm64.bin
|
||||||
configTxt = pkgs.writeText "config.txt" ''
|
cp -r ${pkgs.raspberrypifw}/share/raspberrypi/boot/{start*.elf,*.dtb,bootcode.bin,fixup*.dat,overlays} firmware
|
||||||
[pi02]
|
cp ${config.raspberrypi-config-output} firmware/config.txt
|
||||||
kernel=u-boot-rpi_arm64.bin
|
|
||||||
|
|
||||||
[pi3+]
|
|
||||||
kernel=u-boot-rpi_arm64.bin
|
|
||||||
|
|
||||||
[pi4]
|
|
||||||
kernel=u-boot-rpi_arm64.bin
|
|
||||||
enable_gic=1
|
|
||||||
armstub=armstub8-gic.bin
|
|
||||||
arm_boost=1
|
|
||||||
dtoverlay=vc4-fkms-v3d-pi4
|
|
||||||
dtoverlay=
|
|
||||||
|
|
||||||
# Otherwise the resolution will be weird in most cases, compared to
|
|
||||||
# what the pi3 firmware does by default.
|
|
||||||
disable_overscan=1
|
|
||||||
|
|
||||||
[all]
|
|
||||||
# Boot in 64-bit mode.
|
|
||||||
arm_64bit=1
|
|
||||||
dtparam=audio=on
|
|
||||||
dtparam=krnbt=on
|
|
||||||
|
|
||||||
# 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
|
|
||||||
${config.hardware.raspberry-pi.extra-config}
|
|
||||||
'';
|
|
||||||
in ''
|
|
||||||
(cd ${raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf $NIX_BUILD_TOP/firmware/)
|
|
||||||
|
|
||||||
# Add the config
|
|
||||||
cp ${configTxt} firmware/config.txt
|
|
||||||
|
|
||||||
# Add rpi generic u-boot
|
|
||||||
cp ${pkgs.uboot_rpi_arm64}/u-boot.bin firmware/u-boot-rpi_arm64.bin
|
|
||||||
|
|
||||||
# Add pi3 specific files
|
|
||||||
cp ${raspberrypifw}/share/raspberrypi/boot/bcm2710-rpi-3-b-plus.dtb firmware/
|
|
||||||
|
|
||||||
# Add pi4 specific files
|
|
||||||
cp ${pkgs.raspberrypi-armstubs}/armstub8-gic.bin firmware/armstub8-gic.bin
|
|
||||||
cp ${raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-4-b.dtb firmware/
|
|
||||||
|
|
||||||
# Add pi-zero-2 specific files
|
|
||||||
cp ${raspberrypifw}/share/raspberrypi/boot/bcm2710-rpi-zero-2.dtb firmware/
|
|
||||||
cp ${raspberrypifw}/share/raspberrypi/boot/bcm2710-rpi-zero-2-w.dtb firmware/
|
|
||||||
|
|
||||||
# Add overlays
|
|
||||||
cp -r ${raspberrypifw}/share/raspberrypi/boot/overlays firmware/
|
|
||||||
'';
|
'';
|
||||||
populateRootCommands = ''
|
populateRootCommands = ''
|
||||||
mkdir -p ./files/boot
|
mkdir -p ./files/boot
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue