make: 'make all' default target builds everything, 'make flash' flashes everything

Also added 'make help' target which prints some useful usage summary.
pull/2/merge
Angus Gratton 2016-08-18 17:11:27 +08:00
rodzic 73001bcda2
commit 14eb490bb3
7 zmienionych plików z 78 dodań i 47 usunięć

Wyświetl plik

@ -8,27 +8,30 @@
# Compiling your project
`make app`
`make all`
# Flashing the Bootloader
... will compile app, bootloader and generate a partition table based on the config.
ESP32 has a bootloader in ROM which runs after reset, but ESP-IDF also uses a second stage software bootloader. The ROM bootloader loads the software bootloader, which then loads the firmware app of the ESP32. The software bootloader must be flashed to offset 0x5000 in the flash.
# Flashing your project
To build the software bootloader, navigate to your project's top-level directory and run:
When `make all` finishes, it will print a command line to use esptool.py to flash the chip. However you can also do this from make by running:
``` shell
make bootloader
```
`make flash`
If you've configured the serial port details in `make menuconfig`, then
This will flash the entire project (app, bootloader and partition table) to a new chip. The settings for serial port flashing can be configured with `make menuconfig`.
``` shell
make bootloader-flash
```
You don't need to run `make all` before running `make flash`, `make flash` will automatically rebuild anything which needs it.
... will automatically run esptool.py to flash the image. Otherwise, you can customise the `esptool.py` command that is printed out as part of `make bootloader`.
# Compiling & Flashing Just the App
You only need to flash the ESP32 bootloader once.
After the initial flash, you may just want to build and flash just your app, not the bootloader and partition table:
* `make app` - build just the app.
* `make app-flash` - flash just the app.
`make app-flash` will automatically rebuild the app if it needs it.
(There's no downside to reflashing the bootloader and partition table each time, if they haven't changed.)
# The Partition Table

Wyświetl plik

@ -10,7 +10,6 @@
#
BOOTLOADER_COMPONENT_PATH := $(COMPONENT_PATH)
EXTRA_CLEAN_TARGETS += bootloader-clean
BOOTLOADER_BUILD_DIR=$(BUILD_DIR_BASE)/bootloader
BOOTLOADER_BIN=$(BOOTLOADER_BUILD_DIR)/bootloader.bin
@ -23,7 +22,7 @@ $(BOOTLOADER_BIN): $(COMPONENT_PATH)/src/sdkconfig
LDFLAGS= \
CFLAGS= \
BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) \
make -C $(BOOTLOADER_COMPONENT_PATH)/src MAKEFLAGS= V=$(V) TARGET_BIN_LAYOUT="$(BOOTLOADER_TARGET_BIN_LAYOUT)"
make -C $(BOOTLOADER_COMPONENT_PATH)/src MAKEFLAGS= V=$(V) TARGET_BIN_LAYOUT="$(BOOTLOADER_TARGET_BIN_LAYOUT)" $(BOOTLOADER_BIN)
bootloader-clean:
$(Q) PROJECT_PATH= \
@ -34,10 +33,16 @@ bootloader-clean:
BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) \
make -C $(BOOTLOADER_COMPONENT_PATH)/src clean MAKEFLAGS= V=$(V)
clean: bootloader-clean
bootloader: $(BOOTLOADER_BIN)
@echo "Bootloader built. Default flash command is:"
@echo "$(ESPTOOLPY_SERIAL) write_flash 0x1000 $(BOOTLOADER_BIN)"
all_binaries: $(BOOTLOADER_BIN)
ESPTOOL_ALL_FLASH_ARGS += 0x1000 $(BOOTLOADER_BIN)
# synchronise the project level config to the component's
# config
$(COMPONENT_PATH)/src/sdkconfig: $(PROJECT_PATH)/sdkconfig

Wyświetl plik

@ -10,6 +10,3 @@ COMPONENTS := esptool_py
#adding it in the main/Makefile directory.
include $(SDK_PATH)/make/project.mk
# override configured app offset, as bootloader "app" is at 0x1000
CONFIG_APP_OFFSET := 0x1000

Wyświetl plik

@ -12,14 +12,15 @@ PYTHON ?= $(call dequote,$(CONFIG_PYTHON))
ESPTOOLPY := $(PYTHON) $(SDK_PATH)/bin/esptool.py --chip esp32
ESPTOOLPY_SERIAL := $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD)
PROJECT_FLASH_COMMAND=$(ESPTOOLPY_SERIAL) write_flash $(CONFIG_APP_OFFSET) $(PROJECT_BIN)
APP_FLASH_COMMAND=$(ESPTOOLPY_SERIAL) write_flash $(CONFIG_APP_OFFSET) $(APP_BIN)
ESPTOOL_ALL_FLASH_ARGS += $(CONFIG_APP_OFFSET) $(APP_BIN)
$(PROJECT_BIN): $(PROJECT_ELF)
$(APP_BIN): $(APP_ELF)
$(Q) $(ESPTOOLPY) elf2image -o $@ $<
flash: $(PROJECT_BIN)
flash: all_binaries
@echo "Flashing project app to $(CONFIG_APP_OFFSET)..."
$(Q) $(PROJECT_FLASH_COMMAND)
$(Q) $(ESPTOOLPY_SERIAL) write_flash $(ESPTOOL_ALL_FLASH_ARGS)
# convenience target to flash bootloader, partitions, app all at once
flash_all: bootloader-flash partition_table-flash flash
app-flash: $(APP_BIN)
$(Q) $(APP_FLASH_COMMAND)

Wyświetl plik

@ -8,8 +8,6 @@
#
.PHONY: partition_table partition_table-flash partition_table-clean
EXTRA_CLEAN_TARGETS+=partition_table-clean
# NB: gen_esp32part.py lives in the sdk/bin/ dir not component dir
GEN_ESP32PART := $(PYTHON) $(SDK_PATH)/bin/gen_esp32part.py -q
@ -24,7 +22,10 @@ $(PARTITION_TABLE_BIN): $(PARTITION_TABLE_CSV_PATH)
@echo "Building partitions from $(PARTITION_TABLE_CSV_PATH)..."
$(Q) $(GEN_ESP32PART) $< $@
all_binaries: $(PARTITION_TABLE_BIN)
PARTITION_TABLE_FLASH_CMD = $(ESPTOOLPY_SERIAL) write_flash 0x4000 $(PARTITION_TABLE_BIN)
ESPTOOL_ALL_FLASH_ARGS += 0x4000 $(PARTITION_TABLE_BIN)
partition_table: $(PARTITION_TABLE_BIN)
@echo "Partition table binary generated. Contents:"
@ -40,3 +41,5 @@ partition_table-flash: $(PARTITION_TABLE_BIN)
partition_table-clean:
$(Q) rm -f $(PARTITION_TABLE_BIN)
clean: partition_table-clean

Wyświetl plik

@ -10,8 +10,30 @@
# Makefile is located.
#
.PHONY: build-components menuconfig all build clean
all: project
.PHONY: build-components menuconfig all build clean all_binaries
all: all_binaries # other components will add dependencies to 'all_binaries'
@echo "To flash all build output, run 'make flash' or:"
@echo $(ESPTOOLPY_SERIAL) write_flash $(ESPTOOL_ALL_FLASH_ARGS)
# (the reason all_binaries is used instead of 'all' is so that the flash target
# can build everything without triggering the per-component "to flash..."
# output targets.)
help:
@echo "Welcome to Espressif IDF build system. Some useful make targets:"
@echo ""
@echo "make menuconfig - Configure IDF project"
@echo ""
@echo "make all - Build app, bootloader, partition table"
@echo "make flash - Flash all components to a fresh chip"
@echo "make clean - Remove all build output"
@echo ""
@echo "make app - Build just the app"
@echo "make app-flash - Flash just the app"
@echo "make app-clean - Clean just the app"
@echo ""
@echo "See also 'make bootloader', 'make bootloader-flash', 'make bootloader-clean', "
@echo "'make partition_table', etc, etc."
# disable built-in make rules, makes debugging saner
MAKEFLAGS +=-rR
@ -68,7 +90,7 @@ COMPONENT_LDFLAGS :=
# Extract a variable from a child make process
#
# $(1) - path to directory to invoke make in
# $(2) - name of variable to print via the getvariable target (passed in GET_VARIABLE)
# $(2) - name of variable to print via the get_variable target (passed in GET_VARIABLE)
#
# needs 'sed' processing of stdout because make sometimes echoes other stuff on stdout,
# even if asked not to.
@ -78,10 +100,8 @@ define GetVariable
$(shell "$(MAKE)" -s --no-print-directory -C $(1) get_variable PROJECT_PATH=$(PROJECT_PATH) GET_VARIABLE=$(2) | sed -En "s/^$(2)=(.+)/\1/p" )
endef
ifeq ("$(COMPONENT_INCLUDES)","")
COMPONENT_INCLUDES := $(abspath $(foreach comp,$(COMPONENT_PATHS_BUILDABLE),$(addprefix $(comp)/, \
$(call GetVariable,$(comp),COMPONENT_ADD_INCLUDEDIRS))))
endif
#Also add project include path, for sdk includes
COMPONENT_INCLUDES += $(PROJECT_PATH)/build/include/
@ -89,11 +109,9 @@ export COMPONENT_INCLUDES
#COMPONENT_LDFLAGS has a list of all flags that are needed to link the components together. It's collected
#in the same way as COMPONENT_INCLUDES is.
ifeq ("$(COMPONENT_LDFLAGS)","")
COMPONENT_LDFLAGS := $(foreach comp,$(COMPONENT_PATHS_BUILDABLE), \
$(call GetVariable,$(comp),COMPONENT_ADD_LDFLAGS))
export COMPONENT_LDFLAGS
endif
# Generate component dependency targets from dependencies lists
# each component gains a target of its own <name>-build with dependencies
@ -131,9 +149,10 @@ export CC CXX LD AR OBJCOPY
PYTHON=$(call dequote,$(CONFIG_PYTHON))
PROJECT_ELF:=$(BUILD_DIR_BASE)/$(PROJECT_NAME).elf
PROJECT_MAP:=$(PROJECT_ELF:.elf=.map)
PROJECT_BIN:=$(PROJECT_ELF:.elf=.bin)
# the app is the main executable built by the project
APP_ELF:=$(BUILD_DIR_BASE)/$(PROJECT_NAME).elf
APP_MAP:=$(APP_ELF:.elf=.map)
APP_BIN:=$(APP_ELF:.elf=.bin)
# Include any Makefile.projbuild file letting components add
# configuration at the project level
@ -147,16 +166,17 @@ $(foreach componentpath,$(COMPONENT_PATHS),$(eval $(call includeProjBuildMakefil
include $(SDK_PATH)/make/project_config.mk
# ELF depends on the -build target of every component
$(PROJECT_ELF): $(addsuffix -build,$(notdir $(COMPONENT_PATHS_BUILDABLE)))
$(APP_ELF): $(addsuffix -build,$(notdir $(COMPONENT_PATHS_BUILDABLE)))
$(vecho) LD $(notdir $@)
$(Q) $(CC) $(LDFLAGS) -o $@ -Wl,-Map=$(PROJECT_MAP)
$(Q) $(CC) $(LDFLAGS) -o $@ -Wl,-Map=$(APP_MAP)
# Generation of $(PROJECT_BIN) from $(PROJECT_ELF) is added by the esptool
# Generation of $(APP_BIN) from $(APP_ELF) is added by the esptool
# component's Makefile.projbuild
project: $(PROJECT_BIN)
app: $(APP_BIN)
@echo "App built. Default flash app command is:"
@echo $(PROJECT_FLASH_COMMAND) # PROJECT_FLASH_COMMAND is set in esptool_py's Makefile.projbuild
@echo $(APP_FLASH_COMMAND) # APP_FLASH_COMMAND is set in esptool_py's Makefile.projbuild
all_binaries: $(APP_BIN)
$(BUILD_DIR_BASE):
mkdir -p $(BUILD_DIR_BASE)
@ -181,9 +201,10 @@ $(foreach component,$(COMPONENT_PATHS_BUILDABLE),$(eval $(call GenerateComponent
$(foreach component,$(COMPONENT_PATHS_BUILDABLE),$(eval $(call GenerateComponentTarget,$(component),build,$(PROJECT_PATH)/build/include/sdkconfig.h)))
$(foreach component,$(COMPONENT_PATHS_BUILDABLE),$(eval $(call GenerateComponentTarget,$(component),clean)))
clean: $(addsuffix -clean,$(notdir $(COMPONENT_PATHS_BUILDABLE))) $(EXTRA_CLEAN_TARGETS)
$(vecho) RM $(PROJECT_ELF)
$(Q) rm -f $(PROJECT_ELF) $(PROJECT_BIN) $(PROJECT_MAP)
$(Q) rm -rf $(PROJECT_PATH)/build/include/config $(PROJECT_PATH)/build/include/sdkconfig.h
app-clean: $(addsuffix -clean,$(notdir $(COMPONENT_PATHS_BUILDABLE)))
$(vecho) RM $(APP_ELF)
$(Q) rm -f $(APP_ELF) $(APP_BIN) $(APP_MAP)
clean: app-clean

Wyświetl plik

@ -59,6 +59,7 @@ $(AUTO_CONF_REGEN_TARGET) $(PROJECT_PATH)/build/include/sdkconfig.h: $(PROJECT_P
clean: config-clean
.PHONY: config-clean
EXTRA_CLEAN_TARGETS += config-clean
config-clean:
$(vecho RM CONFIG)
$(MAKE) -C $(KCONFIG_TOOL_DIR) clean
$(Q) rm -rf $(PROJECT_PATH)/build/include/config $(PROJECT_PATH)/build/include/sdkconfig.h