2022-03-28 22:43:47 +00:00
#!/usr/bin/env bash
2020-10-05 16:35:13 +00:00
2020-11-22 16:40:40 +00:00
set -e # exit on any error
2020-10-05 16:35:13 +00:00
2020-11-22 16:40:40 +00:00
UPDATE_FPGA = 1
UPDATE_KERNEL = 1
2021-02-26 18:12:19 +00:00
UPDATE_LOADER = 1
2020-11-22 16:40:40 +00:00
USE_USB = 1
2021-06-11 08:55:59 +00:00
FPGA_IMAGE = precursors/soc_csr.bin
2021-08-03 16:07:47 +00:00
KERNEL_IMAGE = target/riscv32imac-unknown-xous-elf/release/xous.img
LOADER_IMAGE = target/riscv32imac-unknown-xous-elf/release/loader.bin
2021-04-20 11:27:29 +00:00
CSR_CSV =
2021-03-24 19:25:26 +00:00
USE_IDENTITY = 0
2021-02-11 17:51:42 +00:00
USE_NIGHTLY =
2021-03-26 07:53:38 +00:00
IMAGE = hw-image
2021-06-11 08:54:19 +00:00
SOC_SVD = precursors/soc.svd
2020-10-05 16:35:13 +00:00
2020-11-22 16:40:40 +00:00
POSITIONAL = ( )
while [ [ $# -gt 0 ] ]
do
2021-02-26 18:12:19 +00:00
key = " $1 "
2020-11-22 16:40:40 +00:00
case $key in
-k| --kernel-skip)
UPDATE_KERNEL = 0
shift
; ;
-f| --fpga-skip)
UPDATE_FPGA = 0
shift
; ;
2021-02-26 18:12:19 +00:00
-l| --loader-skip)
2021-04-27 11:30:49 +00:00
UPDATE_LOADER = 0
shift
; ;
2020-11-22 16:40:40 +00:00
-c| --copy-to)
DEST_HOST = $2
USE_USB = 0
shift
shift
; ;
-i| --identity)
USE_IDENTITY = 1
IDENTITY = $2
shift
shift
; ;
2020-11-22 19:18:43 +00:00
--current-csr)
2021-04-20 11:27:29 +00:00
CSR_CSV = "--csr-csv ../betrusted-soc/build/csr.csv"
2020-11-22 19:18:43 +00:00
shift
; ;
2021-02-11 17:51:42 +00:00
-n| --nightly)
USE_NIGHTLY = +nightly
shift
; ;
2021-03-26 07:53:38 +00:00
-m| --minimal)
IMAGE = minimal
shift
; ;
2021-04-18 20:54:32 +00:00
-t| --trngtest)
IMAGE = trng-test
shift
; ;
2021-04-19 19:30:19 +00:00
-r| --rotest)
IMAGE = ro-test
shift
; ;
-a| --avtest)
IMAGE = av-test
shift
; ;
2021-04-27 13:56:18 +00:00
--image)
IMAGE = $2
shift
shift
; ;
2020-11-22 16:40:40 +00:00
-h| --help)
2020-11-22 19:18:43 +00:00
echo " $0 provisions betrusted. --kernel-skip skips the kernel, --fpga-skip skips the FPGA. --current-csr indicates to use the CSR for the new FPGA image to do the update (normally you want to use the one corresponding to the older, currently installed version). "
2020-11-22 16:40:40 +00:00
echo "Alternatively, using --copy-to <hostname> copies the files to a remote host and skips provisioning."
echo " --identity <id_file> supplies an identity file to the scp command."
echo " Copying assumes betrusted-scripts repo is cloned on ssh-target at ~/code/betrused-scripts/"
exit 0
; ;
*)
POSITIONAL += ( " $1 " )
shift
; ;
esac
done
2020-10-14 17:04:23 +00:00
2020-11-22 16:40:40 +00:00
set -- " ${ POSITIONAL [@] } "
DESTDIR = code/precursors
2020-10-05 16:35:13 +00:00
2021-01-12 16:24:12 +00:00
# this didn't work. Timestamping is actually kinda broken, because
# you end up capturing just the time that you managed to trigger a
# full rebuild, and not just an incremental rebuild. :-/
#touch services/log-server/src/main.rs # bump the build time in the log server
2021-01-12 15:30:52 +00:00
2021-06-11 08:54:19 +00:00
cargo $USE_NIGHTLY xtask $IMAGE $SOC_SVD
2020-10-05 16:35:13 +00:00
2020-10-12 21:22:19 +00:00
if [ $? -ne 0 ]
then
echo "build failed, aborting!"
exit 1
fi
2020-11-22 16:40:40 +00:00
# case of no private key specified
if [ $USE_USB -eq 1 ]
2020-10-05 16:35:13 +00:00
then
2021-02-26 18:12:19 +00:00
if [ $UPDATE_LOADER -eq 1 ]
then
echo "Burning loader"
2021-08-24 13:28:00 +00:00
cd tools && ./usb_update.py -l
2021-02-26 18:12:19 +00:00
fi
2020-11-22 16:40:40 +00:00
if [ $UPDATE_KERNEL -eq 1 ]
2020-10-05 16:35:13 +00:00
then
2021-02-26 18:12:19 +00:00
echo "Burning kernel"
2021-08-24 13:28:00 +00:00
cd tools && ./usb_update.py -k
fi
if [ $UPDATE_FPGA -eq 1 ]
then
echo "Burning FPGA image"
cd tools && ./usb_update.py -s
echo "*** Select 'Install gateware update' from the main menu to apply the update with your root keys ***"
2020-10-05 16:35:13 +00:00
fi
else
2021-02-26 18:12:19 +00:00
2021-04-27 11:30:49 +00:00
if [ -n " $OVERRIDE_SVD " ]
then
FPGA_IMAGE = precursors/soc_csr.bin
fi
2021-04-26 17:44:00 +00:00
if [ -e " $FPGA_IMAGE " ]
then
md5sum $FPGA_IMAGE
fi
2020-12-31 11:31:12 +00:00
md5sum $KERNEL_IMAGE
2021-02-26 18:12:19 +00:00
md5sum $LOADER_IMAGE
2020-11-22 16:40:40 +00:00
if [ $USE_IDENTITY -eq 1 ]
then
2021-04-22 09:42:43 +00:00
# there is a private key
echo " Copying to $DEST_HOST : $DESTDIR / with public key $IDENTITY "
2021-02-26 18:12:19 +00:00
scp -i $IDENTITY $KERNEL_IMAGE $FPGA_IMAGE $LOADER_IMAGE $DEST_HOST :$DESTDIR /
2020-11-22 16:40:40 +00:00
else
2021-04-22 09:42:43 +00:00
echo " Copying to $DEST_HOST : $DESTDIR / without public key "
2021-02-26 18:12:19 +00:00
scp $KERNEL_IMAGE $FPGA_IMAGE $LOADER_IMAGE $DEST_HOST :$DESTDIR /
2020-11-22 16:40:40 +00:00
fi
2020-10-05 16:35:13 +00:00
fi