SVN: geninitrd/trunk/mod-sata.sh

glen glen at pld-linux.org
Fri Jan 14 12:35:33 CET 2011


Author: glen
Date: Fri Jan 14 12:35:32 2011
New Revision: 12053

Modified:
   geninitrd/trunk/mod-sata.sh
Log:
- more generic and more exact finding code

Modified: geninitrd/trunk/mod-sata.sh
==============================================================================
--- geninitrd/trunk/mod-sata.sh	(original)
+++ geninitrd/trunk/mod-sata.sh	Fri Jan 14 12:35:32 2011
@@ -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
 }


More information about the pld-cvs-commit mailing list