Skip to content

orange-pi-5-max: init #1409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ See code for all available configurations.
| [Omen 15-en1007sa](omen/15-en1007sa) | `<nixos-hardware/omen/15-en1007sa>` |
| [Omen 15-en0002np](omen/15-en0002np) | `<nixos-hardware/omen/15-en0002np>` |
| [One-Netbook OneNetbook 4](onenetbook/4) | `<nixos-hardware/onenetbook/4>` |
| [Orange Pi 5 Max](orange-pi/5-max) | `<nixos-hardware/orange-pi/5-max>` |
| [Panasonic Let's Note CF-LX4](panasonic/letsnote/cf-lx4) | `<nixos-hardware/panasonic/letsnote/cf-lx4>` |
| [PC Engines APU](pcengines/apu) | `<nixos-hardware/pcengines/apu>` |
| [PINE64 Pinebook Pro](pine64/pinebook-pro/) | `<nixos-hardware/pine64/pinebook-pro>` |
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
omen-15-en0002np = import ./omen/15-en0002np;
onenetbook-4 = import ./onenetbook/4;
olimex-teres_i = import ./olimex/teres_i;
orange-pi-5-max = import ./orange-pi/5-max;
pcengines-apu = import ./pcengines/apu;
pine64-pinebook-pro = import ./pine64/pinebook-pro;
pine64-rockpro64 = import ./pine64/rockpro64;
Expand Down
85 changes: 85 additions & 0 deletions orange-pi/5-max/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Creating an installation SD card image

Create and customize a `flake.nix` file:

```nix
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixos-hardware.url = "github:nixos/nixos-hardware";
};

outputs = { nixpkgs, nixos-hardware, ... }:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"riscv64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSupportedSystems = nixpkgs.lib.genAttrs supportedSystems;
in
{
packages = forAllSupportedSystems (system: rec {
default = sd-image;
sd-image = (import "${nixpkgs}/nixos" {
configuration = {
imports = [
"${nixos-hardware}/orange-pi/5-max/sd-image-installer.nix"
];

nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (nixpkgs.lib.getName pkg) [
"orangepi-firmware"
"mali-g610-firmware"
];

# If you want to use ssh set a password
# users.users.nixos.password = "super secure password";
# OR add your public ssh key
# users.users.nixos.openssh.authorizedKeys.keys = [ "ssh-rsa ..." ];

nixpkgs.buildPlatform.system = system;
nixpkgs.hostPlatform.system = "aarch64-linux";

system.stateVersion = "24.11";
};
inherit system;
}).config.system.build.sdImage;
});
};
}
```

Then build the image by running `nix build .#` in the same folder.

## Flashing image
Replace `/dev/sdX` with the device name of your sd card.
```sh
zstdcat result/sd-image/nixos-sd-image-*-orange-pi-5-max.img.zst | sudo dd status=progress bs=8M of=/dev/sdX
```

# Updating the bootloader
Install the enable the update scripts
```nix
hardware.orange-pi."5-max".uboot.updater.enable = true;
```

uart debugging options are applied to the bootloader installed by the firmware update script
```nix
hardware.orange-pi."5-max".uartDebug = {
enable = true; # enabled by default for debugging
baudRate = 57600; # default is 1500000
};
```

## SD-Card
Run as root
``` sh
orangepi5max-firmware-update-sd
```
## SPI Flash
Run as root
``` sh
orangepi5max-firmware-update-flash
```
42 changes: 42 additions & 0 deletions orange-pi/5-max/audio.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{ config, lib, ... }:
let
cfg = config.hardware.orange-pi."5-max".audio;
in
{
options.hardware = {
orange-pi."5-max".audio = {
enable = lib.mkEnableOption "audio device configuration" // {
default = true;
};
};
};

config = lib.mkIf cfg.enable {
services.pipewire.wireplumber.extraConfig = {
"orange-pi-5-max-descriptions" = {
"monitor.alsa.rules" =
let
makeRule = name: description: {
matches = [{ "device.name" = name; }];
actions = {
update-props = {
"device.description" = description;
};
};
};
in
[
(makeRule "alsa_card.platform-hdmi0-sound" "HDMI0 Audio")
(makeRule "alsa_card.platform-hdmi1-sound" "HDMI1 Audio")
(makeRule "alsa_card.platform-sound" "ES8388 Audio")
];
};
};

services.udev.extraRules = ''
SUBSYSTEM=="sound", ENV{ID_PATH}=="platform-hdmi0-sound", ENV{SOUND_DESCRIPTION}="HDMI0 Audio"
SUBSYSTEM=="sound", ENV{ID_PATH}=="platform-hdmi1-sound", ENV{SOUND_DESCRIPTION}="HDMI1 Audio"
SUBSYSTEM=="sound", ENV{ID_PATH}=="platform-sound", ENV{SOUND_DESCRIPTION}="ES8388 Audio"
'';
};
}
52 changes: 52 additions & 0 deletions orange-pi/5-max/bcmdhd_sdio.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{ fetchFromGitHub
, kernel
, lib
, stdenv
, ...
}:
let
rev = "101.10.591.52.27-4";
in
stdenv.mkDerivation rec {
pname = "bcmdhd_sdio";
version = "${rev}-${kernel.version}";

passthru.moduleName = "bcmdhd_sdio";

src = fetchFromGitHub {
owner = "armbian";
repo = "bcmdhd-dkms";
inherit rev;
hash = "sha256-e9oWorovZrsqm7qZjXygVluahTCIxi4yJy2Pp6lwdl8=";
};

sourceRoot = "${src.name}/src";

hardeningDisable = [ "pic" ];

nativeBuildInputs = kernel.moduleBuildDependencies;

postPatch = ''
substituteInPlace include/linuxver.h \
--replace-fail 'del_timer(&((t)->timer))' 'timer_delete(&((t)->timer))'
substituteInPlace include/linuxver.h \
--replace-fail 'del_timer_sync(&((t)->timer))' 'timer_delete_sync(&((t)->timer))'
'';

buildPhase = ''
make \
LINUXDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build \
ARCH=arm64 \
CROSS_COMPILE=${stdenv.cc.targetPrefix} \
bcmdhd_sdio \
CONFIG_BCMDHD_SDIO=y \
CONFIG_BCMDHD_DTS=y
'';

installPhase = ''
install -D bcmdhd_sdio.ko $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/bcmdhd_sdio.ko
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
'';

meta.license = lib.licenses.gpl2Only;
}
183 changes: 183 additions & 0 deletions orange-pi/5-max/bluetooth.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
{ config
, pkgs
, lib
, ...
}:
let
cfg = config.hardware.orange-pi."5-max".bluetooth;
bcmdhd_sdio = config.boot.kernelPackages.callPackage ./bcmdhd_sdio.nix { };
brcm_patchram_plus = pkgs.callPackage ./brcm_patchram_plus.nix { };
orangepi-firmware = pkgs.callPackage ./orangepi-firmware.nix { };
in
{
options.hardware = {
orange-pi."5-max".bluetooth = {
enable = lib.mkEnableOption "configuration for bluetooth" // {
default = config.hardware.bluetooth.enable;
};
};
};

config = lib.mkIf cfg.enable {
boot = {
kernelParams = [ "8250.nr_uarts=8" ];
kernelModules = [ "bcmdhd_sdio" "btbcm" ];
blacklistedKernelModules = [
"bcmdhd"
"dhd_static_buf"
];
extraModulePackages = [ bcmdhd_sdio ];
extraModprobeConfig =
let
options = [
"firmware_path=${orangepi-firmware}/lib/firmware/fw_syn43711a0_sdio.bin"
"nvram_path=${orangepi-firmware}/lib/firmware/nvram_ap6611s.txt"
"clm_path=${orangepi-firmware}/lib/firmware/clm_syn43711a0.blob"
];
in
''
options bcmdhd_sdio ${lib.concatStringsSep " " options}
'';
};

hardware = {
deviceTree = {
overlays = [
{
name = "orangepi-5-max-bt";
dtsText = ''
/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>
#include <dt-bindings/interrupt-controller/irq.h>

/ {
compatible = "xunlong,orangepi-5-max";
};
/ {
fragment@0 {
target = <&pinctrl>;
__overlay__ {
wireless-bluetooth {
bt_reg_on: bt-reg-on {
rockchip,pins = <4 RK_PC4 RK_FUNC_GPIO &pcfg_pull_none>;
};
host_wake_bt: host-wake-bt {
rockchip,pins = <4 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>;
};
bt_wake_host: bt-wake-host {
rockchip,pins = <0 RK_PA0 RK_FUNC_GPIO &pcfg_pull_down>;
};
};
};
};
fragment@1 {
target = <&uart7>;
__overlay__ {
pinctrl-names = "default";
pinctrl-0 = <&uart7m0_xfer &uart7m0_ctsn &uart7m0_rtsn>;
uart-has-rtscts;
status = "okay";
bluetooth {
compatible = "brcm,bcm43438-bt";
clocks = <&hym8563>;
clock-names = "lpo";
device-wakeup-gpios = <&gpio4 RK_PC5 GPIO_ACTIVE_HIGH>;
interrupt-parent = <&gpio0>;
interrupts = <RK_PA0 IRQ_TYPE_EDGE_FALLING>;
interrupt-names = "host-wakeup";
pinctrl-names = "default";
pinctrl-0 = <&bt_reg_on>, <&host_wake_bt>, <&bt_wake_host>;
shutdown-gpios = <&gpio4 RK_PC4 GPIO_ACTIVE_HIGH>;
vbat-supply = <&vcc_3v3_s3>;
vddio-supply = <&vcc_1v8_s3>;
};
};
};
};
'';
}
{
name = "orangepi-5-max-wlan";
dtsText = ''
/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/pinctrl/rockchip.h>

/ {
compatible = "xunlong,orangepi-5-max";
};
/ {
fragment@0 {
target = <&pinctrl>;
__overlay__ {
sdio-pwrseq {
wifi_enable_h: wifi-enable-h {
rockchip,pins = <2 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
wireless-wlan {
wifi_host_wake_irq: wifi-host-wake-irq {
rockchip,pins = <0 RK_PB0 RK_FUNC_GPIO &pcfg_pull_down>;
};
};
};
};
fragment@1 {
target-path = "/";
__overlay__ {
sdio_pwrseq: sdio-pwrseq {
compatible = "mmc-pwrseq-simple";
clocks = <&hym8563>;
clock-names = "ext_clock";
pinctrl-names = "default";
pinctrl-0 = <&wifi_enable_h>;
post-power-on-delay-ms = <200>;
reset-gpios = <&gpio2 RK_PC5 GPIO_ACTIVE_LOW>;
};
wireless_wlan: wireless-wlan {
compatible = "wlan-platdata";
wifi_chip_type = "ap6611";
pinctrl-names = "default";
pinctrl-0 = <&wifi_host_wake_irq>;
WIFI,host_wake_irq = <&gpio0 RK_PB0 GPIO_ACTIVE_HIGH>;
WIFI,poweren_gpio = <&gpio2 RK_PC5 GPIO_ACTIVE_HIGH>;
status = "okay";
};
};
};
fragment@2 {
target = <&sdio>;
__overlay__ {
max-frequency = <150000000>;
no-sd;
no-mmc;
bus-width = <4>;
disable-wp;
cap-sd-highspeed;
cap-sdio-irq;
keep-power-in-suspend;
mmc-pwrseq = <&sdio_pwrseq>;
non-removable;
pinctrl-names = "default";
pinctrl-0 = <&sdiom0_pins>;
sd-uhs-sdr104;
status = "okay";
bcmdhd_wlan {
compatible = "android,bcmdhd_wlan";
gpio_wl_host_wake = <&gpio0 RK_PB0 GPIO_ACTIVE_HIGH>;
};
};
};
};
'';
}
];
};
};
};
}
Loading