2022-03-31 19:11:26 +01:00
|
|
|
{ lib, stdenvNoCC, dtc }:
|
2019-04-24 18:24:16 +01:00
|
|
|
|
2021-01-15 14:45:37 +00:00
|
|
|
with lib; {
|
2020-02-05 14:35:34 +00:00
|
|
|
applyOverlays = (base: overlays': stdenvNoCC.mkDerivation {
|
2019-04-24 18:24:16 +01:00
|
|
|
name = "device-tree-overlays";
|
2022-03-31 19:11:26 +01:00
|
|
|
nativeBuildInputs = [ dtc ];
|
2019-04-24 18:24:16 +01:00
|
|
|
buildCommand = let
|
2020-02-05 14:35:34 +00:00
|
|
|
overlays = toList overlays';
|
2019-04-24 18:24:16 +01:00
|
|
|
in ''
|
2020-02-05 14:35:34 +00:00
|
|
|
mkdir -p $out
|
|
|
|
cd ${base}
|
|
|
|
find . -type f -name '*.dtb' -print0 \
|
|
|
|
| xargs -0 cp -v --no-preserve=mode --target-directory $out --parents
|
|
|
|
|
|
|
|
for dtb in $(find $out -type f -name '*.dtb'); do
|
|
|
|
dtbCompat="$( fdtget -t s $dtb / compatible )"
|
|
|
|
|
|
|
|
${flip (concatMapStringsSep "\n") overlays (o: ''
|
|
|
|
overlayCompat="$( fdtget -t s ${o.dtboFile} / compatible )"
|
|
|
|
# overlayCompat in dtbCompat
|
|
|
|
if [[ "$dtbCompat" =~ "$overlayCompat" ]]; then
|
|
|
|
echo "Applying overlay ${o.name} to $( basename $dtb )"
|
|
|
|
mv $dtb{,.in}
|
|
|
|
fdtoverlay -o "$dtb" -i "$dtb.in" ${o.dtboFile};
|
|
|
|
rm $dtb.in
|
|
|
|
fi
|
|
|
|
'')}
|
|
|
|
|
2019-04-24 18:24:16 +01:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
}
|