What I'm trying to do is:
- - create a user1.bin and user2.bin as defined by espressif to allow the std boot_v1.2 from espressif to be used to switch between two 256KB images
- each image contains the code and the espfs
- optionally the espfs in each image is located at the end of the image and 4KB aligned so it can be updated in-place to allow for rapid dev&test of web pages
- add an http cgi to allow user1.bin or user2.bin to be uploaded followed by a reboot into the new version using the relatively new SDK OTA functions
I successfully managed to add the espfs data to the end of the irom0 text segment such that there is a single chunk to flash. The way I did it is as follows.
In the Makefile I create an elf .o file from the binary espfs image using objcopy:
$(Q) cd html; find | ../espfs/mkespfsimage/mkespfsimage > ../build/espfs.img; cd ..
endif
$(Q) cd build; $(OC) -I binary -O elf32-xtensa-le -B xtensa --rename-section .data=.espfs espfs.img espfs_img.o; cd ..
Where $(OC) is the xtensa objcopy binary.
I then added build/espfs_img.o to the list of required objects:
OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) build/espfs_img.o
In order to append this thing to the end of irom0 I modified the linker file eagle.app.v6.new.512.app1.ld by changing the irom0 definition near the end of the file:
.irom0.text : ALIGN(4)
{
_irom0_text_start = ABSOLUTE(.);
*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
. = ALIGN (4096);
*(.espfs)
_irom0_text_end = ABSOLUTE(.);
} >irom0_0_seg :irom0_0_phdr
What that does is to pull the .espfs section generated by the objcopy in as last piece of .irom0.text with an alignment of 4KB (the flash sector size). The purpose of putting this at the end with this alignment is to allow it to be updated (reflashed) without updating the code itself to allow for fast changes to the web pages. This may not be necessary, in which case the whole .espfs section game is unnecessary.
In the code I can get the address of the espfs start as follows:
extern void *_binary_espfs_img_start;
...
os_printf("\nESPFS @0x%08x\n", (unsigned int)_binary_espfs_img_start);
Where I'm stuck now is at actually booting the user1.bin that I generate. I'm using the open-source esptool.py and I'm concluding that it can't generate the format required for user1.bin. The Espressif SDK's pretty horrible gen_appbin.py has a special boot_mode argument the equivalent of which esptool.py doesn't have. So I'll have to change my Makefile over. But right now it's time to stop for the day...