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