diff --git a/cpu/esp32/bin/bootloader.bin b/cpu/esp32/bin/bootloader.bin deleted file mode 100644 index 951b65a0fe..0000000000 Binary files a/cpu/esp32/bin/bootloader.bin and /dev/null differ diff --git a/cpu/esp32/bin/bootloader_colors.bin b/cpu/esp32/bin/bootloader_colors.bin deleted file mode 100644 index 0ec3e3051a..0000000000 Binary files a/cpu/esp32/bin/bootloader_colors.bin and /dev/null differ diff --git a/cpu/esp32/bin/bootloader_colors_info.bin b/cpu/esp32/bin/bootloader_colors_info.bin deleted file mode 100644 index 6d13559011..0000000000 Binary files a/cpu/esp32/bin/bootloader_colors_info.bin and /dev/null differ diff --git a/cpu/esp32/bin/bootloader_info.bin b/cpu/esp32/bin/bootloader_info.bin deleted file mode 100644 index 08c2b0040b..0000000000 Binary files a/cpu/esp32/bin/bootloader_info.bin and /dev/null differ diff --git a/cpu/esp32/bootloader/Kconfig b/cpu/esp32/bootloader/Kconfig new file mode 100644 index 0000000000..4ad7c1dc40 --- /dev/null +++ b/cpu/esp32/bootloader/Kconfig @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Gunar Schorcht +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +config MODULE_ESP_BOOTLOADER + bool + depends on TEST_KCONFIG + depends on HAS_ARCH_ESP32 + default y + help + Bootloader compiled from ESP-IDF code. diff --git a/cpu/esp32/bootloader/Makefile b/cpu/esp32/bootloader/Makefile new file mode 100644 index 0000000000..2203ebaee2 --- /dev/null +++ b/cpu/esp32/bootloader/Makefile @@ -0,0 +1,295 @@ +# Bootloader binary blob +MODULE = esp_bootloader + +# We are compiling the bootloader from the ESP32 SDK sources, so we +# can't use the automatic module SRC discovery rules. Also, the compiled code +# would not be linked into the application, instead it is linked into its own +# binary file. +NO_AUTO_SRC = 1 + +include $(RIOTBASE)/Makefile.base + +# Bootloader baudrate, set to the application defined one if any or the default +# in serial.inc.mk +BOOTLOADER_BAUD ?= $(BAUD) + +# List of bootloader sources determined by esp-idf/examples/get-started/hello-world +# TODO HowTo generate this list +ESP_SDK_BOOTLOADER_SRCS = \ + components/bootloader/subproject/main/bootloader_start.c \ + components/bootloader/subproject/components/micro-ecc/uECC_verify_antifault.c \ + components/bootloader_support/src/bootloader_clock_init.c \ + components/bootloader_support/src/bootloader_clock_loader.c \ + components/bootloader_support/src/bootloader_common.c \ + components/bootloader_support/src/bootloader_common_loader.c \ + components/bootloader_support/src/bootloader_console.c \ + components/bootloader_support/src/bootloader_console_loader.c \ + components/bootloader_support/src/bootloader_efuse_$(CPU).c \ + components/bootloader_support/src/bootloader_flash.c \ + components/bootloader_support/src/bootloader_flash_config_$(CPU).c \ + components/bootloader_support/src/bootloader_init.c \ + components/bootloader_support/src/bootloader_mem.c \ + components/bootloader_support/src/bootloader_panic.c \ + components/bootloader_support/src/bootloader_random.c \ + components/bootloader_support/src/bootloader_random_$(CPU).c \ + components/bootloader_support/src/bootloader_utility.c \ + components/bootloader_support/src/$(CPU)/bootloader_$(CPU).c \ + components/bootloader_support/src/$(CPU)/bootloader_sha.c \ + components/bootloader_support/src/$(CPU)/bootloader_soc.c \ + components/bootloader_support/src/esp_image_format.c \ + components/bootloader_support/src/flash_encrypt.c \ + components/bootloader_support/src/flash_partitions.c \ + components/bootloader_support/src/flash_qio_mode.c \ + components/bootloader_support/src/secure_boot.c \ + components/efuse/$(CPU)/esp_efuse_fields.c \ + components/efuse/$(CPU)/esp_efuse_table.c \ + components/efuse/$(CPU)/esp_efuse_utility.c \ + components/efuse/src/esp_efuse_api.c \ + components/efuse/src/esp_efuse_fields.c \ + components/efuse/src/esp_efuse_utility.c \ + components/esp_common/src/esp_err_to_name.c \ + components/esp_hw_support/compare_set.c \ + components/esp_hw_support/cpu_util.c \ + components/esp_hw_support/port/$(CPU)/chip_info.c \ + components/esp_hw_support/port/$(CPU)/rtc_clk.c \ + components/esp_hw_support/port/$(CPU)/rtc_clk_init.c \ + components/esp_hw_support/port/$(CPU)/rtc_init.c \ + components/esp_hw_support/port/$(CPU)/rtc_pm.c \ + components/esp_hw_support/port/$(CPU)/rtc_sleep.c \ + components/esp_hw_support/port/$(CPU)/rtc_time.c \ + components/esp_hw_support/port/$(CPU)/rtc_wdt.c \ + components/esp_rom/patches/esp_rom_crc.c \ + components/esp_rom/patches/esp_rom_sys.c \ + components/esp_rom/patches/esp_rom_tjpgd.c \ + components/esp_rom/patches/esp_rom_uart.c \ + components/esp_system/esp_err.c \ + components/hal/cpu_hal.c \ + components/hal/mpu_hal.c \ + components/hal/wdt_hal_iram.c \ + components/log/log_buffers.c \ + components/log/log.c \ + components/log/log_noos.c \ + components/newlib/syscalls.c \ + components/soc/$(CPU)/adc_periph.c \ + components/soc/$(CPU)/dac_periph.c \ + components/soc/$(CPU)/gpio_periph.c \ + components/soc/$(CPU)/i2c_periph.c \ + components/soc/$(CPU)/i2s_periph.c \ + components/soc/$(CPU)/interrupts.c \ + components/soc/$(CPU)/lcd_periph.c \ + components/soc/$(CPU)/ledc_periph.c \ + components/soc/$(CPU)/mcpwm_periph.c \ + components/soc/$(CPU)/pcnt_periph.c \ + components/soc/$(CPU)/rmt_periph.c \ + components/soc/$(CPU)/rtc_io_periph.c \ + components/soc/$(CPU)/sdio_slave_periph.c \ + components/soc/$(CPU)/sdmmc_periph.c \ + components/soc/$(CPU)/sigmadelta_periph.c \ + components/soc/$(CPU)/spi_periph.c \ + components/soc/$(CPU)/timer_periph.c \ + components/soc/$(CPU)/touch_sensor_periph.c \ + components/soc/$(CPU)/uart_periph.c \ + components/soc/lldesc.c \ + components/spi_flash/$(CPU)/spi_flash_rom_patch.c \ + components/xtensa/eri.c \ + components/xtensa/xt_trax.c \ + +ifneq (,$(filter esp32,$(CPU))) + ESP_SDK_BOOTLOADER_SRCS += components/efuse/src/esp_efuse_api_key_esp32.c +else + ESP_SDK_BOOTLOADER_SRCS += components/efuse/src/esp_efuse_api_key_esp32xx.c +endif + +ESP_SDK_BOOTLOADER_ASMSRC = \ + components/esp_rom/patches/esp_rom_longjmp.S \ + +# Bootloader sdkconfig.h defined in CURDIR directory. +INCLUDES = \ + -I$(dir $(RIOTBUILD_CONFIG_HEADER_C)) \ + -I$(CURDIR) \ + -I$(ESP32_SDK_DIR)/components \ + -I$(ESP32_SDK_DIR)/components/bootloader/subproject/components/micro-ecc \ + -I$(ESP32_SDK_DIR)/components/bootloader/subproject/components/micro-ecc/micro-ecc \ + -I$(ESP32_SDK_DIR)/components/bootloader_support/bootloader_flash/include \ + -I$(ESP32_SDK_DIR)/components/bootloader_support/include \ + -I$(ESP32_SDK_DIR)/components/bootloader_support/include_bootloader \ + -I$(ESP32_SDK_DIR)/components/efuse/include \ + -I$(ESP32_SDK_DIR)/components/efuse/private_include \ + -I$(ESP32_SDK_DIR)/components/efuse/$(CPU)/include \ + -I$(ESP32_SDK_DIR)/components/efuse/$(CPU)/private_include \ + -I$(ESP32_SDK_DIR)/components/esp_common/include \ + -I$(ESP32_SDK_DIR)/components/esp_hw_support/include \ + -I$(ESP32_SDK_DIR)/components/esp_hw_support/include/soc \ + -I$(ESP32_SDK_DIR)/components/esp_hw_support/include/soc/$(CPU) \ + -I$(ESP32_SDK_DIR)/components/esp_hw_support/port/$(CPU) \ + -I$(ESP32_SDK_DIR)/components/esp_hw_support/port/$(CPU)/private_include \ + -I$(ESP32_SDK_DIR)/components/esp_rom/$(CPU) \ + -I$(ESP32_SDK_DIR)/components/esp_rom/include \ + -I$(ESP32_SDK_DIR)/components/esp_rom/include/$(CPU) \ + -I$(ESP32_SDK_DIR)/components/hal/$(CPU)/include \ + -I$(ESP32_SDK_DIR)/components/hal/include \ + -I$(ESP32_SDK_DIR)/components/hal/platform_port/include \ + -I$(ESP32_SDK_DIR)/components/log/include \ + -I$(ESP32_SDK_DIR)/components/newlib/platform_include \ + -I$(ESP32_SDK_DIR)/components/soc/$(CPU)/. \ + -I$(ESP32_SDK_DIR)/components/soc/$(CPU)/include \ + -I$(ESP32_SDK_DIR)/components/soc/include \ + -I$(ESP32_SDK_DIR)/components/spi_flash/include \ + -I$(ESP32_SDK_DIR)/components/spi_flash/include/spi_flash \ + -I$(ESP32_SDK_DIR)/components/xtensa/$(CPU)/include \ + -I$(ESP32_SDK_DIR)/components/xtensa/include \ + # + +# BOOTLOADER_BUILD=1 signals to the SDK that's a bootloader build. +CFLAGS = \ + -include '$(RIOTBUILD_CONFIG_HEADER_C)' \ + -mlongcalls \ + -Wno-frame-address \ + -ffunction-sections \ + -fdata-sections \ + -Wall \ + -Werror=all \ + -Wno-error=unused-function \ + -Wno-error=unused-variable \ + -Wno-error=deprecated-declarations \ + -Wextra \ + -Wno-unused-parameter \ + -Wno-sign-compare \ + -ggdb \ + -Os \ + -freorder-blocks \ + -fstrict-volatile-bitfields \ + -Wno-error=unused-but-set-variable \ + -fno-jump-tables \ + -fno-tree-switch-conversion \ + -fno-stack-protector \ + -std=gnu99 \ + -Wno-old-style-declaration \ + -D_GNU_SOURCE \ + -DESP_PLATFORM \ + -DBOOTLOADER_BUILD=1 \ + -DRIOT_BOOTLOADER_BAUD=$(BOOTLOADER_BAUD) \ + -DRIOT_FLASH_SIZE=$(FLASH_SIZE) \ + -DWITH_POSIX \ + -DHAVE_CONFIG_H \ + -MD \ + -MT \ + # + +ifneq (,$(filter esp32 esp32s2 esp32s3,$(CPU))) + ESP_SDK_BOOTLOADER_ADD_LINK_FLAGS += -L$(ESP32_SDK_DIR)/components/xtensa/$(CPU) -lxt_hal +endif + +ifneq (,$(filter esp32 esp32s2,$(CPU))) + ESP_SDK_BOOTLOADER_ADD_LINK_FLAGS += \ + -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU)/ld/$(CPU).rom.newlib-funcs.ld \ + -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU)/ld/$(CPU).rom.spiflash.ld \ + # +endif + +# Bootloader link flags. We use the SDK source and linking files instead of the +# RIOT-OS ones to link the bootloader. Note that we also use the unmodified +# SDK libraries. +LINKFLAGS = \ + -mlongcalls \ + -Wno-frame-address \ + -o $(ESP_SDK_BOOTLOADER_DIR)/bootloader.elf \ + -Wl,--cref \ + -Wl,--defsym=IDF_TARGET_ESP32=0 \ + -Wl,--gc-sections \ + -fno-lto \ + -fno-rtti \ + -u __assert_func \ + -u abort \ + -u __ubsan_include \ + -u bootloader_hooks_include \ + -Wl,--start-group \ + $(ESP_SDK_BOOTLOADER_OBJS) \ + $(ESP_SDK_BOOTLOADER_ADDOBJS) \ + $(ESP_SDK_BOOTLOADER_ASMOBJS) \ + -Lgcc \ + $(ESP_SDK_BOOTLOADER_ADD_LINK_FLAGS) \ + -T$(ESP32_SDK_DIR)/components/bootloader/subproject/main/ld/$(CPU)/bootloader.ld \ + -T$(ESP32_SDK_DIR)/components/bootloader/subproject/main/ld/$(CPU)/bootloader.rom.ld \ + -T$(ESP32_SDK_DIR)/components/soc/$(CPU)/ld/$(CPU).peripherals.ld \ + -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU)/ld/$(CPU).rom.ld \ + -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU)/ld/$(CPU).rom.api.ld \ + -T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU)/ld/$(CPU).rom.libgcc.ld \ + -Wl,--end-group \ + -Wl,-EL \ + +# Build the bootloader on the application directory as it depends on the current +# app settings from riotbuild.h. +ESP_SDK_BOOTLOADER_DIR = $(BINDIR)/$(MODULE) +ESP_SDK_BOOTLOADER_BIN = $(ESP_SDK_BOOTLOADER_DIR)/bootloader.bin +ESP_SDK_BOOTLOADER_ELF = $(ESP_SDK_BOOTLOADER_DIR)/bootloader.elf + +# Objects that need to be filtered out because they are not part of the SDK +# but are used as submodules and required by the Secure Boot which is not yet +# supported due to a conflict of the packages `tinycrypt` and `micro-ecc` +ESP_SDK_BOOTLOADER_OBJ_FILTER = \ + components/bootloader/subproject/components/micro-ecc/uECC_verify_antifault.o \ + components/bootloader_support/src/secure_boot.o \ + components/bootloader_support/src/flash_encrypt.o \ + # + +ESP_SDK_BOOTLOADER_OBJS = \ + $(addprefix $(ESP_SDK_BOOTLOADER_DIR)/, \ + $(filter-out $(ESP_SDK_BOOTLOADER_OBJ_FILTER), \ + $(ESP_SDK_BOOTLOADER_SRCS:%.c=%.o))) + +ESP_SDK_BOOTLOADER_ASMOBJS = \ + $(addprefix $(ESP_SDK_BOOTLOADER_DIR)/, \ + $(ESP_SDK_BOOTLOADER_ASMSRC:%.S=%.o)) + +ESP_SDK_BOOTLOADER_ADDOBJS = \ + $(addprefix $(ESP_SDK_BOOTLOADER_DIR)/,stub.o) \ + +DEPS := $(ESP_SDK_BOOTLOADER_OBJS:%.o=%.d) $(ESP_SDK_BOOTLOADER_ASMOBJS:.o=.d) +-include $(DEPS) + +# Main module dependency. We only build the bootloader.bin from this module. +$(MODULE).module: $(ESP_SDK_BOOTLOADER_BIN) + +OBJ_DEPS += $(CURDIR)/sdkconfig.h + +$(ESP_SDK_BOOTLOADER_OBJS): \ +$(ESP_SDK_BOOTLOADER_DIR)/%.o: $(ESP32_SDK_DIR)/%.c $(OBJ_DEPS) + $(Q)mkdir -p $(dir $@) + $(Q)$(CCACHE) $(CC) \ + $(CFLAGS) $(INCLUDES) -MMD -MP -c $(abspath $<) -o $@ + +$(ESP_SDK_BOOTLOADER_ASMOBJS): \ +$(ESP_SDK_BOOTLOADER_DIR)/%.o: $(ESP32_SDK_DIR)/%.S + $(Q)mkdir -p $(dir $@) + $(Q)$(AS) $(ASFLAGS) -o $@ $(abspath $<) + +$(ESP_SDK_BOOTLOADER_ADDOBJS): \ +$(ESP_SDK_BOOTLOADER_DIR)/%.o: $(CURDIR)/stub.c $(OBJ_DEPS) + $(Q)mkdir -p $(dir $@) + $(Q)$(CCACHE) $(CC) \ + $(CFLAGS) $(INCLUDES) -MMD -MP -c $(abspath $<) -o $@ + +$(ESP_SDK_BOOTLOADER_DIR): + mkdir -p $@ + +$(ESP_SDK_BOOTLOADER_ELF): \ + $(ESP_SDK_BOOTLOADER_OBJS) $(ESP_SDK_BOOTLOADER_ASMOBJS) \ + $(ESP_SDK_BOOTLOADER_ADDOBJS) | $(ESP_SDK_BOOTLOADER_DIR) + $(Q)$(CC) -o $@ $(LINKFLAGS) -Wl,-Map=$(@:%.elf=%.map) + +FLASH_CHIP = $(CPU) +ESPTOOL ?= $(RIOTTOOLS)/esptools/esptool_v3.2.py +# TODO: These should be exported/configurable from the app side. That would +# require to export these values. +FLASH_MODE ?= dout +FLASH_FREQ ?= 40m +FLASH_SIZE ?= 4 + +# We use esptool to extract a version 1 app from the bootloader.elf. This is +# like the regular objdump binary file but it contains a 16 byte header which +# specifies the flash size, mode and speed that the ROM bootloader uses to load +# this second-stage bootloader image. +$(ESP_SDK_BOOTLOADER_BIN): $(ESP_SDK_BOOTLOADER_ELF) + $(Q)$(ESPTOOL) --chip $(FLASH_CHIP) elf2image --flash_mode $(FLASH_MODE) \ + --flash_size $(FLASH_SIZE)MB --flash_freq $(FLASH_FREQ) -o $@ $< diff --git a/cpu/esp32/bootloader/sdkconfig.h b/cpu/esp32/bootloader/sdkconfig.h new file mode 100644 index 0000000000..4e711d6580 --- /dev/null +++ b/cpu/esp32/bootloader/sdkconfig.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2021 iosabi + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup pkg_esp32_sdk + * @{ + * + * @file + * @brief RIOT-OS modification of the bootloader SDK configuration + * + * The bootloader build of the ESP32 SDK needs some settings from the SDK + * configuration. These are normally generated by the menuconfig in the vendor + * SDK. + * + * Some of these parameters are configurable by the application. For example, + * the UART baudrate used by the console and the verbose level of the + * bootloader. + * + * @author iosabi + */ + +#ifndef SDKCONFIG_H +#define SDKCONFIG_H + +#ifndef DOXYGEN + +#include "esp_idf_ver.h" +#include "sdkconfig_default.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if MODULE_ESP_LOG_COLORED +#define CONFIG_LOG_COLORS 1 +#endif + +#ifndef CONFIG_BOOTLOADER_LOG_LEVEL +/* + * SDK Log levels: + * + * 0 = NONE + * 1 = ERROR + * 2 = WARN + * 3 = INFO + * 4 = DEBUG + * 5 = VERBOSE + */ +#if MODULE_ESP_LOG_STARTUP +#define CONFIG_BOOTLOADER_LOG_LEVEL 3 /* INFO */ +#else +#define CONFIG_BOOTLOADER_LOG_LEVEL 0 /* NONE */ +#endif +#endif + +#if FLASH_MODE_QIO +#define CONFIG_FLASHMODE_QIO 1 +#define CONFIG_ESPTOOLPY_FLASHMODE_QIO 1 +#elif FLASH_MODE_QOUT +#define CONFIG_FLASHMODE_QOUT 1 +#define CONFIG_ESPTOOLPY_FLASHMODE_QOUT 1 +#elif FLASH_MODE_DIO +#define CONFIG_FLASHMODE_DIO 1 +#define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1 +#elif FLASH_MODE_DOUT +#define CONFIG_FLASHMODE_DOUT 1 +#define CONFIG_ESPTOOLPY_FLASHMODE_DOUT 1 +#else +#error "Unknown flash mode selected." +#endif + +/* + * Bootloader output baudrate, defined by the app settings as BAUD or + * BOOTLOADER_BAUD. + */ +#define CONFIG_ESP_CONSOLE_UART_BAUDRATE (RIOT_BOOTLOADER_BAUD) + +#ifdef __cplusplus +} +#endif + +#endif /* DOXYGEN */ +/** @} */ + +#endif /* SDKCONFIG_H */ diff --git a/cpu/esp32/bootloader/sdkconfig_default.h b/cpu/esp32/bootloader/sdkconfig_default.h new file mode 100644 index 0000000000..d4fdd96381 --- /dev/null +++ b/cpu/esp32/bootloader/sdkconfig_default.h @@ -0,0 +1,40 @@ +/* + * Generated by ./update_mk.sh, don't modify directly. + * Default CONFIG_ parameters from the SDK package. + */ + +#ifndef SDKCONFIG_DEFAULT_H +#define SDKCONFIG_DEFAULT_H + +#ifndef DOXYGEN + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ +#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 160 +#endif + +#define CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V 1 +#define CONFIG_BOOTLOADER_OFFSET_IN_FLASH 0x1000 +#define CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT 1 +#define CONFIG_CONSOLE_UART_NUM 0 +#define CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4 1 +#define CONFIG_EFUSE_MAX_BLK_LEN 192 +#define CONFIG_ESP_CONSOLE_UART 1 +#define CONFIG_ESP_CONSOLE_UART_NUM 0 +#define CONFIG_ESP32_DEBUG_OCDAWARE 1 +#define CONFIG_ESP32_XTAL_FREQ 40 +#define CONFIG_IDF_FIRMWARE_CHIP_ID 0x0000 +#define CONFIG_LOG_DEFAULT_LEVEL 3 +#define CONFIG_LOG_TIMESTAMP_SOURCE_RTOS 1 +#define CONFIG_PARTITION_TABLE_OFFSET 0x8000 +#define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1 + +#ifdef __cplusplus +} +#endif + +#endif /* DOXYGEN */ +#endif /* SDKCONFIG_DEFAULT_H */ diff --git a/cpu/esp32/bootloader/stub.c b/cpu/esp32/bootloader/stub.c new file mode 100644 index 0000000000..f7d6b2c6cb --- /dev/null +++ b/cpu/esp32/bootloader/stub.c @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2022 Gunar Schorcht + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +#define PTHREAD_CANCEL_DISABLE 1 +/* + * This is a dummy function to avoid undefined references when linking + * against newlib and module pthread is not used. + */ +int pthread_setcancelstate(int state, int *oldstate) +{ + if (oldstate) { + *oldstate = PTHREAD_CANCEL_DISABLE; + } + return 0; +} diff --git a/cpu/esp_common/Makefile.include b/cpu/esp_common/Makefile.include index b817fce4cb..9f7f45257e 100644 --- a/cpu/esp_common/Makefile.include +++ b/cpu/esp_common/Makefile.include @@ -132,8 +132,8 @@ $(ELFFILE).bin: $(ELFFILE) # Convert .elf and .csv to .bin files at build time, but make them available for # tests at flash time. These can't be added to FLASHDEPS because they depend on # on ELFFILE and would trigger a rebuild with "flash-only". -BUILD_FILES += $(FLASHFILE) $(BINDIR)/partitions.bin -TEST_EXTRA_FILES += $(FLASHFILE) $(BINDIR)/partitions.bin +BUILD_FILES += $(FLASHFILE) $(BINDIR)/partitions.bin $(BOOTLOADER_BIN) +TEST_EXTRA_FILES += $(FLASHFILE) $(BINDIR)/partitions.bin $(BOOTLOADER_BIN) # Default partition table with no OTA. Can be replaced with a custom partition # table setting PARTITION_TABLE_CSV. diff --git a/makefiles/tools/esptool.inc.mk b/makefiles/tools/esptool.inc.mk index 24d0853877..5f1bef7351 100644 --- a/makefiles/tools/esptool.inc.mk +++ b/makefiles/tools/esptool.inc.mk @@ -1,11 +1,15 @@ +ifneq ($(CPU),esp32) + ifneq (,$(filter esp_log_colored,$(USEMODULE))) BOOTLOADER_COLOR = _colors endif ifneq (,$(filter esp_log_startup,$(USEMODULE))) BOOTLOADER_INFO = _info endif - -BOOTLOADER_BIN = bootloader$(BOOTLOADER_COLOR)$(BOOTLOADER_INFO).bin +# Full path to the bootloader binary. In the ESP32 case this is set by the +# esp_bootloader module. +BOOTLOADER_BIN ?= $(RIOTCPU)/$(CPU)/bin/bootloader$(BOOTLOADER_COLOR)$(BOOTLOADER_INFO).bin +endif ESPTOOL ?= $(RIOTTOOLS)/esptools/esptool.py @@ -20,7 +24,7 @@ else 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 += $(BOOTLOADER_POS) $(BOOTLOADER_BIN) FFLAGS += 0x8000 $(BINDIR)/partitions.bin FFLAGS += 0x10000 $(FLASHFILE) endif @@ -45,7 +49,7 @@ else $(Q)dd if=/dev/zero bs=1M count=$(FLASH_SIZE) | \ tr "\\000" "\\377" > tmp.bin && cat tmp.bin | \ head -c $$(($(BOOTLOADER_POS))) | \ - cat - $(RIOTCPU)/$(CPU)/bin/$(BOOTLOADER_BIN) tmp.bin | \ + cat - $(BOOTLOADER_BIN) tmp.bin | \ head -c $$((0x8000)) | \ cat - $(BINDIR)/partitions.bin tmp.bin | \ head -c $$((0x10000)) | \