Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Finding modules required for make menuconfig
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
andretti
Tux's lil' helper
Tux's lil' helper


Joined: 25 Feb 2007
Posts: 94

PostPosted: Fri Mar 24, 2017 11:39 pm    Post subject: Finding modules required for make menuconfig Reply with quote

I come across 'modalias' recently and wrote a little script trying to workout what hardware related modules I need for the 'make menuconfig' step.

With quite limited knowledge about modalias, I'm hoping to get some feedback on whether this is sufficient/correct way to do this.

Code:
#!/bin/sh -e

exec 3>&1
exec 1>&2

temp_sysfs_modalias=$(mktemp)
echo "Getting modalias info from /sys into $temp_sysfs_modalias"
find /sys -name modalias -print0 | xargs -0 cat | sort -u > $temp_sysfs_modalias

temp_kernel_dir=$(mktemp -d)
echo "Copying /usr/src/linux to $temp_kernel_dir"
cp -aL /usr/src/linux "$temp_kernel_dir"

echo "Compiling kernel in $temp_kernel_dir with allmodconfig"
pushd "$temp_kernel_dir"/linux
make allmodconfig
make -j9

temp_matching_module=$(mktemp)
echo "Matching module modalias against /sys modalias"
find $temp_kernel_dir -name '*.ko' | while read module; do
   modinfo -F alias "$module" | while read modalias_pattern; do
      cat $temp_sysfs_modalias | while read modalias; do
         if [[ $modalias == ?($modalias_pattern) ]]; then
            echo $module $modalias_pattern $modalias
            echo "${module#$temp_kernel_dir/*}" >> $temp_matching_module
         fi
      done
   done
done

echo "Sending results to STDOUT"

exec 1>&3
sort -u $temp_matching_module

rm $temp_sysfs_modalia $temp_matching_module
rm -R $temp_kernel_dir


I suppose this can only match plugged-in hardware? ie. not the usb drive yet to be plugged in...

Next question: how do we link kernel modules back to kernel config...

References:
https://wiki.archlinux.org/index.php/Modalias
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14300

PostPosted: Sat Mar 25, 2017 12:02 am    Post subject: Re: Finding modules required for make menuconfig Reply with quote

andretti wrote:
Code:

find /sys -name modalias -print0 | xargs -0 cat | sort -u > $temp_sysfs_modalias
Useless Use Of Cat. You can run xargs -0 sort -u directly.
andretti wrote:
Code:

echo "Copying /usr/src/linux to $temp_kernel_dir"
cp -aL /usr/src/linux "$temp_kernel_dir"
Why do you need a copy?
andretti wrote:
Code:

      cat $temp_sysfs_modalias | while read modalias; do
      done
Useless Use Of Cat. You can redirect the stdin of read to the file.
andretti wrote:
Code:
exec 1>&3
sort -u $temp_matching_module
You could redirect stdout of just the sort command, rather than changing the shell.
andretti wrote:
Code:
rm $temp_sysfs_modalia $temp_matching_module
rm -R $temp_kernel_dir
You misspelled $temp_sysfs_modalias here. Since you did not quote it, the misspelled variable expanded to an empty string and no diagnostic was written.
andretti wrote:
Next question: how do we link kernel modules back to kernel config...
You might be able to do this by reading the kernel's makefiles.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 5972

PostPosted: Sat Mar 25, 2017 3:54 am    Post subject: Reply with quote

Why not "make localyesconfig"?
Back to top
View user's profile Send private message
andretti
Tux's lil' helper
Tux's lil' helper


Joined: 25 Feb 2007
Posts: 94

PostPosted: Sat Mar 25, 2017 9:04 am    Post subject: Reply with quote

Ant P. wrote:
Why not "make localyesconfig"?


I was with the impression that it filters from what not currently loaded, so I would need 'all' modules present first, but I failed to boot a kernel with 'all' modules.
Back to top
View user's profile Send private message
andretti
Tux's lil' helper
Tux's lil' helper


Joined: 25 Feb 2007
Posts: 94

PostPosted: Sat Mar 25, 2017 9:08 am    Post subject: Re: Finding modules required for make menuconfig Reply with quote

Hu wrote:
andretti wrote:
Code:

find /sys -name modalias -print0 | xargs -0 cat | sort -u > $temp_sysfs_modalias
Useless Use Of Cat. You can run xargs -0 sort -u directly.
andretti wrote:
Code:

echo "Copying /usr/src/linux to $temp_kernel_dir"
cp -aL /usr/src/linux "$temp_kernel_dir"
Why do you need a copy?
andretti wrote:
Code:

      cat $temp_sysfs_modalias | while read modalias; do
      done
Useless Use Of Cat. You can redirect the stdin of read to the file.
andretti wrote:
Code:
exec 1>&3
sort -u $temp_matching_module
You could redirect stdout of just the sort command, rather than changing the shell.
andretti wrote:
Code:
rm $temp_sysfs_modalia $temp_matching_module
rm -R $temp_kernel_dir
You misspelled $temp_sysfs_modalias here. Since you did not quote it, the misspelled variable expanded to an empty string and no diagnostic was written.
andretti wrote:
Next question: how do we link kernel modules back to kernel config...
You might be able to do this by reading the kernel's makefiles.


All great suggestions and pointers. Thanks Hu! Regarding to 'Why copy', that's just me lack of confidence (and also hoping that it could run faster on my tmpfs /tmp).
Back to top
View user's profile Send private message
andretti
Tux's lil' helper
Tux's lil' helper


Joined: 25 Feb 2007
Posts: 94

PostPosted: Sat Mar 25, 2017 2:15 pm    Post subject: Reply with quote

Following Hu's suggestions, the script now becomes

Code:
#!/bin/sh -e

exec 3>&1
exec 1>&2

temp_sysfs_modalias=$(mktemp)
echo "Getting modalias info from /sys into $temp_sysfs_modalias"
find /sys -name modalias -print0 | xargs -0 sort -u > $temp_sysfs_modalias

temp_kernel_dir=$(mktemp -d)
echo "Copying /usr/src/linux to $temp_kernel_dir"
cp -aL /usr/src/linux "$temp_kernel_dir"

echo "Compiling kernel in $temp_kernel_dir with allmodconfig"
cd "$temp_kernel_dir"/linux
make allmodconfig
make -j9

temp_matching_module=$(mktemp)
echo "Matching module modalias against /sys modalias"
find "$temp_kernel_dir" -name '*.ko' | while read module; do
   modinfo -F alias "$module" | while read modalias_pattern; do
      while read modalias; do
         if [[ $modalias == ?($modalias_pattern) ]]; then
            echo ${module#$temp_kernel_dir/linux/*} $modalias_pattern $modalias
            echo ${module#$temp_kernel_dir/linux/*} >> $temp_matching_module
         fi
      done < $temp_sysfs_modalias
   done
done

echo 'Searching CONFIG_* in Makefile for modules and lookup /usr/src/linux/.config settings'
sort -u "$temp_matching_module" | while read module; do
   module_name=${module##*/}
   module_name=${module_name%.ko}
   current_config_list=`find "$temp_kernel_dir" -name Makefile -print0 | \
      xargs -0 grep -oE "(^|[^[:alnum:]])CONFIG_[A-Z0-9_]+.*[=[:space:]]${module_name}[./]" | \
      grep -oE "CONFIG_[A-Z0-9_]+" | \
      sort -u | \
      while read kernel_config; do
         if current_config=$(grep "^$kernel_config=[ym]" /usr/src/linux/.config); then
            echo -n " $current_config"
         else
            echo -n " $kernel_config=?"
         fi
      done`
   if [[ -z $current_config_list ]]; then
      echo -ne '\033[1;33m' 1>&3
   elif [[ $current_config_list == *=[ym]* ]]; then
      echo -ne '\033[1;32m' 1>&3
   else
      echo -ne '\033[1;31m' 1>&3
   fi
   echo -e "${module}\033[0m${current_config_list}" 1>&3
done

rm "$temp_sysfs_modalias" "$temp_matching_module"
rm -R $temp_kernel_dir


with output showing what I might be missing in my kernel config

Code:
Searching CONFIG_* in Makefile for modules and lookup /usr/src/linux/.config settings
arch/x86/crypto/aesni-intel.ko CONFIG_CRYPTO_AES_NI_INTEL=y
arch/x86/crypto/crc32c-intel.ko CONFIG_CRYPTO_CRC32C_INTEL=y
arch/x86/crypto/crc32-pclmul.ko CONFIG_CRYPTO_CRC32_PCLMUL=y
arch/x86/crypto/crct10dif-pclmul.ko CONFIG_CRYPTO_CRCT10DIF_PCLMUL=?
arch/x86/crypto/ghash-clmulni-intel.ko CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL=y
arch/x86/events/intel/intel-cstate.ko CONFIG_PERF_EVENTS_INTEL_CSTATE=y
arch/x86/events/intel/intel-rapl-perf.ko CONFIG_PERF_EVENTS_INTEL_RAPL=y
arch/x86/events/intel/intel-uncore.ko CONFIG_PERF_EVENTS_INTEL_UNCORE=y
arch/x86/kvm/kvm-intel.ko CONFIG_KVM_INTEL=y
drivers/acpi/ac.ko CONFIG_ACPI_AC=y
drivers/acpi/battery.ko CONFIG_ACPI_BATTERY=y
drivers/acpi/button.ko CONFIG_ACPI_BUTTON=y
drivers/acpi/thermal.ko CONFIG_ACPI_THERMAL=y CONFIG_THERMAL=y
drivers/acpi/video.ko CONFIG_ACPI_VIDEO=y CONFIG_FB_I810=? CONFIG_FB_INTEL=?
drivers/ata/ahci.ko CONFIG_SATA_AHCI=y
drivers/bluetooth/btusb.ko CONFIG_BT_HCIBTUSB=y
drivers/cpufreq/acpi-cpufreq.ko CONFIG_X86_ACPI_CPUFREQ=?
drivers/cpufreq/pcc-cpufreq.ko CONFIG_X86_PCC_CPUFREQ=?
drivers/gpu/drm/i915/i915.ko CONFIG_DRM_I915=y
drivers/gpu/drm/nouveau/nouveau.ko CONFIG_DRM_NOUVEAU=?
drivers/hwmon/coretemp.ko CONFIG_SENSORS_CORETEMP=y
drivers/i2c/busses/i2c-i801.ko CONFIG_I2C_I801=y
drivers/input/evbug.ko CONFIG_INPUT_EVBUG=?
drivers/input/evdev.ko CONFIG_INPUT_EVDEV=y
drivers/input/input-leds.ko CONFIG_INPUT_LEDS=?
drivers/input/joydev.ko CONFIG_INPUT_JOYDEV=?
drivers/input/keyboard/atkbd.ko CONFIG_KEYBOARD_ATKBD=y
drivers/input/misc/pcspkr.ko CONFIG_INPUT_PCSPKR=?
drivers/input/mousedev.ko CONFIG_INPUT_MOUSEDEV=?
drivers/input/mouse/psmouse.ko CONFIG_MOUSE_PS2=y
drivers/input/serio/i8042.ko CONFIG_SERIO_I8042=y
drivers/input/serio/serio_raw.ko CONFIG_SERIO_RAW=?
drivers/macintosh/mac_hid.ko CONFIG_MAC_EMUMOUSEBTN=?
drivers/media/usb/uvc/uvcvideo.ko CONFIG_USB_VIDEO_CLASS=?
drivers/memstick/host/rtsx_pci_ms.ko CONFIG_MEMSTICK_REALTEK_PCI=?
drivers/mfd/rtsx_pci.ko CONFIG_MFD_RTSX_PCI=y
drivers/misc/mei/mei-me.ko CONFIG_INTEL_MEI_ME=?
drivers/mmc/host/rtsx_pci_sdmmc.ko CONFIG_MMC_REALTEK_PCI=?
drivers/net/ethernet/intel/e1000e/e1000e.ko CONFIG_E1000E=y
drivers/net/fjes/fjes.ko CONFIG_FUJITSU_ES=?
drivers/net/wireless/intel/iwlwifi/iwlwifi.ko CONFIG_IWLWIFI=y
drivers/nvme/host/nvme.ko CONFIG_BLK_DEV_NVME=y
drivers/pci/hotplug/shpchp.ko CONFIG_HOTPLUG_PCI_SHPC=y
drivers/platform/x86/thinkpad_acpi.ko CONFIG_THINKPAD_ACPI=y
drivers/platform/x86/wmi.ko CONFIG_ACPI_WMI=?
drivers/powercap/intel_rapl.ko CONFIG_INTEL_RAPL=y
drivers/rtc/rtc-cmos.ko CONFIG_RTC_DRV_CMOS=y
drivers/scsi/sd_mod.ko CONFIG_BLK_DEV_SD=y
drivers/thermal/intel_pch_thermal.ko CONFIG_INTEL_PCH_THERMAL=y
drivers/thermal/intel_powerclamp.ko CONFIG_INTEL_POWERCLAMP=y
drivers/thermal/x86_pkg_temp_thermal.ko CONFIG_X86_PKG_TEMP_THERMAL=y
drivers/usb/core/usbcore.ko CONFIG_USB=y
drivers/usb/host/xhci-pci.ko CONFIG_USB_XHCI_PCI=y
drivers/video/fbdev/nvidia/nvidiafb.ko CONFIG_FB_NVIDIA=?
drivers/watchdog/iTCO_wdt.ko CONFIG_ITCO_WDT=?
sound/drivers/pcsp/snd-pcsp.ko CONFIG_SND_PCSP=?
sound/pci/hda/snd-hda-codec-realtek.ko CONFIG_SND_HDA_CODEC_REALTEK=y
sound/pci/hda/snd-hda-intel.ko CONFIG_SND_HDA_INTEL=y
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum