diff --git a/README.md b/README.md index fcd5fef..9993ebc 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,23 @@ To prevent the GC from erasing the system: $ nix build .#devShells.x86_64-linux.default --out-link result-env ``` -## FPGA +## Lagarto Hun on FPGA Alveo U55C + +First build required dependencies: ``` -. fpga/env.sh -fpga/fpgactl -w /path/to/bitstream -b openpiton2.bin -k kernel-nixos -r initrd-nixos +$ nix develop '.#lagarto-hun' +``` + +Then upload to destination: + +``` +$ fpga/upload.sh +``` + +And then boot the system there: + +``` +cucu$ ./boot.sh +... ``` diff --git a/flake.nix b/flake.nix index 9989226..913dd96 100644 --- a/flake.nix +++ b/flake.nix @@ -54,5 +54,16 @@ NIXOS_SYSTEM_TOPLEVEL = toplevel; OPENSBI = syspkgs.opensbi-uboot; }; + devShells.x86_64-linux.lagarto-hun = + let + nixosconf = self.nixosConfigurations.lagarto-hun; + syspkgs = nixosconf.pkgs; + build = nixosconf.config.system.build; + in pkgs.mkShell { + pname = "lagarto-hun-shell"; + OPENSBI = syspkgs.opensbi; + KERNEL = build.kernel; + INITRD = build.initialRamdisk; + }; }; } diff --git a/fpga/boot.sh b/fpga/boot.sh new file mode 100755 index 0000000..9cb5015 --- /dev/null +++ b/fpga/boot.sh @@ -0,0 +1,9 @@ +#!/usr/bin/bash + +set -x +set -e + +source ./env.sh + +./fpgactl -b opensbi.bin -k kernel.bin -i initrd.bin +picocom -b 115200 /dev/ttyUSB2 diff --git a/fpga/env.sh b/fpga/env.sh index 8ea4d83..573d4f6 100644 --- a/fpga/env.sh +++ b/fpga/env.sh @@ -1,4 +1,3 @@ -#!/bin/false # Source this file to setup the environment diff --git a/fpga/load_image.sh b/fpga/load_image.sh new file mode 100755 index 0000000..6d5406c --- /dev/null +++ b/fpga/load_image.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +source /home/tools/ACME-EA-v1/setup.sh + +if [ $# -ne 2 ]; then + >&2 echo "usage: load-fs.sh
" + exit 1 +fi + +input=$1 +#startaddr=$((0x00000000)) +startaddr=$2 +filesize=$(du -L -b $input | cut -f1) +#chunksize=$((0x10000000)) +#chunksize=$((0x08000000)) +chunksize=$((0x00800000)) +nrchunk=$((filesize/chunksize + ((filesize%chunksize) != 0) )) +lastchunk=$((nrchunk - 1)) +total=0 + +myid=$$ + +rm -f /tmp/sect.tmp.$myid +for i in `seq 0 $lastchunk`; do + echo "extracting section $i... " + dd if=$input of=/tmp/sect.tmp.$myid bs=$chunksize skip=$i count=1 status=none + + from=$((i * chunksize)) + to=$((startaddr + i * chunksize)) + #copysize=$((i != lastchunk ? chunksize : (filesize - i * chunksize) )) + copysize=$(du -L -b /tmp/sect.tmp.$myid | cut -f1) + + echo "copying section $i: from=$from to=$to size=$copysize ($((copysize/1024/1024)) MiB)" + dma-to-device -d /dev/qdma${ID}000-MM-1 -a $to -s $copysize -f /tmp/sect.tmp.$myid + #sleep 0.2 + rm -f /tmp/sect.tmp.$myid + echo -e "done\n" + + total=$((total + copysize)) +done + +if [ $filesize -ne $total ]; then + >&2 echo "Error: Copy failed" + exit 1 +fi diff --git a/fpga/upload.sh b/fpga/upload.sh new file mode 100755 index 0000000..358ca3f --- /dev/null +++ b/fpga/upload.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e +set -x + +dst=femu:nixos/ + +rsync -a fpga/fpgactl "$dst" +rsync -a fpga/boot.sh "$dst" +rsync -a fpga/env.sh "$dst" +rsync "$OPENSBI/share/opensbi/lp64/fpga/openpiton/firmware/fw_payload.bin" "$dst/opensbi.bin" +rsync "$KERNEL/Image" "$dst/kernel.bin" +rsync "$INITRD/initrd" "$dst/initrd.bin" + +echo "Now go to $dst and run ./boot.sh"