Last active
April 2, 2018 14:59
-
-
Save georgewhewell/b359404255f3bce6e54f980b0c092702 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ lib, pkgs, ... }: | |
{ | |
imports = [ ./devicetree.nix ]; | |
boot.initrd.availableKernelModules = [ "fbtft_device" "fb_ssd1351" "fbtft" "spi_sun6i" "fbcon" ]; | |
boot.kernelParams = [ "fbcon=map:10" ]; | |
hardware.devicetree = { | |
enable = true; | |
dtbName = "sun8i-h2-plus-orangepi-zero"; | |
overlay = '' | |
/dts-v1/; | |
/plugin/; | |
/ { | |
compatible = "allwinner,sun8i-h3"; | |
fragment@0 { | |
target = <&pio>; | |
__overlay__ { | |
adafruit13m_pins: adafruit13m_pins { | |
allwinner,pins = "PG11"; | |
allwinner,function = "gpio_out"; | |
}; | |
}; | |
}; | |
fragment@1 { | |
target = <&spi1>; | |
__overlay__ { | |
/* needed to avoid dtc warning */ | |
#address-cells = <1>; | |
#size-cells = <0>; | |
status = "okay"; | |
adafruit13m: adafruit13m@0{ | |
compatible = "solomon,ssd1351"; | |
reg = <0>; | |
pinctrl-names = "default"; | |
pinctrl-0 = <&adafruit13m_pins>; | |
spi-max-frequency = <10000000>; | |
buswidth = <8>; | |
dc-gpios = <&pio 6 11 0>; | |
#debug = <4>; | |
rotate = <0>; | |
}; | |
}; | |
}; | |
__overrides__ { | |
#speed = <&adafruit13m>,"spi-max-frequency:0"; | |
#rotate = <&adafruit13m>,"rotate:0"; | |
fps = <&adafruit13m>,"fps:0"; | |
#debug = <&adafruit13m>,"debug:0"; | |
}; | |
}; | |
''; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, lib, pkgs, ... }: | |
with pkgs.stdenv; | |
with lib; | |
let | |
cfg = config.hardware.devicetree; | |
in { | |
options.hardware.devicetree = { | |
enable = mkOption { | |
type = types.bool; | |
default = false; | |
description = '' | |
Enable devicetree-related functionality | |
''; | |
}; | |
dtbName = mkOption { | |
type = types.string; | |
example = "sun8i-h2-plus-orangepi-zero"; | |
}; | |
overlay = mkOption { | |
type = types.lines; | |
default = '' | |
''; | |
example = '' | |
/dts-v1/; | |
/plugin/; | |
/ { | |
compatible = "allwinner,sun8i-h3"; | |
fragment@0 { | |
target-path = "/aliases"; | |
__overlay__ { | |
serial3 = "/soc/serial@01c28c00"; | |
}; | |
}; | |
fragment@1 { | |
target = <&uart3>; | |
__overlay__ { | |
pinctrl-names = "default"; | |
pinctrl-0 = <&uart3_pins>; | |
status = "okay"; | |
}; | |
}; | |
}; | |
''; | |
description = '' | |
DTB Overlay | |
''; | |
}; | |
}; | |
config = mkIf cfg.enable { | |
system.build.dtb-with-overlay = let | |
overlayDts = pkgs.writeText "overlay.dts" config.hardware.devicetree.overlay; | |
dtbdir = if isArm then "arch/arm/boot/dts" else "arch/arm64/boot/dts"; | |
dtb-orig = mkDerivation { | |
name = "overlay"; | |
inherit (config.system.build.kernel) src nativeBuildInputs; | |
patches = map (patch: patch.patch) config.system.build.kernel.kernelPatches; | |
buildPhase = '' | |
substituteInPlace scripts/Makefile.lib \ | |
--replace 'DTC_FLAGS += $(DTC_FLAGS_$(basetarget))' 'DTC_FLAGS += $(DTC_FLAGS_$(basetarget)) -@' | |
make ${config.nixpkgs.config.platform.kernelBaseConfig} | |
make dtbs | |
''; | |
installPhase = '' | |
mkdir -p $out | |
cp -rv ${dtbdir} $out/dtbs | |
''; | |
}; | |
in pkgs.runCommand "apply-overlays" {} '' | |
${pkgs.dtc}/bin/dtc -I dts ${overlayDts} -O dtb -@ -o overlay.dtbo | |
${pkgs.dtc}/bin/fdtoverlay -i ${dtb-orig}/dtbs/${cfg.dtbName}.dtb -o $out overlay.dtbo | |
''; | |
}; | |
meta = {}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment