Skip to contentSkip to conversation

0/6] Add a kernel module loading mechanism

RFC PATCH New unixmania at gmail.com 2 participants 11 messages Mar 20, 2020 – Mar 28, 2020

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 0/6] Add a kernel module loading mechanism

From: Carlos Santos <[email protected]>

Currently there are two ways to load kernel modules in Buildroot:

- via systemd (systemd-modules-load.service)
- via OpenRC (/etc/init.d/modules)

The systemd mechanism uses configuration files, eacho one containing a list of kernel module names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is # or ; are ignored. Files are loaded in the following order:

/etc/modules-load.d/*.conf
/run/modules-load.d/*.conf
/usr/lib/modules-load.d/*.conf

OpenRC uses /etc/modules-load.d/*.conf, only, and does not ignore lines beginning with ';'.

In order to provide a compatible mechanism for sysvinit/busybox init systems, this series does the following:

Patch #1 adds a S02modules-load init script to kmod (which provides the "modprobe" utility). It roughly mimics the systemd service.

Patch #2 adds the S02modules-load init script to Busybox. It's installed only if kmod is not selected and modprobe is included in buildroot.

Patch #3 adds a target-finalize hook to linux to ensure that depmod -a is executed after all packages install their modules, otherwise modprobe fails at run-time, because the module is not included in /lib/modules/<kernel-version>/modules.dep.

Patchs #4..6 modify packages dmraid, owfs and ti-sgx-km to use the modules-load mechanism.

Package ti-gfx should be modified too, but I did not find a board configuration to test it.

*** BLURB HERE ***

Carlos Santos (6):
package/kmod: add modules-load init script package/busybox: add modules-load init script
linux: run depmod in a target-finalize hook package/dmraid: use modules-load to load the kernel module package/owfs: use modules-load to load the kernel module package/ti-sgx-km: use modules-load to load the kernel module

 linux/linux.mk                  | 11 ++++-
 package/busybox/S02modules-load |  1 +
 package/busybox/busybox.mk      | 12 +++++
 package/dmraid/S20dmraid        |  3 --
 package/dmraid/dmraid.mk        | 12 +++++
 package/kmod/S02modules-load    | 85 +++++++++++++++++++++++++++++++++
 package/kmod/kmod.mk            |  5 ++
 package/owfs/S60owfs            |  2 -
 package/owfs/owfs.mk            | 11 +++++
 package/ti-sgx-km/ti-sgx-km.mk  | 10 ++++
 package/ti-sgx-um/S80ti-sgx     | 19 +-------
 11 files changed, 148 insertions(+), 23 deletions(-)
 create mode 120000 package/busybox/S02modules-load
 create mode 100644 package/kmod/S02modules-load
Signature · 1 line
2.18.2
#1 lore raw

RFC PATCH 1/1 1/6] package/kmod: add modules-load init script

From: Carlos Santos <[email protected]>

Use some scripting to mimic the systemd "modules-load" and the OpenRC "modules" services (load kernel modules based on static configuration).

The configuration files should simply contain a list of kernel module names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is # or ; are ignored.

The configuration directory list and file format is the same as the one described in modules-load.d(5). Files are loaded in the following order:

/etc/modules-load.d/*.conf
/run/modules-load.d/*.conf
/usr/lib/modules-load.d/*.conf

This roughly mimics the logic used by systemd but the files are not sorted by their filename in lexicographic order as systemd does.

Notice that OpenRC uses /etc/modules-load.d/*.conf, only, and does not ignore lines beginning with ';'.

The file redirections do the following:

- stdout is redirected to syslog with facility.level "kern.info"
- stderr is redirected to syslog with facility.level "kern.err"
- file dscriptor 4 is used to pass the result to the "start" function.

foo

---
 package/kmod/S02modules-load | 85 ++++++++++++++++++++++++++++++++++++
 package/kmod/kmod.mk         |  5 +++
 2 files changed, 90 insertions(+)
 create mode 100644 package/kmod/S02modules-load
package/kmod/S02modules-load new file +85 -0
new file mode 100644
index 0000000000..099cc63023
@@ -0,0 +1,85 @@
+#!/bin/sh
+
+PROGRAM="modules-load"
+
+MODULES_LOAD_ARGS=""
+
+# shellcheck source=/dev/null
+[ -r "/etc/default/$PROGRAM" ] && . "/etc/default/$PROGRAM"
+
+# Use some scripting to mimic the systemd "modules-load" and the OpenRC
+# "modules" services (load kernel modules based on static configuration).
+# 
+# The configuration files should simply contain a list of kernel module
+# names to load, separated by newlines. Empty lines and lines whose first
+# non-whitespace character is # or ; are ignored.
+# 
+# The configuration directory list and file format is the same as the one
+# described in modules-load.d(5). Files are loaded in the following order:
+# 
+#   /etc/modules-load.d/*.conf
+#   /run/modules-load.d/*.conf
+#   /usr/lib/modules-load.d/*.conf
+# 
+# This roughly mimics the logic used by systemd but the files are not sorted
+# by their filename in lexicographic order as systemd does.
+# 
+# Notice that OpenRC uses /etc/modules-load.d/*.conf, only, and does not
+# ignore lines beginning with ';'.
+#
+# The file redirections do the following:
+#
+# - stdout is redirected to syslog with facility.level "kern.info"
+# - stderr is redirected to syslog with facility.level "kern.err"
+# - file dscriptor 4 is used to pass the result to the "start" function.
+
+MODULES_LOAD_D="/etc/modules-load.d/ /run/modules-load.d/ /usr/lib/modules-load.d/"
+
+# Use some scripting to mimic the systemd-modules-load utility provided by
+# systemd, reporting results to syslog. Uers not interested on messages can
+# put "-q" in MODULES_LOAD_ARGS.
+
+run_program() {
+	# shellcheck disable=SC2086 # we need the word splitting
+	find $MODULES_LOAD_D -maxdepth 1 -name '*.conf' -print0 2> /dev/null | \
+	xargs -0 -r -n 1 readlink -f | {
+		prog_status="OK"
+		while :; do
+			read -r file
+			if [ -z "$file" ]; then
+				echo "$prog_status" >&4
+				break
+			fi
+			echo "* Applying $file ..."
+			while :; do
+				read -r mod || break
+				case "$mod" in
+					''|'#'*|';'*) ;;
+					*) /sbin/modprobe -s "$mod" || prog_status="FAIL"
+				esac
+			done < "$file"
+		done 2>&1 >&3 | /usr/bin/logger -t "$PROGRAM" -p kern.err
+	} 3>&1 | /usr/bin/logger -t "$PROGRAM" -p kern.info
+}
+
+start() {
+	printf '%s %s: ' "$1" "$PROGRAM"
+	status=$(run_program 4>&1)
+	echo "$status"
+	if [ "$status" = "OK" ]; then
+		return 0
+	fi
+	return 1
+}
+
+case "$1" in
+	start)
+		start "Running";;
+	restart|reload)
+		start "Rerunning";;
+	stop)
+		:;;
+	*)
+		echo "Usage: $0 {start|stop|restart|reload}"
+		exit 1
+esac
package/kmod/kmod.mk +5 -0
index e2dfea5c7b..31bdac6d81 100644
@@ -60,6 +60,11 @@ else
 KMOD_BIN_PATH = ../usr/bin/kmod
 endif
 
+define KMOD_INSTALL_INIT_SYSV
+	$(INSTALL) -m 0755 -D package/kmod/S02modules-load \
+		$(TARGET_DIR)/etc/init.d/S02modules-load
+endef
+
 define KMOD_INSTALL_TOOLS
 	for i in depmod insmod lsmod modinfo modprobe rmmod; do \
 		ln -sf $(KMOD_BIN_PATH) $(TARGET_DIR)/sbin/$$i; \
Signature · 1 line
2.18.2
#2 lore raw

RFC PATCH 1/1 1/6] package/kmod: add modules-load init script

Carlos, All,

On 2020-03-20 20:35 -0300, unixmania at gmail.com spake thusly:

Quoted 3 lines

From: Carlos Santos <[email protected]>
Use some scripting to mimic the systemd "modules-load" and the OpenRC "modules" services (load kernel modules based on static configuration).

So, the goal is laudable, but the implementation is overly complicated and, imho, flawed.

Quoted 3 lines

The configuration files should simply contain a list of kernel module names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is # or ; are ignored.

This is avery simple format to parse:

    for d in ${MODULES_DIRS_LIST}; do
        for f in "${d}"/*; do
            # Skip empty or missing directories, and dangling symlinks
            [ -e "${f}" ] || continue

            for m in $(sed -r -e 's/#.+//' "${f}"); do
                printf 'Loading module %s: ' "${m}"
                mpdorobe -s "${m}" && printf 'OK\n' || printf 'FAIL\n'
            done
        done
    done

No need for anything more complex than that.

Also, logger is from busybox, and a system may entirely lack busybox. Remeber that sysvinit scripts are also used when the init system is, well, initsysv instead of busybox.

I've marked the entire series (except patch 3 that I already appiled) as changes requested.

Also, you made that S02. But I believe this should come after S10mdev or S10udev, which both are going to trigger cold-plug events that may in turn trigger module loading.

Regards,
Yann E. MORIN.

Quoted 142 lines

The configuration directory list and file format is the same as the one described in modules-load.d(5). Files are loaded in the following order:

/etc/modules-load.d/*.conf
/run/modules-load.d/*.conf
/usr/lib/modules-load.d/*.conf

This roughly mimics the logic used by systemd but the files are not sorted by their filename in lexicographic order as systemd does.

Notice that OpenRC uses /etc/modules-load.d/*.conf, only, and does not ignore lines beginning with ';'.

The file redirections do the following:

- stdout is redirected to syslog with facility.level "kern.info"
- stderr is redirected to syslog with facility.level "kern.err"
- file dscriptor 4 is used to pass the result to the "start" function.

foo

---
 package/kmod/S02modules-load | 85 ++++++++++++++++++++++++++++++++++++
 package/kmod/kmod.mk         |  5 +++
 2 files changed, 90 insertions(+)
 create mode 100644 package/kmod/S02modules-load
package/kmod/S02modules-load new file +85 -0
new file mode 100644
index 0000000000..099cc63023
@@ -0,0 +1,85 @@
+#!/bin/sh
+
+PROGRAM="modules-load"
+
+MODULES_LOAD_ARGS=""
+
+# shellcheck source=/dev/null
+[ -r "/etc/default/$PROGRAM" ] && . "/etc/default/$PROGRAM"
+
+# Use some scripting to mimic the systemd "modules-load" and the OpenRC
+# "modules" services (load kernel modules based on static configuration).
+# 
+# The configuration files should simply contain a list of kernel module
+# names to load, separated by newlines. Empty lines and lines whose first
+# non-whitespace character is # or ; are ignored.
+# 
+# The configuration directory list and file format is the same as the one
+# described in modules-load.d(5). Files are loaded in the following order:
+# 
+#   /etc/modules-load.d/*.conf
+#   /run/modules-load.d/*.conf
+#   /usr/lib/modules-load.d/*.conf
+# 
+# This roughly mimics the logic used by systemd but the files are not sorted
+# by their filename in lexicographic order as systemd does.
+# 
+# Notice that OpenRC uses /etc/modules-load.d/*.conf, only, and does not
+# ignore lines beginning with ';'.
+#
+# The file redirections do the following:
+#
+# - stdout is redirected to syslog with facility.level "kern.info"
+# - stderr is redirected to syslog with facility.level "kern.err"
+# - file dscriptor 4 is used to pass the result to the "start" function.
+
+MODULES_LOAD_D="/etc/modules-load.d/ /run/modules-load.d/ /usr/lib/modules-load.d/"
+
+# Use some scripting to mimic the systemd-modules-load utility provided by
+# systemd, reporting results to syslog. Uers not interested on messages can
+# put "-q" in MODULES_LOAD_ARGS.
+
+run_program() {
+	# shellcheck disable=SC2086 # we need the word splitting
+	find $MODULES_LOAD_D -maxdepth 1 -name '*.conf' -print0 2> /dev/null | \
+	xargs -0 -r -n 1 readlink -f | {
+		prog_status="OK"
+		while :; do
+			read -r file
+			if [ -z "$file" ]; then
+				echo "$prog_status" >&4
+				break
+			fi
+			echo "* Applying $file ..."
+			while :; do
+				read -r mod || break
+				case "$mod" in
+					''|'#'*|';'*) ;;
+					*) /sbin/modprobe -s "$mod" || prog_status="FAIL"
+				esac
+			done < "$file"
+		done 2>&1 >&3 | /usr/bin/logger -t "$PROGRAM" -p kern.err
+	} 3>&1 | /usr/bin/logger -t "$PROGRAM" -p kern.info
+}
+
+start() {
+	printf '%s %s: ' "$1" "$PROGRAM"
+	status=$(run_program 4>&1)
+	echo "$status"
+	if [ "$status" = "OK" ]; then
+		return 0
+	fi
+	return 1
+}
+
+case "$1" in
+	start)
+		start "Running";;
+	restart|reload)
+		start "Rerunning";;
+	stop)
+		:;;
+	*)
+		echo "Usage: $0 {start|stop|restart|reload}"
+		exit 1
+esac
package/kmod/kmod.mk +5 -0
index e2dfea5c7b..31bdac6d81 100644
@@ -60,6 +60,11 @@ else
 KMOD_BIN_PATH = ../usr/bin/kmod
 endif
 
+define KMOD_INSTALL_INIT_SYSV
+	$(INSTALL) -m 0755 -D package/kmod/S02modules-load \
+		$(TARGET_DIR)/etc/init.d/S02modules-load
+endef
+
 define KMOD_INSTALL_TOOLS
 	for i in depmod insmod lsmod modinfo modprobe rmmod; do \
 		ln -sf $(KMOD_BIN_PATH) $(TARGET_DIR)/sbin/$$i; \
Signature · 6 lines
2.18.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#3 lore raw

RFC PATCH 1/1 1/6] package/kmod: add modules-load init script

Quoted 10 lines · Yann E. MORIN

Carlos, All,

On 2020-03-20 20:35 -0300, unixmania at gmail.com spake thusly:

Quoted 3 lines

From: Carlos Santos <[email protected]>
Use some scripting to mimic the systemd "modules-load" and the OpenRC "modules" services (load kernel modules based on static configuration).

So, the goal is laudable, but the implementation is overly complicated and, imho, flawed.

I agree that it is complicated but it's definitely not flawed. It was thoroughly tested and matches the construction already used in S02sysctl (check commits 7ab7c6c6b2 and 398c1af1d5).

Quoted 10 lines
Quoted 3 lines

The configuration files should simply contain a list of kernel module names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is # or ; are ignored.

This is avery simple format to parse:

    for d in ${MODULES_DIRS_LIST}; do
        for f in "${d}"/*; do
            # Skip empty or missing directories, and dangling symlinks
            [ -e "${f}" ] || continue

test -e does not fail on empty files or directories:

$ : > /tmp/empty-file
$ ls -l /tmp/empty-file
-rw-rw-r--. 1 casantos casantos 0 Mar 28 18:09 /tmp/empty-file
$ test -e /tmp/empty-file && echo ok
ok
$ mkdir /tmp/empty-dir
$ test -e /tmp/empty-dir && echo ok
ok
Quoted 1 line
            for m in $(sed -r -e 's/#.+//' "${f}"); do

This goes against good shell scripting practices, as pointed by
shellcheck: "SC2013: To read lines rather than words, pipe/redirect to a 'while read' loop."

Quoted 7 lines
                printf 'Loading module %s: ' "${m}"
                mpdorobe -s "${m}" && printf 'OK\n' || printf 'FAIL\n'
            done
        done
    done

No need for anything more complex than that.

We need something more complex than that if we care about the script robustness.

Quoted 3 lines

Also, logger is from busybox, and a system may entirely lack busybox. Remeber that sysvinit scripts are also used when the init system is, well, initsysv instead of busybox.

That's unfortunate. Not being able to send the errors to syslog is terrible on embedded systems, since usually nobody watches the console (if any) at boot time.

S02sysctl already assumes that logger is available, so I suppose that will need to fix it too.

Quoted 6 lines

I've marked the entire series (except patch 3 that I already appiled) as changes requested.

Also, you made that S02. But I believe this should come after S10mdev or S10udev, which both are going to trigger cold-plug events that may in turn trigger module loading.

Good catch. Thanks.

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

RFC PATCH 1/1 2/6] package/busybox: add modules-load init script

In reply to unixmania at gmail.com

From: Carlos Santos <[email protected]>

Use some scripting to mimic the systemd "modules-load" and the OpenRC "modules" services (load kernel modules based on static configuration).

At the moment package/busybox/S02modules-load is a symlink to the kmod script, since it works with both versions of the "modprobe" utility.

---
 package/busybox/S02modules-load |  1 +
 package/busybox/busybox.mk      | 12 ++++++++++++
 2 files changed, 13 insertions(+)
 create mode 120000 package/busybox/S02modules-load
package/busybox/S02modules-load new file +1 -0
new file mode 120000
index 0000000000..84edaae3d7
@@ -0,0 +1 @@
+../kmod/S02modules-load
\ No newline at end of file
package/busybox/busybox.mk +12 -0
index e2a4a8c5c7..767499b0c0 100644
@@ -264,6 +264,17 @@ define BUSYBOX_INSTALL_LOGGING_SCRIPT
 endef
 endif
 
+# Only install our modules-load script if no other package does it.
+ifeq ($(BR2_PACKAGE_KMOD_TOOLS),)
+define BUSYBOX_INSTALL_MODULES_SCRIPT
+	if grep -q CONFIG_MODPROBE=y $(@D)/.config; \
+	then \
+		$(INSTALL) -m 0755 -D package/busybox/S02modules-load \
+			$(TARGET_DIR)/etc/init.d/S02modules-load; \
+	fi
+endef
+endif
+
 # Only install our sysctl scripts if no other package does it.
 ifeq ($(BR2_PACKAGE_PROCPS_NG),)
 define BUSYBOX_INSTALL_SYSCTL_SCRIPT
@@ -368,6 +379,7 @@ define BUSYBOX_INSTALL_INIT_SYSV
 	$(BUSYBOX_INSTALL_MDEV_SCRIPT)
 	$(BUSYBOX_INSTALL_LOGGING_SCRIPT)
 	$(BUSYBOX_INSTALL_WATCHDOG_SCRIPT)
+	$(BUSYBOX_INSTALL_MODULES_SCRIPT)
 	$(BUSYBOX_INSTALL_SYSCTL_SCRIPT)
 	$(BUSYBOX_INSTALL_TELNET_SCRIPT)
 endef
Signature · 1 line
2.18.2
#5 lore raw

RFC PATCH 1/1 3/6] linux: run depmod in a target-finalize hook

In reply to unixmania at gmail.com

From: Carlos Santos <[email protected]>

If a package installs a kernel module then it's necessary to run depmod afterwards, otherwise modprobe fails at run-time, because the module is not included in /lib/modules/<kernel-version>/modules.dep.

Pass a dummy depmod (/dev/null) to the kernel build, since we don't want to run depmod after installing the kernel.

---
 linux/linux.mk | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
linux/linux.mk +10 -1
index f8c34c3dca..a5756148cc 100644
@@ -127,12 +127,14 @@ LINUX_POST_EXTRACT_HOOKS += LINUX_XTENSA_OVERLAY_EXTRACT
 LINUX_EXTRA_DOWNLOADS += $(ARCH_XTENSA_OVERLAY_URL)
 endif
 
+# We don't want to run depmod after installing the kernel. It's done in a
+# target-finalize hook, to encompass modules installed by packages.
 LINUX_MAKE_FLAGS = \
 	HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
 	ARCH=$(KERNEL_ARCH) \
 	INSTALL_MOD_PATH=$(TARGET_DIR) \
 	CROSS_COMPILE="$(TARGET_CROSS)" \
-	DEPMOD=$(HOST_DIR)/sbin/depmod
+	DEPMOD="/dev/null"
 
 ifeq ($(BR2_REPRODUCIBLE),y)
 LINUX_MAKE_ENV += \
@@ -534,6 +536,13 @@ define LINUX_INSTALL_TARGET_CMDS
 	$(LINUX_INSTALL_HOST_TOOLS)
 endef
 
+# Run depmod in a target-finalize hook, to encompass modules installed by
+# packages.
+define LINUX_RUN_DEPMOD
+	$(HOST_DIR)/sbin/depmod -a -b $(TARGET_DIR) $(LINUX_VERSION_PROBED)
+endef
+LINUX_TARGET_FINALIZE_HOOKS += LINUX_RUN_DEPMOD
+
 # Include all our extensions.
 #
 # Note: our package infrastructure uses the full-path of the last-scanned
Signature · 1 line
2.18.2
#6 lore raw

RFC PATCH 1/1 3/6] linux: run depmod in a target-finalize hook

CAlros, All,

On 2020-03-20 20:35 -0300, unixmania at gmail.com spake thusly:

Quoted 21 lines

From: Carlos Santos <[email protected]>

If a package installs a kernel module then it's necessary to run depmod afterwards, otherwise modprobe fails at run-time, because the module is not included in /lib/modules/<kernel-version>/modules.dep.

Pass a dummy depmod (/dev/null) to the kernel build, since we don't want to run depmod after installing the kernel.

---
 linux/linux.mk | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
linux/linux.mk +0 -0
index f8c34c3dca..a5756148cc 100644
@@ -127,12 +127,14 @@ LINUX_POST_EXTRACT_HOOKS += LINUX_XTENSA_OVERLAY_EXTRACT
 LINUX_EXTRA_DOWNLOADS += $(ARCH_XTENSA_OVERLAY_URL)
 endif

linux/linux.mk LINUX_POST_EXTRACT_HOOKS += LINUX_XTENSA_OVERLAY_EXTRACT · line 137

Quoted 10 lines
linux/linux.mk +3 -1
 
+# We don't want to run depmod after installing the kernel. It's done in a
+# target-finalize hook, to encompass modules installed by packages.
 LINUX_MAKE_FLAGS = \
 	HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
 	ARCH=$(KERNEL_ARCH) \
 	INSTALL_MOD_PATH=$(TARGET_DIR) \
 	CROSS_COMPILE="$(TARGET_CROSS)" \
-	DEPMOD=$(HOST_DIR)/sbin/depmod
+	DEPMOD="/dev/null"

This causes a spurious, confusing warning:

     DEPMOD  5.4.27
    ./scripts/depmod.sh: 46: /dev/null: Permission denied
    make[2]: *** [Makefile:1326: _modinst_post] Error 126

Since that call does not cost musch, I've restored it, and applied to master with an extended commit log. Thanks.

Regards,
Yann E. MORIN.

Quoted 23 lines
linux/linux.mk +7 -0
 ifeq ($(BR2_REPRODUCIBLE),y)
 LINUX_MAKE_ENV += \
@@ -534,6 +536,13 @@ define LINUX_INSTALL_TARGET_CMDS
 	$(LINUX_INSTALL_HOST_TOOLS)
 endef
 
+# Run depmod in a target-finalize hook, to encompass modules installed by
+# packages.
+define LINUX_RUN_DEPMOD
+	$(HOST_DIR)/sbin/depmod -a -b $(TARGET_DIR) $(LINUX_VERSION_PROBED)
+endef
+LINUX_TARGET_FINALIZE_HOOKS += LINUX_RUN_DEPMOD
+
 # Include all our extensions.
 #
 # Note: our package infrastructure uses the full-path of the last-scanned
Signature · 6 lines
2.18.2

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#7 lore raw

RFC PATCH 1/1 3/6] linux: run depmod in a target-finalize hook

Quoted 42 lines · Yann E. MORIN

CAlros, All,

On 2020-03-20 20:35 -0300, unixmania at gmail.com spake thusly:

Quoted 21 lines

From: Carlos Santos <[email protected]>

If a package installs a kernel module then it's necessary to run depmod afterwards, otherwise modprobe fails at run-time, because the module is not included in /lib/modules/<kernel-version>/modules.dep.

Pass a dummy depmod (/dev/null) to the kernel build, since we don't want to run depmod after installing the kernel.

---
 linux/linux.mk | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
linux/linux.mk +0 -0
index f8c34c3dca..a5756148cc 100644
@@ -127,12 +127,14 @@ LINUX_POST_EXTRACT_HOOKS += LINUX_XTENSA_OVERLAY_EXTRACT
 LINUX_EXTRA_DOWNLOADS += $(ARCH_XTENSA_OVERLAY_URL)
 endif

linux/linux.mk LINUX_POST_EXTRACT_HOOKS += LINUX_XTENSA_OVERLAY_EXTRACT · line 137

Quoted 10 lines
linux/linux.mk +3 -1
 
+# We don't want to run depmod after installing the kernel. It's done in a
+# target-finalize hook, to encompass modules installed by packages.
 LINUX_MAKE_FLAGS = \
      HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
      ARCH=$(KERNEL_ARCH) \
      INSTALL_MOD_PATH=$(TARGET_DIR) \
      CROSS_COMPILE="$(TARGET_CROSS)" \
-     DEPMOD=$(HOST_DIR)/sbin/depmod
+     DEPMOD="/dev/null"

This causes a spurious, confusing warning:

     DEPMOD  5.4.27
    ./scripts/depmod.sh: 46: /dev/null: Permission denied
    make[2]: *** [Makefile:1326: _modinst_post] Error 126
Quoted 5 lines

Since that call does not cost musch, I've restored it, and applied to master with an extended commit log. Thanks.

Regards,
Yann E. MORIN.

We can avoid the script by using

    DEPMOD=/bin/false \
    cmd_depmod=":"

So cmd_depmod ensures that the script does not run; DEPMOD=/bin/false is as a canary, failing if cmd_depmod does not work in a future kernel version.

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

RFC PATCH 1/1 4/6] package/dmraid: use modules-load to load the kernel module

In reply to unixmania at gmail.com

From: Carlos Santos <[email protected]>

This is compatible with BusyBox/sysvinit (via S02modules-load), OpenRC and systemd. It also prevents trying to load the module each time the init script is executed.

---
Tested on QEMU with a kernel config with MD=y and DM_<FOO>=m. Only the module loading was tested, since there is no RAID device.

---
 package/dmraid/S20dmraid |  3 ---
 package/dmraid/dmraid.mk | 12 ++++++++++++
 2 files changed, 12 insertions(+), 3 deletions(-)
package/dmraid/S20dmraid +0 -3
index b3bfdcc84b..ff325154c6 100644
@@ -2,9 +2,6 @@
 
 set -e
 
-# try to load module in case that hasn't been done yet
-modprobe dm-mod >/dev/null 2>&1
-
 case "$1" in
 	start|"")
 		echo "Setting up DMRAID devices..."
package/dmraid/dmraid.mk +12 -0
index 0382cd4d99..c8facbdabd 100644
@@ -21,4 +21,16 @@ define DMRAID_INSTALL_INIT_SYSV
 		$(TARGET_DIR)/etc/init.d/S20dmraid
 endef
 
+ifeq ($(BR2_LINUX_KERNEL),y)
+define DMRAID_GEN_MODULES_CONF
+	$(INSTALL) -d -m 755 $(TARGET_DIR)/etc/modules-load.d
+	{ \
+		find $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/kernel/drivers/md -name 'dm[_-]mod.ko*'; \
+	} 2> /dev/null | { \
+		sed 's:^.*/::; s:\.ko[^ ]*::'; \
+	} > $(TARGET_DIR)/etc/modules-load.d/20-dmraid.conf
+endef
+DMRAID_TARGET_FINALIZE_HOOKS += DMRAID_GEN_MODULES_CONF
+endif
+
 $(eval $(autotools-package))
Signature · 1 line
2.18.2
#9 lore raw

RFC PATCH 1/1 5/6] package/owfs: use modules-load to load the kernel module

In reply to unixmania at gmail.com

From: Carlos Santos <[email protected]>

This is compatible with BusyBox/sysvinit (via S02modules-load), OpenRC and systemd. It also prevents trying to load the module each time the init script is executed.

---
Tested on QEMU with a kernel config with FUSE_FS=m. Only the module loading was tested, since there is no 1-wire device.

---
 package/owfs/S60owfs |  2 --
 package/owfs/owfs.mk | 11 +++++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
package/owfs/S60owfs +0 -2
index feed676f8a..46b7ec775d 100644
@@ -10,8 +10,6 @@ OWFS_ARGS=""
 case "$1" in
 start)
 	printf "Starting ${NAME}: "
-	# Fuse may be in a module, so try to load it
-	modprobe -q fuse && printf "[fuse] "
 	mkdir -p ${OWFS_MOUNTPOINT}
 	start-stop-daemon -S -x ${DAEMON} -- \
 		--pid_file ${PID_F} -m ${OWFS_MOUNTPOINT} ${OWFS_DEVICES} \
package/owfs/owfs.mk +11 -0
index ffc0b3098d..a09a4bb37b 100644
@@ -35,6 +35,17 @@ define OWFS_CREATE_MOUNTPOINT
 	mkdir -p $(TARGET_DIR)/dev/1wire
 endef
 OWFS_POST_INSTALL_TARGET_HOOKS += OWFS_CREATE_MOUNTPOINT
+ifeq ($(BR2_LINUX_KERNEL),y)
+define OWFS_GEN_MODULES_CONF
+	$(INSTALL) -d -m 755 $(TARGET_DIR)/etc/modules-load.d
+	{ \
+		find $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/kernel/fs/fuse -name 'fuse.ko*'; \
+	} 2> /dev/null | { \
+		sed 's:^.*/::; s:\.ko[^ ]*::'; \
+	} > $(TARGET_DIR)/etc/modules-load.d/60-owfs.conf
+endef
+OWFS_TARGET_FINALIZE_HOOKS += OWFS_GEN_MODULES_CONF
+endif
 else
 OWFS_CONF_OPTS += --disable-owfs
 endif
Signature · 1 line
2.18.2
#10 lore raw

RFC PATCH 1/1 6/6] package/ti-sgx-km: use modules-load to load the kernel module

In reply to unixmania at gmail.com

From: Carlos Santos <[email protected]>

This is compatible with BusyBox/sysvinit (via S02modules-load), OpenRC and systemd. It also prevents trying to load the module each time the init script is executed.

Remove the insmod command from the ti-sgx-um init script.

---
Tested on a BeagleBone Black card using beaglebone_qt5_defconfig.

---
 package/ti-sgx-km/ti-sgx-km.mk | 10 ++++++++++
 package/ti-sgx-um/S80ti-sgx    | 19 ++-----------------
 2 files changed, 12 insertions(+), 17 deletions(-)
package/ti-sgx-km/ti-sgx-km.mk +10 -0
index ae294c300a..7f627f276b 100644
@@ -33,4 +33,14 @@ define TI_SGX_KM_INSTALL_TARGET_CMDS
 		kbuild_install -C $(@D)/$(TI_SGX_KM_SUBDIR)
 endef
 
+define TI_SGX_KM_GEN_MODULES_CONF
+	$(INSTALL) -d -m 755 $(TARGET_DIR)/etc/modules-load.d
+	{ \
+		find $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/extra -name 'pvrsrvkm.ko*'; \
+	} 2> /dev/null | { \
+		sed 's:^.*/::; s:\.ko[^ ]*::'; \
+	} > $(TARGET_DIR)/etc/modules-load.d/50-ti-sgx-km.conf
+endef
+TI_SGX_KM_TARGET_FINALIZE_HOOKS += TI_SGX_KM_GEN_MODULES_CONF
+
 $(eval $(generic-package))
package/ti-sgx-um/S80ti-sgx +2 -17
index 2630a0576a..0f183b6fc5 100644
@@ -1,24 +1,9 @@
 #!/bin/sh
 
-pvrsrvkm_ko="/lib/modules/$(/bin/uname -r)/extra/pvrsrvkm.ko"
-
-pvr_loaded() {
-	/sbin/lsmod | /bin/grep -q '^\<pvrsrvkm\>'
-}
-
-pvr_load() {
-	/sbin/insmod "$pvrsrvkm_ko" > /dev/null 2>&1
-}
-
 start() {
-	printf 'Loading pvrsrvkm module: '
-	pvr_loaded || pvr_load
+	printf 'Starting PowerVR services: '
+	/usr/bin/pvrsrvctl --start --no-module > /dev/null 2>&1
 	status=$?
-	if [ "$status" -eq 0 ]; then
-		printf 'Starting PowerVR services: '
-		/usr/bin/pvrsrvctl --start --no-module > /dev/null 2>&1
-		status=$?
-	fi
 	if [ "$status" -eq 0 ]; then
 		echo "OK"
 	else
Signature · 1 line
2.18.2