Détection automatique du matériel

Suite à la demande de AddiKT1ve, voici le script de chargement automatique des modules de linuxconsole (/etc/init.d/autodrivers)

[code]
ECHO “Auto Drivers”
KRELEASE=uname -r

Kernel 2.4

if [ -e /proc/pci ]
then
for DEVICE in grep Class /proc/pci | cut -d' ' -f9
do
VENDOR=echo $DEVICE | cut -d':' -f1
DEV=echo $DEVICE | cut -d':' -f2
for DRIVER in busmap2mod /lib/modules/$KRELEASE/modules.pcimap $VENDOR $DEV
do
echo -n " $DRIVER"
noskip=“y”
grep askdriver /proc/cmdline &>/dev/null && echo ’ y/n (n) ?’ && read -n 1 noskip
[ “$noskip” == “y” ] && modprobe $DRIVER
done
done
else
for DEVICE in ls /sys/bus/pci/devices/
do
VENDOR=cat /sys/bus/pci/devices/$DEVICE/vendor | cut -d'x' -f2
DEV=cat /sys/bus/pci/devices/$DEVICE/device | cut -d'x' -f2
CLASS=cat /sys/bus/pci/devices/$DEVICE/class
[ “$CLASS” == “0x020000” ] && [ -e /tmp/noethernet ] && echo -n " $CLASS;$VENDOR;$DEV : Ethernet disabled" && continue
[ “$CLASS” == “0x040100” ] && [ -e /tmp/nosound ] && echo -n " $CLASS;$VENDOR;$DEV : Sound card disabled" && continue
[ “$CLASS” == “0x060700” ] && [ -e /tmp/nopcmcia ] && echo -n " $CLASS;$VENDOR;$DEV : PCMCIA disabled" && continue
# echo -n " $CLASS;$VENDOR;$DEV : "
# echo $VENDOR:$DEV >> /tmp/.pcimap
for DRIVER in busmap2mod /lib/modules/$KRELEASE/modules.pcimap $VENDOR $DEV
do
install -d /tmp/.lctmp/hardware/autoload/$DRIVER
[ -e /tmp/.lctmp/hardware/disable/$DRIVER ] && echo -n " $DRIVER disabled in config file " && continue
noskip=“y”
echo -n " $VENDOR:$DEV:$DRIVER"
install -d /tmp/.lctmp/pci/$VENDOR/$DEV/$DRIVER
grep askdriver /proc/cmdline &>/dev/null && echo ’ y/n (n) ?’ && read -n 1 noskip
[ “$noskip” == “y” ] && modprobe $DRIVER
done
done
fi[/code]
evec /patch/src/tools/src/busmap2mod.c :

[code]#define TEXT_SIZE 255
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE * fentree;
char buffer[TEXT_SIZE];
char driver[TEXT_SIZE];
char mydriver[TEXT_SIZE];
int pci_vendor;
int pci_device;
int usb_flag;
int mypci_device=0;
int mypci_vendor=0;
int i=0;
int USB=0;
if (argc < 3) printf(“Generic usage : %s path-to-modules.pcimap\n \n”,argv[0]);
if (argc < 3) printf(“Driver to BUS usage : %s path-to-modules.pcimap driver_name \n \n”,argv[0]);
if (argc < 3) printf(“BUS to Driver usage : %s path-to-modules.pcimap vendor_id bus_id \n \n”,argv[0]);
if (argc < 3) return 2;
if (argc == 3) sscanf(argv[2],"%s",(char *) &mydriver);
if (argc == 4) sscanf(argv[2],"%x",&mypci_vendor);
if (argc == 4) sscanf(argv[3],"%x",&mypci_device);
fentree=fopen(argv[1],“r”);
while((NULL !=fgets(buffer,TEXT_SIZE,fentree)))
{
if (i == 0)
{
if(strstr(buffer,“usb”)) USB=1;
i++;
continue;
}

if (USB)
{
  if (EOF==sscanf(buffer,"%s %x %x %x",(char *) &driver, &usb_flag, &pci_vendor, &pci_device)) return(0);
} 
else
{
  if (EOF==sscanf(buffer,"%s %x %x",(char *) &driver, &pci_vendor, &pci_device)) return(0);
}
  if (argc == 4) 
  {
    if ((mypci_device == pci_device) && (mypci_vendor == pci_vendor)) printf("%s\\n",driver);
  }
  else
  {
    if (argc == 3) 
    {
      if(!strcmp(driver,mydriver)) printf("%04x:%04x\\n",pci_vendor, pci_device);
    }
    else
      if ((mypci_device == pci_device) && (mypci_vendor == pci_vendor)) printf("%s \\n",driver);
   } 
 }  

return 0;
}[/code]

Merci Yann, mais ca reste obscure pour moi :slight_smile:

Génial, merci Yann :).

J’en ai fait un en Ruby perso : http://git.else-projects.org/?p=else/pfe.git;a=tree;f=rimelse/elsedetect;h=640d86ccb7db5fb1bb0aa87e8f42205f9bbc359e;hb=basile