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