diff --git a/docs/build_system.rst b/docs/build_system.rst index 6687fa69ed..2e388bd495 100644 --- a/docs/build_system.rst +++ b/docs/build_system.rst @@ -477,3 +477,12 @@ is set then the component can instruct the linker to link other binaries instead .. _esp-idf-template: https://github.com/espressif/esp-idf-template .. _GNU Make Manual: https://www.gnu.org/software/make/manual/make.html .. _[_f1]: Actually, some components in esp-idf are "pure configuration" components that don't have a component.mk file, only a Makefile.projbuild and/or Kconfig.projbuild file. However, these components are unusual and most components have a component.mk file. + + +Custom sdkconfig defaults +------------------------- + +For example projects or other projects where you don't want to specify a full sdkconfig configuration, but you do want to override some key values from the esp-idf defaults, it is possible to create a file ``sdkconfig.defaults`` in the project directory. This file will be used when running ``make defconfig``, or creating a new config from scratch. + +To override the name of this file, set the ``SDKCONFIG_DEFAULTS`` environment variable. + diff --git a/examples/05_ble_adv/Makefile b/examples/05_ble_adv/Makefile index 3a913b817b..2319786d4a 100644 --- a/examples/05_ble_adv/Makefile +++ b/examples/05_ble_adv/Makefile @@ -6,11 +6,3 @@ PROJECT_NAME := ble_adv include $(IDF_PATH)/make/project.mk - -# Copy some defaults into the sdkconfig by default -# so BT stack is enabled -sdkconfig: sdkconfig.defaults - $(Q) cp $< $@ - -menuconfig: sdkconfig -defconfig: sdkconfig diff --git a/examples/12_blufi/Makefile b/examples/12_blufi/Makefile index 7e7548444f..9c80f26c1a 100644 --- a/examples/12_blufi/Makefile +++ b/examples/12_blufi/Makefile @@ -8,11 +8,3 @@ PROJECT_NAME := blufi_demo COMPONENT_ADD_INCLUDEDIRS := components/include include $(IDF_PATH)/make/project.mk - -# Copy some defaults into the sdkconfig by default -# so BT stack is enabled -sdkconfig: sdkconfig.defaults - $(Q) cp $< $@ - -menuconfig: sdkconfig -defconfig: sdkconfig diff --git a/examples/14_gatt_server/Makefile b/examples/14_gatt_server/Makefile index d7732bd280..2f76e60b60 100644 --- a/examples/14_gatt_server/Makefile +++ b/examples/14_gatt_server/Makefile @@ -8,11 +8,3 @@ PROJECT_NAME := gatt_server_demos COMPONENT_ADD_INCLUDEDIRS := components/include include $(IDF_PATH)/make/project.mk - -# Copy some defaults into the sdkconfig by default -# so BT stack is enabled -sdkconfig: sdkconfig.defaults - $(Q) cp $< $@ - -menuconfig: sdkconfig -defconfig: sdkconfig diff --git a/examples/15_gatt_client/Makefile b/examples/15_gatt_client/Makefile index 93f793308f..700ffd7add 100644 --- a/examples/15_gatt_client/Makefile +++ b/examples/15_gatt_client/Makefile @@ -8,11 +8,3 @@ PROJECT_NAME := gatt_client_demo COMPONENT_ADD_INCLUDEDIRS := components/include include $(IDF_PATH)/make/project.mk - -# Copy some defaults into the sdkconfig by default -# so BT stack is enabled -sdkconfig: sdkconfig.defaults - $(Q) cp $< $@ - -menuconfig: sdkconfig -defconfig: sdkconfig diff --git a/examples/18_ota/sdkconfig b/examples/18_ota/sdkconfig deleted file mode 100644 index 070b529a05..0000000000 --- a/examples/18_ota/sdkconfig +++ /dev/null @@ -1,5 +0,0 @@ -# Some sdkconfig parameters overriden from the defaults for this example, -# This file is in git but will be overwritten with the autogenerated file -# the first time "menuconfig" is run (changes ignored by git). -CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y -CONFIG_PARTITION_TABLE_TWO_OTA=y diff --git a/examples/18_ota/sdkconfig.defaults b/examples/18_ota/sdkconfig.defaults new file mode 100644 index 0000000000..2289a82300 --- /dev/null +++ b/examples/18_ota/sdkconfig.defaults @@ -0,0 +1,4 @@ +# Default sdkconfig parameters to use the OTA +# partition table layout, with a 4MB flash size +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_PARTITION_TABLE_TWO_OTA=y diff --git a/make/project_config.mk b/make/project_config.mk index 187d1ac282..b8e40f4357 100644 --- a/make/project_config.mk +++ b/make/project_config.mk @@ -11,6 +11,10 @@ KCONFIG_TOOL_DIR=$(IDF_PATH)/tools/kconfig # unless it's overriden (happens for bootloader) SDKCONFIG ?= $(PROJECT_PATH)/sdkconfig +# SDKCONFIG_DEFAULTS is an optional file containing default +# overrides (usually used for esp-idf examples) +SDKCONFIG_DEFAULTS ?= $(PROJECT_PATH)/sdkconfig.defaults + # reset MAKEFLAGS as the menuconfig makefile uses implicit compile rules $(KCONFIG_TOOL_DIR)/mconf $(KCONFIG_TOOL_DIR)/conf: MAKEFLAGS=$(ORIGINAL_MAKEFLAGS) CC=$(HOSTCC) LD=$(HOSTLD) \ @@ -21,21 +25,29 @@ KCONFIG_TOOL_ENV=KCONFIG_AUTOHEADER=$(abspath $(BUILD_DIR_BASE)/include/sdkconfi COMPONENT_KCONFIGS="$(COMPONENT_KCONFIGS)" KCONFIG_CONFIG=$(SDKCONFIG) \ COMPONENT_KCONFIGS_PROJBUILD="$(COMPONENT_KCONFIGS_PROJBUILD)" -menuconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig +menuconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig | defconfig $(summary) MENUCONFIG $(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig ifeq ("$(wildcard $(SDKCONFIG))","") ifeq ("$(call prereq_if_explicit,defconfig)","") -# if not configuration is present and defconfig is not a target, run makeconfig -$(SDKCONFIG): menuconfig +# if not configuration is present and defconfig is not a target, run defconfig then menuconfig +$(SDKCONFIG): defconfig menuconfig else +# otherwise, just defconfig $(SDKCONFIG): defconfig endif endif +$(wildcard $(PROJECT_PATH)/sdkconfig.defaults): | menuconfig defconfig + cp $< $@ + +# defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present defconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig $(BUILD_DIR_BASE) $(summary) DEFCONFIG +ifneq ("$(wildcard $(SDKCONFIG_DEFAULTS))","") + cp $(SDKCONFIG_DEFAULTS) $(SDKCONFIG) +endif mkdir -p $(BUILD_DIR_BASE)/include/config $(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/conf --olddefconfig $(IDF_PATH)/Kconfig