LKN: Personalizzare un Kernel: differenze tra le versioni

Nessun oggetto della modifica
Riga 314: Riga 314:


===Un aiuto dallo script===
===Un aiuto dallo script===
Come menzionato all'inizio del capitolo, file e directory nel sysfs cambiano da una versione del kernel a un altra. Qui c'è uno script che è alla portata di mano per determinare il driver del kernel necessario e il module name per ogni dispositivo nel sistema. E' stato sviluppato con gli sviluppatori del kernel responsabili per il sysfs e dovrebbe funzionare con successo con tutte le versioni future del kernel 2.6 .
Per esempio, fa un "short work" del precedente esempio, quando dovete prendere tutti i driver appropriati per i dispositivi a blocco sda:
<strong>$ get-driver.sh sda</strong>
looking at sysfs device: /sys/devices/pci0000:00/0000:00:1f.2/host0/
target0:0:0/0:0:0:0
found driver: sd
found driver: ata_piix
Posso anche trovare tutto sui driver appropriati necessari per cose complicate come i dispositivi USB-toserial:
<strong>$ get-driver.sh ttyUSB0</strong>
looking at sysfs device: /sys/devices/pci0000:00/0000:00:1d.3/usb4/4-2/4-2.
3/4-2.3:1.0/ttyUSB0
found driver: pl2303 from module: pl2303
found driver: pl2303 from module: pl2303
found driver: usb from module: usbcore
found driver: usb from module: usbcore
found driver: usb from module: usbcore
found driver: uhci_hcd from module: uhci_hcd
Potete scaricare un file di esempio contenente questo script dal web site del libro, fornito nella sezione "How to Contact Us" in Preface.
#!/bin/sh
#
# Find all modules and drivers for a given class device.
#
if [ $# != "1" ] ; then<br>
  echo<br>
  echo "Script to display the drivers and modules for a specified sysfs
  class device"
  echo "usage: $0 <CLASS_NAME>"
  echo
  echo "example usage:"
  echo " $0 sda"
  echo "Will show all drivers and modules for the sda block device."
  echo
  exit 1
fi
DEV=$1
if test -e "$1"; then
  DEVPATH=$1
else
  # find sysfs device directory for device
  DEVPATH=$(find /sys/class -name "$1" | head -1)
  test -z "$DEVPATH" && DEVPATH=$(find /sys/block -name "$1" | head -1)
  test -z "$DEVPATH" && DEVPATH=$(find /sys/bus -name "$1" | head -1)
  if ! test -e "$DEVPATH"; then
  echo "no device found"
  exit 1
  fi
fi
echo "looking at sysfs device: $DEVPATH"
if test -L "$DEVPATH"; then
  # resolve class device link to device directory
  DEVPATH=$(readlink -f $DEVPATH)
  echo "resolve link to: $DEVPATH"
fi
if test -d "$DEVPATH"; then
  # resolve old-style "device" link to the parent device
  PARENT="$DEVPATH";
  while test "$PARENT" != "/"; do
  if test -L "$PARENT/device"; then
    DEVPATH=$(readlink -f $PARENT/device)
    echo "follow 'device' link to parent: $DEVPATH"
    break
  fi
  PARENT=$(dirname $PARENT)
  done
fi
while test "$DEVPATH" != "/"; do
  DRIVERPATH=
  DRIVER=
  MODULEPATH=
  MODULE=
  if test -e $DEVPATH/driver; then
  DRIVERPATH=$(readlink -f $DEVPATH/driver)
  DRIVER=$(basename $DRIVERPATH)
  echo -n "found driver: $DRIVER"
  if test -e $DRIVERPATH/module; then
    MODULEPATH=$(readlink -f $DRIVERPATH/module)
    MODULE=$(basename $MODULEPATH)
    echo -n " from module: $MODULE"
  fi
  echo
  fi
  DEVPATH=$(dirname $DEVPATH)
done




128

contributi