Fixes the spiffsimg issues (#1502) (#1503)

* Always build spiffsimg (and make it build)

* Make sure that we have the offset before allowing the user to put it
into the output filename

* Fix the documentation and align the makefile with the docs

* Clean up the docs a bit more

* Revert to include building the 8mb size (for ESP8285)

* Added a spiffsimg target that does what you would expect

* Added support for HOSTCC (defaults to gcc)
This commit is contained in:
Philip Gladstone 2016-09-20 21:45:53 -04:00 committed by Johny Mattsson
parent 04e93b2433
commit 5ba1a6e934
5 changed files with 36 additions and 13 deletions

View File

@ -273,7 +273,7 @@ endif
.PHONY: spiffs-image-remove .PHONY: spiffs-image-remove
spiffs-image-remove: spiffs-image-remove:
$(MAKE) -C tools remove-image $(MAKE) -C tools remove-image spiffsimg/spiffsimg
.PHONY: spiffs-image .PHONY: spiffs-image

View File

@ -27,11 +27,11 @@ spiffsimg -f <filename>
### Supported operations: ### Supported operations:
* `-f` specifies the filename for the disk image. '%x' will be replaced by the calculated offset of the file system. * `-f` specifies the filename for the disk image. '%x' will be replaced by the calculated offset of the file system (`-U` must also be specified to calculate the offset).
* `-o` specifies the file which is to contain the calculated offset. * `-o` specifies the filename which is to contain the calculated offset.
* `-S` specifies the size of the flash chip. `32m` is 32 mbits, `1MB` is 1 megabyte. * `-S` specifies the size of the flash chip. `32m` is 32 mbits, `4MB` is 4 megabytes.
* `-U` specifies the amount of flash used by the firmware. Decimal or Hex bytes. * `-U` specifies the amount of flash used by the firmware. Decimal or Hex bytes (if starts with 0x).
* `-c` Create a blank disk image of the given size. * `-c` Create a blank disk image of the given size. Decimal or Hex bytes (if starts with 0x).
* `-l` List the contents of the given disk image. * `-l` List the contents of the given disk image.
* `-i` Interactive commands. * `-i` Interactive commands.
* `-r` Scripted commands from filename. * `-r` Scripted commands from filename.
@ -73,7 +73,8 @@ f 880 http/favicon.ico
# Technical Details # Technical Details
The SPIFFS configuration is 4k sectors (the only size supported by the SDK) and 8k blocks. 256 byte pages. Magic is enabled and magic_len is also enabled. This allows the firmware to find the start of the filesystem (and also the size). The SPIFFS configuration is 4k sectors (the only size supported by the SDK) and 8k blocks. 256 byte pages. Magic is enabled and magic_len is also enabled. This allows the firmware to find the start of the filesystem (and also the size).
One of the goals is to make the filsystem more persistent across reflashing of the firmware. One of the goals is to make the filsystem more persistent across reflashing of the firmware. However, there are still cases
where spiffs detects a filesystem and uses it when it isn't valid. If you are getting weirdness with the filesystem, then just reformat it.
There are two significant sizes of flash -- the 512K and 4M (or bigger). There are two significant sizes of flash -- the 512K and 4M (or bigger).
@ -82,14 +83,20 @@ not much spare space, so a newly formatted file system will start as low as poss
file system will start on a 64k boundary. A newly formatted file system will start between 64k and 128k from the end of the firmware. This means that the file file system will start on a 64k boundary. A newly formatted file system will start between 64k and 128k from the end of the firmware. This means that the file
system will survive lots of reflashing and at least 64k of firmware growth. system will survive lots of reflashing and at least 64k of firmware growth.
The spiffsimg tool can also be built (from source) in the nodemcu-firmware build tree. If there is any data in the `local/fs` directory tree, then it will The standard build process for the firmware builds the `spiffsimg` tool (found in the `tools/spiffsimg` subdirectory).
be copied into the flash disk image. Two images will normally be created -- one for the 512k flash part and the other for the 4M flash part. If the data doesn't The top level Makfile also checks if
there is any data in the `local/fs` directory tree, and it will then copy these files
into the flash disk image. Two images will normally be created -- one for the 512k flash part and the other for the 4M flash part. If the data doesn't
fit into the 512k part after the firmware is included, then the file will not be generated. fit into the 512k part after the firmware is included, then the file will not be generated.
The disk image file is placed into the `bin` directory and it is named `0x<offset>-<size>.bin` where the offset is the location where it should be The disk image file is placed into the `bin` directory and it is named `0x<offset>-<size>.bin` where the offset is the location where it should be
flashed, and the size is the size of the flash part. It is quite valid (and quicker) to flash the 512k image into a 4M part. However, there will probably be flashed, and the size is the size of the flash part. It is quite valid (and quicker) to flash the 512k image into a 4M part. However, there will probably be
limited space in the file system for creating new files. limited space in the file system for creating new files.
The default configuration will try and build three different file systems for 512KB, 1MB and 4MB flash sizes. The 1MB size is suitable for the ESP8285. This can be overridden by specifying the FLASHSIZE parameter to the makefile.
If the `local/fs` directory is empty, then no flash images will be created (and the ones from the last build will be removed). The `spiffsimg` tool can
then be used to build an image as required.
If no file system is found during platform boot, then a new file system will be formatted. This can take some time on the first boot. If no file system is found during platform boot, then a new file system will be formatted. This can take some time on the first boot.
Note that the last 16k of the flash chip is reserved for the SDK to store parameters (such as the client wifi settings). Note that the last 16k of the flash chip is reserved for the SDK to store parameters (such as the client wifi settings).

View File

@ -5,6 +5,7 @@
FSSOURCE ?= ../local/fs/ FSSOURCE ?= ../local/fs/
FLASHSIZE ?= 4mb 32mb 8mb FLASHSIZE ?= 4mb 32mb 8mb
SUBDIRS = SUBDIRS =
HOSTCC ?= gcc
OBJDUMP = $(or $(shell which objdump),xtensa-lx106-elf-objdump) OBJDUMP = $(or $(shell which objdump),xtensa-lx106-elf-objdump)
@ -28,8 +29,17 @@ FLASH_USED_END = $$((0x`$(OBJDUMP) -t ../app/.output/eagle/debug/image/eagle.app
all: spiffsscript all: spiffsscript
spiffsscript: remove-image .PHONY: spiffsimg
$(MAKE) -C spiffsimg CC=gcc
.PHONY: spiffsimg/spiffsimg
spiffsimg: spiffsimg/spiffsimg
@echo Built spiffsimg in spiffsimg/spiffsimg
spiffsimg/spiffsimg:
@$(MAKE) -C spiffsimg CC=$(HOSTCC)
spiffsscript: remove-image spiffsimg/spiffsimg
rm -f ./spiffsimg/spiffs.lst rm -f ./spiffsimg/spiffs.lst
echo "" >> ./spiffsimg/spiffs.lst echo "" >> ./spiffsimg/spiffs.lst
@$(foreach f, $(SPIFFSFILES), echo "import $(FSSOURCE)$(f) $(f)" >> ./spiffsimg/spiffs.lst ;) @$(foreach f, $(SPIFFSFILES), echo "import $(FSSOURCE)$(f) $(f)" >> ./spiffsimg/spiffs.lst ;)

View File

@ -2,7 +2,7 @@ SRCS=\
main.c \ main.c \
../../app/spiffs/spiffs_cache.c ../../app/spiffs/spiffs_check.c ../../app/spiffs/spiffs_gc.c ../../app/spiffs/spiffs_hydrogen.c ../../app/spiffs/spiffs_nucleus.c ../../app/spiffs/spiffs_cache.c ../../app/spiffs/spiffs_check.c ../../app/spiffs/spiffs_gc.c ../../app/spiffs/spiffs_hydrogen.c ../../app/spiffs/spiffs_nucleus.c
CFLAGS=-g -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -I. -I../../app/spiffs -DNODEMCU_SPIFFS_NO_INCLUDE --include spiffs_typedefs.h CFLAGS=-g -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -I. -I../../app/spiffs -I../../app/include -DNODEMCU_SPIFFS_NO_INCLUDE --include spiffs_typedefs.h
spiffsimg: $(SRCS) spiffsimg: $(SRCS)
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@

View File

@ -282,6 +282,12 @@ int main (int argc, char *argv[])
} }
sz &= ~(0x1fff); sz &= ~(0x1fff);
if (used == 0) {
if (strchr(fname, '%')) {
die("Unable to calculate where to put the flash image, and % present in filename");
}
}
char fnamebuff[1024]; char fnamebuff[1024];
sprintf(fnamebuff, fname, used); sprintf(fnamebuff, fname, used);