Update and extend the README
[apeos.git] / components / esptool_py / Makefile.projbuild
blobc36ea4551f4790d2474cc6faf255470d25acfc17
1 # Copyright 2016-2017 Espressif Systems (Shanghai) PTE LTD
2 # Copyright 2018 apeos contributors
4 # Component support for esptool.py. Doesn't do much by itself,
5 # components have their own flash targets that can use these variables.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 #     http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 ESPPORT ?= $(CONFIG_ESPTOOLPY_PORT)
20 ESPBAUD ?= $(CONFIG_ESPTOOLPY_BAUD)
21 ESPFLASHMODE ?= $(CONFIG_ESPTOOLPY_FLASHMODE)
22 ESPFLASHFREQ ?= $(CONFIG_ESPTOOLPY_FLASHFREQ)
23 ESPFLASHSIZE ?= $(CONFIG_ESPTOOLPY_FLASHSIZE)
25 CONFIG_ESPTOOLPY_COMPRESSED ?=
27 PYTHON ?= $(call dequote,$(CONFIG_PYTHON))
29 # two commands that can be used from other components
30 # to invoke esptool.py (with or without serial port args)
32 ESPTOOLPY_SRC := $(COMPONENT_PATH)/esptool/esptool.py
33 ESPTOOLPY := $(PYTHON) $(ESPTOOLPY_SRC) --chip esp32
34 ESPTOOLPY_SERIAL := $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD) --before $(CONFIG_ESPTOOLPY_BEFORE) --after $(CONFIG_ESPTOOLPY_AFTER)
36 # Supporting esptool command line tools
37 ESPEFUSEPY := $(PYTHON) $(COMPONENT_PATH)/esptool/espefuse.py
38 ESPSECUREPY := $(PYTHON) $(COMPONENT_PATH)/esptool/espsecure.py
39 export ESPSECUREPY  # is used in bootloader_support component
41 ESPTOOL_FLASH_OPTIONS := --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size $(ESPFLASHSIZE)
42 ifdef CONFIG_ESPTOOLPY_FLASHSIZE_DETECT
43 ESPTOOL_WRITE_FLASH_OPTIONS := --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size detect
44 else
45 ESPTOOL_WRITE_FLASH_OPTIONS := $(ESPTOOL_FLASH_OPTIONS)
46 endif
48 ESPTOOL_ELF2IMAGE_OPTIONS :=
50 ESPTOOLPY_WRITE_FLASH=$(ESPTOOLPY_SERIAL) write_flash $(if $(CONFIG_ESPTOOLPY_COMPRESSED),-z,-u) $(ESPTOOL_WRITE_FLASH_OPTIONS)
52 ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
53 ifndef IS_BOOTLOADER_BUILD
54 # for locally signed secure boot image, add a signing step to get from unsigned app to signed app
55 APP_BIN_UNSIGNED := $(APP_BIN:.bin=-unsigned.bin)
57 $(APP_BIN): $(APP_BIN_UNSIGNED) $(SECURE_BOOT_SIGNING_KEY) $(SDKCONFIG_MAKEFILE)
58         $(ESPSECUREPY) sign_data --keyfile $(SECURE_BOOT_SIGNING_KEY) -o $@ $<
59 endif
60 endif
61 # non-secure boot (or bootloader), both these files are the same
62 APP_BIN_UNSIGNED ?= $(APP_BIN)
64 $(APP_BIN_UNSIGNED): $(APP_ELF) $(ESPTOOLPY_SRC)
65         $(ESPTOOLPY) elf2image $(ESPTOOL_FLASH_OPTIONS) $(ESPTOOL_ELF2IMAGE_OPTIONS) -o $@ $<
67 flash: all_binaries $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash)
68         @echo "Flashing binaries to serial port $(ESPPORT)..."
69 ifdef CONFIG_SECURE_BOOT_ENABLED
70         @echo "(Secure boot enabled, so bootloader not flashed automatically. See 'make bootloader' output)"
71 endif
72         $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS)
75 # Submodules normally added in component.mk, but can be added
76 # at the project level as long as qualified path
77 COMPONENT_SUBMODULES += $(COMPONENT_PATH)/esptool
79 erase_flash:
80         @echo "Erasing entire flash..."
81         $(ESPTOOLPY_SERIAL) erase_flash
83 MONITORBAUD ?= $(CONFIG_MONITOR_BAUD)
85 MONITOR_PYTHON := $(PYTHON)
87 ifeq ("$(OS)","Windows_NT")
88 # miniterm and idf_monitor both need a Windows Console PTY in order
89 # to correctly handle user input
90 MONITOR_PYTHON := winpty $(PYTHON)
91 endif
93 # note: if you want to run miniterm from command line, can simply run
94 # miniterm.py on the console. The '$(PYTHON) -m serial.tools.miniterm'
95 # is to allow for the $(PYTHON) variable overriding the python path.
96 simple_monitor: $(call prereq_if_explicit,%flash)
97         $(MONITOR_PYTHON) -m serial.tools.miniterm --rts 0 --dtr 0 --raw $(ESPPORT) $(MONITORBAUD)
99 MONITOR_OPTS := --baud $(MONITORBAUD) --port $(ESPPORT) --toolchain-prefix $(CONFIG_TOOLPREFIX) --make "$(MAKE)"
101 monitor: $(call prereq_if_explicit,%flash)
102         $(summary) MONITOR
103         [ -f $(APP_ELF) ] || echo "*** 'make monitor' target requires an app to be compiled and flashed first."
104         [ -f $(APP_ELF) ] || echo "*** Run 'make flash monitor' to build, flash and monitor"
105         [ -f $(APP_ELF) ] || echo "*** Or alternatively 'make simple_monitor' to view the serial port as-is."
106         [ -f $(APP_ELF) ] || exit 1
107         $(MONITOR_PYTHON) $(IDF_PATH)/tools/idf_monitor.py $(MONITOR_OPTS) $(APP_ELF)
109 .PHONY: erase_flash