]> git.pld-linux.org Git - projects/geninitrd.git/blobdiff - mod-sata.sh
- more generic and more exact finding code
[projects/geninitrd.git] / mod-sata.sh
index c2b5db2a1ef274653846bc6124a95d00cc75a1fb..dc196def0914be3d86d93f62d24f7bf9870dc083 100644 (file)
@@ -2,25 +2,40 @@
 #
 # geninitrd mod: sata
 
-find_modules_sata()
-{
-       debug "Finding SATA modules"
+# private until only mod-sata uses the function
+find_modules_by_class() {
+       local class=$1
+
+       local pcimap="/lib/modules/$kernel/modules.pcimap"
+       # no pcimap, nothing to lookup from
+       if [ ! -f "$pcimap" ]; then
+               return
+       fi
 
        if [ ! -x /sbin/lspci ]; then
                warn "Failed to execute /sbin/lspci. Is pciutils package installed?"
                return
        fi
 
+       set -- $(/sbin/lspci -n -p $pcimap | awk -vclass=$class '$2 == class":" {split($3, p, ":"); printf("0x0000%s 0x0000%s\n", p[1], p[2])}')
+       awk -vvendor=$1 -vdevice=$2 '$2 == vendor && $3 == device {print $1}' $pcimap
+}
+
+find_modules_sata() {
+       debug "Finding SATA modules (class=0x0106)"
+
        # Classes (we want only 0106)
+       # http://pci-ids.ucw.cz/read/PD/01
+       # 0100 - SCSI
        # 0101 - IDE/PATA
        # 0106 - SATA/AHCI
        # 0107 - SAS
-       # 0100 - SCSI
        local module
-       local vendordev
-       vendordev=$(lspci -n -p /lib/modules/$kernel/modules.pcimap 2> /dev/null | awk '/0106/{ gsub(/:/," "); print "0x0000"$4 " " "0x0000"$5}')
-       if [ -n "$vendordev" ]; then
-               module=$(grep "$vendordev" /lib/modules/$kernel/modules.pcimap | awk '{print $1}')
+       module=$(find_modules_by_class 0106)
+
+       if [ "$module" ]; then
+               # FIXME: how to handle if multiple modules returned?
+               # i.e two modules can do same id
                find_module "$module"
        fi
 }
This page took 0.027174 seconds and 4 git commands to generate.