1
0

add hardware.dts.includes option

This commit is contained in:
Daniel Barlow 2024-12-17 20:36:14 +00:00
parent 44caefcd3b
commit b52133a28b
4 changed files with 24 additions and 6 deletions

11
NEWS
View File

@ -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
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.

View File

@ -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\"";

View File

@ -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"
];

View File

@ -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
'';
}