xref: /minix/etc/usr/rc (revision c5da0dff)
1# /usr/etc/rc - continued system initialization.
2
3RANDOM_FILE=/usr/adm/random.dat
4LOCAL_FILE=/usr/etc/rc.local
5
6ARCH="`sysenv arch`"
7
8if [ ! "$ARCH" ]
9then    # 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
14fi
15
16# Get $SERVICES_DIRS
17. /etc/rc.conf
18
19# Directories to find services in
20if [ ! "$SERVICES_DIRS" ]
21then	SERVICES_DIRS=/service
22fi
23
24# Booting from cd?
25bootcd="`/bin/sysenv bootcd`"
26
27case "$#:$1" in
281:start|1:stop)
29    action=$1
30    ;;
31*)  echo >&2 "Usage: $0 [start|stop]"
32    exit 1
33esac
34
35if [ -f "$LOCAL_FILE" ]
36then	. "$LOCAL_FILE" $1
37fi
38
39disabled()
40{
41    ifs="$IFS"; IFS=,
42    for skip in `sysenv disable`
43    do
44        if [ "$skip" = "$1" ]
45	then
46                IFS="$ifs"; unset ifs
47		return 0
48	fi
49    done
50    IFS="$ifs"; unset ifs
51    return 1
52}
53
54daemonize()
55{
56    # Function to start a daemon, if it exists.
57    local IFS=':'
58    local name="$1"
59    test "$1" = tcpd && name="$2"
60
61    for dir in $PATH
62    do
63	if [ -f "$dir/$1" ]
64	then
65
66            # check if this service is disabled at the boot monitor.
67            if disabled $name; then return; fi
68
69	    echo -n " $name"
70	    "$@" &
71	    return
72	fi
73    done
74}
75
76up()
77{
78    # Function to dynamically start a system service
79    opt=""
80    prefix=$(expr "$1 " : '\(-\)')
81    if [ "$prefix" = "-" ];
82    then
83         opt=$1
84         shift
85    fi
86    service=$1
87    shift
88
89    # First check if this service is disabled at the boot monitor.
90    if disabled $service; then return; fi
91
92    # Service is not disabled. Try to bring it up.
93    found=""
94    for dir in $SERVICES_DIRS
95    do	bin=$dir/$service
96	if [ -x $bin -a -z "$found" ]
97	then	minix-service $opt up $bin "$@"
98    		echo -n " $service"
99		found=yes
100	fi
101    done
102    if [ -z "$found" ]
103    then	echo " ($service not found in $SERVICES_DIRS)"
104    fi
105}
106
107get_eth_labels() {
108    # Nothing yet.
109}
110
111# Detect expansion boards on the BeagleBone and load the proper drivers.
112capemgr() {
113
114    # Probe each possible cape EEPROM slave address for a BeagleBone cape.
115    for slave_addr in 54 55 56 57
116    do
117
118        # See if there is a readable EEPROM with address ${slave_addr}.
119        eepromread -f /dev/i2c-3 -a 0x${slave_addr} > /dev/null 2>&1
120        RESULT=$?
121	if [ $RESULT -eq 0 ]
122	then
123
124	    # Found an alive EEPROM. Try reading the cape name.
125            CAPE=`eepromread -i -f /dev/i2c-3 -a 0x${slave_addr} | \
126	        sed -n 's/^PART_NUMBER     : \(.*\)$/\1/p' | \
127		sed -e 's/\.*$//g'` # Strip trailing periods.
128
129	    # Look for a cape specific RC script.
130            if [ -x /etc/rc.capes/${CAPE} ]
131	    then
132
133	        # CAT24C256 EEPROM -- all capes have this chip.
134		test -e /dev/eepromb3s${slave_addr} || \
135		    (cd /dev && MAKEDEV eepromb3s${slave_addr})
136		up cat24c256 -dev /dev/eepromb3s${slave_addr} \
137		    -label cat24c256.3.${slave_addr} \
138		    -args "bus=3 address=0x${slave_addr}"
139
140                # Load the drivers for the cape and do any other configuration.
141		. "/etc/rc.capes/${CAPE}"
142
143	    else
144
145		echo ""
146	        echo "** UNSUPPORTED CAPE: ${CAPE}"
147		echo ""
148
149	    fi
150	fi
151    done
152}
153
154case $action in
155start)
156    # Select console font.
157    test -f /etc/font && loadfont /etc/font </dev/console
158
159    # Cleanup.
160    rm -rf /tmp/* /usr/run/* /usr/spool/lpd/* /usr/spool/locks/*
161
162    # Start servers and drivers set at the boot monitor.
163    echo -n "Starting services:"
164    up -n random -dev /dev/random -period 3HZ
165
166    # load random number generator
167    if [ -f $RANDOM_FILE ]
168    then
169    	cat < $RANDOM_FILE >/dev/random
170    	# overwrite $RANDOM_FILE. We don't want to use this data again
171    	dd if=/dev/random of=$RANDOM_FILE bs=1024 count=1 2> /dev/null
172    else
173	# We couldn't find the old state to restart from, so use a binary
174	# file and the current date instead, even if this is less than ideal.
175	cat /bin/sh >> /dev/urandom
176	date >> /dev/urandom
177    fi
178
179    # start network driver instances for all configured ethernet devices
180    for label in $(get_eth_labels); do
181        driver=$(echo $label | sed 's/\(.*\)_.*/\1/')
182        instance=$(echo $label | sed 's/.*_//')
183        eval arg=\$${driver}_arg
184        if [ ! -z "$arg" ]; then arg=" $arg"; fi
185        arg="-args \"instance=$instance$arg\""
186        eval up $driver -label $label $arg -period 5HZ
187    done
188
189    # pty needs to know the "tty" group ID
190    up pty -dev /dev/ptmx -args "gid=`stat -f '%g' /dev/ptmx`"
191
192    up uds
193
194    up -n ipc
195
196    up log -dev /dev/klog
197
198    if [ $ARCH = i386 ]
199    then
200	up -n printer -dev /dev/lp -period 10HZ
201	# start VirtualBox time sync driver if the device is there
202	if grep '^[^ ]* [^ ]* 80EE:CAFE[^ ]* ' /proc/pci >/dev/null; then
203		up -n vbox -period 10HZ
204	fi
205    fi
206
207    echo .
208
209    echo -n "Starting daemons:"
210    daemonize update
211
212    # Ugly error message when starting cron from CD.
213    # (and cron unnecessary then so..)
214    if [ ! -f /CD ]
215    then	daemonize cron
216    else	mkdir /tmp/log
217    		rm -f /var/log || true
218		ln -s /tmp/log /var/log || true
219		. /etc/rc.cd
220    fi
221
222    echo .
223
224    # i2c only supported on ARM at the moment
225    if [ $ARCH = earm ]
226    then
227	echo -n "Starting i2c subsystem: "
228	for bus in 1 2 3
229	do
230		test -e /dev/i2c-${bus} || (cd /dev && MAKEDEV i2c-${bus})
231		up i2c -dev /dev/i2c-${bus} -label i2c.${bus} \
232			-args instance=${bus}
233	done
234	echo .
235
236	BOARD_NAME=`sysenv board`
237	case "${BOARD_NAME}" in
238
239		ARM-ARMV7-TI-BB-WHITE)
240			echo "Running on a BeagleBone"
241			echo -n "Starting i2c device drivers: "
242
243			# start EEPROM driver for reading board info
244			test -e /dev/eepromb1s50 || \
245				(cd /dev && MAKEDEV eepromb1s50)
246			up cat24c256 -dev /dev/eepromb1s50 \
247				-label cat24c256.1.50 \
248				-args 'bus=1 address=0x50'
249
250			# Start TPS65217 driver for power management.
251			up tps65217 -label tps65217.1.24 \
252			        -args 'bus=1 address=0x24'
253
254			# check for the presence of a display
255			eepromread -f /dev/i2c-2 -n > /dev/null 2>&1
256			RESULT=$?
257			if [ $RESULT -eq 0 ]
258			then
259				# start eeprom driver for reading EDID.
260				test -e /dev/eepromb2s50 || \
261					(cd /dev && MAKEDEV eepromb2s50)
262				up cat24c256 -dev /dev/eepromb2s50 \
263					-label cat24c256.2.50 \
264					-args 'bus=2 address=0x50'
265
266				# start frame buffer
267				#up fb -dev /dev/fb0 -args edid.0=cat24c256.2.50
268				# fb hasn't been ported to AM335X yet.
269			fi
270
271			if [ -e /service/usbd ]
272			then
273				echo "Starting USBD"
274				up usbd
275			fi
276			# Detect expansion boards and start drivers.
277			capemgr
278
279			;;
280
281		ARM-ARMV7-TI-BB-BLACK)
282			echo "Running on a BeagleBone Black"
283			echo -n "Starting i2c device drivers: "
284
285			# start EEPROM driver for reading board info
286			test -e /dev/eepromb1s50 || \
287				(cd /dev && MAKEDEV eepromb1s50)
288			up cat24c256 -dev /dev/eepromb1s50 \
289				-label cat24c256.1.50 \
290				-args 'bus=1 address=0x50'
291
292			# Start TPS65217 driver for power management.
293			up tps65217 -label tps65217.1.24 \
294			        -args 'bus=1 address=0x24'
295
296			# Start TDA19988 driver for reading EDID.
297			up tda19988 -label tda19988.1.3470 -args \
298				'cec_bus=1 cec_address=0x34 hdmi_bus=1 hdmi_address=0x70'
299
300			# start frame buffer
301			#up fb -dev /dev/fb0 -args edid.0=tda19988.1.3470
302			# fb hasn't been ported to AM335X yet.
303
304			if [ -e /service/usbd ]
305			then
306				echo "Starting USBD"
307				up usbd
308			fi
309			# Detect expansion boards and start drivers.
310			capemgr
311
312			;;
313
314		ARM-ARMV7-TI-BBXM-GENERIC)
315			echo "Running on a BeagleBoard-xM"
316			echo -n "Starting i2c device drivers: "
317
318			# Start TPS65950 driver for power management.
319			up tps65950 -label tps65950.1.48 \
320				-args 'bus=1 address=0x48'
321
322			# Set the system time to the time in the TPS65950's RTC
323			readclock
324
325			# check for the presence of a display
326			eepromread -f /dev/i2c-3 -n > /dev/null 2>&1
327			RESULT=$?
328			if [ $RESULT -eq 0 ]
329			then
330				# start eeprom driver for reading edid
331				test -e /dev/eepromb3s50 || \
332					(cd /dev && MAKEDEV eepromb3s50)
333				up cat24c256 -dev /dev/eepromb3s50 \
334					-label cat24c256.3.50 \
335					-args 'bus=3 address=0x50'
336
337				# start frame buffer
338				up fb -dev /dev/fb0 -args edid.0=cat24c256.3.50
339			fi
340
341			;;
342	esac
343
344	echo .
345    fi
346
347    # Load the stored hostname into the sysctl database.
348    test -r /etc/hostname.file && hostname $(cat /etc/hostname.file)
349
350    # Recover files being edited when the system crashed.
351    test -f /usr/bin/elvprsv && elvprsv /usr/tmp/elv*
352
353    # Run the daily cleanup on systems that are not on at night.
354    test -f /usr/etc/daily && sh /usr/etc/daily boot &
355;;
356stop)
357    	# Save random data, if /usr is mounted rw.
358	if grep ' \/usr .*rw.*' /etc/mtab >/dev/null
359	then
360	  if dd if=/dev/random of=$RANDOM_FILE.new bs=1024 count=1 2>/dev/null
361    	  then
362    		mv $RANDOM_FILE.new $RANDOM_FILE
363	  else
364		echo 'Failed to save random data.'
365	  fi
366	fi
367esac
368