summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/udev/udev/init
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/udev/udev/init')
-rw-r--r--meta/recipes-core/udev/udev/init133
1 files changed, 133 insertions, 0 deletions
diff --git a/meta/recipes-core/udev/udev/init b/meta/recipes-core/udev/udev/init
new file mode 100644
index 0000000..410a650
--- /dev/null
+++ b/meta/recipes-core/udev/udev/init
@@ -0,0 +1,133 @@
1#!/bin/sh
2
3### BEGIN INIT INFO
4# Provides: udev
5# Required-Start: mountvirtfs
6# Required-Stop:
7# Default-Start: S
8# Default-Stop:
9# Short-Description: Start udevd, populate /dev and load drivers.
10### END INIT INFO
11
12export TZ=/etc/localtime
13
14[ -d /sys/class ] || exit 1
15[ -r /proc/mounts ] || exit 1
16[ -x @UDEVD@ ] || exit 1
17[ -f /etc/default/udev-cache ] && . /etc/default/udev-cache
18[ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf
19[ -f /etc/default/rcS ] && . /etc/default/rcS
20
21readfiles () {
22 READDATA=""
23 for filename in $@; do
24 if [ -r $filename ]; then
25 while read line; do
26 READDATA="$READDATA$line"
27 done < $filename
28 fi
29 done
30}
31
32kill_udevd () {
33 pid=`pidof -x udevd`
34 [ -n "$pid" ] && kill $pid
35}
36
37case "$1" in
38 start)
39 export ACTION=add
40 # propagate /dev from /sys
41 echo "Starting udev"
42
43 # Check for requireed devtmpfs before trying to start udev and
44 # mount a no-existant fs.
45 if ! grep -q devtmpfs /proc/filesystems
46 then
47 echo "Missing devtmpfs, which is required for udev to run";
48 echo "Halting..."
49 halt
50 fi
51 # mount the devtmpfs on /dev, if not already done
52 LANG=C awk '$2 == "/dev" && ($3 == "devtmpfs") { exit 1 }' /proc/mounts && {
53 mount -n -o mode=0755 -t devtmpfs none "/dev"
54 }
55 [ -e /dev/pts ] || mkdir -m 0755 /dev/pts
56 [ -e /dev/shm ] || mkdir -m 1777 /dev/shm
57 # the automount rule for udev needs /tmp directory available, as /tmp is a symlink
58 # to /var/tmp which in turn is a symlink to /var/volatile/tmp, we need to make sure
59 # /var/volatile/tmp directory to be available.
60 mkdir -p /var/volatile/tmp
61
62 # Cache handling.
63 # A list of files which are used as a criteria to judge whether the udev cache could be reused.
64 CMP_FILE_LIST="/proc/version /proc/cmdline /proc/devices /proc/atags"
65 if [ "$DEVCACHE" != "" ]; then
66 if [ -e $DEVCACHE ]; then
67 readfiles $CMP_FILE_LIST
68 NEWDATA="$READDATA"
69 readfiles /etc/udev/cache.data
70 OLDDATA="$READDATA"
71 if [ "$OLDDATA" = "$NEWDATA" ]; then
72 (cd /; tar xf $DEVCACHE > /dev/null 2>&1)
73 not_first_boot=1
74 [ "$VERBOSE" != "no" ] && echo "udev: using cache file $DEVCACHE"
75 [ -e /dev/shm/udev.cache ] && rm -f /dev/shm/udev.cache
76 else
77 # Output detailed reason why the cached /dev is not used
78 if [ "$VERBOSE" != "no" ]; then
79 echo "udev: udev cache not used"
80 echo "udev: we use $CMP_FILE_LIST as criteria to judge whether the cache /dev could be resued"
81 echo "udev: olddata: $OLDDATA"
82 echo "udev: newdata: $NEWDATA"
83 fi
84 echo "$NEWDATA" > /dev/shm/udev.cache
85 fi
86 else
87 if [ "$ROOTFS_READ_ONLY" != "yes" ]; then
88 # If rootfs is not read-only, it's possible that a new udev cache would be generated;
89 # otherwise, we do not bother to read files.
90 readfiles $CMP_FILE_LIST
91 echo "$READDATA" > /dev/shm/udev.cache
92 fi
93 fi
94 fi
95
96 # make_extra_nodes
97 kill_udevd > "/dev/null" 2>&1
98
99 # trigger the sorted events
100 echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug
101 @UDEVD@ -d
102
103 udevadm control --env=STARTUP=1
104 if [ "$not_first_boot" != "" ];then
105 udevadm trigger --action=add --subsystem-nomatch=tty --subsystem-nomatch=mem --subsystem-nomatch=vc --subsystem-nomatch=vtconsole --subsystem-nomatch=misc --subsystem-nomatch=dcon --subsystem-nomatch=pci_bus --subsystem-nomatch=graphics --subsystem-nomatch=backlight --subsystem-nomatch=video4linux --subsystem-nomatch=platform
106 (udevadm settle --timeout=3; udevadm control --env=STARTUP=)&
107 else
108 udevadm trigger --action=add
109 udevadm settle
110 fi
111 ;;
112 stop)
113 echo "Stopping udevd"
114 start-stop-daemon --stop --name udevd --quiet
115 ;;
116 restart)
117 $0 stop
118 sleep 1
119 $0 start
120 ;;
121 status)
122 pid=`pidof -x udevd`
123 if [ -n "$pid" ]; then
124 echo "udevd (pid $pid) is running ..."
125 else
126 echo "udevd is stopped"
127 fi
128 ;;
129 *)
130 echo "Usage: $0 {start|stop|status|restart}"
131 exit 1
132esac
133exit 0