tools/llvm: Do not build with symbols
[minix3.git] / etc / usr / rc
bloba71d0fe51c982eb9f060ecc4988c4163e3392344
1 # /usr/etc/rc - continued system initialization.
3 RANDOM_FILE=/usr/adm/random.dat
4 LOCAL_FILE=/usr/etc/rc.local
6 ARCH="`sysenv arch`"
8 if [ ! "$ARCH" ]
9 then    # Older kernels do not provide an arch sysenv variable.
10         # We assume we are on x86 then, as existing systems with
11         # kernel and userland (i.e. this script) unsynchronized
12         # will be x86.
13         ARCH=i386
16 # Get $SERVICES_DIRS
17 . /etc/rc.conf
19 # Directories to find services in
20 if [ ! "$SERVICES_DIRS" ]
21 then    SERVICES_DIRS=/usr/sbin
24 # Booting from cd?
25 bootcd="`/bin/sysenv bootcd`"
27 case "$#:$1" in
28 1:autoboot)
29     action=start
30     ;;
31 1:start|1:stop|1:down)
32     action=$1
33     ;;
34 *)  echo >&2 "Usage: $0 autoboot|start|stop|down"
35     exit 1
36 esac
38 if [ -f "$LOCAL_FILE" ]
39 then    . "$LOCAL_FILE" $1
42 disabled()
44     ifs="$IFS"; IFS=,
45     for skip in `sysenv disable`
46     do 
47         if [ "$skip" = "$1" ]
48         then     
49                 IFS="$ifs"; unset ifs
50                 return 0
51         fi
52     done
53     IFS="$ifs"; unset ifs
54     return 1
57 daemonize()
59     # Function to start a daemon, if it exists.
60     local IFS=':'
61     local name="$1"
62     test "$1" = tcpd && name="$2"
64     for dir in $PATH
65     do
66         if [ -f "$dir/$1" ]
67         then
69             # check if this service is disabled at the boot monitor.
70             if disabled $name; then return; fi
72             echo -n " $name"
73             "$@" &
74             return
75         fi
76     done
79 up()
81     # Function to dynamically start a system service
82     opt=""
83     prefix=$(expr "$1 " : '\(-\)')
84     if [ "$prefix" = "-" ];
85     then
86          opt=$1
87          shift
88     fi
89     service=$1
90     shift
92     # First check if this service is disabled at the boot monitor.
93     if disabled $service; then return; fi
95     # Service is not disabled. Try to bring it up.
96     found=""
97     for dir in $SERVICES_DIRS
98     do  bin=$dir/$service
99         if [ -x $bin -a -z "$found" ]
100         then    service $opt up $bin "$@" 
101                 echo -n " $service"
102                 found=yes
103         fi
104     done
105     if [ -z "$found" ]
106     then        echo " ($service not found in $SERVICES_DIRS)"
107     fi
110 get_eth_labels() {
111   # Filter out the non-vlan ethernet entries from inet.conf.
112   # Produce as output a list of "drivername_instancenr"-formatted labels.
113   sed 's/\008/ /g' /etc/inet.conf | \
114     sed -n 's/^ *eth[0-9][0-9]* *\([^ ][^ ]*\) *\([0-9][0-9]*\).*$/\1_\2/p' | \
115     grep -v '^vlan_'
118 # Detect expansion boards on the BeagleBone and load the proper drivers.
119 capemgr() {
121     # Probe each possible cape EEPROM slave address for a BeagleBone cape.
122     for slave_addr in 54 55 56 57
123     do
125         # See if there is a readable EEPROM with address ${slave_addr}.
126         eepromread -f /dev/i2c-3 -a 0x${slave_addr} > /dev/null 2>&1
127         RESULT=$?
128         if [ $RESULT -eq 0 ]
129         then
131             # Found an alive EEPROM. Try reading the cape name.
132             CAPE=`eepromread -i -f /dev/i2c-3 -a 0x${slave_addr} | \
133                 sed -n 's/^PART_NUMBER     : \(.*\)$/\1/p' | \
134                 sed -e 's/\.*$//g'` # Strip trailing periods.
136             # Look for a cape specific RC script.
137             if [ -x /etc/rc.capes/${CAPE} ]
138             then
140                 # CAT24C256 EEPROM -- all capes have this chip.
141                 test -e /dev/eepromb3s${slave_addr} || \
142                     (cd /dev && MAKEDEV eepromb3s${slave_addr})
143                 up cat24c256 -dev /dev/eepromb3s${slave_addr} \
144                     -label cat24c256.3.${slave_addr} \
145                     -args "bus=3 address=0x${slave_addr}"
147                 # Load the drivers for the cape and do any other configuration.
148                 . "/etc/rc.capes/${CAPE}"
150             else
152                 echo ""
153                 echo "** UNSUPPORTED CAPE: ${CAPE}"
154                 echo ""
156             fi
157         fi
158     done
161 DAEMONS=/etc/rc.daemons
163 case $action in
164 start|autoboot)
165     # Select console font.
166     test -f /etc/font && loadfont /etc/font </dev/console
168     # Cleanup.
169     rm -rf /tmp/* /usr/run/* /usr/spool/lpd/* /usr/spool/locks/*
171     # Start servers and drivers set at the boot monitor.
172     echo -n "Starting services:"
173     up -n random -dev /dev/random -period 3HZ
175     # load random number generator
176     if [ -f $RANDOM_FILE ]
177     then
178         cat < $RANDOM_FILE >/dev/random
179         # overwrite $RANDOM_FILE. We don't want to use this data again
180         dd if=/dev/random of=$RANDOM_FILE bs=1024 count=1 2> /dev/null
181     fi
183     # start network driver instances for all configured ethernet devices
184     for label in $(get_eth_labels); do
185         driver=$(echo $label | sed 's/\(.*\)_.*/\1/')
186         instance=$(echo $label | sed 's/.*_//')
187         eval arg=\$${label}_arg
188         if [ ! -z "$arg" ]; then arg=" $arg"; fi
189         arg="-args \"instance=$instance$arg\""
190         eval up $driver -label $label $arg -period 5HZ
191     done
192     if [ X`/bin/sysenv lwip` = Xyes ]
193     then
194         up lwip -script /etc/rs.inet -dev /dev/ip
195     else
196         up inet -script /etc/rs.inet -dev /dev/ip
197     fi
199     up pty -dev /dev/ptyp0
201     up uds -dev /dev/uds
203     up -n ipc
205     up log -dev /dev/klog
207     if [ $ARCH = i386 ]
208     then
209         up -n printer -dev /dev/lp -period 10HZ
210         # start VirtualBox time sync driver if the device is there
211         if grep '^[^ ]* [^ ]* 80EE:CAFE ' /proc/pci >/dev/null; then
212                 up -n vbox -period 10HZ
213         fi
214     fi
216     echo .
218     # Network initialization.
219     (: </dev/tcp) 2>/dev/null && net=t  # Is there a TCP/IP server?
221     echo -n "Starting daemons:"
222     daemonize update
224     # Ugly error message when starting cron from CD.
225     # (and cron unnecessary then so..)
226     if [ ! -f /CD ]
227     then        daemonize cron
228     else        mkdir /tmp/log
229                 rm -f /var/log || true
230                 ln -s /tmp/log /var/log || true
231                 . /etc/rc.cd
232     fi
233     # syslogd has not been started yet
234     rm -f /var/run/syslogd.pid
235     daemonize syslogd
236     echo .
238     # i2c only supported on ARM at the moment
239     if [ $ARCH = earm ]
240     then
241         echo -n "Starting i2c subsystem: "
242         for bus in 1 2 3
243         do
244                 test -e /dev/i2c-${bus} || (cd /dev && MAKEDEV i2c-${bus})
245                 up i2c -dev /dev/i2c-${bus} -label i2c.${bus} \
246                         -args instance=${bus}
247         done
248         echo .
250         BOARD_NAME=`sysenv board`
251         case "${BOARD_NAME}" in
253                 ARM-ARMV7-TI-BB-WHITE)
254                         echo "Running on a BeagleBone"
255                         echo -n "Starting i2c device drivers: "
257                         # start EEPROM driver for reading board info
258                         test -e /dev/eepromb1s50 || \
259                                 (cd /dev && MAKEDEV eepromb1s50)
260                         up cat24c256 -dev /dev/eepromb1s50 \
261                                 -label cat24c256.1.50 \
262                                 -args 'bus=1 address=0x50'
264                         # Start TPS65217 driver for power management.
265                         up tps65217 -label tps65217.1.24 \
266                                 -args 'bus=1 address=0x24'
268                         # check for the presence of a display
269                         eepromread -f /dev/i2c-2 -n > /dev/null 2>&1
270                         RESULT=$?
271                         if [ $RESULT -eq 0 ]
272                         then
273                                 # start eeprom driver for reading EDID.
274                                 test -e /dev/eepromb2s50 || \
275                                         (cd /dev && MAKEDEV eepromb2s50)
276                                 up cat24c256 -dev /dev/eepromb2s50 \
277                                         -label cat24c256.2.50 \
278                                         -args 'bus=2 address=0x50'
280                                 # start frame buffer
281                                 #up fb -dev /dev/fb0 -args edid.0=cat24c256.2.50
282                                 # fb hasn't been ported to AM335X yet.
283                         fi
285                         if [ -e /service/usbd ]
286                         then
287                                 echo "Starting USBD"
288                                 up usbd
289                         fi
290                         # Detect expansion boards and start drivers.
291                         capemgr
293                         ;;
295                 ARM-ARMV7-TI-BB-BLACK)
296                         echo "Running on a BeagleBone Black"
297                         echo -n "Starting i2c device drivers: "
299                         # start EEPROM driver for reading board info
300                         test -e /dev/eepromb1s50 || \
301                                 (cd /dev && MAKEDEV eepromb1s50)
302                         up cat24c256 -dev /dev/eepromb1s50 \
303                                 -label cat24c256.1.50 \
304                                 -args 'bus=1 address=0x50'
306                         # Start TPS65217 driver for power management.
307                         up tps65217 -label tps65217.1.24 \
308                                 -args 'bus=1 address=0x24'
310                         # Start TDA19988 driver for reading EDID.
311                         up tda19988 -label tda19988.1.3470 -args \
312                                 'cec_bus=1 cec_address=0x34 hdmi_bus=1 hdmi_address=0x70'
314                         # start frame buffer
315                         #up fb -dev /dev/fb0 -args edid.0=tda19988.1.3470
316                         # fb hasn't been ported to AM335X yet.
318                         if [ -e /service/usbd ]
319                         then
320                                 echo "Starting USBD"
321                                 up usbd
322                         fi
323                         # Detect expansion boards and start drivers.
324                         capemgr
326                         ;;
328                 ARM-ARMV7-TI-BBXM-GENERIC)
329                         echo "Running on a BeagleBoard-xM"
330                         echo -n "Starting i2c device drivers: "
332                         # Start TPS65950 driver for power management.
333                         up tps65950 -label tps65950.1.48 \
334                                 -args 'bus=1 address=0x48'
336                         # Set the system time to the time in the TPS65950's RTC
337                         readclock
339                         # check for the presence of a display
340                         eepromread -f /dev/i2c-3 -n > /dev/null 2>&1
341                         RESULT=$?
342                         if [ $RESULT -eq 0 ]
343                         then
344                                 # start eeprom driver for reading edid
345                                 test -e /dev/eepromb3s50 || \
346                                         (cd /dev && MAKEDEV eepromb3s50)
347                                 up cat24c256 -dev /dev/eepromb3s50 \
348                                         -label cat24c256.3.50 \
349                                         -args 'bus=3 address=0x50'
351                                 # start frame buffer
352                                 up fb -dev /dev/fb0 -args edid.0=cat24c256.3.50
353                         fi
355                         ;;
356         esac
358         echo .
359     fi
361     if [ "$net" ]
362     then
363         if [ -f /etc/rc.net ]
364         then
365             # Let a customized TCP/IP initialization script figure it out.
366             . /etc/rc.net
367         else
368             # Standard network daemons.
369             echo -n "Starting networking:"
370             if grep -s 'psip0.*default' /etc/inet.conf >/dev/null
371             then        ifconfig -h 10.0.0.1
372             else
373                     if [ X`/bin/sysenv lwip` = Xyes ]
374                     then
375                         dhcpd --lwip &
376                         echo -n " dhcpd"
377                     else
378                         daemonize dhcpd
379                     fi
380             fi
381             daemonize nonamed -L
382             if [ -f "$DAEMONS" ]
383             then        . "$DAEMONS"
384             fi
385             # The last daemon has been started, so close the list:
386             echo .
387         fi
388     fi
390     if [ "$net" ]
391     then
392         # Get the nodename from the DNS and set it.
393         trap '' 2
394         intr -t 20 hostaddr -h
395         trap 2
396     fi
398     # Recover files being edited when the system crashed.
399     test -f /usr/bin/elvprsv && elvprsv /usr/tmp/elv*
401     # Run the daily cleanup on systems that are not on at night.
402     test -f /usr/etc/daily && sh /usr/etc/daily boot &
404 stop|down)
405         # Save random data, if /usr is mounted rw.
406         if grep ' \/usr .*rw.*' /etc/mtab >/dev/null
407         then
408           if dd if=/dev/random of=$RANDOM_FILE.new bs=1024 count=1 2>/dev/null
409           then
410                 mv $RANDOM_FILE.new $RANDOM_FILE
411           else
412                 echo 'Failed to save random data.'
413           fi
414         fi
415 esac
418 # Let packages run their own scripts
419 for d in /usr/local/etc/rc.d /usr/pkg/etc/rc.d
421 if [ -d "$d" -a -z "$bootcd" ]
422 then    ( if cd $d
423         then
424                 echo -n "Local packages ($action): "
425                 for f in *
426                 do
427                         if [ -x "$f" ]
428                         then    echo -n "$f "
429                                 sh "$f" "$action"
430                         fi
431                 done
432                 echo " done."
433         fi
434         )
436 done