diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6260efd..33d9ada 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,4 +3,4 @@ build:lagarto-ox-rd: tags: - nix script: - - nix develop -L .#lagarto-ox-rd --command env + - nix develop -L .#lagarto-ox-rd --command fpga/run-remotely.sh fpgalogin1:ci diff --git a/fpga/boot.sh b/fpga/boot.sh index 41a6813..47f24e1 100755 --- a/fpga/boot.sh +++ b/fpga/boot.sh @@ -1,12 +1,12 @@ #!/usr/bin/bash -set -x +#set -x set -e source ./env.sh -#bitstream="-w system-acme_ea-4h2v.bit" +bitstream="-w bitstream.bit" -./fpgactl $bitstream -b opensbi.bin -k kernel.bin -i initrd.bin -r rootfs.img -R bootrom.bin +./fpgactl $bitstream -R bootrom.bin -b opensbi.bin -k kernel.bin -i initrd.bin -r rootfs.img -picocom -b 115200 /dev/ttyUSB2 +picocom -b 115200 $FPGACTL_UART diff --git a/fpga/run-login.sh b/fpga/run-login.sh new file mode 100755 index 0000000..afe8dca --- /dev/null +++ b/fpga/run-login.sh @@ -0,0 +1,31 @@ +#!/usr/bin/bash + +#set -x +set -e + +path="$1" + +# First determine if we already have jobs already +n=$(squeue --me -lh | wc -l) + +if [ "$n" -gt 1 ]; then + echo "Too many jobs queued already" >&2 + exit 1 +fi + +if [ "$n" == 0 ]; then + # No running jobs, so allocate a new job + echo salloc -N 1 --constraint=dmaqdma --no-shell +fi + +while [ "$n" != 1 ]; do + sleep 2 + n=$(squeue --me -lh) +done + +host=$(squeue -h -o %N) + +echo "Switching to $host" + +# Continue the execution there +ssh "$host" "$path/run-node.sh" "$path" diff --git a/fpga/run-node.sh b/fpga/run-node.sh new file mode 100755 index 0000000..635ca24 --- /dev/null +++ b/fpga/run-node.sh @@ -0,0 +1,30 @@ +#!/usr/bin/bash + +#set -x +set -e + +echo "Hello from $(hostname)" + +path="$1" + +cd "$path" + +# First kill any picocom instance +killall picocom || true + +# Setup the environment +. env.sh + +set -x + +# Then perform the boot +./fpgactl -w bitstream.bit -R bootrom.bin -b opensbi.bin -k kernel.bin -i initrd.bin # -r rootfs.img + +# Restart it again only loading the bootrom and OpenSBI (notice OpenSBI +# relocates itself so it will likely be gone by now) +sleep 1 && ./fpgactl -R bootrom.bin -b opensbi.bin & + +# Set dead switch +sleep 30 && killall picocom & + +picocom -q -x 10000 -b 115200 $FPGACTL_UART diff --git a/fpga/run-remotely.sh b/fpga/run-remotely.sh new file mode 100755 index 0000000..74cbe0f --- /dev/null +++ b/fpga/run-remotely.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Executes a pipeline in a remote machine taking the values from the environment +# Usage fpga/run-remotely.sh : + +set -e + +dst=fpgalogin1:nixos + +if [ "$1" != "" ]; then + dst="$1" +fi + +path=${dst#*:} + +# Copy all required elements to the destination machine +fpga/upload.sh "$dst" + +# Launch the pipeline from there +set +x +ssh fpgalogin1 "$path/run-login.sh" "$path" | awk -f fpga/verify.awk diff --git a/fpga/upload.sh b/fpga/upload.sh index 0c8807e..6e4df7c 100755 --- a/fpga/upload.sh +++ b/fpga/upload.sh @@ -3,16 +3,18 @@ set -e set -x -#dst=femu:nixos/ -dst=fpgalogin1:nixos/ +#dst=femu:nixos +dst=fpgalogin1:nixos if [ "$1" != "" ]; then dst="$1" fi -rsync -a fpga/fpgactl "$dst" -#rsync -a fpga/boot.sh "$dst" -rsync -a fpga/env.sh "$dst" +rsync -a fpga/run-login.sh "$dst/" +rsync -a fpga/run-node.sh "$dst/" +rsync -a fpga/fpgactl "$dst/" +rsync -a fpga/boot.sh "$dst/" +rsync -a fpga/env.sh "$dst/" rsync $(find "$OPENSBI" -name fw_payload.bin) "$dst/opensbi.bin" rsync "$KERNEL/Image" "$dst/kernel.bin" rsync "$INITRD/initrd" "$dst/initrd.bin" diff --git a/fpga/verify.awk b/fpga/verify.awk new file mode 100644 index 0000000..c9daa98 --- /dev/null +++ b/fpga/verify.awk @@ -0,0 +1,20 @@ +BEGIN { + bootrom_ok = 0 + opensbi_ok = 0 + test_ok = 0 +} +/RBOOTROM/ { bootrom_ok = 1 } +/^OpenSBI v/ { opensbi_ok = 1 } +/^TEST-RESULT-OK/ { test_ok = 1 } + { printf "line> "; print } +END { + printf "Test summary:\n" + printf " Bootrom: %s\n", bootrom_ok ? "OK" : "FAIL"; + printf " OpenSBI: %s\n", opensbi_ok ? "OK" : "FAIL"; + #printf " Result: %s\n", test_ok ? "OK" : "FAIL"; + + if (bootrom_ok && opensbi_ok) + exit 0; + else + exit 1; +} diff --git a/overlay.nix b/overlay.nix index 8bf3fca..af8e59e 100644 --- a/overlay.nix +++ b/overlay.nix @@ -108,7 +108,7 @@ final: prev: }; rbootrom = prev.pkgsStatic.stdenv.mkDerivation { - name = "sa-fpga-tests"; + name = "rbootrom"; src = ./bootrom; dontConfigure = true; buildPhase = ''