All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [[PATCH RFC] 0/6] Add a kernel module loading mechanism
@ 2020-03-20 23:35 unixmania at gmail.com
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 1/6] package/kmod: add modules-load init script unixmania at gmail.com
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: unixmania at gmail.com @ 2020-03-20 23:35 UTC (permalink / raw
  To: buildroot

From: Carlos Santos <unixmania@gmail.com>

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

-- 
2.18.2

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Buildroot] [[PATCH RFC] 1/6] package/kmod: add modules-load init script
  2020-03-20 23:35 [Buildroot] [[PATCH RFC] 0/6] Add a kernel module loading mechanism unixmania at gmail.com
@ 2020-03-20 23:35 ` unixmania at gmail.com
  2020-03-21 21:03   ` Yann E. MORIN
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 2/6] package/busybox: " unixmania at gmail.com
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: unixmania at gmail.com @ 2020-03-20 23:35 UTC (permalink / raw
  To: buildroot

From: Carlos Santos <unixmania@gmail.com>

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.

Signed-off-by: Carlos Santos <unixmania@gmail.com>

foo
---
 package/kmod/S02modules-load | 85 ++++++++++++++++++++++++++++++++++++
 package/kmod/kmod.mk         |  5 +++
 2 files changed, 90 insertions(+)
 create mode 100644 package/kmod/S02modules-load

diff --git a/package/kmod/S02modules-load b/package/kmod/S02modules-load
new file mode 100644
index 0000000000..099cc63023
--- /dev/null
+++ b/package/kmod/S02modules-load
@@ -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
diff --git a/package/kmod/kmod.mk b/package/kmod/kmod.mk
index e2dfea5c7b..31bdac6d81 100644
--- a/package/kmod/kmod.mk
+++ b/package/kmod/kmod.mk
@@ -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; \
-- 
2.18.2

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Buildroot] [[PATCH RFC] 2/6] package/busybox: add modules-load init script
  2020-03-20 23:35 [Buildroot] [[PATCH RFC] 0/6] Add a kernel module loading mechanism unixmania at gmail.com
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 1/6] package/kmod: add modules-load init script unixmania at gmail.com
@ 2020-03-20 23:35 ` unixmania at gmail.com
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 3/6] linux: run depmod in a target-finalize hook unixmania at gmail.com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: unixmania at gmail.com @ 2020-03-20 23:35 UTC (permalink / raw
  To: buildroot

From: Carlos Santos <unixmania@gmail.com>

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.

Signed-off-by: Carlos Santos <unixmania@gmail.com>
---
 package/busybox/S02modules-load |  1 +
 package/busybox/busybox.mk      | 12 ++++++++++++
 2 files changed, 13 insertions(+)
 create mode 120000 package/busybox/S02modules-load

diff --git a/package/busybox/S02modules-load b/package/busybox/S02modules-load
new file mode 120000
index 0000000000..84edaae3d7
--- /dev/null
+++ b/package/busybox/S02modules-load
@@ -0,0 +1 @@
+../kmod/S02modules-load
\ No newline at end of file
diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
index e2a4a8c5c7..767499b0c0 100644
--- a/package/busybox/busybox.mk
+++ b/package/busybox/busybox.mk
@@ -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
-- 
2.18.2

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Buildroot] [[PATCH RFC] 3/6] linux: run depmod in a target-finalize hook
  2020-03-20 23:35 [Buildroot] [[PATCH RFC] 0/6] Add a kernel module loading mechanism unixmania at gmail.com
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 1/6] package/kmod: add modules-load init script unixmania at gmail.com
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 2/6] package/busybox: " unixmania at gmail.com
@ 2020-03-20 23:35 ` unixmania at gmail.com
  2020-03-21 20:51   ` Yann E. MORIN
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 4/6] package/dmraid: use modules-load to load the kernel module unixmania at gmail.com
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: unixmania at gmail.com @ 2020-03-20 23:35 UTC (permalink / raw
  To: buildroot

From: Carlos Santos <unixmania@gmail.com>

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.

Signed-off-by: Carlos Santos <unixmania@gmail.com>
---
 linux/linux.mk | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/linux/linux.mk b/linux/linux.mk
index f8c34c3dca..a5756148cc 100644
--- a/linux/linux.mk
+++ b/linux/linux.mk
@@ -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
-- 
2.18.2

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Buildroot] [[PATCH RFC] 4/6] package/dmraid: use modules-load to load the kernel module
  2020-03-20 23:35 [Buildroot] [[PATCH RFC] 0/6] Add a kernel module loading mechanism unixmania at gmail.com
                   ` (2 preceding siblings ...)
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 3/6] linux: run depmod in a target-finalize hook unixmania at gmail.com
@ 2020-03-20 23:35 ` unixmania at gmail.com
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 5/6] package/owfs: " unixmania at gmail.com
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 6/6] package/ti-sgx-km: " unixmania at gmail.com
  5 siblings, 0 replies; 11+ messages in thread
From: unixmania at gmail.com @ 2020-03-20 23:35 UTC (permalink / raw
  To: buildroot

From: Carlos Santos <unixmania@gmail.com>

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.

Signed-off-by: Carlos Santos <unixmania@gmail.com>
---
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(-)

diff --git a/package/dmraid/S20dmraid b/package/dmraid/S20dmraid
index b3bfdcc84b..ff325154c6 100644
--- a/package/dmraid/S20dmraid
+++ b/package/dmraid/S20dmraid
@@ -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..."
diff --git a/package/dmraid/dmraid.mk b/package/dmraid/dmraid.mk
index 0382cd4d99..c8facbdabd 100644
--- a/package/dmraid/dmraid.mk
+++ b/package/dmraid/dmraid.mk
@@ -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))
-- 
2.18.2

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Buildroot] [[PATCH RFC] 5/6] package/owfs: use modules-load to load the kernel module
  2020-03-20 23:35 [Buildroot] [[PATCH RFC] 0/6] Add a kernel module loading mechanism unixmania at gmail.com
                   ` (3 preceding siblings ...)
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 4/6] package/dmraid: use modules-load to load the kernel module unixmania at gmail.com
@ 2020-03-20 23:35 ` unixmania at gmail.com
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 6/6] package/ti-sgx-km: " unixmania at gmail.com
  5 siblings, 0 replies; 11+ messages in thread
From: unixmania at gmail.com @ 2020-03-20 23:35 UTC (permalink / raw
  To: buildroot

From: Carlos Santos <unixmania@gmail.com>

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.

Signed-off-by: Carlos Santos <unixmania@gmail.com>
---
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(-)

diff --git a/package/owfs/S60owfs b/package/owfs/S60owfs
index feed676f8a..46b7ec775d 100644
--- a/package/owfs/S60owfs
+++ b/package/owfs/S60owfs
@@ -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} \
diff --git a/package/owfs/owfs.mk b/package/owfs/owfs.mk
index ffc0b3098d..a09a4bb37b 100644
--- a/package/owfs/owfs.mk
+++ b/package/owfs/owfs.mk
@@ -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
-- 
2.18.2

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Buildroot] [[PATCH RFC] 6/6] package/ti-sgx-km: use modules-load to load the kernel module
  2020-03-20 23:35 [Buildroot] [[PATCH RFC] 0/6] Add a kernel module loading mechanism unixmania at gmail.com
                   ` (4 preceding siblings ...)
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 5/6] package/owfs: " unixmania at gmail.com
@ 2020-03-20 23:35 ` unixmania at gmail.com
  5 siblings, 0 replies; 11+ messages in thread
From: unixmania at gmail.com @ 2020-03-20 23:35 UTC (permalink / raw
  To: buildroot

From: Carlos Santos <unixmania@gmail.com>

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.

Signed-off-by: Carlos Santos <unixmania@gmail.com>
---
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(-)

diff --git a/package/ti-sgx-km/ti-sgx-km.mk b/package/ti-sgx-km/ti-sgx-km.mk
index ae294c300a..7f627f276b 100644
--- a/package/ti-sgx-km/ti-sgx-km.mk
+++ b/package/ti-sgx-km/ti-sgx-km.mk
@@ -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))
diff --git a/package/ti-sgx-um/S80ti-sgx b/package/ti-sgx-um/S80ti-sgx
index 2630a0576a..0f183b6fc5 100644
--- a/package/ti-sgx-um/S80ti-sgx
+++ b/package/ti-sgx-um/S80ti-sgx
@@ -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
-- 
2.18.2

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Buildroot] [[PATCH RFC] 3/6] linux: run depmod in a target-finalize hook
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 3/6] linux: run depmod in a target-finalize hook unixmania at gmail.com
@ 2020-03-21 20:51   ` Yann E. MORIN
  2020-03-21 22:18     ` Carlos Santos
  0 siblings, 1 reply; 11+ messages in thread
From: Yann E. MORIN @ 2020-03-21 20:51 UTC (permalink / raw
  To: buildroot

CAlros, All,

On 2020-03-20 20:35 -0300, unixmania at gmail.com spake thusly:
> From: Carlos Santos <unixmania@gmail.com>
> 
> 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.
> 
> Signed-off-by: Carlos Santos <unixmania@gmail.com>
> ---
>  linux/linux.mk | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/linux/linux.mk b/linux/linux.mk
> index f8c34c3dca..a5756148cc 100644
> --- a/linux/linux.mk
> +++ b/linux/linux.mk
> @@ -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"

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.

>  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
> -- 
> 2.18.2
> 
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  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.  |
'------------------------------^-------^------------------^--------------------'

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Buildroot] [[PATCH RFC] 1/6] package/kmod: add modules-load init script
  2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 1/6] package/kmod: add modules-load init script unixmania at gmail.com
@ 2020-03-21 21:03   ` Yann E. MORIN
  2020-03-28 21:30     ` Carlos Santos
  0 siblings, 1 reply; 11+ messages in thread
From: Yann E. MORIN @ 2020-03-21 21:03 UTC (permalink / raw
  To: buildroot

Carlos, All,

On 2020-03-20 20:35 -0300, unixmania at gmail.com spake thusly:
> From: Carlos Santos <unixmania@gmail.com>
> 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.

> 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.

> 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.
> 
> Signed-off-by: Carlos Santos <unixmania@gmail.com>
> 
> foo
> ---
>  package/kmod/S02modules-load | 85 ++++++++++++++++++++++++++++++++++++
>  package/kmod/kmod.mk         |  5 +++
>  2 files changed, 90 insertions(+)
>  create mode 100644 package/kmod/S02modules-load
> 
> diff --git a/package/kmod/S02modules-load b/package/kmod/S02modules-load
> new file mode 100644
> index 0000000000..099cc63023
> --- /dev/null
> +++ b/package/kmod/S02modules-load
> @@ -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
> diff --git a/package/kmod/kmod.mk b/package/kmod/kmod.mk
> index e2dfea5c7b..31bdac6d81 100644
> --- a/package/kmod/kmod.mk
> +++ b/package/kmod/kmod.mk
> @@ -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; \
> -- 
> 2.18.2
> 
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  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.  |
'------------------------------^-------^------------------^--------------------'

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Buildroot] [[PATCH RFC] 3/6] linux: run depmod in a target-finalize hook
  2020-03-21 20:51   ` Yann E. MORIN
@ 2020-03-21 22:18     ` Carlos Santos
  0 siblings, 0 replies; 11+ messages in thread
From: Carlos Santos @ 2020-03-21 22:18 UTC (permalink / raw
  To: buildroot

On Sat, Mar 21, 2020 at 5:51 PM Yann E. MORIN <yann.morin.1998@free.fr> wrote:
>
> CAlros, All,
>
> On 2020-03-20 20:35 -0300, unixmania at gmail.com spake thusly:
> > From: Carlos Santos <unixmania@gmail.com>
> >
> > 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.
> >
> > Signed-off-by: Carlos Santos <unixmania@gmail.com>
> > ---
> >  linux/linux.mk | 11 ++++++++++-
> >  1 file changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/linux/linux.mk b/linux/linux.mk
> > index f8c34c3dca..a5756148cc 100644
> > --- a/linux/linux.mk
> > +++ b/linux/linux.mk
> > @@ -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"
>
> 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.

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.

-- 
Carlos Santos <unixmania@gmail.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Buildroot] [[PATCH RFC] 1/6] package/kmod: add modules-load init script
  2020-03-21 21:03   ` Yann E. MORIN
@ 2020-03-28 21:30     ` Carlos Santos
  0 siblings, 0 replies; 11+ messages in thread
From: Carlos Santos @ 2020-03-28 21:30 UTC (permalink / raw
  To: buildroot

On Sat, Mar 21, 2020 at 6:03 PM Yann E. MORIN <yann.morin.1998@free.fr> wrote:
>
> Carlos, All,
>
> On 2020-03-20 20:35 -0300, unixmania at gmail.com spake thusly:
> > From: Carlos Santos <unixmania@gmail.com>
> > 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).

> > 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

>             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."

>                 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.

> 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.

> 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.

-- 
Carlos Santos <unixmania@gmail.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-03-28 21:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-20 23:35 [Buildroot] [[PATCH RFC] 0/6] Add a kernel module loading mechanism unixmania at gmail.com
2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 1/6] package/kmod: add modules-load init script unixmania at gmail.com
2020-03-21 21:03   ` Yann E. MORIN
2020-03-28 21:30     ` Carlos Santos
2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 2/6] package/busybox: " unixmania at gmail.com
2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 3/6] linux: run depmod in a target-finalize hook unixmania at gmail.com
2020-03-21 20:51   ` Yann E. MORIN
2020-03-21 22:18     ` Carlos Santos
2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 4/6] package/dmraid: use modules-load to load the kernel module unixmania at gmail.com
2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 5/6] package/owfs: " unixmania at gmail.com
2020-03-20 23:35 ` [Buildroot] [[PATCH RFC] 6/6] package/ti-sgx-km: " unixmania at gmail.com

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.