Added feature to do upgrade on webpage

pull/30/head
Jeroen Domburg 8 years ago
parent 9b215ea547
commit 41181e1cc7
  1. 6
      Makefile
  2. 23
      Makefile.ota
  3. 2
      html/flash/140medley.min.js
  4. 75
      html/flash/index.html
  5. 34
      html/flash/style.css
  6. 2
      libesphttpd
  7. 1
      user/user_main.c

@ -3,12 +3,12 @@
# 'combined' - Combined firmware blob, no OTA upgrade
# 'ota' - Combined firmware blob with OTA upgrades.
#Please do a 'make clean' after changing this.
OUTPUT_TYPE=separate
#OUTPUT_TYPE=separate
#OUTPUT_TYPE=combined
#OUTPUT_TYPE=ota
OUTPUT_TYPE=ota
#SPI flash size, in K
ESP_SPI_FLASH_SIZE_K=512
ESP_SPI_FLASH_SIZE_K=1024
#0: QIO, 1: QOUT, 2: DIO, 3: DOUT
ESP_FLASH_MODE=0
#0: 40MHz, 1: 26MHz, 2: 20MHz, 0xf: 80MHz

@ -1,6 +1,9 @@
#Makefile with the options specific to the build of a non-upgradable firmware with
#the espfs combined into the flash binary.
# Change tagname to some identifier that's unique for your project. 27 chars max.
TAGNAME ?= "generic"
# linker script used for the linker step
LD_MAP_1:=512:eagle.app.v6.new.512.app1.ld 1024:eagle.app.v6.new.1024.app1.ld 2048:eagle.app.v6.new.2048.ld 4096:eagle.app.v6.new.2048.ld
@ -15,6 +18,8 @@ TARGET_OUT := $(TARGET_OUT_USR1) $(TARGET_OUT_USR2)
TARGET_BIN_USR1 := $(addprefix $(BUILD_BASE)/,$(TARGET).user1.bin)
TARGET_BIN_USR2 := $(addprefix $(BUILD_BASE)/,$(TARGET).user2.bin)
TARGET_BIN := $(TARGET_BIN_USR1) $(TARGET_BIN_USR2)
TARGET_OTAFILE := $(addprefix $(BUILD_BASE)/,$(TARGET).ota)
BLANKPOS="$$(printf "0x%X" $$(($(ESP_SPI_FLASH_SIZE_K)*512-0x2000)))"
INITDATAPOS="$$(printf "0x%X" $$(($(ESP_SPI_FLASH_SIZE_K)*512-0x4000)))"
@ -23,6 +28,8 @@ INITDATAPOS="$$(printf "0x%X" $$(($(ESP_SPI_FLASH_SIZE_K)*512-0x4000)))"
FLASH_MAP_CONV:=0:512 2:1024 5:2048 6:4096
ESP_FLASH_SIZE_IX:=$(maplookup $(ESP_SPI_FLASH_SIZE_K),,$(FLASH_MAP_CONV))
CFLAGS += -DOTA_TAGNAME=\"$(TAGNAME)\"
define genappbin
$(1): $$(APP_AR)
$$(vecho) LD $$@
@ -70,21 +77,15 @@ ldscript_memspecific.ld:
#user1.bin:
# $(call makeuser,user1.bin,1)
libesphttpd/mkupgimg/mkupgimg: libesphttpd/mkupgimg/
make -C libesphttpd/mkupgimg/
$(FW_BASE): $(TARGET_BIN)
# $(vecho) "FW $@"
# $(Q) mkdir -p $@
# $(Q) $(ESPTOOL) elf2image $(TARGET_OUT) --output $@/
$(FW_BASE): $(TARGET_BIN) libesphttpd/mkupgimg/mkupgimg
$(Q) libesphttpd/mkupgimg/mkupgimg $(TARGET_BIN_USR1) $(TARGET_BIN_USR2) $(TAGNAME) $(TARGET_OTAFILE)
flash: $(TARGET_OUT) $(FW_BASE)
$(Q) $(ESPTOOL) $(ESPTOOL_OPTS) write_flash $(ESPTOOL_FLASHDEF) 0x00000 "$(SDK_BASE)/bin/boot_v1.4(b1).bin" 0x1000 $(TARGET_BIN_USR1)
# $(Q) $(ESPTOOL) $(ESPTOOL_OPTS) write_flash $(ESPTOOL_FLASHDEF) 0x00000 $(FW_BASE)/0x00000.bin 0x40000 $(FW_BASE)/0x40000.bin
$(Q) $(ESPTOOL) $(ESPTOOL_OPTS) write_flash $(ESPTOOL_FLASHDEF) 0x00000 "$(SDK_BASE)/bin/boot_v1.5.bin" 0x1000 $(TARGET_BIN_USR1)
blankflash:
$(Q) $(ESPTOOL) $(ESPTOOL_OPTS) write_flash $(ESPTOOL_FLASHDEF) $(BLANKPOS) $(SDK_BASE)/bin/blank.bin $(INITDATAPOS) $(SDK_BASE)/bin/esp_init_data_default.bin
htmlflash: libesphttpd
$(Q) if [ $$(stat -c '%s' libesphttpd/webpages.espfs) -gt $$(( $(ESPFS_SIZE) )) ]; then echo "webpages.espfs too big!"; false; fi
$(Q) $(ESPTOOL) $(ESPTOOL_OPTS) write_flash $(ESPTOOL_FLASHDEF) $(ESPFS_POS) libesphttpd/webpages.espfs

@ -0,0 +1,2 @@
var t=function(a,b){return function(c,d){return a.replace(/#{([^}]*)}/g,function(a,f){return Function("x","with(x)return "+f).call(c,d||b||{})})}},s=function(a,b){return b?{get:function(c){return a[c]&&b.parse(a[c])},set:function(c,d){a[c]=b.stringify(d)}}:{}}(this.localStorage||{},JSON),p=function(a,b,c,d){c=c||document;d=c[b="on"+b];a=c[b]=function(e){d=d&&d(e=e||c.event);return(a=a&&b(e))?b:d};c=this},m=function(a,b,c){b=document;c=b.createElement("p");c.innerHTML=a;for(a=b.createDocumentFragment();b=
c.firstChild;)a.appendChild(b);return a},$=function(a,b){a=a.match(/^(\W)?(.*)/);return(b||document)["getElement"+(a[1]?a[1]=="#"?"ById":"sByClassName":"sByTagName")](a[2])},j=function(a){for(a=0;a<4;a++)try{return a?new ActiveXObject([,"Msxml2","Msxml3","Microsoft"][a]+".XMLHTTP"):new XMLHttpRequest}catch(b){}};

@ -0,0 +1,75 @@
<html>
<head><title>Upgrade firmware</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="140medley.min.js"></script>
<script type="text/javascript">
var xhr=j();
function doReboot() {
xhr.open("GET", "reboot");
xhr.onreadystatechange=function() {
if (xhr.readyState==4 && xhr.status>=200 && xhr.status<300) {
window.setTimeout(function() {
location.reload(true);
}, 3000);
}
}
//ToDo: set timer to
xhr.send();
}
function setProgress(amt) {
$("#progressbarinner").style.width=String(amt*200)+"px";
}
function doUpgrade() {
var f=$("#file").files[0];
if (typeof f=='undefined') {
$("#remark").innerHTML="Can't read file!";
return
}
xhr.open("POST", "upload");
xhr.onreadystatechange=function() {
if (xhr.readyState==4 && xhr.status>=200 && xhr.status<300) {
setProgress(1);
if (xhr.responseText!="") {
$("#remark").innerHTML="Error: "+xhr.responseText;
} else {
$("#remark").innerHTML="Uploading done. Rebooting.";
doReboot();
}
}
}
if (typeof xhr.upload.onprogress != 'undefined') {
xhr.upload.onprogress=function(e) {
setProgress(e.loaded / e.total);
}
}
xhr.send(f);
return false;
}
window.onload=function(e) {
xhr.open("GET", "next");
xhr.onreadystatechange=function() {
if (xhr.readyState==4 && xhr.status>=200 && xhr.status<300) {
var txt="Please upload "+xhr.responseText+" or ota file.";
$("#remark").innerHTML=txt;
setProgress(0);
}
}
xhr.send();
}
</script>
</head>
<body>
<div id="main">
<h1>Update firmware</h1>
<div id="remark">Loading...</div>
<input type="file" id="file" />
<input type="submit" value="Upgrade!" onclick="doUpgrade()" />
<div id="progressbar"><div id="progressbarinner"></div></div>
</body>

@ -0,0 +1,34 @@
body {
background-color: #404040;
font-family: sans-serif;
}
#main {
background-color: #d0d0FF;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
border: 2px solid #000000;
width: 800px;
margin: 0 auto;
padding: 20px
}
#progressbar {
margin: 10px;
padding: 0;
border: 1px solid #000000;
height: 20px;
width: 200px;
background-color: #808080;
}
#progressbarinner {
width: 10px;
height: 20px;
border: none;
background-color: #00ff00;
}

@ -1 +1 @@
Subproject commit a38909a9559c5f1562d2933213e4ec6301ef99c3
Subproject commit cbed5b369459649401dea5e6a3be9700c9af4ef1

@ -102,6 +102,7 @@ CgiUploadFlashDef uploadParams={
.fw1Pos=0x1000,
.fw2Pos=((OTA_FLASH_SIZE_K*1024)/2)+0x1000,
.fwSize=((OTA_FLASH_SIZE_K*1024)/2)-0x1000,
.tagName=OTA_TAGNAME
};
#define INCLUDE_FLASH_FNS
#endif

Loading…
Cancel
Save