initial version of scripts, config and debian package
[moebian] / install / etc / init.d / rcS
1 #!/bin/sh
2 # Copyright(C) 2006 Nokia Corporation.
3
4 #  This program is free software; you can redistribute it and/or modify
5 #  it under the terms of the GNU General Public License version 2 as
6 #  published by the Free Software Foundation.
7
8 #  This program is distributed in the hope that it will be useful, but
9 #  WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 #  General Public License for more details.
12
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software
15 #  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
16 #  USA
17
18
19
20 umask 022
21 PATH=/sbin:/bin:/usr/sbin:/usr/bin
22 MODULES="twl4030-vibra
23 dspbridge
24 iommu2
25 omap3-iommu
26 omap34xxcam-mod
27 omap_previewer_hack
28 board-rx51-camera
29 et8ek8
30 ad5820
31 adp1653
32 vs6555
33 uinput"
34
35 if [ -L /var/run ]
36 then
37         rm -f /var/run
38         mkdir /var/run
39 fi
40
41 mount -n -o remount,rw /
42 mount -n -t proc proc /proc
43 mount -n -t sysfs sysfs /sys
44 mount -n -t tmpfs -o size=1M,noatime tmpfs /tmp
45 mount -n -t tmpfs -o size=256k,mode=0755,nosuid,noatime tmpfs /var/run
46
47 MODE=`getbootstate`
48
49 # This doesn't really belong here, but we have start this so early
50 start_bootchart(){
51         if [ -e /bootchart -a -e /etc/init.d/bootchart ]
52         then
53                 /etc/init.d/bootchart start
54         fi
55 }
56
57 start_softupd()
58 {
59         echo "Starting software updater"
60         /etc/init.d/softupd.rcS
61 }
62
63 in_flash_mode()
64 {
65         grep update /proc/component_version 1>/dev/null 2>/dev/null
66 }
67
68 mount_devpts() {
69         TTYGRP=5
70         TTYMODE=620
71
72         if [ ! -d /dev/pts ]
73         then
74             mkdir /dev/pts
75         fi
76
77         if [ ! -c /dev/ptmx ]
78         then
79             mknod /dev/ptmx c 5 2
80                 chmod 666 /dev/ptmx
81         fi
82
83         mount -n -t devpts -ogid=$TTYGRP,mode=$TTYMODE devpts /dev/pts
84         rm -rf /var/tmp/*
85 }
86
87 # I hate this hack.  -- Md
88 make_extra_nodes () {
89     if [ "$(echo /lib/udev/devices/*)" != "/lib/udev/devices/*" ]; then
90         cp -a /lib/udev/devices/* /dev/
91     fi
92   grep '^[^#]' /etc/udev/links.conf | \
93   while read type name arg1; do
94     [ "$type" -a "$name" -a ! -e "/dev/$name" -a ! -L "/dev/$name" ] ||continue
95     case "$type" in
96     L)
97       ln -s $arg1 /dev/$name
98       ;;
99     D)
100       mkdir -p /dev/$name
101       ;;
102     M)
103       mknod /dev/$name $arg1 && chmod 600 /dev/$name
104       ;;
105     *)
106       echo "unparseable line ($type $name $arg1)"
107       ;;
108     esac
109   done
110 }
111
112 load_extra_modules () {
113     echo -n "Loading extra modules..."
114     for i in $MODULES; do
115         echo "Loading $i"
116         modprobe -q $i ||:
117     done
118     echo "done."
119 }
120
121 # Mount home and paging partitions if they are available
122 mount_mmc(){
123    device=$1
124    swap=$device"p1"
125    home=$device"p2"
126    test=$device"p3"
127
128    if [ -e $test ]
129    then
130       echo "Mounting partition $swap for paging"
131       # swap disabled as a workaround for Xorg bug, per NB#111807.
132       swapon $swap
133       modprobe ext3
134       echo "Mounting partition $home as home directory"
135       mount -t ext3 -o noatime,commit=1,data=writeback $home /home
136    else
137       echo "No paging partition available as $swap"
138       echo "No home partition available as $home"
139    fi
140 }
141
142 prepare_start_udev()
143 {
144         . /etc/udev/udev.conf
145
146         if [ -z "$tmpfs_size" ]; then
147                 tmpfs_size="1M"
148         fi
149
150         ACTION=add
151         echo -n "Mounting a tmpfs over /dev..."
152         mount -n -o size=$tmpfs_size,mode=0755,noatime -t tmpfs none /dev
153         echo "done."
154         mkdir -p /dev/.udev/db /dev/.udev/queue
155         echo "" > /sys/kernel/uevent_helper
156         echo -n "Creating extra device nodes... "
157         make_extra_nodes
158         echo "done."
159 }
160
161 start_udev()
162 {
163         prepare_start_udev
164         /sbin/udevd --daemon
165 }
166
167 make_nodes()
168 {
169         echo -n "Creating device nodes... "
170
171         if [ -x /sbin/udevtrigger ]; then
172                 /sbin/udevtrigger
173         else
174                 /sbin/udevadm trigger
175                 #wait for all events
176                 /sbin/udevadm settle
177         fi
178         echo "done."
179 }
180
181 # When modifying this script, do not forget that between the time that
182 # the new /dev has been mounted and udevtrigger has been run there will be
183 # no /dev/null. This also means that you cannot use the "&" shell command.
184
185         start_bootchart
186
187 if in_flash_mode; then
188         start_softupd
189         reboot
190 fi
191
192 # here only in non-flash mode
193
194 # No need to start udev before softupd anymore
195
196         start_udev
197         make_nodes
198         load_extra_modules
199
200 mount_devpts
201 mount -n -o size=64M,nosuid,nodev,noatime -t tmpfs tmpfs /dev/shm
202
203 # mount_mmc "/dev/mmcblk0"
204
205 /sbin/hwclock -s || true
206
207 # cannot collect product data if we are under SDK
208 # it should not be run there, but explicit check is better
209
210 OPI=`which osso-product-info`
211
212 if [ x$OPI != x ]; then
213
214         # Make sure /etc/hostname and /etc/hosts exist and are not empty. They do not
215         # exist if this is the very first boot, and they may be empty if power cut
216         # happended before the contents has reached the media.
217         if [ ! -f /etc/hostname  -o ! -s /etc/hostname -o ! -f /etc/hosts -o ! -s /etc/hosts ]; then
218                 hostname="`$OPI -qOSSO_PRODUCT_SHORT_NAME | sed 's/ /-/g'`-`$OPI -qOSSO_PRODUCT_RELEASE_VERSION | cut -d. -f3`"
219                 echo $hostname > /etc/hostname
220                 echo "127.0.0.1 $hostname localhost" > /etc/hosts
221                 chmod 644 /etc/hosts
222         fi
223
224         # Similarly, make sure /etc/issue and /etc/issue.net are fine
225         if [ ! -f /etc/issue -o ! -s /etc/issue -o ! -f /etc/issue.net -o ! -s /etc/issue.net -o -f /home/user/first-boot-flag ]; then
226                 full_name=`$OPI -qOSSO_PRODUCT_RELEASE_FULL_NAME`
227                 echo "$full_name \n \l" > /etc/issue
228                 echo "" >> /etc/issue
229                 echo "$full_name %h" > /etc/issue.net
230         fi
231 fi
232
233 # Note, normally we would have to sync the FS to make sure the files have
234 # reached the media. But because the files are small, they would be either
235 # empty or non-existing in case of an unclean reboot, and we handle both
236 # cases.
237
238 hostname -F /etc/hostname
239 ifup lo &
240 test $MODE = USER && modprobe g_nokia
241
242 #echo /sbin/udevsend > /proc/sys/kernel/hotplug
243
244 #: > /var/run/utmp
245 #chmod 664 /var/run/utmp
246 #chgrp utmp /var/run/utmp
247
248 rm -f /etc/mtab
249 cat /proc/mounts > /etc/mtab
250
251 echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
252 echo 0 > /proc/sys/net/ipv4/conf/default/accept_redirects
253 echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
254 echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter
255 echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
256 echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
257 echo "49152 65535" > /proc/sys/net/ipv4/ip_local_port_range
258 echo 6000 > /sys/class/bluetooth/hci0/idle_timeout
259
260 # adjust other kernel parameters to minimize memory consumption
261 # and optimize IO pressure
262 echo 4 > /proc/sys/kernel/pty/max
263 echo 1024 > /proc/sys/kernel/threads-max
264 echo 8192 > /proc/sys/fs/file-max
265 echo 100 > /proc/sys/vm/swappiness
266 echo 5 > /proc/sys/vm/page-cluster
267 echo 500 > /proc/sys/vm/dirty_expire_centisecs
268 echo 65536 > /proc/sys/net/core/rmem_default
269 echo 16384 > /proc/sys/net/core/wmem_default
270
271 # Finalize SSU in case it has been interrupted by power failure
272 if test -x /usr/libexec/ham-rescue.sh; then
273   /usr/libexec/ham-rescue.sh
274 fi
275
276 # Disable sysrq to avoid accidental console-carbage resets.
277 echo 0 > /proc/sys/kernel/sysrq
278
279 echo "/what/me/worry" > /proc/sys/kernel/core_pattern
280 echo 1 > /proc/sys/kernel/panic
281 echo 1 > /proc/sys/kernel/panic_on_oops
282
283 umount /mnt/initfs
284 mount -t ubifs -o ro ubi0:rootfs /nand
285
286 if test $MODE = USER; then
287     echo starting ssh
288     ifup usb0
289     /etc/init.d/ssh start
290 fi
291
292 exit 0