From e95283354419397ca26ccc7b0fe652963fb6b949 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 30 Apr 2023 18:58:33 +0200 Subject: pf-modules: new script for loading platform modules A few drivers that are always present at fixed locations do not appear in the device tree but are enumerated by the platform itself. We have to load them as well. Some examples may include RTC or USB controllers. --- .flxfiles | 1 + sbin/pf-modules | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100755 sbin/pf-modules diff --git a/.flxfiles b/.flxfiles index 8b7f4c9..71dd16a 100644 --- a/.flxfiles +++ b/.flxfiles @@ -32,6 +32,7 @@ sbin/detect-board sbin/dt-modules sbin/fix-date sbin/listpart +sbin/pf-modules sbin/service usr/libexec/ipautoconfig etc/init.d diff --git a/sbin/pf-modules b/sbin/pf-modules new file mode 100755 index 0000000..a04856f --- /dev/null +++ b/sbin/pf-modules @@ -0,0 +1,79 @@ +#!/bin/bash + +# sbin/pf-modules - Formilux device-tree modules loader - v0.1 - 2023-04-30 +# +# Copyright (C) 2001-2023 Benoit Dolez & Willy Tarreau +# mailto: benoit@ant-computing.com,willy@ant-computing.com +# +# This program is licenced under GPLv2 ( http://www.gnu.org/licenses/gpl.txt ) + +# This script inspects the platform nodes in /sys/ to spot devices names and +# a matching module. It then loads all matching modules. This allows to load +# important functions that are only provided as a module but not otherwise +# enumerable nor detectable. + +export PATH="/sbin:/usr/sbin:/bin:/usr/bin:$PATH" + +DO_LIST_MOD= +DO_LIST_ALIASES= + +# Show usage message with program name in $1 +usage() { + echo "Usage: ${1##*/} [-h|--help] [-l|-a]" + echo " -h display this help" + echo " -a only list aliases, do not load modules" + echo " -l only list modules, do not load" + echo +} + +if [ "$1" = "-h" -o "$1" = "--help" ]; then + usage "$0" + exit 0 +elif [ "$1" = "-a" ]; then + DO_LIST_ALIASES=1 +elif [ "$1" = "-l" ]; then + DO_LIST_MOD=1 +elif [ -n "$1" ]; then + usage "$1" + exit 1 +fi + +# check if everything is OK first +if [ ! -d "/sys/devices/" ]; then + echo "Fatal: /sys does not seem to be mounted." >&2 + exit 1 +fi + +if [ ! -d "/sys/devices/platform/" ]; then + # no platform nodes + exit 0 +fi + +# see scripts/mod/file2alias.c in the kernel tree after kernel 4.6 for the +# compatible string syntax. +aliases=( $(find /sys/devices/platform -name modalias -print0 | \ + xargs -0 cat | sort -u) ) + +if [ -n "$DO_LIST_ALIASES" ]; then + # -a: only list the aliases + for a in "${aliases[@]}"; do + echo "$a" + done + exit 0 +fi + +# retrieve the list of matching modules (-R resolves aliases from modules.alias +# and modules.builtin.alias, -a takes a whole list, -q doesn't warn about +# missing ones). +modules=( $(modprobe -q -R -a "${aliases[@]}" | sort -u) ) + +if [ -n "$DO_LIST_MOD" ]; then + # -l: only list the modules + for m in "${modules[@]}"; do + echo "$m" + done + exit 0 +fi + +# and load all available modules +exec modprobe -a "${modules[@]}" -- 2.35.3