簡體   English   中英

如何知道是否有一個(嵌入式/內核模塊)設備驅動程序來控制運行中的Linux上的設備?

[英]How to know if there is a (compiled in/kernel module) device driver controlling a device on a running linux?

我如何知道運行的Linux是否支持某個設備,如果支持,則由哪個設備驅動程序控制它? 例如,服務器(PowerEdge 2900)上的lspci提供:

00:00.0 Host bridge: Intel Corporation 5000X Chipset Memory Controller Hub (rev 12)
00:02.0 PCI bridge: Intel Corporation 5000 Series Chipset PCI Express x4 Port 2 (rev 12)
00:03.0 PCI bridge: Intel Corporation 5000 Series Chipset PCI Express x4 Port 3 (rev 12)
00:04.0 PCI bridge: Intel Corporation 5000 Series Chipset PCI Express x4 Port 4 (rev 12)
00:05.0 PCI bridge: Intel Corporation 5000 Series Chipset PCI Express x4 Port 5 (rev 12)
00:06.0 PCI bridge: Intel Corporation 5000 Series Chipset PCI Express x8 Port 6-7 (rev 12)
00:07.0 PCI bridge: Intel Corporation 5000 Series Chipset PCI Express x4 Port 7 (rev 12)
00:08.0 System peripheral: Intel Corporation 5000 Series Chipset DMA Engine (rev 12)
00:10.0 Host bridge: Intel Corporation 5000 Series Chipset FSB Registers (rev 12)
00:10.1 Host bridge: Intel Corporation 5000 Series Chipset FSB Registers (rev 12)
00:10.2 Host bridge: Intel Corporation 5000 Series Chipset FSB Registers (rev 12)
00:11.0 Host bridge: Intel Corporation 5000 Series Chipset Reserved Registers (rev 12)
00:13.0 Host bridge: Intel Corporation 5000 Series Chipset Reserved Registers (rev 12)
00:15.0 Host bridge: Intel Corporation 5000 Series Chipset FBD Registers (rev 12)
00:16.0 Host bridge: Intel Corporation 5000 Series Chipset FBD Registers (rev 12)
00:1c.0 PCI bridge: Intel Corporation 631xESB/632xESB/3100 Chipset PCI Express Root Port 1 (rev 09)
00:1d.0 USB Controller: Intel Corporation 631xESB/632xESB/3100 Chipset UHCI USB Controller #1 (rev 09)
00:1d.1 USB Controller: Intel Corporation 631xESB/632xESB/3100 Chipset UHCI USB Controller #2 (rev 09)
00:1d.2 USB Controller: Intel Corporation 631xESB/632xESB/3100 Chipset UHCI USB Controller #3 (rev 09)
00:1d.3 USB Controller: Intel Corporation 631xESB/632xESB/3100 Chipset UHCI USB Controller #4 (rev 09)
00:1d.7 USB Controller: Intel Corporation 631xESB/632xESB/3100 Chipset EHCI USB2 Controller (rev 09)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev d9)
00:1f.0 ISA bridge: Intel Corporation 631xESB/632xESB/3100 Chipset LPC Interface Controller (rev 09)
00:1f.1 IDE interface: Intel Corporation 631xESB/632xESB IDE Controller (rev 09)
00:1f.2 IDE interface: Intel Corporation 631xESB/632xESB/3100 Chipset SATA IDE Controller (rev 09)
01:00.0 PCI bridge: Intel Corporation 80333 Segment-A PCI Express-to-PCI Express Bridge
01:00.2 PCI bridge: Intel Corporation 80333 Segment-B PCI Express-to-PCI Express Bridge
02:0e.0 RAID bus controller: Dell PowerEdge Expandable RAID controller 5
04:00.0 PCI bridge: Broadcom EPB PCI-Express to PCI-X Bridge (rev c3)
05:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet (rev 12)
06:00.0 PCI bridge: Intel Corporation 6311ESB/6321ESB PCI Express Upstream Port (rev 01)
06:00.3 PCI bridge: Intel Corporation 6311ESB/6321ESB PCI Express to PCI-X Bridge (rev 01)
07:00.0 PCI bridge: Intel Corporation 6311ESB/6321ESB PCI Express Downstream Port E1 (rev 01)
07:01.0 PCI bridge: Intel Corporation 6311ESB/6321ESB PCI Express Downstream Port E2 (rev 01)
08:00.0 PCI bridge: Broadcom EPB PCI-Express to PCI-X Bridge (rev c3)
09:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet (rev 12)
0b:02.0 Multimedia audio controller: Creative Labs SB Audigy (rev 03)
0b:02.1 Input device controller: Creative Labs SB Audigy Game Port (rev 03)
0b:02.2 FireWire (IEEE 1394): Creative Labs SB Audigy FireWire Port
10:0d.0 VGA compatible controller: ATI Technologies Inc ES1000 (rev 02)

我如何找到:

  1. 哪個設備驅動程序(內核模塊)控制每個設備?
  2. 該裝置是通過內核編譯的設備驅動器來控制(未作為模塊和)
  3. 哪個設備沒有設備驅動程序(作為模塊內置或作為模塊編譯)?

該腳本(從“堅果殼中的Linux內核”中的另一個腳本改編而成)部分解析了#1:

#!/bin/bash
for i in $(find /sys/ -name modalias); do
    echo "----------------------------------"
    modalias=$(cat $i)
    echo "$(dirname $i) -->  $modalias" 
    /sbin/modprobe --config /dev/null --show-depends $(cat $i) 2>&1
done

但是它有一些問題:

  1. 我不知道將/sys/devices/pci0000:00/0000:00:1e.0/0000:10:0d.0 --> pci:v00001002d0000515Esv00001028sd000001B1bc03sc00i00轉換為10:0d.0 VGA compatible controller: ATI Technologies Inc ES1000 (rev 02)自動化方法 10:0d.0 VGA compatible controller: ATI Technologies Inc ES1000 (rev 02)

  2. 在某些情況下,設備位於MB的內部,我什至不知道找到設備真實名稱的方法。 例如:

/sys/devices/platform/dcdbas -->  platform:dcdbas
/sys/devices/platform/iTCO_wdt -->  platform:iTCO_wdt
/sys/devices/LNXSYSTM:00 -->  acpi:LNXSYSTM:
/sys/devices/LNXSYSTM:00/device:00/PNP0C33:00 -->  acpi:PNP0C33:PNP0C01:
/sys/devices/LNXSYSTM:00/device:00/PNP0A08:00 -->  acpi:PNP0A08:PNP0A03:
/sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:0d/PNP0200:00 -->  acpi:PNP0200:

還有很多其他

  1. 當設備驅動程序被編譯 (或不存在)時,響應為FATAL: Module _XXXX_ not found. 表示該設備沒有模塊。

在某些情況下,驅動程序是在(例如)

/sys/devices/platform/serial8250 -->  platform:serial8250
FATAL: Module platform:serial8250 not found.

/sys/devices/platform/i8042 -->  platform:i8042
FATAL: Module platform:i8042 not found.

在其他情況下,驅動程序不存在。 但是我不知道一種區別的方法。

有人知道嗎?

我認為您無法在Windows設備管理器中獲得100%明確的答案。

  • 一個設備可以由幾個內核模塊(例如nvidia + agpgart )控制。
  • 內核模塊可以控制多個設備( usbhid )。
  • 您還可以具有多對多關系( usbcore + usbhid )。

嘗試使用HAL設備管理器 ,它也可以作為“ KDE HAL設備管理器”和“ gnome-device-manager”使用。 基本上,這些是硬件抽象層(HAL)的前端,該層讀取/sysfs/等。

它提供類似“ info.linux.driver”的信息,請參見下面的屏幕截圖:

對不起,我不知道如何在sysfs中自己弄亂這些信息,但是如果HAL能夠找到它,它就必須在某處:-)

lspci -n將為您提供PCI ID,您可以在linux內核驅動程序數據庫中進行搜索 這將告訴您要啟用的內核選項。

嗯,這有點晚了,也許在那時(2008年)甚至還不存在,但是lspci -n或更好的lspci -k應該可以解決此問題; 例如:

04:00.0網絡控制器:Broadcom Corporation BCM4312 802.11b / g(rev 01)

  Kernel driver in use: wl Kernel modules: wl, ssb 

下面的腳本將告訴您正在運行哪些動態加載的驅動程序,盡管我也希望以一種自動的方式來確定哪些模塊中的編譯器實際上正在使用中,因此我可以使內核更多。

#!/bin/bash
/sbin/lsmod | tail -n+2 | cut -d" " -f1 | xargs /sbin/modinfo -n | sort ; 

我不確定其余的問題對您的問題有多重視,但認為您或其他人可能會覺得有用。

以下代碼將找出由哪個.config選項控制每個動態加載的內核模塊,盡管我還沒有找到對ubuntu lum軟件包中的動態模塊執行相同操作的方法(此腳本仍在開發中):

#!/usr/bin/perl -w

use strict;
use Getopt::Long;

my ($kernConfigIn, $kernConfigOut, $kernSourceDir, $lumSourceDir, $lumConfigIn, $lumConfigOut, $help);

GetOptions(
    'ksd=s'   => \$kernSourceDir,
    'lsd=s'    => \$lumSourceDir,
    'kci=s'      => \$kernConfigIn,
    'lci=s'       => \$lumConfigIn,
    'kco=s'      => \$kernConfigOut,
    'lco=s'       => \$lumConfigOut,
    'help' => \$help);

if ($help || !$kernSourceDir || !$lumSourceDir ) { Usage($0); }

sub Usage {  print "usage error\n"; exit; };

my @modules = `/sbin/lsmod | tail -n+2 | cut -d" " -f1 | xargs /sbin/modinfo -n | sort ;`;
my @kconfig;

foreach my $module (@modules) {
    my ($package, $path, $modName) = ( $module =~ m/\/((?:kernel)|(?:ubuntu))\/(.*)\/(.*)\.ko/) ;
    $package eq 'kernel' ? push @kconfig, kernel($package, $path, $modName) : ubuntu($package, $path, $modName); 
}

# kernel package
sub kernel {
    my ($package, $path, $modName) = @_;
    my $makefile = $kernSourceDir.$path."/Makefile"; 
#    print "$package, $path, $modName\n";
#    print "$makefile\n";
    my $option;
    chomp($option = `cat $makefile | sed -n "s/^obj-\\\$(CONFIG_\\([A-Z0-9_]*\\))\\W*+=.*"$modName"\\.o.*/CONFIG_\\1/p"`);
    print "$option\n";
    return $option;
}

# deal with lum configs
sub ubuntu {

}

Andreas Goelzer提供了一個腳本,只需稍加修改即可關閉.config中所有未使用的內核模塊,從而顯着加快了編譯速度。

你可以在這里找到它:

http://andreas.goelzer.de/kernel-config-based-on-lsmod-output

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM