slitaz-tools rev 829

tazhw: fix detect-pci
author Christophe Lincoln <pankso@slitaz.org>
date Wed Jan 29 01:48:09 2014 +0100 (2014-01-29)
parents ee8e6af11d45
children 9626739ddfa2
files tinyutils/tazhw
line diff
     1.1 --- a/tinyutils/tazhw	Wed Jan 29 01:00:37 2014 +0100
     1.2 +++ b/tinyutils/tazhw	Wed Jan 29 01:48:09 2014 +0100
     1.3 @@ -67,23 +67,31 @@
     1.4  
     1.5  load_module() {
     1.6  	if ! lsmod | grep -q "^$mod"; then
     1.7 -
     1.8 -		# lsmod and some modules use underscore, others use dash.
     1.9 -		# The real modprobe can handle both but not busybox version
    1.10 -		modprobe $mod 2>/dev/null && \
    1.11 -		_ '* Loaded module:   $mod' || \
    1.12 -		_ '! Missing module:  $mod'
    1.13 -
    1.14 -		# Add it to load automatically at next boot.
    1.15 -		if ! echo "$LOAD_MODULES" | grep -q "$mod"; then
    1.16 -			sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$LOAD_MODULES $mod\""/ \
    1.17 -				/etc/rcS.conf
    1.18 +		# Check if builtin, loaded or missing
    1.19 +		if modprobe $mod 2>/dev/null; then
    1.20 +			if zcat /proc/config.gz | fgrep -i $mod | fgrep -q '=y'; then
    1.21 +				_ '* Builtin module : $mod'
    1.22 +				unset mod
    1.23 +			else
    1.24 +				_ "* Loaded module  : $mod"
    1.25 +			fi
    1.26 +		else
    1.27 +			if zcat /proc/config.gz | fgrep -i $mod | fgrep -q '=y'; then
    1.28 +				_ '* Builtin module : $mod'
    1.29 +				unset mod
    1.30 +			else
    1.31 +				_ '! Missing module : $mod'
    1.32 +			fi
    1.33  		fi
    1.34 -		. /etc/rcS.conf
    1.35 -
    1.36  	else
    1.37 -		_ '> Module in use:   $mod'
    1.38 +		_ '> Module in use  : $mod'
    1.39  	fi
    1.40 +	# Add it to load automatically at next boot.
    1.41 +	if ! echo "$LOAD_MODULES" | grep -q "$mod"; then
    1.42 +		sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$LOAD_MODULES $mod\""/ \
    1.43 +			/etc/rcS.conf
    1.44 +	fi
    1.45 +	. /etc/rcS.conf
    1.46  }
    1.47  
    1.48  # Detect PCI devices and load kernel module only at first boot,
    1.49 @@ -92,9 +100,10 @@
    1.50  	if [ ! -s /var/lib/detected-modules ]; then
    1.51  		. /etc/rcS.conf
    1.52  		# We need module_name to match output of lsmod.
    1.53 -		list=$(lspci -k | grep "modules" | cut -d ":" -f 2 | sed s/-/_/g)
    1.54 +		list=$(lspci -k | grep "driver" | cut -d ":" -f 2 | sed s/-/_/g)
    1.55  		echo "$list" > /var/lib/detected-modules
    1.56 -		for mod in $list; do
    1.57 +		for mod in $(cat /var/lib/detected-modules | uniq)
    1.58 +		do
    1.59  			check_firmware
    1.60  			load_module
    1.61  		done