Skip to contentSkip to conversation

adapt openrc "modules" script to busybox modprobe

PATCH Superseded unixmania at gmail.com 2 participants 8 messages Feb 27, 2020 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover adapt openrc "modules" script to busybox modprobe

From: Carlos Santos <[email protected]>

The busybox modprobe does not have a "--first-time" option, "--verbose" is just "-v" and "--use-blacklist" is just "-b". Also the blacklist support is not selected in the default busybox configuration. So we need to patch the modules scripts accordingly.

Patch 1 adds SED_QUIET, used by the KCONFIG_GET_OPT macro, in patch 2.

Patch 2 adds a KCONFIG_GET_OPT macro. Given a config name and a file, it returns the config value, if set; otherwise returns an empty string.

Patch 3 adapts the "modules" init script to busybox "modprobe".

Patch 4 documents the use of BUSYBOX_BUILD_CONFIG in openrc.mk.

Carlos Santos (4):
Makefile: add SED_QUIET
package/pkg-utils.mk: add KCONFIG_GET_OPT macro package/openrc: adapt "modules" init script to busybox "modprobe" package/busybox: document the use of BUSYBOX_BUILD_CONFIG in openrc.mk

 Makefile                   |  4 +++-
 package/busybox/busybox.mk |  2 ++
 package/openrc/openrc.mk   | 27 ++++++++++++++++++++++++---
 package/pkg-utils.mk       |  4 ++++
 4 files changed, 33 insertions(+), 4 deletions(-)
Signature · 1 line
2.18.2
#1 lore raw

PATCH 1/4 Makefile: add SED_QUIET

From: Carlos Santos <[email protected]>

- Save the sed command full path in HOSTSED
- Define SED as "$(HOSTSED) -i -e"
- Define SED_QUIET as "$(HOSTSED) -n -e"

SED_QUIET will be used by the forthcoming KCONFIG_GET_OPT macro.

---
 Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Makefile +3 -1
index 6311ae643e..c7159059a6 100644
@@ -307,7 +307,9 @@ HOSTLN := $(shell which $(HOSTLN) || type -p $(HOSTLN) || echo ln)
 HOSTNM := $(shell which $(HOSTNM) || type -p $(HOSTNM) || echo nm)
 HOSTOBJCOPY := $(shell which $(HOSTOBJCOPY) || type -p $(HOSTOBJCOPY) || echo objcopy)
 HOSTRANLIB := $(shell which $(HOSTRANLIB) || type -p $(HOSTRANLIB) || echo ranlib)
-SED := $(shell which sed || type -p sed) -i -e
+HOSTSED := $(shell which sed || type -p sed)
+SED := $(HOSTSED) -i -e
+SED_QUIET := $(HOSTSED) -n -e
 
 export HOSTAR HOSTAS HOSTCC HOSTCXX HOSTLD
 export HOSTCC_NOCCACHE HOSTCXX_NOCCACHE
Signature · 1 line
2.18.2
#2 lore raw

PATCH 2/4 package/pkg-utils.mk: add KCONFIG_GET_OPT macro

In reply to unixmania at gmail.com

From: Carlos Santos <[email protected]>

Given a config name and a file, returns the config value if it is set; otherwise returns an empty string.

---
 package/pkg-utils.mk | 4 ++++
 1 file changed, 4 insertions(+)
package/pkg-utils.mk +4 -0
index d324934dba..c8d74520e9 100644
@@ -16,6 +16,10 @@ define KCONFIG_ENABLE_OPT # (option, file)
 	echo '$(1)=y' >> $(2)
 endef
 
+define KCONFIG_GET_OPT # (option, file)
+$(shell $(SED_QUIET) '/^\<$(1)\>=/h;$${x;s/$(1)=//p;}' $(2))
+endef
+
 define KCONFIG_SET_OPT # (option, value, file)
 	$(SED) "/\\<$(1)\\>/d" $(3)
 	echo '$(1)=$(2)' >> $(3)
Signature · 1 line
2.18.2
#3 lore raw

PATCH 3/4 package/openrc: adapt "modules" init script to busybox "modprobe"

In reply to unixmania at gmail.com

From: Carlos Santos <[email protected]>

If kmod tools are not selected, check for the busybox features and adapt the modules script accordingly, since the busybox modprobe does not have a "--first-time" option, "--verbose" is just "-v" and "--use-blacklist" is just "-b". Also the blacklist support is not selected in the default busybox configuration.

If modprobe is not available, do not install the modules script and configuration file.

---
 package/openrc/openrc.mk | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)
package/openrc/openrc.mk +24 -3
index 3f6453cef5..999e34e094 100644
@@ -9,7 +9,7 @@ OPENRC_SITE = $(call github,OpenRC,openrc,$(OPENRC_VERSION))
 OPENRC_LICENSE = BSD-2-Clause
 OPENRC_LICENSE_FILES = LICENSE
 
-OPENRC_DEPENDENCIES = ncurses
+OPENRC_DEPENDENCIES = ncurses $(if $(BR2_PACKAGE_BUSYBOX),busybox)
 
 # set LIBNAME so openrc puts files in proper directories and sets proper
 # paths in installed files. Since in buildroot /lib64 and /lib32 always
@@ -29,9 +29,30 @@ else
 OPENRC_MAKE_OPTS += MKSTATICLIBS=yes
 endif
 
-define OPENRC_BUILD_CMDS
-	$(MAKE) $(OPENRC_MAKE_OPTS) -C $(@D)
+# modprobe can be provided by either kmod or busybox
+ifeq ($(BR2_PACKAGE_KMOD_TOOLS),)
+ifeq ($(BR2_PACKAGE_BUSYBOX),y)
+# Busybox modprobe does not have a --first-time option; --verbose is just -v
+# and --use-blacklist is just -b.
+ifeq ($(call KCONFIG_GET_OPT,CONFIG_MODPROBE,$(BUSYBOX_BUILD_CONFIG)),y)
+ifeq ($(call KCONFIG_GET_OPT,CONFIG_FEATURE_MODPROBE_BLACKLIST,$(BUSYBOX_BUILD_CONFIG)),y)
+OPENRC_MODULES_BLACKLIST = s/ --use-blacklist/ -b/
+else
+OPENRC_MODULES_BLACKLIST = s/ --use-blacklist//
+endif
+define OPENRC_MODULES_CLEAN
+	$(SED) 's/ --first-time//;$(OPENRC_MODULES_BLACKLIST);s/--verbose/-v/' \
+		$(@D)/init.d/modules.in
+endef
+else # BR2_PACKAGE_BUSYBOX
+# No modprobe command available. Do not build/install the modules script.
+define OPENRC_MODULES_CLEAN
+	$(SED) 's/ modules//' $(@D)/{conf.d,init.d,runlevels}/Makefile
 endef
+endif # CONFIG_MODPROBE
+OPENRC_POST_PATCH_HOOKS += OPENRC_MODULES_CLEAN
+endif # BR2_PACKAGE_BUSYBOX
+endif # BR2_PACKAGE_KMOD_TOOLS
 
 define OPENRC_INSTALL_TARGET_CMDS
 	$(MAKE) $(OPENRC_MAKE_OPTS) DESTDIR=$(TARGET_DIR) -C $(@D) install
Signature · 1 line
2.18.2
#4 lore raw

PATCH 3/4 package/openrc: adapt "modules" init script to busybox "modprobe"

package/openrc/openrc.mk else · line 37

Quoted 6 lines · On Thu, 27 Feb 2020 09:39:37 -0300 unixmania at gmail.com wrote:
package/openrc/openrc.mk +6 -0
+# modprobe can be provided by either kmod or busybox
+ifeq ($(BR2_PACKAGE_KMOD_TOOLS),)
+ifeq ($(BR2_PACKAGE_BUSYBOX),y)
+# Busybox modprobe does not have a --first-time option; --verbose is just -v
+# and --use-blacklist is just -b.
+ifeq ($(call KCONFIG_GET_OPT,CONFIG_MODPROBE,$(BUSYBOX_BUILD_CONFIG)),y)

Is this working? Isn't that evaluated when Makefiles are parsed, i.e before the build has extracted Busybox and created its .config file ?

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#5 lore raw

PATCH 3/4 package/openrc: adapt "modules" init script to busybox "modprobe"

Quoted 14 lines · Thomas Petazzoni

package/openrc/openrc.mk else · line 37

Quoted 6 lines · On Thu, 27 Feb 2020 09:39:37 -0300 unixmania at gmail.com wrote:
package/openrc/openrc.mk +6 -0
+# modprobe can be provided by either kmod or busybox
+ifeq ($(BR2_PACKAGE_KMOD_TOOLS),)
+ifeq ($(BR2_PACKAGE_BUSYBOX),y)
+# Busybox modprobe does not have a --first-time option; --verbose is just -v
+# and --use-blacklist is just -b.
+ifeq ($(call KCONFIG_GET_OPT,CONFIG_MODPROBE,$(BUSYBOX_BUILD_CONFIG)),y)

Is this working? Isn't that evaluated when Makefiles are parsed, i.e before the build has extracted Busybox and created its .config file ?

Quoted 7 lines

Best regards,

Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Hum, not in a clean build. Good catch. :-(

But it works if I use

    $(BR2_PACKAGE_BUSYBOX_CONFIG) $(BUSYBOX_BUILD_CONFIG)

So in a clean/first build it will take the value from the first file and in a dirty build it will take the value from the second file.

--
Carlos Santos <[email protected]>

#6 lore raw

PATCH 3/4 package/openrc: adapt "modules" init script to busybox "modprobe"

Quoted 25 lines · Carlos Santos
Quoted 14 lines · Thomas Petazzoni

package/openrc/openrc.mk else · line 37

Quoted 6 lines · On Thu, 27 Feb 2020 09:39:37 -0300 unixmania at gmail.com wrote:
package/openrc/openrc.mk +6 -0
+# modprobe can be provided by either kmod or busybox
+ifeq ($(BR2_PACKAGE_KMOD_TOOLS),)
+ifeq ($(BR2_PACKAGE_BUSYBOX),y)
+# Busybox modprobe does not have a --first-time option; --verbose is just -v
+# and --use-blacklist is just -b.
+ifeq ($(call KCONFIG_GET_OPT,CONFIG_MODPROBE,$(BUSYBOX_BUILD_CONFIG)),y)

Is this working? Isn't that evaluated when Makefiles are parsed, i.e before the build has extracted Busybox and created its .config file ?

Quoted 7 lines

Best regards,

Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Quoted 8 lines

Hum, not in a clean build. Good catch. :-(

But it works if I use

    $(BR2_PACKAGE_BUSYBOX_CONFIG) $(BUSYBOX_BUILD_CONFIG)

So in a clean/first build it will take the value from the first file and in a dirty build it will take the value from the second file.

I just sent a v2 which hopefully cover all the cases. It even deals with kconfig fragment files.

Signature · 1 line
Carlos Santos <[email protected]>
#7 lore raw

PATCH 4/4 package/busybox: document the use of BUSYBOX_BUILD_CONFIG in openrc.mk

In reply to unixmania at gmail.com

From: Carlos Santos <[email protected]>

Prevent filures if the variable is removed or renamed in the future.

---
 package/busybox/busybox.mk | 2 ++
 1 file changed, 2 insertions(+)
package/busybox/busybox.mk +2 -0
index 9eeb784d2a..a761ff569f 100644
@@ -80,7 +80,9 @@ BUSYBOX_CFLAGS += "`$(PKG_CONFIG_HOST_BINARY) --cflags libtirpc`"
 BUSYBOX_CFLAGS_busybox += "`$(PKG_CONFIG_HOST_BINARY) --libs libtirpc`"
 endif
 
+# Warning: this is also used in package/openrc/openrc.mk.
 BUSYBOX_BUILD_CONFIG = $(BUSYBOX_DIR)/.config
+
 # Allows the build system to tweak CFLAGS
 BUSYBOX_MAKE_ENV = \
 	$(TARGET_MAKE_ENV) \
Signature · 1 line
2.18.2