pkg-kconfig now loads kconfig variables
cover pkg-kconfig now loads kconfig variables
This series adds a way to use the configurations of kconfig packages in the buildroot make environnement.
This can be useful when you want to be sure that an option of a kconfig package is selected or when you want to know some information about a kconfig package's configuration
The first patch of the series is the modification of pkg-kconfig to make that change.
The second patch is an exemple of how this can be used.
Denis THULIN (2):
kconfig: Can now use variables outside of package
i2c-tools: Adds check of i2c kernel option
Makefile | 4 +++- package/i2c-tools/i2c-tools.mk | 14 ++++++++++++++ package/pkg-kconfig.mk | 24 +++++++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-)
Signature · 1 line
2.5.0
PATCH 1/2 kconfig: Can now use variables outside of package
This is a small modification of pkg-kconfig.mk that saves the .config file of a kconfig package and that loads it in order to use its variables inside other packages' makefiles. (e.g. it can be used to check if i2c is enabled in the kernel before building i2c-tools).
---
It uses sed to prepends the .config variables with <PACKAGE_NAME>_KCONFIG_.
sed output is in the $(BASE_DIR)/kconfigs directory. The .config file are then included in the make environnment
--- Makefile | 4 +++- package/pkg-kconfig.mk | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-)
Makefile +3 -1
@@ -196,6 +196,7 @@ TARGET_DIR := $(BASE_DIR)/target # .config. HOST_DIR will be overwritten later when .config is included. HOST_DIR := $(BASE_DIR)/host GRAPHS_DIR := $(BASE_DIR)/graphs +KCONFIG_OUTPUT_DIR := $(BASE_DIR)/kconfigs LEGAL_INFO_DIR = $(BASE_DIR)/legal-info REDIST_SOURCES_DIR_TARGET = $(LEGAL_INFO_DIR)/sources
@@ -825,7 +826,8 @@ printvars: clean: rm -rf $(TARGET_DIR) $(BINARIES_DIR) $(HOST_DIR) \ $(BUILD_DIR) $(BASE_DIR)/staging \ - $(LEGAL_INFO_DIR) $(GRAPHS_DIR) + $(LEGAL_INFO_DIR) $(GRAPHS_DIR) \ + $(KCONFIG_OUTPUT_DIR) distclean: clean ifeq ($(DL_DIR),$(TOPDIR)/dl)
package/pkg-kconfig.mk +23 -1
@@ -83,6 +83,7 @@ $$($(2)_DIR)/.stamp_kconfig_fixup_done: $$($(2)_DIR)/.config # Before running configure, the configuration file should be present and fixed $$($(2)_TARGET_CONFIGURE): $$($(2)_DIR)/.stamp_kconfig_fixup_done + # Only enable the foo-*config targets when the package is actually enabled. # Note: the variable $(2)_KCONFIG_VAR is not related to the kconfig # infrastructure, but defined by pkg-generic.mk. The generic infrastructure is
@@ -96,6 +97,7 @@ $$(error Internal error: no value specified for $(2)_KCONFIG_FILE) endif endif + # Configuration editors (menuconfig, ...) # # We need to apply the configuration fixups right after a configuration
@@ -118,6 +120,25 @@ $$($(2)_DIR)/.kconfig_editor_%: $$($(2)_DIR)/.stamp_kconfig_fixup_done rm -f $$($(2)_DIR)/.stamp_{target,staging,images}_installed $$(call $(2)_FIXUP_DOT_CONFIG) +# Before building the package, we want to load the .config file prepended with +# the packages' name in order to use it in other packages. +# For instance, we want to check if LINUX_CONFIG_I2C is selected before +# building i2c-tools. +$$($(2)_TARGET_CONFIGURE): | $(2)_LOAD_KCONFIG + +# In order to load the .config file +$(2)_LOAD_KCONFIG: $$(KCONFIG_OUTPUT_DIR)/$(1).config + @echo Loading $$(KCONFIG_OUTPUT_DIR)/$(1).config + $$(eval include $$(KCONFIG_OUTPUT_DIR)/$(1).config) + +# We also need to be sure the configuration is correct before prefixing it with +# <PKG_NAME>_KCONFIG and saving it to KCONFIG_OUTPUT_DIR. +# As the <package>.config file is not meant to be read by humans, this also +# removes blank lines and commented lines. +$$(KCONFIG_OUTPUT_DIR)/$(1).config: $$($(2)_DIR)/.stamp_kconfig_fixup_done + $(Q)mkdir -p $$(KCONFIG_OUTPUT_DIR) + $(Q)sed -n 's/^\(\w\)/$(2)_KCONFIG_\1/p' $$($(2)_DIR)/.config > $$(KCONFIG_OUTPUT_DIR)/$(1).config + # Saving back the configuration # # Ideally, that should directly depend on $$($(2)_DIR)/.stamp_kconfig_fixup_done,
@@ -171,7 +192,8 @@ endif # package enabled $(1)-savedefconfig \ $(1)-check-configuration-done \ $$($(2)_DIR)/.kconfig_editor_% \ - $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS)) + $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS)) \ + $(2)_LOAD_KCONFIG endef # inner-kconfig-package
Signature · 1 line
2.5.0
PATCH 2/2 i2c-tools: Adds check of i2c kernel option
In reply to Denis THULINThe package will now check if i2c is enabled whithin the kernel before the configure step. If not, build of the package will fail. Also adds linux as a dependancy of i2c-tools to make sure that the kernel config is created before checking one of its options.
--- package/i2c-tools/i2c-tools.mk | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
package/i2c-tools/i2c-tools.mk +14 -0
@@ -10,6 +10,20 @@ I2C_TOOLS_SITE = http://dl.lm-sensors.org/i2c-tools/releases I2C_TOOLS_LICENSE = GPLv2+, GPLv2 (py-smbus) I2C_TOOLS_LICENSE_FILES = COPYING +I2C_TOOLS_DEPENDENCIES += linux +define I2C_TOOLS_KERNEL_OPTION_MISSING + echo '$(LINUX_KCONFIG_CONFIG_DEFCONFIG_LIST)' + @if [ -z $(LINUX_KCONFIG_CONFIG_I2C) ]; then \ + echo ERROR: CONFIG_I2C is not selected in the kernel; \ + exit 1; \ + elif [ $(LINUX_KCONFIG_CONFIG_I2C) != y -a $(LINUX_KCONFIG_CONFIG_I2C) != m ]; then \ + echo ERROR: CONFIG_I2C is not selected in the kernel; \ + exit 1; \ + fi +endef +I2C_TOOLS_PRE_CONFIGURE_HOOKS += I2C_TOOLS_KERNEL_OPTION_MISSING + + ifeq ($(BR2_PACKAGE_PYTHON),y) I2C_TOOLS_DEPENDENCIES += python endif
Signature · 1 line
2.5.0
PATCH 2/2 i2c-tools: Adds check of i2c kernel option
Hello,
Quoted 1 line · Denis THULIN
+I2C_TOOLS_DEPENDENCIES += linux
This is not acceptable: we want to allow people to build just a rootfs, and not necessarily the Linux kernel with Buildroot. I personally use Buildroot a lot to build a small initramfs that I then bundle in my kernel image, which is built separately from Buildroot (because I'm doing kernel development, so I build the kernel myself).
Also, this is going completely backwards compared to what we've been doing until now. Currently, in linux/linux.mk, we have some logic to make sure a number of kernel options are enabled when certain Buildroot packages are enabled:
$(if $(BR2_PACKAGE_KTAP),
$(call KCONFIG_ENABLE_OPT,CONFIG_DEBUG_FS,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_ENABLE_DEFAULT_TRACERS,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_PERF_EVENTS,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_FUNCTION_TRACER,$(@D)/.config))
$(if $(BR2_PACKAGE_SYSTEMD),
$(call KCONFIG_ENABLE_OPT,CONFIG_CGROUPS,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_INOTIFY_USER,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_FHANDLE,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_AUTOFS4_FS,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_TMPFS_POSIX_ACL,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_TMPFS_POSIX_XATTR,$(@D)/.config))
$(if $(BR2_PACKAGE_SMACK),
$(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY_SMACK,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY_NETWORK,$(@D)/.config))
$(if $(BR2_PACKAGE_IPTABLES),
$(call KCONFIG_ENABLE_OPT,CONFIG_IP_NF_IPTABLES,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_IP_NF_FILTER,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER,$(@D)/.config)
$(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER_XTABLES,$(@D)/.config))However, we generally do this only when enabling the kernel option in question is needed to get the package to *build*. When it is necessary to make the thing run properly, or when the dependency is really obvious, we simply don't handle this.
So for example in your case, it is completely obvious that i2c-tools needs I2C support in the kernel, otherwise it's a tool that is quite useless.
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 2/2 i2c-tools: Adds check of i2c kernel option
Hi Thomas,
----- Mail original -----
Quoted 4 lines
Hello,
On Tue, 4 Aug 2015 14:27:07 +0200, Denis THULIN wrote:
Quoted 8 lines
Quoted 1 line
+I2C_TOOLS_DEPENDENCIES += linux
This is not acceptable: we want to allow people to build just a rootfs,
and not necessarily the Linux kernel with Buildroot. I personally use Buildroot a lot to build a small initramfs that I then bundle in my kernel image, which is built separately from Buildroot (because I'm doing kernel development, so I build the kernel myself).
Oops. I had not thought of that.
I understand that this is a mistake for kernel options. But could patch [1/2] be useful for the other kconfig packages ? I think it would be useful to know options of busybox when building packages.
Quoted 46 lines
Also, this is going completely backwards compared to what we've been doing until now. Currently, in
linux/linux.mk, we have some logic to make sure a number of kernel options are enabled when certain Buildroot
packages are enabled:$(if $(BR2_PACKAGE_KTAP), $(call KCONFIG_ENABLE_OPT,CONFIG_DEBUG_FS,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_ENABLE_DEFAULT_TRACERS,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_PERF_EVENTS,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_FUNCTION_TRACER,$(@D)/.config)) $(if $(BR2_PACKAGE_SYSTEMD), $(call KCONFIG_ENABLE_OPT,CONFIG_CGROUPS,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_INOTIFY_USER,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_FHANDLE,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_AUTOFS4_FS,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_TMPFS_POSIX_ACL,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_TMPFS_POSIX_XATTR,$(@D)/.config)) $(if $(BR2_PACKAGE_SMACK), $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY_SMACK,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY_NETWORK,$(@D)/.config)) $(if $(BR2_PACKAGE_IPTABLES), $(call KCONFIG_ENABLE_OPT,CONFIG_IP_NF_IPTABLES,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_IP_NF_FILTER,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER,$(@D)/.config) $(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER_XTABLES,$(@D)/.config))
Quoted 5 lines
However, we generally do this only when enabling the kernel option in question is needed to get the package to *build*. When it is necessary
to make the thing run properly, or when the dependency is really obvious, we simply don't handle this.
Would it not be a better thing for all packages to provide a list of kernel options they need and for LINUX_KCONFIG_FIXUP_CMDS to select those options rather than using lots of if blocks ?
That list could also be exported so that people using a custom kernel would know which options Buildroot would have selected had they used the default kernel.
If it is a better thing to do, I could try to implement that, if time allows.
Best regards,
Denis
Quoted 13 lines
So for example in your case, it is completely obvious that i2c-tools needs I2C support in the kernel, otherwise it's a tool that is quite useless.
Best regards,
Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
PATCH 2/2 i2c-tools: Adds check of i2c kernel option
Denis,
Quoted 4 lines · Denis Thulin
I understand that this is a mistake for kernel options. But could patch [1/2] be useful for the other kconfig packages ? I think it would be useful to know options of busybox when building packages.
I am not sure for what reasons other packages would need to know the Busybox options that are enabled.
Quoted 3 lines
Would it not be a better thing for all packages to provide a list of kernel options they need and for
LINUX_KCONFIG_FIXUP_CMDSto select those options rather than using lots of if blocks ?
Could be, yes. Not sure how that would work, though. We want to keep this list of condition relatively short, and not encourage adding millions of interactions between user space dependencies and kernel options.
Quoted 3 lines
That list could also be exported so that people using a custom kernel would know which options Buildroot would have selected had they used the default kernel.
People using a custom kernel "know what they are doing", so I'm not too interested in solving this particular use case.
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com