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

Add rest of Radxa devices that alredy have U-Boot package in nixpkgs #1366

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ See code for all available configurations.
| [Purism Librem 15v3](purism/librem/13v3) | `<nixos-hardware/purism/librem/15v3>` |
| [Purism Librem 5r4](purism/librem/5r4) | `<nixos-hardware/purism/librem/5r4>` |
| [Radxa ROCK 4C+](radxa/rock-4c-plus) | `<nixos-hardware/radxa/rock-4c-plus>` |
| [Radxa ROCK 5 Model B](radxa/rock-5b) | `<nixos-hardware/radxa/rock-5b>` |
| [Radxa ROCK Pi 4](radxa/rock-pi-4) | `<nixos-hardware/radxa/rock-pi-4>` |
| [Radxa ROCK Pi E](radxa/rock-pi-e) | `<nixos-hardware/radxa/rock-pi-e>` |
| [Raspberry Pi 2](raspberry-pi/2) | `<nixos-hardware/raspberry-pi/2>` |
| [Raspberry Pi 3](raspberry-pi/3) | `<nixos-hardware/raspberry-pi/3>` |
| [Raspberry Pi 4](raspberry-pi/4) | `<nixos-hardware/raspberry-pi/4>` |
Expand Down
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@
raspberry-pi-4 = import ./raspberry-pi/4;
raspberry-pi-5 = import ./raspberry-pi/5;
rock-4c-plus = import ./radxa/rock-4c-plus;
rock-5b = import ./radxa/rock-5b;
rock-pi-4 = import ./radxa/rock-pi-4;
rock-pi-e = import ./radxa/rock-pi-e;
kobol-helios4 = import ./kobol/helios4;
samsung-np900x3c = import ./samsung/np900x3c;
slimbook-hero-rpl-rtx = import ./slimbook/hero/rpl-rtx;
Expand Down
24 changes: 21 additions & 3 deletions radxa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,16 @@ Below is an annoated flake example to create the initial boot image.
system = "aarch64-linux";
modules = [
nixos-hardware.nixosModules.rock-4c-plus # Update the system according to your device.

# Or, if the default platform firmware is not available in the NixOS version you are using:
# (import nixos-hardware.nixosModules.rock-pi-e {
# lib = nixpkgs-unfree.lib;
# config = nixpkgs-unfree.config;
# pkgs = nixpkgs-unfree.legacyPackages.aarch64-linux;
# })
Comment on lines +61 to +66
Copy link
Contributor Author

@RadxaYuntian RadxaYuntian Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, ROCK Pi E's U-Boot package is not available in NixOS 24.11, so we need to override the module input at importing time, since its hardware.rockchip.platformFirmware is resolved before we can override it later.

However, this looks pretty ugly, so I'm wondering if there is more elegant way to do it.

BTW we do need an example for how to use U-Boot in non stable nixpkgs, since I plan to add them after NixOS/nixpkgs/pull/374482 and one of the A-TF 2.10->2.12 PR is merged.


disko.nixosModules.disko # disko usage is optional in the running system, but we need it to generate the initial boot image.
"${nixos-hardware}/radxa/disko.nix" # Common Radxa Disko profile. it is system-agnostic.
"${nixos-hardware}/radxa/disko.nix" # Common Radxa Disko profile. It is system-agnostic.
{
disko = {
imageBuilder = {
Expand All @@ -74,8 +82,8 @@ Below is an annoated flake example to create the initial boot image.
# Override the default bootloader with a cross built one.
# Use this if you do not have binfmt configured on your system.
# For NixOS, please add `boot.binfmt.emulatedSystems = [ "aarch64-linux" ];` to your system configuration.
# Update the system and the firmware package according to your device.
# hardware.radxa.rock-4c-plus.platformFirmware = nixpkgs-unfree.legacyPackages.x86_64-linux.pkgsCross.aarch64-multiplatform.ubootRock4CPlus;
# Read the device module to see how it was configured.
# hardware.rockchip.platformFirmware = nixpkgs-unfree.legacyPackages.x86_64-linux.pkgsCross.aarch64-multiplatform.ubootRock4CPlus;

users.users.radxa = {
isNormalUser = true;
Expand All @@ -92,3 +100,13 @@ Below is an annoated flake example to create the initial boot image.
};
}
```

For most of the supported products, you only need to change the device module (
i.e. `nixos-hardware.nixosModules.rock-4c-plus`) to match the one you are using.

## Known issues

* Currently, the `hardware.radxa` module and Radxa-maintained SoC vendor modules
(eg. `hardware.rockchip`) are tightly coupled and not intended for end-user to
use. Those options are currently used internally for hardware enablement, and
end-user should not need to modify them. Consider those interfaces **unstable**.
17 changes: 3 additions & 14 deletions radxa/rock-4c-plus/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,18 @@
, pkgs
, config
, ...
}:
let
cfg = config.hardware.radxa.rock-4c-plus;
rkCfg = config.hardware.rockchip;
in {
}: {
imports = [
../.
../../rockchip/rk3399
../../rockchip
];

options.hardware.radxa.rock-4c-plus = {
platformFirmware = lib.mkPackageOption pkgs "ubootRock4CPlus" { };
};

config = {
hardware = {
radxa.enable = true;
rockchip = {
rk3399.enable = true;
diskoExtraPostVM = ''
dd conv=notrunc,fsync if=${cfg.platformFirmware}/idbloader.img of=$out/${rkCfg.diskoImageName} bs=512 seek=64
dd conv=notrunc,fsync if=${cfg.platformFirmware}/u-boot.itb of=$out/${rkCfg.diskoImageName} bs=512 seek=16384
'';
platformFirmware = pkgs.ubootRock4CPlus;
};
};
};
Expand Down
20 changes: 20 additions & 0 deletions radxa/rock-5b/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ lib
, pkgs
, config
, ...
}: {
imports = [
../.
../../rockchip
];

config = {
hardware = {
radxa.enable = true;
rockchip = {
rk3588.enable = true;
platformFirmware = pkgs.ubootRock5ModelB;
};
};
};
}
20 changes: 20 additions & 0 deletions radxa/rock-pi-4/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ lib
, pkgs
, config
, ...
}: {
imports = [
../.
../../rockchip
];

config = {
hardware = {
radxa.enable = true;
rockchip = {
rk3399.enable = true;
platformFirmware = pkgs.ubootRockPi4;
};
};
};
}
20 changes: 20 additions & 0 deletions radxa/rock-pi-e/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ lib
, pkgs
, config
, ...
}: {
imports = [
../.
../../rockchip
];

config = {
hardware = {
radxa.enable = true;
rockchip = {
rk3328.enable = true;
platformFirmware = pkgs.ubootRockPiE;
};
};
};
}
24 changes: 22 additions & 2 deletions rockchip/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,38 @@
let
cfg = config.hardware.rockchip;
in {
imports = [
./rk3328
./rk3399
./rk3588
];

options.hardware.rockchip = {
enable = lib.mkEnableOption "Rockchip SoC support";
diskoImageName = lib.mkOption {
type = lib.types.str;
default = "main.raw";
description = ''
The output image name for Disko.
Can be used by diskoExtraPostVM.
The output image name of Disko.
You need to match this value with the real image name. Setting it alone
won't change the output image name, as it is controlled by Disko module.

Can be used in diskoExtraPostVM.
'';
};
platformFirmware = lib.mkPackageOption pkgs "platform firmware" {
default = null;
};
diskoExtraPostVM = lib.mkOption {
type = lib.types.str;
default = ''
${lib.getExe' pkgs.coreutils "dd"} conv=notrunc,fsync if=${config.hardware.rockchip.platformFirmware}/idbloader.img of=$out/${config.hardware.rockchip.diskoImageName} bs=512 seek=64
${lib.getExe' pkgs.coreutils "dd"} conv=notrunc,fsync if=${config.hardware.rockchip.platformFirmware}/u-boot.itb of=$out/${config.hardware.rockchip.diskoImageName} bs=512 seek=16384
'';
defaultText = lib.literalExpression ''
${lib.getExe' pkgs.coreutils "dd"} conv=notrunc,fsync if=${config.hardware.rockchip.platformFirmware}/idbloader.img of=$out/${config.hardware.rockchip.diskoImageName} bs=512 seek=64
${lib.getExe' pkgs.coreutils "dd"} conv=notrunc,fsync if=${config.hardware.rockchip.platformFirmware}/u-boot.itb of=$out/${config.hardware.rockchip.diskoImageName} bs=512 seek=16384
'';
description = ''
The post VM hook for Disko's Image Builder.
Can be used to install platform firmware like U-Boot.
Expand Down
16 changes: 16 additions & 0 deletions rockchip/rk3328/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ lib
, pkgs
, config
, ...
}:
let
cfg = config.hardware.rockchip.rk3328;
in {
options.hardware.rockchip.rk3328 = {
enable = lib.mkEnableOption "Rockchip RK3328 support";
};

config = lib.mkIf cfg.enable {
hardware.rockchip.enable = true;
};
}
6 changes: 1 addition & 5 deletions rockchip/rk3399/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
let
cfg = config.hardware.rockchip.rk3399;
in {
imports = [
../.
];

options.hardware.rockchip.rk3399 = {
enable = lib.mkEnableOption "Rockchip RK3399 support";
enable = lib.mkEnableOption "Rockchip RK3399 support";
};

config = lib.mkIf cfg.enable {
Expand Down
16 changes: 16 additions & 0 deletions rockchip/rk3588/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ lib
, pkgs
, config
, ...
}:
let
cfg = config.hardware.rockchip.rk3588;
in {
options.hardware.rockchip.rk3588 = {
enable = lib.mkEnableOption "Rockchip RK3588 support";
};

config = lib.mkIf cfg.enable {
hardware.rockchip.enable = true;
};
}