-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmicro_build.sh
executable file
·134 lines (106 loc) · 3.06 KB
/
micro_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
#!/bin/bash
# Sep 28, 2021, 00:14:51'
# ------------------------------SPIN CODE-----------------------------------#
function _spinner() {
# $1 start/stop
#
# on start: $2 display message
# on stop : $2 process exit status
# $3 spinner function pid (supplied from stop_spinner)
local on_success="DONE"
local on_fail="FAIL"
local white="\e[1;37m"
local green="\e[1;32m"
local red="\e[1;31m"
local nc="\e[0m"
case $1 in
start)
# calculate the column where spinner and status msg will be displayed
let column=$(tput cols)-${#2}-8
# display message and position the cursor in $column column
echo -ne ${2}
printf "%${column}s"
# start spinner
i=1
sp='\|/-'
delay=${SPINNER_DELAY:-0.15}
while :
do
printf "\b${sp:i++%${#sp}:1}"
sleep $delay
done
;;
stop)
if [[ -z ${3} ]]; then
echo "spinner is not running.."
exit 1
fi
kill $3 > /dev/null 2>&1
# inform the user uppon success or failure
echo -en "\b["
if [[ $2 -eq 0 ]]; then
echo -en "${green}${on_success}${nc}"
else
echo -en "${red}${on_fail}${nc}"
fi
echo -e "]"
;;
*)
echo "invalid argument, try {start/stop}"
exit 1
;;
esac
}
function start_spinner {
# $1 : msg to display
_spinner "start" "${1}" &
# set global spinner pid
_sp_pid=$!
disown
}
function stop_spinner {
# $1 : command exit status
_spinner "stop" $1 $_sp_pid
unset _sp_pid
}
# --------------------------------------------------------------------------#
title="Micropython Firmware Creator "
board="[ESP32]"
red="\e[1;31m"
blue="\e[1;34m"
white2="\e[1;37m"
nc="\e[0m"
clear
echo ""
echo -en " ${red}${title}${blue}${board}${nc}" | sed -e :a -e "s/^.\{1,$(tput cols)\}$/ & /;ta" | tr -d '\n' | head -c $(tput cols)
echo ""
echo ""
echo ""
#
start_spinner "Getting esp-idf export..."
cd esp-idf
source 'export.sh' > /dev/null 2>&1
stop_spinner $?
#
start_spinner "Getting micropython update..."
cd ..
cd micropython
git pull > /dev/null 2>&1
stop_spinner $?
#
start_spinner "Cleaning build space..."
cd ports/esp32
make clean > /dev/null 2>&1
make submodules > /dev/null 2>&1
stop_spinner $?
#
start_spinner "Compiling firmware (slow!) ..."
make > /dev/null 2>&1
# make USER_C_MODULES= ~/st7789_mpy/st7789/micropython.cmake all > /dev/null 2>&1
stop_spinner $?
#
start_spinner "Uploading to board..."
esptool.py -p /dev/ttyUSB0 -b 460800 --before default_reset --after hard_reset --chip esp32 write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x1000 build-GENERIC/bootloader/bootloader.bin 0x8000 build-GENERIC/partition_table/partition-table.bin 0x10000 build-GENERIC/micropython.bin > /dev/null 2>&1
stop_spinner $?
echo ""
echo ""