diff --git a/.profile.roku.dev b/.profile.roku.dev index 11f03a0..f7c5c76 100644 --- a/.profile.roku.dev +++ b/.profile.roku.dev @@ -1,197 +1,14 @@ #!/bin/sh -# I have my automake -export ACLOCAL_PATH=/usr/share/aclocal - -export ROKU_NFS_ROOT=$HOME/roku/nfs -export ROKU_NFS_IP=192.168.0.64 -export EXPORTROOT=${ROKU_NFS_ROOT} - - -export DEVPASSWORD=aaaa -_roku_device() -{ - if [ "$1" != "" ]; then - export ROKU_DEV_TARGET="$1" - export ROKU_DEV_PLATFORM="$(_roku.sh device_platform)" - fi - echo "device: $ROKU_DEV_TARGET" - echo "platform: $ROKU_DEV_PLATFORM" -} +source _roku_shared.sh roku() { - if [ "$1" = "device" -a "$2" != "info" ]; then - shift - _roku_device "$@" - else - _roku.sh "$@" - fi + _roku_dispatch "$@" } - -############################################################################### -# -# Build Completion -# -__roku_completion_contains() -{ - # Platforms - for WORD in "$@"; do - if [[ "${COMP_WORDS[*]}" =~ "$WORD" ]]; then - return 1 - fi - done - return 0 -} - -__roku_completion_add_if() -{ - __roku_completion_contains "$@" - if [[ $? == 0 ]]; then - CANDIDATES+=" $@" - fi -} - -# complete -F __build_completion roku -# __build_completion() -# { -# local CANDIDATES="help clobber tests addon-checksums" - -# # Docker -# __build_completion_add_if docker make - -# # Build hosts -# __build_completion_add_if icecc local - -# # Port dir -# __build_completion_add_if port-only - -# # Platforms -# __build_completion_add_if native marlin bailey loggan lockhart porting-kit streambar stb - -# COMPREPLY=($(compgen -W "$CANDIDATES" "${COMP_WORDS[${COMP_CWORD}]}")) -# } - complete -F __roku_completion roku -__roku_completion() -{ - local CANDIDATES="device get log flash telnet reboot audcap san_update sideload token_install" - # # Docker - # __build_completion_add_if docker make - - # # Build hosts - # __build_completion_add_if icecc local - - # # Port dir - # __build_completion_add_if port-only - - # # Platforms - # __build_completion_add_if native marlin bailey loggan lockhart porting-kit streambar stb - - COMPREPLY=($(compgen -W "$CANDIDATES" "${COMP_WORDS[${COMP_CWORD}]}")) -} - - -################################################################################ -## -## Set active roku device -## - -#rokutelnet() -#{ -# [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 -# telnet "$ROKU_DEV_TARGET" $1 -#} - -################################################################################ -## -## Run commands on active device -## -#__netcat() -#{ -# if [ "$1" != "" ]; then -# netcat -t $ROKU_DEV_TARGET $1 -# else -# netcat -t $ROKU_DEV_TARGET 23 -# fi -#} - -#__set_server_ip() -#{ -# SERVER_IP=$(ip route get "${ROKU_DEV_TARGET}" | sed -n "s/.* src \([\.0-9]*\) .*/\1/p") -#} - -#device_cmd() -#{ -# echo "$1; exit" | __netcat -#} - -#rokuflash() -#{ -# [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 -# __set_server_ip -# device_cmd ". /nvram/san; export SERVER_IP=$SERVER_IP; rokuflash $1" -#} - -#rokulog() -#{ -# [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 -# device_cmd "setconsole /dev/pts/0" -#} - -#rokureboot() -#{ -# [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 -# device_cmd "reboot" -#} - -#update_san() -#{ -# [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 -#} - -################################################################################ -## -## Retrieve audio. -## -#app_cmd() -#{ -#echo "$1 -#exit" | __netcat 8080 -#} - -#rokuaudcap() -#{ -# [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 -# __set_server_ip -# app_cmd "audcap record start 00" -# echo -n "Press Enter to stop capture." -# read -# app_cmd "audcap record stop" -# device_cmd "tftp -p -r $1.pcm -l /tmp/audcap_audio.pcm $SERVER_IP" -# sox -t raw -r 48000 -b 16 -c 2 -e signed-integer $1.pcm $1.wav -#} - -################################################################################ -## -## Work with channels. -## - -#install_auth_token() -#{ -# [ ! -f "$1" ] && echo "usage: install_auth_toke \n ROKU_DEV_TARGET=${ROKU_DEV_TARGET}" && return 0 -# [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 -# curl --data-binary @$1 http://${ROKU_DEV_TARGET}:8060/token/install -#} - -#sideload() -#{ -# [ ! -f "$1" ] && echo "usage: sideload \n ${ROKU_DEV_TARGET}=${ROKU_DEV_TARGET}" && return 0 -# [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 -# curl --anyauth --user "rokudev:${DEVPASSWORD}" -F "mysubmit=Install_Netflix" -F "archive=@$1" http://${ROKU_DEV_TARGET}/plugin_install -#} ############################################################################### # @@ -240,19 +57,3 @@ dtail() fi } -################################################################################ -## -## Misc -## - -#rokuget() -#{ -# [ -z "$1" ] && echo "usage: rokuget " && return 0 -# if [ -z "$ROKU_CORP_PASSWORD" ]; then -# local USER_PASSWORD="--ask-password" -# else -# local USER_PASSWORD="--password=$ROKU_CORP_PASSWORD" -# fi -# wget --no-check-certificate --user=vkhachatryan $USER_PASSWORD $1 -#} - diff --git a/_roku.sh b/_roku.sh index ada60f2..b21977c 100755 --- a/_roku.sh +++ b/_roku.sh @@ -1,13 +1,15 @@ #!/bin/bash +source _roku_shared.sh + ############################################################################### # # Helper functions # -__set_server_ip() +__set_master_ip() { - SERVER_IP=$(ip route get "${ROKU_DEV_TARGET}" | sed -n "s/.* src \([\.0-9]*\) .*/\1/p") + MASTER_IP=$(ip route get "${ROKU_DEV_TARGET}" | sed -n "s/.* src \([\.0-9]*\) .*/\1/p") } __netcat() @@ -33,7 +35,7 @@ __device_cmd() _roku_device_platform() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 - __device_cmd "echo \$ROKU_PLATFORM" | tail -1 + __device_cmd "echo \$ROKU_PLATFORM" | tail -1 | tr -d '\r\n' } @@ -50,16 +52,35 @@ _roku_telnet() _roku_flash() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 - __set_server_ip - __device_cmd ". /nvram/san; export SERVER_IP=$SERVER_IP; rokuflash $1" + __set_master_ip + __device_cmd ". /nvram/san; export MASTER_IP=$MASTER_IP; rokuflash $1" } +# Side loaded applications: +# 8085 dev_ui_console +# 8086 dev_background_console +# 8087 dev_screensaver_console +# 8088 dev_getcontent_console +# 8089 dev_voice_adapter_console +# +# Server loaded applications: +# 8885 ui_console +# 8886 background_console (including NDK) +# 8887 screensaver_console +# 8888 getcontent_console (eg, for 54383, DFP Ad Service) +# 8889 voice_adapter_console _roku_log() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 __device_cmd "setconsole /dev/pts/0" } +_roku_loglog() +{ + [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 + __netcat $1 +} + _roku_reboot() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 @@ -69,8 +90,8 @@ _roku_reboot() _roku_san_update() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 - __set_server_ip - __device_cmd "wget -O /nvram/san http://${SERVER_IP}/roku/san/san" + __set_master_ip + __device_cmd "wget -O /nvram/san http://${MASTER_IP}/roku/san/san; source /nvram/san; setup_san" } ############################################################################### @@ -80,12 +101,12 @@ _roku_san_update() _roku_audcap() { [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 - __set_server_ip + __set_master_ip __app_cmd "audcap record start 00" echo -n "Press Enter to stop capture." read __app_cmd "audcap record stop" - __device_cmd "tftp -p -r $1.pcm -l /tmp/audcap_audio.pcm $SERVER_IP" + __device_cmd "tftp -p -r $1.pcm -l /tmp/audcap_audio.pcm $MASTER_IP" sox -t raw -r 48000 -b 16 -c 2 -e signed-integer $1.pcm $1.wav } @@ -93,24 +114,28 @@ _roku_audcap() # # Debug app # -_roku_debug_attach() +_roku_gdb_attach() { - PLATFORM=lockhart [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 - __device_cmd "/tmp/tools/gdbserver :5555 --attach \$(pgrep Application)" + __device_cmd "/nvram/tools/gdbserver :5555 --attach \$(pgrep Application)" } -_roku_debug() +_roku_gdb() { - PLATFORM=lockhart + echo $ROKU_DEV_PLATFORM >> test.txt [ -z "$ROKU_DEV_TARGET" ] && echo "ROKU_DEV_TARGET must be defined" && return 0 # __device_cmd "/tmp/tools/gdbserver :5555 --attach \$(pgrep Application)" & # sleep 2 gdb-multiarch \ -ex "set non-stop off" \ - -ex "target remote $ROKU_DEBUG_TARGET:5555" \ - -ex "set solib-absolute-prefix $PWD/port/realtek/stark/$ROKU_DEV_TARGET/dist/rootfs" \ - -ex "set sysroot $PWD/port/realtek/stark/$ROKU_DEV_TARGET/dist/rootfs" + -ex "set pagination off" \ + -ex "set solib-absolute-prefix $PWD/port/realtek/stark/$ROKU_DEV_PLATFORM/dist/rootfs" \ + -ex "set sysroot $PWD/port/realtek/stark/$ROKU_DEV_PLATFORM/dist/rootfs" \ + -ex "set substitute-path . $PWD" \ + -ex "target remote $ROKU_DEV_TARGET:5555" + + # -ex "set solib-absolute-prefix $PWD/port/realtek/stark/$ROKU_DEV_PLATFORM/dist/rootfs" \ + # -ex "set sysroot $PWD/port/realtek/stark/$ROKU_DEV_PLATFORM/dist/rootfs" } ############################################################################### @@ -188,31 +213,26 @@ _roku_wget() [ -z "$1" ] && echo "usage: roku_wget " && return 0 if [ -z "$ROKU_CORP_PASSWORD" ]; then local USER_PASSWORD="--ask-password" + echo "NOTE: run 'roku wget pass' to set password." else local USER_PASSWORD="--password=$ROKU_CORP_PASSWORD" fi - wget --no-check-certificate --user=vkhachatryan $USER_PASSWORD $1 + wget --no-check-certificate --user=vkhachatryan $USER_PASSWORD "$@" } +# _roku_wget_pass() sets corp password. It is defined in the +# _roku_shaed.sh as it need to set env on the shell level. + ############################################################################### # # Dispatch commands. # -help() +_roku_help() { echo "Command is not recognised." } -FUNC=help -if [ "$(type -t _roku_$1)" == "function" ]; then - FUNC=_roku_$1 - shift -elif [ "$(type -t _roku_$1_$2)" == "function" ]; then - FUNC=_roku_$1_$2 - shift - shift -fi - -$FUNC "$@" +_ROKU_DEFAULT_DISPATCH_FUNC=_roku_help +_roku_dispatch "$@" diff --git a/_roku_shared.sh b/_roku_shared.sh new file mode 100644 index 0000000..b30fbc0 --- /dev/null +++ b/_roku_shared.sh @@ -0,0 +1,160 @@ +#!/bin/sh + +# I have my automake +export ACLOCAL_PATH=/usr/share/aclocal + +export ROKU_NFS_ROOT=$HOME/roku/nfs +export ROKU_NFS_IP=192.168.0.64 +export EXPORTROOT=${ROKU_NFS_ROOT} + + +export DEVPASSWORD=aaaa +_roku_device() +{ + if [ "$1" != "" ]; then + export ROKU_DEV_TARGET="$1" + export ROKU_DEV_PLATFORM="$(_roku.sh device_platform)" + fi + echo "device: $ROKU_DEV_TARGET" + echo "platform: $ROKU_DEV_PLATFORM" +} + +_roku_wget_pass() +{ + echo "Set ROKU_CORP_PASSWORD:" + read -sr ROKU_CORP_PASSWORD + export ROKU_CORP_PASSWORD +} + +_ROKU_DEFAULT_DISPATCH_FUNC=_roku.sh +_roku_dispatch() +{ + local DISPATCH_FUNC=$_ROKU_DEFAULT_DISPATCH_FUNC + if [ "$(type -t _roku_$1_$2)" == "function" ]; then + DISPATCH_FUNC=_roku_$1_$2 + shift + shift + elif [ "$(type -t _roku_$1)" == "function" ]; then + DISPATCH_FUNC=_roku_$1 + shift + fi + + $DISPATCH_FUNC "$@" +} + +roku() +{ + _roku_dispatch "$@" +} + + +############################################################################### +# +# Build Completion +# +__roku_completion_contains() +{ + # Platforms + for WORD in "$@"; do + if [[ "${COMP_WORDS[*]}" =~ "$WORD" ]]; then + return 1 + fi + done + return 0 +} + +__roku_completion_add_if() +{ + __roku_completion_contains "$@" + if [[ $? == 0 ]]; then + CANDIDATES+=" $@" + fi +} + +# complete -F __build_completion roku +# __build_completion() +# { +# local CANDIDATES="help clobber tests addon-checksums" + +# # Docker +# __build_completion_add_if docker make + +# # Build hosts +# __build_completion_add_if icecc local + +# # Port dir +# __build_completion_add_if port-only + +# # Platforms +# __build_completion_add_if native marlin bailey loggan lockhart porting-kit streambar stb + +# COMPREPLY=($(compgen -W "$CANDIDATES" "${COMP_WORDS[${COMP_CWORD}]}")) +# } + +complete -F __roku_completion roku +__roku_completion() +{ + local CANDIDATES="device get log flash gdb gdb_attach telnet reboot audcap san_update sideload token_install" + + # # Docker + # __build_completion_add_if docker make + + # # Build hosts + # __build_completion_add_if icecc local + + # # Port dir + # __build_completion_add_if port-only + + # # Platforms + # __build_completion_add_if native marlin bailey loggan lockhart porting-kit streambar stb + + COMPREPLY=($(compgen -W "$CANDIDATES" "${COMP_WORDS[${COMP_CWORD}]}")) +} + +############################################################################### +# +# Logging +# +LOGDIR="${HOME}/roku/logs" + + +dcapture() +{ + nc minicom "$@" -C $LOGDIR/.log.$(date +%Y-%m-%d--%H-%M-%S) +} + + +dfile() +{ + local Nth="-1" + if [ $# -gt 0 ]; then + Nth="$1" + fi + + echo $(ls -tr -1 ${LOGDIR}/minicom.log.* | tail ${Nth} | head -1) +} + +dless() +{ + less $(lfile "$@") +} + +dcat() +{ + cat $(lfile "$@") +} + +dgrep() +{ + lcat | grep -a --color "$@" +} + +dtail() +{ + if [ $# -gt 0 ]; then + tail -f $(lfile) | grep "$@" + else + tail -f $(lfile) + fi +} + diff --git a/san b/san index f59dc92..99e43e4 100644 --- a/san +++ b/san @@ -6,14 +6,10 @@ alias ll='ls -la' [ -f /nvram/san.conf ] && source /nvram/san.conf __config(){ - local GATEWAY=$(ip route show 0.0.0.0/0 | sed 's/default via \([0-9.]*\) dev .*/\1/') - if [ -z $SERVER_IP ]; then - if [ "$GATEWAY" == "192.168.144.93" ]; then - SERVER_IP=192.168.144.5 - else - SERVER_IP=192.168.0.64 - fi + 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 @@ -42,14 +38,14 @@ __descr " update_san - update this script." update_san() { - wget -O /nvram/san http://$SERVER_IP/roku/san/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 $SERVER_IP + [ -e $1 ] && tftp -r $(basename $1) -l $1 -p $MASTER_IP } __descr " upload_core - upload /dev/ltcore" @@ -112,7 +108,7 @@ download_from_buildarea() download_firmware() { - ACRAMFS_URL="http://$SERVER_IP/roku/$1" + ACRAMFS_URL="http://$MASTER_IP/roku/$1" echo "Downloading ${ACRAMFS_URL}" wget -O ${ACRAMFS} ${ACRAMFS_URL} if [ $? -ne 0 ]; then @@ -199,7 +195,7 @@ rokuflash() # __header "GDB" #__descr " setup_gdb [seconds|app|zipmountserver|apibroker|apitrace]" -#setup_gdb() +#copy_tools() #{ # #copy tools to /nvram folder for example: # cp -rL /tmp/tools /nvram/ @@ -299,7 +295,7 @@ zms_client() plethora msg-receive /zip-server set +x } - +/ zms_hotswap_stress_test() { local PLUGIN="/nvram/plugins/$1.zip" @@ -505,69 +501,18 @@ setup_plugfest() __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 -SERVER_IP=$SERVER_IP -source /nvram/san -disable_wd -#setup_network +MASTER_IP=$MASTER_IP +mount /nvram -o remount,exec +sh -c "while true ; do noreset; sleep 5; done" & 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 - -