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