embedded2009

最新協作平台活動

Use udev to detect USB storage

The udev is available in http://www.ch.kernel.org/pub/linux/utils/kernel/hotplug/udev-130.tar.gz.

First of all, we need to enter the scratchbox environment.

$ cd /scratchbox
$ ./login

Download the udev package

# wget -O http://www.ch.kernel.org/pub/linux/utils/kernel/hotplug/udev-130.tar.gz
# tar xzvf udev-130.tar.gz

Configure and compile udev


# tar xzvf udev-130.tar.gz
# cd udev-130
# ./configure

Add the following lines into udevd.c at line 50

#ifndef SO_RCVBUFFORCE
#define SO_RCVBUFFORCE  33
#endif

Compile it


# make


Copy necessary files into the default directory in the SDK. We can exit from the scratchbox now. First of all, we need to copy udevd and udevadm to the /sbin directory.
Download rules and scripts from
 
 


 
$ cp /scratchbox/users/wycc/udev-130/udev/udevd /opt/CNS2100-LSDK/rootfs/default/sbin
$ cp /scratchbox/users/wycc/udev-130/udev/udevadm /opt/CNS2100-LSDK/rootfs/default/sbin

Copy rules and scrips to the target from http://homescenario.dyndns.org/udev-rules.tgz.


 
$ mkdir -p /opt/CNS2100-LSDK/rootfs/default/etc/udev/rules.d
$ cp /scratchbox/users/wycc/udev-130/udev.conf /opt/CNS2100-LSDK/rootfs/default/etc/udev
$ cp -a /scratchbox/users/wycc/udev-130/rules/rules.d /opt/CNS2100-LSDK/rootfs/default/etc/udev
$ cd opt/CNS2100-LSDK/rootfs/default/etc/udev; tar xzvf udev-rules.tgz
$ mkdir -p /opt/CNS2100-LSDK/rootfs/default/sys

Modify the init script to start the udev. We need to insert the following lines into the /opt/CNS2100-LSDK/rootfs/default/etc/init.d/rc.sysinit


mount -t sysfs sysfs /sys
mount -t tmpfs / /dev
/sbin/udevd --daemon
/sbin/udevadm trigger

The udevd --daemon is used to start the udev daemon which can read data from the sysfs and create files under /dev.

The udevadm is used to create device files for the drivers which is compiled within the kernel staticly.


Build a new rootfs


Please following the instruction is the previos section to build a new kernel image and download it by using the bootloader. The udev daemon should be runned as a daemon. You can insert a USB pen driver to test it.

Now, we will modify the rules to mount the USB pen driver automatically under the /mnt.