#!/bin/sh export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin echo "---- in modified linuxrc (KAMII) START ---" mount proc /proc -t proc mount sysfs /sys -t sysfs . /usr/local/bin/libbuffalo ## must be same as init.d/bootcomplete ROOTFS_OK=/mnt/etc/rootfs_ok HDDROOTMODE=/mnt/etc/hddrootmode ROOTFS_BOOTING=/mnt/etc/rootfs_booting SetRootfsBootMarker() { date > $ROOTFS_OK } DelRootfsBootMarker() { rm -f $ROOTFS_OK } CopyFromInitrdToHdd() { echo "-- CopyFromInitrdToHdd --" # these files should be same as initrd. # therefore you shouldn't put these files into hddimg. cp -a /etc/linkstation_emergence /mnt/etc/initrd_ver # /lsgl/usr/local/bin if [ ! -d /mnt/lsgl/usr/local/bin ] ; then mkdir -p /mnt/lsgl/usr/local/bin fi for i in bootchange.sh exec_libbuffalo kernelmon_exec.sh imhere.sh \ lcd_error_man.sh libbuffalo set_time.sh shutdown.sh imhere.sh do if [ -e /usr/local/bin/$i -a ! -e /mnt/lsgl/usr/local/bin/$i ] ; then cp -af /usr/local/bin/$i /mnt/lsgl/usr/local/bin/ fi done # /lsgl/usr/local/sbin if [ ! -d /mnt/lsgl/usr/local/sbin ] ; then mkdir -p /mnt/lsgl/usr/local/sbin fi cp -af /usr/local/sbin/* /mnt/lsgl/usr/local/sbin/ # etc/init.d/ for i in bootcomplete.sh checkroot.sh clientUtil_servd.sh \ create_devlink.sh diskmon.sh ftpd.sh \ pwrmgr.sh kernelmon.sh logtag micon_setup.sh miconmon.sh \ networking.sh procps.sh rcDown reboot.sh reboot_start.sh \ restore_config.sh sethostname.sh sendsigs.sh \ shutdown_start.sh syslog.sh umount_disk.sh do if [ -e /etc/init.d/$i -a ! -e /mnt/etc/init.d/$i ] ; then cp -af /etc/init.d/$i /mnt/etc/init.d/ fi done # standby for i in /etc/init.d/standby.* /usr/local/sbin/clientUtil_server \ /etc/dhcpc /sbin/dhcpcd do if [ -e $i -a ! -e /mnt/$i ] ; then cp -af $i /mnt/$i fi done return 0 } fsck_disks() { ##fsck_localdisks echo "== fsck_disks ==" fsck.ext3 -pyf /dev/${DEV_BOOT} FsckXFS /dev/${DEV_ROOTFS1} } HasUpdatedFile() { mkdir ${MPT_BOOT} mount /dev/${DEV_BOOT} ${MPT_BOOT} if [ $? -ne 0 ]; then # retry mount /dev/${DEV_BOOT} ${MPT_BOOT} fi if [ $? -ne 0 ]; then return 0 fi # delete lost+founc rm -rf ${MPT_BOOT}/lost+found/* # if [ -f ${MPT_BOOT}/uImage.buffalo.updated ]; then umount ${MPT_BOOT} return 1 fi if [ -f ${MPT_BOOT}/u-boot.buffalo.updated ]; then umount ${MPT_BOOT} return 1 fi if [ -f ${MPT_BOOT}/initrd.buffalo.updated ]; then umount ${MPT_BOOT} return 1 fi if [ -f ${MPT_BOOT}/hddrootfs.buffalo.updated ]; then umount ${MPT_BOOT} return 1 fi umount ${MPT_BOOT} return 0 } TestRootfs() { ##echo "-- TestRootfs --" mount -n -o rw /dev/${DEV_ROOTFS1} /mnt if [ $? != 0 ]; then # retry mount -n -o rw /dev/${DEV_ROOTFS1} /mnt fi if [ $? = 0 ]; then PRDI1=`grep PRODUCTID /proc/buffalo/firmware` PRDI2=`grep PRODUCTID /mnt/etc/linkstation_release` # delete lost+founc rm -rf /mnt/lost+found/* # echo $PRDI1 $PRDI2 ## check RootfsBootMarker if [ ! -f $HDDROOTMODE ]; then echo "** use initrd mode. **" umount /mnt return 1; fi if [ ! -f $ROOTFS_OK ]; then echo "*** not found $ROOTFS_OK file in rootfs. ***" echo -n "*" >> $ROOTFS_BOOTING chars=`cat $ROOTFS_BOOTING|wc -c` echo "chars=$chars" ## chars=0 means 'write fail'. if [ "$chars" = 0 ] || [ "$chars" -ge 3 ] ; then echo "** over max retry. use initrd mode. **" umount /mnt return 1; fi fi /usr/local/bin/vercomp /proc/buffalo/firmware /mnt/etc/linkstation_release DATE_KERN=$? /usr/local/bin/vercomp /etc/linkstation_emergence /mnt/etc/linkstation_release DATE_INITRD=$? if [ $DATE_KERN -ne 0 ] || [ $DATE_INITRD -ne 0 ]; then echo "***(WARN) hddSys is old. ***" #echo "*** hddSys is old. use initrd mode. ***" #umount /mnt #return 1 fi DelRootfsBootMarker CopyFromInitrdToHdd umount /mnt if [ "$PRDI1" = "$PRDI2" ]; then return 0; else echo "*** version mismatch. use initrd mode. ***" fi fi return 1; } HddRoot() { echo "-HddRoot-" HasUpdatedFile if [ $? != 0 ]; then echo "** has Updated Files **" echo "0x100" >/proc/sys/kernel/real-root-dev return fi TestRootfs if [ $? != 0 ]; then echo "0x100" >/proc/sys/kernel/real-root-dev fi fsck_disks } RamdiskRoot() { echo "-RamdiskRoot-" echo "0x100" >/proc/sys/kernel/real-root-dev } CommandMdode() { echo "-CommandMode-" mount -a /sbin/getty -L ttyS0 115200 vt100 ##/bin/sh } rtc_check() { grep "0000/" /proc/driver/rtc >/dev/null if [ $? -eq 0 ]; then miconapl -b -a boot_device_error "Chip Error E17RTC Failure" fi } pci_check() { PCI_ETH="device 11" PCI_SATA1="device 12" PCI_SATA2="device 13" PCI_USB="device 14" # ETH PCI-ID11 (REALTEK:10ec) grep "$PCI_ETH" /proc/pci >/dev/null if [ $? -ne 0 ]; then miconapl -b -a boot_device_error "Chip Error E21Ethernet Failure" fi # SATA1 PCI-ID12 (SIL:1095) grep "$PCI_SATA1" /proc/pci >/dev/null if [ $? -ne 0 ]; then miconapl -b -a boot_device_error "Chip Error E18SATA1 Failure" fi # SATA2 PCI-ID13 (SIL:1095) grep "$PCI_SATA2" /proc/pci >/dev/null if [ $? -ne 0 ]; then miconapl -b -a boot_device_error "Chip Error E19SATA2 Failure" fi # USB PCI-ID14 (NEC:1033) grep "$PCI_USB" /proc/pci >/dev/null if [ $? -ne 0 ]; then miconapl -b -a boot_device_error "Chip Error E20USB Failure" fi } CheckDevices() { echo "CheckDevices" #pci_check #rtc_check } # set the system time from the hardware clock hwclock -s date ## Setup Micon communication port and send flash-boot complete message. miconapl -b -a boot_flash_ok ### miconapl -a led_set_cpu_mcon off ### miconapl -a led_set_on_off off ### miconapl -a led_set_brink off ### miconapl -a fan_set_speed full miconapl -a fan_set_speed slow CheckDevices echo "linuxrc:choose operation (timeout 4[s])" echo -n " 1:RamRoot other:HddRoot ? " ## timeout is 4[s] ANSWER=`/usr/local/bin/keyinput -t 4` case "$ANSWER" in 1) RamdiskRoot ;; 9) CommandMdode ;; *) HddRoot ;; esac cat /etc/mtab umount /sys umount /proc umount -a exit 0