#!/bin/sh
#
# Start logging
#

# Key to unlock the u-boot environment
KEY=`cat /etc/fw_env.key`

start() {
        echo -n "Checking if tp143 is connected to enable debug functionality: "
        echo "120" > /sys/class/gpio/export
        echo "in" > /sys/class/gpio/gpio120/direction
        STATE=`cat /sys/class/gpio/gpio120/value`


        if [ $STATE == 0 ];
        then
                echo "Enable debug port"
                fw_setenv -a ${KEY} console "ttyAMA0,115200"
        else
                echo "Disable debug port"
                fw_setenv -a ${KEY} console "null"
        fi
        echo "120" > /sys/class/gpio/unexport

}


case "$1" in
  start)
        start
        ;;
  stop)
        ;;
  restart|reload)
        stop
        start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $?

