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

Andreas Ziegler br015 at umbiko.net
Tue Jun 28 09:03:27 UTC 2022


Hi Angelo,

On 2022-06-28 07:56, Angelo Compagnucci wrote:
> On Sat, Jun 25, 2022 at 7:02 AM Andreas Ziegler <br015 at umbiko.net>
> wrote:
> 
>> Hi Angelo,
>> 
>> On 2022-06-21 13:31, Angelo Compagnucci
>> <angelo at amarulasolutions.com>
>> 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 at amarulasolutions.com>
>>>>> ---
>>>>>   package/busybox/S02modules | 56
>> ++++++++++++++++++++++++++++++++++++++
>>>>>   package/busybox/busybox.mk [1] |  2 ++
>>>>>   2 files changed, 58 insertions(+)
>>>>>   create mode 100644 package/busybox/S02modules
>>>>> 
>>>>> 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?
> 
>>>>> 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 [1]
>> b/package/busybox/busybox.mk [1]
>>>>> index 3e49de0a84..40490e866a 100644
>>>>> --- a/package/busybox/busybox.mk [1]
>>>>> +++ b/package/busybox/busybox.mk [1]
>>>>> @@ -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.
> 
> 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.

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

> 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

>> Kind regards,
>> Andreas
>> 
>>>> 
>>>> 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
>>> 
>>> Software Engineer
>>> 
>>> angelo at amarulasolutions.com
>>> __________________________________
>>> Amarula Solutions SRL
>>> 
>>> Via le Canevare 30, 31100 Treviso, Veneto, IT
>>> 
>>> T. +39 (0)42 243 5310
>>> info at amarulasolutions.com
>>> 
>>> www.amarulasolutions.com [2]
>>> [`as] https://www.amarulasolutions.com|
> 
> --
> 
> Angelo Compagnucci
> 
> Software Engineer
> 
> angelo at amarulasolutions.com
> __________________________________
> Amarula Solutions SRL
> 
> Via le Canevare 30, 31100 Treviso, Veneto, IT
> 
> T. +39 (0)42 243 5310
> info at amarulasolutions.com
> 
> www.amarulasolutions.com [3]
> 
> [`as] https://www.amarulasolutions.com|
> 
> Links:
> ------
> [1] http://busybox.mk
> [2] http://www.amarulasolutions.com
> [3] http://www.amarulasolutions.com/



More information about the buildroot mailing list