diff --git a/CHANGELOG.md b/CHANGELOG.md index 462a1d86..ed97b36b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,45 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +<<<<<<< HEAD #### [6.0.1](https://github.com/rdkcentral/sysint/compare/6.0.0...6.0.1) +======= +#### [4.2.1v17](https://github.com/rdkcentral/sysint/compare/6.0.1...4.2.1v17) + +- RDKEMW-21582: Network connection recovery script should handle IPv4-only/IPv6-only networks [`#581`](https://github.com/rdkcentral/sysint/pull/581) +- RDKEMW-19100:gst-cleanup conditions when cdl_flashed_file_name is not present [`#551`](https://github.com/rdkcentral/sysint/pull/551) +- RDKEMW-18972 : RebootReason log adds colon in the Parodus.log file [`#550`](https://github.com/rdkcentral/sysint/pull/550) +- RDKEMW-16152: "Let's get connected" screen displayed during Migration testing [`#549`](https://github.com/rdkcentral/sysint/pull/549) +- RDKEMW-18793a: avoid thermal call in deepsleep [`#548`](https://github.com/rdkcentral/sysint/pull/548) +- RDKEMW-17533 : [support/8.4.4.0] OCDM_WVMediaKey and OCDM_SaThread changes in sysint [`#518`](https://github.com/rdkcentral/sysint/pull/518) +- RDKEMW-17274: 8.4 T2 event for MemAvailable Need To Send Only Numerical Value [`#515`](https://github.com/rdkcentral/sysint/pull/515) +- RDKEMW-15318: [4.2.1] stop ctrlm-main service before bluez for graceful reboot [`#486`](https://github.com/rdkcentral/sysint/pull/486) +- [RDKEMW-14555] : Updating wifi reassociation threshould tolerance RFC [`#462`](https://github.com/rdkcentral/sysint/pull/462) +- Hotfix 4.2.1v8 [`#475`](https://github.com/rdkcentral/sysint/pull/475) +- RDKEMW-13932: Move Bluetooth Mac update from Device Details to Bluetooth Service [`#458`](https://github.com/rdkcentral/sysint/pull/458) +- RDKEMW-13691: Increase Timeout for NTP PartnerURL Read [`#456`](https://github.com/rdkcentral/sysint/pull/456) +- RDKEMW-13425: Remove monarch process name for core upload [`#452`](https://github.com/rdkcentral/sysint/pull/452) +- RDKEMW-13061: Include utility indepenent of T2 for telemetry upload [`#443`](https://github.com/rdkcentral/sysint/pull/443) +- sysint 4.2.1 hotfix release [`35cd500`](https://github.com/rdkcentral/sysint/commit/35cd5003a10a61c13830955014d04822d952f104) +- Sysint 4.2.1 hotfix release [`c542d88`](https://github.com/rdkcentral/sysint/commit/c542d88c469198d0d7c5b55503635a88697beaa3) +- Sysint 4.2.1v13 hotfix release [`27c5acd`](https://github.com/rdkcentral/sysint/commit/27c5acd0f90ce3cacb99383139d441289f56526f) + +#### [6.0.1](https://github.com/rdkcentral/sysint/compare/6.0.0...6.0.1) + +> 20 July 2026 + +>>>>>>> 4.2.1v17 - RDKE-1065: Automated workflow - create pull request to main instead of develop [`#572`](https://github.com/rdkcentral/sysint/pull/572) - RDKEMW-20916 : [RDKE] [Develop] RDKV-to-RDKE Migration: Unexpected Network Connectivity Prior to Migration Completion [`#571`](https://github.com/rdkcentral/sysint/pull/571) - RDKEMW-10439: Reboot device with WareHouse plugin resetDevice [`#381`](https://github.com/rdkcentral/sysint/pull/381) - RDKEMW-21159: avoid thermal call in deepsleep (#548) [`#566`](https://github.com/rdkcentral/sysint/pull/566) - RDKE-1065: Automated Component release workflow [`#562`](https://github.com/rdkcentral/sysint/pull/562) - RDKE-1065: Using ubuntu-latest runner for release workflow [`#557`](https://github.com/rdkcentral/sysint/pull/557) +<<<<<<< HEAD +======= +- 6.0.1 release changelog updates [`658364b`](https://github.com/rdkcentral/sysint/commit/658364b56e7ee794ff8f53b1fa88106a6e8ae007) +>>>>>>> 4.2.1v17 - Merge tag '6.0.0' into develop [`e96c345`](https://github.com/rdkcentral/sysint/commit/e96c34560bc16714dec958463ebf64772902f45d) ### [6.0.0](https://github.com/rdkcentral/sysint/compare/5.1.0...6.0.0) diff --git a/lib/rdk/backup_logs.sh b/lib/rdk/backup_logs.sh new file mode 100755 index 00000000..c087e159 --- /dev/null +++ b/lib/rdk/backup_logs.sh @@ -0,0 +1,165 @@ +#!/bin/sh +############################################################################## +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2020 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Purpose: This script is used to backup the Logs +# Scope: RDK devices +# Usage: This script is triggered by systemd service +############################################################################## + +. /etc/include.properties +. /etc/device.properties + +if [ -f /etc/env_setup.sh ]; then + . /etc/env_setup.sh +fi + +PREV_LOG_PATH="$LOG_PATH/PreviousLogs" +PREV_LOG_BACKUP_PATH="$LOG_PATH/PreviousLogs_backup" + +backupLog() { + timestamp=$(/bin/timestamp) + echo "$timestamp $0: $*" +} + +# create log workspace if not there +if [ ! -d "$LOG_PATH" ];then + mkdir -p "$LOG_PATH" +fi + +# create intermediate log workspace if not there +if [ ! -d $PREV_LOG_PATH ];then + mkdir -p $PREV_LOG_PATH +fi + +# create log backup workspace if not there +if [ ! -d $PREV_LOG_BACKUP_PATH ];then + mkdir -p $PREV_LOG_BACKUP_PATH +else + rm -rf $PREV_LOG_BACKUP_PATH/* +fi + +if [ $APP_PERSISTENT_PATH ];then + PERSISTENT_PATH=$APP_PERSISTENT_PATH +else + PERSISTENT_PATH=/opt/persistent +fi + +touch $PERSISTENT_PATH/logFileBackup + +# disk size check for recovery if /opt size > 90% +if [ -f /lib/rdk/disk_threshold_check.sh ];then + sh /lib/rdk/disk_threshold_check.sh 0 +fi + +backupAndRecoverLogs() +{ + source=$1 + destn=$2 + operation=$3 + s_extn=$4 + d_extn=$5 + + backupLog "backupAndRecoverLogs:start source=$source, destn=$destn, operation=$operation" + + for file in $(find $source -mindepth 1 -maxdepth 1 -type f -name "$s_extn*"); + do + $operation "$file" "$destn$d_extn${file/$source$s_extn/}" + done + backupLog "backupAndRecoverLogs:end" +} + +last_bootfile=$(find "$PREV_LOG_PATH" -name last_reboot) +if [ -f "$last_bootfile" ];then + rm -rf "$last_bootfile" +fi + +sysLog="messages.txt" +sysLogBAK1="bak1_messages.txt" +sysLogBAK2="bak2_messages.txt" +sysLogBAK3="bak3_messages.txt" + +if [ "$HDD_ENABLED" = "false" ]; then + backupLog "HDD disabled device" + BAK1="bak1_" + BAK2="bak2_" + BAK3="bak3_" + if [ ! -f "$PREV_LOG_PATH/$sysLog" ]; then + find $LOG_PATH -maxdepth 1 -mindepth 1 \( -type l -o -type f \) \( -iname "*.txt*" -o -iname "*.log*" -o -iname "*.bin*" -o -name "bootlog" \) -exec mv '{}' $PREV_LOG_PATH \; + if [ $? -ne 0 ]; then + backupLog "Error:Failed to Move the logs from $LOG_PATH to $PREV_LOG_PATH" + fi + elif [ ! -f "$PREV_LOG_PATH/$sysLogBAK1" ]; then + # box reboot within 8 minutes after reboot + backupAndRecoverLogs "$LOG_PATH/" "$PREV_LOG_PATH/" mv "" $BAK1 + elif [ ! -f "$PREV_LOG_PATH/$sysLogBAK2" ]; then + # box reboot within 8 minutes after reboot + backupAndRecoverLogs "$LOG_PATH/" "$PREV_LOG_PATH/" mv "" $BAK2 + elif [ ! -f "$PREV_LOG_PATH/$sysLogBAK3" ]; then + # box reboot within 8 minutes after reboot + backupAndRecoverLogs "$LOG_PATH/" "$PREV_LOG_PATH/" mv "" $BAK3 + else + # box reboot within 8 minutes after reboot + backupAndRecoverLogs "$PREV_LOG_PATH/" "$PREV_LOG_PATH/" mv "$BAK1" "" + backupAndRecoverLogs "$PREV_LOG_PATH/" "$PREV_LOG_PATH/" mv "$BAK2" "$BAK1" + backupAndRecoverLogs "$PREV_LOG_PATH/" "$PREV_LOG_PATH/" mv "$BAK3" "$BAK2" + backupAndRecoverLogs "$LOG_PATH/" "$PREV_LOG_PATH/" mv "" "$BAK3" + fi + + /bin/touch "$PREV_LOG_PATH/last_reboot" + + # logs cleanup after backup + backupLog "Clean up $LOG_PATH" + rm -rf $LOG_PATH/*.* + find $LOG_PATH -name "*-*-*-*-*M-" -exec rm -rf {} \; +else + backupLog "HDD enabled device" + if [ ! -f "$PREV_LOG_PATH/$sysLog" ]; then + backupLog "Move logs from $LOG_PATH to $PREV_LOG_PATH" + find $LOG_PATH -maxdepth 1 -mindepth 1 \( -type l -o -type f \) \( -iname "*.txt*" -o -iname "*.log*" -o -name "bootlog" \) -exec mv '{}' $PREV_LOG_PATH \; + /bin/touch $PREV_LOG_PATH/last_reboot + else + find "$PREV_LOG_PATH" -name last_reboot | xargs rm >/dev/null + timestamp=$(date "+%m-%d-%y-%I-%M-%S%p") + LogFilePathPerm="$PREV_LOG_PATH/logbackup-$timestamp" + mkdir -p "$LogFilePathPerm" + backupLog "Move logs from $LOG_PATH to $LogFilePathPerm" + find "$LOG_PATH" -maxdepth 1 -mindepth 1 \( -type l -o -type f \) \( -iname "*.txt*" -o -iname "*.log*" -o -name "bootlog" \) -exec mv '{}' "$LogFilePathPerm" \; + /bin/touch "$LogFilePathPerm/last_reboot" + fi +fi + +if [ -f /tmp/disk_cleanup.log ];then + mv /tmp/disk_cleanup.log "$LOG_PATH" +fi + +if [ -f /tmp/mount_log.txt ];then + mv /tmp/mount_log.txt "$LOG_PATH" +fi + +if [ -f /tmp/mount-ta_log.txt ];then +    mv /tmp/mount-ta_log.txt "$LOG_PATH" +fi + +cp /version.txt "$LOG_PATH" +cp /etc/skyversion.txt "${LOG_PATH}/skyversion.txt" +cp /etc/rippleversion.txt "${LOG_PATH}/rippleversion.txt" + +backupLog "Send systemd notification ..." +/bin/systemd-notify --ready --status="Logs Backup Done..!" + diff --git a/lib/rdk/core_shell.sh b/lib/rdk/core_shell.sh index 370e865f..f9527abd 100755 --- a/lib/rdk/core_shell.sh +++ b/lib/rdk/core_shell.sh @@ -335,7 +335,11 @@ if [ "$1" = "xcal-discovery-" ] || [ "$1" = "xdiscovery" ] || [ "$1" = "IARMDae [ "$1" = "NWMgrPlugin" ] || [ "$1" = "nm_event_thrd" ] || [ "$1" = "Monitor::IResou" ] || [ "$1" = "DRMSYSTEM" ] || [ "$1" = "HTTPREQUEST_MAN" ] || [ "$1" = "civetweb-worker" ] || [ "$1" = "nfrtool" ] || +<<<<<<< HEAD [ "$1" = "OCDM_WVMediaKey" ] || [ "$1" = "OCDM_SaThread" ] || [ "$1" = "multiqueue28:sr" ]; then +======= + [ "$1" = "OCDM_WVMediaKey" ] || [ "$1" = "OCDM_SaThread" ]; then +>>>>>>> 4.2.1v17 dumpFile exit 0 fi diff --git a/lib/rdk/getDeviceDetails.sh b/lib/rdk/getDeviceDetails.sh index b7899312..e1e0621b 100755 --- a/lib/rdk/getDeviceDetails.sh +++ b/lib/rdk/getDeviceDetails.sh @@ -285,7 +285,11 @@ getBluetoothMac() if [ -f /lib/rdk/readBTAddress-vendor.sh ]; then bluetooth_mac=`sh /lib/rdk/readBTAddress-vendor.sh` else +<<<<<<< HEAD bluetooth_mac=`sh /lib/rdk/readBTAddress-generic.sh` +======= + bluetooth_mac=`sh /lib/rdk/readBTAddress-generic.sh` +>>>>>>> 4.2.1v17 fi echo "$bluetooth_mac" diff --git a/lib/rdk/networkConnectionRecovery.sh b/lib/rdk/networkConnectionRecovery.sh index 8b92bb39..6937bf45 100755 --- a/lib/rdk/networkConnectionRecovery.sh +++ b/lib/rdk/networkConnectionRecovery.sh @@ -21,20 +21,22 @@ #Purpose : To recover from the network breakages and log the details #Scope : RDK Devices #Usage : Invoked by systemd service - + . /etc/device.properties . /etc/include.properties . $RDK_PATH/utils.sh if [ -f /lib/rdk/t2Shared_api.sh ]; then - source /lib/rdk/t2Shared_api.sh + . /lib/rdk/t2Shared_api.sh fi logsFile=$LOG_PATH/ConnectionStats.txt dnsFile="/etc/resolv.dnsmasq" wifiStateFile="/tmp/wifi-on" -packetsLostipv4=0 -packetsLostipv6=0 +ipv4PacketLoss=0 +ipv6PacketLoss=0 +ipv4GwPresent=0 +ipv6GwPresent=0 lossThreshold=10 lnfSSIDConnected=0 lnfPskSSID=A16746DF2466410CA2ED9FB2E32FE7D9 @@ -45,6 +47,7 @@ pingInterval=0.2 #Interval between pings wifiResetWaitTime=180 currentTime=0 tmpFile="/tmp/.Connection.txt" +prevStateFile="/tmp/.ncr_laststate" wifiDriverErrors=0 ##RFC parameters that can be customized @@ -59,6 +62,12 @@ WifiReassociateTolerance=100 dnsFailures=0 maxdnsFailures=3 +# Append a timestamped line to $logsFile. +log() +{ + echo "$(/bin/timestamp) $*" >> "$logsFile" +} + StoreTotmpFile() { [ -f "$tmpFile" ] && rm "$tmpFile" @@ -124,8 +133,8 @@ checkWifiConnected() { [ ! -f "$wifiStateFile" ] && return 0 strBuffer=$(wpa_cli status 2> /dev/null) - [[ ! "$strBuffer" =~ "wpa_state=COMPLETED" ]] && return 0 - [[ "$strBuffer" =~ "$lnfPskSSID" ]] || [[ "$strBuffer" =~ "$lnfEnterpriseSSID" ]] && lnfSSIDConnected=1 && return 0 + case "$strBuffer" in *"wpa_state=COMPLETED"*) ;; *) return 0 ;; esac + case "$strBuffer" in *"$lnfPskSSID"*|*"$lnfEnterpriseSSID"*) lnfSSIDConnected=1 ; return 0 ;; esac return 1 } @@ -138,25 +147,25 @@ checkEthernetConnected() ret=$? if [ $ret -eq 0 ] ; then if [ "$lnfSSIDConnected" = "1" ]; then - echo "$(/bin/timestamp) TELEMETRY_WIFI_CONNECTED_LNF" >> "$logsFile" + log "TELEMETRY_WIFI_CONNECTED_LNF" #Reset count when lnf ssid is connected count=0 t2CountNotify "SYST_INFO_WIFIConn" else #Skip printing wifi not connected log for the first time - [ $count -gt 0 ] && echo "$(/bin/timestamp) TELEMETRY_WIFI_NOT_CONNECTED" >> "$logsFile" + [ $count -gt 0 ] && log "TELEMETRY_WIFI_NOT_CONNECTED" count=$((count + 1)) fi return 0 else - echo "$(/bin/timestamp) TELEMETRY_WIFI_CONNECTED" >> "$logsFile" + log "TELEMETRY_WIFI_CONNECTED" #Reset count when connectivity is good count=0 t2CountNotify "SYST_INFO_WIFIConn" return 0 fi else - echo "$(/bin/timestamp) TELEMETRY_ETHERNET_CONNECTED" >> "$logsFile" + log "TELEMETRY_ETHERNET_CONNECTED" #Reset count when connectivity is good count=0 t2CountNotify "SYST_INFO_ETHConn" @@ -179,7 +188,7 @@ printWifiDetails() wifiReassociate() { - echo "$(/bin/timestamp) Packet Loss WiFi Reassociating" >> "$logsFile" + log "Packet Loss WiFi Reassociating" t2CountNotify "WIFIV_ERR_reassoc" wpa_cli reassociate #set IsWifiReassociated to 1 after wifi reassociation @@ -190,17 +199,18 @@ checkWifiDrvErrors() { dir=$(find /sys/kernel/debug/ieee80211 -type d -maxdepth 1 | sed '1d') if [ -z "$dir" ] ; then - echo "$(/bin/timestamp) phy directory not in /sys/kernel/debug/ieee80211" >> "$logsFile" + log "phy directory not in /sys/kernel/debug/ieee80211" elif [ ! -f "$dir"/ath10k/fw_stats ]; then - echo "$(/bin/timestamp) fw_stats file not in /sys/kernel/debug/ieee80211/$dir/ath10k/" >> "$logsFile" + log "fw_stats file not in $dir/ath10k/" else cat "$dir"/ath10k/fw_stats > /dev/null 2>&1 - if [[ $? -ne 0 ]]; then - echo "$(/bin/timestamp) Cant open file /sys/kernel/debug/ieee80211/$dir/ath10k/ status=$?" >> "$logsFile" + catStatus=$? + if [ "$catStatus" -ne 0 ]; then + log "Can't open file $dir/ath10k/fw_stats status=$catStatus" else #Reset tmp variables to 0 when there is no wifi driver issue FirstWifiDriverIssueTime=0 - ["$IsWifiReassociated" -eq 0 ] && IsWifiReset=0 #$IsWifiReassociated=1 indicates wifi reassociation done already and still packetloss happens hence don't make IsWifiReset=0 + [ "$IsWifiReassociated" -eq 0 ] && IsWifiReset=0 #$IsWifiReassociated=1 indicates wifi reassociation done already and still packetloss happens hence don't make IsWifiReset=0 return 0 fi fi @@ -212,17 +222,31 @@ checkWifiDrvErrors() checkPacketLoss() { version=$1 +<<<<<<< HEAD +======= + packetLoss="" +>>>>>>> 4.2.1v17 currentTime=$(($(date +%s))) if [ -f "/tmp/checkpacketloss" ] ; then if [ "$version" = "V4" ] ; then gwIp=$(cat /tmp/checkpacketloss) pingCmd="ping" +<<<<<<< HEAD +======= + else + gwIp="" +>>>>>>> 4.2.1v17 fi else if [ "$version" = "V4" ] ; then gwIp=$(/sbin/ip -4 route | awk '/default/ { print $3 }' | head -n1 | awk '{print $1;}') +<<<<<<< HEAD pingCmd="ping" +======= + gwIp_interface=$(/sbin/ip -4 route | awk '/default/ { print $5 }' | head -n1 | awk '{print $1;}') + pingCmd="ping -I $gwIp_interface" +>>>>>>> 4.2.1v17 elif [ "$version" = "V6" ] ; then gwIp=$(/sbin/ip -6 route | awk '/default/ { print $3 }' | head -n1 | awk '{print $1;}') gwIp_interface=$(/sbin/ip -6 route | awk '/default/ { print $5 }' | head -n1 | awk '{print $1;}') @@ -232,6 +256,7 @@ checkPacketLoss() if [ "$gwIp" != "" ] && [ "$gwIp" != "dev" ] ; then gwResponse=$($pingCmd -c "$pingCount" -i "$pingInterval" "$gwIp") +<<<<<<< HEAD ret=$(echo "$gwResponse" | grep "packet"|awk '{print $7}'|cut -d'%' -f1) if [ "$version" = "V4" ] ; then @@ -255,12 +280,43 @@ checkPacketLoss() else if [ "$(($GatewayLogTimeStamp+$GatewayLoggingInterval))" -le "$currentTime" ] ; then echo "$(/bin/timestamp) TELEMETRY_GATEWAY_NO_ROUTE_$version" >> "$logsFile" +======= + packetLoss=$(echo "$gwResponse" | grep "packet"|awk '{print $7}'|cut -d'%' -f1) + + if [ "$version" = "V4" ] ; then + ipv4PacketLoss=$packetLoss + ipv4GwPresent=1 + elif [ "$version" = "V6" ] ; then + ipv6PacketLoss=$packetLoss + ipv6GwPresent=1 + fi + + gwResponseTime=$(echo "$gwResponse" | sed '$!d;s|.*/\([0-9.]*\)/.*|\1|') + #Notify 100% gateway packet loss on every run, independent of GatewayLoggingInterval, + #so the marker is not skipped when the run cadence is shorter than GatewayLoggingInterval. + if [ "$packetLoss" = "100" ] ; then + log "$version SYST_WARN_GW100PERC_PACKETLOSS, gateway $gwIp" + t2CountNotify "SYST_WARN_GW100PERC_PACKETLOSS" + fi + if [ "$(($GatewayLogTimeStamp+$GatewayLoggingInterval))" -le "$currentTime" ] ; then + if [ "$packetLoss" = "100" ] ; then + log "TELEMETRY_GATEWAY_RESPONSE_TIME:NR,$gwIp" + else + log "TELEMETRY_GATEWAY_RESPONSE_TIME:$gwResponseTime,$gwIp" + fi + log "TELEMETRY_GATEWAY_PACKET_LOSS:$packetLoss,$gwIp" + fi + else + if [ "$(($GatewayLogTimeStamp+$GatewayLoggingInterval))" -le "$currentTime" ] ; then + log "TELEMETRY_GATEWAY_NO_ROUTE_$version" +>>>>>>> 4.2.1v17 t2CountNotify "WIFIV_INFO_NO${version}ROUTE" fi fi [ "$(($GatewayLogTimeStamp+$GatewayLoggingInterval))" -le "$currentTime" ] && GatewayLogTimeStamp=$(($(date +%s))) +<<<<<<< HEAD #Send telemetry notification for 20%,30%....90% packet loss if [ "$packetsLostipv4" -gt "$lossThreshold" ] || [ "$packetsLostipv6" -gt "$lossThreshold" ] ; then echo "$(/bin/timestamp) Packet loss more than $lossThreshold% observed." >> "$logsFile" @@ -277,10 +333,29 @@ checkPacketLoss() if [ "$packetsLostipv4" -ne 0 ] && [ "$packetsLostipv6" -ne 0 ]; then #Send telemetry notification for 10% packet loss echo "$(/bin/timestamp) Current Packet loss is WIFIV_WARN_PL_10PERC" >> "$logsFile" +======= + #Send telemetry notification for 20%,30%....90% packet loss + if [ -n "$packetLoss" ] ; then + if [ "$packetLoss" -gt "$lossThreshold" ] ; then + log "$version Packet loss more than $lossThreshold% observed (packetLoss=$packetLoss)" + if [ "$packetLoss" -ne 100 ] ; then + for i in 1 2 3 4 5 6 7 8 9; do + if [ "$packetLoss" -ge $((i*10)) ] && [ "$packetLoss" -lt $((i*10+10)) ] ; then + log "$version packet loss is WIFIV_WARN_PL_$((i*10))PERC" + t2CountNotify "WIFIV_WARN_PL_"$((i*10))"PERC" + break + fi + done + fi + elif [ "$packetLoss" -ne 0 ] ; then + #Send telemetry notification for 10% packet loss + log "$version packet loss is WIFIV_WARN_PL_10PERC" +>>>>>>> 4.2.1v17 t2CountNotify "WIFIV_WARN_PL_10PERC" fi fi +<<<<<<< HEAD if [ "$packetsLostipv4" -ge "$WifiReassociateTolerance" ] && [ "$packetsLostipv6" -ge "$WifiReassociateTolerance" ]; then echo "$(/bin/timestamp) ${WifiReassociateTolerance}% Packet loss is observed for both ipv4 and ipv6." >> "$logsFile" #Note down $FirstPacketLossTime when threshold packetloss is detected for the first time @@ -307,6 +382,87 @@ checkPacketLoss() echo "$(/bin/timestamp) [DEBUG_NCR] checkPacketLoss: BELOW TOLERANCE returning 0 - skipping reset (version=$version, waiting for V6 measurement). wifiDriverErrors=$wifiDriverErrors" >> "$logsFile" fi +======= + #Evaluate the packet-loss trigger only on the V6 call, once both stacks have + #been probed (globals set during the preceding V4 call persist here). Classify + #each routed stack as good (loss < tolerance = acceptable connectivity) or bad + #(loss >= tolerance); a stack with no default route or an unparseable ping + #result is ignored. Because any acceptable stack means we should not tear down + #L2, recovery is warranted only when NO routed stack is good and at least one + #routed stack is bad: + # - dual-stack (IPv4 + IPv6): both must be at/above tolerance to return 1 + # - IPv4-only : IPv4 packet loss alone controls the result + # - IPv6-only : IPv6 packet loss alone controls the result + if [ "$version" = "V6" ] ; then + #Log the per-stack route/loss snapshot only when it changes from the previous + #run, so field logs capture every transition without flooding on every run. + currState="ipv4Route=$ipv4GwPresent ipv6Route=$ipv6GwPresent ipv4PacketLoss=$ipv4PacketLoss ipv6PacketLoss=$ipv6PacketLoss" + prevState="" + [ -f "$prevStateFile" ] && prevState=$(cat "$prevStateFile") + if [ "$currState" != "$prevState" ] ; then + log "network state changed: ($currState)" + echo "$currState" > "$prevStateFile" + fi + + #100% packet-loss field-triage marker. Fires when every routed IP stack shows + #exactly 100% loss - the successor to the legacy + #"100% Packet loss is observed for both ipv4 and ipv6." print, generalized so it + #is also emitted correctly on IPv4-only and IPv6-only networks (the old dual-stack + #test silently missed those). A stack with no default route or an unparseable ping + #result is not counted. This is a log-only marker: it is independent of + #WifiReassociateTolerance and of the recovery decision below, so it appears in the + #same 100%-loss situation as the legacy print. Field triage greps the + #"100% Packet loss is observed" head across the fleet. + routedStacks=0 + all100=1 + if [ "$ipv4GwPresent" -eq 1 ] && [ -n "$ipv4PacketLoss" ] ; then + routedStacks=$((routedStacks + 1)) + [ "$ipv4PacketLoss" = "100" ] || all100=0 + fi + if [ "$ipv6GwPresent" -eq 1 ] && [ -n "$ipv6PacketLoss" ] ; then + routedStacks=$((routedStacks + 1)) + [ "$ipv6PacketLoss" = "100" ] || all100=0 + fi + if [ "$routedStacks" -gt 0 ] && [ "$all100" -eq 1 ] ; then + log "100% Packet loss is observed on all routed IP stacks" + fi + + anyGood=0 + anyBad=0 + if [ "$ipv4GwPresent" -eq 1 ] && [ -n "$ipv4PacketLoss" ] ; then + if [ "$ipv4PacketLoss" -ge "$WifiReassociateTolerance" ] ; then anyBad=1 ; else anyGood=1 ; fi + fi + if [ "$ipv6GwPresent" -eq 1 ] && [ -n "$ipv6PacketLoss" ] ; then + if [ "$ipv6PacketLoss" -ge "$WifiReassociateTolerance" ] ; then anyBad=1 ; else anyGood=1 ; fi + fi + + if [ "$anyGood" -eq 0 ] && [ "$anyBad" -eq 1 ] ; then + #No routed stack has acceptable connectivity and at least one is bad -> recover. + log "Packet loss is observed on all routed IP stacks (ipv4Route=$ipv4GwPresent ipv6Route=$ipv6GwPresent ipv4PacketLoss=$ipv4PacketLoss ipv6PacketLoss=$ipv6PacketLoss tolerance=${WifiReassociateTolerance}%)" + #Note down $FirstPacketLossTime when threshold packetloss is detected for the first time + [ "$FirstPacketLossTime" -eq 0 ] && FirstPacketLossTime=$(($(date +%s))) + #Note down $PacketLossLogTimeStamp when PacketLossLogTimeStamp is 0 + [ "$PacketLossLogTimeStamp" -eq 0 ] && PacketLossLogTimeStamp=$(($(date +%s))) + #Note down $EthernetLogTimeStamp when EthernetLogTimeStamp is 0 and ethernet connected + [ "$IsEthernetConnected" -eq 1 ] && [ "$EthernetLogTimeStamp" -eq 0 ] && EthernetLogTimeStamp=$(($(date +%s))) + return 1 + elif [ "$anyGood" -eq 1 ] ; then + #At least one routed stack has acceptable connectivity (below tolerance) -> clear packet-loss state. + # log "[DEBUG_NCR] checkPacketLoss: acceptable connectivity on a routed stack (ipv4PacketLoss=$ipv4PacketLoss ipv6PacketLoss=$ipv6PacketLoss) - resetting FirstPacketLossTime/PacketLossLogTimeStamp/IsWifiReassociated. wifiDriverErrors=$wifiDriverErrors" + FirstPacketLossTime=0 + PacketLossLogTimeStamp=0 + EthernetLogTimeStamp=0 + IsWifiReassociated=0 + [ "$wifiDriverErrors" -eq 0 ] && IsWifiReset=0 #Make IsWifiReset=0 only when there is no wifidriverissue + else + #No routed stack was measurable (no route / unparseable) -> skip reset so a total loss of + #routes does not wipe an in-progress packet-loss timer. + # log "[DEBUG_NCR] checkPacketLoss: no routed-stack measurement (version=$version) - skipping reset. wifiDriverErrors=$wifiDriverErrors" + : + fi + fi + +>>>>>>> 4.2.1v17 return 0 } @@ -324,10 +480,10 @@ wifiReset() #Set IsWifiReset to 1 after wifi reset IsWifiReset=1 StoreTotmpFile - echo "$(/bin/timestamp) Start WiFi Reset. !!!!!!!!!!!!!!" >> "$logsFile" - + log "Start WiFi Reset. !!!!!!!!!!!!!!" + systemctl restart wifi.service - echo "$(/bin/timestamp) WiFi Reset done as part of Recovery. !!!!!!!!!!!!!!" >> "$logsFile" + log "WiFi Reset done as part of Recovery. !!!!!!!!!!!!!!" exit 0 } @@ -335,18 +491,18 @@ checkDnsFile() { if [ -f "$dnsFile" ] ; then if [ $(tr -d ' \r\n\t' < $dnsFile | wc -c ) -eq 0 ] ; then - echo "$(/bin/timestamp) DNS File($dnsFile) is empty" >> "$logsFile" - t2CountNotify "SYST_ERR_DNSFileEmpty" + log "DNS File($dnsFile) is empty" + t2CountNotify "SYST_ERR_DNSFileEmpty" gwIpv4=$(/sbin/ip -4 route show default | awk 'NR==1 {print $3; exit}') gwIpv6=$(/sbin/ip -6 route show default | awk 'NR==1 {print $3; exit}') routeIpv4=$(/sbin/ip -4 route) - routeIpv6=$(/sbin/ip -6 route) + routeIpv6=$(/sbin/ip -6 route) if [ "$gwIpv4" != "" ] || [ "$gwIpv6" != "" ] ; then dnsFailures=$((dnsFailures + 1)) case $routeIpv4 in *"error"*) dnsFailures=0 - ;; + ;; esac case $routeIpv6 in *"error"*) @@ -358,7 +514,7 @@ checkDnsFile() fi if [ "$dnsFailures" -gt "$maxdnsFailures" ] ; then - echo "$(/bin/timestamp) Restarting udhcpc to recover" >> "$logsFile" + log "Restarting udhcpc to recover" InterfaceList="$ethernet_interface $WIFI_INTERFACE" for interface in $InterfaceList do @@ -376,7 +532,7 @@ checkDnsFile() dnsFailures=0 fi else - echo "$(/bin/timestamp) DNS File is not there $dnsFile" >> "$logsFile" + log "DNS File is not there $dnsFile" fi } @@ -384,7 +540,7 @@ checkRfc() { rfcWifiResetEnable="$(tr181 Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.WiFiReset.Enable 2>&1 > /dev/null)" if [ "$rfcWifiResetEnable" = "true" ] ; then - echo "$(/bin/timestamp) WiFiReset RFC is true " >> "$logsFile" + log "WiFiReset RFC is true " rfcEthernetLoggingInterval="$(tr181 Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.WiFiReset.EthernetLoggingInterval 2>&1 > /dev/null)" if [ ! -z "$rfcEthernetLoggingInterval" ] && [ "$rfcEthernetLoggingInterval" != 0 ] ; then EthernetLoggingInterval="$rfcEthernetLoggingInterval" @@ -427,7 +583,7 @@ LoadFromtmpFile if [ "$IsWifiReset" -eq 1 ] ; then currentTime=$(($(date +%s))) if [ "$(($WifiResetTime+$wifiResetWaitTime))" -gt "$currentTime" ] ; then - echo "$(/bin/timestamp) Skip all checks since wifi reset is done recently" >> "$logsFile" + log "Skip all checks since wifi reset is done recently" exit 0 fi fi diff --git a/lib/rdk/rebootNow.sh b/lib/rdk/rebootNow.sh new file mode 100755 index 00000000..15a40b45 --- /dev/null +++ b/lib/rdk/rebootNow.sh @@ -0,0 +1,489 @@ +#!/bin/sh +############################################################################## +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2020 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################## + +. /etc/include.properties +. /etc/device.properties +. /etc/env_setup.sh + +# The reboot cmd is aliased to "reboot -f" in env_setup.sh. Remove force reboot as it causing HDD corruption. +if [ -f /etc/os-release ];then + alias reboot='/sbin/reboot' +fi + +if [ -f /lib/rdk/t2Shared_api.sh ]; then + source /lib/rdk/t2Shared_api.sh +fi + +REBOOT_REASON_LOGFILE="/opt/logs/rebootreason.log" +rebootLog() { + echo "`/bin/timestamp` :$0: $*" >> $REBOOT_REASON_LOGFILE +} + +#Usage: rebootNow.sh [-c "" | -s ""][-r ""][-o ""] +usage() +{ + rebootLog "USAGE: rebootNow.sh -c/-s -r -o " + rebootLog " -s : Source Module or Script Name" + rebootLog " -c : Crash Process Name" + rebootLog " -r : Reason to specify for any particular reason: default=Unknown" + rebootLog " -o : Reason to request for the reboot: default=Unknown" +} + +if [ $# -lt 2 ]; then + rebootLog "Exiting as no argument specified to identify source of reboot!!!" + usage + exit 1 +elif [[ "$3" == "-s" || "$3" == "-c" ]]; then + rebootLog "Exiting as invalid arguments found!!!" + usage + exit 1 +fi + +# Save reboot details in /opt/secure/reboot folder. +REBOOT_INFO_DIR="/opt/secure/reboot" +REBOOT_INFO_FILE="/opt/secure/reboot/reboot.info" +PREVIOUSREBOOT_INFO_FILE="/opt/secure/reboot/previousreboot.info" +PARODUS_REBOOT_INFO_FILE="/opt/secure/reboot/parodusreboot.info" +REBOOTINFO_LOGFILE="/opt/logs/rebootInfo.log" +REBOOTNOW_FLAG="/opt/secure/reboot/rebootNow" +REBOOTSTOP_FLAG="/opt/secure/reboot/rebootStop" +REBOOT_COUNTER="/opt/secure/reboot/rebootCounter" +REBOOTSTOP_DURATION=$(tr181 Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RebootStop.Duration 2>&1 > /dev/null) +REBOOTSTOP_DETECTION=$(tr181 Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RebootStop.Detection 2>&1 > /dev/null) +REBOOT_WINDOW=10 +REBOOT_WINDOW_SECS=$((REBOOT_WINDOW * 60)) +REBOOT_CYCLE_THRESHOLD=5 +CYCLIC_REBOOT_SOURCE="rebootNow.sh" +CYCLIC_REBOOT_REASON="Rebooting device after expiry of Cyclic reboot pause window" +CDLFILE=$(cat /opt/cdl_flashed_file_name) +PREV_CDLFILE=$(cat /tmp/currently_running_image_name) +# Define Reasons for APP_TRIGGERED, OPS_TRIGGERED and MAINTENANCE_TRIGGERED cases +APP_TRIGGERED_REASONS=(Servicemanager systemservice_legacy WarehouseReset WarehouseService HrvInitWHReset HrvColdInitReset HtmlDiagnostics InstallTDK StartTDK TR69Agent SystemServices Bsu_GUI SNMP CVT_CDL Nxserver DRM_Netflix_Initialize hrvinit PaceMFRLibrary) +OPS_TRIGGERED_REASONS=(ScheduledReboot RebootSTB.sh FactoryReset UpgradeReboot_firmwareDwnld.sh UpgradeReboot_restore XFS wait_for_pci0_ready websocketproxyinit NSC_IR_EventReboot host_interface_dma_bus_wait usbhotplug Receiver_MDVRSet Receiver_VidiPath_Enabled Receiver_Toggle_Optimus S04init_ticket Network-Service monitor.sh ecmIpMonitor.sh monitorMfrMgr.sh vlAPI_Caller_Upgrade ImageUpgrade_rmf_osal ImageUpgrade_mfr_api ImageUpgrade_updateNewImage.sh ImageUpgrade_userInitiatedFWDnld.sh ClearSICache tr69hostIfReset hostIf_utils hostifDeviceInfo HAL_SYS_Reboot UpgradeReboot_deviceInitiatedFWDnld.sh UpgradeReboot_rdkvfwupgrader UpgradeReboot_ipdnl.sh PowerMgr_Powerreset PowerMgr_coldFactoryReset DeepSleepMgr PowerMgr_CustomerReset PowerMgr_PersonalityReset Power_Thermmgr PowerMgr_Plat HAL_CDL_notify_mgr_event vldsg_estb_poll_ecm_operational_state BcmIndicateEcmReset SASWatchDog BP3_Provisioning eMMC_FW_UPGRADE BOOTLOADER_UPGRADE cdl_service BCMCommandHandler BRCM_Image_Validate docsis_mode_check.sh tch_nvram.sh Receiver CANARY_Update boot_FSR) +MAINTENANCE_TRIGGERED_REASONS=(AutoReboot.sh PwrMgr) +pid_file="/tmp/.rebootNow.pid" +customReason="Unknown" +otherReason="Unknown" + +touch $REBOOTINFO_LOGFILE + +rebootLog "Start of rebootNow script" + +pidCleanup() +{ + if [ -f "$pid_file" ];then + rm -rf "$pid_file" + fi +} + +trap pidCleanup EXIT + +# exit if an instance is already running +rebootLog "Checking multiple instance of rebootNow.sh script" +if [ -f $pid_file ];then + pid=`cat $pid_file` + if [ -d /proc/$pid -a -f /proc/$pid/cmdline ]; then + processName=`cat /proc/$pid/cmdline` + currentprocessName=`cat /proc/$$/cmdline` + rebootLog "proc entry process name: $processName and running process name $currentprocessName" + if echo "$processName" | grep -q `basename $0`; then + rebootLog "An instance of "$0" with pid $pid is already running.." + rebootLog "Exiting script!!!" + exit 1 + fi + fi +fi +echo $$ > $pid_file + +while getopts ":s:c:r:o:" opt; do + case $opt in + s) + source=$OPTARG + rebootLogReason="Triggered from $source process" + case $source in + runPodRecovery) + t2CountNotify "SYST_ERR_RunPod_reboot" + ;; + CardNotResponding) + t2CountNotify "SYST_ERR_CCNotRepsonding_reboot" + ;; + *) + t2CountNotify "SYST_ERR_$source" + ;; + esac + ;; + c) + source=$OPTARG + rebootLogReason="Triggered from $source process failure or crash..!" + case $source in + dsMgrMain) + t2CountNotify "SYST_ERR_DSMGR_reboot" + ;; + IARMDaemonMain) + t2CountNotify "SYST_ERR_IARMDEMON_reboot" + ;; + rmfStreamer) + t2CountNotify "SYST_ERR_Rmfstreamer_reboot" + ;; + runPod) + t2CountNotify "SYST_ERR_RunPod_reboot" + ;; + *) + t2CountNotify "SYST_ERR_$source_reboot" + ;; + esac + ;; + r) + customReason=$OPTARG + ;; + o) + otherReason=$OPTARG + ;; + \?) + rebootLog "Invalid option: -$OPTARG" + ;; + esac +done + +rebootLog "Reboot requested on the device from Source:$source Reason:$otherReason" + +# Assign rebootreason from source category. +if [[ "${APP_TRIGGERED_REASONS[@]}" == *"$source"* ]];then + rebootReason="APP_TRIGGERED" + if [ $customReason == "MAINTENANCE_REBOOT" ];then + rebootReason="MAINTENANCE_REBOOT" + fi +elif [[ "${OPS_TRIGGERED_REASONS[@]}" == *"$source"* ]];then + rebootReason="OPS_TRIGGERED" +elif [[ "${MAINTENANCE_TRIGGERED_REASONS[@]}" == *"$source"* ]];then + rebootReason="MAINTENANCE_REBOOT" +else + rebootReason="FIRMWARE_FAILURE" +fi + +NewCronHr=0 +NewCronMin=0 +SECS_THRESHOLD=29 +MINS_THRESHOLD=59 +HOUR_THRESHOLD=23 + +getNewCronTime() { + # date is defined as alias of date -u. Due to this on llama uk delay download is not working. + # So removed alias and use only date for cron job schedule. + now=$(\date +"%T") + rebootLog "current time: $now" + NewCronHr=$(echo $now | cut -d':' -f1) + NewCronMin=$(echo $now | cut -d':' -f2) + Sec=$(echo $now | cut -d':' -f3) + + if [ $Sec -gt $SECS_THRESHOLD ]; then + NewCronMin=`expr $NewCronMin + 1` + fi + + NewCronMin=`expr $NewCronMin + $1` + + while [ $NewCronMin -gt $MINS_THRESHOLD ] + do + NewCronMin=`expr $NewCronMin - 60` + NewCronHr=`expr $NewCronHr + 1` + if [ $NewCronHr -gt $HOUR_THRESHOLD ]; then + NewCronHr=0 + fi + done + + echo "*/$NewCronMin $NewCronHr * * *" +} + +#Add the reboot reason check here +reboot_counter_reset=0 +if [ -f $REBOOTNOW_FLAG ] && [ "$REBOOTSTOP_DETECTION" != "false" ];then + rebootLog "Previous Reboot happened on the device was triggred by RDK software" + rebootLog "Reboot Loop Detection enabled to check cyclic reboot scenarios:$REBOOTSTOP_DETECTION" + rm -rf $REBOOTNOW_FLAG + if [ -f $PREVIOUSREBOOT_INFO_FILE ];then + prev_reboot_source=$(grep '"source"' "$PREVIOUSREBOOT_INFO_FILE" | sed -E 's/.*"source":"([^"]+)".*/\1/') + prev_reboot_reason=$(grep '"reason"' "$PREVIOUSREBOOT_INFO_FILE" | sed -E 's/.*"reason":"([^"]+)".*/\1/') + prev_reboot_customreason=$(grep '"customReason"' "$PREVIOUSREBOOT_INFO_FILE" | sed -E 's/.*"customReason":"([^"]+)".*/\1/') + prev_reboot_otherreason=$(grep '"otherReason"' "$PREVIOUSREBOOT_INFO_FILE" | sed -E 's/.*"otherReason":"([^"]+)".*/\1/') + prev_reboot_time=$(grep '"timestamp"' "$PREVIOUSREBOOT_INFO_FILE" | sed -E 's/.*"timestamp":"([^"]+)".*/\1/') + rebootLog "Previous Reboot Information of the Device:" + rebootLog "Time:$prev_reboot_time" + rebootLog "Source:$prev_reboot_source" + rebootLog "Reason:$prev_reboot_reason" + rebootLog "customReason:$prev_reboot_customreason" + rebootLog "otherReason:$prev_reboot_otherreason" + + current_reboot_source="$source" + current_reboot_reason="$rebootReason" + current_reboot_customreason="$customReason" + current_reboot_otherreason="$otherReason" + current_device_uptime=`cat /proc/uptime | awk '{print $1}' | sed "s/\..*//"` + rebootLog "Device Uptime from last reboot: $current_device_uptime secs" + + rebootLog "Current Requested Reboot Information:" + rebootLog "Source:$current_reboot_source" + rebootLog "Reason:$current_reboot_reason" + rebootLog "customReason:$current_reboot_customreason" + rebootLog "otherReason:$current_reboot_otherreason" + if [[ $current_device_uptime -le "$REBOOT_WINDOW_SECS" ]]; then + rebootLog "Reboot requested before the $REBOOT_WINDOW mins, checking reboot reason" + if [ "$current_reboot_source" == "$prev_reboot_source" ] && [ "$current_reboot_reason" == "$prev_reboot_reason" ] && + [ "$current_reboot_customreason" == "$prev_reboot_customreason" ] && [ "$current_reboot_otherreason" == "$prev_reboot_otherreason" ]; then + rebootLog "Reboot Reason for current and previous reboot is same" + if [ -f $REBOOTSTOP_FLAG ]; then + rebootLog "Reboot Operation Halted in the device to avoid continous reboots with same reason!!!" + touch $REBOOTNOW_FLAG + rebootLog "Exiting without rebooting the device" + exit 0 + else + reboot_count=`cat $REBOOT_COUNTER` + rebootLog "Checking device is stuck in cyclic reboot loop with same reboot reason, Current Iteration:$reboot_count" + if [ $reboot_count -ge $REBOOT_CYCLE_THRESHOLD ];then + rebootLog "Detected Reboot Loop in device, Halting reboot for next $REBOOTSTOP_DURATION mins to perform operations!!!" + touch $REBOOTSTOP_FLAG + tr181 -s -v true Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RebootStop.Enable + rebootstopvalue=`tr181 -g Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RebootStop.Enable 2>&1 > /dev/null` + rebootLog "Publishing Reboot Stop Enable Event:$rebootstopvalue" + t2CountNotify "SYST_ERR_Cyclic_reboot" + # Remove any old Reboot Cron Jobs + sh /lib/rdk/cronjobs_update.sh "remove" "rebootNow.sh" + REBOOT_CRON_INTERVAL_TIME=$(getNewCronTime $REBOOTSTOP_DURATION) + rebootLog "Scheduling Cron for rebootNow.sh as a part of Cyclic reboot operations: $REBOOT_CRON_INTERVAL_TIME" + sh /lib/rdk/cronjobs_update.sh "add" "rebootNow.sh" "$REBOOT_CRON_INTERVAL_TIME /bin/sh /lib/rdk/rebootNow.sh -s \"$CYCLIC_REBOOT_SOURCE\" -o \"$CYCLIC_REBOOT_REASON\"" + rebootLog "Device will reboot in $REBOOTSTOP_DURATION mins after expiry of Cyclic reboot pause window!!!" + touch $REBOOTNOW_FLAG + exit 0 + else + reboot_count=$((reboot_count + 1)) + echo $reboot_count > $REBOOT_COUNTER + fi + fi + else + rebootLog "Reboot requested before the $REBOOT_WINDOW mins reboot loop window with different reason" + reboot_counter_reset=1 + fi + else + rebootLog "Reboot requested after the $REBOOT_WINDOW mins reboot loop window" + reboot_counter_reset=1 + fi + else + rebootLog "$PREVIOUSREBOOT_INFO_FILE file not found, proceed without reboot reason check!!!" + reboot_counter_reset=1 + fi +else + if [ ! -f $REBOOTNOW_FLAG ]; then + rebootLog "Last reboot was not triggered by rebootNow.sh script" + else + rebootLog "Reboot Loop Detection disabled to check cyclic reboot scenarios:$REBOOTSTOP_DETECTION" + fi + reboot_counter_reset=1 +fi + +#Reset cyclic reboot counter +if [ $reboot_counter_reset == 1 ];then + rebootLog "Publishing Reboot Stop Disable Event" + tr181 -s -v false Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RebootStop.Enable + rebootLog "Reboot Loop Detection counter reset as device not in reboot loop" + echo 0 > $REBOOT_COUNTER + rm -rf $REBOOTSTOP_FLAG +fi + +syncLog() +{ + if [ -d "$TEMP_LOG_PATH" ]; then + rebootLog "${FUNCNAME[0]}: Find and move the logs from $TEMP_LOG_PATH to $LOG_PATH" + cWD=`pwd` + syncPath=`find $TEMP_LOG_PATH -type l -exec ls -l {} \; | cut -d ">" -f2 | tr -d ' '` + if [ "$syncPath" != "$LOG_PATH" ];then + cd "$TEMP_LOG_PATH" + for file in `ls *.txt *.log` + do + cat $file >> $LOG_PATH/$file + cat /dev/null > $file + done + cd $cWD + else + rebootLog "${FUNCNAME[0]}: Sync Not needed, Same log folder" + fi + else + rebootLog "${FUNCNAME[0]}: $TEMP_LOG_PATH not found!!!" + fi +} + +# Save the reboot info with all the fields +setPreviousRebootInfo() +{ + rebootLog "${FUNCNAME[0]}: Saving reboot info in $REBOOT_INFO_FILE file" + timestamp=$1 + source=$2 + reason=$3 + custom=$4 + other=$5 + echo "{" > $REBOOT_INFO_FILE + echo "\"timestamp\":\"$timestamp\"," >> $REBOOT_INFO_FILE + echo "\"source\":\"$source\"," >> $REBOOT_INFO_FILE + echo "\"reason\":\"$reason\"," >> $REBOOT_INFO_FILE + echo "\"customReason\":\"$custom\"," >> $REBOOT_INFO_FILE + echo "\"otherReason\":\"$other\"" >> $REBOOT_INFO_FILE + echo "}" >> $REBOOT_INFO_FILE + + echo "PreviousRebootInfo:$timestamp,$custom,$source,$reason" >> $PARODUS_REBOOT_INFO_FILE + rebootLog "${FUNCNAME[0]}: Updated Reboot Reason information in $REBOOT_INFO_FILE and $PARODUS_REBOOT_INFO_FILE" +} + +# Log reboot information to rebootInfo.log file +rebootTime=`date -u` + +if [ "$otherReason" == "Unknown" ]; then + echo "RebootReason: $rebootLogReason" >> $REBOOTINFO_LOGFILE +else + echo "RebootReason: $rebootLogReason $otherReason" >> $REBOOTINFO_LOGFILE +fi +echo "RebootInitiatedBy: $source" >> $REBOOTINFO_LOGFILE +echo "RebootTime: $rebootTime" >> $REBOOTINFO_LOGFILE +echo "CustomReason: $customReason" >> $REBOOTINFO_LOGFILE +echo "OtherReason: $otherReason" >> $REBOOTINFO_LOGFILE + +# Create /opt/secure/reboot/ folder before reboot/shutdown. +if [ ! -d $REBOOT_INFO_DIR ]; then + rebootLog "Creating $REBOOT_INFO_DIR folder" + mkdir $REBOOT_INFO_DIR +fi + +# Added check for Hal_SYS_reboot source +multipleSource=`grep -E HAL_SYS_Reboot $REBOOTINFO_LOGFILE` +if [ -z "$multipleSource" ];then + rebootSource=$source +else + rebootSource=`grep RebootReason $REBOOTINFO_LOGFILE | grep -v HAL_SYS_Reboot | grep -v grep | awk -F " " '{print $5}'` + otherReason=`grep RebootReason $REBOOTINFO_LOGFILE | grep -v HAL_SYS_Reboot | grep -v grep | awk -F 'HAL_CDL_notify_mgr_event' '{print $NF}' | sed 's/(.*//'` +fi + +# Save reboot details in reboot.info file under /opt/secure/reboot folder +rebootLog "Invoke setPreviousRebootInfo to save reboot information under $REBOOT_INFO_DIR folder" +setPreviousRebootInfo "$rebootTime" "$rebootSource" "$rebootReason" "$customReason" "$otherReason" + +isMmgbleNotifyEnabled=$(tr181 Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.ManageableNotification.Enable 2>&1 > /dev/null) +rebootLog "Value of Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.ManageableNotification.Enable: $isMmgbleNotifyEnabled" +if [ "${isMmgbleNotifyEnabled}" == "true" ];then + tr181 -s -v 10 Device.DeviceInfo.X_RDKCENTRAL-COM_xOpsDeviceMgmt.RPC.RebootPendingNotification +fi + +#### +# All housekeeping before actual device reboot starts from here +#### + +# Signal telemetry2_0 to send out any pending messages before reboot +rebootLog "Signal telemetry2_0 to send out any pending messages before reboot" +killall -s SIGIO telemetry2_0 + +# Kill the Parodus Process; So that it can close the WebSocket Connection with Server. +rebootLog "Properly shutdown parodus by sending SIGUSR1 kill signal" +killall -s SIGUSR1 parodus + +if [ -f /etc/rdm/rdm-manifest.xml ];then + if [[ ${CDLFILE} != *"${PREV_CDLFILE}"* ]]; then + if [ -d /media/apps ];then + rebootLog "Removing the RDM Apps content from Secondary Storage before Reboot (After IMage Upgrade)" + cd /media/apps + if [ $? -eq 0 ];then + for i in `ls -d */` + do + rm -rf $i + sleep 1 + done + fi + sleep 5 + fi + fi +fi + +if [ ! -f $PERSISTENT_PATH/.lightsleepKillSwitchEnable ];then + syncLog + if [ -f $TEMP_LOG_PATH/.systime ];then + cp $TEMP_LOG_PATH/.systime $PERSISTENT_PATH/ + fi +fi + +if [ "$DEVICE_NAME" = "XI6" ] || [ "$DEVICE_NAME" = "XiOne" ] || [ "$DEVICE_NAME" = "XiOne-SCB" ];then + if [ "$DEVICE_NAME" = "XI6" ];then + # Get eMMC Health report + if [ -f /lib/rdk/emmc_health_diag.sh ];then + sh /lib/rdk/emmc_health_diag.sh "reboot" + rebootLog "Updated eMMC Health report" + fi + fi + # See if we need to Upgrade the eMMC FW + if [ -f /lib/rdk/eMMC_Upgrade.sh ];then + rebootLog "Upgrade eMMC FW if required" + sh /lib/rdk/eMMC_Upgrade.sh + fi +fi + +if [ -f /lib/rdk/aps4_reset.sh ];then + rebootLog "Executing /lib/rdk/aps4_reset.sh" + sh /lib/rdk/aps4_reset.sh +fi + +if [ -f /lib/rdk/update_www-backup.sh ];then + rebootLog "Executing /lib/rdk/update_www-backup.sh" + sh /lib/rdk/update_www-backup.sh +fi + +#If bluetooth is enabled, gracefully shutdown the bluetooth related services +if [ "$BLUETOOTH_ENABLED" = "true" ];then + services=("ctrlm-main" "btmgr" "bluetooth" "bt-hciuart" "btmac-preset" "bt" "syslog-ng") + rebootLog "Shutting down the bluetooth and syslog-ng services gracefully" + for service in "${services[@]}"; do + rebootLog "Shutting down the $service service" + if /bin/systemctl --quiet is-active "$service"; then + /bin/systemctl stop "$service" + if [[ $? -eq 0 ]]; then + rebootLog "$service service stopped successfully" + else + rebootLog "Failed to stop $service service" + fi + else + rebootLog "$service service is not active" + fi + done +fi + +rebootLog "Start the sync" +sync +rebootLog "End of the sync" + +rebootLog "Creating $REBOOTNOW_FLAG as the reboot was triggred by RDK software" +touch $REBOOTNOW_FLAG +rm -rf $pid_file + +rebootLog "Rebooting the Device Now" +reboot & +REBOOT_PID=$! + +sleep 90 +rebootLog "System still running after reboot command, Reboot Failed for $REBOOT_PID..." +systemctl reboot +if [ $? -eq 1 ]; then + rebootLog "Reboot failed due to systemctl hang or connection timeout" +fi +kill $REBOOT_PID 2>/dev/null +rebootLog "Triggering force Reboot after standard soft reboot failure" +reboot -f diff --git a/lib/rdk/system_info_collector.sh b/lib/rdk/system_info_collector.sh index fea0ada0..9532bc91 100755 --- a/lib/rdk/system_info_collector.sh +++ b/lib/rdk/system_info_collector.sh @@ -69,7 +69,10 @@ MEM_AVAILABLE=$(cat /proc/meminfo | grep MemAvailable) echo $MEM_AVAILABLE >> $LOG_PATH/messages.txt MEM_AVAILABLE_VAL=$(echo "$MEM_AVAILABLE" | tr -s '[:space:]' ' ' | cut -d' ' -f2) t2ValNotify "SYST_INFO_MemAvailable_split" "$MEM_AVAILABLE_VAL" +<<<<<<< HEAD +======= +>>>>>>> 4.2.1v17 # Swap Memory Info echo "Available Swap Memory Info:" >> $LOG_PATH/messages.txt diff --git a/lib/rdk/timesyncd-conf-update.sh b/lib/rdk/timesyncd-conf-update.sh index 59a389fe..8c726157 100755 --- a/lib/rdk/timesyncd-conf-update.sh +++ b/lib/rdk/timesyncd-conf-update.sh @@ -82,7 +82,11 @@ get_ntp_hosts_from_bootstrap() { } +<<<<<<< HEAD ntpLog "Retrieve NTP Server URL from /lib/rdk/getPartnerProperty.sh..." +======= +ntpLog "Retrive NTP Server URL from /lib/rdk/getPartnerProperty.sh..." +>>>>>>> 4.2.1v17 while [ "$attempts" -le "$max_attempts" ]; do ntpLog "Attempt $attempts/$max_attempts to retrieve NTP server URL(s)..." diff --git a/lib/rdk/update_previous_reboot_info.sh b/lib/rdk/update_previous_reboot_info.sh new file mode 100755 index 00000000..e92cdfae --- /dev/null +++ b/lib/rdk/update_previous_reboot_info.sh @@ -0,0 +1,487 @@ +#!/bin/sh +############################################################################## +# If not stated otherwise in this file or this component's LICENSE file the +# following copyright and licenses apply: +# +# Copyright 2020 RDK Management +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################## + +# Source Variable +. /etc/device.properties +if [ -f /lib/rdk/t2Shared_api.sh ]; then + source /lib/rdk/t2Shared_api.sh +fi + +# Define logfiles and flags +REBOOT_INFO_LOG_FILE="/opt/logs/rebootInfo.log" +KERNEL_LOG_FILE="/opt/logs/messages.txt" +UIMGR_LOG_FILE="/opt/logs/PreviousLogs/uimgr_log.txt" +OCAPRI_LOG_FILE="/opt/logs/PreviousLogs/ocapri_log.txt" +ECM_CRASH_LOG_FILE="/opt/logs/PreviousLogs/messages-ecm.txt" +PSTORE_CONSOLE_LOG_FILE="/sys/fs/pstore/console-ramoops-0" +KERNEL_PANIC_SEARCH_STRING="PREVIOUS_KERNEL_OOPS_DUMP" +KERNEL_PANIC_SEARCH_STRING_01="Kernel panic - not syncing" +KERNEL_PANIC_SEARCH_STRING_02="Oops - undefined instruction" +KERNEL_PANIC_SEARCH_STRING_03="Oops - bad syscall" +KERNEL_PANIC_SEARCH_STRING_04="branch through zero" +KERNEL_PANIC_SEARCH_STRING_05="unknown data abort code" +KERNEL_PANIC_SEARCH_STRING_06="Illegal memory access" +ECM_CRASH_SEARCH_STRING="\*\*\*\* CRASH \*\*\*\*" +MAX_REBOOT_STRING="Box has rebooted 10 times" +POWERON_STRING="POWER_ON" +REBOOT_INFO_DIR="/opt/secure/reboot" +REBOOT_INFO_FILE="/opt/secure/reboot/reboot.info" +PARODUS_REBOOT_INFO_FILE="/opt/secure/reboot/parodusreboot.info" +KEYPRESS_INFO_FILE="/opt/secure/reboot/keypress.info" +PREVIOUS_REBOOT_INFO_FILE="/opt/secure/reboot/previousreboot.info" +PREVIOUS_PARODUSREBOOT_INFO_FILE="/opt/secure/reboot/previousparodusreboot.info" +PREVIOUS_HARD_REBOOT_INFO_FILE="/opt/secure/reboot/hardpower.info" +PREVIOUS_KEYPRESS_INFO_FILE="/opt/secure/reboot/previouskeypress.info" +STT_FLAG="/tmp/stt_received" +REBOOT_INFO_FLAG="/tmp/rebootInfo_Updated" +UPDATE_REBOOT_INFO_INVOKED_FLAG="/tmp/Update_rebootInfo_invoked" +LOCK_DIR="/tmp/rebootInfo.lock" +PARODUS_LOG="/opt/logs/parodus.log" + +#Use log framework to pring timestamp and source script name +rebootLog() +{ + echo "$0: $*" +} + +rebootLog "Start of Reboot Reason Script" + +# Define Reasons for APP_TRIGGERED, OPS_TRIGGERED and MAINTENANCE_TRIGGERED cases +APP_TRIGGERED_REASONS=(Servicemanager systemservice_legacy WarehouseReset WarehouseService HrvInitWHReset HrvColdInitReset HtmlDiagnostics InstallTDK StartTDK TR69Agent SystemServices Bsu_GUI SNMP CVT_CDL Nxserver DRM_Netflix_Initialize hrvinit ) +OPS_TRIGGERED_REASONS=(ScheduledReboot RebootSTB.sh FactoryReset UpgradeReboot_restore XFS wait_for_pci0_ready websocketproxyinit NSC_IR_EventReboot host_interface_dma_bus_wait usbhotplug Receiver_MDVRSet Receiver_VidiPath_Enabled Receiver_Toggle_Optimus S04init_ticket Network-Service monitorMfrMgr.sh vlAPI_Caller_Upgrade ImageUpgrade_rmf_osal ImageUpgrade_mfr_api ImageUpgrade_userInitiatedFWDnld.sh ClearSICache tr69hostIfReset hostIf_utils hostifDeviceInfo HAL_SYS_Reboot UpgradeReboot_deviceInitiatedFWDnld.sh UpgradeReboot_rdkvfwupgrader UpgradeReboot_ipdnl.sh PowerMgr_Powerreset PowerMgr_coldFactoryReset DeepSleepMgr PowerMgr_CustomerReset PowerMgr_PersonalityReset Power_Thermmgr PowerMgr_Plat HAL_CDL_notify_mgr_event vldsg_estb_poll_ecm_operational_state SASWatchDog BP3_Provisioning eMMC_FW_UPGRADE BOOTLOADER_UPGRADE cdl_service docsis_mode_check.sh Receiver CANARY_Update) +MAINTENANCE_TRIGGERED_REASONS=(AutoReboot.sh PwrMgr) + +# Save the reboot info with all the fields +setPreviousRebootInfo() +{ + # Set Previous reboot info file with received reboot reason. + timestamp=$1 + source=$2 + reason=$3 + custom=$4 + other=$5 + # Get Previous Hard Power reset information + if [ ! -z $PREVIOUS_REBOOT_INFO_FILE ]; then + rebootLog "Reboot reason present in $PREVIOUS_REBOOT_INFO_FILE file:" + cat $PREVIOUS_REBOOT_INFO_FILE + fi + rebootLog "Updating Reboot reason in $PREVIOUS_REBOOT_INFO_FILE file" + echo "{" > $PREVIOUS_REBOOT_INFO_FILE + echo "\"timestamp\":\"$timestamp\"," >> $PREVIOUS_REBOOT_INFO_FILE + echo "\"source\":\"$source\"," >> $PREVIOUS_REBOOT_INFO_FILE + echo "\"reason\":\"$reason\"," >> $PREVIOUS_REBOOT_INFO_FILE + echo "\"customReason\":\"$custom\"," >> $PREVIOUS_REBOOT_INFO_FILE + echo "\"otherReason\":\"$other\"" >> $PREVIOUS_REBOOT_INFO_FILE + echo "}" >> $PREVIOUS_REBOOT_INFO_FILE + + rebootLog "Updating previous reboot reason in $PARODUS_LOG" + existing_reboot_info=$(grep "PreviousRebootInfo" "$PARODUS_LOG" 2>/dev/null | tail -1) + + if [ -z "$existing_reboot_info" ]; then + echo "$(/bin/timestamp) $0: Updating previous reboot info to Parodus" >> "$PARODUS_LOG" + echo "$(/bin/timestamp) $0: PreviousRebootInfo:$timestamp,$reason,$custom,$source" >> "$PARODUS_LOG" + rebootLog "Reboot Information Updated to parodus log:$timestamp,$reason,$custom,$source" + else + rebootLog "${FUNCNAME[0]}: Reboot info already present in $PARODUS_LOG as $existing_reboot_info, skipping update" + fi + + # Set Hard Power reset time with timestamp + if [ "$reason" == "HARD_POWER" ] || [ "$reason" == "POWER_ON_RESET" ] || [ "$reason" == "UNKNOWN_RESET" ] || [ ! -f "$PREVIOUS_HARD_REBOOT_INFO_FILE" ];then + echo "{" > $PREVIOUS_HARD_REBOOT_INFO_FILE + echo "\"lastHardPowerReset\":\"$timestamp\"" >> $PREVIOUS_HARD_REBOOT_INFO_FILE + echo "}" >> $PREVIOUS_HARD_REBOOT_INFO_FILE + rebootLog "Updated Hard Power Reboot Time stamp" + fi + + rebootLog "Updated Previous Reboot Reason information" +} + +# Check for Firmware Failure +fwFailureCheck() +{ + fw_failure=0 + rebootLog "Checking firmware failure cases (ECM Crash, Max Reboot etc)..." + + if [ "$DEVICE_TYPE" != "mediaclient" ]; then + if [ -f "$OCAPRI_LOG_FILE" ] && [[ $(grep "$MAX_REBOOT_STRING" $OCAPRI_LOG_FILE) ]]; then + fw_failure=1 + rebootInitiatedBy="OcapRI" + otherReason="Reboot due to STB reached maximum (10) reboots" + t2CountNotify "SYST_ERR_10Times_reboot" + fi + + if [ -f "$ECM_CRASH_LOG_FILE" ] && [[ $(grep "$ECM_CRASH_SEARCH_STRING" $ECM_CRASH_LOG_FILE) ]]; then + fw_failure=1 + rebootInitiatedBy="EcmLogger" + otherReason="Reboot due to ecm logger crash" + fi + else + if [ -f "$UIMGR_LOG_FILE" ] && [[ $(grep "$MAX_REBOOT_STRING" $UIMGR_LOG_FILE) ]]; then + fw_failure=1 + rebootInitiatedBy="UiMgr" + otherReason="Reboot due to STB reached maximum (10) reboots" + t2CountNotify "SYST_ERR_10Times_reboot" + fi + fi + + return $fw_failure +} + +# Check for OOPS DUMP string in Kernel panic scenarios +oopsDumpCheck() +{ + oops_dump=0 + + if [ "$SOC" = "BRCM" ]; then + # Ensure OOPS DUMP string presence for Kernel Panic in messages.txt + if [ -f "$KERNEL_LOG_FILE" ] && [[ $(grep $KERNEL_PANIC_SEARCH_STRING $KERNEL_LOG_FILE) ]];then + if [[ $(grep -e "Kernel Oops" -e "Kernel Panic" $KERNEL_LOG_FILE) ]];then + oops_dump=1 + fi + fi + elif [ "$RDK_PROFILE" = "TV" ]; then + #Check KERNEL PANIC, OOPS DUMP string presence for Kernel Panic in /sys/fs/pstore/console-ramoops-0 + if [ -f "$PSTORE_CONSOLE_LOG_FILE" ]; then + if [[ $(grep "$KERNEL_PANIC_SEARCH_STRING_01" $PSTORE_CONSOLE_LOG_FILE) ]];then + oops_dump=1 + elif [[ $(grep "$KERNEL_PANIC_SEARCH_STRING_02" $PSTORE_CONSOLE_LOG_FILE) ]];then + oops_dump=1 + elif [[ $(grep "$KERNEL_PANIC_SEARCH_STRING_03" $PSTORE_CONSOLE_LOG_FILE) ]];then + oops_dump=1 + elif [[ $(grep "$KERNEL_PANIC_SEARCH_STRING_04" $PSTORE_CONSOLE_LOG_FILE) ]];then + oops_dump=1 + elif [[ $(grep "$KERNEL_PANIC_SEARCH_STRING_05" $PSTORE_CONSOLE_LOG_FILE) ]];then + oops_dump=1 + elif [[ $(grep "$KERNEL_PANIC_SEARCH_STRING_06" $PSTORE_CONSOLE_LOG_FILE) ]];then + oops_dump=1 + else + oops_dump=0 + fi + + if [ "$oops_dump" -eq "1" ];then + for pstorefile in /sys/fs/pstore/* + do + filename=$(basename "${pstorefile}") + cat $pstorefile > /opt/logs/${filename}.log + done + rebootLog "Please check pstore logs(/sys/fs/pstore/*) for more detail about kerenl panic !" + fi + fi + fi + + return $oops_dump +} + + +#Read the HW Register value of PreviousRebootReason and set details. +setRebootReason() +{ + rebootReason=$1 + case $rebootReason in + SOFTWARE|SOFTWARE_MASTER_RESET) + rebootInitiatedBy="SoftwareReboot" + rebootReason="SOFTWARE_MASTER_RESET" + t2CountNotify "Test_SWReset" + otherReason="Reboot due to user triggered reboot command" + ;; + WATCHDOG|WATCHDOG_TIMER_RESET) + rebootInitiatedBy="WatchDog" + rebootReason="WATCHDOG_TIMER_RESET" + otherReason="Reboot due to watch dog timer reset" + ;; + KERNEL_PANIC_RESET) + rebootInitiatedBy="Kernel" + rebootReason="KERNEL_PANIC" + otherReason="Reboot due to Kernel Panic captured by Oops Dump" + ;; + HARDWARE|POWER_ON_RESET) + rebootInitiatedBy="PowerOn" + rebootReason="POWER_ON_RESET" + otherReason="Reboot due to unplug of power cable from the STB" + ;; + MAIN_CHIP_INPUT_RESET) + rebootInitiatedBy="Main Chip" + rebootReason="MAIN_CHIP_INPUT_RESET" + otherReason="Reboot due to chip's main reset input has been asserted" + ;; + MAIN_CHIP_RESET_INPUT) + rebootInitiatedBy="Main Chip" + rebootReason="MAIN_CHIP_RESET_INPUT" + otherReason="Reboot due to chip's main reset input has been asserted" + ;; + TAP_IN_SYSTEM_RESET) + rebootInitiatedBy="Tap-In System" + rebootReason="TAP_IN_SYSTEM_RESET" + otherReason="Reboot due to the chip's TAP in-system reset has been asserted" + ;; + FRONT_PANEL_4SEC_RESET) + rebootInitiatedBy="FrontPanel Button" + rebootReason="FRONT_PANEL_RESET" + otherReason="Reboot due to the front panel 4 second reset has been asserted" + ;; + S3_WAKEUP_RESET) + rebootInitiatedBy="Standby Wakeup" + rebootReason="S3_WAKEUP_RESET" + otherReason="Reboot due to the chip woke up from deep standby" + ;; + SMARTCARD_INSERT_RESET) + rebootInitiatedBy="SmartCard Insert" + rebootReason="SMARTCARD_INSERT_RESET" + otherReason="Reboot due to the smartcard insert reset has occurred" + ;; + OVERHEAT|OVERTEMP_RESET) + rebootInitiatedBy="OverTemperature" + rebootReason="OVERTEMP_RESET" + otherReason="Reboot due to chip temperature is above threshold (125*C)" + ;; + OVERVOLTAGE_1_RESET|OVERVOLTAGE_RESET) + rebootInitiatedBy="OverVoltage" + rebootReason="OVERVOLTAGE_RESET" + otherReason="Reboot due to chip voltage is above threshold" + ;; + PCIE_1_HOT_BOOT_RESET|PCIE_0_HOT_BOOT_RESET) + rebootInitiatedBy="PCIE Boot" + rebootReason="PCIE_HOT_BOOT_RESET" + otherReason="Reboot due to PCIe hot boot reset has occurred" + ;; + UNDERVOLTAGE_1_RESET|UNDERVOLTAGE_0_RESET|UNDERVOLTAGE_RESET) + rebootInitiatedBy="LowVoltage" + rebootReason="UNDERVOLTAGE_RESET" + otherReason="Reboot due to chip voltage is below threshold" + ;; + SECURITY_MASTER_RESET) + rebootInitiatedBy="SecutiryReboot" + rebootReason="SECURITY_MASTER_RESET" + otherReason="Reboot due to security master reset has occurred" + ;; + CPU_EJTAG_RESET) + rebootInitiatedBy="CPU EJTAG" + rebootReason="CPU_EJTAG_RESET" + otherReason="Reboot due to CPU EJTAG reset has occurred" + ;; + SCPU_EJTAG_RESET) + rebootInitiatedBy="SCPU EJTAG" + rebootReason="SCPU_EJTAG_RESET" + otherReason="Reboot due to SCPU EJTAG reset has occurred" + ;; + GEN_WATCHDOG_1_RESET) + rebootInitiatedBy="GEN WatchDog" + rebootReason="GEN_WATCHDOG_RESET" + otherReason="Reboot due to gen_watchdog_1 timeout reset has occurred" + ;; + AUX_CHIP_EDGE_RESET_0|AUX_CHIP_EDGE_RESET_1) + rebootInitiatedBy="Aux Chip Edge" + rebootReason="AUX_CHIP_EDGE_RESET" + otherReason="Reboot due to the auxiliary edge-triggered chip reset has occurred" + ;; + AUX_CHIP_LEVEL_RESET_0|AUX_CHIP_LEVEL_RESET_1) + rebootInitiatedBy="Aux Chip Level" + rebootReason="AUX_CHIP_LEVEL_RESET" + otherReason="Reboot due to the auxiliary level-triggered chip reset has occurred" + ;; + MPM_RESET) + rebootInitiatedBy="MPM" + rebootReason="MPM_RESET" + otherReason="Reboot due to the MPM reset has occurred" + ;; + *) + rebootInitiatedBy="Hard Power" + rebootReason="$rebootReason" + otherReason="Reboot due to $rebootReason" + ;; + esac +} + +#Perform locking of script execution to avoid parallel execution +lock() +{ + while ! mkdir "$LOCK_DIR" &> /dev/null;do + rebootLog "Waiting for rebootInfo lock" + sleep 5 + done + rebootLog "Acquired rebootInfo lock" +} + +#Unlock before exiting the script +unlock() +{ + rm -rf "$LOCK_DIR" + rebootLog "Releasing rebootInfo lock" +} + +#Check for STT and Reboot Checker flag before updating reboot reason +CheckSTT() +{ + rebootLog "Checking ${STT_FLAG} and ${REBOOT_INFO_FLAG} flag to update the reboot reason" + if [ ! -f "${STT_FLAG}" ] || [ ! -f "${REBOOT_INFO_FLAG}" ];then + rebootLog "Exiting since ${STT_FLAG} or ${REBOOT_INFO_FLAG} flag is not available" + unlock + rebootLog "End of Reboot Reason Script" + exit 0 + fi +} + +#Fucntion to update reboot reason when hardware register is empty +exitforNullrebootreason() +{ + rebootInitiatedBy="Hard Power Reset" + customReason="Hardware Register - NULL" + otherReason="No information found" + rebootReason="HARD_POWER" + setPreviousRebootInfo "$rebootTime" "$rebootInitiatedBy" "$rebootReason" "$customReason" "$otherReason" + unlock + rebootLog "End of Reboot Reason Script" + exit 0 +} + + + +############################## +########## Main APP ########## +############################## + +lock + +#check for first time invocation flag and proceed for script execution + + CheckSTT + +#Creating reboot folder in /opt/secure/ path +if [ ! -d $REBOOT_INFO_DIR ]; then + rebootLog "Creating $REBOOT_INFO_DIR folder..." + mkdir $REBOOT_INFO_DIR +fi + +if [ "$RDK_PROFILE" = "TV" ]; then + # Check to see if we already have the entry in the log + prevReboot=`grep "PreviousRebootReason" $KERNEL_LOG_FILE` + if [ -z "$prevReboot" ]; then + oopsDumpCheck + kernel_crash=$? + if [ $kernel_crash -eq 1 ];then + echo "`/bin/timestamp` PreviousRebootReason: kernel_panic!" >> $KERNEL_LOG_FILE + else + if [ -f /lib/rdk/get-reboot-reason.sh ]; then + sh /lib/rdk/get-reboot-reason.sh >> $KERNEL_LOG_FILE + fi + fi + fi +fi + +# Use current time to report the kernel crash and hard power reset +rebootTimestamp=`date -u` + +# Read and Move /opt/secure/reboot/reboot.info as /opt/secure/reboot/previousreboot.info +if [ -f "$REBOOT_INFO_FILE" ];then + rebootLog "New $REBOOT_INFO_FILE file found, Creating previous reboot info file..." + cat $REBOOT_INFO_FILE + mv $REBOOT_INFO_FILE $PREVIOUS_REBOOT_INFO_FILE + if [ -f "$PARODUS_REBOOT_INFO_FILE" ];then + rebootLog "New $PARODUS_REBOOT_INFO_FILE file found, updating parodus logfile..." + rebootinfo=`cat $PARODUS_REBOOT_INFO_FILE` + echo "`/bin/timestamp` $0: $rebootinfo" >> $PARODUS_LOG + mv $PARODUS_REBOOT_INFO_FILE $PREVIOUS_PARODUSREBOOT_INFO_FILE + fi +else + rebootLog "$REBOOT_INFO_FILE file not found, Assigning default values..." + # Set following variables to NULL before using them + rebootInitiatedBy="" + rebootTime="" + customReason="" + otherReason="" + + # Reading the previous reboot details from /opt/logs/rebootInfo.log + if [ -f "$REBOOT_INFO_LOG_FILE" ];then + rebootLog "$REBOOT_INFO_LOG_FILE logfile found, Fetching source, time and other reasons" + # Parse Previous reboot Info and remove leading space + rebootInitiatedBy=`grep "PreviousRebootInitiatedBy:" $REBOOT_INFO_LOG_FILE | grep -v grep | awk -F "PreviousRebootInitiatedBy:" '{print $2}' | sed 's/^ *//'` + rebootTime=`grep "PreviousRebootTime:" $REBOOT_INFO_LOG_FILE | grep -v grep | awk -F 'PreviousRebootTime:' '{print $2}' | sed 's/^ *//'` + customReason=`grep "PreviousCustomReason:" $REBOOT_INFO_LOG_FILE | grep -v grep | awk -F "PreviousCustomReason:" '{print $2}' | sed 's/^ *//'` + otherReason=`grep "PreviousOtherReason:" $REBOOT_INFO_LOG_FILE | grep -v grep | awk -F 'PreviousOtherReason:' '{print $2}' | sed 's/^ *//'` + fi + + rebootLog "Validating reboot information received from $REBOOT_INFO_LOG_FILE..." + if [ "x$rebootInitiatedBy" == "x" ];then + rebootLog "$REBOOT_INFO_LOG_FILE file not found and Value of rebootInitiatedBy=$rebootInitiatedBy is empty" + rebootTime="$rebootTimestamp" + # Check for Kernel Panic Reboot + rebootLog "Checking for OOPS DUMP for Kernel Panic..." + oopsDumpCheck + kernel_crash=$? + if [ $kernel_crash -eq 1 ];then + rebootReason="KERNEL_PANIC" + rebootInitiatedBy="Kernel" + customReason="Hardware Register - KERNEL_PANIC" + otherReason="Reboot due to Kernel Panic captured by Oops Dump" + else + # Reading hard reset values from sysfs + rebootLog " Hard Power Reboot info is missing!!!" + exitforNullrebootreason + fi + else + rebootLog "$REBOOT_INFO_LOG_FILE logfile found and received source of rebootInitiatedBy=$rebootInitiatedBy" + # Assign reboot reason by comparing the rebootInitiatedBy with APP_TRIGGERED_REASONS/OPS_TRIGGERED_REASONS/MAINTENANCE_TRIGGERED_REASONS + if [[ "${APP_TRIGGERED_REASONS[@]}" == *"$rebootInitiatedBy"* ]];then + rebootReason="APP_TRIGGERED" + # Assign reboot reason as MAINTENANCE_REBOOT if customReason is passed as MAINTENANCE_REBOOT + if [ $customReason == "MAINTENANCE_REBOOT" ];then + rebootReason="MAINTENANCE_REBOOT" + fi + elif [[ "${OPS_TRIGGERED_REASONS[@]}" == *"$rebootInitiatedBy"* ]];then + rebootReason="OPS_TRIGGERED" + elif [[ "${MAINTENANCE_TRIGGERED_REASONS[@]}" == *"$rebootInitiatedBy"* ]];then + rebootReason="MAINTENANCE_REBOOT" + else + rebootReason="FIRMWARE_FAILURE" + fi + fi + + # FIRMWARE FAILURE is of high priority for all the STB platforms and not applicable for TV platforms + # We have to report it before updating any soft/hard reboot scenarios + # Check for FIRMWARE FAILURE cases (ECM Crash, Max reboot etc) for STB platforms + + #Update reboot information in /opt/secure/reboot/previousreboot.info file + setPreviousRebootInfo "$rebootTime" "$rebootInitiatedBy" "$rebootReason" "$customReason" "$otherReason" +fi + + # if we didn't any reboot reason yet. + if [ -z "$prevrebootreason" ]; then + rebootLog "Get reboot reason from get-reboot-reason.sh..." + if [ -f /lib/rdk/get-reboot-reason.sh ]; then + sh /lib/rdk/get-reboot-reason.sh >> $KERNEL_LOG_FILE + fi + fi +fi + +# Keypress information +if [ -f "$KEYPRESS_INFO_FILE" ]; then + cp -f $KEYPRESS_INFO_FILE $PREVIOUS_KEYPRESS_INFO_FILE + rebootLog "Updated previous keypress info" +else + rebootLog "Unable to find the $KEYPRESS_INFO_FILE file" +fi + +# Create flag to ensure updatePreviousRebootInfo.sh script is invoked +if [ ! -f "$UPDATE_REBOOT_INFO_INVOKED_FLAG" ];then + touch $UPDATE_REBOOT_INFO_INVOKED_FLAG +fi + +rebootLog "End of Reboot Reason Script" +unlock