forked from magore/esp8266_ili9341
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_esp-open-sdk
executable file
·298 lines (249 loc) · 5.9 KB
/
get_esp-open-sdk
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
294
295
296
297
#!/bin/bash
#
# install an build the latest ESP8266 OPEN SDK
# ASSUME Ubuntu 14.04LTS or 16.04LTS
# Mike Gore May 2017
# What: display a separator
# Example: sep
sep()
{
echo "====================================================="
echo
echo
echo
}
update_packages()
{
sudo apt-get install make unrar-free autoconf automake \
libtool libltdl7 libltdl-dev libtool-bin \
gcc g++ gperf flex bison texinfo gawk ncurses-dev \
libexpat-dev python-dev python python-serial \
sed git unzip bash help2man wget bzip2
sep
}
# What: Echo ERROR: and arguments
# Arguments: $*
# Returns: Exit 1
# Example:
# fatal we failed
fatal()
{
echo "$*"; exit 1;
}
# What: Display the absolute path of a file - uses echo
# Arguments: path
# Notes: if argument is -bash then return absolute of current directory
# Example:
# absolute ~/file.txt
absolute()
{
if [ -z "$1" ]
then
fatal " $FUNCNAME: missing argument: [$0]"
fi
# FIXME if the argument is -bash, then is this the correct course of action?
if [ "$1" = "-bash" ]
then
echo -n "$(readlink -f \"`pwd`\")"
return
fi
# Our full path name
echo -n "$(readlink -f "$1")"
}
# What: Change directory and verify we actually end up there
# Argument: directory
# Notes: Useful if verifying permission of traget directory
# Example:
# check_cd /tmp/projects
check_cd()
{
declare DIR="$1"
echo "check_cd $DIR"
declare P="`absolute \"$DIR\"`"
if [ -z "$P" ]
then
fatal "$FUNCNAME: No directory"
fi
pushd "$P"
declare PWD=$(pwd)
if [ "$PWD" != "$P" ]
then
fatal "Can NOT change directory to [$P]"
fi
}
check_dir()
{
declare i
for i in $*
do
if [ ! -d "$i" ]
then
fatal "Directory:[$i] missing"
fi
done
}
check_files()
{
declare i
for i in $*
do
if [ ! -f "$i" ]
then
fatal "Directory:[$i] missing"
fi
done
}
rm_path()
{
export PATH
export PATH=$(echo "$PATH" | sed -e "s,$1:,,g")
export PATH=$(echo "$PATH" | sed -e "s/^://g" | sed -e "s/::/:/g")
}
set_path()
{
# See: https://nurdspace.nl/ESP8266/First_setup
# https://github.com/esp8266/esp8266-wiki/wiki/Toolchain
export COMPILE=gcc
export ROOT_DIR="/opt/Espressif"
export SDK_BASE="$ROOT_DIR/esp-open-sdk"
export SDK_HOME="$SDK_BASE/sdk"
export SDK_BIN="$SDK_BASE/xtensa-lx106-elf/bin"
# remove old SDK path
rm_path "$SDK_BIN"
export PATH="$SDK_BIN:$PATH"
echo "COMPILE[$COMPILE]"
echo "ROOT_DIR[$ROOT_DIR]"
echo "SDK_BASE[$SDK_BASE]"
echo "SDK_HOME[$SDK_HOME]"
echo "SDK_BIN[$SDK_BIN]"
sep
}
# Creaate a script that set the enviornment and edits the path when run
make_path()
{
set_path
cat <<EOF >"$SDK_BASE/setpath"
#!/bin/bash
#
rm_path()
{
export PATH
export PATH=\$(echo "\$PATH" | sed -e "s,\$1:,,g")
export PATH=\$(echo "\$PATH" | sed -e "s/^://g" | sed -e "s/::/:/g")
}
# if we export SDK_BASE the compiles break - the sdk uses it somewhere
export COMPILE="$COMPILE"
export ROOT_DIR="$ROOT_DIR"
export SDK_BASE="$SDK_HOME"
export SDK_HOME="$SDK_HOME"
export SDK_BIN="$SDK_BIN"
rm_path "\$SDK_BIN"
export PATH="\$SDK_BIN:\$PATH"
EOF
chmod 755 "$SDK_BASE/setpath"
sep
}
#Save a list of libraries we can use in the sdk home directory
list_libs()
{
LIST="sdk/lib xtensa-lx106-elf/xtensa-lx106-elf/sysroot/usr/lib xtensa-lx106-elf/xtensa-lx106-elf/sysroot/lib xtensa-lx106-elf/lib lx106-hal/src"
for i in $LIST
do
if [ -d "$SDK_BASE"/$i ]
then
find "$SDK_BASE"/$i -type f | grep "\.a$"
fi
done
}
install_open_sdk()
{
set_path
echo Installing Open SDK
check_cd $ROOT_DIR
echo Target is $SDK_BASE
declare DIR=$(basename $SDK_BASE)
echo "DIR:[$DIR]"
if [ ! -d "$SDK_BASE" ]
then
# Grab OPEN SDK
git clone --recursive https://github.com/pfalcon/esp-open-sdk.git
# Grab RTOS libraries and examples while we are at it
git clone --recursive https://github.com/Superhouse/esp-open-rtos.git
check_cd $SDK_BASE
git submodule init
git submodule update
# for stand alone
make STANDALONE=y
# Need for RTOS version libs
# make toolchain esptool libhal STANDALONE=n
# Install SDK for all remaining include files and libraries not in the open SDK
# make sdk
popd
fi
check_dir $SDK_BASE/esptool
sep
make_path
popd
}
add_tools()
{
if [ -d "$SDK_HOME"/bin ]
then
cat $SDK_HOME/bin/blank.bin \
$SDK_HOME/bin/blank.bin \
$SDK_HOME/bin/blank.bin >> $SDK_HOME/bin/clear_eep.bin
check_dir $ROOT_DIR
#get_git https://github.com/themadinventor esptool
#cp -p esptool/*.py $SDK_HOME/tools
chmod 755 $SDK_HOME/tools/*
fi
}
# ==============================================================
build_examples()
{
echo Building Exampless
check_cd $SDK_HOME
get_git https://github.com/esp8266 source-code-examples
if [ ! -d source-code-examples/blinky ]
then
echo "source-code-examples missing"
exit 1
fi
check_cd source-code-examples/blinky
sed -i -e "s;^XTENSA_TOOLS_ROOT.*$;XTENSA_TOOLS_ROOT=$SDK_BIN;" Makefile
sed -i -e "s;^SDK_BASE.*$;SDK_BASE=$SDK_HOME/sdk;" Makefile
sed -i -e "s;^EXTRA_INCDIR.*$;EXTRA_INCDIR= $SDK_HOME/include;" Makefile
make clean
make
sep
popd
popd
}
build_nodemcu()
{
echo "Building Nodemcu Firemware"
check_cd "$ROOT_DIR"
get_git https://github.com/nodemcu nodemcu-firmware
check_cd "$ROOT_DIR/nodemcu-firmware"
make
sep
popd
popd
}
flash_nodemcu()
{
echo "Flashinf Nodemcu Firemware"
check_cd "$ROOT_DIR/nodemcu-firmware"
make flash
sep
popd
}
# ===================================================================
update_packages
install_open_sdk
make_path
list_libs >"$SDK_BASE"/libs.txt
add_tools
#build_examples
#build_nodemcu
#flash_nodemcu