#!/bin/sh
## This is a rcS file for udev startup,dev nodes making,and other init.
## Created by hyyeah@8.12.2008

# If /sbin/udevstart and /sbin/udev both exist,
# using udev and our rules to create device nodes.
if [ -e /sbin/udevstart -a -e /sbin/udevd ] ; then
	
	# Mount tmpfs on /dev, so device nodes created
	# by udev should exist in ram.(tmpfs based on ram)
	/bin/mount -t tmpfs udev /dev >/dev/null 2>&1
	# Error check.
	if [ $? -ne 0 ]; then
		echo "Mounting udev failed"
	fi

	# If /dev/pts directory doesn't exist,
	# we create it.
	if [ ! -e /dev/pts ]; then
		/bin/mkdir -p /dev/pts
	fi
	
	# Mount devpts on /dev/pts, used for
	# pseudo terminal, such as telnet.
	/bin/mount -t devpts devpts /dev/pts >/dev/null 2>&1
	# Error check
	if [ $? -ne 0 ]; then
		echo "Mounting devpts failed"
	fi
	
	if [ -e /proc/sys/kernel/hotplug ] ; then
		echo "" > /proc/sys/kernel/hotplug
	fi

	# The core of udev startup.
	echo -n "Starting udev:      "
	
	# Runing udevd daemon, the return of this command
	# saved in variable $ret.
	/sbin/udevd -d >/dev/null 2>&1; ret=$?
	
	# Running udevstart, the return saved in $?.
	/sbin/udevstart >/dev/null 2>&1
	
	# If udevstart and udevd both return 0,
	# udev starts ok, otherwise failed.
	if [ $? -eq 0 -a $ret -eq 0 ]; then
		echo "[ OK ]"
	else
		echo "[ FAILED ]"
	fi

# If /sbin/udevstart or /sbin/udev doesn't exist,
# using default device nodes created by wrlinux workbench.
else
	 echo "No udev support, use default devfs"
fi

# Create /dev/mtdblock[0|1|3] nodes if they don't exist.
#[ -e /dev/mtdblock0 ] || /bin/mknod -m 660 /dev/mtdblock0 b 31 0
#[ -e /dev/mtdblock1 ] || /bin/mknod -m 660 /dev/mtdblock0 b 31 1
#[ -e /dev/mtdblock3 ] || /bin/mknod -m 660 /dev/mtdblock0 b 31 3


# mount tmpfs on /dev/shm
#[ -e /dev/shm ] || /bin/mkdir -p /dev/shm
#/bin/mount -t tmpfs tmpfs /dev/shm

# Make device nodes if they doesn't exist,
# these nodes can't be created by udev.
#[ -e /dev/watchdog ] || /bin/mknod -m 660 /dev/watchdog c 10 130
#[ -e /dev/hwInfo ] || /bin/mknod -m 660 /dev/hwInfo c 10 242
#[ -e /dev/msmouse ] || /bin/mknod -m 660 /dev/msmouse c 10 2
#[ -e /dev/dsplink ] || /bin/mknod -m 660 /dev/dsplink c 230 0
#[ -e /dev/map0 ] || /bin/mknod -m 660 /dev/map0 c 254 0
#[ -e /dev/map1 ] || /bin/mknod -m 660 /dev/map1 c 254 1
#[ -e /dev/ppp ] || /bin/mknod -m 660 /dev/ppp c 16 13

# Make /dev/dm[0-9] nodes if they doesn't exist, which used by dsp.
#dm_nums=79
#while [ "$dm_nums" -ge 0 ]
#do	
#	# Make /dev/dm* nodes...
#	[ -e /dev/dm"$dm_nums" ] || /bin/mknod -m 660 /dev/dm"$dm_nums" c 225 "$dm_nums"
#	# Reduce $dm_num value by 1.
#	dm_nums=$((dm_nums-1))
#done



#[ -e /dev/ttyS0 ]  || /bin/mknod -m 660 /dev/ttyS0 c 4 64
#[ -e /dev/ttyS1 ]  || /bin/mknod -m 660 /dev/ttyS1 c 4 65
#[ -e /dev/ttyS2 ]  || /bin/mknod -m 660 /dev/ttyS2 c 4 66
#[ -e /dev/cmem ]   || /bin/mknod -m 660 /dev/cmem  c 232 0
