• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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/file.h>
22 #include <android-base/properties.h>
23 #include <android-base/unique_fd.h>
24 #include <cutils/properties.h>
25 #include <hidl/HidlBinderSupport.h>
26 #include <hidl/HidlSupport.h>
27 
28 #include <log/log.h>
29 #include <pthread.h>
30 #include <string.h>
31 
32 #define _SVID_SOURCE
33 #include <dirent.h>
34 
35 #include "DumpstateUtil.h"
36 
37 #define MODEM_LOG_PREFIX_PROPERTY "ro.vendor.radio.log_prefix"
38 #define MODEM_LOG_LOC_PROPERTY "ro.vendor.radio.log_loc"
39 #define MODEM_LOGGING_SWITCH "persist.vendor.radio.smlog_switch"
40 
41 #define DIAG_MDLOG_PERSIST_PROPERTY "persist.vendor.sys.modem.diag.mdlog"
42 #define DIAG_MDLOG_PROPERTY "vendor.sys.modem.diag.mdlog"
43 #define DIAG_MDLOG_STATUS_PROPERTY "vendor.sys.modem.diag.mdlog_on"
44 
45 #define DIAG_MDLOG_NUMBER_BUGREPORT "persist.vendor.sys.modem.diag.mdlog_br_num"
46 
47 #define UFS_BOOTDEVICE "ro.boot.bootdevice"
48 
49 #define TCPDUMP_NUMBER_BUGREPORT "persist.vendor.tcpdump.log.br_num"
50 #define TCPDUMP_PERSIST_PROPERTY "persist.vendor.tcpdump.log.alwayson"
51 
52 #define MODEM_EFS_DUMP_PROPERTY "vendor.sys.modem.diag.efsdump"
53 
54 #define VENDOR_VERBOSE_LOGGING_ENABLED_PROPERTY "persist.vendor.verbose_logging_enabled"
55 
56 using android::os::dumpstate::CommandOptions;
57 using android::os::dumpstate::DumpFileToFd;
58 using android::os::dumpstate::PropertiesHelper;
59 using android::os::dumpstate::RunCommandToFd;
60 
61 namespace android {
62 namespace hardware {
63 namespace dumpstate {
64 namespace V1_1 {
65 namespace implementation {
66 
67 #define DIAG_LOG_PREFIX "diag_log_"
68 #define TCPDUMP_LOG_PREFIX "tcpdump"
69 #define EXTENDED_LOG_PREFIX "extended_log_"
70 
dumpLogs(int fd,std::string srcDir,std::string destDir,int maxFileNum,const char * logPrefix)71 static void dumpLogs(int fd, std::string srcDir, std::string destDir,
72                      int maxFileNum, const char *logPrefix) {
73     struct dirent **dirent_list = NULL;
74     int num_entries = scandir(srcDir.c_str(),
75                               &dirent_list,
76                               0,
77                               (int (*)(const struct dirent **, const struct dirent **)) alphasort);
78     if (!dirent_list) {
79         return;
80     } else if (num_entries <= 0) {
81         return;
82     }
83 
84     int copiedFiles = 0;
85 
86     for (int i = num_entries - 1; i >= 0; i--) {
87         ALOGD("Found %s\n", dirent_list[i]->d_name);
88 
89         if (0 != strncmp(dirent_list[i]->d_name, logPrefix, strlen(logPrefix))) {
90             continue;
91         }
92 
93         if ((copiedFiles >= maxFileNum) && (maxFileNum != -1)) {
94             ALOGD("Skipped %s\n", dirent_list[i]->d_name);
95             continue;
96         }
97 
98         copiedFiles++;
99 
100         CommandOptions options = CommandOptions::WithTimeout(120).Build();
101         std::string srcLogFile = srcDir + "/" + dirent_list[i]->d_name;
102         std::string destLogFile = destDir + "/" + dirent_list[i]->d_name;
103 
104         std::string copyCmd = "/vendor/bin/cp " + srcLogFile + " " + destLogFile;
105 
106         ALOGD("Copying %s to %s\n", srcLogFile.c_str(), destLogFile.c_str());
107         RunCommandToFd(fd, "CP DIAG LOGS", { "/vendor/bin/sh", "-c", copyCmd.c_str() }, options);
108     }
109 
110     while (num_entries--) {
111         free(dirent_list[num_entries]);
112     }
113 
114     free(dirent_list);
115 }
116 
dumpModemThread(void * data)117 static void *dumpModemThread(void *data)
118 {
119     long fdModem = (long)data;
120 
121     ALOGD("dumpModemThread started\n");
122 
123     std::string modemLogDir = android::base::GetProperty(MODEM_LOG_LOC_PROPERTY, "");
124     if (modemLogDir.empty()) {
125         ALOGD("No modem log place is set");
126         return NULL;
127     }
128 
129     std::string filePrefix = android::base::GetProperty(MODEM_LOG_PREFIX_PROPERTY, "");
130 
131     if (filePrefix.empty()) {
132         ALOGD("Modem log prefix is not set");
133         return NULL;
134     }
135 
136     sleep(1);
137     ALOGD("Waited modem for 1 second to flush logs");
138 
139     const std::string modemLogCombined = modemLogDir + "/" + filePrefix + "all.tar";
140     const std::string modemLogAllDir = modemLogDir + "/modem_log";
141 
142     RunCommandToFd(STDOUT_FILENO, "MKDIR MODEM LOG", {"/vendor/bin/mkdir", "-p", modemLogAllDir.c_str()}, CommandOptions::WithTimeout(2).Build());
143 
144     const std::string diagLogDir = "/data/vendor/radio/diag_logs/logs";
145     const std::string diagPoweronLogPath = "/data/vendor/radio/diag_logs/logs/diag_poweron_log.qmdl";
146 
147     bool diagLogEnabled = android::base::GetBoolProperty(DIAG_MDLOG_PERSIST_PROPERTY, false);
148 
149     if (diagLogEnabled) {
150         bool diagLogStarted = android::base::GetBoolProperty( DIAG_MDLOG_STATUS_PROPERTY, false);
151 
152         if (diagLogStarted) {
153             android::base::SetProperty(DIAG_MDLOG_PROPERTY, "false");
154             ALOGD("Stopping diag_mdlog...\n");
155             if (android::base::WaitForProperty(DIAG_MDLOG_STATUS_PROPERTY, "false", std::chrono::seconds(10))) {
156                 ALOGD("diag_mdlog exited");
157             } else {
158                 ALOGE("Waited mdlog timeout after 10 second");
159             }
160         } else {
161             ALOGD("diag_mdlog is not running");
162         }
163 
164         dumpLogs(STDOUT_FILENO, diagLogDir, modemLogAllDir, android::base::GetIntProperty(DIAG_MDLOG_NUMBER_BUGREPORT, 100), DIAG_LOG_PREFIX);
165 
166         if (diagLogStarted) {
167             ALOGD("Restarting diag_mdlog...");
168             android::base::SetProperty(DIAG_MDLOG_PROPERTY, "true");
169         }
170     }
171     RunCommandToFd(STDOUT_FILENO, "CP MODEM POWERON LOG", {"/vendor/bin/cp", diagPoweronLogPath.c_str(), modemLogAllDir.c_str()}, CommandOptions::WithTimeout(2).Build());
172 
173     if (!PropertiesHelper::IsUserBuild()) {
174         char cmd[256] = { 0 };
175 
176         android::base::SetProperty(MODEM_EFS_DUMP_PROPERTY, "true");
177 
178         const std::string tcpdumpLogDir = "/data/vendor/tcpdump_logger/logs";
179         const std::string extendedLogDir = "/data/vendor/radio/extended_logs";
180         const std::vector <std::string> rilAndNetmgrLogs
181             {
182                 "/data/vendor/radio/haldebug_ril0",
183                 "/data/vendor/radio/haldebug_ril1",
184                 "/data/vendor/radio/ril_log0",
185                 "/data/vendor/radio/ril_log0_old",
186                 "/data/vendor/radio/ril_log1",
187                 "/data/vendor/radio/ril_log1_old",
188                 "/data/vendor/radio/qmi_fw_log",
189                 "/data/vendor/radio/qmi_fw_log_old",
190                 "/data/vendor/radio/imsdatadaemon_log",
191                 "/data/vendor/radio/imsdatadaemon_log_old",
192                 "/data/vendor/netmgr/netmgr_log",
193                 "/data/vendor/netmgr/netmgr_log_old",
194                 "/data/vendor/radio/omadm_logs.txt",
195                 "/data/vendor/radio/power_anomaly_data.txt",
196                 "/data/vendor/radio/diag_logs/diag_trace.txt",
197                 "/data/vendor/radio/diag_logs/diag_trace_old.txt",
198                 "/data/vendor/radio/metrics_data",
199                 "/data/vendor/ssrlog/ssr_log.txt",
200                 "/data/vendor/ssrlog/ssr_log_old.txt",
201                 "/data/vendor/rfs/mpss/modem_efs",
202                 "/sys/kernel/debug/ipa/ipa_statistics_msg"
203             };
204 
205        bool tcpdumpEnabled = android::base::GetBoolProperty(TCPDUMP_PERSIST_PROPERTY, false);
206        if (tcpdumpEnabled) {
207             dumpLogs(STDOUT_FILENO, tcpdumpLogDir, modemLogAllDir, android::base::GetIntProperty(TCPDUMP_NUMBER_BUGREPORT, 5), TCPDUMP_LOG_PREFIX);
208         }
209 
210         for (const auto& logFile : rilAndNetmgrLogs) {
211             RunCommandToFd(STDOUT_FILENO, "CP MODEM LOG", {"/vendor/bin/cp", logFile.c_str(), modemLogAllDir.c_str()}, CommandOptions::WithTimeout(2).Build());
212         }
213 
214         //Dump IPA log
215         snprintf(cmd, sizeof(cmd),
216                 "cat /d/ipc_logging/ipa/log > %s/ipa_log",
217                 modemLogAllDir.c_str());
218         RunCommandToFd(STDOUT_FILENO, "Dump IPA log", {"/vendor/bin/sh", "-c", cmd});
219 
220         dumpLogs(STDOUT_FILENO, extendedLogDir, modemLogAllDir, 100, EXTENDED_LOG_PREFIX);
221         android::base::SetProperty(MODEM_EFS_DUMP_PROPERTY, "false");
222     }
223 
224     RunCommandToFd(STDOUT_FILENO, "TAR LOG", {"/vendor/bin/tar", "cvf", modemLogCombined.c_str(), "-C", modemLogAllDir.c_str(), "."}, CommandOptions::WithTimeout(20).Build());
225     RunCommandToFd(STDOUT_FILENO, "CHG PERM", {"/vendor/bin/chmod", "a+w", modemLogCombined.c_str()}, CommandOptions::WithTimeout(2).Build());
226 
227     std::vector<uint8_t> buffer(65536);
228     android::base::unique_fd fdLog(TEMP_FAILURE_RETRY(open(modemLogCombined.c_str(), O_RDONLY | O_CLOEXEC | O_NONBLOCK)));
229 
230     if (fdLog >= 0) {
231         while (1) {
232             ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fdLog, buffer.data(), buffer.size()));
233 
234             if (bytes_read == 0) {
235                 break;
236             } else if (bytes_read < 0) {
237                 ALOGD("read(%s): %s\n", modemLogCombined.c_str(), strerror(errno));
238                 break;
239             }
240 
241             ssize_t result = TEMP_FAILURE_RETRY(write(fdModem, buffer.data(), bytes_read));
242 
243             if (result != bytes_read) {
244                 ALOGD("Failed to write %ld bytes, actually written: %ld", bytes_read, result);
245                 break;
246             }
247         }
248     }
249 
250     RunCommandToFd(STDOUT_FILENO, "RM MODEM DIR", { "/vendor/bin/rm", "-r", modemLogAllDir.c_str()}, CommandOptions::WithTimeout(2).Build());
251     RunCommandToFd(STDOUT_FILENO, "RM LOG", { "/vendor/bin/rm", modemLogCombined.c_str()}, CommandOptions::WithTimeout(2).Build());
252 
253     ALOGD("dumpModemThread finished\n");
254 
255     return NULL;
256 }
257 
DumpTouch(int fd)258 static void DumpTouch(int fd) {
259     const char touch_spi_path[] = "/sys/bus/i2c/drivers/fts/1-0049";
260     char cmd[256];
261 
262     RunCommandToFd(fd, "Force Set AP as Bus Owner",
263                    {"/vendor/bin/sh", "-c",
264                     "echo A0 01 > /proc/fts/driver_test && "
265                     "cat /proc/fts/driver_test"});
266 
267     snprintf(cmd, sizeof(cmd), "%s/appid", touch_spi_path);
268     if (!access(cmd, R_OK)) {
269         // Touch firmware version
270         DumpFileToFd(fd, "STM touch firmware version", cmd);
271 
272         // Touch controller status
273         snprintf(cmd, sizeof(cmd), "%s/status", touch_spi_path);
274         DumpFileToFd(fd, "STM touch status", cmd);
275 
276         // Mutual raw data
277         snprintf(cmd, sizeof(cmd),
278                  "echo 13 00 01 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
279                  touch_spi_path, touch_spi_path);
280         RunCommandToFd(fd, "Mutual Raw", {"/vendor/bin/sh", "-c", cmd});
281 
282         // Mutual strength data
283         snprintf(cmd, sizeof(cmd),
284                  "echo 17 01 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
285                  touch_spi_path, touch_spi_path);
286         RunCommandToFd(fd, "Mutual Strength", {"/vendor/bin/sh", "-c", cmd});
287 
288         // Self raw data
289         snprintf(cmd, sizeof(cmd),
290                  "echo 15 00 01> %s/stm_fts_cmd && cat %s/stm_fts_cmd",
291                  touch_spi_path, touch_spi_path);
292         RunCommandToFd(fd, "Self Raw", {"/vendor/bin/sh", "-c", cmd});
293     }
294 
295     if (!access("/proc/fts/driver_test", R_OK)) {
296         RunCommandToFd(fd, "Lock Normal Active Mode",
297                        {"/vendor/bin/sh", "-c",
298                         "echo 16 A0 03 00 > /proc/fts/driver_test && "
299                         "cat /proc/fts/driver_test"});
300 	RunCommandToFd(fd, "Mutual Raw Data",
301                        {"/vendor/bin/sh", "-c",
302                         "echo 23 00 > /proc/fts/driver_test && "
303                         "cat /proc/fts/driver_test"});
304         RunCommandToFd(fd, "Mutual Baseline Data",
305                        {"/vendor/bin/sh", "-c",
306                         "echo 23 03 > /proc/fts/driver_test && "
307                         "cat /proc/fts/driver_test"});
308         RunCommandToFd(fd, "Mutual Strength Data",
309                        {"/vendor/bin/sh", "-c",
310                         "echo 23 02 > /proc/fts/driver_test && "
311                         "cat /proc/fts/driver_test"});
312         RunCommandToFd(fd, "Self Raw Data",
313                        {"/vendor/bin/sh", "-c",
314                         "echo 24 00 > /proc/fts/driver_test && "
315                         "cat /proc/fts/driver_test"});
316         RunCommandToFd(fd, "Self Baseline Data",
317                        {"/vendor/bin/sh", "-c",
318                         "echo 24 03 > /proc/fts/driver_test && "
319                         "cat /proc/fts/driver_test"});
320         RunCommandToFd(fd, "Self Strength Data",
321                        {"/vendor/bin/sh", "-c",
322                         "echo 24 02 > /proc/fts/driver_test && "
323                         "cat /proc/fts/driver_test"});
324         RunCommandToFd(fd, "Mutual Compensation",
325                        {"/vendor/bin/sh", "-c",
326                         "echo 32 10 > /proc/fts/driver_test && "
327                         "cat /proc/fts/driver_test"});
328         RunCommandToFd(fd, "Self Compensation",
329                        {"/vendor/bin/sh", "-c",
330                         "echo 33 12 > /proc/fts/driver_test && "
331                         "cat /proc/fts/driver_test"});
332 	RunCommandToFd(fd, "Golden MS Raw",
333                        {"/vendor/bin/sh", "-c",
334                         "echo 34 > /proc/fts/driver_test && "
335                         "cat /proc/fts/driver_test"});
336         RunCommandToFd(fd, "Packaging Plant - HW reset",
337                        {"/vendor/bin/sh", "-c",
338                         "echo 01 FA 20 00 00 24 80 > /proc/fts/driver_test"});
339 	RunCommandToFd(fd, "Packaging Plant - Hibernate Memory",
340                        {"/vendor/bin/sh", "-c",
341                         "echo 01 FA 20 00 00 68 08 > /proc/fts/driver_test"});
342 	RunCommandToFd(fd, "Packaging Plant - Read 10 bytes from Address 0x00043F28",
343                        {"/vendor/bin/sh", "-c",
344                         "echo 02 FA 00 04 3F 28 00 0A 00 > /proc/fts/driver_test && "
345                         "cat /proc/fts/driver_test"});
346     }
347 
348     snprintf(cmd, sizeof(cmd), "%s/stm_fts_cmd", touch_spi_path);
349     if (!access(cmd, R_OK)) {
350         // ITO raw data
351         snprintf(cmd, sizeof(cmd),
352                  "echo 01 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
353                  touch_spi_path, touch_spi_path);
354         RunCommandToFd(fd, "ITO Raw", {"/vendor/bin/sh", "-c", cmd});
355     }
356     RunCommandToFd(fd, "Restore Bus Owner",
357                    {"/vendor/bin/sh", "-c",
358                     "echo A0 00 > /proc/fts/driver_test && "
359                     "cat /proc/fts/driver_test"});
360 }
361 
DumpDisplay(int fd)362 static void DumpDisplay(int fd) {
363     DumpFileToFd(fd, "PANEL VENDOR NAME", "/sys/class/panel_info/panel0/panel_vendor_name");
364     DumpFileToFd(fd, "PANEL SN", "/sys/class/panel_info/panel0/serial_number");
365     DumpFileToFd(fd, "PANEL EXTRA INFO", "/sys/class/panel_info/panel0/panel_extinfo");
366 
367     const std::string pmic_regmap_path = "/sys/kernel/debug/regmap/spmi0-05";
368     using android::base::WriteStringToFile;
369 
370     if (WriteStringToFile("0x80", pmic_regmap_path + "/count", true) &&
371             WriteStringToFile("0xE000", pmic_regmap_path + "/address", true)) {
372         DumpFileToFd(fd, "OLEDB Register Dump", pmic_regmap_path + "/data");
373     } else {
374         dprintf(fd, "Unable to print OLEDB Register Dump\n");
375     }
376 
377     if (WriteStringToFile("0x80", pmic_regmap_path + "/count", true) &&
378             WriteStringToFile("0xDE00", pmic_regmap_path + "/address", true)) {
379         DumpFileToFd(fd, "ELVDD Register Dump", pmic_regmap_path + "/data");
380     } else {
381        dprintf(fd, "Unable to print ELVDD Register Dump\n");
382     }
383 
384     if (WriteStringToFile("0x60", pmic_regmap_path + "/count", true) &&
385             WriteStringToFile("0xDC00", pmic_regmap_path + "/address", true)) {
386         DumpFileToFd(fd, "ELVSS Register Dump", pmic_regmap_path + "/data");
387     } else {
388         dprintf(fd, "Unable to print ELVSS Register Dump\n");
389     }
390 }
391 
DumpSensorLog(int fd)392 static void DumpSensorLog(int fd) {
393     const std::string logPath = "/data/vendor/sensors/log/sensor_log.txt";
394     const std::string lastlogPath = "/data/vendor/sensors/log/sensor_lastlog.txt";
395 
396     if (!access(logPath.c_str(), R_OK)) {
397         DumpFileToFd(fd, "sensor log", logPath);
398     }
399     if (!access(lastlogPath.c_str(), R_OK)) {
400         DumpFileToFd(fd, "sensor lastlog", lastlogPath);
401     }
402 }
403 
DumpF2FS(int fd)404 static void DumpF2FS(int fd) {
405     DumpFileToFd(fd, "F2FS", "/sys/kernel/debug/f2fs/status");
406     RunCommandToFd(fd, "F2FS - fragmentation", {"/vendor/bin/sh", "-c",
407                        "for d in $(ls /proc/fs/f2fs/); do "
408                        "echo $d: /dev/block/mapper/`ls -l /dev/block/mapper | grep $d | awk '{print $8,$9,$10}'`; "
409                        "cat /proc/fs/f2fs/$d/segment_info; done"});
410     RunCommandToFd(fd, "F2FS - fsck time (ms)", {"/vendor/bin/sh", "-c", "getprop ro.boottime.init.fsck.data"});
411     RunCommandToFd(fd, "F2FS - checkpoint=disable time (ms)", {"/vendor/bin/sh", "-c", "getprop ro.boottime.init.mount.data"});
412 }
413 
DumpUFS(int fd)414 static void DumpUFS(int fd) {
415     DumpFileToFd(fd, "UFS model", "/sys/block/sda/device/model");
416     DumpFileToFd(fd, "UFS rev", "/sys/block/sda/device/rev");
417     DumpFileToFd(fd, "UFS size", "/sys/block/sda/size");
418     DumpFileToFd(fd, "UFS show_hba", "/sys/kernel/debug/ufshcd0/show_hba");
419 
420     std::string bootdev = android::base::GetProperty(UFS_BOOTDEVICE, "");
421     if (!bootdev.empty()) {
422         DumpFileToFd(fd, "UFS Slow IO Read", "/sys/devices/platform/soc/" + bootdev + "/slowio_read_cnt");
423         DumpFileToFd(fd, "UFS Slow IO Write", "/sys/devices/platform/soc/" + bootdev + "/slowio_write_cnt");
424         DumpFileToFd(fd, "UFS Slow IO Unmap", "/sys/devices/platform/soc/" + bootdev + "/slowio_unmap_cnt");
425         DumpFileToFd(fd, "UFS Slow IO Sync", "/sys/devices/platform/soc/" + bootdev + "/slowio_sync_cnt");
426 
427         std::string ufs_health = "for f in $(find /sys/devices/platform/soc/" + bootdev + "/health -type f); do if [[ -r $f && -f $f ]]; then echo --- $f; cat $f; echo ''; fi; done";
428         RunCommandToFd(fd, "UFS health", {"/vendor/bin/sh", "-c", ufs_health.c_str()});
429         RunCommandToFd(fd, "UFS err_stats", {"/vendor/bin/sh", "-c",
430                            "path=\"/sys/devices/platform/soc/" + bootdev + "/err_stats\"; "
431                            "for node in `ls $path/err_*`; do "
432                            "printf \"%s:%d\\n\" $(basename $node) $(cat $node); done;"});
433         RunCommandToFd(fd, "UFS io_stats", {"/vendor/bin/sh", "-c",
434                            "path=\"/sys/devices/platform/soc/" + bootdev + "/io_stats\"; "
435                            "printf \"\\t\\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
436                            "ReadCnt ReadBytes WriteCnt WriteBytes RWCnt RWBytes; "
437                            "str=$(cat $path/*_start); arr=($str); "
438                            "printf \"Started: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
439                            "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "
440                            "str=$(cat $path/*_complete); arr=($str); "
441                            "printf \"Completed: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
442                            "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "
443                            "str=$(cat $path/*_maxdiff); arr=($str); "
444                            "printf \"MaxDiff: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\\n\" "
445                            "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "});
446 
447         RunCommandToFd(fd, "UFS req_stats", {"/vendor/bin/sh", "-c",
448                            "path=\"/sys/devices/platform/soc/" + bootdev + "/req_stats\"; "
449                            "printf \"\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
450                            "All Write Read Read\\(urg\\) Write\\(urg\\) Flush Discard; "
451                            "str=$(cat $path/*_min); arr=($str); "
452                            "printf \"Min:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
453                            "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]}; "
454                            "str=$(cat $path/*_max); arr=($str); "
455                            "printf \"Max:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
456                            "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]}; "
457                            "str=$(cat $path/*_avg); arr=($str); "
458                            "printf \"Avg.:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
459                            "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]}; "
460                            "str=$(cat $path/*_sum); arr=($str); "
461                            "printf \"Count:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\\n\" "
462                            "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]};"});
463 
464     }
465 }
466 
DumpPower(int fd)467 static void DumpPower(int fd) {
468     RunCommandToFd(fd, "Power Stats Times", {"/vendor/bin/sh", "-c",
469                    "echo -n \"Boot: \" && /vendor/bin/uptime -s && "
470                    "echo -n \"Now: \" && date"});
471     DumpFileToFd(fd, "Sleep Stats", "/sys/power/system_sleep/stats");
472     DumpFileToFd(fd, "Power Management Stats", "/sys/power/rpmh_stats/master_stats");
473     DumpFileToFd(fd, "WLAN Power Stats", "/sys/kernel/wlan/power_stats");
474 }
475 
476 // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow.
dumpstateBoard(const hidl_handle & handle)477 Return<void> DumpstateDevice::dumpstateBoard(const hidl_handle& handle) {
478     // Ignore return value, just return an empty status.
479     dumpstateBoard_1_1(handle, DumpstateMode::DEFAULT, 30 * 1000 /* timeoutMillis */);
480     return Void();
481 }
482 
483 // Methods from ::android::hardware::dumpstate::V1_1::IDumpstateDevice follow.
dumpstateBoard_1_1(const hidl_handle & handle,const DumpstateMode mode,const uint64_t timeoutMillis)484 Return<DumpstateStatus> DumpstateDevice::dumpstateBoard_1_1(const hidl_handle& handle,
485                                                             const DumpstateMode mode,
486                                                             const uint64_t timeoutMillis) {
487     // Unused arguments.
488     (void) timeoutMillis;
489 
490     // Exit when dump is completed since this is a lazy HAL.
491     addPostCommandTask([]() {
492         exit(0);
493     });
494 
495     if (handle == nullptr || handle->numFds < 1) {
496         ALOGE("no FDs\n");
497         return DumpstateStatus::ILLEGAL_ARGUMENT;
498     }
499 
500     int fd = handle->data[0];
501     if (fd < 0) {
502         ALOGE("invalid FD: %d\n", handle->data[0]);
503         return DumpstateStatus::ILLEGAL_ARGUMENT;
504     }
505 
506     bool isModeValid = false;
507     for (const auto dumpstateMode : hidl_enum_range<DumpstateMode>()) {
508         if (mode == dumpstateMode) {
509             isModeValid = true;
510             break;
511         }
512     }
513     if (!isModeValid) {
514         ALOGE("Invalid mode: %d\n", mode);
515         return DumpstateStatus::ILLEGAL_ARGUMENT;
516     } else if (mode == DumpstateMode::WEAR) {
517         // We aren't a Wear device.
518         ALOGE("Unsupported mode: %d\n", mode);
519         return DumpstateStatus::UNSUPPORTED_MODE;
520     }
521 
522     RunCommandToFd(fd, "Notify modem", {"/vendor/bin/modem_svc", "-s"}, CommandOptions::WithTimeout(1).Build());
523 
524     pthread_t modemThreadHandle = 0;
525     if (getVerboseLoggingEnabled()) {
526         ALOGD("Verbose logging is enabled.\n");
527         if (handle->numFds < 2) {
528             ALOGE("no FD for modem\n");
529         } else {
530             int fdModem = handle->data[1];
531             if (pthread_create(&modemThreadHandle, NULL, dumpModemThread, (void *)((long)fdModem)) != 0) {
532                 ALOGE("could not create thread for dumpModem\n");
533             }
534         }
535     }
536 
537     RunCommandToFd(fd, "VENDOR PROPERTIES", {"/vendor/bin/getprop"});
538     DumpFileToFd(fd, "SoC serial number", "/sys/devices/soc0/serial_number");
539     DumpFileToFd(fd, "CPU present", "/sys/devices/system/cpu/present");
540     DumpFileToFd(fd, "CPU online", "/sys/devices/system/cpu/online");
541     DumpFileToFd(fd, "Bootloader Log", "/proc/bldrlog");
542     DumpTouch(fd);
543     DumpDisplay(fd);
544 
545     DumpF2FS(fd);
546     DumpUFS(fd);
547 
548     DumpSensorLog(fd);
549 
550     DumpFileToFd(fd, "INTERRUPTS", "/proc/interrupts");
551 
552     DumpPower(fd);
553 
554     DumpFileToFd(fd, "LL-Stats", "/d/wlan0/ll_stats");
555     DumpFileToFd(fd, "WLAN Connect Info", "/d/wlan0/connect_info");
556     DumpFileToFd(fd, "WLAN Offload Info", "/d/wlan0/offload_info");
557     DumpFileToFd(fd, "WLAN Roaming Stats", "/d/wlan0/roam_stats");
558     DumpFileToFd(fd, "ICNSS Stats", "/d/icnss/stats");
559     DumpFileToFd(fd, "SMD Log", "/d/ipc_logging/smd/log");
560     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"});
561     DumpFileToFd(fd, "dmabuf info", "/d/dma_buf/bufinfo");
562     DumpFileToFd(fd, "dmabuf process info", "/d/dma_buf/dmaprocs");
563     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"});
564     RunCommandToFd(fd, "Cooling Device Current State", {"/vendor/bin/sh", "-c", "for f in /sys/class/thermal/cooling* ; do type=`cat $f/type` ; temp=`cat $f/cur_state` ; echo \"$type: $temp\" ; done"});
565     RunCommandToFd(
566         fd, "LMH info",
567         {"/vendor/bin/sh", "-c",
568          "for f in /sys/bus/platform/drivers/msm_lmh_dcvs/*qcom,limits-dcvs@*/lmh_freq_limit; do "
569          "state=`cat $f` ; echo \"$f: $state\" ; done"});
570     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"});
571     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"});
572     RunCommandToFd(fd, "Airbrush debug info", {"/vendor/bin/sh", "-c", "for f in `ls /sys/devices/platform/soc/c84000.i2c/i2c-4/4-0066/@(*curr|temperature|vbat|total_power)`; do echo \"$f: `cat $f`\" ; done; file=/d/airbrush/airbrush_sm/chip_state; echo \"$file: `cat $file`\""});
573     DumpFileToFd(fd, "TCPM logs", "/d/tcpm/usbpd0");
574     DumpFileToFd(fd, "PD Engine", "/d/logbuffer/usbpd");
575     DumpFileToFd(fd, "ipc-local-ports", "/d/msm_ipc_router/dump_local_ports");
576     RunCommandToFd(fd, "TRICKLE-DEFEND Config", {"/vendor/bin/sh", "-c", " cd /sys/devices/platform/soc/soc:google,battery/power_supply/battery/; echo \"bd_trickle_enable: `cat bd_trickle_enable`\"; echo \"bd_trickle_cnt: `cat bd_trickle_cnt`\";  echo \"bd_trickle_recharge_soc: `cat bd_trickle_recharge_soc`\";  echo \"bd_trickle_dry_run: `cat bd_trickle_dry_run`\";  echo \"bd_trickle_reset_sec: `cat bd_trickle_reset_sec`\""});
577     RunCommandToFd(fd, "DWELL-DEFEND Config", {"/vendor/bin/sh", "-c", " cd /sys/devices/platform/soc/soc:google,charger/; for f in `ls charge_s*` ; do echo \"$f: `cat $f`\" ; done"});
578     RunCommandToFd(fd, "TEMP-DEFEND Config", {"/vendor/bin/sh", "-c", " cd /sys/devices/platform/soc/soc:google,charger/; for f in `ls bd_*` ; do echo \"$f: `cat $f`\" ; done"});
579     RunCommandToFd(fd, "USB Device Descriptors", {"/vendor/bin/sh", "-c", "cd /sys/bus/usb/devices/1-1 && cat product && cat bcdDevice; cat descriptors | od -t x1 -w16 -N96"});
580     RunCommandToFd(fd, "Power supply properties", {"/vendor/bin/sh", "-c", "for f in `ls /sys/class/power_supply/*/uevent` ; do echo \"------ $f\\n`cat $f`\\n\" ; done"});
581     RunCommandToFd(fd, "PMIC Votables", {"/vendor/bin/sh", "-c", "cat /sys/kernel/debug/pmic-votable/*/status"});
582     RunCommandToFd(fd, "Google Charger", {"/vendor/bin/sh", "-c", "cd /d/google_charger/; for f in `ls pps_*` ; do echo \"$f: `cat $f`\" ; done"});
583     RunCommandToFd(fd, "Google Battery", {"/vendor/bin/sh", "-c", "cd /d/google_battery/; for f in `ls ssoc_*` ; do echo \"$f: `cat $f`\" ; done"});
584     RunCommandToFd(fd, "Battery EEPROM", {"/vendor/bin/sh", "-c", "xxd /sys/devices/platform/soc/a8c000.i2c/i2c-2/2-0050/2-00500/nvmem"});
585     DumpFileToFd(fd, "BMS", "/d/logbuffer/ssoc");
586     DumpFileToFd(fd, "smblib", "/d/logbuffer/smblib");
587     DumpFileToFd(fd, "TTF", "/d/logbuffer/ttf");
588     DumpFileToFd(fd, "TTF details", "/sys/class/power_supply/battery/ttf_details");
589     DumpFileToFd(fd, "TTF stats", "/sys/class/power_supply/battery/ttf_stats");
590 
591     DumpFileToFd(fd, "Modem Stat", "/data/vendor/modem_stat/debug.txt");
592     DumpFileToFd(fd, "Pixel trace", "/d/tracing/instances/pixel-trace/trace");
593 
594     // Slower dump put later in case stuck the rest of dump
595     // Timeout after 3s as TZ log missing EOF
596     RunCommandToFd(fd, "QSEE logs", {"/vendor/bin/sh", "-c", "/vendor/bin/timeout 3 cat /d/tzdbg/qsee_log"});
597 
598     // Citadel info
599     RunCommandToFd(fd, "Citadel VERSION", {"/vendor/bin/hw/citadel_updater", "-lv"});
600     RunCommandToFd(fd, "Citadel STATS", {"/vendor/bin/hw/citadel_updater", "--stats"});
601     RunCommandToFd(fd, "Citadel BOARDID", {"/vendor/bin/hw/citadel_updater", "--board_id"});
602 
603     // Dump fastrpc dma buffer size
604     DumpFileToFd(fd, "Fastrpc dma buffer", "/sys/kernel/fastrpc/total_dma_kb");
605 
606     // Keep this at the end as very long on not for humans
607     DumpFileToFd(fd, "WLAN FW Log Symbol Table", "/vendor/firmware/Data.msc");
608 
609     if (modemThreadHandle) {
610         pthread_join(modemThreadHandle, NULL);
611     }
612 
613     return DumpstateStatus::OK;
614 }
615 
setVerboseLoggingEnabled(const bool enable)616 Return<void> DumpstateDevice::setVerboseLoggingEnabled(const bool enable) {
617     android::base::SetProperty(VENDOR_VERBOSE_LOGGING_ENABLED_PROPERTY, enable ? "true" : "false");
618     return Void();
619 }
620 
getVerboseLoggingEnabled()621 Return<bool> DumpstateDevice::getVerboseLoggingEnabled() {
622     return android::base::GetBoolProperty(VENDOR_VERBOSE_LOGGING_ENABLED_PROPERTY, false);
623 }
624 
625 }  // namespace implementation
626 }  // namespace V1_1
627 }  // namespace dumpstate
628 }  // namespace hardware
629 }  // namespace android
630