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