xref: /minix3/etc/usr/rc (revision 60299d873c4b49985abe58ba4eb1807d1e6152e5)
1b684a8edSBen Gras# /usr/etc/rc - continued system initialization.
2b684a8edSBen Gras
361a4e15bSJorrit HerderRANDOM_FILE=/usr/adm/random.dat
4*60299d87SDavid van MoolenbroekTCPISN_FILE=/usr/adm/tcpisn.dat
5e21c135fSBen GrasLOCAL_FILE=/usr/etc/rc.local
661a4e15bSJorrit Herder
75acaa081SBen GrasARCH="`sysenv arch`"
85acaa081SBen Gras
95acaa081SBen Grasif [ ! "$ARCH" ]
105acaa081SBen Grasthen    # Older kernels do not provide an arch sysenv variable.
115acaa081SBen Gras        # We assume we are on x86 then, as existing systems with
125acaa081SBen Gras        # kernel and userland (i.e. this script) unsynchronized
135acaa081SBen Gras        # will be x86.
145acaa081SBen Gras        ARCH=i386
155acaa081SBen Grasfi
165acaa081SBen Gras
17349a1580SBen Gras# Get $SERVICES_DIRS
18349a1580SBen Gras. /etc/rc.conf
19349a1580SBen Gras
20349a1580SBen Gras# Directories to find services in
21349a1580SBen Grasif [ ! "$SERVICES_DIRS" ]
22e60f57aaSDavid van Moolenbroekthen	SERVICES_DIRS=/service
23349a1580SBen Grasfi
24349a1580SBen Gras
25a03f679eSBen Gras# Booting from cd?
26a03f679eSBen Grasbootcd="`/bin/sysenv bootcd`"
27a03f679eSBen Gras
28b684a8edSBen Grascase "$#:$1" in
29325ce30bSDavid van Moolenbroek1:start|1:stop)
30b684a8edSBen Gras    action=$1
31b684a8edSBen Gras    ;;
32325ce30bSDavid van Moolenbroek*)  echo >&2 "Usage: $0 [start|stop]"
33b684a8edSBen Gras    exit 1
34b684a8edSBen Grasesac
35b684a8edSBen Gras
36e21c135fSBen Grasif [ -f "$LOCAL_FILE" ]
37e21c135fSBen Grasthen	. "$LOCAL_FILE" $1
38e21c135fSBen Grasfi
39e21c135fSBen Gras
4040e9875fSJorrit Herderdisabled()
4140e9875fSJorrit Herder{
4240e9875fSJorrit Herder    ifs="$IFS"; IFS=,
438cb902dcSJorrit Herder    for skip in `sysenv disable`
4440e9875fSJorrit Herder    do
458cb902dcSJorrit Herder        if [ "$skip" = "$1" ]
4640e9875fSJorrit Herder	then
4740e9875fSJorrit Herder                IFS="$ifs"; unset ifs
4840e9875fSJorrit Herder		return 0
4940e9875fSJorrit Herder	fi
5040e9875fSJorrit Herder    done
5140e9875fSJorrit Herder    IFS="$ifs"; unset ifs
5240e9875fSJorrit Herder    return 1
5340e9875fSJorrit Herder}
5440e9875fSJorrit Herder
55b684a8edSBen Grasdaemonize()
56b684a8edSBen Gras{
57b684a8edSBen Gras    # Function to start a daemon, if it exists.
58b684a8edSBen Gras    local IFS=':'
59b684a8edSBen Gras    local name="$1"
60b684a8edSBen Gras
61b684a8edSBen Gras    for dir in $PATH
62b684a8edSBen Gras    do
63b684a8edSBen Gras	if [ -f "$dir/$1" ]
64b684a8edSBen Gras	then
6540e9875fSJorrit Herder
6640e9875fSJorrit Herder            # check if this service is disabled at the boot monitor.
6740e9875fSJorrit Herder            if disabled $name; then return; fi
6840e9875fSJorrit Herder
69b684a8edSBen Gras	    echo -n " $name"
70b684a8edSBen Gras	    "$@" &
71b684a8edSBen Gras	    return
72b684a8edSBen Gras	fi
73b684a8edSBen Gras    done
74b684a8edSBen Gras}
75b684a8edSBen Gras
7661a4e15bSJorrit Herderup()
7761a4e15bSJorrit Herder{
783de6a807SCristiano Giuffrida    # Function to dynamically start a system service
793de6a807SCristiano Giuffrida    opt=""
803de6a807SCristiano Giuffrida    prefix=$(expr "$1 " : '\(-\)')
813de6a807SCristiano Giuffrida    if [ "$prefix" = "-" ];
823de6a807SCristiano Giuffrida    then
8365ef5397SCristiano Giuffrida         opt=$1
8465ef5397SCristiano Giuffrida         shift
853de6a807SCristiano Giuffrida    fi
8661a4e15bSJorrit Herder    service=$1
872aac756eSJorrit Herder    shift
8861a4e15bSJorrit Herder
8961a4e15bSJorrit Herder    # First check if this service is disabled at the boot monitor.
9040e9875fSJorrit Herder    if disabled $service; then return; fi
9161a4e15bSJorrit Herder
9261a4e15bSJorrit Herder    # Service is not disabled. Try to bring it up.
93349a1580SBen Gras    found=""
94349a1580SBen Gras    for dir in $SERVICES_DIRS
95349a1580SBen Gras    do	bin=$dir/$service
96349a1580SBen Gras	if [ -x $bin -a -z "$found" ]
97c58da9fbSDavid van Moolenbroek	then	minix-service $opt up $bin "$@"
9861a4e15bSJorrit Herder    		echo -n " $service"
99349a1580SBen Gras		found=yes
100349a1580SBen Gras	fi
101349a1580SBen Gras    done
102349a1580SBen Gras    if [ -z "$found" ]
103349a1580SBen Gras    then	echo " ($service not found in $SERVICES_DIRS)"
104349a1580SBen Gras    fi
10561a4e15bSJorrit Herder}
106f8c380c1SPhilip Homburg
107e4dbab1eSDavid van Moolenbroek# Print a list of labels of detected PCI ethernet hardware devices.
108e4dbab1eSDavid van Moolenbroekget_pci_eth_labels()
109e4dbab1eSDavid van Moolenbroek{
110e4dbab1eSDavid van Moolenbroek	# We need to match all PCI ethernet hardware devices against all
111e4dbab1eSDavid van Moolenbroek	# drivers.  For performance reasons, we construct a lookup table on the
112e4dbab1eSDavid van Moolenbroek	# fly here.  In order to do that, we need to give both a list of all
113e4dbab1eSDavid van Moolenbroek	# available network drivers with PCI device IDs (part 1 of the code
114e4dbab1eSDavid van Moolenbroek	# below) and a list of all actually present ethernet hardware devices
115e4dbab1eSDavid van Moolenbroek	# (part 2) to an awk script (part 3).  The awk script can tell the
116e4dbab1eSDavid van Moolenbroek	# difference between the list entries based on whether there is a
117e4dbab1eSDavid van Moolenbroek	# leading space on the line.  For part 2, we grab only devices that are
118e4dbab1eSDavid van Moolenbroek	# in PCI class 2 (network controller) subclass 0 (ethernet controller).
119e4dbab1eSDavid van Moolenbroek
120e4dbab1eSDavid van Moolenbroek	# Part 1: collect all network drivers with supported PCI IDs
121e4dbab1eSDavid van Moolenbroek	(for dir in $SYSTEM_CONF_DIRS; do
122e4dbab1eSDavid van Moolenbroek		for f in $dir/$SYSTEM_CONF_SUBDIR/*; do
123e4dbab1eSDavid van Moolenbroek			if [ -f $f ]; then
124e4dbab1eSDavid van Moolenbroek				printconfig $f | grep ',type net.*,pci device'
125e4dbab1eSDavid van Moolenbroek			fi
126e4dbab1eSDavid van Moolenbroek		done
127e4dbab1eSDavid van Moolenbroek	done | sed 's/^service \([^,]*\),.*,pci device/ \1/g';
128e4dbab1eSDavid van Moolenbroek	# Part 2: grab all PCI IDs of ethernet hardware devices (class 2/0)
129e4dbab1eSDavid van Moolenbroek	cat /proc/pci | grep '^[^ ]* 2/0/' | cut -d' ' -f3) | awk '
130e4dbab1eSDavid van Moolenbroek	# Part 3: first construct a PCI-ID-to-driver table based on the lines
131e4dbab1eSDavid van Moolenbroek	# produced by part 1 (with leading space), which each contain one
132e4dbab1eSDavid van Moolenbroek	# driver name followed by one or more PCI IDs; then, go through all
133e4dbab1eSDavid van Moolenbroek	# the ethernet hardware devices found in part 2 (no leading space) and
134e4dbab1eSDavid van Moolenbroek	# if if there is a hit in the table, print the driver label to use.
135e4dbab1eSDavid van Moolenbroek	/^ / { for (i=2;i<=NF;i++) drivers[$(i)]=$1 }
136e4dbab1eSDavid van Moolenbroek	/^[^ ]/ {
137e4dbab1eSDavid van Moolenbroek		# There is a bit of a discrepancy between output formats of
138e4dbab1eSDavid van Moolenbroek		# /proc/pci and printconfig: the former uses
139e4dbab1eSDavid van Moolenbroek		# "vid:did:sub_vid:sub_did" whereas the latter uses
140e4dbab1eSDavid van Moolenbroek		# "vid:did/sub_vid:sub_did".  No problem; in the common case
141e4dbab1eSDavid van Moolenbroek		# (= no sub IDs used) we need to split the PCI ID anyway.
142e4dbab1eSDavid van Moolenbroek		if (split($1,id,":") >= 4) {
143e4dbab1eSDavid van Moolenbroek			# Try a full "vid:did:sub_vid:sub_did" match.
144e4dbab1eSDavid van Moolenbroek			name=drivers[id[1]":"id[2]"/"id[3]":"id[4]]
145e4dbab1eSDavid van Moolenbroek		}
146e4dbab1eSDavid van Moolenbroek		# No sub IDs or no match found?  Try a "vid:did" match.
147e4dbab1eSDavid van Moolenbroek		if (!name) name=drivers[id[1]":"id[2]]
148e4dbab1eSDavid van Moolenbroek		# If found, print the resulting label (<name>_<instance>)
149e4dbab1eSDavid van Moolenbroek		if (name) {
150e4dbab1eSDavid van Moolenbroek			print name"_"(instance[name]+0)
151e4dbab1eSDavid van Moolenbroek			instance[name]++
152e4dbab1eSDavid van Moolenbroek		}
153e4dbab1eSDavid van Moolenbroek	}
154e4dbab1eSDavid van Moolenbroek	'
155e4dbab1eSDavid van Moolenbroek}
156e4dbab1eSDavid van Moolenbroek
157e4dbab1eSDavid van Moolenbroek# Print a list of labels of ethernet hardware devices that have been detected
158e4dbab1eSDavid van Moolenbroek# to be present on the system.  Each label has the format '<driver>_<instance>'
159e4dbab1eSDavid van Moolenbroek# where <driver> is the file name of the driver (in /service) and <instance> is
160e4dbab1eSDavid van Moolenbroek# a zero-based, per-driver instance number of the device.
1619ba65d2eSDavid van Moolenbroekget_eth_labels() {
162e4dbab1eSDavid van Moolenbroek	# For now, do autodetection only on platforms with (x86) PCI support.
163e4dbab1eSDavid van Moolenbroek	# For (x86) ISA drivers, a custom network setting script is required;
164e4dbab1eSDavid van Moolenbroek	# see below.  For ARM platforms, the driver (if any) is started based
165e4dbab1eSDavid van Moolenbroek	# on the board; there is no device autodetection.
166e4dbab1eSDavid van Moolenbroek	if [ -f /proc/pci ]; then
167e4dbab1eSDavid van Moolenbroek		get_pci_eth_labels
168e4dbab1eSDavid van Moolenbroek	fi
169e4dbab1eSDavid van Moolenbroek
170e4dbab1eSDavid van Moolenbroek	# Add any network drivers manually configured in /usr/etc/rc.local by
171e4dbab1eSDavid van Moolenbroek	# the netconf(8) utility.
172e4dbab1eSDavid van Moolenbroek	if [ -n "$netdriver" ]; then
173e4dbab1eSDavid van Moolenbroek		echo "${netdriver}_0"
174e4dbab1eSDavid van Moolenbroek	fi
1759ba65d2eSDavid van Moolenbroek}
176103f18cbSBen Gras
177e7855d00SThomas Cort# Detect expansion boards on the BeagleBone and load the proper drivers.
178e7855d00SThomas Cortcapemgr() {
179e7855d00SThomas Cort
180e7855d00SThomas Cort    # Probe each possible cape EEPROM slave address for a BeagleBone cape.
181e7855d00SThomas Cort    for slave_addr in 54 55 56 57
182e7855d00SThomas Cort    do
183e7855d00SThomas Cort
184e7855d00SThomas Cort        # See if there is a readable EEPROM with address ${slave_addr}.
185e7855d00SThomas Cort        eepromread -f /dev/i2c-3 -a 0x${slave_addr} > /dev/null 2>&1
186e7855d00SThomas Cort        RESULT=$?
187e7855d00SThomas Cort	if [ $RESULT -eq 0 ]
188e7855d00SThomas Cort	then
189e7855d00SThomas Cort
190e7855d00SThomas Cort	    # Found an alive EEPROM. Try reading the cape name.
191e7855d00SThomas Cort            CAPE=`eepromread -i -f /dev/i2c-3 -a 0x${slave_addr} | \
192e7855d00SThomas Cort	        sed -n 's/^PART_NUMBER     : \(.*\)$/\1/p' | \
193e7855d00SThomas Cort		sed -e 's/\.*$//g'` # Strip trailing periods.
194e7855d00SThomas Cort
195e7855d00SThomas Cort	    # Look for a cape specific RC script.
196e7855d00SThomas Cort            if [ -x /etc/rc.capes/${CAPE} ]
197e7855d00SThomas Cort	    then
198e7855d00SThomas Cort
199e7855d00SThomas Cort	        # CAT24C256 EEPROM -- all capes have this chip.
200e7855d00SThomas Cort		test -e /dev/eepromb3s${slave_addr} || \
201e7855d00SThomas Cort		    (cd /dev && MAKEDEV eepromb3s${slave_addr})
202e7855d00SThomas Cort		up cat24c256 -dev /dev/eepromb3s${slave_addr} \
203e7855d00SThomas Cort		    -label cat24c256.3.${slave_addr} \
204e7855d00SThomas Cort		    -args "bus=3 address=0x${slave_addr}"
205e7855d00SThomas Cort
206e7855d00SThomas Cort                # Load the drivers for the cape and do any other configuration.
207e7855d00SThomas Cort		. "/etc/rc.capes/${CAPE}"
208e7855d00SThomas Cort
209e7855d00SThomas Cort	    else
210e7855d00SThomas Cort
211e7855d00SThomas Cort		echo ""
212e7855d00SThomas Cort	        echo "** UNSUPPORTED CAPE: ${CAPE}"
213e7855d00SThomas Cort		echo ""
214e7855d00SThomas Cort
215e7855d00SThomas Cort	    fi
216e7855d00SThomas Cort	fi
217e7855d00SThomas Cort    done
218e7855d00SThomas Cort}
219e7855d00SThomas Cort
220b684a8edSBen Grascase $action in
221325ce30bSDavid van Moolenbroekstart)
222b684a8edSBen Gras    # Select console font.
223b684a8edSBen Gras    test -f /etc/font && loadfont /etc/font </dev/console
224b684a8edSBen Gras
225b684a8edSBen Gras    # Cleanup.
226e257c999SThomas Veerman    rm -rf /tmp/* /usr/run/* /usr/spool/lpd/* /usr/spool/locks/*
227b684a8edSBen Gras
228e5610815SJorrit Herder    # Start servers and drivers set at the boot monitor.
2293cb00065SJorrit Herder    echo -n "Starting services:"
2306331e8f8SDavid van Moolenbroek    up -n random -dev /dev/random -period 3HZ
231c12b74daSPhilip Homburg
232f8c380c1SPhilip Homburg    # load random number generator
233f8c380c1SPhilip Homburg    if [ -f $RANDOM_FILE ]
234f8c380c1SPhilip Homburg    then
235f8c380c1SPhilip Homburg    	cat < $RANDOM_FILE >/dev/random
236f8c380c1SPhilip Homburg    	# overwrite $RANDOM_FILE. We don't want to use this data again
2370bd61375SJorrit Herder    	dd if=/dev/random of=$RANDOM_FILE bs=1024 count=1 2> /dev/null
23869eead77SJean-Baptiste Boric    else
23969eead77SJean-Baptiste Boric	# We couldn't find the old state to restart from, so use a binary
24069eead77SJean-Baptiste Boric	# file and the current date instead, even if this is less than ideal.
24169eead77SJean-Baptiste Boric	cat /bin/sh >> /dev/urandom
24269eead77SJean-Baptiste Boric	date >> /dev/urandom
243f8c380c1SPhilip Homburg    fi
244f8c380c1SPhilip Homburg
245e4dbab1eSDavid van Moolenbroek    # start network driver instances for all detected ethernet devices
2469ba65d2eSDavid van Moolenbroek    for label in $(get_eth_labels); do
2479ba65d2eSDavid van Moolenbroek        driver=$(echo $label | sed 's/\(.*\)_.*/\1/')
2489ba65d2eSDavid van Moolenbroek        instance=$(echo $label | sed 's/.*_//')
249cb796b75SDavid van Moolenbroek        eval arg=\$${driver}_arg
2509ba65d2eSDavid van Moolenbroek        if [ ! -z "$arg" ]; then arg=" $arg"; fi
2519ba65d2eSDavid van Moolenbroek        arg="-args \"instance=$instance$arg\""
2529ba65d2eSDavid van Moolenbroek        eval up $driver -label $label $arg -period 5HZ
253e5610815SJorrit Herder    done
2543ea34559SDavid van Moolenbroek
255da21d850SDavid van Moolenbroek    # pty needs to know the "tty" group ID
256da21d850SDavid van Moolenbroek    up pty -dev /dev/ptmx -args "gid=`stat -f '%g' /dev/ptmx`"
257760f3d62SDavid van Moolenbroek
258*60299d87SDavid van Moolenbroek    # Start the LWIP service.
259*60299d87SDavid van Moolenbroek    up lwip -dev /dev/bpf -script /etc/rs.lwip
260*60299d87SDavid van Moolenbroek
261*60299d87SDavid van Moolenbroek    # Load stable seed for TCP Initial Sequence Number generation (RFC 6528).
262*60299d87SDavid van Moolenbroek    # The idea here is that (especially) after a system crash, the seed stays
263*60299d87SDavid van Moolenbroek    # the same, so as to make it unlikely that incoming packets for connections
264*60299d87SDavid van Moolenbroek    # from before the crash are accepted on connections after the crash.
265*60299d87SDavid van Moolenbroek    TCPISN_LEN=$(sysctl -n net.inet.tcp.isn_secret | awk '{print length/2}')
266*60299d87SDavid van Moolenbroek    if [ ! -f $TCPISN_FILE ]; then
267*60299d87SDavid van Moolenbroek	# If the /usr file system is read-only, we cannot create the file.  In
268*60299d87SDavid van Moolenbroek	# that case, we draw a temporary secret from the random service.
269*60299d87SDavid van Moolenbroek	if grep ' \/usr .*rw.*' /etc/mtab >/dev/null; then
270*60299d87SDavid van Moolenbroek	    dd if=/dev/random of=$TCPISN_FILE bs=$TCPISN_LEN count=1 2>/dev/null
271*60299d87SDavid van Moolenbroek	else
272*60299d87SDavid van Moolenbroek	    TCPISN_FILE=/dev/random
273*60299d87SDavid van Moolenbroek	fi
274*60299d87SDavid van Moolenbroek    fi
275*60299d87SDavid van Moolenbroek    sysctl -qw net.inet.tcp.isn_secret=`dd if=$TCPISN_FILE bs=$TCPISN_LEN \
276*60299d87SDavid van Moolenbroek	count=1 2>/dev/null | hexdump -v -e '/1 "%02x"'` 2>/dev/null
277*60299d87SDavid van Moolenbroek
278*60299d87SDavid van Moolenbroek    # LWIP does not block until all network drivers have fully initialized and
279*60299d87SDavid van Moolenbroek    # reported back to LWIP.  That may prevent proper configuration of the
280*60299d87SDavid van Moolenbroek    # corresponding interfaces a bit later.  Sleep up to five seconds waiting
281*60299d87SDavid van Moolenbroek    # for all registered network drivers to initialize and report to LWIP.
282*60299d87SDavid van Moolenbroek    for i in 1 2 3 4 5; do
283*60299d87SDavid van Moolenbroek	[ $(sysctl -n minix.lwip.drivers.pending) -gt 0 ] && sleep 1
284*60299d87SDavid van Moolenbroek    done
285*60299d87SDavid van Moolenbroek
28627852ebeSDavid van Moolenbroek    up uds
287b003ed09SDavid van Moolenbroek
2883de6a807SCristiano Giuffrida    up -n ipc
2895acaa081SBen Gras
29036ac0dbcSDavid van Moolenbroek    up log -dev /dev/klog
29136ac0dbcSDavid van Moolenbroek
2925acaa081SBen Gras    if [ $ARCH = i386 ]
2935acaa081SBen Gras    then
2945acaa081SBen Gras	up -n printer -dev /dev/lp -period 10HZ
2950aa01a2dSDavid van Moolenbroek	# start VirtualBox time sync driver if the device is there
2969e77ef50SLionel Sambuc	if grep '^[^ ]* [^ ]* 80EE:CAFE[^ ]* ' /proc/pci >/dev/null; then
2970aa01a2dSDavid van Moolenbroek		up -n vbox -period 10HZ
2980aa01a2dSDavid van Moolenbroek	fi
2995acaa081SBen Gras    fi
3005acaa081SBen Gras
30161a4e15bSJorrit Herder    echo .
302b684a8edSBen Gras
303b684a8edSBen Gras    echo -n "Starting daemons:"
304b684a8edSBen Gras    daemonize update
3059748a653SBen Gras
3069748a653SBen Gras    # Ugly error message when starting cron from CD.
3079748a653SBen Gras    # (and cron unnecessary then so..)
3089748a653SBen Gras    if [ ! -f /CD ]
309ea398f99SBen Gras    then	daemonize cron
3103775ce2eSBen Gras    else	mkdir /tmp/log
311ea398f99SBen Gras    		rm -f /var/log || true
3123775ce2eSBen Gras		ln -s /tmp/log /var/log || true
3133775ce2eSBen Gras		. /etc/rc.cd
3149748a653SBen Gras    fi
315325ce30bSDavid van Moolenbroek
3160bd61375SJorrit Herder    echo .
317b684a8edSBen Gras
318550fdfb4SThomas Cort    # i2c only supported on ARM at the moment
319550fdfb4SThomas Cort    if [ $ARCH = earm ]
320550fdfb4SThomas Cort    then
321550fdfb4SThomas Cort	echo -n "Starting i2c subsystem: "
322550fdfb4SThomas Cort	for bus in 1 2 3
323550fdfb4SThomas Cort	do
324550fdfb4SThomas Cort		test -e /dev/i2c-${bus} || (cd /dev && MAKEDEV i2c-${bus})
325550fdfb4SThomas Cort		up i2c -dev /dev/i2c-${bus} -label i2c.${bus} \
326550fdfb4SThomas Cort			-args instance=${bus}
327550fdfb4SThomas Cort	done
328550fdfb4SThomas Cort	echo .
329fdbede5dSThomas Cort
330df28b6a5SKees Jongenburger	BOARD_NAME=`sysenv board`
331fdbede5dSThomas Cort	case "${BOARD_NAME}" in
33226f14d6bSThomas Cort
333df28b6a5SKees Jongenburger		ARM-ARMV7-TI-BB-WHITE)
334df28b6a5SKees Jongenburger			echo "Running on a BeagleBone"
335fdbede5dSThomas Cort			echo -n "Starting i2c device drivers: "
33626f14d6bSThomas Cort
33726f14d6bSThomas Cort			# start EEPROM driver for reading board info
33826f14d6bSThomas Cort			test -e /dev/eepromb1s50 || \
33926f14d6bSThomas Cort				(cd /dev && MAKEDEV eepromb1s50)
340fdbede5dSThomas Cort			up cat24c256 -dev /dev/eepromb1s50 \
341d9b62047SThomas Cort				-label cat24c256.1.50 \
342d9b62047SThomas Cort				-args 'bus=1 address=0x50'
343d9b62047SThomas Cort
344d9b62047SThomas Cort			# Start TPS65217 driver for power management.
345d9b62047SThomas Cort			up tps65217 -label tps65217.1.24 \
346d9b62047SThomas Cort			        -args 'bus=1 address=0x24'
347d9b62047SThomas Cort
348e4dbab1eSDavid van Moolenbroek			# Start ethernet driver.
349e4dbab1eSDavid van Moolenbroek			up lan8710a -label lan8710a_0 -args 'instance=0'
350e4dbab1eSDavid van Moolenbroek
35126f14d6bSThomas Cort			# check for the presence of a display
35226f14d6bSThomas Cort			eepromread -f /dev/i2c-2 -n > /dev/null 2>&1
35326f14d6bSThomas Cort			RESULT=$?
35426f14d6bSThomas Cort			if [ $RESULT -eq 0 ]
35526f14d6bSThomas Cort			then
35626f14d6bSThomas Cort				# start eeprom driver for reading EDID.
35726f14d6bSThomas Cort				test -e /dev/eepromb2s50 || \
35826f14d6bSThomas Cort					(cd /dev && MAKEDEV eepromb2s50)
35926f14d6bSThomas Cort				up cat24c256 -dev /dev/eepromb2s50 \
36026f14d6bSThomas Cort					-label cat24c256.2.50 \
36126f14d6bSThomas Cort					-args 'bus=2 address=0x50'
36226f14d6bSThomas Cort
36326f14d6bSThomas Cort				# start frame buffer
36426f14d6bSThomas Cort				#up fb -dev /dev/fb0 -args edid.0=cat24c256.2.50
36526f14d6bSThomas Cort				# fb hasn't been ported to AM335X yet.
36626f14d6bSThomas Cort			fi
36726f14d6bSThomas Cort
3688edaaa30SLionel Sambuc			if [ -e /service/usbd ]
369489a81f5SKees Jongenburger			then
370489a81f5SKees Jongenburger				echo "Starting USBD"
371489a81f5SKees Jongenburger				up usbd
372489a81f5SKees Jongenburger			fi
373e7855d00SThomas Cort			# Detect expansion boards and start drivers.
374e7855d00SThomas Cort			capemgr
375e7855d00SThomas Cort
376fdbede5dSThomas Cort			;;
37726f14d6bSThomas Cort
378df28b6a5SKees Jongenburger		ARM-ARMV7-TI-BB-BLACK)
379df28b6a5SKees Jongenburger			echo "Running on a BeagleBone Black"
380fdbede5dSThomas Cort			echo -n "Starting i2c device drivers: "
38126f14d6bSThomas Cort
38226f14d6bSThomas Cort			# start EEPROM driver for reading board info
38326f14d6bSThomas Cort			test -e /dev/eepromb1s50 || \
38426f14d6bSThomas Cort				(cd /dev && MAKEDEV eepromb1s50)
385fdbede5dSThomas Cort			up cat24c256 -dev /dev/eepromb1s50 \
38626f14d6bSThomas Cort				-label cat24c256.1.50 \
38726f14d6bSThomas Cort				-args 'bus=1 address=0x50'
3881b78e86fSThomas Cort
389d9b62047SThomas Cort			# Start TPS65217 driver for power management.
390d9b62047SThomas Cort			up tps65217 -label tps65217.1.24 \
391d9b62047SThomas Cort			        -args 'bus=1 address=0x24'
392d9b62047SThomas Cort
393d9b62047SThomas Cort			# Start TDA19988 driver for reading EDID.
3941b78e86fSThomas Cort			up tda19988 -label tda19988.1.3470 -args \
3951b78e86fSThomas Cort				'cec_bus=1 cec_address=0x34 hdmi_bus=1 hdmi_address=0x70'
39626f14d6bSThomas Cort
397e4dbab1eSDavid van Moolenbroek			# Start ethernet driver.
398e4dbab1eSDavid van Moolenbroek			up lan8710a -label lan8710a_0 -args 'instance=0'
399e4dbab1eSDavid van Moolenbroek
40026f14d6bSThomas Cort			# start frame buffer
40126f14d6bSThomas Cort			#up fb -dev /dev/fb0 -args edid.0=tda19988.1.3470
40226f14d6bSThomas Cort			# fb hasn't been ported to AM335X yet.
40326f14d6bSThomas Cort
4048edaaa30SLionel Sambuc			if [ -e /service/usbd ]
405489a81f5SKees Jongenburger			then
406489a81f5SKees Jongenburger				echo "Starting USBD"
407489a81f5SKees Jongenburger				up usbd
408489a81f5SKees Jongenburger			fi
409e7855d00SThomas Cort			# Detect expansion boards and start drivers.
410e7855d00SThomas Cort			capemgr
411e7855d00SThomas Cort
412fdbede5dSThomas Cort			;;
41326f14d6bSThomas Cort
414df28b6a5SKees Jongenburger		ARM-ARMV7-TI-BBXM-GENERIC)
415df28b6a5SKees Jongenburger			echo "Running on a BeagleBoard-xM"
416fdbede5dSThomas Cort			echo -n "Starting i2c device drivers: "
417bab2a34eSThomas Cort
418bab2a34eSThomas Cort			# Start TPS65950 driver for power management.
419bab2a34eSThomas Cort			up tps65950 -label tps65950.1.48 \
420bab2a34eSThomas Cort				-args 'bus=1 address=0x48'
421bab2a34eSThomas Cort
422039c8db7SThomas Cort			# Set the system time to the time in the TPS65950's RTC
423039c8db7SThomas Cort			readclock
424039c8db7SThomas Cort
42526f14d6bSThomas Cort			# check for the presence of a display
42626f14d6bSThomas Cort			eepromread -f /dev/i2c-3 -n > /dev/null 2>&1
42726f14d6bSThomas Cort			RESULT=$?
42826f14d6bSThomas Cort			if [ $RESULT -eq 0 ]
42926f14d6bSThomas Cort			then
43026f14d6bSThomas Cort				# start eeprom driver for reading edid
43126f14d6bSThomas Cort				test -e /dev/eepromb3s50 || \
43226f14d6bSThomas Cort					(cd /dev && MAKEDEV eepromb3s50)
43326f14d6bSThomas Cort				up cat24c256 -dev /dev/eepromb3s50 \
43426f14d6bSThomas Cort					-label cat24c256.3.50 \
43526f14d6bSThomas Cort					-args 'bus=3 address=0x50'
43626f14d6bSThomas Cort
43726f14d6bSThomas Cort				# start frame buffer
43826f14d6bSThomas Cort				up fb -dev /dev/fb0 -args edid.0=cat24c256.3.50
43926f14d6bSThomas Cort			fi
44026f14d6bSThomas Cort
441fdbede5dSThomas Cort			;;
442fdbede5dSThomas Cort	esac
443fdbede5dSThomas Cort
444fdbede5dSThomas Cort	echo .
445550fdfb4SThomas Cort    fi
446550fdfb4SThomas Cort
447d2532d3dSDavid van Moolenbroek    # Load the stored hostname into the sysctl database.
448d2532d3dSDavid van Moolenbroek    test -r /etc/hostname.file && hostname $(cat /etc/hostname.file)
449d2532d3dSDavid van Moolenbroek
450b684a8edSBen Gras    # Recover files being edited when the system crashed.
451b684a8edSBen Gras    test -f /usr/bin/elvprsv && elvprsv /usr/tmp/elv*
452b684a8edSBen Gras
453b684a8edSBen Gras    # Run the daily cleanup on systems that are not on at night.
454b684a8edSBen Gras    test -f /usr/etc/daily && sh /usr/etc/daily boot &
455f8c380c1SPhilip Homburg;;
456325ce30bSDavid van Moolenbroekstop)
457093cfe11SBen Gras    	# Save random data, if /usr is mounted rw.
458d9f4f719SThomas Veerman	if grep ' \/usr .*rw.*' /etc/mtab >/dev/null
459093cfe11SBen Gras	then
460f8c380c1SPhilip Homburg	  if dd if=/dev/random of=$RANDOM_FILE.new bs=1024 count=1 2>/dev/null
461f8c380c1SPhilip Homburg    	  then
462f8c380c1SPhilip Homburg    		mv $RANDOM_FILE.new $RANDOM_FILE
463f8c380c1SPhilip Homburg	  else
464f8c380c1SPhilip Homburg		echo 'Failed to save random data.'
465f8c380c1SPhilip Homburg	  fi
466428f9d63SBen Gras	fi
467b684a8edSBen Grasesac
468