1 #!/system/bin/sh 2 #set -x 3 4 ###### KNOWN ISSUES ###### 5 # - qbpfs pull is returning $?=0 when it fails 6 # - AP needs a more deterministic way of detecting the max dumps the BP will 7 # store. Otherwise the script will fail to calculate the rollover back 8 # to index 0. 9 10 ###### FUNCTIONS ###### 11 12 setupDirs() { 13 case $parentExists in 14 1) 15 outDirRoot=$1 16 outDirBranch=$2 17 ;; 18 0) 19 outDirRoot="/data/misc/ril" 20 outDirBranch="bp-dump/${timestamp}/qcom" 21 cd $outDirRoot 22 case $? in 0) ;; *) echo "Couldn\'t cd to $outDirRoot"; exit 1;; esac 23 # Set delimiter to slash for separating directories 24 OIFS=$IFS; IFS='/' 25 for dir in $outDirBranch; do 26 mkdir "$dir" 2>/dev/null 27 cd "$dir" 2>&1 28 case $? in 0) ;; *) echo "Couldn\'t cd to $dir"; exit 1;; esac 29 outDirBranchUnwind="$dir $outDirBranchUnwind" 30 done 31 IFS=$OIFS 32 ;; 33 esac 34 outDir="${outDirRoot}/${outDirBranch}" 35 } 36 37 processLogs() { 38 # Initialize communication with the BP 39 qbpfs hello 40 case $? in 0) ;; *) echo "qbpfs hello failed"; return;; esac 41 42 local maxIndexes=$1 43 local nextErrIndex="" 44 local indexesToPull="" 45 case $maxIndexes in 46 0) 47 echo "Nothing to do for indexes=0" 48 return 49 ;; 50 1) 51 # If we only support one dump, then we can detect when it has finished 52 # by first removing the err_index.txt and then watching for it to 53 # reappear. 54 qbpfs rm "/err/err_index.txt" 55 indexesToPull="00" 56 nextErrIndex="00" 57 ;; 58 *) 59 # If we support more than one dump, we can watch the index to change. 60 qbpfs pull "/err/err_index.txt" "${outDir}/err_index.txt" 2>&1 61 local lastErrIndex=`cat ${outDir}/err_index.txt` 62 rm "${outDir}/err_index.txt" 63 case $maxIndexes in 64 2) 65 indexesToPull="00 01" 66 case $lastErrIndex in 67 "") nextErrIndex="00";; 68 00) nextErrIndex="01";; 69 01) nextErrIndex="00";; 70 esac 71 ;; 72 3) 73 indexesToPull="00 01 02" 74 case $lastErrIndex in 75 "") nextErrIndex="00";; 76 00) nextErrIndex="01";; 77 01) nextErrIndex="02";; 78 02) nextErrIndex="00";; 79 esac 80 ;; 81 4) 82 indexesToPull="00 01 02 03" 83 case $lastErrIndex in 84 "") nextErrIndex="00";; 85 00) nextErrIndex="01";; 86 01) nextErrIndex="02";; 87 02) nextErrIndex="03";; 88 03) nextErrIndex="00";; 89 esac 90 ;; 91 *) 92 echo "No support for indexes=$maxIndexes" 93 return 94 ;; 95 esac 96 ;; 97 esac 98 99 # Trigger dump from RAM to EFS 100 echo dump_log > /sys/class/radio/mdm6600/command 101 102 local errIndex="" 103 # Loop until err_index.txt changes 104 for i in 1 2 3 4 5 ; do 105 qbpfs ls # This defeats a dir caching bug in the BP 106 qbpfs pull "/err/err_index.txt" "${outDir}/err_index.txt" 2>&1 107 errIndex=$(cat ${outDir}/err_index.txt) 108 rm "${outDir}/err_index.txt" 109 case $errIndex in 110 $nextErrIndex) 111 break 112 ;; 113 *) 114 case $i in 115 5) echo "Could not find BP log after $i attempts"; return;; 116 *) echo "No change to err_index.txt: $errIndex"; sleep 1;; 117 esac 118 ;; 119 esac 120 done 121 122 # Dump err_index.txt 123 echo "file:begin:txt:${outDirBranch}/err_index.txt" 124 echo "$errIndex" 125 echo "file:end:txt:${outDirBranch}/err_index.txt" 126 127 # Do NOT redirect stderr to stdout for bin files. It may confuse the base64 decoder. 128 for i in $indexesToPull ; do 129 dataIndexFile="err_data_index${i}_log00.txt" 130 qbpfs pull "/err/${dataIndexFile}" "${outDir}/${dataIndexFile}" 2>&1 131 case $? in 0) ;; *) echo "qbpfs pull failed for /err/${dataIndexFile}"; continue;; esac 132 echo "file:begin:txt:${outDirBranch}/${dataIndexFile}" 133 cat "${outDir}/${dataIndexFile}" 134 catRes=$? 135 echo "file:end:txt:${outDirBranch}/${dataIndexFile}" 136 rm "${outDir}/${dataIndexFile}" 137 case $catRes in 0) ;; *) echo "cat failed for /err/${dataIndexFile}"; continue;; esac 138 139 binFileExtensions="crs f3 id" 140 for ext in $binFileExtensions; do 141 binFile="err_f3_index${i}.${ext}" 142 qbpfs pull "/err/${binFile}" "${outDir}/${binFile}" 2>&1 143 case $? in 0) ;; *) echo "qbpfs pull failed for /err/${binFile}"; continue;; esac 144 base64 -e "${outDir}/${binFile}" "${outDir}/${binFile}-base64" 2>&1 145 case $? in 146 0) 147 ;; 148 *) 149 echo "base64 failed for ${outDir}/${binFile}" 150 rm "${outDir}/${binFile}" 151 continue 152 ;; 153 esac 154 echo "file:begin:bin:${outDirBranch}/${binFile}" 155 cat "${outDir}/${binFile}-base64" 156 catRes=$? 157 echo "file:end:bin:${outDirBranch}/${binFile}" 158 case $catRes in 0) ;; *) "cat failed for ${outDir}/${binFile}-base64";; esac 159 rm "${outDir}/${binFile}" "${outDir}/${binFile}-base64" 160 done 161 done 162 } 163 164 cleanupDirs() { 165 case $parentExists in 166 0) 167 # Cleanup output dirs 168 cd $outDir 169 case $? in 0) ;; *) echo "Couldn\'t cd to $outDir"; exit 1;; esac 170 for dir in $outDirBranchUnwind; do 171 cd .. 172 rmdir $dir 173 done 174 ;; 175 esac 176 } 177 178 ###### MAIN ROUTINE ###### 179 180 # Generate a timestamp if none passed in from parent script 181 case $1 in 182 "") timestamp=$(date +'%Y-%m-%d_%H-%M-%S'); parentExists=0;; 183 *) timestamp=$1; parentExists=1;; 184 esac 185 186 echo "Dumping QCOM BP logs @ $timestamp" 187 setupDirs $2 $3 188 processLogs 2 189 cleanupDirs