-
Notifications
You must be signed in to change notification settings - Fork 0
/
.update.sh
executable file
·215 lines (189 loc) · 4.96 KB
/
.update.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
# vim: ai ts=2 sw=2 et sts=2 ft=sh
# vim: autoindent tabstop=2 shiftwidth=2 expandtab softtabstop=2 filetype=sh
# .update.sh [branch] [commit-id] [message]
#
# branch - unstable, testing, stable
# commit-id - For unstable and testing, it is commit id of target from git://github.com/timvideos/HDMI2USB.git
# For stable, it shouldn't be given.
#
# The latest testing version becomes stable.
set -e
set -x
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
function checkout_firmware {
FIRMWARE_LOCATION="$1"
COMMIT_ID="$2"
if [ ! -d "$FIRMWARE_LOCATION" ]; then
git clone git://github.com/timvideos/HDMI2USB.git "$FIRMWARE_LOCATION"
else
(
cd "$FIRMWARE_LOCATION"
git fetch --tags
)
fi
(
cd "$FIRMWARE_LOCATION"
git checkout "$COMMIT_ID"
git reset --hard
if [ ! -z "$CLEAN" ]; then
git clean -X -d -f
fi
)
}
function describe_firmware {
FIRMWARE_LOCATION="$1"
(cd "$FIRMWARE_LOCATION"; git describe --long --match v*)
}
function build_firmware {
FIRMWARE_LOCATION="$1"
# Generate the .hex file (Cypress USB Firmware)
build_hex() {
cd "$FIRMWARE_LOCATION/cypress"
make clean
make
}
CYPRESS_FILE="$FIRMWARE_LOCATION/cypress/hdmi2usb.hex"
if [ \( ! -z "$CLEAN" \) -o \( ! -f "$CYPRESS_FILE" \) ]; then
build_hex
fi
if [ ! -f "$CYPRESS_FILE" ]; then
echo "Cypress Firmware failed to build!"
echo "No '$CYPRESS_FILE' file found."
exit 1
fi
# Generate the .bit file (FPGA Firmware)
build_bit() {
source /opt/Xilinx/14.7/ISE_DS/settings64.sh
cd "$FIRMWARE_LOCATION"
make clean
make all
}
FPGA_BITFILE="$FIRMWARE_LOCATION/build/hdmi2usb.bit"
if [ \( ! -z "$CLEAN" \) -o \( ! -f "$FPGA_BITFILE" \) ]; then
build_bit
fi
if [ ! -f "$FPGA_BITFILE" ]; then
echo "FPGA Firmware failed to build!"
echo "No '$FPGA_BITFILE' file found."
exit 1
fi
# Generate the .xsvf file (FPGA Firmare converted for libfpgalink)
build_xsvf() {
. /opt/Xilinx/14.7/ISE_DS/settings64.sh
cd "$FIRMWARE_LOCATION"
make xsvf
}
FPGA_XSVF="$FIRMWARE_LOCATION/build/hdmi2usb.xsvf"
if [ \( ! -z "$CLEAN" \) -o \( ! -f "$FPGA_XSVF" \) ]; then
build_xsvf
fi
if [ ! -f "$FPGA_XSVF" ]; then
echo "FPGA Firmware failed to convert to .xsvf!"
echo "No '$FPGA_XSVF' file found."
exit 1
fi
}
function copy_firmware {
FIRMWARE_LOCATION="$1"
OUTPUT_LOCATION="$2"
mkdir "$OUTPUT_LOCATION"
FILES=(
"cypress/hdmi2usb.hex"
"build/hdmi2usb.bit"
"build/hdmi2usb.xsvf"
)
for FILE in "${FILES[@]}"; do
OUTFILE="$OUTPUT_LOCATION/$(basename $FILE)"
cp "$FIRMWARE_LOCATION/$FILE" "$OUTFILE"
git add "$OUTFILE"
done
LOGS=(
"hdmi2usb.bgn"
"hdmi2usb.bld"
"hdmi2usb.drc"
"hdmi2usb_map.mrp"
"hdmi2usb.pad"
"hdmi2usb_pad.csv"
"hdmi2usb_pad.txt"
"hdmi2usb.par"
"hdmi2usb.syr"
"hdmi2usb.twr"
"hdmi2usb.unroutes"
)
mkdir -p $OUTPUT_LOCATION/logs
for LOG in "${LOGS[@]}"; do
OUTFILE="$OUTPUT_LOCATION/logs/$LOG"
cp "$FIRMWARE_LOCATION/build/$LOG" "$OUTFILE"
git add "$OUTFILE"
done
XRPTS=(
"hdmi2usb_map.xrpt"
"hdmi2usb_ngdbuild.xrpt"
"hdmi2usb_par.xrpt"
"hdmi2usb_xst.xrpt"
)
mkdir -p $OUTPUT_LOCATION/xrpt
for XRPT in "${XRPTS[@]}"; do
OUTFILE="$OUTPUT_LOCATION/xrpt/$XRPT"
cp "$FIRMWARE_LOCATION/build/$XRPT" "$OUTFILE"
git add "$OUTFILE"
done
}
function update_link {
BRANCH="$1"
COMMIT_NAME="$2"
EXTRA_MSG="$3"
rm $BRANCH
ln -s Archive/$COMMIT_NAME $BRANCH
git add $BRANCH
git commit -m "Updating $BRANCH to $COMMIT_NAME$EXTRA_MSG"
}
if [ ! -f /opt/Xilinx/14.7/ISE_DS/settings64.sh ]; then
echo "To build the firmware, Xilinx ISE 14.7 needs to be installed to /opt/Xilinx"
echo "See https://github.com/timvideos/HDMI2USB/wiki/Development-Environment for more information."
exit 1
fi
BRANCH=$1
COMMIT_ID=$2
EXTRA_MSG=$3
case x$BRANCH in
xstable)
if [ "x$COMMIT_ID" != "x" ]; then
echo "Don't specify a commit id for stable, it will use the latest testing version."
exit 1
fi
# Make the stable firmware equal to testing
COMMIT_ID="$(basename $(readlink testing))"
EXTRA_MSG="(current testing branch) $EXTRA_MSG"
;;
xtesting|xunstable)
if [ "x$COMMIT_ID" == "x" ]; then
echo "Need to specify a commit id!"
exit 1
fi
;;
*)
echo "Unknown branch '$1'"
exit 1
;;
esac
# Build the firmware
SRC_DIR=$SCRIPT_DIR/src
checkout_firmware "$SRC_DIR" "$COMMIT_ID"
cd $SCRIPT_DIR
COMMIT_NAME=$(describe_firmware "$SRC_DIR")
echo "Name for '$COMMIT_ID' is '$COMMIT_NAME'"
OUT_DIR=Archive/$COMMIT_NAME
if [ \( ! -z "$CLEAN" \) -o \( ! -d "$OUT_DIR" \) ]; then
if [ ! -z "$CLEAN" ]; then
rm -rvf $OUT_DIR
fi
( build_firmware "$SRC_DIR" )
# The git add in copy_firmware needs a relative path.
( copy_firmware "$SRC_DIR" "$OUT_DIR" )
fi
if [ "x$EXTRA_MSG" != x ]; then
EXTRA_MSG=" $EXTRA_MSG"
fi
( update_link "$BRANCH" "$COMMIT_NAME" "$EXTRA_MSG" )