circuitpython/ports/espressif/Makefile
Jeff Epler 2b0f1cd087
espressif: fix dependencies in esp-idf modules
while developing esp-camera I had the problem that firmware.elf was
not regenerated if the only file I edited was in the esp32-camera
submodule.

By telling make that $(IDF_CMAKE_TARGETS), the list of .a fliles
produced by ninja-building esp-idf, depend on esp-idf-stamp and that
firmware.elf in turn depends on these files, the ninja build is re-run
on each make, which is reasonably quick if nothing needs to be rebuilt.
2023-08-02 07:52:45 -05:00

494 lines
18 KiB
Makefile

# This file is part of the MicroPython project, http://micropython.org/
#
# The MIT License (MIT)
#
# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
include ../../py/circuitpy_mkenv.mk
ifeq ($(IDF_TARGET),esp32c3)
IDF_TARGET_ARCH = riscv
CROSS_COMPILE = riscv32-esp-elf-
else
IDF_TARGET_ARCH = xtensa
CROSS_COMPILE = xtensa-$(IDF_TARGET)-elf-
endif
#######################################
# CFLAGS
#######################################
INC += \
-I.\
-I./boards \
-I./boards/$(BOARD) \
-I./peripherals \
-I../.. \
-I../../lib/mp-readline \
-I../../lib/tinyusb/src \
-I../../supervisor/shared/usb \
-I$(BUILD) \
-I$(BUILD)/genhdr \
-I$(BUILD)/esp-idf/config \
-isystem esp-idf \
-isystem esp-idf/components/app_update/include \
-isystem esp-idf/components/bootloader_support/include \
-isystem esp-idf/components/bt/include/$(IDF_TARGET)/include \
-isystem esp-idf/components/bt/host/nimble/esp-hci/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/controller/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/services/gap/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/include \
-isystem esp-idf/components/bt/host/nimble/nimble/nimble/host/util/include \
-isystem esp-idf/components/bt/host/nimble/nimble/porting/nimble/include \
-isystem esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/include \
-isystem esp-idf/components/bt/host/nimble/port/include \
-isystem esp-idf/components/driver/include \
-isystem esp-idf/components/driver/$(IDF_TARGET)/include \
-isystem esp-idf/components/efuse/include \
-isystem esp-idf/components/efuse/$(IDF_TARGET)/include \
-isystem esp-idf/components/$(IDF_TARGET)/include \
-isystem esp-idf/components/esp_adc_cal/include \
-isystem esp-idf/components/esp_common/include \
-isystem esp-idf/components/esp_event/include \
-isystem esp-idf/components/esp_hw_support/include \
-isystem esp-idf/components/esp_hw_support/include/soc \
-isystem esp-idf/components/esp_ipc/include \
-isystem esp-idf/components/esp_netif/include \
-isystem esp-idf/components/esp_pm/include \
-isystem esp-idf/components/esp_ringbuf/include \
-isystem esp-idf/components/esp_rom/include \
-isystem esp-idf/components/esp_system/include \
-isystem esp-idf/components/esp_timer/include \
-isystem esp-idf/components/esp_wifi/include \
-isystem esp-idf/components/freertos/include \
-isystem esp-idf/components/freertos/include/freertos \
-isystem esp-idf/components/freertos/include/esp_additions \
-isystem esp-idf/components/freertos/include/esp_additions/freertos \
-isystem esp-idf/components/freertos/port/$(IDF_TARGET_ARCH)/include \
-isystem esp-idf/components/hal/include \
-isystem esp-idf/components/hal/$(IDF_TARGET)/include \
-isystem esp-idf/components/hal/platform_port/include \
-isystem esp-idf/components/heap/include \
-isystem esp-idf/components/log/include \
-isystem esp-idf/components/lwip/include \
-isystem esp-idf/components/lwip/lwip/src/include \
-isystem esp-idf/components/lwip/port/esp32/include \
-isystem esp-idf/components/mbedtls/esp_crt_bundle/include \
-isystem esp-idf/components/mbedtls/mbedtls/include \
-isystem esp-idf/components/mbedtls/port/include \
-isystem esp-idf/components/newlib/platform_include \
-isystem esp-idf/components/nvs_flash/include \
-isystem esp-idf/components/soc/include \
-isystem esp-idf/components/soc/$(IDF_TARGET)/include \
-isystem esp-idf/components/spi_flash/include \
-isystem esp-idf/components/$(IDF_TARGET_ARCH)/include \
-isystem esp-idf/components/$(IDF_TARGET_ARCH)/$(IDF_TARGET)/include
# See https://github.com/espressif/esp-idf/issues/6906
ifeq ($(IDF_TARGET),esp32c3)
CFLAGS += -include "esp32c3_fix.h"
endif
CFLAGS += \
-DHAVE_CONFIG_H \
-DESP_PLATFORM=1 \
-DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" \
-DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX
# Make our canary value match FreeRTOS's
# This define is in FreeRTOS as tskSTACK_FILL_BYTE 0xa5U which we expand out to a full word.
CFLAGS += -DSTACK_CANARY_VALUE=0xa5a5a5a5
#Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -ggdb
ifeq ($(IDF_TARGET_ARCH),riscv)
OPTIMIZATION_FLAGS ?= -Os
CFLAGS += -DNDEBUG
else
OPTIMIZATION_FLAGS ?= -Og
CFLAGS += -DDEBUG
endif
# You may want to enable these flags to make setting breakpoints easier.
# CFLAGS += -fno-inline -fno-ipa-sra
else
CFLAGS += -DNDEBUG -ggdb3
# RISC-V is larger than xtensa
# Use -Os for RISC-V when it overflows
ifeq ($(IDF_TARGET_ARCH),riscv)
OPTIMIZATION_FLAGS ?= -Os
else
OPTIMIZATION_FLAGS ?= -O2
endif
endif
# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
CFLAGS += $(OPTIMIZATION_FLAGS)
CFLAGS += $(INC) -Werror -Wall -std=gnu11 -Wl,--gc-sections $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) -Werror=missing-prototypes
ifeq ($(IDF_TARGET_ARCH),xtensa)
CFLAGS += -mlongcalls
else ifeq ($(IDF_TARGET_ARCH),riscv)
CFLAGS += -march=rv32imc
endif
LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-Map=$@.map -Wl,-cref -Wl,--undefined=uxTopUsedPriority
LDFLAGS += \
-L$(BUILD)/esp-idf/esp-idf/esp_system/ld \
-Lesp-idf/components/esp_rom/$(IDF_TARGET)/ld \
-Lesp-idf/components/soc/$(IDF_TARGET)/ld \
-Tmemory.ld \
-Tsections.ld \
-T$(IDF_TARGET).peripherals.ld \
-T$(IDF_TARGET).rom.ld \
-T$(IDF_TARGET).rom.api.ld \
-T$(IDF_TARGET).rom.libgcc.ld \
-T$(IDF_TARGET).rom.newlib-nano.ld \
-Wl,-Bstatic \
-Wl,--no-warn-mismatch \
-Wl,--build-id=none \
-fno-rtti
ifeq ($(IDF_TARGET),esp32)
LDFLAGS += \
-T$(IDF_TARGET).rom.newlib-data.ld \
-T$(IDF_TARGET).rom.newlib-funcs.ld \
-T$(IDF_TARGET).rom.spiflash.ld
else ifeq ($(IDF_TARGET),esp32c3)
LDFLAGS += \
-Tesp32c3.rom.newlib.ld \
-Tesp32c3.rom.version.ld \
-Tesp32c3.rom.eco3.ld
else ifeq ($(IDF_TARGET),esp32s2)
LDFLAGS += \
-T$(IDF_TARGET).rom.newlib-data.ld \
-T$(IDF_TARGET).rom.newlib-funcs.ld \
-T$(IDF_TARGET).rom.spiflash.ld
else ifeq ($(IDF_TARGET),esp32s3)
LDFLAGS += \
-Tesp32s3.rom.newlib.ld \
-Tesp32s3.rom.version.ld
endif
LIBS := -lgcc -lc -lstdc++
# Use toolchain libm if we're not using our own.
ifndef INTERNAL_LIBM
LIBS += -lm
endif
# TinyUSB defines
ifeq ($(CIRCUITPY_USB),1)
ifeq ($(IDF_TARGET),esp32s2)
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32S2
else ifeq ($(IDF_TARGET),esp32s3)
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32S3
endif
CFLAGS += \
-DCFG_TUSB_OS=OPT_OS_FREERTOS \
-DCFG_TUD_CDC_RX_BUFSIZE=1024 \
-DCFG_TUD_CDC_TX_BUFSIZE=1024 \
-DCFG_TUD_MSC_BUFSIZE=4096 \
-DCFG_TUD_MIDI_RX_BUFSIZE=128 \
-DCFG_TUD_MIDI_TX_BUFSIZE=128 \
-DCFG_TUD_VENDOR_RX_BUFSIZE=128 \
-DCFG_TUD_VENDOR_TX_BUFSIZE=128 \
-DCFG_TUD_TASK_QUEUE_SZ=32
endif
######################################
# source
######################################
SRC_C += \
background.c \
mphalport.c \
boards/$(BOARD)/board.c \
boards/$(BOARD)/pins.c \
shared/netutils/netutils.c \
peripherals/i2c.c \
peripherals/rmt.c \
peripherals/timer.c \
peripherals/$(IDF_TARGET)/pins.c
ifneq ($(IDF_TARGET),esp32c3)
SRC_C += \
peripherals/pcnt.c \
peripherals/touch.c
ifeq ($(IDF_TARGET),esp32s2)
SRC_C += \
i2s_lcd_esp32s2_driver.c
endif
endif
ifeq ($(IDF_TARGET),esp32c3)
SRC_C += \
supervisor/usb_serial_jtag.c
endif
$(BUILD)/i2s_lcd_esp32s2_driver.o: CFLAGS += -Wno-sign-compare
ifneq ($(CIRCUITPY_USB),0)
SRC_C += lib/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c
endif
ifneq ($(CIRCUITPY_BLEIO),0)
SRC_C += common-hal/_bleio/ble_events.c
endif
ifneq ($(CIRCUITPY_ESPCAMERA),0)
SRC_CAMERA := \
$(wildcard common-hal/espcamera/*.c) \
$(wildcard bindings/espcamera/*.c)
SRC_C += $(SRC_CAMERA)
CFLAGS += -isystem esp32-camera/driver/include
CFLAGS += -isystem esp32-camera/conversions/include
endif
ifneq ($(CIRCUITPY_ESPIDF),0)
SRC_ESPIDF := \
$(wildcard common-hal/espidf/*.c) \
$(wildcard bindings/espidf/*.c)
SRC_C += $(SRC_ESPIDF)
endif
ifneq ($(CIRCUITPY_ESPNOW),0)
SRC_ESPNOW := \
$(wildcard common-hal/espnow/*.c) \
$(wildcard bindings/espnow/*.c)
SRC_C += $(SRC_ESPNOW)
endif
ifneq ($(CIRCUITPY_ESPULP),0)
SRC_ULP := \
$(wildcard common-hal/espulp/*.c) \
$(wildcard bindings/espulp/*.c)
SRC_C += $(SRC_ULP)
CFLAGS += -isystem esp-idf/components/ulp/include
CFLAGS += -isystem esp-idf/components/ulp/ulp_riscv/include
endif
SRC_COMMON_HAL_EXPANDED = \
$(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \
$(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \
$(addprefix common-hal/, $(SRC_COMMON_HAL))
SRC_SHARED_MODULE_EXPANDED = \
$(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
$(addprefix shared-module/, $(SRC_SHARED_MODULE)) \
$(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL))
ifneq ($(FROZEN_MPY_DIR),)
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
endif
OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
ifeq ($(INTERNAL_LIBM),1)
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
endif
OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os
$(BUILD)/lib/protomatter/src/core.o: CFLAGS += -DESP32
# List of sources for qstr extraction
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
# IDF build commands
IDF_PATH = $(realpath ./esp-idf)
# create the directory
$(BUILD)/esp-idf:
$(Q)$(MKDIR) -p $@
TARGET_SDKCONFIG = esp-idf-config/sdkconfig-$(IDF_TARGET).defaults
ifeq ($(CIRCUITPY_ESP_FLASH_SIZE), 2MB)
FLASH_SDKCONFIG ?= esp-idf-config/sdkconfig-$(CIRCUITPY_ESP_FLASH_SIZE)-no-ota-no-uf2.defaults
else
UF2_BOOTLOADER ?= $(CIRCUITPY_USB)
ifeq ($(UF2_BOOTLOADER), 1)
FLASH_SDKCONFIG ?= esp-idf-config/sdkconfig-$(CIRCUITPY_ESP_FLASH_SIZE).defaults
else
FLASH_SDKCONFIG ?= esp-idf-config/sdkconfig-$(CIRCUITPY_ESP_FLASH_SIZE)-no-uf2.defaults
endif
endif
ifeq ($(DEBUG), 1)
DEBUG_SDKCONFIG = esp-idf-config/sdkconfig-debug.defaults
else
DEBUG_SDKCONFIG = esp-idf-config/sdkconfig-opt.defaults
endif
SDKCONFIGS := esp-idf-config/sdkconfig.defaults;$(DEBUG_SDKCONFIG);$(FLASH_SDKCONFIG);$(TARGET_SDKCONFIG);boards/$(BOARD)/sdkconfig
ifneq ($(CIRCUITPY_BLEIO),0)
SDKCONFIGS := esp-idf-config/sdkconfig-ble.defaults;$(SDKCONFIGS)
endif
# create the config headers
.PHONY: do-sdkconfig
do-sdkconfig: $(BUILD)/esp-idf/config/sdkconfig.h
$(BUILD)/esp-idf/config/sdkconfig.h: boards/$(BOARD)/sdkconfig CMakeLists.txt | $(BUILD)/esp-idf
IDF_PATH=$(IDF_PATH) cmake -S . -B $(BUILD)/esp-idf -DSDKCONFIG=$(BUILD)/esp-idf/sdkconfig -DSDKCONFIG_DEFAULTS="$(SDKCONFIGS)" -DCMAKE_TOOLCHAIN_FILE=$(IDF_PATH)/tools/cmake/toolchain-$(IDF_TARGET).cmake -DIDF_TARGET=$(IDF_TARGET) -GNinja -DCIRCUITPY_ESPCAMERA=$(CIRCUITPY_ESPCAMERA)
# build a lib
# Adding -d explain -j 1 -v to the ninja line will output debug info
#$(BUILD)/esp-idf/esp-idf/%.a: $(BUILD)/esp-idf/config/sdkconfig.h
# ninja -C $(BUILD)/esp-idf esp-idf/$*.a
$(BUILD)/esp-idf/esp-idf/$(IDF_TARGET)/$(IDF_TARGET)_out.ld: $(BUILD)/esp-idf/config/sdkconfig.h
ninja -C $(BUILD)/esp-idf esp-idf/$(IDF_TARGET)/$(IDF_TARGET)_out.ld
$(BUILD)/esp-idf/esp-idf/$(IDF_TARGET)/ld/$(IDF_TARGET).project.ld: $(BUILD)/esp-idf/config/sdkconfig.h
ninja -C $(BUILD)/esp-idf esp-idf/$(IDF_TARGET)/ld/$(IDF_TARGET).project.ld
$(BUILD)/esp-idf/partition_table/partition-table.bin: $(BUILD)/esp-idf/config/sdkconfig.h
IDF_PATH=$(IDF_PATH) ninja -C $(BUILD)/esp-idf partition_table/partition-table.bin
# run menuconfig and then remove standard settings
menuconfig: $(BUILD)/esp-idf/config $(BUILD)/esp-idf/config/sdkconfig.h
$(Q)ninja -C $(BUILD)/esp-idf menuconfig
# Newer versions of the idf will have save-defconfig that will only include non-default values.
# We should use that when available. For now, we sort out everything.
python tools/update_sdkconfig.py --board=$(BOARD) --debug=$(DEBUG)
# qstr builds include headers so we need to make sure they are up to date
$(HEADER_BUILD)/qstr.split: | $(BUILD)/esp-idf/config/sdkconfig.h
BINARY_WIFI_BLOBS = libcoexist.a libcore.a libespnow.a libmesh.a libnet80211.a libpp.a libsmartconfig.a libwapi.a
BINARY_BLOBS = esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libphy.a $(addprefix esp-idf/components/esp_wifi/lib/$(IDF_TARGET)/, $(BINARY_WIFI_BLOBS))
ifeq ($(IDF_TARGET),esp32)
BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/librtc.a
endif
ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) app_update bootloader_support driver efuse esp_adc_cal esp_common esp_event esp_hw_support esp_ipc esp_netif esp_pm esp_phy esp_ringbuf esp_rom esp_system esp_timer esp-tls esp_wifi freertos hal heap log lwip mbedtls mdns newlib nvs_flash pthread soc spi_flash vfs wpa_supplicant
ifneq ($(CIRCUITPY_BLEIO),0)
ESP_IDF_COMPONENTS_LINK += bt
BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libbtbb.a \
esp-idf/components/bt/controller/lib_esp32c3_family/$(IDF_TARGET)/libbtdm_app.a
endif
ifneq ($(CIRCUITPY_ESPULP),0)
ESP_IDF_COMPONENTS_LINK += ulp
endif
ESP_IDF_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a)
MBEDTLS_COMPONENTS_LINK = crypto tls x509
MBEDTLS_COMPONENTS_LINK_EXPANDED = $(foreach component, $(MBEDTLS_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/mbedtls/mbedtls/library/libmbed$(component).a)
ifeq ($(IDF_TARGET_ARCH),xtensa)
BINARY_BLOBS += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a
ESP_IDF_COMPONENTS_EXPANDED += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a
endif
ifneq ($(CIRCUITPY_ESPCAMERA),0)
ESP_IDF_COMPONENTS_EXPANDED += $(BUILD)/esp-idf/esp-idf/esp32-camera/libesp32-camera.a
#$(error $(ESP_IDF_COMPONENTS_EXPANDED))
endif
ifneq ($(VALID_BOARD),)
# BOOTLOADER_OFFSET is determined by chip type, based on the ROM bootloader, and is not changeable.
ifeq ($(IDF_TARGET),esp32)
BOOTLOADER_OFFSET = 0x1000
else ifeq ($(IDF_TARGET),esp32c3)
BOOTLOADER_OFFSET = 0x0
else ifeq ($(IDF_TARGET),esp32s3)
BOOTLOADER_OFFSET = 0x0
else ifeq ($(IDF_TARGET),esp32s2)
BOOTLOADER_OFFSET = 0x1000
else
$(error unknown IDF_TARGET $(IDF_TARGET))
endif
endif
IDF_CMAKE_TARGETS = \
bootloader/bootloader.bin \
esp-idf/esp_system/__ldgen_output_sections.ld \
$(foreach component, $(ESP_IDF_COMPONENTS_LINK), esp-idf/$(component)/lib$(component).a)
PARTITION_TABLE_OFFSET = 0x8000
FIRMWARE_OFFSET = 0x10000
ESP_AUTOGEN_LD = $(BUILD)/esp-idf/esp-idf/$(IDF_TARGET)/$(IDF_TARGET)_out.ld $(BUILD)/esp-idf/esp-idf/$(IDF_TARGET)/ld/$(IDF_TARGET).project.ld
FLASH_FLAGS = --flash_mode $(CIRCUITPY_ESP_FLASH_MODE) --flash_freq $(CIRCUITPY_ESP_FLASH_FREQ) --flash_size $(CIRCUITPY_ESP_FLASH_SIZE)
ESPTOOL_FLAGS ?= --before=default_reset --after=no_reset --baud 921600
ifeq ($(UF2_BOOTLOADER),1)
all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2
else
all: $(BUILD)/firmware.bin
endif
$(IDF_CMAKE_TARGETS): esp-idf-stamp
.PHONY: esp-idf-stamp
esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h
$(Q)ninja -C $(BUILD)/esp-idf $(IDF_CMAKE_TARGETS)
$(BUILD)/firmware.elf: $(OBJ) | esp-idf-stamp $(IDF_CMAKE_TARGETS)
$(STEPECHO) "LINK $@"
$(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) $(MBEDTLS_COMPONENTS_LINK_EXPANDED) $(BUILD)/esp-idf/esp-idf/newlib/libnewlib.a -Wl,--end-group -u newlib_include_pthread_impl -u ld_include_highint_hdl -Wl,--start-group $(LIBS) -Wl,--end-group $(BUILD)/esp-idf/esp-idf/pthread/libpthread.a -u __cxx_fatal_exception
$(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf | tools/build_memory_info.py
$(STEPECHO) "Create $@"
$(Q)esptool.py --chip $(IDF_TARGET) elf2image $(FLASH_FLAGS) --elf-sha256-offset 0xb0 -o $@ $^
$(Q)$(PYTHON) tools/build_memory_info.py $< $(BUILD)/esp-idf/sdkconfig $@ $(BUILD)
ifeq ($(VALID_BOARD),)
$(BUILD)/firmware.bin: invalid-board
else
$(BUILD)/firmware.bin: $(BUILD)/circuitpython-firmware.bin | esp-idf-stamp
$(Q)$(PYTHON) ../../tools/join_bins.py $@ $(BOOTLOADER_OFFSET) $(BUILD)/esp-idf/bootloader/bootloader.bin $(PARTITION_TABLE_OFFSET) $(BUILD)/esp-idf/partition_table/partition-table.bin $(FIRMWARE_OFFSET) $(BUILD)/circuitpython-firmware.bin
endif
UF2_FAMILY_ID_esp32s2 = 0xbfdd4eee
UF2_FAMILY_ID_esp32s3 = 0xc47e5767
$(BUILD)/firmware.uf2: $(BUILD)/circuitpython-firmware.bin
$(STEPECHO) "Create $@"
$(Q)$(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID_$(IDF_TARGET)) -b 0x0000 -c -o $@ $^
flash: $(BUILD)/firmware.bin
esptool.py --chip $(IDF_TARGET) -p $(PORT) $(ESPTOOL_FLAGS) write_flash $(FLASH_FLAGS) 0x0000 $^
flash-circuitpython-only: $(BUILD)/circuitpython-firmware.bin
esptool.py --chip $(IDF_TARGET) -p $(PORT) $(ESPTOOL_FLAGS) write_flash $(FLASH_FLAGS) $(FIRMWARE_OFFSET) $^
monitor: $(BUILD)/firmware.elf
cp $< build/circuitpython.elf
idf.py monitor -p $(PORT)
include $(TOP)/py/mkrules.mk
# Print out the value of a make variable.
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
print-%:
@echo $* = $($*)