forked from elua/elua
-
Notifications
You must be signed in to change notification settings - Fork 1
/
go
executable file
·293 lines (254 loc) · 7.57 KB
/
go
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#! /bin/sh
# Compile, program and run eLua.
# Usage, from an elua source directory hereunder:
# ../go [options]
# options are a selection of:
usage=" avr32program Use JTAG programmer instead of dfu bootloader
batchisp3 Use batchisp3 programmer instead of dfu-programmer
dfu Use dfu-programmer (which is the default)
noprog Don't program the firmware to the board
evk1100 Make image for EVK1100 board instead of Mizar32
128/256/512 Build for 128KB 256KB or 512KB models (default 256)
emblod Prepare image to put on SD card for emBLOD bootloader
lua,lualong Compile eLua with floating point or integer variables
lualonglong Compile eLua with 64-bit integer variables
picoc,picoclong Compile picoc with floating point or without
picolisp Compile picolisp
tinyscheme Compile tinyscheme
simple Use simple allocator (default for 128)
multiple Use multiple allocator (default for 256/512)
newlib Use newlib's allocator
allocator=x Synonym for one of the above three
optram=n Set memory optimization (default optram=2)
rostrings Enable read-only strings and functions
avr32-tools Use jsnyder's gcc-4.4
x-tools Use crosstool-ng's compiler
as4e-ide Use AVR32Studio's compiler
scons Use the scons build system
build_elua Use the Lua build system
clean Remove all object files from the source tree first
build_date Include the build date (as suffix) in output file
-a [opts] Build all supported combinations"
set -e
JFLAG="-j 8"
if [ "$1" = "-a" ]; then
shift
for target in lua lualong lualonglong \
picoc picoclong \
picolisp tinyscheme
do
echo -n "${target}: "
if $0 $target noprog "$@" > errs 2>&1; then
echo "OK"
else
echo "FAIL"
fi
done
exit $?
fi
# $board, $cpu and $target are just the values to pass to scons' "board=X" args.
# The other optional scons flags' values are of the form "allocator=simple",
# so $allocator's value is either "" or, for example, "allocator=simple"
# This lets us say "scons $allocator" below, to let scons choose a default
# value if not set.
board=mizar32
flash=256
# cpu is automatically derived from flash size
lang=
target=
allocator=
programmer=dfu
bootloader=
media="$(echo /media/????-????)"
optram=
rostrings=
build_system=scons
build_date=false
gcc=
clean=false
# Process command-line options and override default settings
for arg
do
case "$arg" in
avr32program|batchisp3|dfu|noprog) programmer="$arg" ;;
evk1100) board=ATEVK1100; flash=512 ;;
emblod) bootloader="bootloader=emblod"
programmer=emblod ;;
board=*) eval $arg ;;
lua) lang=elua; target=fp ;;
lualong) lang=elua; target=long ;;
lualonglong) lang=elua; target=longlong ;;
picoc) lang=picoc; target=fp ;;
picoclong) lang=picoc; target=long ;;
picolisp) lang=picolisp; target=regular ;;
tinyscheme) lang=tinyscheme; target=fp ;;
128|256|512) flash=$arg ;;
allocator=*) allocator="$arg" ;;
simple|multiple|newlib) allocator="allocator=$arg" ;;
optram=[012]) optram="$arg" ;;
rostrings) rostrings="rostrings=1" ;;
rostrings=[01]) rostrings="$arg" ;;
gcc-4.3|gcc-4.4|avr32-tools|x-tools|as4e-ide) gcc=$arg ;;
scons|build_elua) build_system=$arg ;;
clean) clean=true ;;
build_date) build_date=true ;;
*) echo "What's \"$arg\"? Options are:
$usage"
exit 1
esac
done
# Apply defaults
if [ ! "$lang" ]; then
lang=elua
fi
if [ ! "$target" ]; then
lang=elua
case "$flash" in
128) target=long ;;
256|512) target=long ;;
*) echo "target undefined and flash size unrecognized" 1>&2
exit 1 ;;
esac
fi
# If optram is not set, 128 model defaults to the smallest code size
if [ ! "$optram" ]; then
case "$flash" in
128) optram="optram=0" ;;
esac
fi
# If rostrings is not set, 128 model defaults to the smallest code size
if [ ! "$rostrings" ]; then
case "$flash" in
128) rostrings="rostrings=0" ;;
esac
fi
# If allocator is not set, 128 model defaults to the smallest code size
if [ ! "$allocator" ]; then
case "$flash" in
128) allocator="allocator=simple" ;;
esac
fi
case "$gcc" in
avr32-tools|x-tools|as4e-ide)
case "$gcc" in
avr32-tools) BIN=$HOME/avr32-tools/bin ;;
x-tools) BIN=$HOME/x-tools/avr32-unknown-none/bin ;;
as4e-ide) BIN=/usr/local/as4e-ide/plugins/com.atmel.avr.toolchains.linux.x86_3.0.0.201009140852/os/linux/x86/bin ;;
esac
if [ ! -x $BIN/avr32-gcc ]; then
echo "$BIN/avr32-gcc not found" 1>&2
exit 1
fi
PATH="$BIN:$PATH"
export PATH
# Check we got it right...
if [ "`which avr32-gcc`" != "$BIN/avr32-gcc" ]; then
echo "We're getting the wrong toolchain" 1>&2
exit 1
fi
;;
"")
: # Uses the default avr32-gcc
;;
*)
echo "BUG in $0: gcc=$gcc not recognized" 1>&2
exit 1
;;
esac
# Values derived from the above
part=at32uc3a0${flash}
cpu=$(echo $part | tr a-z A-Z)
if $clean; then
scons board=$board lang=$lang target=$target -c
rm -rf .build # build_lua.lua object dir
rm -f *.elf *.hex *.bin config.log
fi
# Compile it
case "$build_system" in
scons)
echo scons $JFLAG \
board=$board cpu=$cpu lang=$lang target=$target $bootloader $allocator \
$optram $rostrings build_date=$build_date
scons $JFLAG \
board=$board cpu=$cpu lang=$lang target=$target $bootloader $allocator \
$optram $rostrings build_date=$build_date || exit 1
;;
build_elua)
echo lua build_elua.lua \
board=$board cpu=$cpu target=$target $bootloader $allocator \
$optram $rostrings build_date=$build_date
lua build_elua.lua \
board=$board cpu=$cpu target=$target $bootloader $allocator \
$optram $rostrings build_date=$build_date || exit 1
;;
*)
echo "Unrecognized build system '$build_system'"
exit 1
esac
# $firmware: basename of output filenames, different for elua and Alcor6L
# raman: The date now is an optional parameter.
date=`date +%Y%m%d`
case "$(basename $(pwd))" in
elua*) firmware=elua_${target}_${part} ;;
*) case "$lang" in
elua|picoc|picolisp|tinyscheme)
if [ ! "$build_date" ]; then
firmware=Alcor6L_${lang}_${target}_${part}_${date}
else
firmware=Alcor6L_${lang}_${target}_${part}
fi ;;
*) echo "Unrecognised lang \"$lang\"" ; exit 1 ;;
esac ;;
esac
# Make hex and bin versions for distribution
echo Making .hex and .bin versions...
avr32-objcopy -O ihex $firmware.elf $firmware.hex
avr32-objcopy -O binary $firmware.elf $firmware.bin
# Program it to the chip
case "$programmer" in
noprog)
;;
avr32program)
avr32program program -cxtal -e -v -f internal@0x80000000,${flash}kB $firmware.elf
avr32program reset -r
;;
batchisp3)
echo "=== If erasure fails, wait 10 seconds and press I ==="
batchisp3 -hardware usb -device $part -operation \
erase f memory flash blankcheck \
loadbuffer $PWD/$firmware.elf \
program verify start reset 0
;;
dfu)
# Make sure device is present. Quit if not.
sudo dfu-programmer $part get || exit 1
echo dfu-programmer $part erase
sudo dfu-programmer $part erase || {
sleep 1
until sudo dfu-programmer $part get > /dev/null
do
echo "Erase failed. Waiting..."
sleep 1
done
}
echo dfu-programmer $part flash $firmware.hex
sudo dfu-programmer $part flash $firmware.hex
false && {
echo "Verifying..."
avr32-objcopy -O binary $firmware.elf $firmware.bin
size="`ls -l $firmware.bin | awk '{print $5}'`" # size of elua
echo $size
# Drop 8k boot loader from dump, and compare only up to the size of elua
sudo dfu-programmer $part dump | \
tail -c +8193 | head -c "$size" | \
cmp -l - $firmware.bin
}
echo dfu-programmer $part start
sudo dfu-programmer $part start
;;
emblod)
avr32-objcopy -O binary $firmware.elf $firmware.bin
cp $firmware.bin "$media"/autorun.bin
umount "$media"
;;
esac