commit b52133a28bfc8bd7e264a9a3b9ea0cce7e64224a
parent 44caefcd3bab54c69012d872c681ae782ef3c043
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 17 Dec 2024 20:36:14 +0000
add hardware.dts.includes option
Diffstat:
4 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/NEWS b/NEWS
@@ -134,6 +134,11 @@ and then run the generated `install.sh` script
2024-12-16
-config option rename: config.hardware.dts.includes is now
-hardware.dts.includePaths, which is a better name and also
-means I can use hardware.dts.includes for a different purpose
-\ No newline at end of file
+Config options changed: if you had set config.hardware.dts.includes
+(maybe in an out-of-tree device port) to specify the search paths
+in which dtc finds include files, you will need to change this to
+hardware.dts.includePaths.
+
+The "new" hardware.dts.includes option is now for dtsi files which
+should be merged into the device tree.
+
diff --git a/modules/hardware.nix b/modules/hardware.nix
@@ -29,6 +29,11 @@ in
description = "List of directories to search for DTS includes (.dtsi files)";
type = types.listOf types.path;
};
+ includes = mkOption {
+ default = [ ];
+ description = "\"dtsi\" fragments to include in the generated device tree";
+ type = types.listOf types.path;
+ };
};
defaultOutput = mkOption {
description = "\"Default\" output: what gets built for this device when outputs.default is requested. Typically this is \"mtdimage\" or \"vmroot\"";
diff --git a/modules/outputs.nix b/modules/outputs.nix
@@ -104,7 +104,7 @@ in
system.outputs = rec {
dtb = liminix.builders.dtb {
inherit (config.boot) commandLine;
- dts = config.hardware.dts.src;
+ dts = config.hardware.dts.includes ++ [config.hardware.dts.src];
includes = config.hardware.dts.includePaths ++ [
"${o.kernel.headers}/include"
];
diff --git a/pkgs/kernel/dtb.nix b/pkgs/kernel/dtb.nix
@@ -2,6 +2,8 @@
stdenv
, dtc
, lib
+, runCommand
+, writeText
}:
{ dts
, includes
@@ -10,14 +12,20 @@
cppDtSearchFlags = builtins.concatStringsSep " " (map (f: "-I${f}") includes);
dtcSearchFlags = builtins.concatStringsSep " " (map (f: "-i${f}") includes);
cmdline = lib.concatStringsSep " " commandLine;
+ chosen = writeText "chosen.dtsi" "/{ chosen { bootargs = ${builtins.toJSON cmdline}; }; };";
+ combined = writeText "combined-dts-fragments"
+ (lib.concatStrings
+ (builtins.map
+ (f: "#include \"${f}\"\n")
+ (dts ++ [ chosen ])));
in stdenv.mkDerivation {
name = "dtb";
phases = [ "buildPhase" ];
nativeBuildInputs = [ dtc ];
buildPhase = ''
- ${stdenv.cc.targetPrefix}cpp -nostdinc -x assembler-with-cpp ${cppDtSearchFlags} -undef -D__DTS__ -o dtb.tmp ${dts}
- echo '/{ chosen { bootargs = ${builtins.toJSON cmdline}; }; };' >> dtb.tmp
+ ${stdenv.cc.targetPrefix}cpp -nostdinc -x assembler-with-cpp ${cppDtSearchFlags} -undef -D__DTS__ -o dtb.tmp ${combined}
dtc ${dtcSearchFlags} -I dts -O dtb -o $out dtb.tmp
+ # dtc -I dtb -O dts $out
test -e $out
'';
}