#!/bin/sh
# The following code detects if something is connected to USB port 0,
# and if so checks for a flash drive with /tsinit to execute.

. /ts7xxx.subr
usb_init
TMP=`usb_port_devexists 0`
if test "$TMP" = "1"; then
  led1 1
  insmod /ts7xxx_nand.o
  mount -o ro /dev/mtdblock/3 /mnt/root
  insmod -q usbcore
  insmod -q pcipool
  insmod -q usb-ohci
  insmod -q usb-ohci-ep93xx
  insmod -q scsi_mod
  insmod -q sd_mod
  insmod -q usb-storage
  insmod -q fat
  insmod -q vfat
  umount /mnt/root
  TMP=0
  while test $TMP -lt 15 -a ! -b /dev/scsi/host0/bus0/target0/lun0/part1; do 
    let TMP=$TMP+1; 
    sleep 1; 
  done
  if test -b /dev/scsi/host0/bus0/target0/lun0/part1; then
    mount -o ro /dev/scsi/host0/bus0/target0/lun0/part1 /mnt/root
    if test -x /mnt/root/tsinit; then
      /mnt/root/tsinit < /dev/console > /dev/console 2>&1
    fi
    umount /mnt/root
  fi
  led1 0
else
  usb_off
fi
