diff mbox series

[4/4] package/busybox: add service to load kernel modules at boot

Message ID 20220620214058.1435436-5-angelo@amarulasolutions.com
State Superseded
Headers show
Series Configure default wifi through kconfig | expand

Commit Message

Angelo Compagnucci June 20, 2022, 9:40 p.m. UTC
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.

Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
---
 package/busybox/S02modules | 56 ++++++++++++++++++++++++++++++++++++++
 package/busybox/busybox.mk |  2 ++
 2 files changed, 58 insertions(+)
 create mode 100644 package/busybox/S02modules

Comments

Arnout Vandecappelle June 21, 2022, 7:49 a.m. UTC | #1
On 20/06/2022 23:40, Angelo Compagnucci wrote:
> 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.

  Do you have a concrete example of something that needs this? It's kind of a 
hack for e.g. a device connected to a serial port that isn't described in DT 
(e.g. on an x86 platform), right?

  I'm not altogether sure if it is worth making an init script for that.

  Also, this would belong to the initscripts package because it would also be 
needed if busybox isn't used at all (it would of course require kmod).


> 
> Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
> ---
>   package/busybox/S02modules | 56 ++++++++++++++++++++++++++++++++++++++
>   package/busybox/busybox.mk |  2 ++
>   2 files changed, 58 insertions(+)
>   create mode 100644 package/busybox/S02modules
> 
> diff --git a/package/busybox/S02modules b/package/busybox/S02modules
> new file mode 100644
> index 0000000000..f25712e1ca
> --- /dev/null
> +++ b/package/busybox/S02modules
> @@ -0,0 +1,56 @@
> +#!/bin/sh
> +
> +MODULES="modules"
> +
> +load_unload() {
> +	[ ! -f /etc/${MODULES} ] && echo ' OK' && exit 0
> +
> +	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 < /etc/${MODULES}
> +}
> +
> +start() {
> +	printf 'Starting %s:' "$MODULES"
> +
> +	load_unload load
> +
> +	echo ' OK'
> +}
> +
> +stop() {
> +	printf 'Stopping %s: ' "$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
> diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
> index 3e49de0a84..40490e866a 100644
> --- a/package/busybox/busybox.mk
> +++ b/package/busybox/busybox.mk
> @@ -382,6 +382,8 @@ define BUSYBOX_INSTALL_TARGET_CMDS
>   	$(BUSYBOX_INSTALL_UDHCPC_SCRIPT)
>   	$(BUSYBOX_INSTALL_ZCIP_SCRIPT)
>   	$(BUSYBOX_INSTALL_MDEV_CONF)
> +	$(INSTALL) -m 0755 -D package/busybox/S02modules \
> +			$(TARGET_DIR)/etc/init.d/S02modules;

  This is a sysvinit script, so it should be installed in BUSYBOX_INSTALL_INIT_SYSV.



  Regards,
  Arnout

>   endef
>   
>   # Install the sysvinit scripts, for the moment, but not those that already
Angelo Compagnucci June 21, 2022, 9:20 a.m. UTC | #2
On Tue, Jun 21, 2022 at 9:49 AM Arnout Vandecappelle <arnout@mind.be> wrote:

>
>
> On 20/06/2022 23:40, Angelo Compagnucci wrote:
> > 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.
>
>   Do you have a concrete example of something that needs this? It's kind
> of a
> hack for e.g. a device connected to a serial port that isn't described in
> DT
> (e.g. on an x86 platform), right?
>

Wifi card connected on SDIO with an out of tree kernel module.


>   I'm not altogether sure if it is worth making an init script for that.
>

Most distros out there have the /etc/modules loaded at boot time.


>   Also, this would belong to the initscripts package because it would also
> be
> needed if busybox isn't used at all (it would of course require kmod).
>

Right, I'll fix it


>
>
> >
> > Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
> > ---
> >   package/busybox/S02modules | 56 ++++++++++++++++++++++++++++++++++++++
> >   package/busybox/busybox.mk |  2 ++
> >   2 files changed, 58 insertions(+)
> >   create mode 100644 package/busybox/S02modules
> >
> > diff --git a/package/busybox/S02modules b/package/busybox/S02modules
> > new file mode 100644
> > index 0000000000..f25712e1ca
> > --- /dev/null
> > +++ b/package/busybox/S02modules
> > @@ -0,0 +1,56 @@
> > +#!/bin/sh
> > +
> > +MODULES="modules"
> > +
> > +load_unload() {
> > +     [ ! -f /etc/${MODULES} ] && echo ' OK' && exit 0
> > +
> > +     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 < /etc/${MODULES}
> > +}
> > +
> > +start() {
> > +     printf 'Starting %s:' "$MODULES"
> > +
> > +     load_unload load
> > +
> > +     echo ' OK'
> > +}
> > +
> > +stop() {
> > +     printf 'Stopping %s: ' "$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
> > diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
> > index 3e49de0a84..40490e866a 100644
> > --- a/package/busybox/busybox.mk
> > +++ b/package/busybox/busybox.mk
> > @@ -382,6 +382,8 @@ define BUSYBOX_INSTALL_TARGET_CMDS
> >       $(BUSYBOX_INSTALL_UDHCPC_SCRIPT)
> >       $(BUSYBOX_INSTALL_ZCIP_SCRIPT)
> >       $(BUSYBOX_INSTALL_MDEV_CONF)
> > +     $(INSTALL) -m 0755 -D package/busybox/S02modules \
> > +                     $(TARGET_DIR)/etc/init.d/S02modules;
>
>   This is a sysvinit script, so it should be installed in
> BUSYBOX_INSTALL_INIT_SYSV.
>
>
>
>   Regards,
>   Arnout
>
> >   endef
> >
> >   # Install the sysvinit scripts, for the moment, but not those that
> already
>
diff mbox series

Patch

diff --git a/package/busybox/S02modules b/package/busybox/S02modules
new file mode 100644
index 0000000000..f25712e1ca
--- /dev/null
+++ b/package/busybox/S02modules
@@ -0,0 +1,56 @@ 
+#!/bin/sh
+
+MODULES="modules"
+
+load_unload() {
+	[ ! -f /etc/${MODULES} ] && echo ' OK' && exit 0
+
+	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 < /etc/${MODULES}
+}
+
+start() {
+	printf 'Starting %s:' "$MODULES"
+
+	load_unload load
+
+	echo ' OK'
+}
+
+stop() {
+	printf 'Stopping %s: ' "$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
diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
index 3e49de0a84..40490e866a 100644
--- a/package/busybox/busybox.mk
+++ b/package/busybox/busybox.mk
@@ -382,6 +382,8 @@  define BUSYBOX_INSTALL_TARGET_CMDS
 	$(BUSYBOX_INSTALL_UDHCPC_SCRIPT)
 	$(BUSYBOX_INSTALL_ZCIP_SCRIPT)
 	$(BUSYBOX_INSTALL_MDEV_CONF)
+	$(INSTALL) -m 0755 -D package/busybox/S02modules \
+			$(TARGET_DIR)/etc/init.d/S02modules;
 endef
 
 # Install the sysvinit scripts, for the moment, but not those that already