Skip to content
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

orange-pi-5-max: init #1409

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-es8388-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-es8388-sound", ENV{SOUND_DESCRIPTION}="ES8388 Audio"
'';
};
}
48 changes: 48 additions & 0 deletions orange-pi/5-max/bluetooth.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ config, pkgs, lib, ... }:
let
cfg = config.hardware.orange-pi."5-max".bluetooth;
bcmdhd_sdio = config.boot.kernelPackages.callPackage ./kernel/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 = {
kernelModules = [ "bcmdhd_sdio" ];
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}
'';
};

systemd.services."ap611s-bluetooth" = {
enable = lib.mkDefault config.hardware.bluetooth.enable;
description = "Bluetooth loading for AP611S";
after = [ "bluetooth.target" ];
serviceConfig = {
Type = "forking";
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 &";
TimeoutSec = "0s";
RemainAfterExit = true;
};
wantedBy = [ "multi-user.target" ];
};
};
}
24 changes: 24 additions & 0 deletions orange-pi/5-max/brcm_patchram_plus.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ fetchFromGitHub
, lib
, stdenv
, ...
}:
stdenv.mkDerivation rec {
pname = "brcm_patchram_plus";
version = "2024.11.26";

src = fetchFromGitHub {
owner = "orangepi-xunlong";
repo = "orangepi-build";
rev = "5f17bb471115d2764b66eeb40b99cd1a885b8be4";
sha256 = "sha256-gn/y8HVb4pZZNZyQXqhkI3NqNKAfnprfvIp1oSaT05I=";
};

sourceRoot = "${src.name}/external/cache/sources/brcm_patchram_plus";

installPhase = ''
install -Dm755 brcm_patchram_plus -t $out/bin
'';

meta.license = lib.licenses.asl20;
}
68 changes: 68 additions & 0 deletions orange-pi/5-max/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{ lib, pkgs, ... }:
let
linux_rk3588 = pkgs.linuxPackagesFor (pkgs.callPackage ./kernel { });
orangepi-firmware = pkgs.callPackage ./orangepi-firmware.nix { };
in
{
imports = [
./audio.nix
./bluetooth.nix
./graphics.nix
./leds.nix
./uart.nix
./uboot
../../common/gpu/24.05-compat.nix
];

powerManagement.cpuFreqGovernor = lib.mkDefault "ondemand";

boot = {
kernelPackages = linux_rk3588;

kernelParams = [
"rootwait"
"consoleblank=0"
"console=tty1"
];

initrd.includeDefaultModules = false;
initrd.availableKernelModules = [
"nvme"
"mmc_block"
"usbhid"
"hid_generic"
"dm_mod"
"input_leds"
];

loader = {
grub.enable = lib.mkDefault false;
generic-extlinux-compatible.enable = lib.mkDefault true;
};
};

disabledModules = [ "profiles/all-hardware.nix" ];

hardware = {
deviceTree = {
enable = lib.mkDefault true;
name = lib.mkDefault "rockchip/rk3588-orangepi-5-max.dtb";
filter = lib.mkDefault "rk3588-orangepi-5-max.dtb";
};

firmware = [ orangepi-firmware ];

enableRedistributableFirmware = lib.mkDefault true;
};

networking.networkmanager.wifi.scanRandMacAddress = lib.mkDefault false;

systemd.services."orangepi5-usb2-init" = {
description = "Initialize USB2 on Orange Pi 5";
wantedBy = [ "default.target" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.bash}/bin/sh -c 'echo host > /sys/kernel/debug/usb/fc000000.usb/mode'";
};
};
}
52 changes: 52 additions & 0 deletions orange-pi/5-max/graphics.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{ config, pkgs, lib, ... }:
let
cfg = config.hardware.orange-pi."5-max".graphics;
mali-firmware = pkgs.callPackage ./mali-firmware.nix { };
in
{
options.hardware = {
orange-pi."5-max".graphics = {
enable = lib.mkEnableOption "gpu configuration" // {
default = config.hardware.graphics.enable;
};
};
};

config = lib.mkIf cfg.enable {
hardware = {
deviceTree = {
overlays = [
{
name = "rockchip-rk3588-panthor-gpu";
dtsText = ''
/dts-v1/;
/plugin/;
/ {
compatible = "rockchip,rk3588";
};
/ {
fragment@0 {
target = <&gpu>;
__overlay__ {
status = "disabled";
};
};
fragment@1 {
target = <&gpu_panthor>;
__overlay__ {
status = "okay";
mali-supply = <&vdd_gpu_s0>;
};
};
};
'';
}
];
};

firmware = [
mali-firmware
];
};
};
}
46 changes: 46 additions & 0 deletions orange-pi/5-max/kernel/bcmdhd_sdio.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{ fetchFromGitHub
, kernel
, lib
, stdenv
, ...
}:
let
rev = "101.10.591.52.27-1";
in
stdenv.mkDerivation rec {
pname = "bcmdhd_sdio";
version = "${rev}-${kernel.version}";

passthru.moduleName = "bcmdhd_sdio";

src = fetchFromGitHub {
owner = "Joshua-Riek";
repo = "bcmdhd-dkms";
inherit rev;
hash = "sha256-vOpyQB5HMJxL8vKdyHDz3d5R6LWC9yUcjH50Nwbch38=";
};

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

hardeningDisable = [ "pic" ];

nativeBuildInputs = kernel.moduleBuildDependencies;

buildPhase = ''
make -C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build \
M=$PWD \
ARCH=arm64 \
CROSS_COMPILE=${stdenv.cc.targetPrefix} \
modules \
CONFIG_BCMDHD_SDIO=y \
CONFIG_BCMDHD_PCIE= \
CONFIG_BCMDHD_USB=
'';

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;
}
Loading