From cc942923915d500c83822b72edef50b6c649ab35 Mon Sep 17 00:00:00 2001 From: Jakob Leifhelm Date: Thu, 8 Jun 2023 20:24:13 +0200 Subject: [PATCH] starfive visionfive2: Add firmware update script. --- starfive/visionfive/v2/README.md | 28 ++++++++++++++++++++++++++++ starfive/visionfive/v2/firmware.nix | 21 +++++++++++++++++++-- starfive/visionfive/v2/sd-image.nix | 5 +++-- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/starfive/visionfive/v2/README.md b/starfive/visionfive/v2/README.md index 64f4c84..aa5d6ea 100644 --- a/starfive/visionfive/v2/README.md +++ b/starfive/visionfive/v2/README.md @@ -83,3 +83,31 @@ hardware.deviceTree.overlays = [{ "${nixos-hardware}/starfive/visionfive/v2/visionfive-2-v1.2a-8GB.dts"; }]; ``` +# Updating the bootloader +## SD-Card +Install the firmware update script +``` nix +environment.systemPackages = [ + (pkgs.callPackage + "${nixos-hardware}/starfive/visionfive/v2/firmware.nix" + { }).updater-sd +]; +``` +Then run as root +``` sh +visionfive2-firmware-update-sd +``` +## SPI Flash +Install the firmware update script +``` nix +environment.systemPackages = [ + (pkgs.callPackage + "${nixos-hardware}/starfive/visionfive/v2/firmware.nix" + { }).updater-flash +]; +``` +Then run as root +``` sh +visionfive2-firmware-update-flash +``` + diff --git a/starfive/visionfive/v2/firmware.nix b/starfive/visionfive/v2/firmware.nix index 97592b3..f2e6861 100644 --- a/starfive/visionfive/v2/firmware.nix +++ b/starfive/visionfive/v2/firmware.nix @@ -1,4 +1,5 @@ -{ callPackage, pkgsBuildHost, runCommand, writeText, stdenv, dtc }: +{ callPackage, pkgsBuildHost, runCommand, writeText, writeShellApplication +, stdenv, dtc, mtdutils, coreutils }: let uboot = callPackage ./uboot.nix { }; opensbi = callPackage ./opensbi.nix { @@ -36,7 +37,7 @@ let }; }; ''; -in { +in rec { inherit opensbi uboot; spl = stdenv.mkDerivation { name = "starfive-visionfive2-spl"; @@ -58,4 +59,20 @@ in { ${uboot}/mkimage -f ${its-file} -A riscv -O u-boot -T firmware $out/share/starfive-visionfive2/visionfive2_fw_payload.img ''; }; + updater-flash = writeShellApplication { + name = "visionfive2-firmware-update-flash"; + runtimeInputs = [ mtdutils ]; + text = '' + flashcp -v ${spl}/share/starfive-visionfive2/spl.bin /dev/mtd0 + flashcp -v ${uboot-fit-image}/share/starfive-visionfive2/visionfive2_fw_payload.img /dev/mtd1 + ''; + }; + updater-sd = writeShellApplication { + name = "visionfive2-firmware-update-sd"; + runtimeInputs = [ ]; + text = '' + dd if=${spl}/share/starfive-visionfive2/spl.bin of=/dev/mmcblk0p1 conv=fsync + dd if=${uboot-fit-image}/share/starfive-visionfive2/visionfive2_fw_payload.img of=/dev/mmcblk0p2 conv=fsync + ''; + }; } diff --git a/starfive/visionfive/v2/sd-image.nix b/starfive/visionfive/v2/sd-image.nix index 06af34c..6ee39e3 100644 --- a/starfive/visionfive/v2/sd-image.nix +++ b/starfive/visionfive/v2/sd-image.nix @@ -1,7 +1,6 @@ { config, pkgs, lib, modulesPath, ... }: -let - firmware = pkgs.callPackage ./firmware.nix { }; +let firmware = pkgs.callPackage ./firmware.nix { }; in { imports = [ "${modulesPath}/profiles/base.nix" @@ -48,4 +47,6 @@ in { ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot ''; }; + + environment.systemPackages = [ firmware.updater-flash ]; }