From 4ae00fa04596c8edaef8a1fad4178037199643a7 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Thu, 14 May 2015 00:31:44 -0700 Subject: [PATCH] rewrote flash handlers --- Makefile | 6 +- ...junge-katze-iv.jpg => junge-katze-iv.jpg-} | Bin html/cats/junge-katze-iv_01.jpg | Bin 0 -> 11340 bytes html/index.tpl | 2 +- include/esp8266.h | 1 + user/cgiflash.c | 78 +++++++++++++++--- user/cgiflash.h | 6 +- user/user_main.c | 6 +- 8 files changed, 78 insertions(+), 21 deletions(-) rename html/cats/{junge-katze-iv.jpg => junge-katze-iv.jpg-} (100%) create mode 100644 html/cats/junge-katze-iv_01.jpg diff --git a/Makefile b/Makefile index f060dd9..6610c2e 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,7 @@ LIBS = c gcc hal phy pp net80211 wpa main lwip # compiler flags using during compilation of source files CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -D_STDINT_H \ - -Wno-address -DESPFS_POS=$(ESPFS_POS) -DESPFS_SIZE=$(ESPFS_SIZE) + -Wno-address -DFIRMWARE_SIZE=$(ESP_FLASH_MAX) # linker flags used to generate the main object file LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static @@ -235,11 +235,11 @@ build/eagle.esphttpd.v6.ld: $(SDK_LDDIR)/eagle.app.v6.ld $(SDK_LDDIR)/eagle.app.v6.ld >$@ 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/32000/' \ + -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/32000/' \ + -e '/^ irom0_0_seg/ s/2B000/38000/' \ $(SDK_LDDIR)/eagle.app.v6.new.512.app2.ld >$@ blankflash: diff --git a/html/cats/junge-katze-iv.jpg b/html/cats/junge-katze-iv.jpg- similarity index 100% rename from html/cats/junge-katze-iv.jpg rename to html/cats/junge-katze-iv.jpg- diff --git a/html/cats/junge-katze-iv_01.jpg b/html/cats/junge-katze-iv_01.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0b2944ed3fe5316eba155ca79790b7ca578209a8 GIT binary patch literal 11340 zcmbVyd0bQ1+U`yufRP~RjzUDs7?LPRAYl|6hG-JT>;OWaqg{nQE20@KN7^;XCK~bDq6>4pJj^7U2bH4B1`^UXE{8skL&dy%@eb-v= z^SsZ?hdUp}0c*}$_F4diMgc735BTs9^#wCekPZNBHU+Q%0HiHMnE)uHXKVx%X70Eh z=`a1%--Yx^pRPe8eJTnK;E>~fq7cGd3&PDKK4<_7+;s0 z0}yil52OLoPuEaAJyFt+?>;=Xe*QG>h^up{;orJ=fSfV&yJn>@Zn#R9|j&j zdx&x)lYKmWwgd)ld06#L)x-bi*M}~^#sYN;oneA|z(%L)X_vljbb? zzcZ-l|I4C(8}x5`KHN91_Yb3hr3ng|HWM4*bD#<)HQ8z*s2{}yW9C{oJDh<5x&K?6 z&vXR=F7s1cn<+)Zr2nPy*nj^@0+8f-cL3xvKQ@Sf0o+0H#}Ph_g#P%U7HfJ0-ql`z?j-r2*ej$qDVHU=C?2?a`6V9v^^< zl(@R3mtvejajw>lvnnmdGYIFNZl2OVbTnu3N1=GY>gdxiWlio+)EdK%?Y}oc5&Fxl zDwq-cR3Iovo)kSd+^1m|m%}7L_OYP^-hZ2o9C^#&Qh1+P!HRv-cV2kZR*p&O?gk8oKN}V zuE&}*iH5d6>EPa&iT<_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elh)tnY#fICv9*L+pGFfyKktb}PpDM}6hfE?BwCEQYxrpKI^oSWt+r%N*eqBm zh7g2&mW7s(CtJhmMfi9HHxm3qf9^EdK_RQoH;}Rs-Bm6$y|Y*@t5V<2;zrB)JeKyL zOvKZGBJqnDa!=tgCzuzB@FGMUNkIfzYhx|PQ)*8j$x#*I5)OGRN$oeIcrVa$vlDiM zhbq_{ZIZisoSZ2uDv`vHaeheJ?+TVU%EX2k2kAht62PsFO|3_Y%Dt?uaHgiw#7RQT zcbdJhu#xUh2Sef99j6brJqeFrP1qTtR4gNP_#I`3Grde{m!*T#%0gV1Tt}8GQE(K- znQ-KY9Nl+(=%^!DROCmq6h#FIF30R0;axEIBg*5~Xs-&*muoLH`zM|oX}QW?Edkm_ X#Ms~{(1IJzbVSqyL|p#n!`=S^%bH+w literal 0 HcmV?d00001 diff --git a/html/index.tpl b/html/index.tpl index 2f9b18e..50c49cc 100644 --- a/html/index.tpl +++ b/html/index.tpl @@ -18,7 +18,7 @@ been loaded %counter% times.

And because we're on the Internets now, here are the required pictures of cats:
-
+

diff --git a/include/esp8266.h b/include/esp8266.h index 69e6c8a..ce92455 100644 --- a/include/esp8266.h +++ b/include/esp8266.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "espmissingincludes.h" diff --git a/user/cgiflash.c b/user/cgiflash.c index db82e06..f5917a3 100644 --- a/user/cgiflash.c +++ b/user/cgiflash.c @@ -39,37 +39,89 @@ int ICACHE_FLASH_ATTR cgiReadFlash(HttpdConnData *connData) { if (*pos>=0x40200000+(512*1024)) return HTTPD_CGI_DONE; else return HTTPD_CGI_MORE; } -//Cgi that allows the ESPFS image to be replaced via http POST -int ICACHE_FLASH_ATTR cgiUploadEspfs(HttpdConnData *connData) { +// Return which firmware needs to be uploaded next +int ICACHE_FLASH_ATTR cgiGetFirmwareNext(HttpdConnData *connData) { if (connData->conn==NULL) { //Connection aborted. Clean up. return HTTPD_CGI_DONE; } - /* TODO: fix this check so it calculates the end of the irom segment minus the start of the espfs - if(connData->post->len > ESPFS_SIZE){ + + uint8 id = system_upgrade_userbin_check(); + httpdStartResponse(connData, 200); + httpdHeader(connData, "Content-Type", "text/plain"); + httpdEndHeaders(connData); + httpdSend(connData, (id == 1 ? "user1.bin" : "user2.bin"), -1); + os_printf("Next firmware: user%d.bin\n", 1-id); + + return HTTPD_CGI_DONE; +} + +//Cgi that allows the firmware to be replaced via http POST +int ICACHE_FLASH_ATTR cgiUploadFirmware(HttpdConnData *connData) { + if (connData->conn==NULL) { + //Connection aborted. Clean up. + return HTTPD_CGI_DONE; + } + + if(connData->post->len > FIRMWARE_SIZE){ // The uploaded file is too large - os_printf("ESPFS file too large\n"); - httpdSend(connData, "HTTP/1.0 500 Internal Server Error\r\nServer: esp8266-httpd/0.3\r\nConnection: close\r\nContent-Type: text/plain\r\nContent-Length: 24\r\n\r\nESPFS image loo large.\r\n", -1); + os_printf("Firmware image too large\n"); + httpdStartResponse(connData, 400); + httpdHeader(connData, "Content-Type", "text/plain"); + httpdEndHeaders(connData); + httpdSend(connData, "Firmware image loo large.\r\n", -1); return HTTPD_CGI_DONE; } - */ - // The source should be 4byte aligned, so go ahead and flash whatever we have - int address = ESPFS_POS + connData->post->received - connData->post->buffLen; + uint8 id = system_upgrade_userbin_check(); + + int address; + if (id == 1) { + address = 4*1024; // start after 4KB boot partition + } else { + // 4KB boot, firmware1, 16KB user param, 4KB reserved + address = 4*1024 + FIRMWARE_SIZE + 16*1024 + 4*1024; + } + address += connData->post->received - connData->post->buffLen; + if(address % SPI_FLASH_SEC_SIZE == 0){ // We need to erase this block - os_printf("Erasing flash at %d\n", address/SPI_FLASH_SEC_SIZE); + os_printf("Erasing flash at 0x%05x (id=%d)\n", address, 2-id); spi_flash_erase_sector(address/SPI_FLASH_SEC_SIZE); } + // Write the data - os_printf("Writing at: 0x%x\n", address); + os_printf("Writing %d bytes at 0x%05x (%d of %d)\n", connData->post->buffSize, address, + connData->post->received, connData->post->len); spi_flash_write(address, (uint32 *)connData->post->buff, connData->post->buffLen); - os_printf("Wrote %d bytes (%dB of %d)\n", connData->post->buffSize, connData->post->received, connData->post->len);//&connData->postBuff)); if (connData->post->received == connData->post->len){ - httpdSend(connData, "Finished uploading", -1); + // TODO: verify the firmware (is there a checksum or something???) + httpdStartResponse(connData, 200); + httpdEndHeaders(connData); return HTTPD_CGI_DONE; } else { return HTTPD_CGI_MORE; } } + +// Handle request to reboot into the new firmware +int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) { + if (connData->conn==NULL) { + //Connection aborted. Clean up. + return HTTPD_CGI_DONE; + } + + // TODO: sanity-check that the 'next' partition actually contains something that looks like + // valid firmware + + // This hsould probably be forked into a separate task that waits a second to let the + // current HTTP request finish... + system_upgrade_flag_set(UPGRADE_FLAG_FINISH); + system_upgrade_reboot(); + httpdStartResponse(connData, 200); + httpdEndHeaders(connData); + return HTTPD_CGI_DONE; +} + + diff --git a/user/cgiflash.h b/user/cgiflash.h index 268a62f..15c60c2 100644 --- a/user/cgiflash.h +++ b/user/cgiflash.h @@ -4,6 +4,8 @@ #include "httpd.h" int cgiReadFlash(HttpdConnData *connData); -int cgiUploadEspfs(HttpdConnData *connData); +int cgiGetFirmwareNext(HttpdConnData *connData); +int cgiUploadFirmware(HttpdConnData *connData); +int cgiRebootFirmware(HttpdConnData *connData); -#endif \ No newline at end of file +#endif diff --git a/user/user_main.c b/user/user_main.c index c5a0aad..58ff4dd 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -53,11 +53,13 @@ should be placed above the URLs they protect. */ HttpdBuiltInUrl builtInUrls[]={ {"/", cgiRedirect, "/index.tpl"}, - {"/flash.bin", cgiReadFlash, NULL}, + {"/flash/download", cgiReadFlash, NULL}, + {"/flash/next", cgiGetFirmwareNext, NULL}, + {"/flash/upload", cgiUploadFirmware, NULL}, + {"/flash/reboot", cgiRebootFirmware, NULL}, {"/led.tpl", cgiEspFsTemplate, tplLed}, {"/index.tpl", cgiEspFsTemplate, tplCounter}, {"/led.cgi", cgiLed, NULL}, - {"/updateweb.cgi", cgiUploadEspfs, NULL}, //Routines to make the /wifi URL and everything beneath it work.