Skip to content

Commit fa7ced3

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

24 files changed

+16082
-0
lines changed

README.md

+1
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

+1
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

+85
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

+42
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-es8388-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-es8388-sound", ENV{SOUND_DESCRIPTION}="ES8388 Audio"
40+
'';
41+
};
42+
}

orange-pi/5-max/bluetooth.nix

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{ config, pkgs, lib, ... }:
2+
let
3+
cfg = config.hardware.orange-pi."5-max".bluetooth;
4+
bcmdhd_sdio = config.boot.kernelPackages.callPackage ./kernel/bcmdhd_sdio.nix { };
5+
brcm_patchram_plus = pkgs.callPackage ./brcm_patchram_plus.nix { };
6+
orangepi-firmware = pkgs.callPackage ./orangepi-firmware.nix { };
7+
in
8+
{
9+
options.hardware = {
10+
orange-pi."5-max".bluetooth = {
11+
enable = lib.mkEnableOption "configuration for bluetooth" // {
12+
default = config.hardware.bluetooth.enable;
13+
};
14+
};
15+
};
16+
17+
config = lib.mkIf cfg.enable {
18+
boot = {
19+
kernelModules = [ "bcmdhd_sdio" ];
20+
blacklistedKernelModules = [ "bcmdhd" "dhd_static_buf" ];
21+
extraModulePackages = [ bcmdhd_sdio ];
22+
extraModprobeConfig =
23+
let
24+
options = [
25+
"firmware_path=${orangepi-firmware}/lib/firmware/fw_syn43711a0_sdio.bin"
26+
"nvram_path=${orangepi-firmware}/lib/firmware/nvram_ap6611s.txt"
27+
"clm_path=${orangepi-firmware}/lib/firmware/clm_syn43711a0.blob"
28+
];
29+
in
30+
''
31+
options bcmdhd_sdio ${lib.concatStringsSep " " options}
32+
'';
33+
};
34+
35+
systemd.services."ap611s-bluetooth" = {
36+
enable = lib.mkDefault config.hardware.bluetooth.enable;
37+
description = "Bluetooth loading for AP611S";
38+
after = [ "bluetooth.target" ];
39+
serviceConfig = {
40+
Type = "forking";
41+
ExecStart = "${brcm_patchram_plus}/bin/brcm_patchram_plus --bd_addr_rand --enable_hci --no2bytes --use_baudrate_for_download --tosleep 200000 --baudrate 1500000 --patchram ${orangepi-firmware}/lib/firmware/SYN43711A0.hcd /dev/ttyS7 &";
42+
TimeoutSec = "0s";
43+
RemainAfterExit = true;
44+
};
45+
wantedBy = [ "multi-user.target" ];
46+
};
47+
};
48+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{ fetchFromGitHub
2+
, lib
3+
, stdenv
4+
, ...
5+
}:
6+
stdenv.mkDerivation rec {
7+
pname = "brcm_patchram_plus";
8+
version = "2024.11.26";
9+
10+
src = fetchFromGitHub {
11+
owner = "orangepi-xunlong";
12+
repo = "orangepi-build";
13+
rev = "5f17bb471115d2764b66eeb40b99cd1a885b8be4";
14+
sha256 = "sha256-gn/y8HVb4pZZNZyQXqhkI3NqNKAfnprfvIp1oSaT05I=";
15+
};
16+
17+
sourceRoot = "${src.name}/external/cache/sources/brcm_patchram_plus";
18+
19+
installPhase = ''
20+
install -Dm755 brcm_patchram_plus -t $out/bin
21+
'';
22+
23+
meta.license = lib.licenses.asl20;
24+
}

orange-pi/5-max/default.nix

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{ lib, pkgs, ... }:
2+
let
3+
linux_rk3588 = pkgs.linuxPackagesFor (pkgs.callPackage ./kernel { });
4+
orangepi-firmware = pkgs.callPackage ./orangepi-firmware.nix { };
5+
in
6+
{
7+
imports = [
8+
./audio.nix
9+
./bluetooth.nix
10+
./graphics.nix
11+
./leds.nix
12+
./uart.nix
13+
./uboot
14+
../../common/gpu/24.05-compat.nix
15+
];
16+
17+
powerManagement.cpuFreqGovernor = lib.mkDefault "ondemand";
18+
19+
boot = {
20+
kernelPackages = linux_rk3588;
21+
22+
kernelParams = [
23+
"rootwait"
24+
"consoleblank=0"
25+
"console=tty1"
26+
];
27+
28+
initrd.includeDefaultModules = false;
29+
initrd.availableKernelModules = [
30+
"nvme"
31+
"mmc_block"
32+
"usbhid"
33+
"hid_generic"
34+
"dm_mod"
35+
"input_leds"
36+
];
37+
38+
loader = {
39+
grub.enable = lib.mkDefault false;
40+
generic-extlinux-compatible.enable = lib.mkDefault true;
41+
};
42+
};
43+
44+
disabledModules = [ "profiles/all-hardware.nix" ];
45+
46+
hardware = {
47+
deviceTree = {
48+
enable = lib.mkDefault true;
49+
name = lib.mkDefault "rockchip/rk3588-orangepi-5-max.dtb";
50+
filter = lib.mkDefault "rk3588-orangepi-5-max.dtb";
51+
};
52+
53+
firmware = [ orangepi-firmware ];
54+
55+
enableRedistributableFirmware = lib.mkDefault true;
56+
};
57+
58+
networking.networkmanager.wifi.scanRandMacAddress = lib.mkDefault false;
59+
60+
systemd.services."orangepi5-usb2-init" = {
61+
description = "Initialize USB2 on Orange Pi 5";
62+
wantedBy = [ "default.target" ];
63+
serviceConfig = {
64+
Type = "oneshot";
65+
ExecStart = "${pkgs.bash}/bin/sh -c 'echo host > /sys/kernel/debug/usb/fc000000.usb/mode'";
66+
};
67+
};
68+
}

orange-pi/5-max/graphics.nix

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{ config, pkgs, lib, ... }:
2+
let
3+
cfg = config.hardware.orange-pi."5-max".graphics;
4+
mali-firmware = pkgs.callPackage ./mali-firmware.nix { };
5+
in
6+
{
7+
options.hardware = {
8+
orange-pi."5-max".graphics = {
9+
enable = lib.mkEnableOption "gpu configuration" // {
10+
default = config.hardware.graphics.enable;
11+
};
12+
};
13+
};
14+
15+
config = lib.mkIf cfg.enable {
16+
hardware = {
17+
deviceTree = {
18+
overlays = [
19+
{
20+
name = "rockchip-rk3588-panthor-gpu";
21+
dtsText = ''
22+
/dts-v1/;
23+
/plugin/;
24+
/ {
25+
compatible = "rockchip,rk3588";
26+
};
27+
/ {
28+
fragment@0 {
29+
target = <&gpu>;
30+
__overlay__ {
31+
status = "disabled";
32+
};
33+
};
34+
fragment@1 {
35+
target = <&gpu_panthor>;
36+
__overlay__ {
37+
status = "okay";
38+
mali-supply = <&vdd_gpu_s0>;
39+
};
40+
};
41+
};
42+
'';
43+
}
44+
];
45+
};
46+
47+
firmware = [
48+
mali-firmware
49+
];
50+
};
51+
};
52+
}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{ fetchFromGitHub
2+
, kernel
3+
, lib
4+
, stdenv
5+
, ...
6+
}:
7+
let
8+
rev = "101.10.591.52.27-1";
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 = "Joshua-Riek";
18+
repo = "bcmdhd-dkms";
19+
inherit rev;
20+
hash = "sha256-vOpyQB5HMJxL8vKdyHDz3d5R6LWC9yUcjH50Nwbch38=";
21+
};
22+
23+
sourceRoot = "${src.name}/src";
24+
25+
hardeningDisable = [ "pic" ];
26+
27+
nativeBuildInputs = kernel.moduleBuildDependencies;
28+
29+
buildPhase = ''
30+
make -C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build \
31+
M=$PWD \
32+
ARCH=arm64 \
33+
CROSS_COMPILE=${stdenv.cc.targetPrefix} \
34+
modules \
35+
CONFIG_BCMDHD_SDIO=y \
36+
CONFIG_BCMDHD_PCIE= \
37+
CONFIG_BCMDHD_USB=
38+
'';
39+
40+
installPhase = ''
41+
install -D bcmdhd_sdio.ko $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/bcmdhd_sdio.ko
42+
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
43+
'';
44+
45+
meta.license = lib.licenses.gpl2Only;
46+
}

0 commit comments

Comments
 (0)