Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- init-2.05b# ls
- Readme.txt dev lib lost+found opt root sysroot usr
- bin etc linuxrc nn proc sbin tmp var
- init-2.05b# cat ./linuxrc
- #!/bin/bash
- . /etc/rc.d/init.d/functions
- . /etc/rc.d/init.d/init_functions
- echo "Setting PATHs"
- PATH=/sbin:/usr/sbin:/bin:/usr/bin:/opt/sbin:/nn/bin:/nn/sbin
- LD_LIBRARY_PATH=/lib:/usr/lib:/var/lib:/nn/lib:/usr/local/lib
- LD_RUN_PATH="$LD_LIBRARY_PATH"
- TERM=xterm
- export PATH LD_LIBRARY_PATH LD_RUN_PATH TERM
- echo "Mounting /proc"
- #action $"Mounting proc filesystem: " /bin/mount -n -t proc /proc /proc
- /bin/mount -n -t proc none /proc
- echo "Mounting /dev/pts"
- /bin/mount -t devpts none /dev/pts
- fw_print=/nn/bin/fw_printenv
- fw_set=/nn/bin/fw_setenv
- nn_setled=/nn/bin/setled
- word_count=/opt/bin/wc
- num_partitions=0
- num_flash_partitions=0
- num_hd_partitions=0
- usb_flash=0
- hd_exist=0
- logfile="/mnt/factoryImg/ResetButton.log"
- reset_request=
- _mode=
- /sbin/ldconfig
- ###################################################################
- #
- # Determine hardware type
- # : hw_type - M50
- # : default is 50
- #
- # Detect devices, look for
- # : sda - usb flash - Not used
- # : sda - hard disk
- #
- #
- ###################################################################
- init_setup()
- {
- echo "Entering init_setup..."
- flash_id=
- hd_id=
- #need to load the modules for fw_printenv and fw_setenv
- /etc/rc.d/init.d/nn_modules start
- # First the /proc/partitions entries
- if [ ! -e /proc/partitions ]; then
- # No usb or HD devices present or /proc failed to load, nothing to do
- echo "No /proc/partitions, cannot detect hard disk or internal flash device. Please check hard disk or contact support."
- /bin/sleep 60
- echo "Rebooting..."
- /bin/sleep 5
- /sbin/shutdown -rn now
- fi
- if [ -e /dev/mainfs ]; then
- /bin/rm -f /dev/mainfs
- fi
- if [ -e /dev/mfgfs ]; then
- /bin/rm -f /dev/mfgfs
- fi
- # Set the default /dev/mainfs value to /dev/sdb3
- # It may be overwritten if logic dictates
- /bin/ln -sf /dev/sdb3 /dev/mainfs
- #Need to figure out if HD is sda or sdb
- #Required before we had the kernel dedicate sda to flash and sdb for HD
- num_sda_partitions=`/bin/cat /proc/partitions | /bin/grep sda[1-9] | $word_count -l`
- num_sdb_partitions=`/bin/cat /proc/partitions | /bin/grep sdb[1-9] | $word_count -l`
- #hard disk exists at sdb
- if [ $num_sdb_partitions -eq 12 ]; then
- hd_id=sdb
- #hard disk exists at sda
- elif [ $num_sda_partitions -eq 12 ]; then
- hd_id=sda
- else
- return 1
- fi
- hd_exist=1
- ext2_parts="sda7 sda8 sda9"
- ext3_parts="sda3 sda5 sda6"
- /bin/ln -sf /dev/sda3 /dev/mainfs
- /bin/ln -s /dev/sda5 /dev/mfgfs
- # used for hard disk info in inventory manager
- # should always be sda on m50
- /bin/ln -sf /dev/sda /dev/bcm_hdd1
- echo hd_exist=$hd_exist
- }
- ####################################################################
- #
- # Set the LED status
- # reset request - POWER LED/STATUS LED
- # mfg mode - SOLID RED/SOLID GREEN
- # L2 - SOLID RED/SOLID RED
- # L1 - SOLID RED/BLINK YELLOW
- #
- ####################################################################
- set_leds()
- {
- if [ $# -ne 2 ]; then
- return 1
- fi
- #First variable is LED device
- #Second value is what to set LED to
- echo -en "\x$2" > /dev/led"$1"
- }
- ####################################################################
- #
- # Filesystem check based on devices detected
- #
- ####################################################################
- # USB flash partitions
- # /dev/sda3 Config Data ext2
- # /dev/sda5 Logs ext2
- # /dev/sda6 MFG,Diags,reset ext2
- # /dev/sda7 MSW ext2
- # Hard Disk partitions - 450
- #/dev/sdb3 / ext3
- #/dev/sdb5 /nn/altroot ext3 defaults 1 2
- #/dev/sdb6 /var ext3 defaults 1 2
- #/dev/sdb7 /var/shadow ext2 defaults 1 2
- #/dev/sdb8 /var/log ext2 defaults 1 2
- #/dev/sdb9 /nn/patches ext2 defaults 1 2
- # Hard Disk partitions - M50
- #/dev/sda3 / ext3
- #/dev/sda5 /nn/altroot ext3 defaults 1 2
- #/dev/sda6 /var ext3 defaults 1 2
- #/dev/sda7 /var/shadow ext2 defaults 1 2
- #/dev/sda8 /var/log ext2 defaults 1 2
- #/dev/sda9 /nn/patches ext2 defaults 1 2
- file_system_check()
- {
- echo "Entering file_system_check..."
- #The ext2_parts and ext3_parts were set in init_setup
- #These should really be split to use a seperate function
- if [ $hd_exist -eq 1 ]; then
- for _part in $ext2_parts; do
- echo Checking $ext2_parts
- /sbin/fsck -t ext2 -y /dev/$_part
- _rc=$?
- if [ $_rc -gt 1 ]; then
- #We need to set LED's and halt
- echo Error detected error $_rc
- set_leds 0 8c #POWER LED BLINK RED
- set_leds 1 8c #STATUS LED BLINK RED
- else
- echo $_part check complete
- fi
- done
- for _part in $ext3_parts; do
- /sbin/fsck -t ext3 -y /dev/$_part
- _rc=$?
- if [ $_rc -gt 1 ]; then
- #We need to set LED's and halt
- echo Error detected error $_rc
- set_leds 0 8c #POWER LED BLINK RED
- set_leds 1 8c #STATUS LED BLINK RED
- else
- echo $_part check complete
- fi
- done
- fi
- if [ $usb_flash -eq 1 ]; then
- for _part in $flash_parts; do
- /sbin/fsck -t ext2 -y /dev/$_part
- _rc=$?
- if [ $_rc -gt 1 ]; then
- #We need to set LED's and halt
- echo Error detected error $_rc
- set_leds 0 8c #POWER LED BLINK RED
- set_leds 1 8c #STATUS LED BLINK RED
- else
- echo $_part check complete
- fi
- done
- fi
- }
- ####################################################################
- #
- # Mount /dev/sdb10 and look for flag
- # if not file /mnt/config/foundandlost
- # Set bootdelay=5
- # touch /mnt/configfs/foundandlost
- # unmount /dev/sdb10
- # reboot
- #
- ####################################################################
- check_first_boot()
- {
- if [ ! -e /mnt/configfs ]; then
- /bin/mkdir -p /mnt/configfs
- fi
- /bin/mount -t auto /dev/"$hd_id"10 /mnt/configfs
- if [ ! -e /mnt/configfs/foundandlost ]; then
- /bin/touch /mnt/configfs/foundandlost || /bin/echo `date` " Failed to create foundandlost" >/mnt/configfs/mfg_error.log
- if [ ! `$fw_print | grep "bootdelay=5"` ]; then
- /nn/bin/fw_setenv bootdelay 5
- /bin/umount /dev/"$hd_id"10
- /bin/sync
- /sbin/shutdown -rn now
- fi
- fi
- /bin/umount /dev/"$hd_id"10
- }
- ####################################################################
- #
- # Copy networking and account information from mainfs
- #
- ####################################################################
- sync_with_hd()
- {
- if [ ! -e /dev/mainfs ]; then
- echo "mainfs not defined, using default account and networking values"
- fi
- if [ ! -e /mnt/mainfs ]; then
- /bin/mkdir -p /mnt/mainfs
- fi
- /bin/mount -t auto /dev/mainfs /mnt/mainfs
- #network configuration
- /bin/cp -a /mnt/mainfs/etc/hosts /etc/hosts
- /bin/cp -a /mnt/mainfs/etc/sysconfig/network /etc/sysconfig/network
- /bin/cp -a /mnt/mainfs/etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/
- #account information
- #first test to make sure nnadmin exists and root account set properly
- _bcount=`grep root /etc/shadow | cut -f2 -d : | $word_count -c`
- /bin/grep -q nnadmin /mnt/mainfs/etc/passwd
- _passwdrc=$?
- /bin/grep -q nnadmin /mnt/mainfs/etc/shadow
- _shadowrc=$?
- if [ $_bcount -gt 4 -a $_passwdrc -eq 0 -a $_shadowrc -eq 0 ]; then
- /bin/cp -a /mnt/mainfs/etc/passwd /etc/passwd
- /bin/cp -a /mnt/mainfs/etc/shadow /etc/shadow
- echo 0
- fi
- if [ -e /mnt/mainfs/nn/etc/.systemid ]; then
- /bin/cp -a /mnt/mainfs/nn/etc/.systemid /nn/etc/
- fi
- if [ -e /mnt/mainfs/usr/local/etc/ssh_host_key ]; then
- cp -a /mnt/mainfs/usr/local/etc/ssh_host_key /usr/local/etc/
- fi
- if [ -e /mnt/mainfs/usr/local/etc/ssh_host_rsa_key ]; then
- cp -a /mnt/mainfs/usr/local/etc/ssh_host_rsa_key /usr/local/etc/
- fi
- if [ -e /mnt/mainfs/usr/local/etc/ssh_host_dsa_key ]; then
- cp -a /mnt/mainfs/usr/local/etc/ssh_host_dsa_key /usr/local/etc/
- fi
- #initialize the layer 2 switch
- /nn/sbin/swctl init
- /sbin/ifdown eth1
- /sbin/ifup eth1
- #bring up OAM interface
- /sbin/ifup eth2
- /etc/rc.d/init.d/sshd start
- /bin/umount /dev/mainfs
- }
- ####################################################################
- #
- # Read the uboot variable for reset_request and act accordingly
- #
- # L1 - mount reset partitions and perfrom a L1 reset
- # L2 - mount reset partitions and perform a L2 reset
- # mfg - mount /dev/sda5 and start stestd
- # mainos - pivot root and boot main file system using init
- # safeos - start CLI and halt in safeos
- #
- # If reset_request is explicitly set to safeos then call
- # CallBCMCli with the long parameter to indicate a 60 second timeout
- #
- # If reset_request is blank, the CLI timeout is 10 seconds
- #
- ####################################################################
- read_request()
- {
- echo "Entering read_request..."
- echo $1
- _request=none
- _cleanup=0
- _mfgtest=0
- #enable boot delay and reboot if set
- if [ $hd_exist -eq 1 ]; then
- check_first_boot
- fi
- if [ -n "$_mode" ]; then
- _request="reset_request=$_mode"
- _cleanup=1
- else
- _request=`$fw_print reset_request`
- fi
- #Blank the reset_request, default will booot to safeos
- $fw_print | grep "mfgtest" >/dev/null 2>&1
- _rc=$?
- if [ $_rc -ne 0 ]; then
- $fw_set reset_request
- $fw_set bootdelay 5
- elif [ "$_request" != "reset_request=mfg" ]; then
- $fw_set mfgtest
- $fw_set bootdelay 5
- fi
- echo $_request
- case "$_request" in
- "reset_request=mainos" | "reset_request=mainos_mode" )
- if [ $_cleanup -eq 1 ]; then
- unload_things
- else
- unload_modules_only
- fi
- mainos_chroot
- ;;
- "reset_request=safeos" )
- sync_with_hd
- start_services
- /nn/sbin/CallBCMCLI long &
- safeos_mode
- ;;
- "reset_request=l1" | "reset_request=L1" )
- set_leds 0 89 #POWER LED SOLID RED
- set_leds 1 cc #STATUS LED BLINK YELLOW
- start_services
- l1_reset
- ;;
- "reset_request=l2" | "reset_request=L2" )
- set_leds 0 89 #POWER LED SOLID RED
- set_leds 1 89 #STATUS LED SOLID RED
- sync_with_hd
- start_services
- l2_reset
- ;;
- "reset_request=mfg" )
- if [ $hd_exist -eq 1 ]; then
- sync_with_hd
- fi
- set_leds 0 89 #POWER LED SOLID RED
- set_leds 1 98 #STATUS LED GREEN
- start_services
- #/nn/sbin/CallBCMCLI wait &
- echo "Swapping to manufacturing mode..."
- mfg_mode
- ;;
- "reset_request=reset" )
- /sbin/shutdown -nr now
- ;;
- "reset_request=idle" )
- unload_things
- safeos_mode
- ;;
- * )
- sync_with_hd
- start_services
- /nn/sbin/CallBCMCLI short &
- safeos_mode
- ;;
- esac
- }
- ####################################################################
- #
- # Start the test daemon
- #
- ####################################################################
- start_stestd()
- {
- /etc/rc.d/init.d/xinetd start
- echo "Starting stestd..."
- prog="stestd"
- RC=0
- export HOME=/root/
- if [ -e /nn/sbin/stestd ]; then
- /nn/sbin/stestd 6800 &
- echo "stestd started"
- else
- echo "WARNING: stestd does not exist in /nn/sbin"
- fi
- }
- ####################################################################
- #
- # Start the test daemon
- #
- ####################################################################
- start_services()
- {
- /etc/rc.d/init.d/portmap start
- /etc/rc.d/init.d/syslog start
- /etc/rc.d/init.d/random start
- }
- ####################################################################
- #
- # Start the test daemon
- #
- ####################################################################
- safeos_mode()
- {
- rc=0
- while [ $rc -eq 0 ]; do
- if [ -e /root/swap ]; then
- /usr/bin/killall BCMCli >/dev/null 2>&1
- _mode=`cat /root/swap`
- echo "Swapping to $_mode"
- /bin/rm -f /root/swap
- read_request $_mode
- rc=1
- else
- sleep 10
- fi
- done
- }
- ####################################################################
- #
- # Mount altroot partition /dev/sdb5
- # For L1, L2 resets and manufacturing
- #
- ####################################################################
- mfg_mode()
- {
- if [ ! -d /mnt/altroot ]; then
- /bin/mkdir -p /mnt/altroot
- fi
- if [ ! -d /mnt/mainfs ]; then
- /bin/mkdir -p /mnt/mainfs
- fi
- /bin/mount -t auto /dev/mfgfs /mnt/altroot
- /bin/mount -t ext3 /dev/mainfs /mnt/mainfs
- #make stestd utilities visible
- /bin/mount --bind /mnt/altroot/nn /nn
- #load additional required klms
- #BCM50 requires lm85.o, nn_secsi.o and nn_timeswitch.o
- if [ -e /nn/lib/modules/lm85.o ]; then
- /sbin/insmod -f /nn/lib/modules/lm85.o
- fi
- if [ -e /nn/lib/modules/nn_secsi.o ]; then
- /sbin/insmod -f /nn/lib/modules/nn_secsi.o
- fi
- if [ -e /nn/lib/modules/nn_timeswitch.o ]; then
- /sbin/insmod -f /nn/lib/modules/nn_timeswitch.o
- fi
- if [ -e /nn/lib/modules/nn_dchan_drv.o ]; then
- /sbin/insmod -f /nn/lib/modules/nn_dchan_drv.o
- fi
- #replace the existing configuration files so telnet/ftp are enabled
- #telnet and ftp are started by xinetd, started later in start_stestd
- /bin/rm -f /etc/xinetd.d/telnet
- /bin/cp -a /mnt/altroot/etc/xinetd.d/telnet /etc/xinetd.d/telnet
- /bin/cp -a /mnt/altroot/usr/bin/ftp /usr/bin/
- /bin/cp -a /mnt/altroot/root/.netrc /root/
- /sbin/ifup eth2
- echo "Starting stestd"
- start_stestd
- /bin/touch /tmp/CLITimeout #meh
- if [ ! -e /dev/nn_secsi ]; then
- /bin/mknod /dev/nn_secsi c 0 29
- fi
- if [ ! -e /dev/mtd4 ]; then
- /bin/mknod /dev/mtd4 c 90 8
- fi
- #CLI should not be used often in mfg mode, present it just in case
- #/nn/sbin/CallBCMCLI wait &
- #call safeos_mode so we do not restart
- safeos_mode
- }
- ####################################################################
- #
- # Unload modules and stop running processes before going into mainos
- #
- ####################################################################
- unload_things()
- {
- #Stop services
- echo "Stopping portmap..."
- /etc/rc.d/init.d/portmap stop
- echo "Stopping sshd..."
- /etc/rc.d/init.d/sshd stop
- echo "Stopping network..."
- /etc/rc.d/init.d/network stop
- echo "stopping syslog..."
- /etc/rc.d/init.d/syslog stop
- #Unload modules
- echo "Unloading modules..."
- /etc/rc.d/init.d/nn_modules stop
- }
- ####################################################################
- #
- # Unload modules
- #
- ####################################################################
- unload_modules_only()
- {
- #Unload modules
- echo "Unloading modules..."
- /etc/rc.d/init.d/nn_modules stop
- }
- ####################################################################
- #
- # Mount mainos partition, pivot_root, execute rc.sysinit, chroot
- # to finish transferring to mainos
- #
- ####################################################################
- mainos_chroot()
- {
- echo "Entering mainos_chroot..."
- if [ ! -e /dev/mainfs ]; then
- echo "!!!ERROR!!! mainfs not defined. either no hard disk present or it is not partitioned, halting in safeos..."
- safeos_mode
- fi
- /bin/mount -t auto /dev/mainfs /sysroot
- /bin/umount /dev/pts
- /bin/umount /proc
- /bin/mkdir -p /sysroot/initrd
- cd /sysroot
- /bin/pivot_root . initrd
- exec /sbin/chroot . /bin/bash -c '/sbin/init 3'<dev/console >dev/console 2>&1
- }
- ####################################################################
- #
- # Mount reset partitions
- #
- ####################################################################
- mount_reset_partitions()
- {
- if [ ! -d /mnt/factoryImg ]; then
- /bin/mkdir -p /mnt/factoryImg
- fi
- if [ ! -d /mnt/configfs ]; then
- /bin/mkdir -p /mnt/configfs
- fi
- if [ ! -d /mnt/mainfs/var ]; then
- /bin/mkdir -p /mnt/mainfs/var
- fi
- if [ ! -d /mnt/mainfs/var/shadow ]; then
- /bin/mkdir -p /mnt/mainfs/var/shadow
- fi
- if [ ! -d /mnt/mainfs/var/log ]; then
- /bin/mkdir -p /mnt/mainfs/var/log
- fi
- if [ ! -d /mnt/mainfs/nn/patches ]; then
- /bin/mkdir -p /mnt/mainfs/nn/patches
- fi
- if [ ! -d /mnt/mainfs/nn/images/kernels ]; then
- /bin/mkdir -p /mnt/mainfs/nn/images/kernels
- fi
- #was using hd_id for device name but issue with missing /proc/partitions
- #forced the partitions to be hard-coded for now
- /bin/mount -t auto /dev/"$hd_id"3 /mnt/mainfs
- /bin/mount -t auto /dev/"$hd_id"6 /mnt/mainfs/var
- /bin/mount -t auto /dev/"$hd_id"7 /mnt/mainfs/var/shadow
- /bin/mount -t auto /dev/"$hd_id"8 /mnt/mainfs/var/log
- /bin/mount -t auto /dev/"$hd_id"9 /mnt/mainfs/nn/patches
- /bin/mount -t auto /dev/"$hd_id"1 /mnt/mainfs/nn/images/kernels
- /bin/mount -t auto /dev/"$hd_id"10 /mnt/factoryImg
- /bin/mount >>/mnt/factoryImg/ResetButton.log
- echo "Reset partitions mounted"
- }
- umount_reset_partitions()
- {
- echo "Reset partitions unmounted"
- /bin/umount /dev/"$hd_id"10
- /bin/umount /dev/"$hd_id"1
- /bin/umount /dev/"$hd_id"9
- /bin/umount /dev/"$hd_id"8
- /bin/umount /dev/"$hd_id"7
- /bin/umount /dev/"$hd_id"6
- /bin/umount /dev/"$hd_id"3
- /bin/mount >>/mnt/factoryImg/ResetButton.log
- }
- ####################################################################
- #
- # Perform L1 reset
- #
- ####################################################################
- l1_reset()
- {
- mount_reset_partitions
- echo `date` "LEVEL 1 RESET REQUESTED" >> $logfile
- /nn/bin/Level1.sh
- rc=$?
- /bin/sleep 3
- if [ "$rc" = "0" ]; then
- /nn/bin/fw_setenv reset_request "mainos"
- /bin/sync
- umount_reset_partitions
- /sbin/shutdown -rn now
- else
- echo `date` " L1 reset FAILED" >> $logfile
- /nn/bin/fw_setenv reset_request "mainos"
- /bin/sync
- umount_reset_partitions
- /sbin/shutdown -rn now
- fi
- }
- ####################################################################
- #
- # Perform L2 reset
- #
- ####################################################################
- l2_reset()
- {
- echo `date` "LEVEL 2 RESET REQUESTED" >> $logfile
- mount_reset_partitions
- #Call L2 with sda or sdb, $boot_hd_id for 450 and just $hd_id for 50
- /nn/bin/Level2.sh $hd_id
- rc=$?
- sleep 3
- if [ "$rc" = "0" ]; then
- echo "l2 test done"
- /nn/bin/fw_setenv reset_request "mainos"
- /bin/sync
- umount_reset_partitions
- /sbin/shutdown -rn now
- else
- echo `date` " L2 reset FAILED" >> $logfile
- /nn/bin/fw_setenv reset_request "mainos"
- /bin/sync
- umount_reset_partitions
- /sbin/shutdown -rn now
- fi
- }
- ####################################################################
- #
- # Main
- #
- ####################################################################
- echo "linuxrc starting..."
- if [ $# -eq 0 ]; then
- init_setup
- file_system_check
- read_request
- echo "Should not have gone this far"
- exit 0
- else
- echo "linuxrc test"
- fi
- #Should never actually exit from here
- exit 0
- init-2.05b#
Advertisement
Add Comment
Please, Sign In to add comment