-
Notifications
You must be signed in to change notification settings - Fork 37
/
update_firmware.sh
executable file
·78 lines (65 loc) · 2.97 KB
/
update_firmware.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
#!/bin/bash
# Copyright (C) 2018 SuperGreenLab <[email protected]>
# Author: Constantin Clauzel <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
. ${0%/*}/build.env
GREEN="\033[0;32m"
NC="\033[0m"
NAME="SuperGreenOSBoilerplate"
SERIAL_PORT=${SERIAL_PORT:-"/dev/ttyUSB1"}
if [ "$#" -eq 1 ]; then
NAME=$1
else
echo "Using default name $NAME, change it as first parameter."
fi
TS=`date +"%s"`
DEST="releases/$NAME/$TS"
mkdir -p $DEST
sed -i -E "s/^#define OTA_BUILD_TIMESTAMP [^$]+/#define OTA_BUILD_TIMESTAMP ${TS}/g" main/core/ota/ota.h
echo -e "Set timestamp in main/core/ota/ota.h to $TS: ${GREEN}Done${NC}"
make -j4
echo -e "Building project: ${GREEN}Done${NC}"
for i in build/ota_data_initial.bin build/bootloader/bootloader.bin build/partitions.bin build/firmware.bin $IDF_PATH/components/esptool_py/esptool/esptool.py
do
cp $i $DEST/
echo -e "Copying $i to $DEST/$i: ${GREEN}Done${NC}"
done
echo $TS > "releases/$NAME/last_timestamp"
echo $TS > "$DEST/timestamp"
echo "#!/bin/bash" > $DEST/flash.sh
echo 'DIR=`dirname "$0"`' >> $DEST/flash.sh
echo 'DIR=`( cd "$DIR" && pwd )`' >> $DEST/flash.sh
echo 'python2 $DIR/esptool.py --chip esp32 --port ${SERIAL_PORT} --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0xd000 $DIR/ota_data_initial.bin 0x1000 $DIR/bootloader.bin 0x10000 $DIR/firmware.bin 0x8000 $DIR/partitions.bin' >> $DEST/flash.sh
chmod +x $DEST/flash.sh
echo -e "Created $DEST/flash.sh: ${GREEN}Done${NC}"
# TODO DRY with ./write_spiffs.sh
echo -e "Creating spiffs.bin partition:"
mkdir spiffs_fs_gz
for i in $(ls ./spiffs_fs); do
gzip -c "./spiffs_fs/$i" >> "./spiffs_fs_gz/$i"
echo -e "Created spiffs_fs_gq/$i: ${GREEN}Done${NC}"
done
mkspiffs -c spiffs_fs_gz/ -b 4096 -p 256 -s 0x8000 $DEST/spiffs.bin
cp -r spiffs_fs_gz $DEST/html_app
rm -rf spiffs_fs_gz
echo -e "Created $DEST/spiffs.bin: ${GREEN}Done${NC}"
echo "#!/bin/bash" > $DEST/write_spiffs.sh
echo 'DIR=`dirname "$0"`' >> $DEST/write_spiffs.sh
echo 'DIR=`( cd "$DIR" && pwd )`' >> $DEST/write_spiffs.sh
echo 'python $DIR/esptool.py --chip esp32 --port ${SERIAL_PORT} --baud 921600 write_flash -z 0x3f0000 spiffs.bin' >> $DEST/write_spiffs.sh
chmod +x $DEST/write_spiffs.sh
echo -e "Created $DEST/write_spiffs.sh: ${GREEN}Done${NC}"
sed -i -E "s/^#define OTA_BUILD_TIMESTAMP [^$]+/#define OTA_BUILD_TIMESTAMP 0/g" main/core/ota/ota.h