Skip to content

Commit

Permalink
upload littlefs for esp32 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
jscrane authored Oct 14, 2023
1 parent 44b127b commit 2c7a46d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
12 changes: 8 additions & 4 deletions docs/esp.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ targets:
- ota: uploads compiled sketch "over the air"
- spiffs: creates $(SPIFFS_IMAGE)
- upload-spiffs: writes $(SPIFFS_IMAGE) to flash
- fs: creates $(LITTLEFS_IMAGE)
- upload-fs: writes $(FS_IMAGE) to flash
- littlefs: creates $(LITTLEFS_IMAGE)
- upload-littlefs: writes $(FS_IMAGE) to flash

### esp32

Expand All @@ -60,15 +60,19 @@ menu options:
- ERASEFLASH: none (all)

other variables:
- SPIFFS_DIR: data
- FS_DIR: data
- SPIFFS_IMAGE: spiffs.img
- LITTLEFS_IMAGE: littlefs.img
- OTA_HOST
- OTA_PORT
- OTA_PASSWORD

targets:
- ota
- upload-spiffs: builds and uploads spiffs image
- spiffs: creates $(SPIFFS_IMAGE)
- upload-spiffs: writes $(SPIFFS_IMAGE) to flash
- littlefs: creates $(LITTLEFS_IMAGE)
- upload-littlefs: writes $(FS_IMAGE) to flash

### examples

Expand Down
30 changes: 21 additions & 9 deletions esp32.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
SERIAL_PORT ?= /dev/ttyUSB0
FS_DIR ?= data
SPIFFS_IMAGE ?= spiffs.img
LITTLEFS_IMAGE ?= littlefs.img

# menus
JTAGADAPTER ?= default
Expand Down Expand Up @@ -41,19 +42,30 @@ ota: network.password = $(OTA_PASSWORD)
ota: prebuild $(SKETCH_BIN)
$(tools.$(upload.tool).upload.network_pattern)

BUILD_EXTRAS := $(SPIFFS_IMAGE)
BUILD_EXTRAS := $(SPIFFS_IMAGE) $(LITTLEFS_IMAGE)

PARTITIONS := $(build.path)/partitions.csv
SPIFFS_PART := $(shell sed -ne "/^spiffs/p" $(PARTITIONS))
SPIFFS_START := $(shell echo $(SPIFFS_PART) | cut -f4 -d, -)
SPIFFS_SIZE := $(shell echo $(SPIFFS_PART) | cut -f5 -d, -)
SPIFFS_PAGESIZE := 256
SPIFFS_BLOCKSIZE := 4096
$(SPIFFS_IMAGE): $(wildcard $(SPIFFS_DIR)/*)
$(runtime.tools.mkspiffs.path)/$(runtime.tools.mkspiffs.cmd) -c $(FS_DIR) -b $(SPIFFS_BLOCKSIZE) -p $(SPIFFS_PAGESIZE) -s $(SPIFFS_SIZE) $@
FS_START := $(shell echo $(SPIFFS_PART) | cut -f4 -d, -)
FS_SIZE := $(shell echo $(SPIFFS_PART) | cut -f5 -d, -)
FS_PAGESIZE := 256
FS_BLOCKSIZE := 4096
$(SPIFFS_IMAGE): $(wildcard $(FS_DIR)/*)
$(runtime.tools.mkspiffs.path)/$(runtime.tools.mkspiffs.cmd) -c $(FS_DIR) -b $(FS_BLOCKSIZE) -p $(FS_PAGESIZE) -s $(FS_SIZE) $@

spiffs: $(SPIFFS_IMAGE)

upload-spiffs: cmd = $(tools.$(upload.tool).cmd)
upload-spiffs: $(SPIFFS_IMAGE)
$(runtime.tools.$(upload.tool).path)/$(cmd) --chip esp32 --port $(serial.port) --before default_reset --after hard_reset write_flash -z --flash_mode $(build.flash_mode) --flash_freq $(build.flash_freq) --flash_size detect $(SPIFFS_START) $(SPIFFS_IMAGE)
$(runtime.tools.$(upload.tool).path)/$(cmd) --chip esp32 --port $(serial.port) --before default_reset --after hard_reset write_flash -z --flash_mode $(build.flash_mode) --flash_freq $(build.flash_freq) --flash_size detect $(FS_START) $(SPIFFS_IMAGE)

$(LITTLEFS_IMAGE): $(wildcard $(FS_DIR)/*)
$(runtime.tools.mklittlefs.path)/$(runtime.tools.mklittlefs.cmd) -c $(FS_DIR) -b $(FS_BLOCKSIZE) -p $(FS_PAGESIZE) -s $(FS_SIZE) $@

littlefs: $(LITTLEFS_IMAGE)

upload-littlefs: cmd = $(tools.$(upload.tool).cmd)
upload-littlefs: $(LITTLEFS_IMAGE)
$(runtime.tools.$(upload.tool).path)/$(cmd) --chip esp32 --port $(serial.port) --before default_reset --after hard_reset write_flash -z --flash_mode $(build.flash_mode) --flash_freq $(build.flash_freq) --flash_size detect $(FS_START) $(LITTLEFS_IMAGE)

.PHONY: upload upload-spiffs ota
.PHONY: upload spiffs upload-spiffs littlefs upload-littlefs ota
6 changes: 3 additions & 3 deletions esp8266.mk
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ upload-spiffs: $(SPIFFS_IMAGE)
$(LITTLEFS_IMAGE): $(wildcard $(FS_DIR)/*)
$(runtime.tools.mklittlefs.path)/$(tools.mklittlefs.cmd) -c $(FS_DIR) -b $(build.spiffs_blocksize) -p $(build.spiffs_pagesize) -s $$(( $(build.spiffs_end) - $(build.spiffs_start) )) $@

fs: $(LITTLEFS_IMAGE)
littlefs: $(LITTLEFS_IMAGE)

upload-fs: $(LITTLEFS_IMAGE)
upload-littlefs: $(LITTLEFS_IMAGE)
$(tools.esptool.cmd) $(runtime.platform.path)/tools/upload.py --chip esp8266 --port $(serial.port) --baud $(upload.speed) $(upload.verbose) write_flash $(build.spiffs_start) $<

.PHONY: ota spiffs upload-spiffs fs upload-fs
.PHONY: ota spiffs upload-spiffs littlefs upload-littlefs

0 comments on commit 2c7a46d

Please sign in to comment.