On Thu, Oct 25, 2007 at 03:15:08PM +0530, Rajeev Bansal wrote:
> Hello All,
> 
> I know this is not the right forum  to ask this question but I am just  
> wondering if someone knows the solution of my problem he/she can post 
> the reply. I am describing my problem below:
> 
> Actually I am booting up Linux kernel from a CD using the custom file 
> system in which I am using Busybox. I am able to get a bash prompt after 
> booting. But I don't have any clue that how my init scripts or kernel 
> will insomd the required drivers of the attached hardwares, like hard 
> disk, CDROM, ether net  card of my machine. Does Busy box helps in this 
> by any means? I need to make a CD which is able to identified most 
> common hardwares and insmod their driver.

I use diethotplug (0.5, not part of busybox) and mdev (part of busybox).
mdev for building /dev, diethotplug for loading modules on device
insertion.

For that, I have a hotplug.rd script:
#!/bin/bash
[ "$1" ] && /sbin/hotplug "$@"
[ -n "$ACTION" -a -n "$DEVPATH" ] && /sbin/mdev

On boot:

* init /dev:
  - mdev -s
  - create symlinks if needed (fd, core, stdin, stdout, stderr)

* tell the kernel to use the hotplug script:
  - echo /sbin/hotplug.rd > /proc/sys/kernel/hotplug

* load drivers from existing devices:
  - (see attached script)

* load drivers without devices
  - force="vmxnet dm-mod md-mod sd_mod ide-disk ide-cd"
    for m in $force; do
      modprobe -q $m &> /dev/null
    done

It is possible that current busybox's mdev does the job of diethotplug,
I don't know.

The full script for setting /dev and loading modules is attached.

-- 
lfr
0/0
#!/bin/bash
# vim:et:sw=4:ts=4

PATH=/usr/bin:/bin:/usr/sbin:/sbin

KDIR=/lib/modules/`uname -r`
for ko in $KDIR/*.ko; do
    insmod $ko 2> /dev/null && rm -f $ko
done

[ -n "$ramfs" ] && mount -o mode=0755 -t $ramfs none /dev

cd /dev

mkdir -p pts shm mapper
mount -t devpts -o gid=5,mode=620 none pts
[ -n "$ramfs" ] && mount -t $ramfs -o mode=01777 none shm

[ -e fd ] || ln -fs /proc/self/fd fd
[ -e core ] || ln -fs /proc/kcore core
[ -e stdin ] || ln -fs /proc/self/fd/0 stdin
[ -e stdout ] || ln -fs /proc/self/fd/1 stdout
[ -e stderr ] || ln -fs /proc/self/fd/2 stderr
[ -e XOR ] || ln -fs null XOR

mdev -s

if [ -e $KDIR/kernel.sfs ]; then
    mount -t squashfs -r -o loop $KDIR/kernel.sfs $KDIR/kernel
fi

if [ -e $KDIR/kernel.cfs ]; then
    mount -t cramfs -r -o loop $KDIR/kernel.cfs $KDIR/kernel
fi

echo /sbin/hotplug.rd > /proc/sys/kernel/hotplug

ACTION=add
export ACTION

load_pci()
{
    cd /sys/bus/pci/devices/ || return 0

    # make sure the pci agent will run
    PCI_CLASS=0
    PCI_ID=0:0
    PCI_SLOT=0:0.0
    PCI_SLOT_NAME=0:0.0
    PCI_SUBSYS_ID=0:0
    export PCI_CLASS PCI_ID PCI_SLOT PCI_SLOT_NAME PCI_SUBSYS_ID

    for PCI_DEVICE in *; do
        PCI_SLOT_NAME="${PCI_DEVICE#*:}"
        PCI_CLASS="$(< $PCI_DEVICE/class)"
        PCI_CLASS="${PCI_CLASS#0x}"
        vendor_id="$(< $PCI_DEVICE/vendor)"
        device_id="$(< $PCI_DEVICE/device)"
        PCI_ID="${vendor_id#0x}:${device_id#0x}"
        sub_vendor_id="$(< $PCI_DEVICE/subsystem_vendor)"
        sub_device_id="$(< $PCI_DEVICE/subsystem_device)"
        PCI_SUBSYS_ID="${sub_vendor_id#0x}:${sub_device_id#0x}"
        run_hotplug pci
    done
    unset PCI_CLASS PCI_ID PCI_SLOT PCI_SLOT_NAME PCI_SUBSYS_ID
}

load_usb()
{
    modprobe -q usbcore &> /dev/null
    grep -q /proc/bus/usb /proc/mounts || mount -t usbfs none /proc/bus/usb

    modprobe -q ehci-hcd &> /dev/null
    modprobe -q ohci-hcd &> /dev/null
    modprobe -q uhci-hcd &> /dev/null

    PRODUCT=0/0/0
    TYPE=
    INTERFACE=
    DEVPATH=
    DEVFS=/proc/bus/usb
    DEVICE=
    export ACTION PRODUCT TYPE INTERFACE DEVPATH DEVFS DEVICE

    cd /sys/bus/usb/devices || return 0
    for d in [0-9]*; do
        [ -f $d/../idVendor ] || continue

        DEVPATH=/bus/usb/devices/$d
        PRODUCT="$(< $d/../idVendor)/$(< $d/../idProduct)/$(< $d/../bcdDevice)"
        if [ -f $d/../../devnum ]; then
            devbus="000$(< $d/../../devnum)"
            devdev="000$(< $d/../devnum)"
            while [ ${#devbus} -gt 3 ]; do devbus="${devbus#?}"; done
            while [ ${#devdev} -gt 3 ]; do devdev="${devdev#?}"; done
            DEVICE="/proc/bus/usb/$devbus/$devdev"
        else
            DEVICE=
        fi
        run_hotplug usb
    done
    unset ACTION PRODUCT TYPE INTERFACE DEVPATH DEVFS DEVICE
}

run_hotplug()
{
    /sbin/hotplug.rd "$@"
}

exec 2> /dev/null

force="vmxnet dm-mod md-mod sd_mod ide-disk ide-cd"
for m in $force; do
    modprobe -q $m &> /dev/null
done

load_pci
load_usb

# serial devices
for d in /dev/ttyS* /dev/ttyAM* /dev/ttyUSB*; do
    [ -e "$d" ] && stty -F $d ospeed 57600
done

if [ -d /proc/acpi ]; then
    for module in $KDIR/kernel/drivers/acpi/*.ko ; do
        module=${module##*/}
        module=${module%.ko}
        modprobe $module &> /dev/null
    done
fi

(cat /proc/bus/*/devices; dmesg ) > /dev/urandom

Attachment: pgpETYcnN4faR.pgp
Description: PGP signature

_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to