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/properties.h>
22 #include <android-base/unique_fd.h>
23 #include <cutils/properties.h>
24 #include <hidl/HidlBinderSupport.h>
25 #include <hidl/HidlSupport.h>
26
27 #include <log/log.h>
28 #include <pthread.h>
29 #include <string.h>
30 #include <sys/stat.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
71 #define BUFSIZE 65536
copyFile(std::string srcFile,std::string destFile)72 static void copyFile(std::string srcFile, std::string destFile) {
73 uint8_t buffer[BUFSIZE];
74 ssize_t size;
75
76 int fdSrc = open(srcFile.c_str(), O_RDONLY);
77 if (fdSrc < 0) {
78 ALOGD("Failed to open source file %s\n", srcFile.c_str());
79 return;
80 }
81
82 int fdDest = open(destFile.c_str(), O_WRONLY | O_CREAT, 0666);
83 if (fdDest < 0) {
84 ALOGD("Failed to open destination file %s\n", destFile.c_str());
85 close(fdSrc);
86 return;
87 }
88
89 ALOGD("Copying %s to %s\n", srcFile.c_str(), destFile.c_str());
90 while ((size = TEMP_FAILURE_RETRY(read(fdSrc, buffer, BUFSIZE))) > 0) {
91 TEMP_FAILURE_RETRY(write(fdDest, buffer, size));
92 }
93
94 close(fdDest);
95 close(fdSrc);
96 }
97
98 struct PosixTarHeader {
99 char name[100]; /* 0 */
100 char mode[8]; /* 100 */
101 char uid[8]; /* 108 */
102 char gid[8]; /* 116 */
103 char size[12]; /* 124 */
104 char mtime[12]; /* 136 */
105 char chksum[8]; /* 148 */
106 char typeflag; /* 156 */
107 char linkname[100]; /* 157 */
108 char magic[6]; /* 257 */
109 char version[2]; /* 259 */
110 char uname[32]; /* 265 */
111 char gname[32]; /* 297 */
112 char devmajor[8]; /* 329 */
113 char devminor[8]; /* 337 */
114 char prefix[155]; /* 345 */
115 char pad[12]; /* 500 */
116 };
117
tarCheckSum(PosixTarHeader * header)118 static unsigned int tarCheckSum(PosixTarHeader *header) {
119 unsigned int sum = 0;
120 char *p = (char *)header;
121 char *q = p + sizeof(PosixTarHeader);
122 for (int i = 0; i < 8; i++) {
123 header->chksum[i] = ' ';
124 }
125 while (p < q) {
126 sum += *p++ & 0xff;
127 }
128 return sum;
129 }
130
tarHeader(PosixTarHeader * header,char * fileName,ssize_t fileSize)131 static PosixTarHeader *tarHeader(PosixTarHeader *header, char *fileName, ssize_t fileSize) {
132 memset(header, 0, sizeof(PosixTarHeader));
133 strcpy(header->name, fileName);
134 sprintf(header->mode, "%07o", 0600);
135 sprintf(header->size, "%011llo", (long long unsigned int)fileSize);
136 sprintf(header->mtime, "%011o", 0);
137 header->typeflag = '0';
138 strcpy(header->magic, "ustar");
139 strcpy(header->version, " ");
140 sprintf(header->chksum, "%06o", tarCheckSum(header));
141 return header;
142 }
143
createTarFile(std::string tarFile,std::string srcDir)144 static void createTarFile(std::string tarFile, std::string srcDir) {
145 uint8_t buffer[BUFSIZE];
146 struct dirent *dirent;
147 struct stat st;
148 PosixTarHeader header;
149 ssize_t size, tarLen = 0, blockSize = sizeof(PosixTarHeader);
150 char padding = '\0';
151
152 DIR *dirp = opendir(srcDir.c_str());
153 if (dirp == NULL) {
154 ALOGD("Unable to open folder %s\n", srcDir.c_str());
155 return;
156 }
157
158 int fdTar = open(tarFile.c_str(), O_WRONLY | O_CREAT, 0666);
159 if (fdTar < 0) {
160 ALOGD("Unable to open file %s\n", tarFile.c_str());
161 closedir(dirp);
162 return;
163 }
164
165 ALOGD("Creating tar file %s\n", tarFile.c_str());
166 while ((dirent = readdir(dirp)) != NULL) {
167 if (dirent->d_name[0] == '.') {
168 continue;
169 }
170
171 std::string path = srcDir + "/" + dirent->d_name;
172 int fd = open(path.c_str(), O_RDONLY);
173 if (fd < 0) {
174 ALOGD("Unable to open file %s\n", path.c_str());
175 continue;
176 }
177 fstat(fd, &st);
178
179 if (TEMP_FAILURE_RETRY(write(fdTar, tarHeader(
180 &header, dirent->d_name, st.st_size), blockSize)) <= 0) {
181 ALOGD("Error while writing file %s, errno=%d\n", tarFile.c_str(), errno);
182 close(fd);
183 continue;
184 }
185 tarLen += blockSize;
186
187 while ((size = TEMP_FAILURE_RETRY(read(fd, buffer, BUFSIZE))) > 0) {
188 write(fdTar, buffer, size);
189 tarLen += size;
190 }
191
192 while (tarLen % blockSize != 0) {
193 write(fdTar, &padding, 1);
194 tarLen++;
195 }
196 close(fd);
197 }
198 close(fdTar);
199 closedir(dirp);
200 }
201
dumpLogs(int fd,std::string srcDir,std::string destDir,int maxFileNum,const char * logPrefix)202 static void dumpLogs(int fd, std::string srcDir, std::string destDir,
203 int maxFileNum, const char *logPrefix) {
204 (void) fd;
205 struct dirent **dirent_list = NULL;
206 int num_entries = scandir(srcDir.c_str(),
207 &dirent_list,
208 0,
209 (int (*)(const struct dirent **, const struct dirent **)) alphasort);
210
211 if (!dirent_list) {
212 return;
213 } else if (num_entries <= 0) {
214 return;
215 }
216
217 int copiedFiles = 0;
218
219 for (int i = num_entries - 1; i >= 0; i--) {
220 ALOGD("Found %s\n", dirent_list[i]->d_name);
221
222 if (0 != strncmp(dirent_list[i]->d_name, logPrefix, strlen(logPrefix))) {
223 continue;
224 }
225
226 if ((copiedFiles >= maxFileNum) && (maxFileNum != -1)) {
227 ALOGD("Skipped %s\n", dirent_list[i]->d_name);
228 continue;
229 }
230
231 copiedFiles++;
232
233 std::string srcLogFile = srcDir + "/" + dirent_list[i]->d_name;
234 std::string destLogFile = destDir + "/" + dirent_list[i]->d_name;
235 copyFile(srcLogFile, destLogFile);
236 }
237
238 while (num_entries--) {
239 free(dirent_list[num_entries]);
240 }
241
242 free(dirent_list);
243 }
244
dumpModemThread(void * data)245 static void *dumpModemThread(void *data)
246 {
247 long fdModem = (long)data;
248
249 ALOGD("dumpModemThread started\n");
250
251 std::string modemLogDir = android::base::GetProperty(MODEM_LOG_LOC_PROPERTY, "");
252 if (modemLogDir.empty()) {
253 ALOGD("No modem log place is set");
254 return NULL;
255 }
256
257 std::string filePrefix = android::base::GetProperty(MODEM_LOG_PREFIX_PROPERTY, "");
258
259 if (filePrefix.empty()) {
260 ALOGD("Modem log prefix is not set");
261 return NULL;
262 }
263
264 bool diagLogEnabled = android::base::GetBoolProperty(DIAG_MDLOG_PERSIST_PROPERTY, false);
265 bool diagLogStarted = android::base::GetBoolProperty(DIAG_MDLOG_STATUS_PROPERTY, false);
266
267 if (diagLogEnabled) {
268 if (diagLogStarted) {
269 android::base::SetProperty(DIAG_MDLOG_PROPERTY, "false");
270 ALOGD("Stopping diag_mdlog...\n");
271 if (android::base::WaitForProperty(DIAG_MDLOG_STATUS_PROPERTY, "false", std::chrono::seconds(10))) {
272 ALOGD("diag_mdlog exited");
273 } else {
274 ALOGE("Waited mdlog timeout after 10 second");
275 }
276 } else {
277 ALOGD("diag_mdlog is not running");
278 }
279 }
280
281 sleep(1);
282 ALOGD("Waited modem for 1 second to flush logs");
283
284 const std::string modemLogCombined = modemLogDir + "/" + filePrefix + "all.tar";
285 const std::string modemLogAllDir = modemLogDir + "/modem_log";
286
287 RunCommandToFd(STDOUT_FILENO, "MKDIR MODEM LOG", {"/vendor/bin/mkdir", "-p", modemLogAllDir.c_str()}, CommandOptions::WithTimeout(2).Build());
288
289 const std::string diagLogDir = "/data/vendor/radio/diag_logs/logs";
290 const std::string diagPoweronLogPath = "/data/vendor/radio/diag_logs/logs/diag_poweron_log.qmdl";
291
292 if (diagLogEnabled) {
293 dumpLogs(STDOUT_FILENO, diagLogDir, modemLogAllDir, android::base::GetIntProperty(DIAG_MDLOG_NUMBER_BUGREPORT, 100), DIAG_LOG_PREFIX);
294
295 if (diagLogStarted) {
296 ALOGD("Restarting diag_mdlog...");
297 android::base::SetProperty(DIAG_MDLOG_PROPERTY, "true");
298 }
299 }
300 copyFile(diagPoweronLogPath, modemLogAllDir + "/" + basename(diagPoweronLogPath.c_str()));
301
302 if (!PropertiesHelper::IsUserBuild()) {
303 char cmd[256] = { 0 };
304
305 android::base::SetProperty(MODEM_EFS_DUMP_PROPERTY, "true");
306
307 const std::string tcpdumpLogDir = "/data/vendor/tcpdump_logger/logs";
308 const std::string extendedLogDir = "/data/vendor/radio/extended_logs";
309 const std::vector <std::string> rilAndNetmgrLogs
310 {
311 "/data/vendor/radio/haldebug_ril0",
312 "/data/vendor/radio/haldebug_ril1",
313 "/data/vendor/radio/ril_log0",
314 "/data/vendor/radio/ril_log0_old",
315 "/data/vendor/radio/ril_log1",
316 "/data/vendor/radio/ril_log1_old",
317 "/data/vendor/radio/qmi_fw_log",
318 "/data/vendor/radio/qmi_fw_log_old",
319 "/data/vendor/radio/imsdatadaemon_log",
320 "/data/vendor/radio/imsdatadaemon_log_old",
321 "/data/vendor/netmgr/netmgr_log",
322 "/data/vendor/netmgr/netmgr_log_old",
323 "/data/vendor/radio/omadm_logs.txt",
324 "/data/vendor/radio/power_anomaly_data.txt",
325 "/data/vendor/radio/diag_logs/diag_trace.txt",
326 "/data/vendor/radio/diag_logs/diag_trace_old.txt",
327 "/data/vendor/radio/metrics_data",
328 "/data/vendor/ssrlog/ssr_log.txt",
329 "/data/vendor/ssrlog/ssr_log_old.txt",
330 "/data/vendor/rfs/mpss/modem_efs",
331 "/sys/kernel/debug/ipa/ipa_statistics_msg"
332 };
333
334 bool tcpdumpEnabled = android::base::GetBoolProperty(TCPDUMP_PERSIST_PROPERTY, false);
335 if (tcpdumpEnabled) {
336 dumpLogs(STDOUT_FILENO, tcpdumpLogDir, modemLogAllDir, android::base::GetIntProperty(TCPDUMP_NUMBER_BUGREPORT, 5), TCPDUMP_LOG_PREFIX);
337 }
338
339 for (const auto& logFile : rilAndNetmgrLogs) {
340 copyFile(logFile, modemLogAllDir + "/" + basename(logFile.c_str()));
341 }
342
343 //Dump IPA log
344 snprintf(cmd, sizeof(cmd),
345 "cat /d/ipc_logging/ipa/log > %s/ipa_log",
346 modemLogAllDir.c_str());
347 RunCommandToFd(STDOUT_FILENO, "Dump IPA log", {"/vendor/bin/sh", "-c", cmd});
348
349 dumpLogs(STDOUT_FILENO, extendedLogDir, modemLogAllDir, 100, EXTENDED_LOG_PREFIX);
350 android::base::SetProperty(MODEM_EFS_DUMP_PROPERTY, "false");
351 }
352
353 createTarFile(modemLogCombined, modemLogAllDir);
354
355 std::vector<uint8_t> buffer(65536);
356 android::base::unique_fd fdLog(TEMP_FAILURE_RETRY(open(modemLogCombined.c_str(), O_RDONLY | O_CLOEXEC | O_NONBLOCK)));
357
358 if (fdLog >= 0) {
359 while (1) {
360 ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fdLog, buffer.data(), buffer.size()));
361
362 if (bytes_read == 0) {
363 break;
364 } else if (bytes_read < 0) {
365 ALOGD("read(%s): %s\n", modemLogCombined.c_str(), strerror(errno));
366 break;
367 }
368
369 ssize_t result = TEMP_FAILURE_RETRY(write(fdModem, buffer.data(), bytes_read));
370
371 if (result != bytes_read) {
372 ALOGD("Failed to write %ld bytes, actually written: %ld", bytes_read, result);
373 break;
374 }
375 }
376 }
377
378 RunCommandToFd(STDOUT_FILENO, "RM MODEM DIR", { "/vendor/bin/rm", "-r", modemLogAllDir.c_str()}, CommandOptions::WithTimeout(2).Build());
379 RunCommandToFd(STDOUT_FILENO, "RM LOG", { "/vendor/bin/rm", modemLogCombined.c_str()}, CommandOptions::WithTimeout(2).Build());
380
381 ALOGD("dumpModemThread finished\n");
382
383 return NULL;
384 }
385
DumpTouch(int fd)386 static void DumpTouch(int fd) {
387 const char touch_spi_path[] = "/sys/class/spi_master/spi0/spi0.0";
388 char cmd[256];
389
390 snprintf(cmd, sizeof(cmd), "%s/appid", touch_spi_path);
391 if (!access(cmd, R_OK)) {
392 // Touch firmware version
393 DumpFileToFd(fd, "STM touch firmware version", cmd);
394
395 // Touch controller status
396 snprintf(cmd, sizeof(cmd), "%s/status", touch_spi_path);
397 DumpFileToFd(fd, "STM touch status", cmd);
398
399 // Mutual raw data
400 snprintf(cmd, sizeof(cmd),
401 "echo 13 00 01 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
402 touch_spi_path, touch_spi_path);
403 RunCommandToFd(fd, "Mutual Raw", {"/vendor/bin/sh", "-c", cmd});
404
405 // Mutual strength data
406 snprintf(cmd, sizeof(cmd),
407 "echo 17 01 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
408 touch_spi_path, touch_spi_path);
409 RunCommandToFd(fd, "Mutual Strength", {"/vendor/bin/sh", "-c", cmd});
410
411 // Self raw data
412 snprintf(cmd, sizeof(cmd),
413 "echo 15 00 01> %s/stm_fts_cmd && cat %s/stm_fts_cmd",
414 touch_spi_path, touch_spi_path);
415 RunCommandToFd(fd, "Self Raw", {"/vendor/bin/sh", "-c", cmd});
416 }
417
418 if (!access("/proc/fts/driver_test", R_OK)) {
419 RunCommandToFd(fd, "Mutual Raw Data",
420 {"/vendor/bin/sh", "-c",
421 "echo 23 00 > /proc/fts/driver_test && "
422 "cat /proc/fts/driver_test"});
423 RunCommandToFd(fd, "Mutual Baseline Data",
424 {"/vendor/bin/sh", "-c",
425 "echo 23 03 > /proc/fts/driver_test && "
426 "cat /proc/fts/driver_test"});
427 RunCommandToFd(fd, "Mutual Strength Data",
428 {"/vendor/bin/sh", "-c",
429 "echo 23 02 > /proc/fts/driver_test && "
430 "cat /proc/fts/driver_test"});
431 RunCommandToFd(fd, "Self Raw Data",
432 {"/vendor/bin/sh", "-c",
433 "echo 24 00 > /proc/fts/driver_test && "
434 "cat /proc/fts/driver_test"});
435 RunCommandToFd(fd, "Self Baseline Data",
436 {"/vendor/bin/sh", "-c",
437 "echo 24 03 > /proc/fts/driver_test && "
438 "cat /proc/fts/driver_test"});
439 RunCommandToFd(fd, "Self Strength Data",
440 {"/vendor/bin/sh", "-c",
441 "echo 24 02 > /proc/fts/driver_test && "
442 "cat /proc/fts/driver_test"});
443 RunCommandToFd(fd, "Mutual Compensation",
444 {"/vendor/bin/sh", "-c",
445 "echo 32 10 > /proc/fts/driver_test && "
446 "cat /proc/fts/driver_test"});
447 RunCommandToFd(fd, "Self Compensation",
448 {"/vendor/bin/sh", "-c",
449 "echo 33 12 > /proc/fts/driver_test && "
450 "cat /proc/fts/driver_test"});
451 RunCommandToFd(fd, "Golden MS Raw",
452 {"/vendor/bin/sh", "-c",
453 "echo 34 > /proc/fts/driver_test && "
454 "cat /proc/fts/driver_test"});
455 RunCommandToFd(fd, "Packaging Plant - HW reset",
456 {"/vendor/bin/sh", "-c",
457 "echo 01 FA 20 00 00 24 80 > /proc/fts/driver_test"});
458 RunCommandToFd(fd, "Packaging Plant - Hibernate Memory",
459 {"/vendor/bin/sh", "-c",
460 "echo 01 FA 20 00 00 68 08 > /proc/fts/driver_test"});
461 RunCommandToFd(fd, "Packaging Plant - Read 16 bytes from Address 0x00043FD8",
462 {"/vendor/bin/sh", "-c",
463 "echo 02 FB 00 04 3F D8 00 10 01 > /proc/fts/driver_test && "
464 "cat /proc/fts/driver_test"});
465 }
466
467 snprintf(cmd, sizeof(cmd), "%s/stm_fts_cmd", touch_spi_path);
468 if (!access(cmd, R_OK)) {
469 // ITO raw data
470 snprintf(cmd, sizeof(cmd),
471 "echo 01 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
472 touch_spi_path, touch_spi_path);
473 RunCommandToFd(fd, "ITO Raw", {"/vendor/bin/sh", "-c", cmd});
474 }
475 }
476
DumpDisplay(int fd)477 static void DumpDisplay(int fd) {
478 DumpFileToFd(fd, "PANEL VENDOR NAME", "/sys/class/panel_info/panel0/panel_vendor_name");
479 DumpFileToFd(fd, "PANEL SN", "/sys/class/panel_info/panel0/serial_number");
480 DumpFileToFd(fd, "PANEL EXTRA INFO", "/sys/class/panel_info/panel0/panel_extinfo");
481 }
482
DumpSensorLog(int fd)483 static void DumpSensorLog(int fd) {
484 const std::string logPath = "/data/vendor/sensors/log/sensor_log.txt";
485 const std::string lastlogPath = "/data/vendor/sensors/log/sensor_lastlog.txt";
486
487 if (!access(logPath.c_str(), R_OK)) {
488 DumpFileToFd(fd, "sensor log", logPath);
489 }
490 if (!access(lastlogPath.c_str(), R_OK)) {
491 DumpFileToFd(fd, "sensor lastlog", lastlogPath);
492 }
493 }
494
DumpF2FS(int fd)495 static void DumpF2FS(int fd) {
496 DumpFileToFd(fd, "F2FS", "/sys/kernel/debug/f2fs/status");
497 DumpFileToFd(fd, "F2FS", "/dev/fscklogs/fsck");
498 RunCommandToFd(fd, "F2FS - fsck time (ms)", {"/vendor/bin/sh", "-c", "getprop ro.boottime.init.fsck.data"});
499 RunCommandToFd(fd, "F2FS - checkpoint=disable time (ms)", {"/vendor/bin/sh", "-c", "getprop ro.boottime.init.mount.data"});
500 }
501
DumpUFS(int fd)502 static void DumpUFS(int fd) {
503 DumpFileToFd(fd, "UFS model", "/sys/block/sda/device/model");
504 DumpFileToFd(fd, "UFS rev", "/sys/block/sda/device/rev");
505 DumpFileToFd(fd, "UFS size", "/sys/block/sda/size");
506
507 std::string bootdev = android::base::GetProperty(UFS_BOOTDEVICE, "");
508 if (!bootdev.empty()) {
509 DumpFileToFd(fd, "UFS Slow IO Read", "/sys/devices/platform/soc/" + bootdev + "/slowio_read_cnt");
510 DumpFileToFd(fd, "UFS Slow IO Write", "/sys/devices/platform/soc/" + bootdev + "/slowio_write_cnt");
511 DumpFileToFd(fd, "UFS Slow IO Unmap", "/sys/devices/platform/soc/" + bootdev + "/slowio_unmap_cnt");
512 DumpFileToFd(fd, "UFS Slow IO Sync", "/sys/devices/platform/soc/" + bootdev + "/slowio_sync_cnt");
513
514 RunCommandToFd(fd, "UFS io_stats", {"/vendor/bin/sh", "-c",
515 "path=\"/sys/devices/platform/soc/" + bootdev + "/io_stats\"; "
516 "printf \"\\t\\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
517 "ReadCnt ReadBytes WriteCnt WriteBytes RWCnt RWBytes; "
518 "str=$(cat $path/*_start); arr=($str); "
519 "printf \"Started: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
520 "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "
521 "str=$(cat $path/*_complete); arr=($str); "
522 "printf \"Completed: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
523 "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "
524 "str=$(cat $path/*_maxdiff); arr=($str); "
525 "printf \"MaxDiff: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\\n\" "
526 "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "});
527
528 RunCommandToFd(fd, "UFS req_stats", {"/vendor/bin/sh", "-c",
529 "path=\"/sys/devices/platform/soc/" + bootdev + "/req_stats\"; "
530 "printf \"\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
531 "All Write Read Read\\(urg\\) Write\\(urg\\) Flush Discard; "
532 "str=$(cat $path/*_min); arr=($str); "
533 "printf \"Min:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
534 "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]}; "
535 "str=$(cat $path/*_max); arr=($str); "
536 "printf \"Max:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
537 "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]}; "
538 "str=$(cat $path/*_avg); arr=($str); "
539 "printf \"Avg.:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
540 "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]}; "
541 "str=$(cat $path/*_sum); arr=($str); "
542 "printf \"Count:\\t%-10s %-10s %-10s %-10s %-10s %-10s %-10s\\n\\n\" "
543 "${arr[0]} ${arr[3]} ${arr[6]} ${arr[4]} ${arr[5]} ${arr[2]} ${arr[1]};"});
544
545 std::string ufs_health = "for f in $(find /sys/devices/platform/soc/" + bootdev + "/health_descriptor -type f); do if [[ -r $f && -f $f ]]; then echo --- $f; cat $f; echo ''; fi; done";
546 RunCommandToFd(fd, "UFS health", {"/vendor/bin/sh", "-c", ufs_health.c_str()});
547 }
548 }
549
550 // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow.
dumpstateBoard(const hidl_handle & handle)551 Return<void> DumpstateDevice::dumpstateBoard(const hidl_handle& handle) {
552 // Ignore return value, just return an empty status.
553 dumpstateBoard_1_1(handle, DumpstateMode::DEFAULT, 30 * 1000 /* timeoutMillis */);
554 return Void();
555 }
556
557 // Methods from ::android::hardware::dumpstate::V1_1::IDumpstateDevice follow.
dumpstateBoard_1_1(const hidl_handle & handle,const DumpstateMode mode,const uint64_t timeoutMillis)558 Return<DumpstateStatus> DumpstateDevice::dumpstateBoard_1_1(const hidl_handle& handle,
559 const DumpstateMode mode,
560 const uint64_t timeoutMillis) {
561 // Unused arguments.
562 (void) timeoutMillis;
563
564 // Exit when dump is completed since this is a lazy HAL.
565 addPostCommandTask([]() {
566 exit(0);
567 });
568
569 if (handle == nullptr || handle->numFds < 1) {
570 ALOGE("no FDs\n");
571 return DumpstateStatus::ILLEGAL_ARGUMENT;
572 }
573
574 int fd = handle->data[0];
575 if (fd < 0) {
576 ALOGE("invalid FD: %d\n", handle->data[0]);
577 return DumpstateStatus::ILLEGAL_ARGUMENT;
578 }
579
580 bool isModeValid = false;
581 for (const auto dumpstateMode : hidl_enum_range<DumpstateMode>()) {
582 if (mode == dumpstateMode) {
583 isModeValid = true;
584 break;
585 }
586 }
587 if (!isModeValid) {
588 ALOGE("Invalid mode: %d\n", mode);
589 return DumpstateStatus::ILLEGAL_ARGUMENT;
590 } else if (mode == DumpstateMode::WEAR) {
591 // We aren't a Wear device.
592 ALOGE("Unsupported mode: %d\n", mode);
593 return DumpstateStatus::UNSUPPORTED_MODE;
594 }
595
596 RunCommandToFd(fd, "Notify modem", {"/vendor/bin/modem_svc", "-s"}, CommandOptions::WithTimeout(1).Build());
597
598 pthread_t modemThreadHandle = 0;
599 if (getVerboseLoggingEnabled()) {
600 ALOGD("Verbose logging is enabled.\n");
601 if (handle->numFds < 2) {
602 ALOGE("no FD for modem\n");
603 } else {
604 int fdModem = handle->data[1];
605 if (pthread_create(&modemThreadHandle, NULL, dumpModemThread, (void *)((long)fdModem)) != 0) {
606 ALOGE("could not create thread for dumpModem\n");
607 }
608 }
609 }
610
611 RunCommandToFd(fd, "VENDOR PROPERTIES", {"/vendor/bin/getprop"});
612 DumpFileToFd(fd, "SoC serial number", "/sys/devices/soc0/serial_number");
613 DumpFileToFd(fd, "CPU present", "/sys/devices/system/cpu/present");
614 DumpFileToFd(fd, "CPU online", "/sys/devices/system/cpu/online");
615 DumpFileToFd(fd, "Bootloader Log", "/proc/bldrlog");
616 DumpTouch(fd);
617 DumpDisplay(fd);
618
619 DumpF2FS(fd);
620 DumpUFS(fd);
621
622 DumpSensorLog(fd);
623
624 DumpFileToFd(fd, "INTERRUPTS", "/proc/interrupts");
625 DumpFileToFd(fd, "Sleep Stats", "/sys/power/system_sleep/stats");
626 DumpFileToFd(fd, "Power Management Stats", "/sys/power/rpmh_stats/master_stats");
627 DumpFileToFd(fd, "WLAN Power Stats", "/sys/kernel/wlan/power_stats");
628 DumpFileToFd(fd, "LL-Stats", "/d/wlan0/ll_stats");
629 DumpFileToFd(fd, "WLAN Connect Info", "/d/wlan0/connect_info");
630 DumpFileToFd(fd, "WLAN Offload Info", "/d/wlan0/offload_info");
631 DumpFileToFd(fd, "WLAN Roaming Stats", "/d/wlan0/roam_stats");
632 DumpFileToFd(fd, "ICNSS Stats", "/d/icnss/stats");
633 DumpFileToFd(fd, "SMD Log", "/d/ipc_logging/smd/log");
634 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"});
635 DumpFileToFd(fd, "dmabuf info", "/d/dma_buf/bufinfo");
636 DumpFileToFd(fd, "dmabuf process info", "/d/dma_buf/dmaprocs");
637 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"});
638 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"});
639 RunCommandToFd(fd, "Cooling Device Time in State", {"/vendor/bin/sh", "-c", "for f in /sys/class/thermal/cooling* ; do type=`cat $f/type` ; temp=`cat $f/stats/time_in_state_ms` ; echo \"$type:\n$temp\" ; done"});
640 RunCommandToFd(fd, "Cooling Device Trans Table", {"/vendor/bin/sh", "-c", "for f in /sys/class/thermal/cooling* ; do type=`cat $f/type` ; temp=`cat $f/stats/trans_table` ; echo \"$type:\n$temp\" ; done"});
641 RunCommandToFd(
642 fd, "LMH info",
643 {"/vendor/bin/sh", "-c",
644 "for f in /sys/bus/platform/drivers/msm_lmh_dcvs/*qcom,limits-dcvs@*/lmh_freq_limit; do "
645 "state=`cat $f` ; echo \"$f: $state\" ; done"});
646 RunCommandToFd(
647 fd, "CPU MAX FREQ info",
648 {"/vendor/bin/sh", "-c",
649 "for f in /sys/devices/system/cpu/cpufreq/policy*/scaling_max_freq; do "
650 "max_freq=`cat $f` ; echo \"$f: $max_freq\" ; done"});
651 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"});
652 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"});
653 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`\""});
654 DumpFileToFd(fd, "TCPM logs", "/d/usb/tcpm-usbpd0");
655 DumpFileToFd(fd, "PD Engine", "/dev/logbuffer_usbpd");
656 DumpFileToFd(fd, "PPS", "/dev/logbuffer_pps");
657 DumpFileToFd(fd, "BMS", "/dev/logbuffer_ssoc");
658 DumpFileToFd(fd, "smblib", "/dev/logbuffer_smblib");
659 DumpFileToFd(fd, "TTF", "/dev/logbuffer_ttf");
660 DumpFileToFd(fd, "TTF details", "/sys/class/power_supply/battery/ttf_details");
661 DumpFileToFd(fd, "TTF stats", "/sys/class/power_supply/battery/ttf_stats");
662 DumpFileToFd(fd, "ipc-local-ports", "/d/msm_ipc_router/dump_local_ports");
663 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`\""});
664 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"});
665 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"});
666 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"});
667 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"});
668 RunCommandToFd(fd, "PMIC Votables", {"/vendor/bin/sh", "-c", "cat /sys/kernel/debug/pmic-votable/*/status"});
669
670 if (!PropertiesHelper::IsUserBuild()) {
671 RunCommandToFd(fd, "Google Charger", {"/vendor/bin/sh", "-c", "cd /d/google_charger/; for f in `ls pps_*` ; do echo \"$f: `cat $f`\" ; done"});
672 RunCommandToFd(fd, "Google Battery", {"/vendor/bin/sh", "-c", "cd /d/google_battery/; for f in `ls ssoc_*` ; do echo \"$f: `cat $f`\" ; done"});
673 }
674
675 RunCommandToFd(fd, "eSIM Status", {"/vendor/bin/sh", "-c", "od -t x1 /sys/firmware/devicetree/base/chosen/cdt/cdb2/esim"});
676 DumpFileToFd(fd, "Modem Stat", "/data/vendor/modem_stat/debug.txt");
677 DumpFileToFd(fd, "Pixel trace", "/d/tracing/instances/pixel-trace/trace");
678
679 // Slower dump put later in case stuck the rest of dump
680 // Timeout after 3s as TZ log missing EOF
681 RunCommandToFd(fd, "QSEE logs", {"/vendor/bin/sh", "-c", "/vendor/bin/timeout 3 cat /d/tzdbg/qsee_log"});
682
683 // Citadel info
684 RunCommandToFd(fd, "Citadel VERSION", {"/vendor/bin/hw/citadel_updater", "-lv"});
685 RunCommandToFd(fd, "Citadel STATS", {"/vendor/bin/hw/citadel_updater", "--stats"});
686 RunCommandToFd(fd, "Citadel BOARDID", {"/vendor/bin/hw/citadel_updater", "--board_id"});
687
688 // Dump various events in WiFi data path
689 DumpFileToFd(fd, "WLAN DP Trace", "/d/wlan/dpt_stats/dump_set_dpt_logs");
690
691 // Keep this at the end as very long on not for humans
692 DumpFileToFd(fd, "WLAN FW Log Symbol Table", "/vendor/firmware/Data.msc");
693
694 // Dump camera profiler log
695 RunCommandToFd(fd, "Camera Profiler Logs", {"/vendor/bin/sh", "-c", "for f in /data/vendor/camera/profiler/camx_*; do echo [$f]; cat \"$f\";done"});
696
697 // Dump fastrpc dma buffer size
698 DumpFileToFd(fd, "Fastrpc dma buffer", "/sys/kernel/fastrpc/total_dma_kb");
699
700 if (modemThreadHandle) {
701 pthread_join(modemThreadHandle, NULL);
702 }
703
704 return DumpstateStatus::OK;
705 }
706
setVerboseLoggingEnabled(const bool enable)707 Return<void> DumpstateDevice::setVerboseLoggingEnabled(const bool enable) {
708 android::base::SetProperty(VENDOR_VERBOSE_LOGGING_ENABLED_PROPERTY, enable ? "true" : "false");
709 return Void();
710 }
711
getVerboseLoggingEnabled()712 Return<bool> DumpstateDevice::getVerboseLoggingEnabled() {
713 return android::base::GetBoolProperty(VENDOR_VERBOSE_LOGGING_ENABLED_PROPERTY, false);
714 }
715
716 } // namespace implementation
717 } // namespace V1_1
718 } // namespace dumpstate
719 } // namespace hardware
720 } // namespace android
721