#!/bin/sh
# Copyright (c) 2006, Technologic Systems.
# All rights reserved.
#
# Uses initrd as root filesystem and drops to shell-- on exit of serial shell, 
# real Linux is booted.  Ethernet is configured as 192.168.0.50 and telnet 
# server is run.  If a USB device is present, it is checked for the presence
# of an auto-update script "/tsinit", which is then run.

mount -t proc proc /proc

export CONSOLE=/dev/ttyAM0
stty -F $CONSOLE ospeed 115200 >/dev/null 2>&1
setcons  <$CONSOLE >$CONSOLE 2>&1

echo "" >$CONSOLE
echo "" >$CONSOLE
echo "" >$CONSOLE
echo ">> #############################################<<" >$CONSOLE
echo ">>        SMI CM-II #1 : linuxrc-fastboot       <<" >$CONSOLE
echo ">> #############################################<<" >$CONSOLE
#echo ">> installed smiCmDio driver..." >$CONSOLE

export PATH=/bin:/sbin:/mnt/root/bin:/mnt/root/sbin:/mnt/root/usr/bin:/mnt/root/usr/sbin:/mnt/root/usr/local/bin
export BOOTTIME=`eptime`
ifconfig eth0 10.0.110.35 netmask 255.255.255.0
route add default gw 10.0.110.1
echo ">> updated networking parameters..." >$CONSOLE

telnetd
echo ">> checking for USB pendrive..." >$CONSOLE
check-usb-update >/dev/null 2>&1 </dev/null &

(
  export ENV=/shinit
  setcons
  exec /bin/sh -i
) <$CONSOLE >$CONSOLE 2>&1

killall busybox

insmod -q -f /sdcard.o dmaenable=1 >/dev/null 2>&1
if [ -e /dev/sdcard0/disc0/part3 -a ! -e /mnt/root/bin/mount ]; then
  mount -o ro /dev/sdcard0/disc0/part3 /mnt/root >/dev/null 2>&1
fi

if [ -e /mnt/root/bin/mount -a ! -e /mnt/root/notrootfs ]; then
  USING="SD card"
else 
  insmod -q -f /ts7xxx_nand.o >/dev/null 2>&1
  umount /mnt/root >/dev/null 2>&1
  mount -t yaffs2 /dev/mtdblock/3 /mnt/root >/dev/null 2>&1
  USING="onboard flash"
fi 

export CONSOLE=/dev/ttyAM0
stty -F $CONSOLE ospeed 115200 >/dev/null 2>&1
setcons  <$CONSOLE >$CONSOLE 2>&1
echo ">> Booting Linux (using $USING)..." >$CONSOLE
echo ">> ....">$CONSOLE

#///////////////////////////////////////////////////////////
#// now go and start the kernel
#///////////////////////////////////////////////////////////
cd /mnt/root
ls /mnt/root/bin/pivot_root

pivot_root . initrd
./bin/mount -n --move initrd/dev dev
./bin/mount -n --move initrd/proc proc
exec ./usr/sbin/chroot . ./sbin/init <.$CONSOLE >.$CONSOLE 2>&1

