2020-03-19 12:22:36 +01:00
|
|
|
############################################################################
|
2021-02-03 15:55:59 +01:00
|
|
|
# tools/esp32/Config.mk
|
2020-03-19 12:22:36 +01:00
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership. The
|
|
|
|
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
# "License"); you may not use this file except in compliance with the
|
|
|
|
# License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
#
|
|
|
|
############################################################################
|
|
|
|
|
|
|
|
# These are the macros that will be used in the NuttX make system to compile
|
2020-08-27 13:41:30 +02:00
|
|
|
# and assemble source files and to insert the resulting object files into an
|
2020-03-19 12:22:36 +01:00
|
|
|
# archive. These replace the default definitions at tools/Config.mk
|
|
|
|
|
2021-03-01 14:03:50 +01:00
|
|
|
ifeq ($(CONFIG_ESP32_FLASH_2M),y)
|
|
|
|
FLASH_SIZE := 2MB
|
|
|
|
else ifeq ($(CONFIG_ESP32_FLASH_4M),y)
|
|
|
|
FLASH_SIZE := 4MB
|
|
|
|
else ifeq ($(CONFIG_ESP32_FLASH_8M),y)
|
|
|
|
FLASH_SIZE := 8MB
|
|
|
|
else ifeq ($(CONFIG_ESP32_FLASH_16M),y)
|
|
|
|
FLASH_SIZE := 16MB
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(CONFIG_ESP32_FLASH_MODE_DIO),y)
|
|
|
|
FLASH_MODE := dio
|
|
|
|
else ifeq ($(CONFIG_ESP32_FLASH_MODE_DOUT),y)
|
|
|
|
FLASH_MODE := dout
|
|
|
|
else ifeq ($(CONFIG_ESP32_FLASH_MODE_QIO),y)
|
|
|
|
FLASH_MODE := qio
|
|
|
|
else ifeq ($(CONFIG_ESP32_FLASH_MODE_QOUT),y)
|
|
|
|
FLASH_MODE := qout
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(CONFIG_ESP32_FLASH_FREQ_80M),y)
|
|
|
|
FLASH_FREQ := 80m
|
|
|
|
else ifeq ($(CONFIG_ESP32_FLASH_FREQ_40M),y)
|
|
|
|
FLASH_FREQ := 40m
|
|
|
|
else ifeq ($(CONFIG_ESP32_FLASH_FREQ_26M),y)
|
|
|
|
FLASH_FREQ := 26m
|
|
|
|
else ifeq ($(CONFIG_ESP32_FLASH_FREQ_20M),y)
|
|
|
|
FLASH_FREQ := 20m
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(CONFIG_ESP32_FLASH_DETECT),y)
|
2021-03-08 21:02:46 +01:00
|
|
|
ESPTOOL_WRITEFLASH_OPTS := -fs detect -fm dio -ff $(FLASH_FREQ)
|
2021-03-01 14:03:50 +01:00
|
|
|
else
|
2021-03-08 21:02:46 +01:00
|
|
|
ESPTOOL_WRITEFLASH_OPTS := -fs $(FLASH_SIZE) -fm dio -ff $(FLASH_FREQ)
|
2021-03-01 14:03:50 +01:00
|
|
|
endif
|
|
|
|
|
2021-09-08 11:28:41 +02:00
|
|
|
ESPTOOL_FLASH_OPTS := -fs $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ)
|
|
|
|
|
2021-06-23 20:26:33 +02:00
|
|
|
# Configure the variables according to build environment
|
|
|
|
|
2021-08-13 22:14:16 +02:00
|
|
|
ifdef ESPTOOL_BINDIR
|
|
|
|
ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y)
|
|
|
|
BL_OFFSET := 0x1000
|
|
|
|
PT_OFFSET := 0x8000
|
|
|
|
BOOTLOADER := $(ESPTOOL_BINDIR)/bootloader-esp32.bin
|
|
|
|
PARTITION_TABLE := $(ESPTOOL_BINDIR)/partition-table-esp32.bin
|
|
|
|
FLASH_BL := $(BL_OFFSET) $(BOOTLOADER)
|
|
|
|
FLASH_PT := $(PT_OFFSET) $(PARTITION_TABLE)
|
|
|
|
ESPTOOL_BINS := $(FLASH_BL) $(FLASH_PT)
|
|
|
|
else ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
|
|
|
|
BL_OFFSET := 0x1000
|
|
|
|
BOOTLOADER := $(ESPTOOL_BINDIR)/mcuboot-esp32.bin
|
|
|
|
FLASH_BL := $(BL_OFFSET) $(BOOTLOADER)
|
|
|
|
ESPTOOL_BINS := $(FLASH_BL)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2021-08-13 21:56:53 +02:00
|
|
|
ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y)
|
2021-08-13 22:14:16 +02:00
|
|
|
APP_OFFSET := 0x10000
|
|
|
|
APP_IMAGE := nuttx.bin
|
|
|
|
FLASH_APP := $(APP_OFFSET) $(APP_IMAGE)
|
2021-06-23 20:26:33 +02:00
|
|
|
else ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
|
|
|
|
ifeq ($(CONFIG_ESP32_ESPTOOL_TARGET_PRIMARY),y)
|
2021-08-13 22:14:16 +02:00
|
|
|
VERIFIED := --confirm
|
|
|
|
APP_OFFSET := $(CONFIG_ESP32_OTA_PRIMARY_SLOT_OFFSET)
|
2021-06-23 20:26:33 +02:00
|
|
|
else ifeq ($(CONFIG_ESP32_ESPTOOL_TARGET_SECONDARY),y)
|
2021-08-13 22:14:16 +02:00
|
|
|
VERIFIED :=
|
|
|
|
APP_OFFSET := $(CONFIG_ESP32_OTA_SECONDARY_SLOT_OFFSET)
|
2021-06-23 20:26:33 +02:00
|
|
|
endif
|
|
|
|
|
2021-08-31 16:41:21 +02:00
|
|
|
APP_IMAGE := nuttx.signed.bin
|
2021-08-13 22:14:16 +02:00
|
|
|
FLASH_APP := $(APP_OFFSET) $(APP_IMAGE)
|
2020-03-22 22:47:51 +01:00
|
|
|
endif
|
2020-03-19 12:22:36 +01:00
|
|
|
|
2021-08-13 22:14:16 +02:00
|
|
|
ESPTOOL_BINS += $(FLASH_APP)
|
|
|
|
|
2021-09-02 00:19:47 +02:00
|
|
|
# MERGEBIN -- Merge raw binary files into a single file
|
|
|
|
|
|
|
|
define MERGEBIN
|
|
|
|
$(Q) if [ -z $(ESPTOOL_BINDIR) ]; then \
|
|
|
|
echo "MERGEBIN error: Missing argument for binary files directory."; \
|
|
|
|
echo "USAGE: make ESPTOOL_BINDIR=<dir>"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
$(Q) if [ -z $(FLASH_SIZE) ]; then \
|
|
|
|
echo "Missing Flash memory size configuration for the ESP32 chip."; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
2021-10-14 18:13:31 +02:00
|
|
|
$(eval ESPTOOL_MERGEBIN_OPTS := \
|
|
|
|
$(if $(CONFIG_ESP32_QEMU_IMAGE), \
|
|
|
|
--fill-flash-size $(FLASH_SIZE) -fm $(FLASH_MODE) -ff $(FLASH_FREQ), \
|
|
|
|
$(ESPTOOL_FLASH_OPTS) \
|
|
|
|
) \
|
|
|
|
)
|
|
|
|
esptool.py -c esp32 merge_bin --output nuttx.merged.bin $(ESPTOOL_MERGEBIN_OPTS) $(ESPTOOL_BINS)
|
2021-09-02 00:19:47 +02:00
|
|
|
$(Q) echo nuttx.merged.bin >> nuttx.manifest
|
|
|
|
|
2021-10-14 18:13:31 +02:00
|
|
|
$(Q) if [ "$(CONFIG_ESP32_QEMU_IMAGE)" = "y" ]; then \
|
|
|
|
echo "Generated: nuttx.merged.bin (QEMU compatible)"; \
|
|
|
|
else \
|
|
|
|
echo "Generated: nuttx.merged.bin"; \
|
|
|
|
fi
|
2021-09-02 00:19:47 +02:00
|
|
|
endef
|
|
|
|
|
2021-09-04 12:28:53 +02:00
|
|
|
# SIGNBIN -- Sign the binary image file
|
2021-02-05 18:46:26 +01:00
|
|
|
|
2021-06-23 20:26:33 +02:00
|
|
|
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
|
2021-09-04 12:28:53 +02:00
|
|
|
define SIGNBIN
|
2021-06-23 20:26:33 +02:00
|
|
|
$(Q) echo "MKIMAGE: ESP32 binary"
|
|
|
|
$(Q) if ! imgtool version 1>/dev/null 2>&1; then \
|
|
|
|
echo ""; \
|
|
|
|
echo "imgtool not found. Please run: \"pip install imgtool\""; \
|
|
|
|
echo ""; \
|
2021-08-31 16:41:21 +02:00
|
|
|
echo "Run make again to create the nuttx.signed.bin image."; \
|
2021-06-23 20:26:33 +02:00
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
imgtool sign --pad --pad-sig $(VERIFIED) --align 4 -v 0 \
|
|
|
|
-H $(CONFIG_ESP32_APP_MCUBOOT_HEADER_SIZE) --pad-header \
|
|
|
|
-S $(CONFIG_ESP32_OTA_SLOT_SIZE) \
|
2021-08-31 16:41:21 +02:00
|
|
|
nuttx.bin nuttx.signed.bin
|
2021-09-03 21:45:08 +02:00
|
|
|
$(Q) echo nuttx.signed.bin >> nuttx.manifest
|
2021-08-31 16:41:21 +02:00
|
|
|
$(Q) echo "Generated: nuttx.signed.bin (MCUboot compatible)"
|
2021-06-23 20:26:33 +02:00
|
|
|
endef
|
2021-09-04 12:28:53 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
# ELF2IMAGE -- Convert an ELF file into a binary file in Espressif application image format
|
|
|
|
|
|
|
|
ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y)
|
|
|
|
define ELF2IMAGE
|
2021-02-04 02:01:44 +01:00
|
|
|
$(Q) echo "MKIMAGE: ESP32 binary"
|
2021-02-03 23:12:14 +01:00
|
|
|
$(Q) if ! esptool.py version 1>/dev/null 2>&1; then \
|
2020-03-19 12:22:36 +01:00
|
|
|
echo ""; \
|
2021-02-08 14:34:24 +01:00
|
|
|
echo "esptool.py not found. Please run: \"pip install esptool\""; \
|
2020-03-19 12:22:36 +01:00
|
|
|
echo ""; \
|
2021-02-03 23:12:14 +01:00
|
|
|
echo "Run make again to create the nuttx.bin image."; \
|
2021-02-04 20:18:32 +01:00
|
|
|
exit 1; \
|
2020-03-19 12:22:36 +01:00
|
|
|
fi
|
2021-02-09 19:39:32 +01:00
|
|
|
$(Q) if [ -z $(FLASH_SIZE) ]; then \
|
|
|
|
echo "Missing Flash memory size configuration for the ESP32 chip."; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
2021-09-08 11:28:41 +02:00
|
|
|
esptool.py -c esp32 elf2image $(ESPTOOL_FLASH_OPTS) -o nuttx.bin nuttx
|
2021-02-09 19:39:32 +01:00
|
|
|
$(Q) echo "Generated: nuttx.bin (ESP32 compatible)"
|
2021-09-04 12:28:53 +02:00
|
|
|
endef
|
|
|
|
endif
|
|
|
|
|
|
|
|
# POSTBUILD -- Perform post build operations
|
|
|
|
|
|
|
|
ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
|
|
|
|
define POSTBUILD
|
|
|
|
$(call SIGNBIN)
|
2021-10-14 18:13:31 +02:00
|
|
|
$(if $(CONFIG_ESP32_MERGE_BINS), $(call MERGEBIN), )
|
2021-09-04 12:28:53 +02:00
|
|
|
endef
|
|
|
|
else ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y)
|
|
|
|
define POSTBUILD
|
|
|
|
$(call ELF2IMAGE)
|
2021-10-14 18:13:31 +02:00
|
|
|
$(if $(CONFIG_ESP32_MERGE_BINS), $(call MERGEBIN), )
|
2020-03-19 12:22:36 +01:00
|
|
|
endef
|
2021-06-23 20:26:33 +02:00
|
|
|
endif
|
2021-02-05 18:46:26 +01:00
|
|
|
|
|
|
|
# ESPTOOL_BAUD -- Serial port baud rate used when flashing/reading via esptool.py
|
|
|
|
|
|
|
|
ESPTOOL_BAUD ?= 921600
|
|
|
|
|
2021-10-14 15:57:21 +02:00
|
|
|
# FLASH -- Download a binary image via esptool.py
|
2021-02-05 18:46:26 +01:00
|
|
|
|
2021-10-14 15:57:21 +02:00
|
|
|
define FLASH
|
2021-02-05 18:46:26 +01:00
|
|
|
$(Q) if [ -z $(ESPTOOL_PORT) ]; then \
|
2021-10-14 15:57:21 +02:00
|
|
|
echo "FLASH error: Missing serial port device argument."; \
|
|
|
|
echo "USAGE: make flash ESPTOOL_PORT=<port> [ ESPTOOL_BAUD=<baud> ] [ ESPTOOL_BINDIR=<dir> ]"; \
|
2021-02-05 18:46:26 +01:00
|
|
|
exit 1; \
|
|
|
|
fi
|
2021-03-01 14:03:50 +01:00
|
|
|
esptool.py -c esp32 -p $(ESPTOOL_PORT) -b $(ESPTOOL_BAUD) write_flash $(ESPTOOL_WRITEFLASH_OPTS) $(ESPTOOL_BINS)
|
2021-02-05 18:46:26 +01:00
|
|
|
endef
|