1 # /usr/etc/rc - continued system initialization.
3 RANDOM_FILE=/usr/adm/random.dat
4 TCPISN_FILE=/usr/adm/tcpisn.dat
5 LOCAL_FILE=/usr/etc/rc.local
10 then # Older kernels do not provide an arch sysenv variable.
11 # We assume we are on x86 then, as existing systems with
12 # kernel and userland (i.e. this script) unsynchronized
20 # Directories to find services in
21 if [ ! "$SERVICES_DIRS" ]
22 then SERVICES_DIRS=/service
26 bootcd="`/bin/sysenv bootcd`"
32 *) echo >&2 "Usage: $0 [start|stop]"
36 if [ -f "$LOCAL_FILE" ]
37 then . "$LOCAL_FILE" $1
43 for skip in `sysenv disable`
57 # Function to start a daemon, if it exists.
66 # check if this service is disabled at the boot monitor.
67 if disabled $name; then return; fi
78 # Function to dynamically start a system service
80 prefix=$(expr "$1 " : '\(-\)')
81 if [ "$prefix" = "-" ];
89 # First check if this service is disabled at the boot monitor.
90 if disabled $service; then return; fi
92 # Service is not disabled. Try to bring it up.
94 for dir in $SERVICES_DIRS
96 if [ -x $bin -a -z "$found" ]
97 then minix-service $opt up $bin "$@"
103 then echo " ($service not found in $SERVICES_DIRS)"
107 # Print a list of labels of detected PCI ethernet hardware devices.
110 # We need to match all PCI ethernet hardware devices against all
111 # drivers. For performance reasons, we construct a lookup table on the
112 # fly here. In order to do that, we need to give both a list of all
113 # available network drivers with PCI device IDs (part 1 of the code
114 # below) and a list of all actually present ethernet hardware devices
115 # (part 2) to an awk script (part 3). The awk script can tell the
116 # difference between the list entries based on whether there is a
117 # leading space on the line. For part 2, we grab only devices that are
118 # in PCI class 2 (network controller) subclass 0 (ethernet controller).
120 # Part 1: collect all network drivers with supported PCI IDs
121 (for dir in $SYSTEM_CONF_DIRS; do
122 for f in $dir/$SYSTEM_CONF_SUBDIR/*; do
124 printconfig $f | grep ',type net.*,pci device'
127 done | sed 's/^service \([^,]*\),.*,pci device/ \1/g';
128 # Part 2: grab all PCI IDs of ethernet hardware devices (class 2/0)
129 cat /proc/pci | grep '^[^ ]* 2/0/' | cut -d' ' -f3) | awk '
130 # Part 3: first construct a PCI-ID-to-driver table based on the lines
131 # produced by part 1 (with leading space), which each contain one
132 # driver name followed by one or more PCI IDs; then, go through all
133 # the ethernet hardware devices found in part 2 (no leading space) and
134 # if if there is a hit in the table, print the driver label to use.
135 /^ / { for (i=2;i<=NF;i++) drivers[$(i)]=$1 }
137 # There is a bit of a discrepancy between output formats of
138 # /proc/pci and printconfig: the former uses
139 # "vid:did:sub_vid:sub_did" whereas the latter uses
140 # "vid:did/sub_vid:sub_did". No problem; in the common case
141 # (= no sub IDs used) we need to split the PCI ID anyway.
142 if (split($1,id,":") >= 4) {
143 # Try a full "vid:did:sub_vid:sub_did" match.
144 name=drivers[id[1]":"id[2]"/"id[3]":"id[4]]
146 # No sub IDs or no match found? Try a "vid:did" match.
147 if (!name) name=drivers[id[1]":"id[2]]
148 # If found, print the resulting label (<name>_<instance>)
150 print name"_"(instance[name]+0)
157 # Print a list of labels of ethernet hardware devices that have been detected
158 # to be present on the system. Each label has the format '<driver>_<instance>'
159 # where <driver> is the file name of the driver (in /service) and <instance> is
160 # a zero-based, per-driver instance number of the device.
162 # For now, do autodetection only on platforms with (x86) PCI support.
163 # For (x86) ISA drivers, a custom network setting script is required;
164 # see below. For ARM platforms, the driver (if any) is started based
165 # on the board; there is no device autodetection.
166 if [ -f /proc/pci ]; then
170 # Add any network drivers manually configured in /usr/etc/rc.local by
171 # the netconf(8) utility.
172 if [ -n "$netdriver" ]; then
173 echo "${netdriver}_0"
177 # Detect expansion boards on the BeagleBone and load the proper drivers.
180 # Probe each possible cape EEPROM slave address for a BeagleBone cape.
181 for slave_addr in 54 55 56 57
184 # See if there is a readable EEPROM with address ${slave_addr}.
185 eepromread -f /dev/i2c-3 -a 0x${slave_addr} > /dev/null 2>&1
190 # Found an alive EEPROM. Try reading the cape name.
191 CAPE=`eepromread -i -f /dev/i2c-3 -a 0x${slave_addr} | \
192 sed -n 's/^PART_NUMBER : \(.*\)$/\1/p' | \
193 sed -e 's/\.*$//g'` # Strip trailing periods.
195 # Look for a cape specific RC script.
196 if [ -x /etc/rc.capes/${CAPE} ]
199 # CAT24C256 EEPROM -- all capes have this chip.
200 test -e /dev/eepromb3s${slave_addr} || \
201 (cd /dev && MAKEDEV eepromb3s${slave_addr})
202 up cat24c256 -dev /dev/eepromb3s${slave_addr} \
203 -label cat24c256.3.${slave_addr} \
204 -args "bus=3 address=0x${slave_addr}"
206 # Load the drivers for the cape and do any other configuration.
207 . "/etc/rc.capes/${CAPE}"
212 echo "** UNSUPPORTED CAPE: ${CAPE}"
222 # Select console font.
223 test -f /etc/font && loadfont /etc/font </dev/console
226 rm -rf /tmp/* /usr/run/* /usr/spool/lpd/* /usr/spool/locks/*
228 # Start servers and drivers set at the boot monitor.
229 echo -n "Starting services:"
230 up -n random -dev /dev/random -period 3HZ
232 # load random number generator
233 if [ -f $RANDOM_FILE ]
235 cat < $RANDOM_FILE >/dev/random
236 # overwrite $RANDOM_FILE. We don't want to use this data again
237 dd if=/dev/random of=$RANDOM_FILE bs=1024 count=1 2> /dev/null
239 # We couldn't find the old state to restart from, so use a binary
240 # file and the current date instead, even if this is less than ideal.
241 cat /bin/sh >> /dev/urandom
245 # start network driver instances for all detected ethernet devices
246 for label in $(get_eth_labels); do
247 driver=$(echo $label | sed 's/\(.*\)_.*/\1/')
248 instance=$(echo $label | sed 's/.*_//')
249 eval arg=\$${driver}_arg
250 if [ ! -z "$arg" ]; then arg=" $arg"; fi
251 arg="-args \"instance=$instance$arg\""
252 eval up $driver -label $label $arg -period 5HZ
255 # pty needs to know the "tty" group ID
256 up pty -dev /dev/ptmx -args "gid=`stat -f '%g' /dev/ptmx`"
258 # Start the LWIP service.
259 up lwip -dev /dev/bpf -script /etc/rs.lwip
261 # Load stable seed for TCP Initial Sequence Number generation (RFC 6528).
262 # The idea here is that (especially) after a system crash, the seed stays
263 # the same, so as to make it unlikely that incoming packets for connections
264 # from before the crash are accepted on connections after the crash.
265 TCPISN_LEN=$(sysctl -n net.inet.tcp.isn_secret | awk '{print length/2}')
266 if [ ! -f $TCPISN_FILE ]; then
267 # If the /usr file system is read-only, we cannot create the file. In
268 # that case, we draw a temporary secret from the random service.
269 if grep ' \/usr .*rw.*' /etc/mtab >/dev/null; then
270 dd if=/dev/random of=$TCPISN_FILE bs=$TCPISN_LEN count=1 2>/dev/null
272 TCPISN_FILE=/dev/random
275 sysctl -qw net.inet.tcp.isn_secret=`dd if=$TCPISN_FILE bs=$TCPISN_LEN \
276 count=1 2>/dev/null | hexdump -v -e '/1 "%02x"'` 2>/dev/null
278 # LWIP does not block until all network drivers have fully initialized and
279 # reported back to LWIP. That may prevent proper configuration of the
280 # corresponding interfaces a bit later. Sleep up to five seconds waiting
281 # for all registered network drivers to initialize and report to LWIP.
282 for i in 1 2 3 4 5; do
283 [ $(sysctl -n minix.lwip.drivers.pending) -gt 0 ] && sleep 1
290 up log -dev /dev/klog
294 up -n printer -dev /dev/lp -period 10HZ
295 # start VirtualBox time sync driver if the device is there
296 if grep '^[^ ]* [^ ]* 80EE:CAFE[^ ]* ' /proc/pci >/dev/null; then
297 up -n vbox -period 10HZ
303 echo -n "Starting daemons:"
306 # Ugly error message when starting cron from CD.
307 # (and cron unnecessary then so..)
311 rm -f /var/log || true
312 ln -s /tmp/log /var/log || true
318 # i2c only supported on ARM at the moment
321 echo -n "Starting i2c subsystem: "
324 test -e /dev/i2c-${bus} || (cd /dev && MAKEDEV i2c-${bus})
325 up i2c -dev /dev/i2c-${bus} -label i2c.${bus} \
326 -args instance=${bus}
330 BOARD_NAME=`sysenv board`
331 case "${BOARD_NAME}" in
333 ARM-ARMV7-TI-BB-WHITE)
334 echo "Running on a BeagleBone"
335 echo -n "Starting i2c device drivers: "
337 # start EEPROM driver for reading board info
338 test -e /dev/eepromb1s50 || \
339 (cd /dev && MAKEDEV eepromb1s50)
340 up cat24c256 -dev /dev/eepromb1s50 \
341 -label cat24c256.1.50 \
342 -args 'bus=1 address=0x50'
344 # Start TPS65217 driver for power management.
345 up tps65217 -label tps65217.1.24 \
346 -args 'bus=1 address=0x24'
348 # Start ethernet driver.
349 up lan8710a -label lan8710a_0 -args 'instance=0'
351 # check for the presence of a display
352 eepromread -f /dev/i2c-2 -n > /dev/null 2>&1
356 # start eeprom driver for reading EDID.
357 test -e /dev/eepromb2s50 || \
358 (cd /dev && MAKEDEV eepromb2s50)
359 up cat24c256 -dev /dev/eepromb2s50 \
360 -label cat24c256.2.50 \
361 -args 'bus=2 address=0x50'
364 #up fb -dev /dev/fb0 -args edid.0=cat24c256.2.50
365 # fb hasn't been ported to AM335X yet.
368 if [ -e /service/usbd ]
373 # Detect expansion boards and start drivers.
378 ARM-ARMV7-TI-BB-BLACK)
379 echo "Running on a BeagleBone Black"
380 echo -n "Starting i2c device drivers: "
382 # start EEPROM driver for reading board info
383 test -e /dev/eepromb1s50 || \
384 (cd /dev && MAKEDEV eepromb1s50)
385 up cat24c256 -dev /dev/eepromb1s50 \
386 -label cat24c256.1.50 \
387 -args 'bus=1 address=0x50'
389 # Start TPS65217 driver for power management.
390 up tps65217 -label tps65217.1.24 \
391 -args 'bus=1 address=0x24'
393 # Start TDA19988 driver for reading EDID.
394 up tda19988 -label tda19988.1.3470 -args \
395 'cec_bus=1 cec_address=0x34 hdmi_bus=1 hdmi_address=0x70'
397 # Start ethernet driver.
398 up lan8710a -label lan8710a_0 -args 'instance=0'
401 #up fb -dev /dev/fb0 -args edid.0=tda19988.1.3470
402 # fb hasn't been ported to AM335X yet.
404 if [ -e /service/usbd ]
409 # Detect expansion boards and start drivers.
414 ARM-ARMV7-TI-BBXM-GENERIC)
415 echo "Running on a BeagleBoard-xM"
416 echo -n "Starting i2c device drivers: "
418 # Start TPS65950 driver for power management.
419 up tps65950 -label tps65950.1.48 \
420 -args 'bus=1 address=0x48'
422 # Set the system time to the time in the TPS65950's RTC
425 # check for the presence of a display
426 eepromread -f /dev/i2c-3 -n > /dev/null 2>&1
430 # start eeprom driver for reading edid
431 test -e /dev/eepromb3s50 || \
432 (cd /dev && MAKEDEV eepromb3s50)
433 up cat24c256 -dev /dev/eepromb3s50 \
434 -label cat24c256.3.50 \
435 -args 'bus=3 address=0x50'
438 up fb -dev /dev/fb0 -args edid.0=cat24c256.3.50
447 # Load the stored hostname into the sysctl database.
448 test -r /etc/hostname.file && hostname $(cat /etc/hostname.file)
450 # Recover files being edited when the system crashed.
451 test -f /usr/bin/elvprsv && elvprsv /usr/tmp/elv*
453 # Run the daily cleanup on systems that are not on at night.
454 test -f /usr/etc/daily && sh /usr/etc/daily boot &
457 # Save random data, if /usr is mounted rw.
458 if grep ' \/usr .*rw.*' /etc/mtab >/dev/null
460 if dd if=/dev/random of=$RANDOM_FILE.new bs=1024 count=1 2>/dev/null
462 mv $RANDOM_FILE.new $RANDOM_FILE
464 echo 'Failed to save random data.'