From 0b2e2fe9b312d973d347ec71ec9323685dd17e5b Mon Sep 17 00:00:00 2001 From: ZHANG Yuntian Date: Fri, 7 Feb 2025 14:28:18 +0800 Subject: [PATCH] rockchip: support generic firmware installation --- radxa/README.md | 4 ++-- radxa/rock-4c-plus/default.nix | 15 ++------------- radxa/rock-5b/default.nix | 15 ++------------- radxa/rock-pi-4/default.nix | 15 ++------------- rockchip/default.nix | 18 ++++++++++++++++-- 5 files changed, 24 insertions(+), 43 deletions(-) diff --git a/radxa/README.md b/radxa/README.md index b17e6b67..b4ec2a97 100644 --- a/radxa/README.md +++ b/radxa/README.md @@ -74,8 +74,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; diff --git a/radxa/rock-4c-plus/default.nix b/radxa/rock-4c-plus/default.nix index 5f1b0278..7550483d 100644 --- a/radxa/rock-4c-plus/default.nix +++ b/radxa/rock-4c-plus/default.nix @@ -2,29 +2,18 @@ , pkgs , config , ... -}: -let - cfg = config.hardware.radxa.rock-4c-plus; - rkCfg = config.hardware.rockchip; -in { +}: { imports = [ ../. ../../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; }; }; }; diff --git a/radxa/rock-5b/default.nix b/radxa/rock-5b/default.nix index 992b5ca2..aff9a81b 100644 --- a/radxa/rock-5b/default.nix +++ b/radxa/rock-5b/default.nix @@ -2,29 +2,18 @@ , pkgs , config , ... -}: -let - cfg = config.hardware.radxa.rock-5b; - rkCfg = config.hardware.rockchip; -in { +}: { imports = [ ../. ../../rockchip ]; - options.hardware.radxa.rock-5b = { - platformFirmware = lib.mkPackageOption pkgs "ubootRock5ModelB" { }; - }; - config = { hardware = { radxa.enable = true; rockchip = { rk3588.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.ubootRock5ModelB; }; }; }; diff --git a/radxa/rock-pi-4/default.nix b/radxa/rock-pi-4/default.nix index 3cf2c6a4..74b97dd9 100644 --- a/radxa/rock-pi-4/default.nix +++ b/radxa/rock-pi-4/default.nix @@ -2,29 +2,18 @@ , pkgs , config , ... -}: -let - cfg = config.hardware.radxa.rock-pi-4; - rkCfg = config.hardware.rockchip; -in { +}: { imports = [ ../. ../../rockchip ]; - options.hardware.radxa.rock-pi-4 = { - platformFirmware = lib.mkPackageOption pkgs "ubootRockPi4" { }; - }; - 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.ubootRockPi4; }; }; }; diff --git a/rockchip/default.nix b/rockchip/default.nix index 38a451fd..2d4715d3 100644 --- a/rockchip/default.nix +++ b/rockchip/default.nix @@ -17,12 +17,26 @@ in { 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.