From dd78777e1275a646a214e66f9b9157d304250030 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Sun, 31 Dec 2023 22:50:15 -0500 Subject: [PATCH] starfive visionfive2: rework firmware build/update scripts --- starfive/visionfive/v2/firmware.nix | 76 +++++------------------------ starfive/visionfive/v2/sd-image.nix | 4 +- 2 files changed, 14 insertions(+), 66 deletions(-) diff --git a/starfive/visionfive/v2/firmware.nix b/starfive/visionfive/v2/firmware.nix index 03c7707..710576d 100644 --- a/starfive/visionfive/v2/firmware.nix +++ b/starfive/visionfive/v2/firmware.nix @@ -1,78 +1,26 @@ -{ callPackage, pkgsBuildHost, writeText, writeShellApplication -, stdenv, dtc, mtdutils, coreutils }: -let - uboot = callPackage ./uboot.nix { }; - opensbi = callPackage ./opensbi.nix { - withPayload = "${uboot}/u-boot.bin"; - withFDT = "${uboot}/starfive_visionfive2.dtb"; - }; - spl-tool = pkgsBuildHost.callPackage ./spl-tool.nix { }; - its-file = writeText "visionfive2-uboot-fit-image.its" '' - /dts-v1/; +{ callPackage +, writeShellApplication +, stdenv +, mtdutils +}: - / { - description = "U-boot-spl FIT image for JH7110 VisionFive2"; - #address-cells = <2>; - - images { - firmware { - description = "u-boot"; - data = /incbin/("${opensbi}/share/opensbi/lp64/generic/firmware/fw_payload.bin"); - type = "firmware"; - arch = "riscv"; - os = "u-boot"; - load = <0x0 0x40000000>; - entry = <0x0 0x40000000>; - compression = "none"; - }; - }; - - configurations { - default = "config-1"; - - config-1 { - description = "U-boot-spl FIT config for JH7110 VisionFive2"; - firmware = "firmware"; - }; - }; - }; - ''; -in rec { - inherit opensbi uboot; - spl = stdenv.mkDerivation { - name = "starfive-visionfive2-spl"; - depsBuildBuild = [ spl-tool ]; - phases = [ "installPhase" ]; - installPhase = '' - mkdir -p $out/share/starfive-visionfive2/ - ln -s ${uboot}/u-boot-spl.bin . - spl_tool -c -f ./u-boot-spl.bin - cp u-boot-spl.bin.normal.out $out/share/starfive-visionfive2/spl.bin - ''; - }; - uboot-fit-image = stdenv.mkDerivation { - name = "starfive-visionfive2-uboot-fit-image"; - nativeBuildInputs = [ dtc ]; - phases = [ "installPhase" ]; - installPhase = '' - mkdir -p $out/share/starfive-visionfive2/ - ${uboot}/mkimage -f ${its-file} -A riscv -O u-boot -T firmware $out/share/starfive-visionfive2/visionfive2_fw_payload.img - ''; - }; +rec { + opensbi = callPackage ./opensbi.nix { }; + uboot = callPackage ./uboot.nix { inherit opensbi; }; 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 + flashcp -v ${uboot}/u-boot-spl.bin.normal.out /dev/mtd0 + flashcp -v ${uboot}/u-boot.itb /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 + dd if=${uboot}/u-boot-spl.bin.normal.out of=/dev/mmcblk0p1 conv=fsync + dd if=${uboot}/u-boot.itb of=/dev/mmcblk0p2 conv=fsync ''; }; } diff --git a/starfive/visionfive/v2/sd-image.nix b/starfive/visionfive/v2/sd-image.nix index 79bb6f3..7c30f9c 100644 --- a/starfive/visionfive/v2/sd-image.nix +++ b/starfive/visionfive/v2/sd-image.nix @@ -36,10 +36,10 @@ in { EOF eval $(partx $img -o START,SECTORS --nr 1 --pairs) - dd conv=notrunc if=${firmware.spl}/share/starfive-visionfive2/spl.bin of=$img seek=$START count=$SECTORS + dd conv=notrunc if=${firmware.uboot}/u-boot-spl.bin.normal.out of=$img seek=$START count=$SECTORS eval $(partx $img -o START,SECTORS --nr 2 --pairs) - dd conv=notrunc if=${firmware.uboot-fit-image}/share/starfive-visionfive2/visionfive2_fw_payload.img of=$img seek=$START count=$SECTORS + dd conv=notrunc if=${firmware.uboot}/u-boot.itb of=$img seek=$START count=$SECTORS ''; populateRootCommands = ''