From fa53686650323add3a259742691d70cb9e7bd1a6 Mon Sep 17 00:00:00 2001 From: Polprzewodnikowy Date: Wed, 10 Nov 2021 01:10:33 +0100 Subject: [PATCH] reworked build script --- .github/workflows/main.yml | 2 +- build.sh | 160 +++++++++++++++++++++++++++++++------ build_in_docker.sh | 6 -- docker_build.sh | 8 ++ fw/SummerCart64.qsf | 3 +- fw/scripts/post_flow.tcl | 6 ++ 6 files changed, 152 insertions(+), 33 deletions(-) delete mode 100755 build_in_docker.sh create mode 100644 docker_build.sh create mode 100644 fw/scripts/post_flow.tcl diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 86be24e..0aa8995 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: submodules: true - name: Build script - run: ./build_in_docker.sh + run: ./docker_build.sh release - name: Upload artifact uses: actions/upload-artifact@v2 diff --git a/build.sh b/build.sh index 40a5558..c8aa6c9 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,9 @@ #!/bin/bash +set -e PACKAGE_FILE_NAME="SummerCart64" + FILES=( "./fw/output_files/SC64_firmware.pof" "./fw/output_files/SC64_update.bin" @@ -10,40 +12,148 @@ FILES=( "./LICENSE" ) +BUILT_CIC=false +BUILT_N64=false +BUILT_RISCV=false +BUILT_FPGA=false +BUILT_UPDATE=false +BUILT_RELEASE=false -set -e +build_cic () { + if [ "$BUILT_CIC" = true ]; then return; fi + pushd sw/cic + avra UltraCIC-III.asm -D attiny45 + popd -pushd sw/cic -echo "Building UltraCIC-III software" -avra UltraCIC-III.asm -D attiny45 -popd + BUILT_CIC=true +} +build_n64 () { + if [ "$BUILT_N64" = true ]; then return; fi -pushd sw/n64 -echo "Building N64 bootloader software" -make clean all -popd + pushd sw/n64 + make clean all + popd + BUILT_N64=true +} -pushd sw/riscv -echo "Building RISC-V controller software" -make clean all -popd +build_riscv () { + if [ "$BUILT_RISCV" = true ]; then return; fi + pushd sw/riscv + make clean all + popd -pushd fw -echo "Building FPGA firmware" -quartus_sh --flow compile ./SummerCart64.qpf -quartus_cpf -c ./SummerCart64.cof -cp output_files/SC64_firmware.pof output_files/SC64_update.pof -cat output_files/sc64_firmware_ufm_auto.rpd output_files/sc64_firmware_cfm0_auto.rpd > output_files/SC64_update_LE.bin -riscv32-unknown-elf-objcopy -I binary -O binary --reverse-bytes=4 output_files/SC64_update_LE.bin output_files/SC64_update.bin -popd + BUILT_RISCV=true +} +build_fpga () { + if [ "$BUILT_FPGA" = true ]; then return; fi -echo "Zipping files" -if [[ -e "./${PACKAGE_FILE_NAME}.zip" ]]; then - rm -f "./${PACKAGE_FILE_NAME}.zip" + build_n64 + build_riscv + + pushd fw + quartus_sh --flow compile ./SummerCart64.qpf + popd + + BUILT_FPGA=true +} + +build_update () { + if [ "$BUILT_UPDATE" = true ]; then return; fi + + build_fpga + + pushd fw/output_files + cat sc64_firmware_ufm_auto.rpd sc64_firmware_cfm0_auto.rpd > SC64_update_tmp.bin + objcopy -I binary -O binary --reverse-bytes=4 SC64_update_tmp.bin SC64_update.bin + rm SC64_update_tmp.bin + popd + + BUILT_UPDATE=true +} + +build_release () { + if [ "$BUILT_RELEASE" = true ]; then return; fi + + build_cic + build_update + + if [[ -e "./${PACKAGE_FILE_NAME}.zip" ]]; then + rm -f "./${PACKAGE_FILE_NAME}.zip" + fi + zip -r "./${PACKAGE_FILE_NAME}.zip" ${FILES[@]} + + BUILT_RELEASE=true +} + +print_usage () { + echo "builder script for SummerCart64" + echo "usage: ./build.sh [cic] [n64] [riscv] [fpga] [update] [release] [--help]" + echo "parameters:" + echo " cic - assemble UltraCIC-III software" + echo " n64 - compile N64 bootloader software" + echo " riscv - compile cart governor software" + echo " fpga - compile FPGA design (triggers 'n64' and 'riscv' build)" + echo " update - convert programming .pof file to raw binary for user upgrade (triggers 'fpga' build)" + echo " release - collect and zip files for release (triggers 'cic' and 'update' build)" + echo " --help - print this guide" +} + +if test $# -eq 0; then + echo "error: no parameters provided" + echo " " + print_usage + exit 1 fi -zip -r "./${PACKAGE_FILE_NAME}.zip" ${FILES[@]} + +TRIGGER_CIC=false +TRIGGER_N64=false +TRIGGER_RISCV=false +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 + ;; + fpga) + TRIGGER_FPGA=true + ;; + update) + TRIGGER_UPDATE=true + ;; + release) + TRIGGER_RELEASE=true + ;; + --help) + print_usage + exit 0 + ;; + *) + echo "error: unknown parameter \"$1\"" + echo " " + print_usage + exit 1 + ;; + esac + shift +done + +if [ "$TRIGGER_CIC" = true ]; then build_cic; fi +if [ "$TRIGGER_N64" = true ]; then build_n64; fi +if [ "$TRIGGER_RISCV" = true ]; then build_riscv; fi +if [ "$TRIGGER_FPGA" = true ]; then build_fpga; fi +if [ "$TRIGGER_UPDATE" = true ]; then build_update; fi +if [ "$TRIGGER_RELEASE" = true ]; then build_release; fi diff --git a/build_in_docker.sh b/build_in_docker.sh deleted file mode 100755 index 1bcf5a5..0000000 --- a/build_in_docker.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -docker run --rm -it \ - --mount type=bind,src="$(pwd)",target="/workdir" \ - ghcr.io/polprzewodnikowy/sc64env:v1.1 \ - /bin/bash -c "./build.sh" diff --git a/docker_build.sh b/docker_build.sh new file mode 100644 index 0000000..2767a1a --- /dev/null +++ b/docker_build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +docker run \ + --rm \ + -it \ + --mount type=bind,src="$(pwd)",target="/workdir" \ + ghcr.io/polprzewodnikowy/sc64env:v1.2 \ + ./build.sh $@ diff --git a/fw/SummerCart64.qsf b/fw/SummerCart64.qsf index 6ddfce7..b0b22b8 100644 --- a/fw/SummerCart64.qsf +++ b/fw/SummerCart64.qsf @@ -19,7 +19,7 @@ # # Quartus Prime # Version 21.1.0 Build 842 10/21/2021 SJ Lite Edition -# Date created = 20:25:39 November 08, 2021 +# Date created = 23:52:20 November 09, 2021 # # -------------------------------------------------------------------------- # # @@ -83,6 +83,7 @@ set_global_assignment -name SYSTEMVERILOG_FILE rtl/system/config.sv set_global_assignment -name SYSTEMVERILOG_FILE rtl/system/sc64.sv set_global_assignment -name SYSTEMVERILOG_FILE rtl/system/system.sv set_global_assignment -name SYSTEMVERILOG_FILE rtl/usb/usb_ft1248.sv +set_global_assignment -name POST_FLOW_SCRIPT_FILE "quartus_sh:scripts/post_flow.tcl" # Pin & Location Assignments # ========================== diff --git a/fw/scripts/post_flow.tcl b/fw/scripts/post_flow.tcl new file mode 100644 index 0000000..9fa437e --- /dev/null +++ b/fw/scripts/post_flow.tcl @@ -0,0 +1,6 @@ +set flow [lindex $quartus(args) 0] + +if [string match "compile" $flow] { + post_message "Generating final programming file" + qexec "quartus_cpf -c SummerCart64.cof" +}