Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Angelo Compagnucci <angelo@amarulasolutions.com>
To: buildroot@buildroot.org
Cc: br015@umbiko.net, Angelo Compagnucci <angelo@amarulasolutions.com>
Subject: [Buildroot] [PATCH v3 5/5] package/initscripts: add service to load kernel modules at boot
Date: Tue,  5 Jul 2022 09:32:06 +0200	[thread overview]
Message-ID: <20220705073206.1442280-6-angelo@amarulasolutions.com> (raw)
In-Reply-To: <20220705073206.1442280-1-angelo@amarulasolutions.com>

In cases where no hotplug is available (by choice or by the lack of a
proper hotplug method for a device), this service can be used to load
kernel module drivers by reading the /etc/modules file.
The modules files matches the one used by systemd, which in turn has
a builtin mechanism to load a module at boot, therefore making systemv
init on par with systemd features.

Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
---
Changes

v2:
* Moved script to initscripts (Arnout)
* Moved script to S11modules, after S10[mu]dev (Andreas)
* Use /etc/modules-load.d/ to share the same setup with systemd (me)

 package/initscripts/init.d/S11modules | 59 +++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 package/initscripts/init.d/S11modules

diff --git a/package/initscripts/init.d/S11modules b/package/initscripts/init.d/S11modules
new file mode 100644
index 0000000000..3937945596
--- /dev/null
+++ b/package/initscripts/init.d/S11modules
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+MODULES="*.conf"
+MODULES_DIR="/etc/modules-load.d"
+
+[ -z "$(ls -A ${MODULES_DIR}/${MODULES} 2> /dev/null)" ] && exit 0
+
+load_unload() {
+	for module_file in $(ls -1 ${MODULES_DIR}); do
+		while read module args; do
+
+			case "$module" in
+				""|"#"*) continue ;;
+			esac
+
+			if [ "$1" = "load" ]; then
+				modprobe -q ${module} ${args} >/dev/null && \
+					printf ' %s success,' "$module" ||
+					printf ' %s failed,' "$module"
+			else
+				rmmod ${module} >/dev/null
+			fi
+
+		done < ${MODULES_DIR}/${module_file}
+	done
+}
+
+start() {
+	printf 'Starting modules:'
+
+	load_unload load
+
+	echo ' OK'
+}
+
+stop() {
+	printf 'Stopping modules:'
+
+	load_unload unload
+
+	echo 'OK'
+}
+
+restart() {
+	stop
+	sleep 1
+	start
+}
+
+case "$1" in
+	start|stop|restart)
+		"$1";;
+	reload)
+		# Restart, since there is no true "reload" feature.
+		restart;;
+	*)
+		echo "Usage: $0 {start|stop|restart|reload}"
+		exit 1
+esac
-- 
2.25.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  parent reply	other threads:[~2022-07-05  7:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-05  7:32 [Buildroot] [PATCH v3 0/5] Configure default wifi through kconfig Angelo Compagnucci
2022-07-05  7:32 ` [Buildroot] [PATCH v3 1/5] system: adding options for configuring wifi Angelo Compagnucci
2022-09-18  9:57   ` Peter Korsgaard
2022-10-03 15:42     ` Angelo Compagnucci
2022-10-04  9:05       ` Andreas Ziegler
2022-10-04  9:14         ` Angelo Compagnucci
2022-07-05  7:32 ` [Buildroot] [PATCH v3 2/5] package/wpa_supplicant: configure wifi on systemv when enabled Angelo Compagnucci
2022-07-05  7:32 ` [Buildroot] [PATCH v3 3/5] package/wpa_supplicant: configure wifi on systemd " Angelo Compagnucci
2022-09-18 10:00   ` Peter Korsgaard
2022-10-03 15:44     ` Angelo Compagnucci
2022-07-05  7:32 ` [Buildroot] [PATCH v3 4/5] package/ifupdown-scripts: add wifi configuration " Angelo Compagnucci
2022-09-18 10:03   ` Peter Korsgaard
2022-10-03 15:50     ` Angelo Compagnucci
2022-07-05  7:32 ` Angelo Compagnucci [this message]
2022-09-18 10:10   ` [Buildroot] [PATCH v3 5/5] package/initscripts: add service to load kernel modules at boot Peter Korsgaard
2022-10-03 15:53     ` Angelo Compagnucci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220705073206.1442280-6-angelo@amarulasolutions.com \
    --to=angelo@amarulasolutions.com \
    --cc=br015@umbiko.net \
    --cc=buildroot@buildroot.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox