risc-v/esp32c3: Add more flash options to esptool.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
Abdelatif Guettouche 2021-03-01 14:54:16 +01:00 committed by Xiang Xiao
parent 77302f9d3a
commit 85620c3c1a
2 changed files with 93 additions and 20 deletions

View File

@ -52,6 +52,11 @@ config ESP32C3_DUAL_CPU
bool bool
default n default n
config ESP32C3_ESP32C3XXX
bool
default n
select ESP32C3_SINGLE_CPU
config ESP32C3_FLASH_2M config ESP32C3_FLASH_2M
bool bool
default n default n
@ -68,10 +73,46 @@ config ESP32C3_FLASH_16M
bool bool
default n default n
config ESP32C3_ESP32C3XXX config ESP32C3_FLASH_DETECT
bool bool "Auto-detect FLASH size (to be used with master esptool)"
default n default n
select ESP32C3_SINGLE_CPU help
Auto detect flash size when flashing.
Current released version of esptool doesn't support auto-detecting flash size.
Use latest master from https://github.com/espressif/esptool.
choice ESP32C3_FLASH_MODE
prompt "SPI FLASH mode"
default ESP32C3_FLASH_MODE_DIO
help
These options control how many I/O pins are used for communication with the attached SPI flash chip.
The option selected here is then used by esptool when flashing.
config ESP32C3_FLASH_MODE_DIO
bool "Dual IO (DIO)"
config ESP32C3_FLASH_MODE_DOUT
bool "Dual Output (DOUT)"
config ESP32C3_FLASH_MODE_QIO
bool "Quad IO (QIO)"
config ESP32C3_FLASH_MODE_QOUT
bool "Quad Output (QOUT)"
endchoice # ESP32C3_FLASH_MODE
choice ESP32C3_FLASH_FREQ
prompt "SPI FLASH frequency"
default ESP32C3_FLASH_FREQ_40M
help
SPI FLASH frequency
config ESP32C3_FLASH_FREQ_80M
bool "80 MHz"
config ESP32C3_FLASH_FREQ_40M
bool "40 MHz"
config ESP32C3_FLASH_FREQ_26M
bool "26 MHz"
config ESP32C3_FLASH_FREQ_20M
bool "20 MHz"
endchoice # ESP32C3_FLASH_FREQ
choice ESP32C3_CPU_FREQ choice ESP32C3_CPU_FREQ
prompt "CPU frequency" prompt "CPU frequency"

View File

@ -22,23 +22,52 @@
# and assemble source files and to insert the resulting object files into an # and assemble source files and to insert the resulting object files into an
# archive. These replace the default definitions at tools/Config.mk # archive. These replace the default definitions at tools/Config.mk
ifdef ESPTOOL_BINDIR ifeq ($(CONFIG_ESP32C3_FLASH_2M),y)
BL_OFFSET=0x0 FLASH_SIZE := 2MB
PT_OFFSET=0x8000 else ifeq ($(CONFIG_ESP32C3_FLASH_4M),y)
BOOTLOADER=$(ESPTOOL_BINDIR)/bootloader-esp32c3.bin FLASH_SIZE := 4MB
PARTITION_TABLE=$(ESPTOOL_BINDIR)/partition-table-esp32c3.bin else ifeq ($(CONFIG_ESP32C3_FLASH_8M),y)
FLASH_BL=$(BL_OFFSET) $(BOOTLOADER) FLASH_SIZE := 8MB
FLASH_PT=$(PT_OFFSET) $(PARTITION_TABLE) else ifeq ($(CONFIG_ESP32C3_FLASH_16M),y)
FLASH_SIZE := 16MB
endif endif
ifeq ($(CONFIG_ESP32C3_FLASH_2M),y) ifeq ($(CONFIG_ESP32C3_FLASH_MODE_DIO),y)
FLASH_SIZE="2MB" FLASH_MODE := dio
else ifeq ($(CONFIG_ESP32C3_FLASH_4M),y) else ifeq ($(CONFIG_ESP32C3_FLASH_MODE_DOUT),y)
FLASH_SIZE="4MB" FLASH_MODE := dout
else ifeq ($(CONFIG_ESP32C3_FLASH_8M),y) else ifeq ($(CONFIG_ESP32C3_FLASH_MODE_QIO),y)
FLASH_SIZE="8MB" FLASH_MODE := qio
else ifeq ($(CONFIG_ESP32C3_FLASH_16M),y) else ifeq ($(CONFIG_ESP32C3_FLASH_MODE_QOUT),y)
FLASH_SIZE="16MB" FLASH_MODE := qout
endif
ifeq ($(CONFIG_ESP32C3_FLASH_FREQ_80M),y)
FLASH_FREQ := 80m
else ifeq ($(CONFIG_ESP32C3_FLASH_FREQ_40M),y)
FLASH_FREQ := 40m
else ifeq ($(CONFIG_ESP32C3_FLASH_FREQ_26M),y)
FLASH_FREQ := 26m
else ifeq ($(CONFIG_ESP32C3_FLASH_FREQ_20M),y)
FLASH_FREQ := 20m
endif
ESPTOOL_FLASH_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ)
ESPTOOL_ELF2IMG_OPTS := $(ESPTOOL_FLASH_OPTS)
ifeq ($(CONFIG_ESP32C3_FLASH_DETECT),y)
ESPTOOL_WRITEFLASH_OPTS := -fs detect -fm $(FLASH_MODE) -ff $(FLASH_FREQ)
else
ESPTOOL_WRITEFLASH_OPTS := $(ESPTOOL_FLASH_OPTS)
endif
ifdef ESPTOOL_BINDIR
BL_OFFSET := 0x0
PT_OFFSET := 0x8000
BOOTLOADER := $(ESPTOOL_BINDIR)/bootloader-esp32c3.bin
PARTITION_TABLE := $(ESPTOOL_BINDIR)/partition-table-esp32c3.bin
FLASH_BL := $(BL_OFFSET) $(BOOTLOADER)
FLASH_PT := $(PT_OFFSET) $(PARTITION_TABLE)
endif endif
# POSTBUILD -- Perform post build operations # POSTBUILD -- Perform post build operations
@ -57,7 +86,7 @@ define POSTBUILD
echo "Missing Flash memory size configuration for the ESP32-C3 chip."; \ echo "Missing Flash memory size configuration for the ESP32-C3 chip."; \
exit 1; \ exit 1; \
fi fi
esptool.py --chip esp32c3 elf2image --flash_mode dio --flash_size $(FLASH_SIZE) -o nuttx.bin nuttx esptool.py -c esp32c3 elf2image $(ESPTOOL_ELF2IMG_OPTS) -o nuttx.bin nuttx
$(Q) echo "Generated: nuttx.bin (ESP32-C3 compatible)" $(Q) echo "Generated: nuttx.bin (ESP32-C3 compatible)"
endef endef
@ -68,10 +97,13 @@ ESPTOOL_BAUD ?= 921600
# DOWNLOAD -- Download binary image via esptool.py # DOWNLOAD -- Download binary image via esptool.py
define DOWNLOAD define DOWNLOAD
$(eval ESPTOOL_BINS := $(FLASH_BL) $(FLASH_PT) 0x10000 $(1).bin)
$(Q) if [ -z $(ESPTOOL_PORT) ]; then \ $(Q) if [ -z $(ESPTOOL_PORT) ]; then \
echo "DOWNLOAD error: Missing serial port device argument."; \ echo "DOWNLOAD error: Missing serial port device argument."; \
echo "USAGE: make download ESPTOOL_PORT=<port> [ ESPTOOL_BAUD=<baud> ]"; \ echo "USAGE: make download ESPTOOL_PORT=<port> [ ESPTOOL_BAUD=<baud> ]"; \
exit 1; \ exit 1; \
fi fi
esptool.py --chip esp32c3 --port $(ESPTOOL_PORT) --baud $(ESPTOOL_BAUD) write_flash $(FLASH_BL) $(FLASH_PT) 0x10000 $(1).bin esptool.py -c esp32c3 -p $(ESPTOOL_PORT) -b $(ESPTOOL_BAUD) write_flash $(ESPTOOL_WRITEFLASH_OPTS) $(ESPTOOL_BINS)
endef endef