522 lines
12 KiB
Bash
522 lines
12 KiB
Bash
#!/bin/sh
|
|
set -o vi
|
|
# set -x
|
|
alias ll='ls -la'
|
|
|
|
|
|
[ -f /nvram/san.conf ] && source /nvram/san.conf
|
|
__config(){
|
|
if [ -z $MASTER_IP ]; then
|
|
MASTER_IP=192.168.0.64
|
|
fi
|
|
[ ! -f /nvram/san.conf ] && echo "MASTER_IP=$MASTER_IP" >> /nvram/san.conf
|
|
}
|
|
__config
|
|
|
|
|
|
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"
|
|
}
|
|
|
|
__descr " update_san - update this script."
|
|
update_san()
|
|
{
|
|
|
|
wget -O /nvram/san http://$MASTER_IP/roku/san/san
|
|
source /nvram/san
|
|
}
|
|
|
|
__descr " upload - upload through tftp. e.g. upload /dev/ltcore"
|
|
upload()
|
|
{
|
|
[ -e $1 ] && tftp -r $(basename $1) -l $1 -p $MASTER_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
|
|
|
|
set_image_dir()
|
|
{
|
|
case $ROKU_PLATFORM in
|
|
lockhart)
|
|
IMAGE_DIR="port/realtek/stark/$ROKU_PLATFORM"
|
|
;;
|
|
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://$MASTER_IP/roku/$1"
|
|
echo "Downloading ${ACRAMFS_URL}"
|
|
wget -O ${ACRAMFS} ${ACRAMFS_URL}
|
|
if [ $? -ne 0 ]; then
|
|
echo "Download failed."
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
update_firmware()
|
|
{
|
|
local MMC_ACTIVE_DEV=/dev/mmc_Active
|
|
local MMC_UPDATE_DEV=/dev/mmc_Update
|
|
local SWUP_DEV=/dev/swupdev
|
|
local SWUP_PROC=/proc/swupdev
|
|
|
|
if [ "$ROKU_PLATFORM" == "rockett" ]; then
|
|
MMC_UPDATE_DEV=/dev/mtdblock_Update
|
|
fi
|
|
|
|
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|svin|nrd|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"
|
|
;;
|
|
svin)
|
|
BUILD_AREA="firmware/main"
|
|
;;
|
|
cert)
|
|
BUILD_AREA="firmware/nrd6.1_r12.0"
|
|
;;
|
|
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]"
|
|
#copy_tools()
|
|
#{
|
|
# #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/
|
|
}
|
|
|
|
__descr " tail_dmesg - "
|
|
tail_dmesg()
|
|
{
|
|
while true; do
|
|
dmesg -c
|
|
done
|
|
}
|
|
|
|
###############################################################################v
|
|
# Tools
|
|
#
|
|
__header "Tools"
|
|
|
|
__descr " zms_client <action> <mount> <file> {<swapto>} "
|
|
zms_client()
|
|
{
|
|
if [ "$1" == "" -o "$1" == "help" ]; then
|
|
echo "zms_client <action> <mount> <file> {<swapto>}"
|
|
return
|
|
fi
|
|
local MSG="{ \"action\":\"$1\","
|
|
|
|
[ "$2" != "" ] && MSG="$MSG \"mount\":\"$2\", "
|
|
[ "$3" != "" ] && MSG="$MSG \"file\":\"$3\", "
|
|
[ "$4" != "" ] && MSG="$MSG \"swapto\":\"$4\", "
|
|
|
|
MSG="$MSG \"type\":\"zip\", \"uid\":501, \"gid\":501, \"flags\":0 }"
|
|
|
|
set -x
|
|
plethora msg-send /zip-client "$MSG"
|
|
plethora msg-receive /zip-server
|
|
set +x
|
|
}
|
|
|
|
zms_hotswap_stress_test()
|
|
{
|
|
local PLUGIN="/nvram/plugins/$1.zip"
|
|
local PLUGIN_COPY="/tmp/$1.zip"
|
|
cp $PLUGIN $PLUGIN_COPY
|
|
|
|
# local MPOINT=$(zms_client query $PLUGIN | sed -e 's/^.*"mount":"\([^"]*\)".*$/\1/')
|
|
local MPOINT=/tmp/hotswap_test
|
|
mkdir $MPOINT
|
|
zms_client mount "$MPOINT" "$PLUGIN_COPY" "$PLUGIN"
|
|
while true; do
|
|
zms_client hotswap "$MPOINT" "$PLUGIN" "$PLUGIN_COPY"
|
|
zms_client hotswap "$MPOINT" "$PLUGIN_COPY" "$PLUGIN"
|
|
done
|
|
}
|
|
|
|
|
|
################################################################################
|
|
#
|
|
# 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
|
|
}
|
|
|
|
|
|
################################################################################
|
|
#
|
|
# bug reproduce
|
|
#
|
|
|
|
|
|
|
|
################################################################################
|
|
#
|
|
# Done
|
|
#
|
|
__descr " setup_san - "
|
|
setup_san()
|
|
{
|
|
# Copy GDB and other tools to nvram.
|
|
[ ! -d /nvram/tools ] && [ -d /tmp/tools ] && cp -rL /tmp/tools /nvram/
|
|
|
|
# Create autostart.
|
|
grep /nvram/san /nvram/autostart > /dev/null
|
|
if [ $? != 0 ]; then
|
|
cat > /nvram/autostart << EOF
|
|
#!/bin/sh
|
|
MASTER_IP=$MASTER_IP
|
|
mount /nvram -o remount,exec
|
|
sh -c "while true ; do noreset; sleep 5; done" &
|
|
EOF
|
|
fi
|
|
ConfigService -so fw.apibroker.failsafe-disable=true
|
|
ConfigService -so fw.fastboot.capture.snapshot=false
|
|
ConfigService -so fw.system.cs-boot-loop-count=20
|
|
}
|
|
|