Upload ESP FS image after flashing and reboot

pull/112/head
Timo Wischer 9 years ago
parent e7678550df
commit 9ecfb2a0a5
  1. 20
      Makefile
  2. 2
      esp-link/cgiflash.c
  3. 2
      esp-link/main.c
  4. 73
      wiflash

@ -395,9 +395,14 @@ checkdirs: $(BUILD_DIR)
$(BUILD_DIR):
$(Q) mkdir -p $@
ifeq ("$(USE_OTHER_PARTITION_FOR_ESPFS)","yes")
wiflash: all
./wiflash $(ESP_HOSTNAME) $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin build/espfs.img
else
wiflash: all
./wiflash $(ESP_HOSTNAME) $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin
endif
baseflash: all
$(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(ET_PART1) $(FW_BASE)/user1.bin
@ -480,6 +485,18 @@ endif
# edit the loader script to add the espfs section to the end of irom with a 4 byte alignment.
# we also adjust the sizes of the segments 'cause we need more irom0
# in the end the only thing that matters wrt size is that the whole shebang fits into the
# 236KB available (in a 512KB flash)
ifeq ("$(FLASH_SIZE)","512KB")
build/eagle.esphttpd1.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.512.app1.ld
$(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \
-e '/^ irom0_0_seg/ s/2B000/38000/' \
$(SDK_LDDIR)/eagle.app.v6.new.512.app1.ld >$@
build/eagle.esphttpd2.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.512.app2.ld
$(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \
-e '/^ irom0_0_seg/ s/2B000/38000/' \
$(SDK_LDDIR)/eagle.app.v6.new.512.app2.ld >$@
else
build/eagle.esphttpd1.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.1024.app1.ld
$(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \
-e '/^ irom0_0_seg/ s/6B000/7C000/' \
@ -488,6 +505,7 @@ build/eagle.esphttpd2.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.1024.app2.ld
$(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \
-e '/^ irom0_0_seg/ s/6B000/7C000/' \
$(SDK_LDDIR)/eagle.app.v6.new.1024.app2.ld >$@
endif
espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/
$(Q) $(MAKE) -C espfs/mkespfsimage GZIP_COMPRESSION="$(GZIP_COMPRESSION)"

@ -45,7 +45,7 @@ static char* ICACHE_FLASH_ATTR check_header(void *buf) {
// check whether the flash map/size we have allows for OTA upgrade
static bool canOTA(void) {
enum flash_size_map map = system_get_flash_size_map();
return map >= FLASH_SIZE_8M_MAP_512_512;
return map >= FLASH_SIZE_4M_MAP_256_256;
}
static char *flash_too_small = "Flash too small for OTA update";

@ -69,6 +69,7 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/flash/next", cgiGetFirmwareNext, NULL },
{ "/flash/upload", cgiUploadFirmware, NULL },
{ "/flash/reboot", cgiRebootFirmware, NULL },
{ "/log/reset", cgiReset, NULL },
#ifdef CGI_ADVANCED
{ "/pgm/sync", cgiOptibootSync, NULL },
{ "/pgm/upload", cgiOptibootData, NULL },
@ -81,7 +82,6 @@ HttpdBuiltInUrl builtInUrls[] = {
#ifdef LOG
{ "/log/text", ajaxLog, NULL },
{ "/log/dbg", ajaxLogDbg, NULL },
{ "/log/reset", cgiReset, NULL },
#endif
#ifdef CONSOLE
{ "/console/reset", ajaxConsoleReset, NULL },

@ -13,7 +13,7 @@
show_help() {
cat <<EOT
Usage: ${0##*/} [-options...] hostname user1.bin user2.bin
Usage: ${0##*/} [-options...] hostname user1.bin user2.bin [espfs.img]
Flash the esp8266 running esphttpd at <hostname> with either <user1.bin> or <user2.bin>
depending on its current state. Reboot the esp8266 after flashing and wait for it to come
up again.
@ -25,6 +25,30 @@ Example: ${0##*/} -v esp8266 firmware/user1.bin firmware/user2.bin
EOT
}
check_response() {
sleep 2
echo "Waiting for ESP8266 to come back"
while true; do
[[ -n "$verbose" ]] && echo "Fetching http://$hostname/flash/next" >&2
next2=`curl -m 10 $v -s "http://$hostname/flash/next"`
[[ -n "$verbose" ]] && echo "got: $next2"
re='user[12]\.bin'
if [[ "$next2" =~ $re ]]; then
if [[ "$next2" != "$next" ]]; then
sec=$(( `date +%s` - $start ))
echo "Success, took $sec seconds" >&2
break
else
echo "Flashing seems to have failed and it reverted to the old firmware?" >&2
exit 1
fi
fi
sleep 1
done
}
if ! which curl >/dev/null; then
echo "ERROR: Cannot find curl: it is required for this script." >&2
exit 1
@ -49,13 +73,15 @@ done
shift "$((OPTIND-1))"
# Get the fixed arguments
if [[ $# != 3 ]]; then
# only 3 or 4 are accepted
if [[ $# < 3 || $# > 4 ]]; then
show_help >&2
exit 1
fi
hostname=$1
user1=$2
user2=$3
espfs=$4
re='[-A-Za-z0-9.]+'
if [[ ! "$hostname" =~ $re ]]; then
@ -112,22 +138,29 @@ sleep 2
echo "Rebooting into new firmware" >&2
curl -m 10 -s "http://$hostname/flash/reboot"
check_response
# everything is done, if no ESP FS image file was spezified
if [ ! "$espfs" ]; then
exit 0
fi
if [[ ! -r "$espfs" ]]; then
echo "ERROR: cannot read ESP FS image file ($espfs)" >&2
exit 1
fi
echo "Uploading ESP FS image" >&2
res=`curl $silent -XPOST --data-binary "@$espfs" "http://$hostname/flash/upload"`
if [[ $? != 0 ]]; then
echo "Error uploading $espfs" >&2
exit 1
fi
sleep 2
echo "Waiting for ESP8266 to come back"
while true; do
[[ -n "$verbose" ]] && echo "Fetching http://$hostname/flash/next" >&2
next2=`curl -m 10 $v -s "http://$hostname/flash/next"`
[[ -n "$verbose" ]] && echo "got: $next2"
re='user[12]\.bin'
if [[ "$next2" =~ $re ]]; then
if [[ "$next2" != "$next" ]]; then
sec=$(( `date +%s` - $start ))
echo "Success, took $sec seconds" >&2
exit 0
else
echo "Flashing seems to have failed and it reverted to the old firmware?" >&2
exit 1
fi
fi
sleep 1
done
echo "Reseting to load new ESP FS image" >&2
curl -m 10 -s "http://$hostname/log/reset"
check_response

Loading…
Cancel
Save