Skip to content

Commit

Permalink
Update/fix flash components
Browse files Browse the repository at this point in the history
* Rename Host `flasher` -> `vflash`
* dos2unix on esptool/component.mk
* Fix `make flashfs` to ensure output directory exists
* Move `flashfs` target back into app.mk
* Rename `WriteFlashChunks` to `WriteFlash` and fix usage
  • Loading branch information
mikee47 committed Jun 16, 2019
1 parent 65b697d commit 316ed95
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 101 deletions.
137 changes: 64 additions & 73 deletions Sming/Arch/Esp8266/Components/esptool/component.mk
Original file line number Diff line number Diff line change
@@ -1,73 +1,64 @@
# We don't build a component
COMPONENT_TARGETS :=

## Flash parameters

CONFIG_VARS += SPI_SPEED SPI_MODE SPI_SIZE

# SPI_SPEED = 40, 26, 20, 80
SPI_SPEED ?= 40
# SPI_MODE: qio, qout, dio, dout
SPI_MODE ?= qio
# SPI_SIZE: 512K, 256K, 1M, 2M, 4M
SPI_SIZE ?= 512K

ifeq ($(SPI_SPEED), 26)
flashimageoptions := -ff 26m
else ifeq ($(SPI_SPEED), 20)
flashimageoptions := -ff 20m
else ifeq ($(SPI_SPEED), 80)
flashimageoptions := -ff 80m
else
flashimageoptions := -ff 40m
endif

ifeq ($(SPI_MODE), qout)
flashimageoptions += -fm qout
else ifeq ($(SPI_MODE), dio)
flashimageoptions += -fm dio
else ifeq ($(SPI_MODE), dout)
flashimageoptions += -fm dout
else
flashimageoptions += -fm qio
endif

ifeq ($(SPI_SIZE), 256K)
flashimageoptions += -fs 2m
else ifeq ($(SPI_SIZE), 1M)
flashimageoptions += -fs 8m
INIT_BIN_ADDR := 0x0fc000
BLANK_BIN_ADDR := 0x0fe000
else ifeq ($(SPI_SIZE), 2M)
flashimageoptions += -fs 16m
INIT_BIN_ADDR := 0x1fc000
BLANK_BIN_ADDR := 0x1fe000
else ifeq ($(SPI_SIZE), 4M)
flashimageoptions += -fs 32m
INIT_BIN_ADDR := 0x3fc000
BLANK_BIN_ADDR := 0x3fe000
else
flashimageoptions += -fs 4m
INIT_BIN_ADDR := 0x07c000
BLANK_BIN_ADDR := 0x04b000
endif

ESPTOOL := $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL)

# Write data to flash
# $1 -> Start offset
# $2 -> File containing data to write
define WriteFlashChunk
$(info WriteFlash $1 -> $2)
$(ESPTOOL) write_flash $(flashimageoptions) $1 $2
endef


# Write one or more chunks to flash
# $1 -> List of `Offset=File` chunks
define WriteFlashChunks
$(info WriteFlash $1)
$(ESPTOOL) write_flash $(flashimageoptions) $(subst =, ,$1)
endef

ERASE_FLASH := $(ESPTOOL) erase_flash
# We don't build a component
COMPONENT_TARGETS :=

## Flash parameters

CONFIG_VARS += SPI_SPEED SPI_MODE SPI_SIZE

# SPI_SPEED = 40, 26, 20, 80
SPI_SPEED ?= 40
# SPI_MODE: qio, qout, dio, dout
SPI_MODE ?= qio
# SPI_SIZE: 512K, 256K, 1M, 2M, 4M
SPI_SIZE ?= 512K

ifeq ($(SPI_SPEED), 26)
flashimageoptions := -ff 26m
else ifeq ($(SPI_SPEED), 20)
flashimageoptions := -ff 20m
else ifeq ($(SPI_SPEED), 80)
flashimageoptions := -ff 80m
else
flashimageoptions := -ff 40m
endif

ifeq ($(SPI_MODE), qout)
flashimageoptions += -fm qout
else ifeq ($(SPI_MODE), dio)
flashimageoptions += -fm dio
else ifeq ($(SPI_MODE), dout)
flashimageoptions += -fm dout
else
flashimageoptions += -fm qio
endif

ifeq ($(SPI_SIZE), 256K)
flashimageoptions += -fs 2m
else ifeq ($(SPI_SIZE), 1M)
flashimageoptions += -fs 8m
INIT_BIN_ADDR := 0x0fc000
BLANK_BIN_ADDR := 0x0fe000
else ifeq ($(SPI_SIZE), 2M)
flashimageoptions += -fs 16m
INIT_BIN_ADDR := 0x1fc000
BLANK_BIN_ADDR := 0x1fe000
else ifeq ($(SPI_SIZE), 4M)
flashimageoptions += -fs 32m
INIT_BIN_ADDR := 0x3fc000
BLANK_BIN_ADDR := 0x3fe000
else
flashimageoptions += -fs 4m
INIT_BIN_ADDR := 0x07c000
BLANK_BIN_ADDR := 0x04b000
endif

ESPTOOL := $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL)

# Write file contents to Flash
# $1 -> List of `Offset=File` chunks
define WriteFlash
$(info WriteFlash $1)
$(ESPTOOL) write_flash $(flashimageoptions) $(subst =, ,$1)
endef

ERASE_FLASH := $(ESPTOOL) erase_flash
2 changes: 1 addition & 1 deletion Sming/Arch/Esp8266/Components/rboot/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ $(LIBMAIN_RBOOT): $(LIBMAIN_SRC)
$(Q) $(OBJCOPY) -W Cache_Read_Enable_New $^ $@



# Add these dependencies to the main application build

app: $(RBOOT_ROM_0) $(RBOOT_ROM_1)

Expand Down
17 changes: 6 additions & 11 deletions Sming/Arch/Esp8266/Components/spiffs/component.mk
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

# => SMING
# => SPIFFS

COMPONENT_SUBMODULES := spiffs
COMPONENT_SRCDIRS := . spiffs/src
COMPONENT_INCDIRS := . spiffs/src

# Spiffy

# => Spiffy

SPIFFY := $(COMPONENT_BUILD_DIR)/spiffy$(TOOL_EXT)

COMPONENT_TARGETS += $(SPIFFY)
Expand Down Expand Up @@ -53,13 +55,14 @@ spiff_update: spiff_clean $(SPIFF_BIN_OUT) ##Rebuild the SPIFFS filesystem image
.PHONY: spiff_clean
spiff_clean: ##Remove SPIFFS image file
$(vecho) "Cleaning $(SPIFF_BIN_OUT)"
$(Q) rm -rf $(SPIFF_BIN_OUT)
$(Q) rm -f $(SPIFF_BIN_OUT)

# Generating spiffs_bin
$(SPIFF_BIN_OUT):
ifeq ($(DISABLE_SPIFFS), 1)
$(vecho) "(!) Spiffs support disabled. Remove 'DISABLE_SPIFFS' make argument to enable spiffs."
else
$(Q) mkdir -p $(dir $(SPIFF_BIN_OUT))
$(vecho) "Checking for spiffs files"
$(Q) if [ -d "$(SPIFF_FILES)" ]; then \
echo "$(SPIFF_FILES) directory exists. Creating $(SPIFF_BIN_OUT)"; \
Expand All @@ -71,11 +74,3 @@ else
fi
endif

.PHONY: flashfs
flashfs: $(SPIFF_BIN_OUT) ##Write just the SPIFFS filesystem image
ifeq ($(DISABLE_SPIFFS), 1)
$(vecho) "SPIFFS are not enabled!"
else
$(call WriteFlashChunk,$(RBOOT_SPIFFS_0),$(SPIFF_BIN_OUT))
endif

22 changes: 15 additions & 7 deletions Sming/Arch/Esp8266/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -103,35 +103,43 @@ $(TARGET_OUT_1): $(APP_AR) $(COMPONENTS)

.PHONY: flashboot
flashboot: $(RBOOT_BIN) ##Write just the rBoot boot sector
$(call WriteFlashChunk,0x00000=$(RBOOT_BIN))
$(call WriteFlash,0x00000=$(RBOOT_BIN))

.PHONY: flashconfig
flashconfig: kill_term ##Erase the rBoot config sector
$(vecho) "Erasing rBoot config sector"
$(call WriteFlashChunk,0x01000=$(SDK_BASE)/bin/blank.bin)
$(call WriteFlash,0x01000=$(SDK_BASE)/bin/blank.bin)

.PHONY: flashapp
flashapp: all kill_term ##Write just the application image
$(call WriteFlashChunk,$(ROM_0_ADDR)=$(RBOOT_ROM_0))
$(call WriteFlash,$(ROM_0_ADDR)=$(RBOOT_ROM_0))

.PHONY: flashfs
flashfs: $(SPIFF_BIN_OUT) ##Write just the SPIFFS filesystem image
ifeq ($(DISABLE_SPIFFS), 1)
$(vecho) "SPIFFS are not enabled!"
else
$(call WriteFlash,$(RBOOT_SPIFFS_0)=$(SPIFF_BIN_OUT))
endif

# flashes rboot and first rom
FLASH_CHUNKS := 0x00000=$(RBOOT_BIN)
FLASH_CHUNKS = 0x00000=$(RBOOT_BIN)
FLASH_CHUNKS += $(ROM_0_ADDR)=$(RBOOT_ROM_0)
ifneq ($(DISABLE_SPIFFS), 1)
FLASH_CHUNKS += $(RBOOT_SPIFFS_0)=$(SPIFF_BIN_OUT)
endif

.PHONY: flash
flash: all kill_term ##Write the rBoot boot sector, application image and (if enabled) SPIFFS image
$(call WriteFlashChunks,$(FLASH_CHUNKS))
$(call WriteFlash,$(FLASH_CHUNKS))
ifeq ($(ENABLE_GDB), 1)
$(GDB)
else
$(TERMINAL)
endif

# Wipe flash
FLASH_INIT_CHUNKS := $(INIT_BIN_ADDR)=$(SDK_BASE)/bin/esp_init_data_default.bin
FLASH_INIT_CHUNKS = $(INIT_BIN_ADDR)=$(SDK_BASE)/bin/esp_init_data_default.bin
FLASH_INIT_CHUNKS += $(BLANK_BIN_ADDR)=$(SDK_BASE)/bin/blank.bin
ifneq ($(DISABLE_SPIFFS), 1)
FLASH_INIT_CHUNKS += $(RBOOT_SPIFFS_0)=$(ARCH_BASE)/Compiler/data/blankfs.bin
Expand All @@ -142,4 +150,4 @@ flashinit: ##Erase your device's flash memory and reset system configuration are
$(vecho) "Flash init data default and blank data."
$(vecho) "DISABLE_SPIFFS = $(DISABLE_SPIFFS)"
$(ERASE_FLASH)
$(WRITE_FLASH) $(FLASH_INIT_CHUNKS)
$(call WriteFlash,$(FLASH_INIT_CHUNKS))
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
COMPONENT_TARGETS :=

# spiffs_get_storage_config()
APPCODE += $(ESP8266_COMPONENTS)/rboot/appcode
APPCODE += $(ESP8266_COMPONENTS)/rboot/appcode
RBOOT_SPIFFS_0 ?= 0x100000

# Use DD to update $(FW_BASE)/flash.bin
# Use DD to update FLASH_BIN, which represents the entire flash device contents

DD := dd
DD := dd

CONFIG_VARS += FLASH_BIN
FLASH_BIN ?= $(FW_BASE)/flash.bin
CONFIG_VARS += FLASH_BIN
FLASH_BIN ?= $(FW_BASE)/flash.bin

CONFIG_VARS += SPI_SIZE
SPI_SIZE ?= 4M

# Write data to flash
# $1 -> Start offset
Expand All @@ -24,8 +27,8 @@ endef

# Write one or more chunks to flash
# $1 -> List of `Offset=File` chunks
define WriteFlashChunks
$(foreach chunk,$1,$(call WriteFlashChunk,$(subst =, ,$(chunk))))
define WriteFlash
$(foreach c,$1,$(call WriteFlashChunk,$(word 1,$(subst =, ,$c)),$(word 2,$(subst =, ,$c))))
endef

#
Expand Down
10 changes: 9 additions & 1 deletion Sming/Arch/Host/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ $(TARGET_OUT_0): $(APP_AR) $(COMPONENTS)
.PHONY: run
run: all ##Run the application image
$(TARGET_OUT_0) $(SMING_TARGET_OPTIONS)


.PHONY: flashfs
flashfs: $(SPIFF_BIN_OUT) ##Write just the SPIFFS filesystem image
ifeq ($(DISABLE_SPIFFS), 1)
$(vecho) "SPIFFS are not enabled!"
else
$(call WriteFlash,$(RBOOT_SPIFFS_0)=$(SPIFF_BIN_OUT))
endif

.PHONY: flash
flash: all flashfs ##Write the SPIFFS filesystem image then run the application
ifeq ($(ENABLE_GDB), 1)
Expand Down
2 changes: 1 addition & 1 deletion samples/HttpServer_ConfigNetwork/Makefile-user.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ web-pack:
$(Q) date +'%a, %d %b %Y %H:%M:%S GMT' -u > web/build/.lastModified

web-upload: web-pack spiff_update
$(call WriteFlashChunk,$(SPIFF_START_OFFSET),$(SPIFF_BIN_OUT))
$(call WriteFlash,$(SPIFF_START_OFFSET)=$(SPIFF_BIN_OUT))

0 comments on commit 316ed95

Please sign in to comment.