forked from Polprzewodnikowy/SummerCart64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·194 lines (163 loc) · 4.7 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
set -e
PACKAGE_FILE_NAME="SummerCart64"
FILES=(
"./fw/output_files/SC64_firmware.pof"
"./fw/output_files/SC64_update.bin"
"./hw/ftdi-template.xml"
"./sw/cic/UltraCIC-III.hex"
"./LICENSE"
)
BUILT_CIC=false
BUILT_N64=false
BUILT_RISCV=false
BUILT_FPGA=false
BUILT_UPDATE=false
BUILT_RELEASE=false
FORCE_CLEAN=false
SKIP_FPGA_REBUILD=false
DEBUG_ENABLED=false
USER_FLAGS+=" -D__SC64_VERSION=\"$__SC64_VERSION\""
build_cic () {
if [ "$BUILT_CIC" = true ]; then return; fi
pushd sw/cic > /dev/null
avra UltraCIC-III.asm -D attiny45
popd > /dev/null
BUILT_CIC=true
}
build_n64 () {
if [ "$BUILT_N64" = true ]; then return; fi
pushd sw/n64 > /dev/null
if [ "$FORCE_CLEAN" = true ]; then
make clean
fi
make all -j USER_FLAGS="$USER_FLAGS"
popd > /dev/null
BUILT_N64=true
}
build_riscv () {
if [ "$BUILT_RISCV" = true ]; then return; fi
pushd sw/riscv > /dev/null
if [ "$FORCE_CLEAN" = true ]; then
make clean
fi
make all -j USER_FLAGS="$USER_FLAGS"
popd > /dev/null
BUILT_RISCV=true
}
build_fpga () {
if [ "$BUILT_FPGA" = true ]; then return; fi
build_n64
build_riscv
pushd fw > /dev/null
if [ "$SKIP_FPGA_REBUILD" = true ] && [ -f output_files/SummerCart64.sof ]; then
quartus_cpf -c SummerCart64.cof
else
if [ "$DEBUG_ENABLED" = true ]; then
quartus_sh --set VERILOG_MACRO="DEBUG" ./SummerCart64.qpf
fi
quartus_sh --flow compile ./SummerCart64.qpf
quartus_sh --set -remove VERILOG_MACRO="DEBUG" ./SummerCart64.qpf
fi
popd > /dev/null
BUILT_FPGA=true
}
build_update () {
if [ "$BUILT_UPDATE" = true ]; then return; fi
build_fpga
pushd fw/output_files > /dev/null
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 > /dev/null
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 -j -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] [-c] [-s] [-d] [--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 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"
echo " -d | --debug"
echo " - enable debug features"
echo " --help - print this guide"
}
if test $# -eq 0; then
echo "error: no parameters provided"
echo " "
print_usage
exit 1
fi
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
;;
-c|--force-clean)
FORCE_CLEAN=true
;;
-s|--skip-fpga-rebuild)
SKIP_FPGA_REBUILD=true
;;
-d|--debug)
DEBUG_ENABLED=true
;;
--help)
print_usage
exit 0
;;
*)
echo "error: unknown parameter \"$1\""
echo " "
print_usage
exit 1
;;
esac
shift
done
if [ "$DEBUG_ENABLED" = true ]; then USER_FLAGS+=" -DDEBUG"; fi
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