Skip to contentSkip to conversation

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

PATCH Andreas Ziegler 4 participants 8 messages Jun 25, 2022 – Jun 28, 2022 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

Hi Angelo,

Quoted 37 lines · Angelo Compagnucci
Quoted 7 lines · Angelo Compagnucci
Quoted 3 lines

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.

Quoted 7 lines

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.

Quoted 3 lines

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.

Quoted 5 lines

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

Quoted 3 lines
Quoted 3 lines
Quoted 8 lines
Quoted 8 lines

package/busybox/S02modules

Quoted 8 lines
---
  package/busybox/S02modules | 56 ++++++++++++++++++++++++++++++++++++++
  package/busybox/busybox.mk |  2 ++
  2 files changed, 58 insertions(+)

create mode 100644 package/busybox/S02modules

package/busybox/S02modules +0 -0

S02 is a bit early, [mu]dev use S10.

Quoted 63 lines
Quoted 63 lines
Quoted 63 lines

new file mode 100644
index 0000000000..f25712e1ca

package/busybox/S02modules new file +56 -0
@@ -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
package/busybox/busybox.mk +0 -0
index 3e49de0a84..40490e866a 100644
Quoted 8 lines
Quoted 8 lines

package/busybox/busybox.mk define BUSYBOX_INSTALL_TARGET_CMDS · line 386

Quoted 8 lines
package/busybox/busybox.mk +2 -0
@@ -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;

Since this is intended for systems without dynamic device handling, you might use an optional script, similar to BUSYBOX_INSTALL_*_SCRIPT:

# Copy S22modules to /etc/init.d if no dynamic device handling is used ifeq ($(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
define BUSYBOX_INSTALL_MODULES_SCRIPT

	$(INSTALL) -m 0755 -D package/busybox/S22modules \
		$(TARGET_DIR)/etc/init.d/S22modules;

endef # BUSYBOX_INSTALL_MODULES_SCRIPT

Probably a default /etc/modules could also be installed.

Kind regards,
Andreas

Quoted 26 lines
Quoted 6 lines

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

Quoted 8 lines

Regards,
Arnout

package/busybox/busybox.mk define BUSYBOX_INSTALL_TARGET_CMDS · line 389

Quoted 3 lines
package/busybox/busybox.mk +0 -0
  endef
 
  # Install the sysvinit scripts, for the moment, but not those that

already

--

Angelo Compagnucci

Software Engineer

[email protected]
__________________________________
Amarula Solutions SRL

Quoted 7 lines

Via le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 (0)42 243 5310
[email protected]

www.amarulasolutions.com
[`as] https://www.amarulasolutions.com|

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#7 lore raw

Re: [Buildroot] [PATCH 1/4] system: adding options for configuring wifi

In reply to a message not in the archive

Hi Angelo,

Quoted 23 lines · Angelo Compagnucci

These options can be used by packages to configure a wifi card to connect at boot.

---
 system/Config.in | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
system/Config.in +0 -0
index 888c24ce81..9a5bdb2932 100644
@@ -418,6 +418,21 @@ comment "automatic network configuration via DHCP

needs ifupdown or busybox or n

system/Config.in +5 -0
 	depends on !(BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_IFUPDOWN || \
 		BR2_PACKAGE_SYSTEMD_NETWORKD || BR2_PACKAGE_NETIFRC)
 
+config BR2_SYSTEM_CONNECT_WIFI
+	bool "Connect to a default wifi access point"
+	default n
+	depends on BR2_PACKAGE_WPA_SUPPLICANT
+

system/Config.in

Quoted 10 lines
system/Config.in +10 -0
+config BR2_SYSTEM_CONNECT_WIFI_SSID
+	string "Access point SSID"
+	default ""
+	depends on BR2_SYSTEM_CONNECT_WIFI
+
+config BR2_SYSTEM_CONNECT_WIFI_PASSWORD
+	string "Access point password"
+	default ""
+	depends on BR2_SYSTEM_CONNECT_WIFI
+

Just nagging, but this is how security breaches get born. If I want to do something like this, I use a private overlay outside the region under backup or version control ...

Kind regards,
Andreas

Quoted 5 lines

endif # BR2_ROOTFS_SKELETON_DEFAULT

config BR2_SYSTEM_DEFAULT_PATH
--
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#8 lore raw

Re: [Buildroot] [PATCH 1/4] system: adding options for configuring wifi

Quoted 33 lines · Andreas Ziegler

Hi Angelo,

Quoted 29 lines · Angelo Compagnucci

These options can be used by packages to configure a wifi card to connect at boot.

---
 system/Config.in | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
system/Config.in +0 -0
index 888c24ce81..9a5bdb2932 100644
@@ -418,6 +418,21 @@ comment "automatic network configuration via DHCP

needs ifupdown or busybox or n

      depends on !(BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_IFUPDOWN || \
              BR2_PACKAGE_SYSTEMD_NETWORKD || BR2_PACKAGE_NETIFRC)
system/Config.in +11 -0
+config BR2_SYSTEM_CONNECT_WIFI
+     bool "Connect to a default wifi access point"
+     default n
+     depends on BR2_PACKAGE_WPA_SUPPLICANT
+
+config BR2_SYSTEM_CONNECT_WIFI_SSID
+     string "Access point SSID"
+     default ""
+     depends on BR2_SYSTEM_CONNECT_WIFI
+
+config BR2_SYSTEM_CONNECT_WIFI_PASSWORD
Quoted 9 lines

system/Config.in

Quoted 4 lines
system/Config.in +4 -0
+     string "Access point password"
+     default ""
+     depends on BR2_SYSTEM_CONNECT_WIFI
+

Just nagging, but this is how security breaches get born. If I want to do something like this, I use a private overlay outside the region under backup or version control ...

I wouldn't be so worried about security since a user can have BR2_TARGET_GENERIC_ROOT_PASSWD in his .config

Anyway, you end up having the wifi password stored somewhere in the overlay anyway, so I can't see a problem here.

Or you can use an empty password to store in the .config on the version control, and have a simple sed to replace with the correct credentials just before the developer makes a build. In any case, having those options makes way easier to configure a wifi than guessing the correct overlay to setup.

Quoted 9 lines

Kind regards,
Andreas

Quoted 5 lines

endif # BR2_ROOTFS_SKELETON_DEFAULT

config BR2_SYSTEM_DEFAULT_PATH
--
2.25.1

Signature · 15 lines
Angelo Compagnucci

Software Engineer

[email protected]
__________________________________
Amarula Solutions SRL

Via le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 (0)42 243 5310
[email protected]

www.amarulasolutions.com
[`as] https://www.amarulasolutions.com|

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#2 lore raw
In reply to Andreas Ziegler
Quoted 46 lines · Andreas Ziegler

Hi Angelo,

Quoted 26 lines · Angelo Compagnucci
Quoted 7 lines · Angelo Compagnucci
Quoted 3 lines

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.

Quoted 8 lines

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.

Quoted 3 lines

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.

Quoted 15 lines
Quoted 5 lines

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

Quoted 6 lines
Quoted 6 lines
---
  package/busybox/S02modules | 56
Quoted 9 lines

++++++++++++++++++++++++++++++++++++++

Quoted 5 lines
Quoted 5 lines

package/busybox/S02modules

Quoted 5 lines
  package/busybox/busybox.mk |  2 ++
  2 files changed, 58 insertions(+)

create mode 100644 package/busybox/S02modules

package/busybox/S02modules +0 -0

S02 is a bit early, [mu]dev use S10.

Can you point me to these [mu]dev scripts?

Quoted 75 lines
Quoted 63 lines
Quoted 63 lines
Quoted 63 lines

new file mode 100644
index 0000000000..f25712e1ca

package/busybox/S02modules new file +56 -0
@@ -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
package/busybox/busybox.mk +0 -0
index 3e49de0a84..40490e866a 100644
Quoted 8 lines
Quoted 8 lines

package/busybox/busybox.mk define BUSYBOX_INSTALL_TARGET_CMDS · line 386

Quoted 8 lines
package/busybox/busybox.mk +2 -0
@@ -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;

Since this is intended for systems without dynamic device handling, you might use an optional script, similar to BUSYBOX_INSTALL_*_SCRIPT:

Quoted 9 lines

# Copy S22modules to /etc/init.d if no dynamic device handling is used ifeq ($(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
define BUSYBOX_INSTALL_MODULES_SCRIPT

        $(INSTALL) -m 0755 -D package/busybox/S22modules \
                $(TARGET_DIR)/etc/init.d/S22modules;

endef # BUSYBOX_INSTALL_MODULES_SCRIPT

Probably a default /etc/modules could also be installed.

Yes, but it is not the only usecase here. A usecase could be a userspace software that needs a special kernel module to be loaded on boot or a hardware which cannot be hotplugged.
My usecase was for a wifi card connected via sdio running only with an out of tree kernel module. The wifi card is soldered and doesn't have a CS to trigger an hotplug event and the only sensible way I found to load the module at boot was to have a proper way to load modules at boot. I'm not aware normal distros does so much tinkering about loading a kernel module at boot: /etc/modules or the newly /etc/modules-load.d/ for systemd are widely adopted and are usually working out of the box.

Quoted 38 lines

Kind regards,
Andreas

Quoted 33 lines
Quoted 6 lines

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

Quoted 8 lines

Regards,
Arnout

package/busybox/busybox.mk define BUSYBOX_INSTALL_TARGET_CMDS · line 389

Quoted 3 lines
package/busybox/busybox.mk +0 -0
  endef
 
  # Install the sysvinit scripts, for the moment, but not those that

already

--

Angelo Compagnucci

Software Engineer

[email protected]
__________________________________
Amarula Solutions SRL

Via le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 (0)42 243 5310
[email protected]

www.amarulasolutions.com
[`as] https://www.amarulasolutions.com|

Signature · 15 lines
Angelo Compagnucci

Software Engineer

[email protected]
__________________________________
Amarula Solutions SRL

Via le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 (0)42 243 5310
[email protected]

www.amarulasolutions.com
[`as] https://www.amarulasolutions.com|

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#4 lore raw

Il giorno mar 28 giu 2022 alle ore 10:23 Nicolas Cavallari <[email protected]> ha scritto:

Quoted 11 lines · Angelo Compagnucci
Quoted 7 lines

>> > diff --git a/package/busybox/S02modules
b/package/busybox/S02modules

S02 is a bit early, [mu]dev use S10.

Can you point me to these [mu]dev scripts?

package/eudev/S10udev and package/busybox/S10mdev

Thanks! So basically the idea is to move this service after the [mu]dev ones, S11modules should be ok, will do.

Quoted 4 lines

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

Signature · 5 lines
Profile: http://it.linkedin.com/in/compagnucciangelo
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#5 lore raw
In reply to Angelo Compagnucci

Hi Angelo,

Quoted 157 lines · Angelo Compagnucci
Quoted 55 lines · Andreas Ziegler

Hi Angelo,

Quoted 4 lines · Angelo Compagnucci
Quoted 4 lines · Angelo Compagnucci
Quoted 1 line

In cases where no hotplug is available (by choice or by the

lack of a

Quoted 1 line
Quoted 1 line
Quoted 1 line

proper hotplug method for a device), this service can be used

to load

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

kernel module drivers by reading the /etc/modules file.

Do you have a concrete example of something that needs this?

It's

Quoted 3 lines
Quoted 3 lines

kind
of a
hack for e.g. a device connected to a serial port that isn't

described

Quoted 9 lines
Quoted 4 lines

in
DT
(e.g. on an x86 platform), right?

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

Quoted 1 line

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

for

Quoted 7 lines
Quoted 2 lines

that.

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

Quoted 1 line

Also, this would belong to the initscripts package because it

would

Quoted 3 lines
Quoted 3 lines

also
be
needed if busybox isn't used at all (it would of course require

kmod).

Quoted 11 lines
Quoted 1 line

Right, I'll fix it

Quoted 6 lines
Quoted 6 lines
---
  package/busybox/S02modules | 56

++++++++++++++++++++++++++++++++++++++

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 5 lines
  package/busybox/busybox.mk [1] |  2 ++
  2 files changed, 58 insertions(+)

create mode 100644 package/busybox/S02modules

(quoted diff) +0 -0

b/package/busybox/S02modules

S02 is a bit early, [mu]dev use S10.

Can you point me to these [mu]dev scripts?

Quoted 88 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

new file mode 100644
index 0000000000..f25712e1ca

package/busybox/S02modules new file +7 -0
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+MODULES="modules"
+
+load_unload() {
+     [ ! -f /etc/${MODULES} ] && echo ' OK' && exit 0
+
Quoted 8 lines
Quoted 8 lines

package/busybox/S02modules line 15

Quoted 8 lines
package/busybox/S02modules new file +8 -0
+     while read module args; do
+
+             case "$module" in
+                     ""|"#"*) continue ;;
+             esac
+
+             if [ "$1" = "load" ]; then
+                     modprobe -q ${module} ${args} >/dev/null

&& \

Quoted 1 line
Quoted 1 line

package/busybox/S02modules line 16

Quoted 1 line
package/busybox/S02modules new file +1 -0
+                             printf ' %s success,' "$module"
||
>>> +                             printf ' %s failed,' "$module"
>>> +             else
>>> +                     rmmod ${module} >/dev/null
>>> +             fi
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
package/busybox/S02modules new file +23 -0
+
+     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
Quoted 8 lines
Quoted 8 lines

package/busybox/S02modules line 47

Quoted 8 lines
package/busybox/S02modules new file +8 -0
+     start
+}
+
+case "$1" in
+     start|stop|restart)
+             "$1";;
+     reload)
+             # Restart, since there is no true "reload"

feature.

Quoted 6 lines
Quoted 6 lines

[1]

Quoted 6 lines
package/busybox/S02modules new file +5 -0
+             restart;;
+     *)
+             echo "Usage: $0 {start|stop|restart|reload}"
+             exit 1
+esac
[1] renamed from package/busybox/busybox.mk +0 -0

b/package/busybox/busybox.mk [1]

Quoted 9 lines
Quoted 9 lines

package/busybox/busybox.mk [1] define BUSYBOX_INSTALL_TARGET_CMDS · line 386

Quoted 9 lines

index 3e49de0a84..40490e866a 100644

package/busybox/busybox.mk [1] +2 -0
@@ -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;

Since this is intended for systems without dynamic device handling, you
might use an optional script, similar to BUSYBOX_INSTALL_*_SCRIPT:

# Copy S22modules to /etc/init.d if no dynamic device handling is used
ifeq ($(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
define BUSYBOX_INSTALL_MODULES_SCRIPT
$(INSTALL) -m 0755 -D package/busybox/S22modules \
$(TARGET_DIR)/etc/init.d/S22modules;
endef # BUSYBOX_INSTALL_MODULES_SCRIPT

Quoted 5 lines
Quoted 1 line

Probably a default /etc/modules could also be installed.

Yes, but it is not the only usecase here. A usecase could be a userspace software that needs a special kernel module to be loaded on boot or a hardware which cannot be hotplugged.

Then a Config.in item to select this feature would be appreciated, since most configurations will not need it.

Quoted 5 lines

My usecase was for a wifi card connected via sdio running only with an out of tree kernel module. The wifi card is soldered and doesn't have a CS to trigger an hotplug event and the only sensible way I found to load the module at boot was to have a proper way to load modules at boot.

I used something similar initially, until switching to udev.

Quoted 4 lines

I'm not aware normal distros does so much tinkering about loading a kernel module at boot: /etc/modules or the newly /etc/modules-load.d/ for systemd are widely adopted and are usually working out of the box.

Kind regards,
Andreas

Quoted 55 lines
Quoted 9 lines

Kind regards,
Andreas

Quoted 6 lines
Quoted 6 lines

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

Quoted 28 lines
Quoted 6 lines
Quoted 6 lines

Regards,
Arnout

Quoted 3 lines
package/busybox/busybox.mk [1] +0 -0
  endef
 
  # Install the sysvinit scripts, for the moment, but not those

that

Quoted 21 lines
Quoted 2 lines

already

--

Angelo Compagnucci

Software Engineer

[email protected]
__________________________________
Amarula Solutions SRL

Via le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 (0)42 243 5310
[email protected]

www.amarulasolutions.com [2]
[`as] https://www.amarulasolutions.com|

--

Angelo Compagnucci

Software Engineer

[email protected]
__________________________________
Amarula Solutions SRL

Via le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 (0)42 243 5310
[email protected]

www.amarulasolutions.com [3]

Quoted 7 lines

[`as] https://www.amarulasolutions.com|

Links:
------
[1] http://busybox.mk
[2] http://www.amarulasolutions.com
[3] http://www.amarulasolutions.com/

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#6 lore raw
Quoted 160 lines · Andreas Ziegler

Hi Angelo,

Quoted 157 lines · Angelo Compagnucci
Quoted 55 lines · Andreas Ziegler

Hi Angelo,

Quoted 4 lines · Angelo Compagnucci
Quoted 4 lines · Angelo Compagnucci
Quoted 1 line

In cases where no hotplug is available (by choice or by the

lack of a

Quoted 1 line
Quoted 1 line
Quoted 1 line

proper hotplug method for a device), this service can be used

to load

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

kernel module drivers by reading the /etc/modules file.

Do you have a concrete example of something that needs this?

It's

Quoted 3 lines
Quoted 3 lines

kind
of a
hack for e.g. a device connected to a serial port that isn't

described

Quoted 9 lines
Quoted 4 lines

in
DT
(e.g. on an x86 platform), right?

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

Quoted 1 line

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

for

Quoted 7 lines
Quoted 2 lines

that.

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

Quoted 1 line

Also, this would belong to the initscripts package because it

would

Quoted 3 lines
Quoted 3 lines

also
be
needed if busybox isn't used at all (it would of course require

kmod).

Quoted 11 lines
Quoted 1 line

Right, I'll fix it

Quoted 6 lines
Quoted 6 lines
---
  package/busybox/S02modules | 56

++++++++++++++++++++++++++++++++++++++

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 5 lines
  package/busybox/busybox.mk [1] |  2 ++
  2 files changed, 58 insertions(+)

create mode 100644 package/busybox/S02modules

(quoted diff) +0 -0

b/package/busybox/S02modules

S02 is a bit early, [mu]dev use S10.

Can you point me to these [mu]dev scripts?

Quoted 88 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

new file mode 100644
index 0000000000..f25712e1ca

package/busybox/S02modules new file +7 -0
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+MODULES="modules"
+
+load_unload() {
+     [ ! -f /etc/${MODULES} ] && echo ' OK' && exit 0
+
Quoted 8 lines
Quoted 8 lines

package/busybox/S02modules line 15

Quoted 8 lines
package/busybox/S02modules new file +8 -0
+     while read module args; do
+
+             case "$module" in
+                     ""|"#"*) continue ;;
+             esac
+
+             if [ "$1" = "load" ]; then
+                     modprobe -q ${module} ${args} >/dev/null

&& \

Quoted 1 line
Quoted 1 line

package/busybox/S02modules line 16

Quoted 1 line
package/busybox/S02modules new file +1 -0
+                             printf ' %s success,' "$module"
||
>>> +                             printf ' %s failed,' "$module"
>>> +             else
>>> +                     rmmod ${module} >/dev/null
>>> +             fi
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
package/busybox/S02modules new file +23 -0
+
+     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
Quoted 8 lines
Quoted 8 lines

package/busybox/S02modules line 47

Quoted 8 lines
package/busybox/S02modules new file +8 -0
+     start
+}
+
+case "$1" in
+     start|stop|restart)
+             "$1";;
+     reload)
+             # Restart, since there is no true "reload"

feature.

Quoted 6 lines
Quoted 6 lines

[1]

Quoted 6 lines
package/busybox/S02modules new file +5 -0
+             restart;;
+     *)
+             echo "Usage: $0 {start|stop|restart|reload}"
+             exit 1
+esac
[1] renamed from package/busybox/busybox.mk +0 -0

b/package/busybox/busybox.mk [1]

Quoted 9 lines
Quoted 9 lines

package/busybox/busybox.mk [1] define BUSYBOX_INSTALL_TARGET_CMDS · line 386

Quoted 9 lines

index 3e49de0a84..40490e866a 100644

package/busybox/busybox.mk [1] +2 -0
@@ -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;

Since this is intended for systems without dynamic device handling, you
might use an optional script, similar to BUSYBOX_INSTALL_*_SCRIPT:

# Copy S22modules to /etc/init.d if no dynamic device handling is used
ifeq ($(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
define BUSYBOX_INSTALL_MODULES_SCRIPT
$(INSTALL) -m 0755 -D package/busybox/S22modules \
$(TARGET_DIR)/etc/init.d/S22modules;
endef # BUSYBOX_INSTALL_MODULES_SCRIPT

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Probably a default /etc/modules could also be installed.

Yes, but it is not the only usecase here. A usecase could be a userspace software that needs a special kernel module to be loaded on boot or a hardware which cannot be hotplugged.

Then a Config.in item to select this feature would be appreciated, since most configurations will not need it.

Not sure if it will be happily accepted ;)
The last word is on the BR maintainers.
Anyway, in systemd we have the service always installed and available, it prints anything to the console if no module should be loaded. I can move the check for the modules file at the very beginning of the script, so it's like it has never been executed.

Quoted 8 lines

My usecase was for a wifi card connected via sdio running only with an

Quoted 4 lines

out of tree kernel module. The wifi card is soldered and doesn't have a CS to trigger an hotplug event and the only sensible way I found to load the module at boot was to have a proper way to load modules at boot.

I used something similar initially, until switching to udev.

Sure I can, but this patch is exactly to cover the cases where a developer cannot/won't switch to something like that.

Quoted 72 lines
Quoted 5 lines

I'm not aware normal distros does so much tinkering about loading a kernel module at boot: /etc/modules or the newly /etc/modules-load.d/ for systemd are widely adopted and are usually working out of the box.

Kind regards,
Andreas

Quoted 62 lines
Quoted 9 lines

Kind regards,
Andreas

Quoted 6 lines
Quoted 6 lines

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

Quoted 28 lines
Quoted 6 lines
Quoted 6 lines

Regards,
Arnout

Quoted 3 lines
package/busybox/busybox.mk [1] +0 -0
  endef
 
  # Install the sysvinit scripts, for the moment, but not those

that

Quoted 21 lines
Quoted 2 lines

already

--

Angelo Compagnucci

Software Engineer

[email protected]
__________________________________
Amarula Solutions SRL

Via le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 (0)42 243 5310
[email protected]

www.amarulasolutions.com [2]
[`as] https://www.amarulasolutions.com|

--

Angelo Compagnucci

Software Engineer

[email protected]
__________________________________
Amarula Solutions SRL

Via le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 (0)42 243 5310
[email protected]

www.amarulasolutions.com [3]

[`as] https://www.amarulasolutions.com|

Links:
------
[1] http://busybox.mk
[2] http://www.amarulasolutions.com
[3] http://www.amarulasolutions.com/

Signature · 15 lines
Angelo Compagnucci

Software Engineer

[email protected]
__________________________________
Amarula Solutions SRL

Via le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 (0)42 243 5310
[email protected]

www.amarulasolutions.com
[`as] https://www.amarulasolutions.com|

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot