-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
build.sh
executable file
·215 lines (182 loc) · 5.47 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
set -e
SC64_VERSION=${SC64_VERSION:-"none"}
PACKAGE_FILE_NAME="sc64-extra"
TOP_FILES=(
"./fw/ftdi/ft232h_config.xml"
"./fw/project/lcmxo2/impl1/fpga_max_frequency.txt"
"./sw/tools/primer.py"
"./sw/tools/requirements.txt"
"./sc64-firmware-${SC64_VERSION}.bin"
)
FILES=(
"./assets/*"
"./docs/*"
"./hw/pcb/sc64v2_bom.html"
"./hw/pcb/sc64v2.kicad_pcb"
"./hw/pcb/sc64v2.kicad_pro"
"./hw/pcb/sc64v2.kicad_sch"
"./hw/shell/sc64_shell_back.stl"
"./hw/shell/sc64_shell_front.stl"
"./LICENSE"
"./README.md"
)
BUILT_BOOTLOADER=false
BUILT_CONTROLLER=false
BUILT_CIC=false
BUILT_FPGA=false
BUILT_UPDATE=false
BUILT_RELEASE=false
FORCE_CLEAN=false
build_bootloader () {
if [ "$BUILT_BOOTLOADER" = true ]; then return; fi
pushd sw/bootloader > /dev/null
if [ "$FORCE_CLEAN" = true ]; then
make clean
fi
VERSION=""
if [ ! -z "${GIT_BRANCH+x}" ]; then VERSION+=" -DGIT_BRANCH='\"$GIT_BRANCH\"'"; fi
if [ ! -z "${GIT_TAG+x}" ]; then VERSION+=" -DGIT_TAG='\"$GIT_TAG\"'"; fi
if [ ! -z "${GIT_SHA+x}" ]; then VERSION+=" -DGIT_SHA='\"$GIT_SHA\"'"; fi
if [ ! -z "${GIT_MESSAGE+x}" ]; then VERSION+=" -DGIT_MESSAGE='\"$GIT_MESSAGE\"'"; fi
make all -j VERSION="$VERSION" USER_FLAGS="$USER_FLAGS"
popd > /dev/null
BUILT_BOOTLOADER=true
}
build_controller () {
if [ "$BUILT_CONTROLLER" = true ]; then return; fi
pushd sw/controller > /dev/null
if [ "$FORCE_CLEAN" = true ]; then
./build.sh clean
fi
USER_FLAGS="$USER_FLAGS" ./build.sh all
popd > /dev/null
BUILT_CONTROLLER=true
}
build_cic () {
if [ "$BUILT_CIC" = true ]; then return; fi
pushd sw/cic > /dev/null
if [ "$FORCE_CLEAN" = true ]; then
./build.sh clean
fi
./build.sh all
popd > /dev/null
BUILT_CIC=true
}
build_fpga () {
if [ "$BUILT_FPGA" = true ]; then return; fi
build_cic
pushd fw/project/lcmxo2 > /dev/null
if [ "$FORCE_CLEAN" = true ]; then
rm -rf ./impl1/
fi
./build.sh
popd > /dev/null
BUILT_FPGA=true
}
build_update () {
if [ "$BUILT_UPDATE" = true ]; then return; fi
build_bootloader
build_controller
build_cic
build_fpga
pushd sw/tools > /dev/null
if [ "$FORCE_CLEAN" = true ]; then
rm -f ../../sc64-firmware-*.bin
fi
GIT_INFO=""
GIT_INFO+=$'\n'"freq: $(cat ../../fw/project/lcmxo2/impl1/fpga_max_frequency.txt)"
if [ ! -z "${SC64_VERSION}" ]; then GIT_INFO+=$'\n'"ver: $SC64_VERSION"; fi
if [ ! -z "${GIT_BRANCH}" ]; then GIT_INFO+=$'\n'"branch: $GIT_BRANCH"; fi
if [ ! -z "${GIT_TAG}" ]; then GIT_INFO+=$'\n'"tag: $GIT_TAG"; fi
if [ ! -z "${GIT_SHA}" ]; then GIT_INFO+=$'\n'"sha: $GIT_SHA"; fi
if [ ! -z "${GIT_MESSAGE}" ]; then GIT_INFO+=$'\n'"msg: $GIT_MESSAGE"; fi
python3 update.py \
--git "$GIT_INFO" \
--mcu ../controller/build/app/app.bin \
--fpga ../../fw/project/lcmxo2/impl1/sc64_impl1.jed \
--boot ../bootloader/build/bootloader.bin \
--primer ../controller/build/primer/primer.bin \
../../sc64-firmware-${SC64_VERSION}.bin
popd > /dev/null
BUILT_UPDATE=true
}
build_release () {
if [ "$BUILT_RELEASE" = true ]; then return; fi
build_update
if [ -e "./${PACKAGE_FILE_NAME}-${SC64_VERSION}.zip" ]; then
rm -f ./${PACKAGE_FILE_NAME}-${SC64_VERSION}.zip
fi
PACKAGE="./${PACKAGE_FILE_NAME}-${SC64_VERSION}.zip"
zip -j -r $PACKAGE ${TOP_FILES[@]}
zip -r $PACKAGE ${FILES[@]}
BUILT_RELEASE=true
}
print_usage () {
echo "builder script for SC64"
echo "usage: ./build.sh [bootloader] [controller] [cic] [fpga] [update] [release] [-c] [--help]"
echo "parameters:"
echo " bootloader - compile N64 bootloader software"
echo " controller - compile MCU controller software"
echo " cic - compile CIC emulation software"
echo " fpga - compile FPGA design"
echo " update - compile all software and designs"
echo " release - collect and zip files for release (triggers 'update' build)"
echo " -c | --force-clean"
echo " - clean compilation result directories before build"
echo " --help - print this guide"
}
if test $# -eq 0; then
echo "error: no parameters provided"
echo " "
print_usage
exit 1
fi
TRIGGER_BOOTLOADER=false
TRIGGER_CONTROLLER=false
TRIGGER_CIC=false
TRIGGER_FPGA=false
TRIGGER_UPDATE=false
TRIGGER_RELEASE=false
while test $# -gt 0; do
case "$1" in
bootloader)
TRIGGER_BOOTLOADER=true
;;
controller)
TRIGGER_CONTROLLER=true
;;
cic)
TRIGGER_CIC=true
;;
fpga)
TRIGGER_FPGA=true
;;
update)
TRIGGER_UPDATE=true
;;
release)
TRIGGER_RELEASE=true
;;
-c|--force-clean)
FORCE_CLEAN=true
;;
--help)
print_usage
exit 0
;;
*)
echo "error: unknown parameter \"$1\""
echo " "
print_usage
exit 1
;;
esac
shift
done
if [ "$TRIGGER_BOOTLOADER" = true ]; then build_bootloader; fi
if [ "$TRIGGER_CONTROLLER" = true ]; then build_controller; fi
if [ "$TRIGGER_CIC" = true ]; then build_cic; 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