Skip to content

Commit e2ecce7

Browse files
committed
cpu/esp32: variant independent bootloader makefile
Bootloader makefile that can be used for different ESP32x variants
1 parent 79ee2d0 commit e2ecce7

File tree

1 file changed

+53
-22
lines changed

1 file changed

+53
-22
lines changed

cpu/esp32/bootloader/Makefile

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ ESP_SDK_BOOTLOADER_SRCS = \
5757
components/esp_hw_support/port/$(CPU)/rtc_pm.c \
5858
components/esp_hw_support/port/$(CPU)/rtc_sleep.c \
5959
components/esp_hw_support/port/$(CPU)/rtc_time.c \
60-
components/esp_hw_support/port/$(CPU)/rtc_wdt.c \
6160
components/esp_rom/patches/esp_rom_crc.c \
6261
components/esp_rom/patches/esp_rom_sys.c \
6362
components/esp_rom/patches/esp_rom_tjpgd.c \
@@ -71,38 +70,56 @@ ESP_SDK_BOOTLOADER_SRCS = \
7170
components/log/log_noos.c \
7271
components/newlib/syscalls.c \
7372
components/soc/$(CPU)/adc_periph.c \
74-
components/soc/$(CPU)/dac_periph.c \
7573
components/soc/$(CPU)/gpio_periph.c \
7674
components/soc/$(CPU)/i2c_periph.c \
7775
components/soc/$(CPU)/i2s_periph.c \
7876
components/soc/$(CPU)/interrupts.c \
79-
components/soc/$(CPU)/lcd_periph.c \
8077
components/soc/$(CPU)/ledc_periph.c \
81-
components/soc/$(CPU)/mcpwm_periph.c \
82-
components/soc/$(CPU)/pcnt_periph.c \
8378
components/soc/$(CPU)/rmt_periph.c \
84-
components/soc/$(CPU)/rtc_io_periph.c \
85-
components/soc/$(CPU)/sdio_slave_periph.c \
86-
components/soc/$(CPU)/sdmmc_periph.c \
8779
components/soc/$(CPU)/sigmadelta_periph.c \
8880
components/soc/$(CPU)/spi_periph.c \
8981
components/soc/$(CPU)/timer_periph.c \
90-
components/soc/$(CPU)/touch_sensor_periph.c \
9182
components/soc/$(CPU)/uart_periph.c \
9283
components/soc/lldesc.c \
9384
components/spi_flash/$(CPU)/spi_flash_rom_patch.c \
94-
components/xtensa/eri.c \
95-
components/xtensa/xt_trax.c \
85+
#
86+
87+
ifneq (,$(filter xtensa%,$(TARGET_ARCH)))
88+
ESP_SDK_BOOTLOADER_SRCS += components/esp_hw_support/port/$(CPU)/rtc_wdt.c
89+
ESP_SDK_BOOTLOADER_SRCS += components/soc/$(CPU)/lcd_periph.c
90+
ESP_SDK_BOOTLOADER_SRCS += components/soc/$(CPU)/pcnt_periph.c
91+
ESP_SDK_BOOTLOADER_SRCS += components/soc/$(CPU)/rtc_io_periph.c
92+
ESP_SDK_BOOTLOADER_SRCS += components/soc/$(CPU)/touch_sensor_periph.c
93+
ESP_SDK_BOOTLOADER_SRCS += components/xtensa/eri.c
94+
ESP_SDK_BOOTLOADER_SRCS += components/xtensa/xt_trax.c
95+
else
96+
ESP_SDK_BOOTLOADER_SRCS += components/esp_hw_support/port/$(CPU)/cpu_util_$(CPU).c
97+
endif
98+
99+
ifneq (,$(filter esp32 esp32s2,$(CPU)))
100+
ESP_SDK_BOOTLOADER_SRCS += components/soc/$(CPU)/dac_periph.c
101+
endif
102+
103+
ifneq (,$(filter esp32 esp32s3,$(CPU)))
104+
ESP_SDK_BOOTLOADER_SRCS += components/soc/$(CPU)/mcpwm_periph.c
105+
ESP_SDK_BOOTLOADER_SRCS += components/soc/$(CPU)/sdio_slave_periph.c
106+
ESP_SDK_BOOTLOADER_SRCS += components/soc/$(CPU)/sdmmc_periph.c
107+
endif
108+
109+
ifneq (,$(filter esp32c3 esp32h2 esp32s3,$(CPU)))
110+
ESP_SDK_BOOTLOADER_SRCS += components/efuse/$(CPU)/esp_efuse_rtc_calib.c
111+
endif
96112

97113
ifneq (,$(filter esp32,$(CPU)))
98114
ESP_SDK_BOOTLOADER_SRCS += components/efuse/src/esp_efuse_api_key_esp32.c
115+
ESP_SDK_BOOTLOADER_ASMSRC = components/esp_rom/patches/esp_rom_longjmp.S
99116
else
100117
ESP_SDK_BOOTLOADER_SRCS += components/efuse/src/esp_efuse_api_key_esp32xx.c
118+
ESP_SDK_BOOTLOADER_SRCS += components/soc/$(CPU)/dedic_gpio_periph.c
119+
ESP_SDK_BOOTLOADER_SRCS += components/soc/$(CPU)/gdma_periph.c
120+
ESP_SDK_BOOTLOADER_SRCS += components/soc/soc_include_legacy_warn.c
101121
endif
102122

103-
ESP_SDK_BOOTLOADER_ASMSRC = \
104-
components/esp_rom/patches/esp_rom_longjmp.S \
105-
106123
# Bootloader sdkconfig.h defined in CURDIR directory.
107124
INCLUDES = \
108125
-I$(dir $(RIOTBUILD_CONFIG_HEADER_C)) \
@@ -136,14 +153,27 @@ INCLUDES = \
136153
-I$(ESP32_SDK_DIR)/components/soc/include \
137154
-I$(ESP32_SDK_DIR)/components/spi_flash/include \
138155
-I$(ESP32_SDK_DIR)/components/spi_flash/include/spi_flash \
139-
-I$(ESP32_SDK_DIR)/components/xtensa/$(CPU)/include \
140-
-I$(ESP32_SDK_DIR)/components/xtensa/include \
141156
#
142157

158+
CFLAGS = -include '$(RIOTBUILD_CONFIG_HEADER_C)' \
159+
160+
ifneq (,$(filter riscv32%,$(TARGET_ARCH)))
161+
INCLUDES += -I$(ESP32_SDK_DIR)/components/riscv/include
162+
CFLAGS += -DCONFIG_IDF_TARGET_ARCH_RISCV
163+
CFLAGS += -march=rv32imc
164+
CFLAGS += -Wno-error=format=
165+
CFLAGS += -nostartfiles
166+
CFLAGS += -Wno-format
167+
endif
168+
169+
ifneq (,$(filter xtensa%,$(TARGET_ARCH)))
170+
INCLUDES += -I$(ESP32_SDK_DIR)/components/xtensa/include
171+
INCLUDES += -I$(ESP32_SDK_DIR)/components/xtensa/$(CPU)/include
172+
CFLAGS += -mlongcalls -mtext-section-literals
173+
endif
174+
143175
# BOOTLOADER_BUILD=1 signals to the SDK that's a bootloader build.
144-
CFLAGS = \
145-
-include '$(RIOTBUILD_CONFIG_HEADER_C)' \
146-
-mlongcalls \
176+
CFLAGS += \
147177
-Wno-frame-address \
148178
-ffunction-sections \
149179
-fdata-sections \
@@ -176,11 +206,13 @@ CFLAGS = \
176206
-MT \
177207
#
178208

179-
ifneq (,$(filter esp32 esp32s2 esp32s3,$(CPU)))
209+
ifneq (,$(filter xtensa%,$(TARGET_ARCH)))
210+
LINKFLAGS = -mlongcalls
180211
ESP_SDK_BOOTLOADER_ADD_LINK_FLAGS += -L$(ESP32_SDK_DIR)/components/xtensa/$(CPU) -lxt_hal
181212
endif
182213

183214
ifneq (,$(filter esp32 esp32s2,$(CPU)))
215+
LINKFLAGS =
184216
ESP_SDK_BOOTLOADER_ADD_LINK_FLAGS += \
185217
-T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU)/ld/$(CPU).rom.newlib-funcs.ld \
186218
-T$(ESP32_SDK_DIR)/components/esp_rom/$(CPU)/ld/$(CPU).rom.spiflash.ld \
@@ -190,8 +222,7 @@ endif
190222
# Bootloader link flags. We use the SDK source and linking files instead of the
191223
# RIOT-OS ones to link the bootloader. Note that we also use the unmodified
192224
# SDK libraries.
193-
LINKFLAGS = \
194-
-mlongcalls \
225+
LINKFLAGS += \
195226
-Wno-frame-address \
196227
-o $(ESP_SDK_BOOTLOADER_DIR)/bootloader.elf \
197228
-Wl,--cref \

0 commit comments

Comments
 (0)