2021-09-25 20:00:36 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
set -e
|
2021-09-26 14:42:50 +02:00
|
|
|
|
|
|
|
PACKAGE_FILE_NAME="SummerCart64"
|
2021-11-10 02:05:51 +01:00
|
|
|
|
2021-09-26 14:42:50 +02:00
|
|
|
FILES=(
|
2021-11-10 02:05:51 +01:00
|
|
|
"./fw/output_files/SC64_firmware.pof"
|
2021-10-26 23:44:09 +02:00
|
|
|
"./fw/output_files/SC64_update.bin"
|
|
|
|
"./hw/ftdi-template.xml"
|
2021-09-26 14:42:50 +02:00
|
|
|
"./sw/cic/UltraCIC-III.hex"
|
|
|
|
"./LICENSE"
|
|
|
|
)
|
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
BUILT_CIC=false
|
|
|
|
BUILT_N64=false
|
|
|
|
BUILT_RISCV=false
|
2022-01-18 19:21:49 +01:00
|
|
|
BUILT_SW=false
|
2021-11-10 02:05:51 +01:00
|
|
|
BUILT_FPGA=false
|
|
|
|
BUILT_UPDATE=false
|
|
|
|
BUILT_RELEASE=false
|
2021-09-26 14:42:50 +02:00
|
|
|
|
2021-11-16 22:37:48 +01:00
|
|
|
FORCE_CLEAN=false
|
|
|
|
SKIP_FPGA_REBUILD=false
|
2021-12-10 17:36:30 +01:00
|
|
|
DEBUG_ENABLED=false
|
2021-11-16 22:37:48 +01:00
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
build_cic () {
|
|
|
|
if [ "$BUILT_CIC" = true ]; then return; fi
|
|
|
|
|
2021-12-10 17:36:30 +01:00
|
|
|
pushd sw/cic > /dev/null
|
2021-11-10 02:05:51 +01:00
|
|
|
avra UltraCIC-III.asm -D attiny45
|
2021-12-10 17:36:30 +01:00
|
|
|
popd > /dev/null
|
2021-11-10 02:05:51 +01:00
|
|
|
|
|
|
|
BUILT_CIC=true
|
|
|
|
}
|
|
|
|
|
|
|
|
build_n64 () {
|
|
|
|
if [ "$BUILT_N64" = true ]; then return; fi
|
|
|
|
|
2021-12-10 17:36:30 +01:00
|
|
|
pushd sw/n64 > /dev/null
|
2021-11-16 22:37:48 +01:00
|
|
|
if [ "$FORCE_CLEAN" = true ]; then
|
|
|
|
make clean
|
|
|
|
fi
|
2022-01-16 22:52:45 +01:00
|
|
|
N64_FLAGS="$USER_FLAGS"
|
|
|
|
if [ ! -z "${GIT_BRANCH+x}" ]; then N64_FLAGS+=" -DGIT_BRANCH='\"$GIT_BRANCH\"'"; fi
|
|
|
|
if [ ! -z "${GIT_TAG+x}" ]; then N64_FLAGS+=" -DGIT_TAG='\"$GIT_TAG\"'"; fi
|
|
|
|
if [ ! -z "${GIT_SHA+x}" ]; then N64_FLAGS+=" -DGIT_SHA='\"$GIT_SHA\"'"; fi
|
|
|
|
make all -j USER_FLAGS="$N64_FLAGS"
|
2021-12-10 17:36:30 +01:00
|
|
|
popd > /dev/null
|
2021-11-10 02:05:51 +01:00
|
|
|
|
|
|
|
BUILT_N64=true
|
|
|
|
}
|
|
|
|
|
|
|
|
build_riscv () {
|
|
|
|
if [ "$BUILT_RISCV" = true ]; then return; fi
|
2021-09-26 14:42:50 +02:00
|
|
|
|
2021-12-10 17:36:30 +01:00
|
|
|
pushd sw/riscv > /dev/null
|
2021-11-16 22:37:48 +01:00
|
|
|
if [ "$FORCE_CLEAN" = true ]; then
|
|
|
|
make clean
|
|
|
|
fi
|
2021-12-10 17:36:30 +01:00
|
|
|
make all -j USER_FLAGS="$USER_FLAGS"
|
|
|
|
popd > /dev/null
|
2021-09-26 14:42:50 +02:00
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
BUILT_RISCV=true
|
|
|
|
}
|
2021-09-26 14:42:50 +02:00
|
|
|
|
2022-01-18 19:21:49 +01:00
|
|
|
build_sw () {
|
|
|
|
if [ "$BUILT_SW" = true ]; then return; fi
|
2021-09-26 14:42:50 +02:00
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
build_n64
|
|
|
|
build_riscv
|
2021-09-26 14:42:50 +02:00
|
|
|
|
2022-01-18 19:21:49 +01:00
|
|
|
pushd fw > /dev/null
|
|
|
|
mkdir -p output_files > /dev/null
|
|
|
|
cat ../sw/n64/build/n64boot.bin ../sw/riscv/build/governor.bin > output_files/SC64_software.bin
|
|
|
|
objcopy -I binary -O ihex output_files/SC64_software.bin output_files/SC64_software.hex
|
|
|
|
popd
|
|
|
|
|
|
|
|
BUILT_SW=true
|
|
|
|
}
|
|
|
|
|
|
|
|
build_fpga () {
|
|
|
|
if [ "$BUILT_FPGA" = true ]; then return; fi
|
|
|
|
|
|
|
|
build_sw
|
|
|
|
|
2021-12-10 17:36:30 +01:00
|
|
|
pushd fw > /dev/null
|
2021-11-16 22:37:48 +01:00
|
|
|
if [ "$SKIP_FPGA_REBUILD" = true ] && [ -f output_files/SummerCart64.sof ]; then
|
2022-01-18 19:21:49 +01:00
|
|
|
echo Skipping FPGA build
|
2021-11-16 22:37:48 +01:00
|
|
|
else
|
2021-12-10 17:36:30 +01:00
|
|
|
if [ "$DEBUG_ENABLED" = true ]; then
|
|
|
|
quartus_sh --set VERILOG_MACRO="DEBUG" ./SummerCart64.qpf
|
2022-01-20 20:28:59 +01:00
|
|
|
else
|
|
|
|
quartus_sh --set -remove VERILOG_MACRO="DEBUG" ./SummerCart64.qpf
|
2021-12-10 17:36:30 +01:00
|
|
|
fi
|
2021-11-16 22:37:48 +01:00
|
|
|
quartus_sh --flow compile ./SummerCart64.qpf
|
|
|
|
fi
|
2021-12-10 17:36:30 +01:00
|
|
|
popd > /dev/null
|
2021-09-26 14:42:50 +02:00
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
BUILT_FPGA=true
|
|
|
|
}
|
2021-09-26 14:42:50 +02:00
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
build_update () {
|
|
|
|
if [ "$BUILT_UPDATE" = true ]; then return; fi
|
2021-09-26 14:42:50 +02:00
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
build_fpga
|
2021-09-26 14:42:50 +02:00
|
|
|
|
2021-12-10 17:36:30 +01:00
|
|
|
pushd fw/output_files > /dev/null
|
2022-01-18 19:21:49 +01:00
|
|
|
objcopy -I binary -O binary --reverse-bytes=4 sc64_firmware_cfm0_auto.rpd SC64_firmware.bin
|
|
|
|
cat SC64_software.bin SC64_firmware.bin > SC64_update.bin
|
2021-12-10 17:36:30 +01:00
|
|
|
popd > /dev/null
|
2021-09-26 14:42:50 +02:00
|
|
|
|
2021-11-10 02:05:51 +01:00
|
|
|
BUILT_UPDATE=true
|
|
|
|
}
|
|
|
|
|
|
|
|
build_release () {
|
|
|
|
if [ "$BUILT_RELEASE" = true ]; then return; fi
|
|
|
|
|
|
|
|
build_cic
|
|
|
|
build_update
|
|
|
|
|
2021-11-16 22:37:48 +01:00
|
|
|
if [ -e "./${PACKAGE_FILE_NAME}.zip" ]; then
|
2021-11-10 02:05:51 +01:00
|
|
|
rm -f "./${PACKAGE_FILE_NAME}.zip"
|
|
|
|
fi
|
2021-11-16 22:37:48 +01:00
|
|
|
zip -j -r "./${PACKAGE_FILE_NAME}.zip" ${FILES[@]}
|
2021-11-10 02:05:51 +01:00
|
|
|
|
|
|
|
BUILT_RELEASE=true
|
|
|
|
}
|
|
|
|
|
|
|
|
print_usage () {
|
|
|
|
echo "builder script for SummerCart64"
|
2021-12-10 17:36:30 +01:00
|
|
|
echo "usage: ./build.sh [cic] [n64] [riscv] [fpga] [update] [release] [-c] [-s] [-d] [--help]"
|
2021-11-10 02:05:51 +01:00
|
|
|
echo "parameters:"
|
2021-11-16 22:37:48 +01:00
|
|
|
echo " cic - assemble UltraCIC-III software"
|
|
|
|
echo " n64 - compile N64 bootloader software"
|
|
|
|
echo " riscv - compile cart governor software"
|
2022-01-18 19:21:49 +01:00
|
|
|
echo " sw - compile all software (triggers 'n64' and 'riscv' build)"
|
|
|
|
echo " fpga - compile FPGA design (triggers 'sw' build)"
|
2021-11-16 22:37:48 +01:00
|
|
|
echo " update - convert programming .pof file to raw binary for self-upgrade (triggers 'fpga' build)"
|
|
|
|
echo " release - collect and zip files for release (triggers 'cic' and 'update' build)"
|
|
|
|
echo " -c | --force-clean"
|
|
|
|
echo " - clean software compilation result directories before build"
|
|
|
|
echo " -s | --skip-fpga-rebuild"
|
|
|
|
echo " - do not recompile whole FPGA design if it's already done, just update software binaries"
|
2021-12-10 17:36:30 +01:00
|
|
|
echo " -d | --debug"
|
|
|
|
echo " - enable debug features"
|
2021-11-16 22:37:48 +01:00
|
|
|
echo " --help - print this guide"
|
2021-11-10 02:05:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if test $# -eq 0; then
|
|
|
|
echo "error: no parameters provided"
|
|
|
|
echo " "
|
|
|
|
print_usage
|
|
|
|
exit 1
|
2021-09-26 14:42:50 +02:00
|
|
|
fi
|
2021-11-10 02:05:51 +01:00
|
|
|
|
|
|
|
TRIGGER_CIC=false
|
|
|
|
TRIGGER_N64=false
|
|
|
|
TRIGGER_RISCV=false
|
2022-01-18 19:21:49 +01:00
|
|
|
TRIGGER_SW=false
|
2021-11-10 02:05:51 +01:00
|
|
|
TRIGGER_FPGA=false
|
|
|
|
TRIGGER_UPDATE=false
|
|
|
|
TRIGGER_RELEASE=false
|
|
|
|
|
|
|
|
while test $# -gt 0; do
|
|
|
|
case "$1" in
|
|
|
|
cic)
|
|
|
|
TRIGGER_CIC=true
|
|
|
|
;;
|
|
|
|
n64)
|
|
|
|
TRIGGER_N64=true
|
|
|
|
;;
|
|
|
|
riscv)
|
|
|
|
TRIGGER_RISCV=true
|
|
|
|
;;
|
2022-01-18 19:21:49 +01:00
|
|
|
sw)
|
|
|
|
TRIGGER_SW=true
|
|
|
|
;;
|
2021-11-10 02:05:51 +01:00
|
|
|
fpga)
|
|
|
|
TRIGGER_FPGA=true
|
|
|
|
;;
|
|
|
|
update)
|
|
|
|
TRIGGER_UPDATE=true
|
|
|
|
;;
|
|
|
|
release)
|
|
|
|
TRIGGER_RELEASE=true
|
|
|
|
;;
|
2021-11-16 22:37:48 +01:00
|
|
|
-c|--force-clean)
|
|
|
|
FORCE_CLEAN=true
|
|
|
|
;;
|
|
|
|
-s|--skip-fpga-rebuild)
|
|
|
|
SKIP_FPGA_REBUILD=true
|
|
|
|
;;
|
2021-12-10 17:36:30 +01:00
|
|
|
-d|--debug)
|
|
|
|
DEBUG_ENABLED=true
|
|
|
|
;;
|
2021-11-10 02:05:51 +01:00
|
|
|
--help)
|
|
|
|
print_usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "error: unknown parameter \"$1\""
|
|
|
|
echo " "
|
|
|
|
print_usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2021-12-10 17:36:30 +01:00
|
|
|
if [ "$DEBUG_ENABLED" = true ]; then USER_FLAGS+=" -DDEBUG"; fi
|
2021-11-10 02:05:51 +01:00
|
|
|
if [ "$TRIGGER_CIC" = true ]; then build_cic; fi
|
|
|
|
if [ "$TRIGGER_N64" = true ]; then build_n64; fi
|
|
|
|
if [ "$TRIGGER_RISCV" = true ]; then build_riscv; fi
|
2022-01-18 19:21:49 +01:00
|
|
|
if [ "$TRIGGER_SW" = true ]; then build_sw; fi
|
2021-11-10 02:05:51 +01:00
|
|
|
if [ "$TRIGGER_FPGA" = true ]; then build_fpga; fi
|
|
|
|
if [ "$TRIGGER_UPDATE" = true ]; then build_update; fi
|
|
|
|
if [ "$TRIGGER_RELEASE" = true ]; then build_release; fi
|