Merge pull request #187528 from rnhmjoj/pr-fix-dt-overlays
nixos/hardware/device-tree: make overlays more reliable
This commit is contained in:
commit
66d043b296
2 changed files with 34 additions and 11 deletions
|
@ -14,6 +14,15 @@ let
|
|||
'';
|
||||
};
|
||||
|
||||
filter = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
example = "*rpi*.dtb";
|
||||
description = lib.mdDoc ''
|
||||
Only apply to .dtb files matching glob expression.
|
||||
'';
|
||||
};
|
||||
|
||||
dtsFile = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
description = lib.mdDoc ''
|
||||
|
@ -150,6 +159,7 @@ in
|
|||
'';
|
||||
type = types.listOf (types.coercedTo types.path (path: {
|
||||
name = baseNameOf path;
|
||||
filter = null;
|
||||
dtboFile = path;
|
||||
}) overlayType);
|
||||
description = lib.mdDoc ''
|
||||
|
|
|
@ -8,22 +8,35 @@ with lib; {
|
|||
overlays = toList overlays';
|
||||
in ''
|
||||
mkdir -p $out
|
||||
cd ${base}
|
||||
cd "${base}"
|
||||
find . -type f -name '*.dtb' -print0 \
|
||||
| xargs -0 cp -v --no-preserve=mode --target-directory $out --parents
|
||||
| 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 )"
|
||||
for dtb in $(find "$out" -type f -name '*.dtb'); do
|
||||
dtbCompat=$(fdtget -t s "$dtb" / compatible 2>/dev/null || true)
|
||||
# skip files without `compatible` string
|
||||
test -z "$dtbCompat" && continue
|
||||
|
||||
${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
|
||||
overlayCompat="$(fdtget -t s "${o.dtboFile}" / compatible)"
|
||||
|
||||
# skip incompatible and non-matching overlays
|
||||
if [[ ! "$dtbCompat" =~ "$overlayCompat" ]]; then
|
||||
echo -n "Skipping overlay ${o.name}: incompatible with $(basename "$dtb")"
|
||||
continue
|
||||
fi
|
||||
${optionalString (o.filter != null) ''
|
||||
if [[ "''${dtb//${o.filter}/}" == "$dtb" ]]; then
|
||||
echo -n "Skipping overlay ${o.name}: filter does not match $(basename "$dtb")"
|
||||
continue
|
||||
fi
|
||||
''}
|
||||
|
||||
echo -n "Applying overlay ${o.name} to $(basename "$dtb")... "
|
||||
mv "$dtb"{,.in}
|
||||
fdtoverlay -o "$dtb" -i "$dtb.in" "${o.dtboFile}"
|
||||
echo "ok"
|
||||
rm "$dtb.in"
|
||||
'')}
|
||||
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue