From 4229b42d82383e9675eb57b56eaf20007873c996 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 9 Dec 2023 15:51:30 +0000 Subject: [PATCH] make config.hardware.dts.src nullable This is for QEMU where we won't have to provide a dtb because the device tree is built by the platform according the (emulated) hardware present. Maybe in future there will be other hardware devices where we don't need to provide a dtb. --- modules/hardware.nix | 10 ++++++++-- modules/outputs/extlinux.nix | 13 +++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/modules/hardware.nix b/modules/hardware.nix index 81ab050..2a6823f 100644 --- a/modules/hardware.nix +++ b/modules/hardware.nix @@ -16,8 +16,14 @@ in { hardware = { dts = { src = mkOption { - type = types.path; - description = "Path to the device tree source (usually from OpenWrt)"; + type = types.nullOr types.path; + description = '' + If the device requires an external device tree to be loaded + alongside the kernel, this is the path to the device tree source + (we usually get these from OpenWrt). This value may be null if the + platform creates the device tree - currently this is the case + only for QEMU. + ''; }; includes = mkOption { default = []; diff --git a/modules/outputs/extlinux.nix b/modules/outputs/extlinux.nix index a4d3516..25150fe 100644 --- a/modules/outputs/extlinux.nix +++ b/modules/outputs/extlinux.nix @@ -9,6 +9,7 @@ let cfg = config.boot.loader.extlinux; o = config.system.outputs; cmdline = concatStringsSep " " config.boot.commandLine; + wantsDtb = config.hardware.dts ? src && config.hardware.dts.src != null; in { options.system.outputs.extlinux = mkOption { type = types.package; @@ -20,18 +21,18 @@ in { system.outputs.extlinux = pkgs.runCommand "extlinux" {} '' mkdir $out cd $out - # cp {o.dtb} dtb + ${if wantsDtb then "cp ${o.dtb} dtb" else "true"} cp ${o.initramfs} initramfs - gzip -9f < ${o.kernel} > kernel.gz + cp ${o.zimage} kernel mkdir extlinux cat > extlinux/extlinux.conf << _EOF menu title Liminix timeout 100 label Liminix - kernel /boot/kernel.gz - initrd /boot/initramfs - append ${cmdline} - # fdt /boot/dtb + kernel /boot/kernel + # initrd /boot/initramfs + append ${cmdline} root=/dev/vda1 + ${if wantsDtb then "fdt /boot/dtb" else ""} _EOF ''; };