-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sh
executable file
·153 lines (134 loc) · 3.29 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
#!/bin/sh
set -eu
project="$1"
action="${2:-}"
blueroot="$(bsc --help | grep "Bluespec directory: " | awk '{print $3}')"
bluelib="$blueroot/Libraries"
bluev="$blueroot/Verilog"
libpath="lib:$bluelib"
buildout="out/${project}"
function prepare_hex() {
outdir="$1"
has_asm=$(ls -1 ${project} | grep '.asm' | wc -l)
if [ "$has_asm" != "0" ]; then
for f in ${project}/*.asm; do
out="${f##*/}"
go run ${project}/asm.go $f "$outdir/${out%.asm}.hex"
done
fi
has_hex=$(ls -1 ${project} | grep '.hex' | wc -l)
if [ "$has_hex" != "0" ]; then
cp -f ${project}/*.hex "$outdir"
fi
}
function phase() {
echo
echo "****************************************"
echo "**** $1"
echo "****************************************"
echo
}
mkdir -p "$buildout"
buildout=$(readlink -f "$buildout")
synth() {
##################
# Generate Verilog from BSV
##################
phase "Bluespec to Verilog"
bsc -aggressive-conditions -check-assert -u -verilog -info-dir "$buildout" -vdir "$buildout" -bdir "$buildout" -g "mkTop" -p "lib:${project}:${bluelib}" "$project/Top.bsv"
##################
# Synthesize Verilog
##################
phase "Synthesis"
function getLibfiles() {
find "$bluev" -name '*.v' | while read f; do
case "${f##*/}" in
main.v)
;;
InoutConnect.v)
;;
ProbeHook.v)
;;
*)
echo -n "$f "
;;
esac
done
echo
}
libFiles=$(getLibfiles)
cat >"$buildout/synth.ys" <<EOF
read_verilog -defer -sv $libFiles $buildout/mkTop.v
hierarchy -top mkTop
EOF
logflag="-l $buildout/yosys.log -Q -v0"
if [ "$action" = "shell" ]; then
echo "shell" >>"$buildout/synth.ys"
logflag=""
else
echo "synth_ecp5 -abc9 -top mkTop -json $buildout/Top.json" >>"$buildout/synth.ys"
fi
prepare_hex "$buildout"
(
cd "$buildout"
yosys $logflag -T "$buildout/synth.ys"
)
if [ "$action" = "shell" ]; then
exit 0
fi
##################
# Place and Route
##################
phase "Place & Route"
nextpnr-ecp5 --85k --detailed-timing-report -q -l "$buildout/pnr.log" --json "$buildout/Top.json" --lpf "$project/ulx3s.lpf" --package CABGA381 --textcfg "$buildout/Top.pnr"
cat >"$buildout/filter.awk" <<EOF
BEGIN { want = 0 }
/Info: Logic utilisation/ { want = 1 }
/Info: Device utilisation/ { want = 1 }
/Info: Max frequency/ { want = 1 }
/^\$/ {
if (want == 1) { print }
want = 0
}
{ if (want == 1) { print } }
EOF
awk -f "$buildout/filter.awk" "$buildout/pnr.log"
##################
# Pack bitstream
##################
phase "Pack"
ecppack "$buildout/Top.pnr" "$buildout/Top.bit"
##################
# Flash board
##################
if [ "$action" = "flash" ]; then
phase "Flash"
openFPGALoader -b ulx3s "$buildout/Top.bit"
fi
}
function runTest() {
infile="$1"
testout="$buildout/test/${infile%%_*}"
mkdir -p "$testout"
prepare_hex "$testout"
bsc -show-schedule -aggressive-conditions -check-assert -u -sim -info-dir "$testout" -simdir "$testout" -bdir "$testout" -g "mkTB" -p "lib:${project}:${bluelib}" "$project/$infile"
(
set -eu
cd "$testout"
bsc -sim -e mkTB -o TB
echo
./TB
) || exit 1
}
if [ "$action" = "test" ]; then
specifictest="${3:-}"
if [ "$specifictest" == "" ]; then
find "$project" -name "*_Test.bsv" | while read testfile; do
runTest "${testfile##*/}"
done
else
runTest "${specifictest}_Test.bsv"
fi
else
synth
fi