update default rpi config

This commit is contained in:
Travis Staton 2023-02-24 16:09:45 -05:00
parent 67f257e524
commit 739c404f11
6 changed files with 147 additions and 104 deletions

View file

@ -1,6 +1,6 @@
{ lib, config, pkgs, ... }:
let
cfg = config;
cfg = config.hardware.raspberry-pi;
render-raspberrypi-config = let
render-options = opts:
lib.strings.concatStringsSep "\n" (render-dt-kvs opts);
@ -22,11 +22,11 @@ let
args = render-dt-kvs v;
}) overlays);
render-config-section = k:
{ options, base-dtb-params, dt-overlays }:
{ options, base-dt-params, dt-overlays }:
let
all-config = lib.concatStringsSep "\n" (lib.filter (x: x != "") [
(render-options options)
(render-base-dt-params base-dtb-params)
(render-base-dt-params base-dt-params)
(render-dt-overlays dt-overlays)
]);
in ''
@ -38,48 +38,48 @@ let
(lib.attrsets.mapAttrsToList render-config-section conf);
in {
options = {
raspberrypi-config = let
raspberrypi-config-options = {
options = {
options = lib.mkOption {
type = with lib.types; attrsOf anything;
default = { };
example = {
enable_gic = true;
armstub = "armstub8-gic.bin";
arm_boost = true;
hardware.raspberry-pi = {
config = let
raspberry-pi-config-options = {
options = {
options = lib.mkOption {
type = with lib.types; attrsOf anything;
default = { };
example = {
enable_gic = true;
arm_boost = true;
};
};
};
base-dtb-params = lib.mkOption {
type = with lib.types; attrsOf anything;
default = { };
example = {
i2c = "on";
audio = "on";
base-dt-params = lib.mkOption {
type = with lib.types; attrsOf anything;
default = { };
example = {
i2c = "on";
audio = "on";
};
description = "parameters to pass to the base dtb";
};
dt-overlays = lib.mkOption {
type = with lib.types; attrsOf (attrsOf (nullOr str));
default = { };
example = { vc4-kms-v3d = { cma-256 = null; }; };
description = "dtb overlays to apply";
};
description = "parameters to pass to the base dtb";
};
dt-overlays = lib.mkOption {
type = with lib.types; attrsOf (attrsOf (nullOr str));
default = { };
example = { vc4-kms-v3d = { cma-256 = null; }; };
description = "dtb overlays to apply";
};
};
in lib.mkOption {
type = with lib.types; attrsOf (submodule raspberry-pi-config-options);
};
in lib.mkOption {
type = with lib.types; attrsOf (submodule raspberrypi-config-options);
};
raspberrypi-config-output = lib.mkOption {
type = lib.types.package;
default = pkgs.writeTextFile {
name = "config.txt";
text = ''
# Auto-generated by nix. Modifications will be overwritten.
${render-raspberrypi-config cfg.raspberrypi-config}
'';
config-output = lib.mkOption {
type = lib.types.package;
default = pkgs.writeTextFile {
name = "config.txt";
text = ''
# This is a generated file. Do not edit!
${render-raspberrypi-config cfg.config}
'';
};
};
};
};
}

View file

@ -2,8 +2,10 @@
{ lib, pkgs, config, ... }:
{
imports = [ ../sd-image ./config.nix ];
imports = [ ../sd-image ./config.nix ./i2c.nix ];
# On activation install u-boot, Raspberry Pi firmware, and our
# generated config.txt
system.activationScripts.raspberrypi = {
text = ''
if ! grep -qs '/boot/firmware ' /proc/mounts; then
@ -11,29 +13,28 @@
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
cp ${config.hardware.raspberry-pi.config-output} /boot/firmware/config.txt
'';
};
raspberrypi-config = {
pi4 = {
options = {
enable_gic = true;
armstub = "armstub8-gic.bin";
arm_boost = true;
disable_overscan = true;
};
dt-overlays = { vc4-kms-v3d-pi4 = { cma-512 = null; }; };
};
pi02 = { dt-overlays = { vc4-kms-v3d = { cma-256 = null; }; }; };
# Default config.txt on Raspberry Pi OS:
# https://github.com/RPi-Distro/pi-gen/blob/master/stage1/00-boot-files/files/config.txt
hardware.raspberry-pi.config = {
cm4 = { options = { otg_mode = true; }; };
pi4 = { options = { arm_boost = true; }; };
all = {
options = {
# The firmware will start our u-boot binary rather than a
# linux kernel.
kernel = "u-boot-rpi-arm64.bin";
arm_64bit = true;
enable_uart = true;
avoid_warnings = true;
arm_64bit = true;
camera_auto_detect = true;
display_auto_detect = true;
disable_overscan = true;
};
base-dtb-params = { krnbt = "on"; };
dt-overlays = { vc4-kms-v3d = { }; };
};
};
@ -59,4 +60,12 @@
};
};
hardware.enableRedistributableFirmware = true;
services = {
udev.extraRules = ''
SUBSYSTEM=="dma_heap", GROUP="video", MODE="0660"
KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
KERNEL=="gpiochip*", GROUP="gpio", MODE="0660"
'';
};
}

14
rpi/i2c.nix Normal file
View file

@ -0,0 +1,14 @@
{ config, lib, pkgs, ... }:
let cfg = config.hardware.raspberry-pi.i2c;
in {
options.hardware.raspberry-pi.i2c = {
enable = lib.mkEnableOption "configuration for i2c";
};
config = lib.mkIf cfg.enable {
hardware = {
raspberry-pi.config.all.base-dt-params = { i2c = "on"; };
i2c.enable = true;
};
};
}