blob: 2533b262ded569d318e1d8a356ecd1a6b09bff06 (
plain)
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
|
#!/bin/sh
#
# Build envsensors and install on a Micropython board.
#
basedir="$(dirname "$0")"
[ "$(echo "$basedir" | cut -c1)" = '/' ] || basedir="$PWD/$basedir"
rootdir="$(realpath -m "$basedir/..")"
die()
{
echo "ERROR: $*" >&2
exit 1
}
echos()
{
printf '%s' "$*"
}
build()
{
echo "=== build ==="
cd "$basedir" || die "Failed to switch to dir."
local pys="$(find . \( -name boot.py -prune \) -o \( -name main.py -prune \) -o \( -name '*.py' -print \))"
local targets=
[ -n "$clean" ] && local targets="$targets clean"
local targets="$targets all"
for target in $targets; do
echo "--- $target ---"
make -j "$(getconf _NPROCESSORS_ONLN)" \
SRCDIR=. \
MAINPYDIR=. \
BUILDDIR="$builddir" \
MPYCROSS="$mpycross" \
MARCH="$march" \
PYS="$pys" \
$target || die "make failed."
done
}
pyboard()
{
echo "$pyboard -d $dev $*"
"$pyboard" -d "$dev" "$@" || die "pyboard: $pyboard failed."
}
reboot_dev()
{
pyboard --no-follow -c 'import machine as m;m.reset()'
}
format_flash()
{
local wd_timeout="120000"
local cmd="import machine as m, flashbdev as f, uos as u;"
cmd="${cmd}m.WDT(0,${wd_timeout}).feed();"
cmd="${cmd}u.umount('/');"
cmd="${cmd}u.VfsLfs2.mkfs(f.bdev);"
cmd="${cmd}u.mount(u.VfsLfs2(f.bdev), '/');"
pyboard -c "$cmd"
}
transfer()
{
local from="$1"
local to="$2"
if [ -d "$from" ]; then
pyboard -f mkdir "$to"
for f in "$from"/*; do
transfer "$f" "$to/$(basename "$f")"
done
return
fi
pyboard -f cp "$from" "$to"
}
transfer_to_device()
{
echo "=== transfer to device $dev ==="
format_flash
reboot_dev
sleep 2
for f in "$builddir"/*; do
transfer "$f" :/"$(basename $f)"
done
reboot_dev
}
builddir="$rootdir/build/sensor_firmware"
buildonly=0
dev="/dev/ttyUSB0"
march="xtensawin"
pyboard="pyboard.py"
mpycross="mpy-cross"
clean=
while [ $# -ge 1 ]; do
[ "$(echos "$1" | cut -c1)" != "-" ] && break
case "$1" in
-h|--help)
echo "install.sh [OPTIONS] [TARGET-UART-DEVICE]"
echo
echo "Build envsensors and install on a Micropython board."
echo
echo "TARGET-UART-DEVICE:"
echo " Target serial device. Default: /dev/ttyUSB0"
echo
echo "Options:"
echo " -c|--clean Clean before build."
echo " -b|--build-only Build only. Do not install."
echo " -B|--build-dir DIR Set the build directory."
echo " Default: build/sensor_firmware"
echo " -a|--march ARCH Target architecture for cross compile."
echo " Default: xtensawin"
echo " -M|--mpycross PATH Path to mpy-cross executable."
echo " Default: mpy-cross"
echo " -p|--pyboard PATH Path to pyboard executable."
echo " Default: pyboard.py"
echo " -h|--help Show this help."
exit 0
;;
-b|--build-only)
buildonly=1
;;
-B|--build-dir)
shift
builddir="$1"
;;
-a|--march)
shift
march="$1"
;;
-p|--pyboard)
shift
pyboard="$1"
;;
-M|--mpycross)
shift
mpycross="$1"
;;
-c|--clean)
clean=1
;;
*)
die "Unknown option: $1"
;;
esac
shift
done
if [ $# -ge 1 ]; then
dev="$1"
shift
fi
if [ $# -ge 1 ]; then
die "Too many arguments."
fi
build
[ $buildonly -eq 0 ] && transfer_to_device
exit 0
|