Files
san/san

489 lines
10 KiB
Bash

#!/bin/sh
set -o vi
# set -x
if [ -z $SAN_SERVER_IP ]; then
SAN_SERVER_IP=192.168.0.64
fi
DESCR=""
descr(){
# echo "$1"
DESCR="$DESCR\n$1"
}
header(){
descr ""
descr " * $1"
}
descr "Available Commands:"
descr " san_help - print this help."
san_help()
{
printf "$DESCR\n"
}
UPDATE_SAN="wget -O /nvram/san http://$SAN_SERVER_IP/roku/san/san"
descr " update_san - update this script."
descr " Manually: $UPDATE_SAN"
update_san()
{
eval $UPDATE_SAN
source /nvram/san
}
descr " upload - upload through tftp. e.g. upload /dev/ltcore"
upload()
{
[ -e $1 ] && tftp -r $(basename $1) -l $1 -p $SAN_SERVER_IP
}
descr " upload_core - upload /dev/ltcore"
upload_core()
{
upload /dev/ltcore
}
descr " app_config - "
app_config()
{
telnet 127.0.0.1 8080
}
descr " factory_reset - "
factory_reset()
{
touch /nvram/factoryresetflag2 && reboot
}
descr " disable_wd - disable watchdog"
disable_wd()
{
sh -c "while true ; do noreset; sleep 5; done" &
}
################################################################################
#
# Firmware flash.
#
ACRAMFS=/tmp/acramfs.bin
MMC_ACTIVE_DEV=/dev/mmc_Active
MMC_UPDATE_DEV=/dev/mmc_Update
SWUP_DEV=/dev/swupdev
SWUP_PROC=/proc/swupdev
set_image_dir()
{
case $ROKU_PLATFORM in
bailey)
IMAGE_DIR="port/realtek/stark/$ROKU_PLATFORM"
;;
marlin)
IMAGE_DIR="port/realtek/hank/$ROKU_PLATFORM"
;;
*)
exit
;;
esac
}
download_from_buildarea()
{
set_image_dir
ACRAMFS_URL="$1/${IMAGE_DIR}/dist/image/acramfs/acramfs.bin"
download_firmware "${ACRAMFS_URL}"
}
download_firmware()
{
ACRAMFS_URL="http://$SAN_SERVER_IP/roku/$1"
echo "Downloading ${ACRAMFS_URL}"
wget -O ${ACRAMFS} ${ACRAMFS_URL}
if [ $? -ne 0 ]; then
echo "Download failed."
return 1
fi
}
update_firmware()
{
if [ -c $SWUP_DEV ]; then
dd if=${ACRAMFS} of=$SWUP_DEV bs=65536
echo -n memlock >$SWUP_PROC
echo -n writeswupmagic >$SWUP_PROC
echo -n commit >$SWUP_PROC
elif [ -b $MMC_UPDATE_DEV ]; then
if [ "$1" == "active" -o "$1" == "both" ]; then
echo "Flashing $MMC_ACTIVE_DEV"
[ -b "$MMC_ACTIVE_DEV" ] && dd if=${ACRAMFS} of=$MMC_ACTIVE_DEV bs=65536
fi
if [ "$1" == "update" -o "$1" == "both" ]; then
echo "Flashing $MMC_UPDATE_DEV"
dd if=${ACRAMFS} of=$MMC_UPDATE_DEV bs=65536
fi
else
rm -f ${ACRAMFS}
echo 'Cannot update this platform' >&2
false
fi
}
descr " rokuflash [active|both] [main|main2|bailey_cert|golden|<acramfs path>] - empty flashes from build area"
rokuflash()
{
REMOTE_ACRAMFS=""
UPDATE_PARTITION="update"
BUILD_AREA="main"
while [ $# -gt 0 ]; do
case "$1" in
active|both)
UPDATE_PARTITION="$1"
;;
main|main2)
BUILD_AREA="$1"
;;
bailey_cert)
BUILD_AREA="r10.5.0.13000"
;;
golden)
REMOTE_ACRAMFS="golden/acramfs.${ROKU_PLATFORM}.bin"
;;
*)
REMOTE_ACRAMFS="$1"
;;
esac
shift
done
if [ -z "$REMOTE_ACRAMFS" ]; then
download_from_buildarea "$BUILD_AREA"
else
download_firmware $REMOTE_ACRAMFS
fi
[ $? -eq 0 ] && update_firmware $UPDATE_PARTITION
[ $? -eq 0 ] && fastboot_reset
}
###############################################################################v
# Ddd to the start of the script
# export APP_GDBSERVER="/nvram/tools/gdbserver :5555"ebug Server
#
header "GDB"
#descr " setup_gdb [seconds|app|zipmountserver|apibroker|apitrace]"
#setup_gdb()
#{
# #copy tools to /nvram folder for example:
# cp -rL /tmp/tools /nvram/
# #remount nvram with executable flag executable
# # mount /nvram -o remount,exec
# #make nvram to preserve the exec flag after reboot:
# # kdir /nvram/debug_overlay
# # Create debug script, where we copy gdb back to tmp and run it from there.
# # This is to allow fastboot to umount /nvram
##cat > /nvram/launch_gdb.sh << EOF
###!/bin/sh
###export APIB_GDBSERVER="/tmp/tools2/strace -f"
##EOF
#}
launch_gdb()
{
cp -r /nvram/tools /tmp/tools2
export appargs="-nowd"
local delay=0
if [ "$1" == "" ]; then
delay = 5
elif [ "$1" == "apibroker" ]; then
export APIB_GDBSERVER="/tmp/tools2/gdbserver :5555"
elif [ "$1" == "apitrace" ]; then
export APIB_GDBSERVER="/tmp/tools2/strace -f"
elif [ "$1" == "app" ]; then
export APP_GDBSERVER="/tmp/tools2/gdbserver :5555"
elif [ "$1" == "zipmountserver" ]; then
/tmp/tools2/gdbserver :5557 --attach $(pgrep ZipMountServer)
else
delay = $1
fi
if [ $delay != 0 ]; then
sh -c "while true; do apid=\$(pgrep Application); [ \$? == 0 ] && break; done; echo \$apid; sleep $1; /tmp/tools2/gdbserver :5555 --attach \$apid " &
fi
}
descr " enable_gdb [seconds|app|zipmountserver|apibroker|apitrace]"
enable_gdb()
{
[ ! -f /nvram/tools/gdbserver ] && cp -rL /tmp/tools /nvram/
[ -f /nvram/autostart ] && cat /nvram/autostart | sed '/launch_gdb/d' > /tmp/autostart
local cmd="app"
[ "$1" != "" ] && cmd=$1
echo "launch_gdb $cmd" >> /tmp/autostart
rm /nvram/autostart
mv /tmp/autostart /nvram/
}
descr " disable_gdb - "
disable_gdb()
{
[ -f /nvram/autostart ] && cat /nvram/autostart | sed '/launch_gdb/d' > /tmp/autostart
rm /nvram/autostart
mv /tmp/autostart /nvram/
}
################################################################################
#
# Log
#
header "LOG"
LOG_CONF="/nvram/logapi.conf"
descr " log_reset - reset log configuration"
log_reset()
{
[ -f $LOG_CONF ] && rm $LOG_CONF
echo "+T" >> $LOG_CONF
echo "+e" >> $LOG_CONF
}
descr " log_all - log everything"
log_all()
{
echo "+c *" >> $LOG_CONF
}
descr " log_seconds - show seconds."
log_seconds()
{
echo "+e" >> $LOG_CONF
}
################################################################################
#
# Config
#
header "Config"
descr " config_reset - erase configuration"
config_reset()
{
su app -c "ConfigService -ro"
}
descr " config_list - "
config_list()
{
su app -c "ConfigService -lo"
}
config_enable()
{
su app -c "ConfigService -so $1=true"
}
config_disable()
{
su app -c "ConfigService -so $1=true"
}
descr " disable_failsafe - "
disable_failsafe()
{
config_enable "fw.apibroker.failsafe-disable"
}
################################################################################
#
# Fastboot related
#
header "FastBoot"
descr " enable_fastboot - "
enable_fastboot()
{
su app -c "ConfigService -so fw.fastboot.capture.snapshot=true"
su app -c "ConfigService -so fw.fastboot.force.enable.snapshot=true"
fastboot_reset
}
descr " disable_fastboot - "
disable_fastboot()
{
su app -c "ConfigService -so fw.fastboot.capture.snapshot=false"
fastboot_reset
}
descr " enable_fastboot2 - "
enable_fastboot2()
{
su app -c "ConfigService -so fw.fastboot.snapshot-after-precompile=true"
fastboot_reset
}
descr " disable_fastboot2 - "
disable_fastboot2()
{
su app -c "ConfigService -so fw.fastboot.snapshot-after-precompile=false"
fastboot_reset
}
descr " fastboot_reset - "
fastboot_reset()
{
[ -e /dev/mapper/snapshotree ] && mkswap /dev/mapper/snapshotree
}
################################################################################
#
# Wifi Setup
#
header "WiFi"
IFACE=wlan0
wpa()
{
wpa_cli -p /tmp/wpa_ctrl -i $IFACE "$@"
}
set_office_network()
{
SSID="roku-npi-vahagn"
PSK="ahovwxy@.0"
}
descr " setup_wifi - "
setup_wifi()
{
rm -f /tmp/wpa_ctrl/$IFACE
wifi_reset
sleep 5
[ "$(wpa scan)" == "OK" ] || return 1
sleep 3
set_office_network
wpa scan_result | grep $SSID
[ $? == 0 ] || return 2
NETWORK=$(wpa add_network)
[ $(wpa set_network $NETWORK ssid \"$SSID\") == "OK" ] || return 3
[ $(wpa set_network $NETWORK psk \"$PSK\") == "OK" ] || return 4
# wpa set_network $NETWORK key_mgmt NONE
wpa enable_network $NETWORK
wpa save_config
sleep 3
IP=$(udhcpc -i $IFACE | sed -n 's/^.* \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\) .*$/\1/p')
echo "IP=$IP"
ip a add $IP/22 dev $IFACE
}
descr " setup_network - "
setup_network()
{
/sbin/udhcpc -i eth0 -s /etc/udhcpc.sh
}
alias ll='ls -la'
################################################################################
#
# Plugfest
#
descr " setup_plugfest - "
setup_plugfest()
{
[ -f $LOG_CONF ] && rm $LOG_CONF
echo "+c pal.hdmi.* " >> $LOG_CONF
echo "+c pal_player.hdmi.* " >> $LOG_CONF
echo "+c tv.hdmi.* " >> $LOG_CONF
echo "+c ui.hdmi.* " >> $LOG_CONF
echo "+c rtk.hdmiservice.* " >> $LOG_CONF
echo "+c edid.* " >> $LOG_CONF
echo "+Te" >> $LOG_CONF
disable_failsafe
disable_fastboot
}
################################################################################
#
# Done
#
descr " setup_san - "
setup_san()
{
grep /nvram/san /nvram/autostart > /dev/null
if [ $? != 0 ]; then
cat > /nvram/autostart << EOF
#!/bin/sh
SAN_SERVER_IP=$SAN_SERVER_IP
source /nvram/san
disable_wd
#setup_network
EOF
fi
}
san_help
# PROGNAME="${0##*/}"
# usage()
# {
# echo "Usage: $PROGNAME [-s] [-t] $0 firmware-build" >&2
# exit
# }
# ARGS=$(getopt fhstuec $*)
# if [ $? -ne 0 ]; then
# usage
# fi
# set -- $ARGS
# while [ $# -gt 0 ]; do
# case "$1" in
# -f)
# DEBUG_SERVER=false
# TFTP=true
# ;;
# -h)
# usage 0
# ;;
# -s)
# DEBUG_SERVER=false
# ;;
# -t)
# USE_TUNNEL=true
# ;;
# -u)
# download_firmware
# update_firmware
# exit
# ;;
# -e)
# enable_fastboot
# ;;
# -c)
# remove_config
# ;;
# --)
# shift
# break
# ;;
# esac
# shift
# done
# if [ $# -ne 1 ]; then
# usage
# fi