From 5a85dae22a6bf1483ac01574598fc9ce256d1d8d Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Tue, 12 May 2015 22:11:07 -0700 Subject: [PATCH] moved espfs at end of irom0 resulting in single flash chunk --- Makefile | 41 ++++++++++-------- ...cross-eyed-cat.jpg => cross-eyed-cat.jpg-} | Bin ...en-loves-toy.jpg => kitten-loves-toy.jpg-} | Bin html/index.tpl | 4 +- user/cgiflash.c | 10 +++-- user/user_main.c | 9 +++- 6 files changed, 39 insertions(+), 25 deletions(-) rename html/cats/{cross-eyed-cat.jpg => cross-eyed-cat.jpg-} (100%) rename html/cats/{kitten-loves-toy.jpg => kitten-loves-toy.jpg-} (100%) diff --git a/Makefile b/Makefile index 7b591ff..9e88b41 100644 --- a/Makefile +++ b/Makefile @@ -27,10 +27,6 @@ YUI-COMPRESSOR ?= /usr/bin/yui-compressor #any support in the browser. USE_HEATSHRINK ?= yes -#Position and maximum length of espfs in flash memory -ESPFS_POS = 0x12000 -ESPFS_SIZE = 0x2E000 - # -------------- End of esphttpd config options ------------- @@ -80,7 +76,7 @@ CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno- LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static # linker script used for the above linkier step -LD_SCRIPT = eagle.app.v6.ld +LD_SCRIPT := eagle.esphttpd.v6.ld # various paths from the SDK used in this project SDK_LIBDIR = lib @@ -91,6 +87,8 @@ SDK_INCDIR = include include/json CC := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc AR := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-ar LD := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc +OBJCP := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objcopy +OBJDP := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objdump #### @@ -100,15 +98,17 @@ SRC_DIR := $(MODULES) BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES)) SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR)) +SDK_LDDIR := $(addprefix $(SDK_BASE)/,$(SDK_LDDIR)) SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR)) SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c)) -OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) +OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) $(BUILD_BASE)/espfs_img.o LIBS := $(addprefix -l,$(LIBS)) APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a) TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out) -LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT)) +#LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT)) +LD_SCRIPT := -Tbuild/$(LD_SCRIPT) INCDIR := $(addprefix -I,$(SRC_DIR)) EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) @@ -143,9 +143,10 @@ endef all: checkdirs $(TARGET_OUT) $(FW_BASE) -$(TARGET_OUT): $(APP_AR) +$(TARGET_OUT): $(APP_AR) build/eagle.esphttpd.v6.ld $(vecho) "LD $@" $(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@ + $(Q) $(OBJDP) -x $(TARGET_OUT) | egrep espfs_img $(FW_BASE): $(TARGET_OUT) $(vecho) "FW $@" @@ -165,7 +166,7 @@ $(BUILD_DIR): flash: $(TARGET_OUT) $(FW_BASE) $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash 0x00000 $(FW_BASE)/0x00000.bin 0x40000 $(FW_BASE)/0x40000.bin -webpages.espfs: html/ html/wifi/ espfs/mkespfsimage/mkespfsimage +$(BUILD_BASE)/espfs_img.o: html/ html/wifi/ espfs/mkespfsimage/mkespfsimage ifeq ("$(COMPRESS_W_YUI)","yes") $(Q) rm -rf html_compressed; $(Q) cp -r html html_compressed; @@ -173,13 +174,21 @@ ifeq ("$(COMPRESS_W_YUI)","yes") $(Q) for file in `find html_compressed -type f -name "*.js"`; do $(YUI-COMPRESSOR) --type js $$file -o $$file; done $(Q) for file in `find html_compressed -type f -name "*.css"`; do $(YUI-COMPRESSOR) --type css $$file -o $$file; done $(Q) awk "BEGIN {printf \"YUI compression ratio was: %.2f%%\\n\", (`du -b -s html_compressed/ | sed 's/\([0-9]*\).*/\1/'`/`du -b -s html/ | sed 's/\([0-9]*\).*/\1/'`)*100}" - -# mkespfsimage will compress html, css and js files with gzip by default if enabled -# override with -g cmdline parameter - $(Q) cd html_compressed; find | ../espfs/mkespfsimage/mkespfsimage > ../webpages.espfs; cd ..; + # mkespfsimage will compress html, css and js files with gzip by default if enabled + # override with -g cmdline parameter + $(Q) cd html_compressed; find | ../espfs/mkespfsimage/mkespfsimage > ../build/espfs.img; cd ..; else - $(Q) cd html; find | ../espfs/mkespfsimage/mkespfsimage > ../webpages.espfs; cd .. + $(Q) cd html; find . \! -name \*- | ../espfs/mkespfsimage/mkespfsimage > ../build/espfs.img; cd .. endif + $(Q) cd build; $(OBJCP) -I binary -O elf32-xtensa-le -B xtensa --rename-section .data=.espfs \ + espfs.img espfs_img.o; cd .. + +# edit the loader script to add the espfs section to the end of irom with a 4KB alignment to +# allow the section to be reflashed at runtime, if you run tight in space you could change the +# alignment to 4 and forego the reflash capability +build/eagle.esphttpd.v6.ld: $(SDK_LDDIR)/eagle.app.v6.ld + sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4096);' -e 'a *(.espfs)' -e '}' \ + $(SDK_LDDIR)/eagle.app.v6.ld >$@ blankflash: $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash 0x7E000 $(SDK_BASE)/bin/blank.bin @@ -187,10 +196,6 @@ blankflash: espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/ $(Q) $(MAKE) -C espfs/mkespfsimage USE_HEATSHRINK="$(USE_HEATSHRINK)" GZIP_COMPRESSION="$(GZIP_COMPRESSION)" -htmlflash: webpages.espfs - $(Q) if [ $$(stat -c '%s' webpages.espfs) -gt $$(( $(ESPFS_SIZE) )) ]; then echo "webpages.espfs too big!"; false; fi - $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash $(ESPFS_POS) webpages.espfs - clean: $(Q) rm -f $(APP_AR) $(Q) rm -f $(TARGET_OUT) diff --git a/html/cats/cross-eyed-cat.jpg b/html/cats/cross-eyed-cat.jpg- similarity index 100% rename from html/cats/cross-eyed-cat.jpg rename to html/cats/cross-eyed-cat.jpg- diff --git a/html/cats/kitten-loves-toy.jpg b/html/cats/kitten-loves-toy.jpg- similarity index 100% rename from html/cats/kitten-loves-toy.jpg rename to html/cats/kitten-loves-toy.jpg- diff --git a/html/index.tpl b/html/index.tpl index 4310cb3..2f9b18e 100644 --- a/html/index.tpl +++ b/html/index.tpl @@ -17,9 +17,9 @@ been loaded %counter% times.

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

diff --git a/user/cgiflash.c b/user/cgiflash.c index 7243dbd..db82e06 100644 --- a/user/cgiflash.c +++ b/user/cgiflash.c @@ -5,9 +5,9 @@ Some flash handling cgi routines. Used for reading the existing flash and updati /* * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): - * Jeroen Domburg wrote this file. As long as you retain - * this notice you can do whatever you want with this stuff. If we meet some day, - * and you think this stuff is worth it, you can buy me a beer in return. + * Jeroen Domburg wrote this file. As long as you retain + * this notice you can do whatever you want with this stuff. If we meet some day, + * and you think this stuff is worth it, you can buy me a beer in return. * ---------------------------------------------------------------------------- */ @@ -45,13 +45,15 @@ int ICACHE_FLASH_ATTR cgiUploadEspfs(HttpdConnData *connData) { //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){ // 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); 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; if(address % SPI_FLASH_SEC_SIZE == 0){ diff --git a/user/user_main.c b/user/user_main.c index 66b0da6..c5a0aad 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -85,14 +85,21 @@ static void ICACHE_FLASH_ATTR prHeapTimerCb(void *arg) { } #endif +// address of espfs binary blob +extern uint8_t _binary_espfs_img_start; + //Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. void user_init(void) { stdoutInit(); ioInit(); + os_delay_us(10000L); + os_printf("\n\nInitializing esphttpd\n"); // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. - espFsInit((void*)(0x40200000 + ESPFS_POS)); + //EspFsInitResult res = espFsInit((void*)(0x40200000 + ESPFS_POS)); + EspFsInitResult res = espFsInit(&_binary_espfs_img_start); + os_printf("espFsInit(0x%08lx) returned %d\n", (uint32_t)&_binary_espfs_img_start, res); httpdInit(builtInUrls, 80); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer);