From 5ba1a6e934f0b862482b85b4509b8bbdd487bbda Mon Sep 17 00:00:00 2001 From: Philip Gladstone Date: Tue, 20 Sep 2016 21:45:53 -0400 Subject: [PATCH] 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) --- Makefile | 2 +- docs/en/spiffs.md | 25 ++++++++++++++++--------- tools/Makefile | 14 ++++++++++++-- tools/spiffsimg/Makefile | 2 +- tools/spiffsimg/main.c | 6 ++++++ 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index cc5bf30e..f3e8bc45 100644 --- a/Makefile +++ b/Makefile @@ -273,7 +273,7 @@ endif .PHONY: spiffs-image-remove spiffs-image-remove: - $(MAKE) -C tools remove-image + $(MAKE) -C tools remove-image spiffsimg/spiffsimg .PHONY: spiffs-image diff --git a/docs/en/spiffs.md b/docs/en/spiffs.md index 1a30dc5e..e75aa206 100644 --- a/docs/en/spiffs.md +++ b/docs/en/spiffs.md @@ -27,11 +27,11 @@ spiffsimg -f ### Supported operations: - * `-f` specifies the filename for the disk image. '%x' will be replaced by the calculated offset of the file system. - * `-o` specifies the file which is to contain the calculated offset. - * `-S` specifies the size of the flash chip. `32m` is 32 mbits, `1MB` is 1 megabyte. - * `-U` specifies the amount of flash used by the firmware. Decimal or Hex bytes. - * `-c` Create a blank disk image of the given size. + * `-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 filename which is to contain the calculated offset. + * `-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 (if starts with 0x). + * `-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. * `-i` Interactive commands. * `-r` Scripted commands from filename. @@ -73,7 +73,8 @@ f 880 http/favicon.ico # 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). -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). @@ -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 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 -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 standard build process for the firmware builds the `spiffsimg` tool (found in the `tools/spiffsimg` subdirectory). +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. - The disk image file is placed into the `bin` directory and it is named `0x-.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 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. Note that the last 16k of the flash chip is reserved for the SDK to store parameters (such as the client wifi settings). diff --git a/tools/Makefile b/tools/Makefile index 0c24a4ee..ab36e756 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -5,6 +5,7 @@ FSSOURCE ?= ../local/fs/ FLASHSIZE ?= 4mb 32mb 8mb SUBDIRS = +HOSTCC ?= gcc 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 -spiffsscript: remove-image - $(MAKE) -C spiffsimg CC=gcc +.PHONY: spiffsimg + +.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 echo "" >> ./spiffsimg/spiffs.lst @$(foreach f, $(SPIFFSFILES), echo "import $(FSSOURCE)$(f) $(f)" >> ./spiffsimg/spiffs.lst ;) diff --git a/tools/spiffsimg/Makefile b/tools/spiffsimg/Makefile index 5b46de6d..82dfb797 100644 --- a/tools/spiffsimg/Makefile +++ b/tools/spiffsimg/Makefile @@ -2,7 +2,7 @@ SRCS=\ 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 -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) $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ diff --git a/tools/spiffsimg/main.c b/tools/spiffsimg/main.c index 26f7b8ab..b6ecc3fb 100644 --- a/tools/spiffsimg/main.c +++ b/tools/spiffsimg/main.c @@ -282,6 +282,12 @@ int main (int argc, char *argv[]) } 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]; sprintf(fnamebuff, fname, used);