diff options
author | Richard Marko <srk@48.io> | 2020-02-05 15:35:34 +0100 |
---|---|---|
committer | Richard Marko <srk@48.io> | 2020-09-09 16:34:58 +0200 |
commit | 6c9df40a4bc819fcab0836ad28ee944c8ce66db0 (patch) | |
tree | 80ffcae7dfc607f7b1ffd88cebb973ece359dbc1 /pkgs/os-specific/linux/device-tree | |
parent | 51428e8d38271d14146211867984b8742d304ea4 (diff) | |
download | nixpkgs-6c9df40a4bc819fcab0836ad28ee944c8ce66db0.tar nixpkgs-6c9df40a4bc819fcab0836ad28ee944c8ce66db0.tar.gz nixpkgs-6c9df40a4bc819fcab0836ad28ee944c8ce66db0.tar.bz2 nixpkgs-6c9df40a4bc819fcab0836ad28ee944c8ce66db0.tar.lz nixpkgs-6c9df40a4bc819fcab0836ad28ee944c8ce66db0.tar.xz nixpkgs-6c9df40a4bc819fcab0836ad28ee944c8ce66db0.tar.zst nixpkgs-6c9df40a4bc819fcab0836ad28ee944c8ce66db0.zip |
nixos/device-tree: improve overlays support
Now allows applying external overlays either in form of .dts file, literal dts context added to store or precompiled .dtbo. If overlays are defined, kernel device-trees are compiled with '-@' so the .dtb files contain symbols which we can reference in our overlays. Since `fdtoverlay` doesn't respect `/ compatible` by itself we query compatible strings of both `dtb` and `dtbo(verlay)` and apply only if latter is substring of the former. Also adds support for filtering .dtb files (as there are now nearly 1k dtbs). Co-authored-by: georgewhewell <georgerw@gmail.com> Co-authored-by: Kai Wohlfahrt <kai.wohlfahrt@gmail.com>
Diffstat (limited to 'pkgs/os-specific/linux/device-tree')
-rw-r--r-- | pkgs/os-specific/linux/device-tree/default.nix | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/pkgs/os-specific/linux/device-tree/default.nix b/pkgs/os-specific/linux/device-tree/default.nix index 13d819a08a5..0599289ab72 100644 --- a/pkgs/os-specific/linux/device-tree/default.nix +++ b/pkgs/os-specific/linux/device-tree/default.nix @@ -1,16 +1,31 @@ { stdenvNoCC, dtc, findutils }: with stdenvNoCC.lib; { - applyOverlays = (base: overlays: stdenvNoCC.mkDerivation { + applyOverlays = (base: overlays': stdenvNoCC.mkDerivation { name = "device-tree-overlays"; nativeBuildInputs = [ dtc findutils ]; buildCommand = let - quotedDtbos = concatMapStringsSep " " (o: "\"${toString o}\"") (toList overlays); + overlays = toList overlays'; in '' - for dtb in $(find ${base} -name "*.dtb" ); do - outDtb=$out/$(realpath --relative-to "${base}" "$dtb") - mkdir -p "$(dirname "$outDtb")" - fdtoverlay -o "$outDtb" -i "$dtb" ${quotedDtbos}; + 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 + '')} + done ''; }); |