Adding scripts for bringup.
Change-Id: I17d7f5a35401121ea1b6137d182d1938800fa33a
diff --git a/y2019/vision/tools/Jevois_fstab b/y2019/vision/tools/Jevois_fstab
new file mode 100644
index 0000000..6b44012
--- /dev/null
+++ b/y2019/vision/tools/Jevois_fstab
@@ -0,0 +1,9 @@
+/dev/root / ext4 ro,flush,noatime,noauto 0 0
+devpts /dev/pts devpts defaults,gid=5,mode=620 0 0
+tmpfs /dev/shm tmpfs mode=0777 0 0
+tmpfs /tmp tmpfs mode=1777 0 0
+tmpfs /run tmpfs mode=0755,nosuid,nodev 0 0
+sysfs /sys sysfs defaults 0 0
+debugfs /sys/kernel/debug debugfs defaults 0 0
+/dev/mmcblk0p1 /boot vfat ro,flush,noatime,umask=000 0 0
+/dev/mmcblk0p3 /jevois ext4 rw,noatime 0 0
diff --git a/y2019/vision/tools/austin_cam.sh b/y2019/vision/tools/austin_cam.sh
new file mode 100755
index 0000000..063b7dc
--- /dev/null
+++ b/y2019/vision/tools/austin_cam.sh
@@ -0,0 +1,142 @@
+#!/bin/sh
+
+##############################################################################################################
+# Default settings:
+##############################################################################################################
+
+CAMERA=ov9650
+if [ -f /boot/sensor ]; then CAMERA=`tail -1 /boot/sensor`; fi
+
+use_usbserial=1 # Allow using a serial-over-USB to communicate with JeVois command-line interface
+use_usbsd=1 # Allow exposing the JEVOIS partition of the microSD as a USB drive
+use_serialtty=0 # Use a TTY on the hardware serial and do not use it in jevois-daemon
+use_usbserialtty=0 # Use a TTY on the serial-over-USB and do not use it in jevois-daemon
+use_maxbandwidth=1 # Use 100% of isochronous bandwidth to minimize latency; disable to connect several cameras
+use_quietcmd=0 # Do not say OK after every good command when true
+use_nopython=0 # Disable python to save memory when true
+
+if [ -f /boot/nousbserial ]; then use_usbserial=0; echo "JeVois serial-over-USB disabled"; fi
+if [ -f /boot/nousbsd ]; then use_usbsd=0; echo "JeVois microSD access over USB disabled"; fi
+if [ -f /boot/multicam ]; then use_maxbandwidth=0; echo "JeVois multi-camera mode enabled"; fi
+if [ -f /boot/quietcmd ]; then use_quietcmd=1; echo "JeVois quiet command-line mode enabled"; fi
+if [ -f /boot/nopython ]; then use_nopython=1; echo "JeVois python support disabled"; fi
+
+# Block device we present to the host as a USB drive, or empty to not present it at start:
+usbsdfile=""
+if [ -f /boot/usbsdauto ]; then usbsdfile="/dev/mmcblk0p3"; echo "JeVois microSD access over USB is AUTO"; fi
+
+# Login prompts over hardware serial or serial-over-USB:
+if [ -f /boot/serialtty ]; then use_serialtty=1; echo "Using tty on JeVois hardware serial"; fi
+if [ "X${use_usbserial}" != "X1" ]; then use_usbserialtty=0;
+elif [ -f /boot/usbserialtty ]; then use_usbserialtty=1; echo "Using tty on JeVois serial-over-USB"; fi
+
+##############################################################################################################
+# Load all required kernel modules:
+##############################################################################################################
+
+cd /lib/modules/3.4.39
+
+for m in videobuf-core videobuf-dma-contig videodev vfe_os vfe_subdev v4l2-common v4l2-int-device \
+ cci ${CAMERA} vfe_v4l2 ump disp mali ; do
+ if [ $m = "vfe_v4l2" ]; then
+ echo "### insmod ${m}.ko sensor=${CAMERA} ###"
+ insmod ${m}.ko sensor="${CAMERA}"
+ else
+ echo "### insmod ${m}.ko ###"
+ insmod ${m}.ko
+ fi
+done
+
+##############################################################################################################
+# Install any new packages:
+##############################################################################################################
+
+cd /jevois
+for f in packages/*.jvpkg; do
+ if [ -f "${f}" ]; then
+ echo "### Installing package ${f} ###"
+ bzcat "${f}" | tar xvf -
+ sync
+ rm -f "${f}"
+ sync
+ fi
+done
+
+##############################################################################################################
+# Find any newly unpacked postinstall scripts, run them, and delete them:
+##############################################################################################################
+
+for f in modules/*/*/postinstall; do
+ if [ -f "${f}" ]; then
+ echo "### Running ${f} ###"
+ d=`dirname "${f}"`
+ cd "${d}"
+ sh postinstall
+ sync
+ rm -f postinstall
+ sync
+ cd /jevois
+ fi
+done
+
+##############################################################################################################
+# Build a default videomappings.cfg, if missing:
+##############################################################################################################
+
+if [ ! -f /jevois/config/videomappings.cfg ]; then
+ echo 'YUYV 640 360 30.0 YUYV 320 240 30.0 JeVois JeVoisIntro *' > /jevois/config/videomappings.cfg
+ echo 'YUYV 640 480 30.0 YUYV 320 240 30.0 JeVois JeVoisIntro' >> /jevois/config/videomappings.cfg
+fi
+
+##############################################################################################################
+# Get a list of all our needed library paths:
+##############################################################################################################
+
+LIBPATH="/lib:/usr/lib"
+for d in `find /jevois/lib -type d -print`; do LIBPATH="${LIBPATH}:${d}"; done
+export LD_LIBRARY_PATH=${LIBPATH}
+
+##############################################################################################################
+# Insert the gadget driver:
+##############################################################################################################
+
+echo "### Insert gadget driver ###"
+MODES=`/usr/bin/jevois-module-param ${CAMERA}`
+
+echo $MODES
+
+insmodopts=""
+if [ "X${use_usbsd}" = "X1" ]; then insmodopts="${insmodopts} file=${usbsdfile}"; fi
+
+insmod /lib/modules/3.4.39/g_jevoisa33.ko modes=${MODES} use_serial=${use_usbserial} \
+ use_storage=${use_usbsd} max_bandwidth=${use_maxbandwidth} ${insmodopts}
+echo insmod /lib/modules/3.4.39/g_jevoisa33.ko modes=${MODES} use_serial=${use_usbserial} \
+ use_storage=${use_usbsd} max_bandwidth=${use_maxbandwidth} ${insmodopts}
+
+##############################################################################################################
+# Launch jevois-daemon:
+##############################################################################################################
+
+/jevois/deploy/launch.sh
+
+echo "### Start jevois daemon ###"
+opts=""
+if [ "X${use_usbserial}" != "X1" -o "X${use_usbserialtty}" = "X1" ]; then opts="${opts} --usbserialdev="; fi
+if [ "X${use_serialtty}" = "X1" ]; then opts="${opts} --serialdev="; fi
+if [ "X${use_maxbandwidth}" != "X1" ]; then opts="${opts} --multicam=1"; fi
+if [ "X${use_quietcmd}" = "X1" ]; then opts="${opts} --quietcmd=1"; fi
+if [ "X${use_nopython}" = "X1" ]; then opts="${opts} --python=0"; fi
+if [ "X${CAMERA}" != "X" ]; then opts="${opts} --camerasens=${CAMERA}"; fi
+
+if [ ! -f /tmp/do_not_export_sd_card ]; then
+ sync
+ echo "### FALLBACK remount ###"
+ mount -o remount,ro /jevois || exit
+ echo "### FALLBACK disk publish (Device is unusable after this point...) ###"
+ echo /dev/mmcblk0p3 > /sys/devices/platform/sunxi_usb_udc/gadget/lun0/file
+fi
+
+
+# Start the jevois daemon:
+echo /usr/bin/jevois-daemon ${opts}
+/usr/bin/jevois-daemon ${opts}
diff --git a/y2019/vision/tools/deploy.sh b/y2019/vision/tools/deploy.sh
new file mode 100755
index 0000000..4ad926f
--- /dev/null
+++ b/y2019/vision/tools/deploy.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+echo "Mount jevois ..."
+./jevois-cmd usbsd
+
+echo "Waiting for fs ..."
+while [ ! -d /media/$USER/JEVOIS ]
+do
+ sleep 1
+done
+echo "OK"
+
+echo "Copying files ..."
+cp ./austin_cam.sh /media/$USER/JEVOIS/
+
+echo "Unmount sd card ..."
+umount /media/$USER/JEVOIS
+echo "OK"
+
+echo "Rebooting Jevois."
+./jevois-cmd restart
diff --git a/y2019/vision/tools/flash.sh b/y2019/vision/tools/flash.sh
new file mode 100755
index 0000000..5daad73
--- /dev/null
+++ b/y2019/vision/tools/flash.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+if [ "$(id -u)" != "0" ]
+then
+ echo "Please run as root: $(id -u)"
+ exit
+fi
+
+DEV_BASE=/dev/mmcblk0p
+
+echo "Please check that ${DEV_BASE}3 is the correct drive to format. This is a destructive command so please be sure."
+read -p "Enter \"yes\" when you are ready: " input
+
+if [ "$input" != "yes" ]
+then
+ echo "Format aborted."
+ exit -1
+fi
+
+# need to disable some new features on 17.x
+sudo mkfs.ext4 -L JEVOIS -O ^64bit,uninit_bg,^metadata_csum ${DEV_BASE}3
+
+echo "Mounting JEVOIS."
+mkdir -p /tmp/JEVOIS
+sudo mount ${DEV_BASE}3 /tmp/JEVOIS
+
+echo "Mounting LINUX."
+mkdir -p /tmp/LINUX
+sudo mount ${DEV_BASE}2 /tmp/LINUX
+
+echo "Make JEVOIS directories."
+mkdir -p /tmp/JEVOIS/packages
+mkdir -p /tmp/JEVOIS/modules
+mkdir -p /tmp/JEVOIS/config
+mkdir -p /tmp/JEVOIS/lib
+
+echo "Copy configs."
+cp ./austin_cam.sh /tmp/JEVOIS
+cp ./videomappings.cfg /tmp/JEVOIS/config/
+cp ./rcS_script.txt /tmp/LINUX/etc/init.d/rcS
+cp Jevois_fstab /tmp/LINUX/etc/fstab
+
+echo "Un-mounting JEVOIS"
+sudo umount /tmp/JEVOIS
+
+echo "Un-mounting LINUX"
+sudo umount /tmp/LINUX
+
+
diff --git a/y2019/vision/tools/jevois-cmd b/y2019/vision/tools/jevois-cmd
new file mode 100755
index 0000000..6fe19d3
--- /dev/null
+++ b/y2019/vision/tools/jevois-cmd
@@ -0,0 +1,39 @@
+#!/bin/bash
+# USAGE: jevois-cmd [-d /dev/ttyACMX] command
+#
+# Send a command to a connected JeVois camera using the serial-over-USB port
+#
+# Tip: If things appear garbled in some way, maybe your TTY settings got messed up. Run screen /dev/ttyACM0 115200 to
+# reset to the expected state.
+#
+# You may need to install: sudo apt install python-serial
+
+ttydev="/dev/ttyACM0"
+if [ "X$1" = "X-d" ]; then ttydev=$2; shift 2; fi
+
+if [ ! -c "$ttydev" ]; then echo "Cannot access $ttydev -- is JeVois plugged in? -- ABORT"; exit 1; fi
+
+# Set the tty flags:
+sudo stty -F "${ttydev}" sane raw igncr clocal cread -echo
+
+# First read any accumulated junk in the serial buffers:
+while true; do
+ sudo bash -c "read -s -t 0.05 < \"${ttydev}\""
+ if [ $? -ne 0 ]; then break; fi
+done
+
+# Make a python program:
+prog="import serial
+ser = serial.Serial('$ttydev', 115200, timeout=1)
+ser.write('$*\n')
+nothing=1
+out = ''
+while nothing or ser.inWaiting() > 0:
+ out += ser.read(1)
+ nothing=0
+if out != '':
+ print out,
+"
+
+# Send the command:
+sudo python2.7 -c "$prog"
diff --git a/y2019/vision/tools/launch.sh b/y2019/vision/tools/launch.sh
new file mode 100755
index 0000000..f2bd68d
--- /dev/null
+++ b/y2019/vision/tools/launch.sh
@@ -0,0 +1 @@
+touch /tmp/do_not_export_sd_card
diff --git a/y2019/vision/tools/rcS_script.txt b/y2019/vision/tools/rcS_script.txt
new file mode 100644
index 0000000..3909a6e
--- /dev/null
+++ b/y2019/vision/tools/rcS_script.txt
@@ -0,0 +1,6 @@
+#!/bin/sh
+hostname jevois
+MODULES_DIR=/lib/modules/3.4.39
+
+if [ ! -f /boot/login ]; then /jevois/austin_cam.sh
+else while true; do /sbin/getty -L ttyS0 115200 vt100; done; fi
diff --git a/y2019/vision/tools/videomappings.cfg b/y2019/vision/tools/videomappings.cfg
new file mode 100644
index 0000000..395cbe4
--- /dev/null
+++ b/y2019/vision/tools/videomappings.cfg
@@ -0,0 +1,2 @@
+YUYV 640 360 30.0 YUYV 640 480 30.0 JeVois PassThrough *
+YUYV 640 480 30.0 YUYV 640 480 30.0 JeVois PassThrough