From 6351f283eb9ac988979a5db9a8d091b7a96202d3 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 30 Apr 2023 18:04:29 +0200 Subject: dt-modules: new script to load modules for device-tree nodes Some ARM platforms require loading certain modules to access controllers that are enumerated in the device tree and without which nothing else can be detected (e.g. PCIe controllers, MMC/SD controllers, etc). The new dt-modules script scans the device tree nodes in /sys looking for nodes that are supported by some of the modules, and loads them. It may for example allow to find the flash device, a hard disk or an ethernet controller. It also supports simply listing aliases or the modules. --- .flxfiles | 1 + sbin/dt-modules | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100755 sbin/dt-modules diff --git a/.flxfiles b/.flxfiles index 876e541..8b7f4c9 100644 --- a/.flxfiles +++ b/.flxfiles @@ -29,6 +29,7 @@ sbin/autoraid sbin/bootcmd sbin/bootmodules sbin/detect-board +sbin/dt-modules sbin/fix-date sbin/listpart sbin/service diff --git a/sbin/dt-modules b/sbin/dt-modules new file mode 100755 index 0000000..29e7f0e --- /dev/null +++ b/sbin/dt-modules @@ -0,0 +1,80 @@ +#!/bin/bash + +# sbin/dt-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 device-tree 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/firmware/" ]; then + echo "Fatal: /sys does not seem to be mounted." >&2 + exit 1 +fi + +if [ ! -d "/sys/firmware/devicetree/" ]; then + # no device tree + exit 0 +fi + +# see scripts/mod/file2alias.c in the kernel tree after kernel 4.6 for the +# compatible string syntax. +aliases=( $(find /sys/firmware/devicetree/base/* -name compatible | \ + xargs sed -e 's, ,,g' -e 's,\([ -~]*\).,of:NTC\1\n,g' | \ + 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