Skip to content

Commit 21feee5

Browse files
committed
orange-pi-5-max: init
1 parent b48cc4d commit 21feee5

21 files changed

+1699
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ See code for all available configurations.
340340
| [Omen 15-en1007sa](omen/15-en1007sa) | `<nixos-hardware/omen/15-en1007sa>` |
341341
| [Omen 15-en0002np](omen/15-en0002np) | `<nixos-hardware/omen/15-en0002np>` |
342342
| [One-Netbook OneNetbook 4](onenetbook/4) | `<nixos-hardware/onenetbook/4>` |
343+
| [Orange Pi 5 Max](orange-pi/5-max) | `<nixos-hardware/orange-pi/5-max>` |
343344
| [Panasonic Let's Note CF-LX4](panasonic/letsnote/cf-lx4) | `<nixos-hardware/panasonic/letsnote/cf-lx4>` |
344345
| [PC Engines APU](pcengines/apu) | `<nixos-hardware/pcengines/apu>` |
345346
| [PINE64 Pinebook Pro](pine64/pinebook-pro/) | `<nixos-hardware/pine64/pinebook-pro>` |

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
omen-15-en0002np = import ./omen/15-en0002np;
293293
onenetbook-4 = import ./onenetbook/4;
294294
olimex-teres_i = import ./olimex/teres_i;
295+
orange-pi-5-max = import ./orange-pi/5-max;
295296
pcengines-apu = import ./pcengines/apu;
296297
pine64-pinebook-pro = import ./pine64/pinebook-pro;
297298
pine64-rockpro64 = import ./pine64/rockpro64;

orange-pi/5-max/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Creating an installation SD card image
2+
3+
Create and customize a `flake.nix` file:
4+
5+
```nix
6+
{
7+
inputs = {
8+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
9+
nixos-hardware.url = "github:nixos/nixos-hardware";
10+
};
11+
12+
outputs = { nixpkgs, nixos-hardware, ... }:
13+
let
14+
supportedSystems = [
15+
"x86_64-linux"
16+
"aarch64-linux"
17+
"riscv64-linux"
18+
"x86_64-darwin"
19+
"aarch64-darwin"
20+
];
21+
forAllSupportedSystems = nixpkgs.lib.genAttrs supportedSystems;
22+
in
23+
{
24+
packages = forAllSupportedSystems (system: rec {
25+
default = sd-image;
26+
sd-image = (import "${nixpkgs}/nixos" {
27+
configuration = {
28+
imports = [
29+
"${nixos-hardware}/orange-pi/5-max/sd-image-installer.nix"
30+
];
31+
32+
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (nixpkgs.lib.getName pkg) [
33+
"orangepi-firmware"
34+
"mali-g610-firmware"
35+
];
36+
37+
# If you want to use ssh set a password
38+
# users.users.nixos.password = "super secure password";
39+
# OR add your public ssh key
40+
# users.users.nixos.openssh.authorizedKeys.keys = [ "ssh-rsa ..." ];
41+
42+
nixpkgs.buildPlatform.system = system;
43+
nixpkgs.hostPlatform.system = "aarch64-linux";
44+
45+
system.stateVersion = "24.11";
46+
};
47+
inherit system;
48+
}).config.system.build.sdImage;
49+
});
50+
};
51+
}
52+
```
53+
54+
Then build the image by running `nix build .#` in the same folder.
55+
56+
## Flashing image
57+
Replace `/dev/sdX` with the device name of your sd card.
58+
```sh
59+
zstdcat result/sd-image/nixos-sd-image-*-orange-pi-5-max.img.zst | sudo dd status=progress bs=8M of=/dev/sdX
60+
```
61+
62+
# Updating the bootloader
63+
Install the enable the update scripts
64+
```nix
65+
hardware.orange-pi."5-max".uboot.updater.enable = true;
66+
```
67+
68+
uart debugging options are applied to the bootloader installed by the firmware update script
69+
```nix
70+
hardware.orange-pi."5-max".uartDebug = {
71+
enable = true; # enabled by default for debugging
72+
baudRate = 57600; # default is 1500000
73+
};
74+
```
75+
76+
## SD-Card
77+
Run as root
78+
``` sh
79+
orangepi5max-firmware-update-sd
80+
```
81+
## SPI Flash
82+
Run as root
83+
``` sh
84+
orangepi5max-firmware-update-flash
85+
```

orange-pi/5-max/audio.nix

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{ config, lib, ... }:
2+
let
3+
cfg = config.hardware.orange-pi."5-max".audio;
4+
in
5+
{
6+
options.hardware = {
7+
orange-pi."5-max".audio = {
8+
enable = lib.mkEnableOption "audio device configuration" // {
9+
default = true;
10+
};
11+
};
12+
};
13+
14+
config = lib.mkIf cfg.enable {
15+
services.pipewire.wireplumber.extraConfig = {
16+
"orange-pi-5-max-descriptions" = {
17+
"monitor.alsa.rules" =
18+
let
19+
makeRule = name: description: {
20+
matches = [{ "device.name" = name; }];
21+
actions = {
22+
update-props = {
23+
"device.description" = description;
24+
};
25+
};
26+
};
27+
in
28+
[
29+
(makeRule "alsa_card.platform-hdmi0-sound" "HDMI0 Audio")
30+
(makeRule "alsa_card.platform-hdmi1-sound" "HDMI1 Audio")
31+
(makeRule "alsa_card.platform-sound" "ES8388 Audio")
32+
];
33+
};
34+
};
35+
36+
services.udev.extraRules = ''
37+
SUBSYSTEM=="sound", ENV{ID_PATH}=="platform-hdmi0-sound", ENV{SOUND_DESCRIPTION}="HDMI0 Audio"
38+
SUBSYSTEM=="sound", ENV{ID_PATH}=="platform-hdmi1-sound", ENV{SOUND_DESCRIPTION}="HDMI1 Audio"
39+
SUBSYSTEM=="sound", ENV{ID_PATH}=="platform-sound", ENV{SOUND_DESCRIPTION}="ES8388 Audio"
40+
'';
41+
};
42+
}

orange-pi/5-max/bcmdhd_sdio.nix

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{ fetchFromGitHub
2+
, kernel
3+
, lib
4+
, stdenv
5+
, ...
6+
}:
7+
let
8+
rev = "101.10.591.52.27-4";
9+
in
10+
stdenv.mkDerivation rec {
11+
pname = "bcmdhd_sdio";
12+
version = "${rev}-${kernel.version}";
13+
14+
passthru.moduleName = "bcmdhd_sdio";
15+
16+
src = fetchFromGitHub {
17+
owner = "armbian";
18+
repo = "bcmdhd-dkms";
19+
inherit rev;
20+
hash = "sha256-e9oWorovZrsqm7qZjXygVluahTCIxi4yJy2Pp6lwdl8=";
21+
};
22+
23+
sourceRoot = "${src.name}/src";
24+
25+
hardeningDisable = [ "pic" ];
26+
27+
nativeBuildInputs = kernel.moduleBuildDependencies;
28+
29+
postPatch = ''
30+
substituteInPlace include/linuxver.h \
31+
--replace-fail 'del_timer(&((t)->timer))' 'timer_delete(&((t)->timer))'
32+
substituteInPlace include/linuxver.h \
33+
--replace-fail 'del_timer_sync(&((t)->timer))' 'timer_delete_sync(&((t)->timer))'
34+
'';
35+
36+
buildPhase = ''
37+
make \
38+
LINUXDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build \
39+
ARCH=arm64 \
40+
CROSS_COMPILE=${stdenv.cc.targetPrefix} \
41+
bcmdhd_sdio \
42+
CONFIG_BCMDHD_SDIO=y \
43+
CONFIG_BCMDHD_DTS=y
44+
'';
45+
46+
installPhase = ''
47+
install -D bcmdhd_sdio.ko $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/bcmdhd_sdio.ko
48+
install -D dhd_static_buf_sdio.ko $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/dhd_static_buf_sdio.ko
49+
'';
50+
51+
meta.license = lib.licenses.gpl2Only;
52+
}

orange-pi/5-max/bluetooth.nix

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
{ config
2+
, pkgs
3+
, lib
4+
, ...
5+
}:
6+
let
7+
cfg = config.hardware.orange-pi."5-max".bluetooth;
8+
bcmdhd_sdio = config.boot.kernelPackages.callPackage ./bcmdhd_sdio.nix { };
9+
brcm_patchram_plus = pkgs.callPackage ./brcm_patchram_plus.nix { };
10+
orangepi-firmware = pkgs.callPackage ./orangepi-firmware.nix { };
11+
in
12+
{
13+
options.hardware = {
14+
orange-pi."5-max".bluetooth = {
15+
enable = lib.mkEnableOption "configuration for bluetooth" // {
16+
default = config.hardware.bluetooth.enable;
17+
};
18+
};
19+
};
20+
21+
config = lib.mkIf cfg.enable {
22+
boot = {
23+
kernelParams = [ "8250.nr_uarts=8" ];
24+
kernelModules = [ "bcmdhd_sdio" "btbcm" ];
25+
blacklistedKernelModules = [
26+
"bcmdhd"
27+
"dhd_static_buf"
28+
];
29+
extraModulePackages = [ bcmdhd_sdio ];
30+
extraModprobeConfig =
31+
let
32+
options = [
33+
"firmware_path=${orangepi-firmware}/lib/firmware/fw_syn43711a0_sdio.bin"
34+
"nvram_path=${orangepi-firmware}/lib/firmware/nvram_ap6611s.txt"
35+
"clm_path=${orangepi-firmware}/lib/firmware/clm_syn43711a0.blob"
36+
];
37+
in
38+
''
39+
options bcmdhd_sdio ${lib.concatStringsSep " " options}
40+
'';
41+
};
42+
43+
hardware = {
44+
deviceTree = {
45+
overlays = [
46+
{
47+
name = "orangepi-5-max-bt";
48+
dtsText = ''
49+
/dts-v1/;
50+
/plugin/;
51+
52+
#include <dt-bindings/gpio/gpio.h>
53+
#include <dt-bindings/pinctrl/rockchip.h>
54+
#include <dt-bindings/interrupt-controller/irq.h>
55+
56+
/ {
57+
compatible = "xunlong,orangepi-5-max";
58+
};
59+
/ {
60+
fragment@0 {
61+
target = <&pinctrl>;
62+
__overlay__ {
63+
wireless-bluetooth {
64+
bt_reg_on: bt-reg-on {
65+
rockchip,pins = <4 RK_PC4 RK_FUNC_GPIO &pcfg_pull_none>;
66+
};
67+
host_wake_bt: host-wake-bt {
68+
rockchip,pins = <4 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>;
69+
};
70+
bt_wake_host: bt-wake-host {
71+
rockchip,pins = <0 RK_PA0 RK_FUNC_GPIO &pcfg_pull_down>;
72+
};
73+
};
74+
};
75+
};
76+
fragment@1 {
77+
target = <&uart7>;
78+
__overlay__ {
79+
pinctrl-names = "default";
80+
pinctrl-0 = <&uart7m0_xfer &uart7m0_ctsn &uart7m0_rtsn>;
81+
uart-has-rtscts;
82+
status = "okay";
83+
bluetooth {
84+
compatible = "brcm,bcm43438-bt";
85+
clocks = <&hym8563>;
86+
clock-names = "lpo";
87+
device-wakeup-gpios = <&gpio4 RK_PC5 GPIO_ACTIVE_HIGH>;
88+
interrupt-parent = <&gpio0>;
89+
interrupts = <RK_PA0 IRQ_TYPE_EDGE_FALLING>;
90+
interrupt-names = "host-wakeup";
91+
pinctrl-names = "default";
92+
pinctrl-0 = <&bt_reg_on>, <&host_wake_bt>, <&bt_wake_host>;
93+
shutdown-gpios = <&gpio4 RK_PC4 GPIO_ACTIVE_HIGH>;
94+
vbat-supply = <&vcc_3v3_s3>;
95+
vddio-supply = <&vcc_1v8_s3>;
96+
};
97+
};
98+
};
99+
};
100+
'';
101+
}
102+
{
103+
name = "orangepi-5-max-wlan";
104+
dtsText = ''
105+
/dts-v1/;
106+
/plugin/;
107+
108+
#include <dt-bindings/gpio/gpio.h>
109+
#include <dt-bindings/pinctrl/rockchip.h>
110+
111+
/ {
112+
compatible = "xunlong,orangepi-5-max";
113+
};
114+
/ {
115+
fragment@0 {
116+
target = <&pinctrl>;
117+
__overlay__ {
118+
sdio-pwrseq {
119+
wifi_enable_h: wifi-enable-h {
120+
rockchip,pins = <2 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>;
121+
};
122+
};
123+
wireless-wlan {
124+
wifi_host_wake_irq: wifi-host-wake-irq {
125+
rockchip,pins = <0 RK_PB0 RK_FUNC_GPIO &pcfg_pull_down>;
126+
};
127+
};
128+
};
129+
};
130+
fragment@1 {
131+
target-path = "/";
132+
__overlay__ {
133+
sdio_pwrseq: sdio-pwrseq {
134+
compatible = "mmc-pwrseq-simple";
135+
clocks = <&hym8563>;
136+
clock-names = "ext_clock";
137+
pinctrl-names = "default";
138+
pinctrl-0 = <&wifi_enable_h>;
139+
post-power-on-delay-ms = <200>;
140+
reset-gpios = <&gpio2 RK_PC5 GPIO_ACTIVE_LOW>;
141+
};
142+
wireless_wlan: wireless-wlan {
143+
compatible = "wlan-platdata";
144+
wifi_chip_type = "ap6611";
145+
pinctrl-names = "default";
146+
pinctrl-0 = <&wifi_host_wake_irq>;
147+
WIFI,host_wake_irq = <&gpio0 RK_PB0 GPIO_ACTIVE_HIGH>;
148+
WIFI,poweren_gpio = <&gpio2 RK_PC5 GPIO_ACTIVE_HIGH>;
149+
status = "okay";
150+
};
151+
};
152+
};
153+
fragment@2 {
154+
target = <&sdio>;
155+
__overlay__ {
156+
max-frequency = <150000000>;
157+
no-sd;
158+
no-mmc;
159+
bus-width = <4>;
160+
disable-wp;
161+
cap-sd-highspeed;
162+
cap-sdio-irq;
163+
keep-power-in-suspend;
164+
mmc-pwrseq = <&sdio_pwrseq>;
165+
non-removable;
166+
pinctrl-names = "default";
167+
pinctrl-0 = <&sdiom0_pins>;
168+
sd-uhs-sdr104;
169+
status = "okay";
170+
bcmdhd_wlan {
171+
compatible = "android,bcmdhd_wlan";
172+
gpio_wl_host_wake = <&gpio0 RK_PB0 GPIO_ACTIVE_HIGH>;
173+
};
174+
};
175+
};
176+
};
177+
'';
178+
}
179+
];
180+
};
181+
};
182+
};
183+
}

0 commit comments

Comments
 (0)