Initial commit.

This commit is contained in:
2022-03-16 16:07:41 +00:00
commit 3dc93a52a1

281
san Normal file
View File

@@ -0,0 +1,281 @@
#!/bin/sh
set -o vi
# set -x
SERVER_IP=192.168.0.63
DESCR=""
descr(){
# echo "$1"
DESCR="$DESCR\n$1"
}
descr "Available Commands:"
descr " san_help - print this help."
san_help()
{
printf "$DESCR\n"
}
descr " update_san - update this script."
update_san()
{
tftp -r san -l /nvram/san -g $SERVER_IP
source /nvram/san
}
descr " upload - upload through tftp. e.g. upload /dev/ltcore"
upload()
{
tftp -r $(basename $1) -l $1 -g $SERVER_IP
}
descr " app_config - "
app_config()
{
telnet 127.0.0.1 8080
}
descr " factory_reset - "
factory_reset()
{
touch /nvram/factoryresetflag2 && reboot
}
################################################################################
#
# Firmware flash.
#
ACRAMFS=/tmp/acramfs.bin
MMC_UP_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_firmware()
{
BRANCH_DIR="roku/main"
set_image_dir
ACRAMFS_URL="http://$SERVER_IP/${BRANCH_DIR}/${IMAGE_DIR}/dist/image/acramfs/acramfs.bin"
echo "Downloading ${ACRAMFS_URL}"
wget -O ${ACRAMFS} ${ACRAMFS_URL}
[ $? -eq 0 ] || exit
}
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_UP_DEV ]; then
dd if=${ACRAMFS} of=$MMC_UP_DEV bs=65536
else
rm -f ${ACRAMFS}
echo 'Cannot update this platform' >&2
false
fi
}
descr " rokuflash - "
rokuflash()
{
download_firmware
update_firmware
}
descr " rokuflashgold - "
rokuflashgold()
{
ACRAMFS_URL="http://$SERVER_IP/acramfs.${ROKU_PLATFORM}.bin"
echo "Downloading ${ACRAMFS_URL}"
wget -O ${ACRAMFS} ${ACRAMFS_URL}
update_firmware
}
###############################################################################v
# Ddd to the start of the script
# export APP_GDBSERVER="/nvram/tools/gdbserver :5555"ebug Server
#
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:
mkdir /nvram/debug_overlay
#enable gdbserver to /etc/autostart script
#add to the start of the script
grep APP_GDBSERVER /nvram/autostart
if [ $? != 0 ]; then
echo "export APP_GDBSERVER=\"/nvram/tools/gdbserver :5555\"" >> /nvram/autostart
fi
}
################################################################################
#
# Fastboot related
#
descr " enable_fastboot - "
enable_fastboot()
{
echo "
{
\"configi\" : {
\"fw.fastboot.capture.snapshot\": \"true\"
}
}" > /nvram/CSOverride.json
}
descr " disable_fastboot - "
disable_fastboot()
{
echo "
{
\"configi\" : {
\"fw.fastboot.capture.snapshot\": \"false\"
}
}" > /nvram/CSOverride.json
}
descr " remove_config - "
remove_config()
{
rm /nvram/CSOverride.json
}
################################################################################
#
# Wifi Setup
#
IFACE=wlan0
wpa()
{
wpa_cli -p /tmp/wpa_ctrl -i $IFACE "$@"
}
set_office_network()
{
SSID="roku-npi-vahagn"
PSK="ahovwxy@.0"
}
set_home_network()
{
SSID="vodafone399827"
PSK="v98AkhachA+1Vika33831294215495"
}
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 ] || set_home_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
}
alias ll='ls -la'
################################################################################
#
# Done
#
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