Chumby Rootdisk - RFS1 (analyzed)

= Boot Script: /etc/init.d/rcS from Chumby Classic =

Start

 * 1) ! /bin/sh
 * 2) ken@chumby.com

echo "Chumby Rootdisk - RFS1 (ken@chumby.com)"


 * 1) /proc and /sys get mounted by /linuxrc

mount -t tmpfs none /dev -o mode=755 /usr/chumby/scripts/mkdevs /dev mount -t devpts pts /dev/pts

export LD_LIBRARY_PATH=/lib export PATH=${PATH}:/usr/chumby/scripts

mount -t tmpfs -o size=32m none /tmp mount -t tmpfs -o size=32m none /var mount -t tmpfs -o size=32m none /mnt
 * 1) mount temp partitions

mount -t jffs2 /dev/mtdblock1 /psp
 * 1) mount psp partition

mkdir -p /var/lock/subsystem mkdir -p /var/run mkdir -p /var/log mkdir -p /var/empty mkdir -p /var/spool/cron/crontabs mkdir -p /tmp/chumby
 * 1) create some required dirs

/sbin/syslogd -C200
 * 1) start syslogd

/usr/chumby/scripts/cpi.sh -a 2147483647
 * 1) set chumby alarm to 118 years from now

First custom boot Injection point
If the file /psp/rfs1/rcS exists then at this point in the script it will be loaded and nothing else of the original boot script will be run.

Warning: Create this file at your own peril

if [ -x /psp/rfs1/rcS ]; then /psp/rfs1/rcS exit fi

Loading of System Continues
echo "Starting udevd as daemon" /sbin/udevd --daemon

/usr/chumby/scripts/wait_for_usb
 * 1) wait for USB subsystem to finish loading

mkdir -p /mnt/usb mount /mnt/usb || rmdir /mnt/usb

Insertion point for userhook0
userhook0 can be placed on usb stick and on internal psp mount if [ -x /mnt/usb/userhook0 ]; then # Run in context of current script so it can change PATH and other # environment variables. . /mnt/usb/userhook0 fi if [ -x /psp/rfs1/userhook0 ]; then # Run in context of current script so it can change PATH and other # environment variables. . /psp/rfs1/userhook0 fi
 * 1) run any scripts for debug configuration of chumby from a USB thumb drive
 * 1) run any scripts for debug configuration of chumby from /psp

Loading of system continues
unzip -p /bitmap/chumby_logo.zip >/dev/fb
 * 1) Display the chumby logo

echo "Starting mountmon as daemon" mountmon --daemon
 * 1) Start mountmon

ln -s /etc/cron/crontabs/root /var/spool/cron/crontabs/root
 * 1) link crontabs

hwversion=`/usr/chumby/scripts/chumby_version -h`

if [ "$hwversion" == "3.8" ]; then # touch screen insmod /drivers/chumby-tsc2100.ko version038=1

# chumby sensor driver insmod /drivers/chumby_sense1.ko version038=1 else # touch screen insmod /drivers/chumby-tsc2100.ko

# chumby sensor driver insmod /drivers/chumby_sense1.ko fi

if [ -f /psp/firsttime ]; then FIRSTTIME=`cat /psp/firsttime` if [ "$FIRSTTIME" -eq "1" ]; then if [ "$hwversion" == "3.8" ]; then echo -n "101,3909,3984,-3815" >/psp/ts_settings else echo -n "136,3768,3835,-3540" >/psp/ts_settings fi   fi fi
 * 1) check if this is the first time that chumby has been run and set
 * 2) touch screen settings

if [ -e /psp/ts_settings_backup ]; then cp /psp/ts_settings_backup /psp/ts_settings rm /psp/ts_settings_backup fi
 * 1) restore touch screen settings from /psp if present

if [ -e /mnt/usb/ts_settings ]; then cp /mnt/usb/ts_settings /psp fi
 * 1) restore touch screen settings from USB if present

insmod /drivers/chumby_udma.ko
 * 1) chumby udma driver

echo 0 > /proc/sys/sense1/spkmute usleep 500000 echo 1 > /dev/dsp echo 1 > /proc/sys/sense1/spkmute usleep 500000

echo 0 > /proc/chumby/touchscreen/touchclick
 * 1) Initially disable touch click

insmod /drivers/snd-rawmidi.ko insmod /drivers/snd-seq-midi.ko insmod /drivers/snd-usb-lib.ko insmod /drivers/snd-hwdep.ko insmod /drivers/snd-usb-audio.ko insmod /drivers/usbhid.ko
 * 1) sound drivers

if [ -e /psp/mute ]; then echo -n "Restoring mute setting: " chumby_set_volume --master_mute `cat /psp/mute` fi
 * 1) set the speaker mute based on previous speaker settings

if [ -e /psp/volume ]; then echo -n "Restoring volume setting: " chumby_set_volume --master_volume `cat /psp/volume` fi
 * 1) set the volume

if [ -e /psp/pan ]; then echo -n "Restoring speaker pan setting: " chumby_set_volume --master_panning `cat /psp/pan` fi
 * 1) set the speaker panning

insmod /drivers/chumby_timer.ko mknod /dev/timerx c `cat /proc/devices |awk '/timer/ {print $1}'` 0 mknod /dev/timerm c `cat /proc/devices |awk '/timer/ {print $1}'` 1
 * 1) chumby aux timer

insmod /drivers/chumby_accel.ko mknod /dev/accel c `cat /proc/devices |awk '/accel/ {print $1}'` 0
 * 1) chumby accelerometer

mknod /dev/switch c `cat /proc/devices |awk '/switch/ {print $1}'` 0
 * 1) chumby switch

mknod /dev/dcid c `cat /proc/devices |awk '/dcid/ {print $1}'` 0
 * 1) chumby daughter card id

mknod /dev/udma c `cat /proc/devices |awk '/udma/ {print $1}'` 1
 * 1) chumby udma

echo "Triggering udevd events for usb devices" udevtrigger --subsystem-match=usb_device --subsystem-match=block
 * 1) After kernel modules have been loaded, trigger events for usb hotplug devices

headphone_mgr &
 * 1) start multi-purpose monitor (headphone jack, battery level, network status)

if [ ! -f /psp/UPDATE1 ]; then /usr/chumby/scripts/start_opening_anim & fi
 * 1) start and fork opening animation

ifconfig lo 127.0.0.1

insmod /drivers/usbnet.ko insmod /drivers/asix.ko
 * 1) load wired Ethernet drivers

insmod /drivers/rt73.ko
 * 1) load wifi driver

if [ -e /mnt/usb/network_config ]; then cp /mnt/usb/network_config /psp /usr/chumby/scripts/start_network else if [ -e /psp/network_config ]; then /usr/chumby/scripts/start_network else ifconfig rausb0 up	fi fi
 * 1) start the network
 * 1) start the network

Insertion point for userhook1
if [ -x /mnt/usb/userhook1 ]; then /mnt/usb/userhook1 fi if [ -x /psp/rfs1/userhook1 ]; then /psp/rfs1/userhook1 fi
 * 1) run any scripts for debug configuration of chumby from a USB thumb drive
 * 1) run any scripts for debug configuration of chumby from /psp

After userhook1 has completed
if [ -x /mnt/usb/debugchumbyearly ]; then /mnt/usb/debugchumbyearly fi
 * 1) run any scripts for debug configuration of chumby from a USB thumb drive

/usr/chumby/scripts/restore_time
 * 1) attempt to restore time based on the crypto processor's uptime counter

running=`ifconfig rausb0 |grep RUNNING` if [ -z "$running" ]; then echo "Network is down. Network time not updated." else /usr/chumby/scripts/sync_time.sh -b & fi
 * 1) sync time if the network is running

Built-in Web Server Starts Up
/usr/sbin/httpd -h /www
 * If we'd run our own server before this point, then this should fail (silently?) to start the builtin.
 * If we need to start our own server afterwards we should `killall httpd`
 * 1) webserver

more stuff runs
HOSTNAME="$(hostname)" if [ "${HOSTNAME}" = "chumby" ] then echo "Creating default hostname: " HOSTNAME="$(default_hostname)" [ "${HOSTNAME}" ] && echo "${HOSTNAME}" >/psp/hostname echo "New hostname: ${HOSTNAME}" fi
 * 1) Check for hostname

echo "Starting zeroconf service" PATH=/usr/chumby/scripts:/usr/sbin:${PATH} service_control zeroconf start
 * 1) zeroconf - howl

echo "Starting chumbhowld service" PATH=/usr/chumby/scripts:${PATH} service_control chumbhowld start
 * 1) Start howl daemon

/usr/sbin/crond -c /etc/cron/crontabs
 * 1) start crond

if [ ! -f /psp/UPDATE1 ]; then /usr/chumby/scripts/wait_for_opening fi
 * 1) make sure that the opening animation has completed before proceeding

if [ -f /psp/UPDATE1 ]; then UPDATE_URL=`cat /psp/UPDATE1`
 * 1) check to see if an update of RFS2 is needed

# check to see if there was a problem connecting to the network if [ ! -e /tmp/chumby/network_status.xml ]; then network_errors=`/usr/chumby/scripts/network_status.sh |grep error` else network_errors=`cat /tmp/chumby/network_status.xml |grep error` fi

if [ -z "$network_errors" -o "$UPDATE_URL" == "update1" ]; then # update if there are no network errors or updating via USB echo "Updating RFS2.." if [ -e /psp/UPDATE1_MD5 ]; then /usr/chumby/scripts/update.sh `cat /psp/UPDATE1` NETWORK `cat /psp/UPDATE1_MD5` >/tmp/update1.log 2>&1 if [ "$?" -eq "0" ]; then # RFS2 update succeeded, remove flags rm -f /psp/UPDATE1 if [ -e /psp/save_update1 ]; then rm -f /psp/save_update1 fi           fi        else /usr/chumby/scripts/update.sh `cat /psp/UPDATE1` >/tmp/update1.log 2>&1 if [ "$?" -eq "0" ]; then # RFS2 update succeeded, remove flags rm -f /psp/UPDATE1 if [ -e /psp/save_update1 ]; then rm -f /psp/save_update1 fi           fi        fi    else # set save_update1 to ensure that /psp/UPDATE1 is not removed when setting to factory defaults touch /psp/save_update1 fi fi

echo "Clearing paranoid boot flag" flash_eraseall /dev/mtd7 nandwrite /dev/mtd7 /usr/chumby/msp_00_64k_no_oob.bin 0x70000
 * 1) set paranoid boot flag/semaphore

echo "Starting btplay daemon" /usr/sbin/btplayd >/dev/null 2>&1 &
 * 1) start resident portion of btplay

Insertion point for userhook2
if [ -x /mnt/usb/userhook2 ]; then /mnt/usb/userhook2 fi if [ -x /psp/rfs1/userhook2 ]; then /psp/rfs1/userhook2 fi
 * 1) run any scripts for debug configuration of chumby from a USB thumb drive
 * 1) run any scripts for debug configuration of chumby from /psp

Debug Chumby
if [ -x /mnt/usb/debugchumby ]; then /mnt/usb/debugchumby fi
 * 1) run any scripts for debug configuration of chumby from a USB thumb drive

Remaining script runs
/usr/chumby/scripts/start_intro

/bin/chumbalarmd
 * 1) start chumby backup alarm daemon

if [ -e /psp/missed_alarm ]; then # chumbalarmd has detected that an alarm was missed, allow chumbalarmd to fire the backup alarm # start_control_panel will be called automatically from chumbalarmd rm /psp/missed_alarm sync else # henry - enable logins /usr/chumby/scripts/start_control_panel >/dev/null 2>&1 & fi