Skip to Content.
Sympa Menu

sm-discuss - [SM-Discuss] Fwd: [Sgl-Discuss] Hardware autodetection

sm-discuss AT lists.ibiblio.org

Subject: Public SourceMage Discussion List

List archive

Chronological Thread  
  • From: Jason Flatt <jasonflatt AT wizard.com>
  • To: sm-discuss AT lists.ibiblio.org
  • Subject: [SM-Discuss] Fwd: [Sgl-Discuss] Hardware autodetection
  • Date: Sat, 28 Sep 2002 10:58:39 -0700

This was sent to the list a few months back.



---------- Forwarded Message ----------

Subject: [Sgl-Discuss] Hardware autodetection
Date: 09 Jul 2002 23:50:02 -0700
From: Aaron Brice <abrice2 AT cox.net>
To: sgl-discuss AT sourcemage.org

So I've been thinking lately that hardware autodetection and
configuration would be a handy thing. I remember installing SGL and
having trouble figuring out what kernel module my D-Link ethernet card
should use (Mandrake had always figured it out for me). I don't know if
this is still a problem with the new install ISO..

I don't think that getting kudzu or HardDrake to work with SMGL would be
very easy, and those two programs were about all I could find in the way
of hardware detection/configuration..

However, attached is a script that is a first attempt to duplicate some
of the functionality. It depends on lspci from the pciutils spells, and
the hwdata spell that I just submitted to sgl-spell-submit. It only
checks the PCI bus, but can give you the kernel modules needed for a
category of hardware.

For example, instead of asking the user what module to use for the
ethernet card, you can put:

MOD=$(devlist.sh --module --category NETWORK_ETHERNET)

For the alsa-driver spell, instead of using the dialog to let a user
select the audio module, you could do:

CARD=$(devlist.sh --module --category MULTIMEDIA_AUDIO)

Again, as far as I know this only works for stuff on the PCI bus. I
don't have any ISA cards or ISA slots for that matter, but I assume
lspci will not display ISA cards.

Before I go any further I'd like to see if anyone else has opinions on
the subject. Maybe kudzu would be the way to go, or maybe there's an
easy-to-configure autoconfiguration utility out there somewhere that I
wasn't able to find..

Aaron

-------------------------------------------------------


--
Jason Flatt
Section maintainer for printer
E-mail (remove the spaces): jasonflatt @ wizard . com
E-mail (remove the spaces): jflatt @ sourcemage . org
IRC: Oadae
#!/bin/sh

# CLASSFILE is the file containing the class id definitions
CLASSFILE=/usr/src/linux/include/linux/pci_ids.h
# MODFILE maps the device id's to linux modules
MODFILE=/usr/share/hwdata/pcitable

help()  {

  cat  <<  EOF

SYNOPSIS

	devlist.sh [--module] [--category CATEGORY]

DESCRIPTION

	devlist.sh is much like lspci, it lists infomation about the PCI cards
        in the computer.  The main difference is that the required kernel 
        module is also listed, useful for auto-detecting which modules need to
        be loaded.

OPTIONS

	-m, --module
        	display *only* the kernel modules required for the specified 
                categories (or all modules if no category is specified).  
                Output is one module per line

	-c, --category
		Used to specify a certain type of PCI device.  For example,
                specifying --category NETWORK_ETHERNET will display only the
                ethernet card, if found.  The categories are found in
                /usr/src/linux/include/pci_ids.h and start with PCI_CLASS_
	-h, --help
        	This message


EOF

exit 1

}

depcheck()  {
  RETVAL=0
  if  [ !  -e  /sbin/lspci ];  then
    echo  "Must cast the pciutils spell first"
    RETVAL=1
  fi
  if  [ !  -e  $MODFILE ];  then
    echo "Must cast the hwdata spell first"
    RETVAL=1
  fi
  return $RETVAL
}


process_parameters()  {
  
  CATEGORY="ALL"
  while  [  -n  "$1"  ];  do

    case  $1  in

      -m|--module)    ONLYMODULE="yes";  shift 1;  ;;
      -c|--category)  CATEGORY="$2";  shift 2;  ;;
      -h|--help)      help  ;;
      *)              help  ;;
      
    esac

  done
}


# Main 
if  !  depcheck;  then
  exit 1
fi

process_parameters $*

DEVICES=$(lspci -n  |  awk  '{ print $3$4 }')

for  DEV  in  $DEVICES;  do
  CLASSID=$(echo  $DEV  |  cut  -d:  -f1)
  VENDORID=$(echo  $DEV  |  cut  -d:  -f2)
  DEVID=$(echo  $DEV  |  cut  -d:  -f3)
  
  CLASSNAME=$(grep  $CLASSID  $CLASSFILE | grep  PCI_CLASS  |  awk  '{ print $2 }'  |  sed  -e  "s/PCI_CLASS_//")
  if  [[ $CATEGORY != "ALL" && $CLASSNAME != $CATEGORY ]];  then
    continue
  fi
  if  [[ $ONLYMODULE != "yes" ]];  then
    echo
    echo  "Device Category:  $CLASSNAME"

    echo  -n  "Vendor:           "
    grep  "^0x$VENDORID	0x$DEVID"  $MODFILE  |  sed  -e  "s/0x$VENDORID	0x$DEVID	\".*\"	\"//"  |  sed  -e  "s/\"//"  |  awk  -F\|  '{ print $1 }'

    echo  -n  "Device:           "
    grep  "^0x$VENDORID	0x$DEVID"  $MODFILE  |  sed  -e  "s/0x$VENDORID	0x$DEVID	\".*\"	\"//"  |  sed  -e  "s/\"//"  |  awk  -F\|  '{ print $2 }'

    echo  -n  "Module:           "
  fi
  grep  "^0x$VENDORID	0x$DEVID"  $MODFILE  |  sed  -e  "s/0x$VENDORID	0x$DEVID	\"//"  |  sed  -e  "s/\".*//"
  
done



Archive powered by MHonArc 2.6.24.

Top of Page