#!/bin/sh
# Copyright (c) 2006, Technologic Systems.
# All rights reserved.
#
# Roots to USB flash dongle, assumes partition #1. 
# symlink to /linuxrc and run "save" to use

mount -t proc proc /proc

export CONSOLE=/dev/ttyAM0

(
  b="/dev/scsi/host0/bus0/target0/lun0/part1"
  insmod /ts7xxx_nand.o
  mount -o ro /dev/mtdblock/3 /mnt/root
  for m in usbcore pcipool usb-ohci usb-ohci-ep93xx scsi_mod sd_mod usb-storage fat vfat; do
    insmod -q $m
  done 
  umount /mnt/root
  t=0
  while test $t -lt 15 -a ! -b $b; do
    let t=$t+1;
    sleep 1;
  done
  mount -o ro $b /mnt/root
) >/dev/null 2>&1

cd /proc
if [ -e /mnt/root/fastboot -o ! -e /mnt/root/bin/mount ]; then
  (
  export BOOTTIME=`eptime`
  export ENV=/shinit
  setcons
  ifconfig eth0 192.168.0.50
  cd /mnt/root
  telnetd
  exec sh -i
  ) <$CONSOLE >$CONSOLE 2>&1
  killall busybox
fi
 
(
stty -F $CONSOLE ospeed 115200 >/dev/null 2>&1 
echo ">> Booting Linux..." 
setcons
) >$CONSOLE <$CONSOLE 2>&1

cd /mnt/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
