Hardware detection w/example code.
Any reason not to put hardware detection into the boot-floppies?
"libdetect" works fairly well on each of the three machines I've
tried it on.
Note that in the case of a USB keyboard and mouse, you'll want to
load the HID stuff right away, even before they try to type
anything... Right? (I've no system with USB keyboard only to try
this with.) There's a "kbd-reset" kernel command line option that
causes the kernel to attempt to reset a PS/2 or old style keyboard.
When the keyboard is thus found to be non-present, a message is
printed via printk. It can be gotten from "dmesg" or whatever...
This script segment should bring in IDE, SCSI, USB, and NIC
drivers. (WFM, YMMV)... Requires Linux 2.4 with devfs, tested with
"busybox" "ash" (this is from a /linuxrc I wrote)
8<----------------------------------------------------------------->8
disc_list()
{
if [ -d $DEV/discs ]
then
# deterministic order is important - ls will sort.
for disc in $(ls $DEV/discs)
do
echo discs/$disc
done
fi
}
cd_candidates ()
{
if [ -d $DEV/cdroms ]
then
# deterministic order is important - ls will sort.
for cd in $(ls $DEV/cdroms)
do
echo cdroms/$cd
done
fi
}
mount -n -t proc proc /proc
mount -t tmpfs tmpfs /tmp
# Since "devfs" might already be mounted by a kernel command line
# option or by default, send errors and output to /dev/null.
#
mount -t devfs devfs /dev >/dev/null 2>&1 || true
# Load drivers:
#
DRIVERS=$(discover --disable-all --enable=pci,pcmcia,usb,ide,scsi --module bridge ide scsi cdrom ethernet)
for i in $DRIVERS; do
modprobe $i
done
unset DRIVERS
modprobe ide-probe-mod
IDE_MEDIA=$(
for m in $(find /proc/ide -name media -print)
do
cat $m
done
)
if echo $IDE_MEDIA | grep -q cdrom
then
modprobe ide-cd
fi
if echo $IDE_MEDIA | grep -q disk
then
modprobe ide-disk
fi
rmmod ide-probe-mod
if [ -d $DEV/scsi ]
then
cdroms=$(cd_candidates)
modprobe sr_mod
# cd_candidates() MUST return them in deterministic order for this
# to work right. Otherwise, the same logical set returned in a
# different order would appear to this test as there being a new
# cdrom.
#
if [ "$(cd_candidates)" = "$cdroms" ]
then
# No new CDROM(s), so unload it.
rmmod --stacks sr_mod # XXX ? Is "--stacks" correct here?
fi
unset cdroms
discs=$(disc_list)
modprobe sd_mod
if [ "$(disc_list)" = "$discs" ] # ditto for disc_list() re sorting.
then
# No new disc(s), so unload it.
rmmod --stacks sd_mod # XXX ? Is "--stacks" correct here?
fi
unset discs
fi
8<----------------------------------------------------------------->8
--
mailto: (Karl M. Hegbloom) karlheg@microsharp.com
Free the Software http://www.debian.org/social_contract
http://www.microsharp.com
phone://USA/WA/360-260-2066
Reply to: