mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
d0cc955394
Flashing an ESP board first requires the creation of a flash image from the ELF file. This is realized in the `preflash` target. However, the `preflash` target only depends on the variable `BUILD_BEFORE_FLASH` but on the ELF file. Therefore, the variable `BUILD_BEFORE_FLASH` must be set to the ELF file to ensure that when using multiple make processes, the compilation of the ELF file is completed before the flash image is created.
141 lines
5.2 KiB
Makefile
141 lines
5.2 KiB
Makefile
# Default compile configurations
|
|
|
|
# FLASH_MODE=[ dout | dio | qout | qio ]
|
|
# use flash mode dout by default to keep GPIO9 and GPIO10 free for use
|
|
FLASH_MODE ?= dout
|
|
|
|
# ESP* pseudomodules
|
|
|
|
PSEUDOMODULES += esp_gdb
|
|
PSEUDOMODULES += esp_i2c_sw
|
|
PSEUDOMODULES += esp_log_colored
|
|
PSEUDOMODULES += esp_log_tagged
|
|
PSEUDOMODULES += esp_log_startup
|
|
PSEUDOMODULES += esp_qemu
|
|
PSEUDOMODULES += esp_spiffs
|
|
PSEUDOMODULES += esp_wifi_any
|
|
|
|
# Common includes
|
|
|
|
INCLUDES += -I$(RIOTBOARD)/common/$(CPU)/include
|
|
INCLUDES += -I$(RIOTCPU)/esp_common
|
|
INCLUDES += -I$(RIOTCPU)/esp_common/include
|
|
INCLUDES += -I$(RIOTCPU)/esp_common/include/freertos
|
|
INCLUDES += -I$(RIOTCPU)/esp_common/vendor/
|
|
INCLUDES += -I$(RIOTCPU)/esp_common/vendor/esp
|
|
|
|
# Flags
|
|
|
|
CFLAGS += -Wno-unused-parameter -Wformat=0
|
|
CFLAGS += -mlongcalls -mtext-section-literals -fstrict-volatile-bitfields
|
|
CFLAGS += -fdata-sections -ffunction-sections -fzero-initialized-in-bss
|
|
|
|
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow
|
|
OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation
|
|
OPTIONAL_CFLAGS_BLACKLIST += -gz
|
|
|
|
ASFLAGS += --longcalls --text-section-literals
|
|
|
|
# thin archives trigger a reboot loop - see #12258, #12035, #12346
|
|
ARFLAGS = rcs
|
|
|
|
CFLAGS_DBG ?= -ggdb -g3
|
|
|
|
# override default CFLAGS_OPT in case module esp_gdb is enabled
|
|
CFLAGS_OPT ?= $(if $(filter esp_gdb,$(USEMODULE)),-Og,-Os)
|
|
|
|
CFLAGS += $(CFLAGS_OPT) $(CFLAGS_DBG)
|
|
|
|
# add -DQEMU for qemu
|
|
ifneq (,$(filter esp_qemu,$(USEMODULE)))
|
|
CFLAGS += -DQEMU
|
|
endif
|
|
|
|
# NOTE: These checks can be turned into normal conditionals when #9913 is fixed
|
|
# use 32 priority levels if any WiFi interface or the ETH interface is used
|
|
CFLAGS += $(if $(filter esp_wifi_any esp_eth,$(USEMODULE)),-DSCHED_PRIO_LEVELS=32)
|
|
|
|
# The threads for handling the ESP hardware have the priorities from 2 to 4.
|
|
# The priority of lwIP TCPIP thread should be lower than these priorities.
|
|
ifneq (,$(filter lwip,$(USEMODULE)))
|
|
CFLAGS += -DTCPIP_THREAD_PRIO=5
|
|
endif
|
|
|
|
# if SPI RAM is enabled, the qout flash mode has to be used
|
|
# NOTE: These checks can be turned into normal conditionals when #9913 is fixed
|
|
_FLASH_MODE_PREV := $(FLASH_MODE)
|
|
FLASH_MODE = $(if $(filter esp_spi_ram,$(USEMODULE)),qout,$(_FLASH_MODE_PREV))
|
|
|
|
# set CFLAG for the correspondant FLASH_MODE
|
|
CFLAGS += $(if $(findstring qout,$(FLASH_MODE)),-DFLASH_MODE_QOUT=1)
|
|
CFLAGS += $(if $(findstring qio,$(FLASH_MODE)),-DFLASH_MODE_QIO=1)
|
|
CFLAGS += $(if $(findstring dio,$(FLASH_MODE)),-DFLASH_MODE_DIO=1)
|
|
CFLAGS += $(if $(findstring dout,$(FLASH_MODE)),-DFLASH_MODE_DOUT=1)
|
|
|
|
BASELIBS += -lhal -lg -lc
|
|
|
|
LINKFLAGS += $(CFLAGS_OPT) $(CFLAGS_DBG)
|
|
LINKFLAGS += -L$(ESP_SDK_DIR)/components/$(CPU)
|
|
LINKFLAGS += -L$(ESP_SDK_DIR)/components/$(CPU)/lib
|
|
LINKFLAGS += -nostdlib -Wl,-gc-sections -Wl,-static
|
|
|
|
# LINKFLAGS += -Wl,--verbose
|
|
# LINKFLAGS += -Wl,--print-gc-sections
|
|
|
|
# NOTE: These checks can be turned into normal conditionals when #9913 is fixed
|
|
BOOTLOADER_COLOR = $(if $(filter esp_log_colored,$(USEMODULE)),_colors)
|
|
BOOTLOADER_INFO = $(if $(filter esp_log_startup,$(USEMODULE)),_info)
|
|
|
|
BOOTLOADER_BIN = bootloader$(BOOTLOADER_COLOR)$(BOOTLOADER_INFO).bin
|
|
|
|
ESPTOOL ?= $(RIOTTOOLS)/esptool/esptool.py
|
|
|
|
# The ELFFILE is the base one used for flashing
|
|
FLASHFILE ?= $(ELFFILE)
|
|
|
|
# configure preflasher to convert .elf to .bin before flashing
|
|
PREFLASHER = $(ESPTOOL)
|
|
PREFFLAGS = --chip $(FLASH_CHIP) elf2image
|
|
PREFFLAGS += --flash_mode $(FLASH_MODE) --flash_size $(FLASH_SIZE)MB
|
|
PREFFLAGS += --flash_freq $(FLASH_FREQ) $(FLASH_OPTS)
|
|
PREFFLAGS += -o $(FLASHFILE).bin $(FLASHFILE);
|
|
PREFFLAGS += printf "\n" > $(BINDIR)/partitions.csv;
|
|
PREFFLAGS += printf "nvs, data, nvs, 0x9000, 0x6000\n" >> $(BINDIR)/partitions.csv;
|
|
PREFFLAGS += printf "phy_init, data, phy, 0xf000, 0x1000\n" >> $(BINDIR)/partitions.csv;
|
|
PREFFLAGS += printf "factory, app, factory, 0x10000, " >> $(BINDIR)/partitions.csv;
|
|
PREFFLAGS += ls -l $(FLASHFILE).bin | awk '{ print $$5 }' >> $(BINDIR)/partitions.csv;
|
|
|
|
PREFFLAGS += python3 $(RIOTTOOLS)/esptool/gen_esp32part.py
|
|
PREFFLAGS += --verify $(BINDIR)/partitions.csv $(BINDIR)/partitions.bin
|
|
FLASHDEPS += preflash
|
|
|
|
BUILD_BEFORE_FLASH += $(FLASHFILE)
|
|
|
|
# flasher configuration
|
|
ifneq (,$(filter esp_qemu,$(USEMODULE)))
|
|
FLASHER = dd
|
|
FFLAGS += if=/dev/zero bs=1M count=$(FLASH_SIZE) |
|
|
FFLAGS += tr "\\000" "\\377" > tmp.bin && cat tmp.bin |
|
|
FFLAGS += head -c $$(($(BOOTLOADER_POS))) |
|
|
FFLAGS += cat - $(RIOTCPU)/$(CPU)/bin/$(BOOTLOADER_BIN) tmp.bin |
|
|
FFLAGS += head -c $$((0x8000)) |
|
|
FFLAGS += cat - $(BINDIR)/partitions.bin tmp.bin |
|
|
FFLAGS += head -c $$((0x10000)) |
|
|
FFLAGS += cat - $(FLASHFILE).bin tmp.bin |
|
|
FFLAGS += head -c $(FLASH_SIZE)MB > $(BINDIR)/$(CPU)flash.bin && rm tmp.bin;
|
|
else
|
|
PROGRAMMER_SPEED ?= 460800
|
|
FLASHER = $(ESPTOOL)
|
|
FFLAGS += --chip $(FLASH_CHIP) --port $(PROG_DEV) --baud $(PROGRAMMER_SPEED)
|
|
FFLAGS += --before default_reset write_flash -z
|
|
FFLAGS += --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ)
|
|
FFLAGS += $(BOOTLOADER_POS) $(RIOTCPU)/$(CPU)/bin/$(BOOTLOADER_BIN)
|
|
FFLAGS += 0x8000 $(BINDIR)/partitions.bin
|
|
FFLAGS += 0x10000 $(FLASHFILE).bin
|
|
endif
|
|
|
|
# NOTE: These checks can be turned into normal conditionals when #9913 is fixed
|
|
# increase the test timeout for file system tests that use the SPI flash drive
|
|
RIOT_TEST_TIMEOUT = $(if $(filter spiffs littlefs,$(USEMODULE)),120)
|
|
$(call target-export-variables,test,RIOT_TEST_TIMEOUT)
|