mirror of
https://github.com/NixOS/nixos-hardware
synced 2024-11-23 03:19:42 +01:00
raspberry-pi/4: dtmerge update
Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
This commit is contained in:
parent
e462a4baf7
commit
93b1cdbb77
1 changed files with 35 additions and 15 deletions
|
@ -1,5 +1,5 @@
|
|||
# modification of nixpkgs deviceTree.applyOverlays to resolve https://github.com/NixOS/nixpkgs/issues/125354
|
||||
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/device-tree/default.nix
|
||||
# derived from https://github.com/NixOS/nixpkgs/blob/916ca8f2b0c208def051f8ea9760c534a40309db/pkgs/os-specific/linux/device-tree/default.nix
|
||||
{ lib, pkgs, stdenvNoCC, dtc, libraspberrypi }:
|
||||
|
||||
with lib; (base: overlays': stdenvNoCC.mkDerivation {
|
||||
|
@ -9,22 +9,42 @@ with lib; (base: overlays': stdenvNoCC.mkDerivation {
|
|||
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
|
||||
for dtb in $(find $out -type f -name '*.dtb'); do
|
||||
dtbCompat="$( fdtget -t s $dtb / compatible )"
|
||||
| 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 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}
|
||||
cp ${o.dtboFile}{,.dtbo}
|
||||
dtmerge "$dtb.in" "$dtb" ${o.dtboFile}.dtbo;
|
||||
rm $dtb.in ${o.dtboFile}.dtbo
|
||||
overlayCompat="$(fdtget -t s "${o.dtboFile}" / compatible)"
|
||||
|
||||
# skip incompatible and non-matching overlays
|
||||
if [[ ! "$dtbCompat" =~ "$overlayCompat" ]]; then
|
||||
echo "Skipping overlay ${o.name}: incompatible with $(basename "$dtb")"
|
||||
continue
|
||||
fi
|
||||
${optionalString ((o.filter or null) != null) ''
|
||||
if [[ "''${dtb//${o.filter}/}" == "$dtb" ]]; then
|
||||
echo "Skipping overlay ${o.name}: filter does not match $(basename "$dtb")"
|
||||
continue
|
||||
fi
|
||||
''}
|
||||
|
||||
echo -n "Applying overlay ${o.name} to $(basename "$dtb")... "
|
||||
mv "$dtb"{,.in}
|
||||
|
||||
# dtmerge requires a .dtbo ext for dtbo files, otherwise it adds it to the given file implicitly
|
||||
dtboWithExt="$TMPDIR/$(basename "${o.dtboFile}").dtbo"
|
||||
cp -r ${o.dtboFile} "$dtboWithExt"
|
||||
|
||||
dtmerge "$dtb.in" "$dtb" "$dtboWithExt"
|
||||
|
||||
echo "ok"
|
||||
rm "$dtb.in" "$dtboWithExt"
|
||||
'')}
|
||||
done
|
||||
'';
|
||||
|
||||
done'';
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue