441 lines
9.2 KiB
Bash
441 lines
9.2 KiB
Bash
#!/bin/sh
|
|
set -o vi
|
|
# set -x
|
|
|
|
if [ -z $SAN_SERVER_IP ]; then
|
|
SAN_SERVER_IP=10.23.135.17
|
|
fi
|
|
|
|
DESCR=""
|
|
descr(){
|
|
# echo "$1"
|
|
DESCR="$DESCR\n$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
|
|
#
|
|
descr ""
|
|
descr " GDB"
|
|
descr " setup_gdb - "
|
|
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
|
|
cp -r /nvram/tools /tmp/tools2
|
|
#export APIB_GDBSERVER="/tmp/tools2/strace -f"
|
|
#export APIB_GDBSERVER="/tmp/tools2/gdbserver :5555"
|
|
export APP_GDBSERVER="/tmp/tools2/gdbserver :5555"
|
|
#/tmp/tools2/gdbserver :5557 --attach \$(pgrep ZipMountServer)
|
|
#no watch dog
|
|
export appargs="-nowd"
|
|
# sh -c "while true ; do noreset; sleep 5; done"
|
|
EOF
|
|
}
|
|
|
|
descr " enable_gdb - "
|
|
enable_gdb()
|
|
{
|
|
grep launch_gdb.sh /nvram/autostart > /dev/null
|
|
if [ $? != 0 ]; then
|
|
echo "source /nvram/launch_gdb.sh" >> /nvram/autostart
|
|
fi
|
|
}
|
|
|
|
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
|
|
#
|
|
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
|
|
#
|
|
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
|
|
#
|
|
|
|
descr ""
|
|
descr " 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
|
|
#
|
|
descr ""
|
|
descr " 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'
|
|
|
|
################################################################################
|
|
#
|
|
# 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=192.168.0.64
|
|
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
|
|
|
|
|