From 067351be80dd45a125a98740ad5b2477affac8d6 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 1 Jul 2018 16:00:15 +0300 Subject: [PATCH] esp-idf-bootloader: esp-idf build system tweaks These changes are needed for building apeos flash binary which is named bootloader in esp-idf. --- components/bootloader/Makefile.projbuild | 2 +- components/bootloader/subproject/Makefile | 17 +++++++- components/esptool_py/Makefile.projbuild | 1 - esp-idf.mk | 20 +++++++-- make/component_wrapper.mk | 4 +- make/project.mk | 68 ++++++++++++------------------- 6 files changed, 62 insertions(+), 50 deletions(-) diff --git a/components/bootloader/Makefile.projbuild b/components/bootloader/Makefile.projbuild index f6960ae..375d2ad 100644 --- a/components/bootloader/Makefile.projbuild +++ b/components/bootloader/Makefile.projbuild @@ -46,6 +46,7 @@ BOOTLOADER_MAKE= +\ $(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/subproject \ V=$(V) \ BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) \ + TOP_DIR=$(TOP_DIR) \ TEST_COMPONENTS= \ TESTS_ALL= @@ -135,7 +136,6 @@ all_binaries: $(BOOTLOADER_BIN) endif bootloader-clean: $(SDKCONFIG_MAKEFILE) - $(BOOTLOADER_MAKE) app-clean ifdef CONFIG_SECURE_BOOTLOADER_REFLASHABLE rm -f $(SECURE_BOOTLOADER_KEY) $(BOOTLOADER_DIGEST_BIN) endif diff --git a/components/bootloader/subproject/Makefile b/components/bootloader/subproject/Makefile index 5334b4e..95da466 100644 --- a/components/bootloader/subproject/Makefile +++ b/components/bootloader/subproject/Makefile @@ -21,15 +21,24 @@ endif PROJECT_NAME := bootloader +COMPONENT_DIRS = $(TOP_DIR)/components $(IDF_PATH)/components $(PROJECT_PATH)/main COMPONENTS := esptool_py bootloader_support log spi_flash micro-ecc soc main # Clear C and CXX from top level project -CFLAGS = +# but ensure -pipe to reduce flash wear +CFLAGS = -pipe CXXFLAGS = #We cannot include the esp32 component directly but we need its includes. CFLAGS += -I $(IDF_PATH)/components/esp32/include +# apeos bootloader build needs these +CFLAGS += -I $(IDF_PATH)/components/driver/include +CFLAGS += -I $(IDF_PATH)/components/freertos/include + +# Add apeos include dir (PROJECT_PATH) to esp-idf bootloader search path +CFLAGS += -I $(PROJECT_PATH)/include + CFLAGS += -Werror=unused-function CFLAGS += -Werror=unused-but-set-variable CFLAGS += -Werror=unused-variable @@ -47,4 +56,8 @@ CFLAGS += -D BOOTLOADER_BUILD=1 # include the top-level "project" include directory, for sdkconfig.h CFLAGS += -I$(BUILD_DIR_BASE)/../include -include $(IDF_PATH)/make/project.mk +# add apeos include directory to include search locations +CFLAGS += -I$(TOP_DIR)/include + +$(if $(V),$(info including $(TOP_DIR)/make/project.mk...)) +include $(TOP_DIR)/make/project.mk diff --git a/components/esptool_py/Makefile.projbuild b/components/esptool_py/Makefile.projbuild index 8b40eef..c36ea45 100644 --- a/components/esptool_py/Makefile.projbuild +++ b/components/esptool_py/Makefile.projbuild @@ -71,7 +71,6 @@ ifdef CONFIG_SECURE_BOOT_ENABLED endif $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS) -app-flash: $(APP_BIN) $(ESPTOOLPY_SRC) $(call prereq_if_explicit,erase_flash) # Submodules normally added in component.mk, but can be added # at the project level as long as qualified path diff --git a/esp-idf.mk b/esp-idf.mk index 53eec1c..294f97d 100644 --- a/esp-idf.mk +++ b/esp-idf.mk @@ -17,8 +17,20 @@ PROJECT_NAME := apeos -include $(IDF_PATH)/make/project.mk +# customize esp-idf components +COMPONENTS := bootloader # modified esp-idf bootloader, Apache License, Version 2.0 +COMPONENTS += esptool_py # modified esp-idf esptool for installing apeos on esp-32 flash, GPLv2+ -# don't trash flash storage when building on systems -# where tmp files are stored on flash -CFLAGS += -pipe +# apeos is being built +EXTRA_CPPFLAGS := -DAPEOS + +# apeos is being built through esp-idf based build system +EXTRA_CPPFLAGS += -DESP_IDF_APEOS_BUILD + +# Don't wear flash storage when building on systems +# where tmp files are stored on flash. +# Also probably faster unless /tmp is ramfs. +EXTRA_CFLAGS := -pipe + +$(if $(V),$(info including make/project.mk...)) +include make/project.mk diff --git a/make/component_wrapper.mk b/make/component_wrapper.mk index 1fe7395..4467a90 100644 --- a/make/component_wrapper.mk +++ b/make/component_wrapper.mk @@ -42,7 +42,8 @@ COMPONENT_BUILD_DIR := $(abspath .) # include elements common to both project & component makefiles # (includes project configuration set via menuconfig) -include $(IDF_PATH)/make/common.mk +$(if $(V),$(info including $(TOP_DIR)/make/common.mk...)) +include $(TOP_DIR)/make/common.mk # Some of the following defaults may be overriden by the component's component.mk makefile, # during the next step: @@ -115,6 +116,7 @@ COMPONENT_PATH := $(COMPILING_COMPONENT_PATH) # Include component.mk for this component. +$(if $(V),$(info including $(COMPONENT_MAKEFILE)...)) include $(COMPONENT_MAKEFILE) diff --git a/make/project.mk b/make/project.mk index 4f7fb07..8475f88 100644 --- a/make/project.mk +++ b/make/project.mk @@ -1,9 +1,12 @@ # Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD +# Copyright 2018 apeos contributors # -# Main Project Makefile -# This Makefile is included directly from the user project Makefile in order to call the component.mk -# makefiles of all components (in a separate make process) to build all the libraries, then links them -# together into the final file. If so, PWD is the project dir (we assume). +# Main Project Makefile (based on esp-idf file with similar purpose) +# This Makefile is included directly from the user project Makefile in +# order to call the component.mk makefiles of all components (in a +# separate make process) to build all the libraries, then links them +# together into the final file. If so, PWD is the project dir (we +# assume). # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,8 +21,8 @@ # limitations under the License. # -# This makefile requires the environment variable IDF_PATH to be set to the top-level esp-idf directory -# where this file is located. +# This makefile requires the environment variable IDF_PATH to be set +# to the top-level esp-idf directory where this file is located. # .PHONY: build-components menuconfig defconfig all build clean all_binaries check-submodules size size-components size-files list-components @@ -34,7 +37,7 @@ all: all_binaries # flash..." output targets.) help: - @echo "Welcome to Espressif IDF build system. Some useful make targets:" + @echo "Welcome to apeos build system. Some useful make targets:" @echo "" @echo "make menuconfig - Configure IDF project" @echo "make defconfig - Set defaults for all new configuration options" @@ -49,9 +52,6 @@ help: @echo "make simple_monitor - Monitor serial output on terminal console" @echo "make list-components - List all components in the project" @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 "make print_flash_cmd - Print the arguments for esptool when flash" @echo "" @echo "See also 'make bootloader', 'make bootloader-flash', 'make bootloader-clean', " @@ -121,8 +121,13 @@ PROJECT_PATH := $(abspath $(dir $(firstword $(MAKEFILE_LIST)))) export PROJECT_PATH endif +# TOP_DIR is useful to distinguish apeos esp-idf build system variant +# from upstream esp-idf variant in IDF_PATH +TOP_DIR=$(PROJECT_PATH) +export TOP_DIR + # A list of the "common" makefiles, to use as a target dependency -COMMON_MAKEFILES := $(abspath $(IDF_PATH)/make/project.mk $(IDF_PATH)/make/common.mk $(IDF_PATH)/make/component_wrapper.mk $(firstword $(MAKEFILE_LIST))) +COMMON_MAKEFILES := $(abspath $(TOP_DIR)/make/project.mk $(TOP_DIR)/make/common.mk $(TOP_DIR)/make/component_wrapper.mk $(firstword $(MAKEFILE_LIST))) export COMMON_MAKEFILES # The directory where we put all objects/libraries/binaries. The project Makefile can @@ -215,7 +220,8 @@ COMPONENT_INCLUDES += $(abspath $(BUILD_DIR_BASE)/include/) export COMPONENT_INCLUDES # Set variables common to both project & component -include $(IDF_PATH)/make/common.mk +$(if $(V),$(info including $(TOP_DIR)/make/common.mk...)) +include $(TOP_DIR)/make/common.mk all: ifdef CONFIG_SECURE_BOOT_ENABLED @@ -227,7 +233,7 @@ ifndef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES endif @echo "To flash app & partition table, run 'make flash' or:" else - @echo "To flash all build output, run 'make flash' or:" + @echo "To flash all build output, run:" endif @echo $(ESPTOOLPY_WRITE_FLASH) $(ESPTOOL_ALL_FLASH_ARGS) @@ -368,6 +374,7 @@ export CC CXX LD AR OBJCOPY SIZE PYTHON=$(call dequote,$(CONFIG_PYTHON)) # the app is the main executable built by the project +# bootloader subproject is considered app APP_ELF:=$(BUILD_DIR_BASE)/$(PROJECT_NAME).elf APP_MAP:=$(APP_ELF:.elf=.map) APP_BIN:=$(APP_ELF:.elf=.bin) @@ -387,9 +394,11 @@ $(foreach componentpath,$(COMPONENT_PATHS), \ # # (bootloader build doesn't need this, config is exported from top-level) ifndef IS_BOOTLOADER_BUILD -include $(IDF_PATH)/make/project_config.mk +$(if $(V),$(info including $(TOP_DIR)/make/project_config.mk...)) +include $(TOP_DIR)/make/project_config.mk endif +ifdef IS_BOOTLOADER_BUILD # ELF depends on the library archive files for COMPONENT_LIBRARIES # the rules to build these are emitted as part of GenerateComponentTarget below # @@ -400,18 +409,8 @@ $(APP_ELF): $(foreach libcomp,$(COMPONENT_LIBRARIES),$(BUILD_DIR_BASE)/$(libcomp $(summary) LD $(patsubst $(PWD)/%,%,$@) $(CC) $(LDFLAGS) -o $@ -Wl,-Map=$(APP_MAP) -app: $(APP_BIN) -ifeq ("$(CONFIG_SECURE_BOOT_ENABLED)$(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)","y") # secure boot enabled, but remote sign app image - @echo "App built but not signed. Signing step via espsecure.py:" - @echo "espsecure.py sign_data --keyfile KEYFILE $(APP_BIN)" - @echo "Then flash app command is:" - @echo $(ESPTOOLPY_WRITE_FLASH) $(CONFIG_APP_OFFSET) $(APP_BIN) -else - @echo "App built. Default flash app command is:" - @echo $(ESPTOOLPY_WRITE_FLASH) $(CONFIG_APP_OFFSET) $(APP_BIN) -endif - all_binaries: $(APP_BIN) +endif $(BUILD_DIR_BASE): mkdir -p $(BUILD_DIR_BASE) @@ -422,7 +421,7 @@ $(BUILD_DIR_BASE): # # Is recursively expanded by the GenerateComponentTargets macro define ComponentMake -+$(MAKE) -C $(BUILD_DIR_BASE)/$(2) -f $(IDF_PATH)/make/component_wrapper.mk COMPONENT_MAKEFILE=$(1)/component.mk COMPONENT_NAME=$(2) ++$(MAKE) -C $(BUILD_DIR_BASE)/$(2) -f $(TOP_DIR)/make/component_wrapper.mk COMPONENT_MAKEFILE=$(1)/component.mk COMPONENT_NAME=$(2) endef # Generate top-level component-specific targets for each component @@ -462,24 +461,11 @@ endef $(foreach component,$(COMPONENT_PATHS),$(eval $(call GenerateComponentTargets,$(component),$(notdir $(component))))) $(foreach component,$(TEST_COMPONENT_PATHS),$(eval $(call GenerateComponentTargets,$(component),$(lastword $(subst /, ,$(dir $(component))))_test))) -app-clean: $(addprefix component-,$(addsuffix -clean,$(notdir $(COMPONENT_PATHS)))) - $(summary) RM $(APP_ELF) - rm -f $(APP_ELF) $(APP_BIN) $(APP_MAP) - -size: $(APP_ELF) - $(PYTHON) $(IDF_PATH)/tools/idf_size.py $(APP_MAP) - -size-files: $(APP_ELF) - $(PYTHON) $(IDF_PATH)/tools/idf_size.py --files $(APP_MAP) - -size-components: $(APP_ELF) - $(PYTHON) $(IDF_PATH)/tools/idf_size.py --archives $(APP_MAP) - # NB: this ordering is deliberate (app-clean & bootloader-clean before # _config-clean), so config remains valid during all component clean # targets -config-clean: app-clean bootloader-clean -clean: app-clean bootloader-clean config-clean +config-clean: bootloader-clean +clean: bootloader-clean config-clean # phony target to check if any git submodule listed in COMPONENT_SUBMODULES are missing # or out of date, and exit if so. Components can add paths to this variable. -- 2.11.4.GIT