Skip to content

Instantly share code, notes, and snippets.

@calebccff
Last active February 27, 2025 15:10
Show Gist options
  • Save calebccff/f5e33a25c56c1b2bf32c199bdb76e0de to your computer and use it in GitHub Desktop.
Save calebccff/f5e33a25c56c1b2bf32c199bdb76e0de to your computer and use it in GitHub Desktop.
Find the list of modules explicitly required by your ARM device.

hwmodules.sh

This script uses the devicetree compatible properties in the modalias info and compares them to all the compatible properties used on the running device. Essentially, it filters lsmod to only show modules which are directly used for hardware functionality on your device. This is NOT an exhaustive list of modules, but should be added to your distros existing list. It doesn't cover basic things like nvme, etc.

Example output

On the Lenovo Yoga Slim 7x laptop, the following is printed:

; ./hwmodules.sh
Populating list of compatible properties...
Finding modules required by this device...
The following modules are needed by hardware, consider adding them to your initramfs:
q6prm_clocks
q6apm_lpass_dais
q6apm_dai
q6prm
snd_q6apm
apr
fastrpc
qcom_pon
nvmem_qcom_spmi_sdam
qcom_spmi_temp_alarm
snd_soc_x1e80100
qcom_stats
soundwire_qcom
qcom_q6v5_pas
snd_soc_lpass_rx_macro
snd_soc_lpass_tx_macro
snd_soc_lpass_va_macro
snd_soc_lpass_wsa_macro
pinctrl_sm8550_lpass_lpi
lpasscc_sc8280xp
panel_samsung_atna33xc20
msm
i2c_hid_of
phy_qcom_eusb2_repeater
phy_qcom_qmp_combo
phy_qcom_snps_eusb2
i2c_qcom_geni
phy_qcom_edp
dispcc_x1e80100
llcc_qcom
gpucc_x1e80100
phy_qcom_qmp_pcie
icc_bwmon
pmic_glink
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Get all compatible properties used on this device
compat_file=$(mktemp)
echo "Populating list of compatible properties..."
find /sys/firmware/devicetree/base/ -name compatible -exec cat {} \; | tr '\0' '\n' > $compat_file
if [ -z "$(cat $compat_file)" ]; then
echo "No compatible properties found, are you running on the target device?"
exit 1
fi
echo "Finding modules required by this device..."
needed_modules=""
# List all modules, skip the first line of lsmod
eval "set -- \$(lsmod | tail -n +2 | cut -d' ' -f1)"
for module; do
aliases=$(modinfo $module -F alias -0)
if [ -z "$aliases" ]; then
continue
fi
#printf '%s: %s\n' "$module" "$aliases"
if printf '%s' "$aliases" | grep -q -f $compat_file; then
needed_modules="$needed_modules $module"
fi
done
printf 'The following modules are needed by hardware, consider adding them to your initramfs:\n'
printf '%s\n' $needed_modules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment