From ee4b3c9e3374977ad13f89f681762ebcbb0de9c8 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 16 Feb 2023 13:21:01 +0100 Subject: [PATCH] Add nix run visionFive2_* commands --- flake.nix | 2 +- visionfive2/README.md | 61 ++++++++++++++++++++++ visionfive2/commands.nix | 107 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 visionfive2/README.md create mode 100644 visionfive2/commands.nix diff --git a/flake.nix b/flake.nix index 91a8582..2a7d644 100644 --- a/flake.nix +++ b/flake.nix @@ -131,7 +131,7 @@ type = "app"; program = "${program}"; }; - }; + } // import ./visionfive2/commands.nix { inherit inputs pkgs; }; packages.${system} = { jh7100-recover = pkgs.writeCBin "jh7100-recover" (builtins.readFile "${jh71xx-tools}/jh7100-recover.c"); }; diff --git a/visionfive2/README.md b/visionfive2/README.md new file mode 100644 index 0000000..a86f83d --- /dev/null +++ b/visionfive2/README.md @@ -0,0 +1,61 @@ + +# VisionFive 2 + +As of writing, VisionFive 2 support is quite experimental. + +## Flash the bootloader via serial connection + +This step may be optional. + +Make the serial connection according to the section "Recovering the Bootloader" in . +Flip the tiny switches towards the H (as opposed to L) marking on the PCB (towards edge of the board) as described that section (Step 2). +Power up, and assuming your serial device is `/dev/ttyUSB0`, run: + +```shellSession +nix run .#visionFive2_bootloader_recover /dev/ttyUSB0 +``` + +## Write a bootable SD card + +```shellSession +$ nix build .#images.visionfive2-cross +``` + +Insert an SD card of which all contents will be replaced. + +These instructions assume your SD card reader is `/dev/mmcblk0`. + +Make sure no partitions are mounted. + +```shellSession +$ echo /dev/mmcblk0p* +$ sudo umount /dev/mmcblk0p1 +$ sudo umount /dev/mmcblk0p2 +... repeat for all partitions +``` + +`pv` provides a rough progress indicator based on the compressed size. +If you don't have `pv`, run in `nix shell nixpkgs#pv` or use `cat` instead. + +```shellSession +$ sudo sh -c 'pv &2 NOTE: If your board appears to hang, RX/TX may be flipped, + echo >&2 _depending on boot setting_!!! + echo "$0" + ${expectScript} "$@" + echo >&2 "Launching new session. Hint enter to display help." + ${visionFive2_recovery_resume.program} "$@" + ''; + in { type = "app"; program = "${wrapSudo program}"; }; + + visionFive2_recovery_resume = + let + program = pkgs.writeScript "recoverBootloader_resume" '' + #!${pkgs.runtimeShell} + set -eu + ${pkgs.picocom}/bin/picocom $1 -b 115200 -s "${pkgs.lrzsz}/bin/sz -X" + ''; + in { type = "app"; program = "${wrapSudo program}"; }; + + visionFive2_bootloader_recover = + let + expectScript = pkgs.writeScript "expect-visionfive-recover-bootLoader" '' + #!${pkgs.expect}/bin/expect -f + set timeout -1 + spawn ${pkgs.picocom}/bin/picocom [lindex $argv 0] -b 115200 -s "${pkgs.lrzsz}/bin/sz -X" + expect "CC" + send "\x01\x13" + expect "*** file:" + send "${inputs.jh7110_recovery_binary}" + send "\r" + expect "Transfer complete" + + # Wait for menu and install SPL + expect "0: update 2ndboot/SPL in flash" + send "0\r" + + expect "CC" + send "\x01\x13" + expect "*** file:" + send "${inputs.jh7110_u-boot-spl-bin}" + send "\r" + expect "Transfer complete" + + # Wait for menu and install u-boot + expect "2: update fw_verif/uboot in flash" + send "2\r" + expect "CC" + send "\x01\x13" + expect "*** file:" + send "${inputs.jh7110_u-boot-bin}" + send "\r" + expect "Transfer complete" + ''; + program = pkgs.writeShellScript "flash-visionfive.sh" '' + cat >&2 <&2 <