• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "dumpstate"
18 
19 #include "DumpstateDevice.h"
20 
21 #include <android-base/properties.h>
22 #include <android-base/unique_fd.h>
23 #include <cutils/properties.h>
24 #include <hidl/HidlBinderSupport.h>
25 #include <libgen.h>
26 
27 #include <log/log.h>
28 #include <stdlib.h>
29 #include <string>
30 
31 #include "DumpstateUtil.h"
32 
33 #define MODEM_LOG_PREFIX_PROPERTY "ro.radio.log_prefix"
34 #define MODEM_LOG_LOC_PROPERTY "ro.radio.log_loc"
35 #define MODEM_LOGGING_SWITCH "persist.radio.smlog_switch"
36 
37 using android::os::dumpstate::CommandOptions;
38 using android::os::dumpstate::DumpFileToFd;
39 using android::os::dumpstate::PropertiesHelper;
40 using android::os::dumpstate::RunCommandToFd;
41 
42 namespace android {
43 namespace hardware {
44 namespace dumpstate {
45 namespace V1_0 {
46 namespace implementation {
47 
dumpModem(int fd,int fdModem)48 void DumpstateDevice::dumpModem(int fd, int fdModem)
49 {
50     bool modemLogsEnabled = 0;
51     std::string modemLogDir = android::base::GetProperty(MODEM_LOG_LOC_PROPERTY, "");
52     if (modemLogDir.empty()) {
53         ALOGD("No modem log place is set\n");
54         return;
55     }
56     /* Check if smlog_dump tool exist */
57     if (!PropertiesHelper::IsUserBuild() && !access("/vendor/bin/smlog_dump", X_OK)) {
58         modemLogsEnabled = android::base::GetBoolProperty(MODEM_LOGGING_SWITCH, false);
59 
60         /* Execute SMLOG DUMP if SMLOG is enabled */
61         if (modemLogsEnabled) {
62             CommandOptions options = CommandOptions::WithTimeout(120).Build();
63             std::string modemLogAllDir = modemLogDir + "/modem_log";
64             std::vector<std::string> rilAndNetmgrLogs
65                 {
66                  "/data/misc/radio/ril_log",
67                  "/data/misc/radio/ril_log_old",
68                  "/data/misc/netmgr/netmgr_log",
69                  "/data/misc/netmgr/netmgr_log_old"
70                 };
71             std::string modemLogMkDirCmd= "/vendor/bin/mkdir " + modemLogAllDir;
72             RunCommandToFd(fd, "MKDIR MODEM LOG", { "/vendor/bin/sh", "-c", modemLogMkDirCmd.c_str()}, options);
73             RunCommandToFd(fd, "SMLOG DUMP", { "smlog_dump", "-d", "-o", modemLogAllDir.c_str() }, options);
74             for (std::string logFile : rilAndNetmgrLogs)
75             {
76               std::string copyCmd= "/vendor/bin/cp " + logFile + " " + modemLogAllDir;
77               RunCommandToFd(fd, "MV MODEM LOG", { "/vendor/bin/sh", "-c", copyCmd.c_str()}, options);
78             }
79             std::string filePrefix = android::base::GetProperty(MODEM_LOG_PREFIX_PROPERTY, "");
80             if (!filePrefix.empty()) {
81                 std::string modemLogCombined = modemLogDir + "/" + filePrefix + "all.tar";
82                 std::string modemLogTarCmd= "/vendor/bin/tar cvf " + modemLogCombined + " -C " + modemLogAllDir + " .";
83                 RunCommandToFd(fd, "TAR LOG", { "/vendor/bin/sh", "-c", modemLogTarCmd.c_str()}, options);
84                 std::string modemLogPermCmd= "/vendor/bin/chmod a+rw " + modemLogCombined;
85                 RunCommandToFd(fd, "CHG PERM", { "/vendor/bin/sh", "-c", modemLogPermCmd.c_str()}, options);
86 
87                 std::vector<uint8_t> buffer(65536);
88                 android::base::unique_fd fdLog(TEMP_FAILURE_RETRY(open(modemLogCombined.c_str(), O_RDONLY | O_CLOEXEC | O_NONBLOCK)));
89 
90                 if (fdLog >= 0) {
91                     while (1) {
92                         ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fdLog, buffer.data(), buffer.size()));
93 
94                         if (bytes_read == 0) {
95                             break;
96                         } else if (bytes_read < 0) {
97                             ALOGD("read(%s): %s\n", modemLogCombined.c_str(), strerror(errno));
98                             break;
99                         }
100 
101                         ssize_t result = TEMP_FAILURE_RETRY(write(fdModem, buffer.data(), bytes_read));
102 
103                         if (result != bytes_read) {
104                             ALOGD("Failed to write %ld bytes, actually written: %ld", bytes_read, result);
105                             break;
106                         }
107                     }
108                 }
109 
110                 std::string modemLogClearCmd= "/vendor/bin/rm -r " + modemLogAllDir;
111                 RunCommandToFd(fd, "RM MODEM DIR", { "/vendor/bin/sh", "-c", modemLogClearCmd.c_str()}, options);
112                 RunCommandToFd(fd, "RM LOG", { "/vendor/bin/rm", modemLogCombined.c_str()}, options);
113             }
114         }
115     }
116 }
117 
118 // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow.
dumpstateBoard(const hidl_handle & handle)119 Return<void> DumpstateDevice::dumpstateBoard(const hidl_handle& handle) {
120     // Exit when dump is completed since this is a lazy HAL.
121     addPostCommandTask([]() {
122         exit(0);
123     });
124 
125     if (handle == nullptr || handle->numFds < 1) {
126         ALOGE("no FDs\n");
127         return Void();
128     }
129 
130     int fd = handle->data[0];
131     if (fd < 0) {
132         ALOGE("invalid FD: %d\n", handle->data[0]);
133         return Void();
134     }
135 
136     if (handle->numFds < 2) {
137         ALOGE("no FD for modem\n");
138     }
139     else {
140         int fdModem = handle->data[1];
141         dumpModem(fd, fdModem);
142     }
143 
144     RunCommandToFd(fd, "VENDOR PROPERTIES", {"/vendor/bin/getprop"});
145     DumpFileToFd(fd, "CPU present", "/sys/devices/system/cpu/present");
146     DumpFileToFd(fd, "CPU online", "/sys/devices/system/cpu/online");
147     DumpFileToFd(fd, "INTERRUPTS", "/proc/interrupts");
148 
149     DumpFileToFd(fd, "UFS model", "/sys/block/sda/device/model");
150     DumpFileToFd(fd, "UFS rev", "/sys/block/sda/device/rev");
151     DumpFileToFd(fd, "UFS size", "/sys/block/sda/size");
152     DumpFileToFd(fd, "UFS health", "/sys/devices/soc/624000.ufshc/health");
153     RunCommandToFd(fd, "UFS dump", {"/vendor/bin/sh", "-c", "for f in $(find /sys/kernel/debug/ufshcd0 -type f); do if [[ -r $f && -f $f ]]; then echo --- $f; cat $f; fi; done"});
154 
155     DumpFileToFd(fd, "RPM Stats", "/d/rpm_stats");
156     DumpFileToFd(fd, "Power Management Stats", "/d/rpm_master_stats");
157     DumpFileToFd(fd, "WLAN Power Stats", "/d/wlan_wcnss/power_stats");
158     DumpFileToFd(fd, "Runtime-PM Stats", "/d/cnss_runtime_pm");
159     DumpFileToFd(fd, "CNSS Pre-Alloc", "/d/cnss-prealloc/status");
160 
161     DumpFileToFd(fd, "SMD Log", "/d/ipc_logging/smd/log");
162     RunCommandToFd(fd, "ION HEAPS", {"/vendor/bin/sh", "-c", "for d in $(ls -d /d/ion/*); do for f in $(ls $d); do echo --- $d/$f; cat $d/$f; done; done"});
163     DumpFileToFd(fd, "dmabuf info", "/d/dma_buf/bufinfo");
164     DumpFileToFd(fd, "MDP xlogs", "/d/mdp/xlog/dump");
165     DumpFileToFd(fd, "TCPM logs", "/d/tcpm/9-0022");
166     RunCommandToFd(fd, "Temperatures", {"/vendor/bin/sh", "-c", "for f in /sys/class/thermal/thermal* ; do type=`cat $f/type` ; temp=`cat $f/temp` ; echo \"$type: $temp\" ; done"});
167     RunCommandToFd(fd, "CPU time-in-state", {"/vendor/bin/sh", "-c", "for cpu in /sys/devices/system/cpu/cpu*; do f=$cpu/cpufreq/stats/time_in_state; if [ ! -f $f ]; then continue; fi; echo $f:; cat $f; done"});
168     RunCommandToFd(fd, "CPU cpuidle", {"/vendor/bin/sh", "-c", "for cpu in /sys/devices/system/cpu/cpu*; do for d in $cpu/cpuidle/state*; do if [ ! -d $d ]; then continue; fi; echo \"$d: `cat $d/name` `cat $d/desc` `cat $d/time` `cat $d/usage`\"; done; done"});
169     DumpFileToFd(fd, "FUSB302 logs", "/d/ipc_logging/fusb302/log");
170 
171     RunCommandToFd(fd, "Power supply properties", {"/vendor/bin/sh", "-c", "for f in /sys/class/power_supply/*/uevent ; do echo \"\n------ $f\" ; cat $f ; done"});
172     DumpFileToFd(fd, "Battery cycle count", "/sys/class/power_supply/bms/device/cycle_counts_bins");
173     RunCommandToFd(fd, "QCOM FG SRAM", {"/vendor/bin/sh", "-c", "echo 0x400 > /d/fg_memif/address ; echo 0x200 > /d/fg_memif/count ; cat /d/fg_memif/data"});
174 
175     /* Check if qsee_logger tool exists */
176     if (!access("/vendor/bin/qsee_logger", X_OK)) {
177       RunCommandToFd(fd, "FP LOGS", {"qsee_logger", "-d"});
178     }
179 
180     DumpFileToFd(fd, "WLAN FW Log Symbol Table", "/vendor/firmware/Data.msc");
181 
182     return Void();
183 };
184 
185 }  // namespace implementation
186 }  // namespace V1_0
187 }  // namespace dumpstate
188 }  // namespace hardware
189 }  // namespace android
190