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_device"
18
19 #include <inttypes.h>
20
21 #include <android-base/file.h>
22 #include <android-base/stringprintf.h>
23 #include <android-base/properties.h>
24 #include <android-base/unique_fd.h>
25 #include <log/log.h>
26 #include <sys/stat.h>
27
28 #include "Dumpstate.h"
29
30 #include "DumpstateUtil.h"
31
32 #define MODEM_LOG_DIRECTORY "/data/vendor/radio/logs/always-on"
33 #define MODEM_LOG_HISTORY_DIRECTORY "data/vendor/radio/logs/history"
34 #define MODEM_EXTENDED_LOG_DIRECTORY "/data/vendor/radio/extended_logs"
35 #define RIL_LOG_DIRECTORY "/data/vendor/radio"
36 #define RIL_LOG_DIRECTORY_PROPERTY "persist.vendor.ril.log.base_dir"
37 #define RIL_LOG_NUMBER_PROPERTY "persist.vendor.ril.log.num_file"
38 #define MODEM_LOGGING_PERSIST_PROPERTY "persist.vendor.sys.modem.logging.enable"
39 #define MODEM_LOGGING_PROPERTY "vendor.sys.modem.logging.enable"
40 #define MODEM_LOGGING_STATUS_PROPERTY "vendor.sys.modem.logging.status"
41 #define MODEM_LOGGING_NUMBER_BUGREPORT_PROPERTY "persist.vendor.sys.modem.logging.br_num"
42 #define MODEM_LOGGING_PATH_PROPERTY "vendor.sys.modem.logging.log_path"
43 #define GPS_LOG_DIRECTORY "/data/vendor/gps/logs"
44 #define GPS_LOG_NUMBER_PROPERTY "persist.vendor.gps.aol.log_num"
45 #define GPS_LOGGING_STATUS_PROPERTY "vendor.gps.aol.enabled"
46
47 #define UFS_BOOTDEVICE "ro.boot.bootdevice"
48
49 #define TCPDUMP_LOG_DIRECTORY "/data/vendor/tcpdump_logger/logs"
50 #define TCPDUMP_NUMBER_BUGREPORT "persist.vendor.tcpdump.log.br_num"
51 #define TCPDUMP_PERSIST_PROPERTY "persist.vendor.tcpdump.log.alwayson"
52
53 #define HW_REVISION "ro.boot.hardware.revision"
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 aidl {
61 namespace android {
62 namespace hardware {
63 namespace dumpstate {
64
65 #define GPS_LOG_PREFIX "gl-"
66 #define GPS_MCU_LOG_PREFIX "esw-"
67 #define MODEM_LOG_PREFIX "sbuff_"
68 #define EXTENDED_LOG_PREFIX "extended_log_"
69 #define RIL_LOG_PREFIX "rild.log."
70 #define BUFSIZE 65536
71 #define TCPDUMP_LOG_PREFIX "tcpdump"
72
73 typedef std::chrono::time_point<std::chrono::steady_clock> timepoint_t;
74
75 const char kVerboseLoggingProperty[] = "persist.vendor.verbose_logging_enabled";
76
dumpLogs(int fd,std::string srcDir,std::string destDir,int maxFileNum,const char * logPrefix)77 void Dumpstate::dumpLogs(int fd, std::string srcDir, std::string destDir, int maxFileNum,
78 const char *logPrefix) {
79 struct dirent **dirent_list = NULL;
80 int num_entries = scandir(srcDir.c_str(),
81 &dirent_list,
82 0,
83 (int (*)(const struct dirent **, const struct dirent **)) alphasort);
84 if (!dirent_list) {
85 return;
86 } else if (num_entries <= 0) {
87 return;
88 }
89
90 int copiedFiles = 0;
91
92 for (int i = num_entries - 1; i >= 0; i--) {
93 ALOGD("Found %s\n", dirent_list[i]->d_name);
94
95 if (0 != strncmp(dirent_list[i]->d_name, logPrefix, strlen(logPrefix))) {
96 continue;
97 }
98
99 if ((copiedFiles >= maxFileNum) && (maxFileNum != -1)) {
100 ALOGD("Skipped %s\n", dirent_list[i]->d_name);
101 continue;
102 }
103
104 copiedFiles++;
105
106 CommandOptions options = CommandOptions::WithTimeout(120).Build();
107 std::string srcLogFile = srcDir + "/" + dirent_list[i]->d_name;
108 std::string destLogFile = destDir + "/" + dirent_list[i]->d_name;
109
110 std::string copyCmd = "/vendor/bin/cp " + srcLogFile + " " + destLogFile;
111
112 ALOGD("Copying %s to %s\n", srcLogFile.c_str(), destLogFile.c_str());
113 RunCommandToFd(fd, "CP LOGS", { "/vendor/bin/sh", "-c", copyCmd.c_str() }, options);
114 }
115
116 while (num_entries--) {
117 free(dirent_list[num_entries]);
118 }
119
120 free(dirent_list);
121 }
122
dumpRilLogs(int fd,std::string destDir)123 void Dumpstate::dumpRilLogs(int fd, std::string destDir) {
124 std::string rilLogDir =
125 ::android::base::GetProperty(RIL_LOG_DIRECTORY_PROPERTY, RIL_LOG_DIRECTORY);
126
127 int maxFileNum = ::android::base::GetIntProperty(RIL_LOG_NUMBER_PROPERTY, 50);
128
129 const std::string currentLogDir = rilLogDir + "/cur";
130 const std::string previousLogDir = rilLogDir + "/prev";
131 const std::string currentDestDir = destDir + "/cur";
132 const std::string previousDestDir = destDir + "/prev";
133
134 RunCommandToFd(fd, "MKDIR RIL CUR LOG", {"/vendor/bin/mkdir", "-p", currentDestDir.c_str()},
135 CommandOptions::WithTimeout(2).Build());
136 RunCommandToFd(fd, "MKDIR RIL PREV LOG", {"/vendor/bin/mkdir", "-p", previousDestDir.c_str()},
137 CommandOptions::WithTimeout(2).Build());
138
139 dumpLogs(fd, currentLogDir, currentDestDir, maxFileNum, RIL_LOG_PREFIX);
140 dumpLogs(fd, previousLogDir, previousDestDir, maxFileNum, RIL_LOG_PREFIX);
141 }
142
copyFile(std::string srcFile,std::string destFile)143 void copyFile(std::string srcFile, std::string destFile) {
144 uint8_t buffer[BUFSIZE];
145 ssize_t size;
146
147 int fdSrc = open(srcFile.c_str(), O_RDONLY);
148 if (fdSrc < 0) {
149 ALOGD("Failed to open source file %s\n", srcFile.c_str());
150 return;
151 }
152
153 int fdDest = open(destFile.c_str(), O_WRONLY | O_CREAT, 0666);
154 if (fdDest < 0) {
155 ALOGD("Failed to open destination file %s\n", destFile.c_str());
156 close(fdSrc);
157 return;
158 }
159
160 ALOGD("Copying %s to %s\n", srcFile.c_str(), destFile.c_str());
161 while ((size = TEMP_FAILURE_RETRY(read(fdSrc, buffer, BUFSIZE))) > 0) {
162 TEMP_FAILURE_RETRY(write(fdDest, buffer, size));
163 }
164
165 close(fdDest);
166 close(fdSrc);
167 }
168
dumpNetmgrLogs(std::string destDir)169 void dumpNetmgrLogs(std::string destDir) {
170 const std::vector <std::string> netmgrLogs
171 {
172 "/data/vendor/radio/metrics_data",
173 "/data/vendor/radio/omadm_logs.txt",
174 "/data/vendor/radio/power_anomaly_data.txt",
175 };
176 for (const auto& logFile : netmgrLogs) {
177 copyFile(logFile, destDir + "/" + basename(logFile.c_str()));
178 }
179 }
180
181 /** Dumps last synced NV data into bugreports */
dumpModemEFS(std::string destDir)182 void dumpModemEFS(std::string destDir) {
183 const std::string EFS_DIRECTORY = "/mnt/vendor/efs/";
184 const std::vector <std::string> nv_files
185 {
186 EFS_DIRECTORY+"nv_normal.bin",
187 EFS_DIRECTORY+"nv_protected.bin",
188 };
189 for (const auto& logFile : nv_files) {
190 copyFile(logFile, destDir + "/" + basename(logFile.c_str()));
191 }
192 }
193
startSection(int fd,const std::string & sectionName)194 timepoint_t startSection(int fd, const std::string §ionName) {
195 ::android::base::WriteStringToFd(
196 "\n"
197 "------ Section start: " + sectionName + " ------\n"
198 "\n", fd);
199 return std::chrono::steady_clock::now();
200 }
201
endSection(int fd,const std::string & sectionName,timepoint_t startTime)202 void endSection(int fd, const std::string §ionName, timepoint_t startTime) {
203 auto endTime = std::chrono::steady_clock::now();
204 auto elapsedMsec = std::chrono::duration_cast<std::chrono::milliseconds>
205 (endTime - startTime).count();
206
207 ::android::base::WriteStringToFd(
208 "\n"
209 "------ Section end: " + sectionName + " ------\n"
210 "Elapsed msec: " + std::to_string(elapsedMsec) + "\n"
211 "\n", fd);
212 }
213
214 // If you are adding a single RunCommandToFd() or DumpFileToFd() call, please
215 // add it to dumpMiscSection(). But if you are adding multiple items that are
216 // related to each other - for instance, for a Foo peripheral - please add them
217 // to a new dump function and include it in this table so it can be accessed from the
218 // command line, e.g.:
219 // dumpsys android.hardware.dumpstate.IDumpstateDevice/default foo
220 //
221 // However, if your addition generates attachments and/or binary data for the
222 // bugreport (i.e. if it requires two file descriptors to execute), it must not be
223 // added to this table and should instead be added to dumpstateBoard() below.
224
Dumpstate()225 Dumpstate::Dumpstate()
226 : mTextSections{
227 { "wlan", [this](int fd) { dumpWlanSection(fd); } },
228 { "modem", [this](int fd) { dumpModemSection(fd); } },
229 { "soc", [this](int fd) { dumpSocSection(fd); } },
230 { "storage", [this](int fd) { dumpStorageSection(fd); } },
231 { "memory", [this](int fd) { dumpMemorySection(fd); } },
232 { "Devfreq", [this](int fd) { dumpDevfreqSection(fd); } },
233 { "cpu", [this](int fd) { dumpCpuSection(fd); } },
234 { "power", [this](int fd) { dumpPowerSection(fd); } },
235 { "thermal", [this](int fd) { dumpThermalSection(fd); } },
236 { "touch", [this](int fd) { dumpTouchSection(fd); } },
237 { "display", [this](int fd) { dumpDisplaySection(fd); } },
238 { "sensors-usf", [this](int fd) { dumpSensorsUSFSection(fd); } },
239 { "aoc", [this](int fd) { dumpAoCSection(fd); } },
240 { "ramdump", [this](int fd) { dumpRamdumpSection(fd); } },
241 { "misc", [this](int fd) { dumpMiscSection(fd); } },
242 { "gsc", [this](int fd) { dumpGscSection(fd); } },
243 { "trusty", [this](int fd) { dumpTrustySection(fd); } },
244 { "led", [this](int fd) { dumpLEDSection(fd); } },
245 { "pixel-trace", [this](int fd) { dumpPixelTraceSection(fd); } },
246 { "perf-metrics", [this](int fd) { dumpPerfMetricsSection(fd); } },
247 { "pcie", [this](int fd) { dumpPCIeSection(fd); } },
248 },
249 mLogSections{
__anon8291a9001602() 250 { "modem", [this](int fd, const std::string &destDir) { dumpModemLogs(fd, destDir); } },
__anon8291a9001702() 251 { "radio", [this](int fd, const std::string &destDir) { dumpRadioLogs(fd, destDir); } },
__anon8291a9001802() 252 { "camera", [this](int fd, const std::string &destDir) { dumpCameraLogs(fd, destDir); } },
__anon8291a9001902() 253 { "gps", [this](int fd, const std::string &destDir) { dumpGpsLogs(fd, destDir); } },
__anon8291a9001a02() 254 { "gxp", [this](int fd, const std::string &destDir) { dumpGxpLogs(fd, destDir); } },
255 } {
256 }
257
258 // Dump data requested by an argument to the "dump" interface, or help info
259 // if the specified section is not supported.
dumpTextSection(int fd,const std::string & sectionName)260 void Dumpstate::dumpTextSection(int fd, const std::string §ionName) {
261 bool dumpAll = (sectionName == kAllSections);
262
263 for (const auto §ion : mTextSections) {
264 if (dumpAll || sectionName == section.first) {
265 auto startTime = startSection(fd, section.first);
266 section.second(fd);
267 endSection(fd, section.first, startTime);
268
269 if (!dumpAll) {
270 return;
271 }
272 }
273 }
274
275 if (dumpAll) {
276 return;
277 }
278
279 // An unsupported section was requested on the command line
280 ::android::base::WriteStringToFd("Unrecognized text section: " + sectionName + "\n", fd);
281 ::android::base::WriteStringToFd("Try \"" + kAllSections + "\" or one of the following:", fd);
282 for (const auto §ion : mTextSections) {
283 ::android::base::WriteStringToFd(" " + section.first, fd);
284 }
285 ::android::base::WriteStringToFd("\nNote: sections with attachments (e.g. modem) are"
286 "not avalable from the command line.\n", fd);
287 }
288
289 // Dump items related to wlan
dumpWlanSection(int fd)290 void Dumpstate::dumpWlanSection(int fd) {
291 // Dump firmware symbol table for firmware log decryption
292 DumpFileToFd(fd, "WLAN FW Log Symbol Table", "/vendor/firmware/Data.msc");
293 RunCommandToFd(fd, "WLAN TWT Dump", {"/vendor/bin/sh", "-c",
294 "cat /sys/wlan_ptracker/twt/*"});
295 }
296
297 // Dump items related to power and battery
dumpPowerSection(int fd)298 void Dumpstate::dumpPowerSection(int fd) {
299 struct stat buffer;
300
301 RunCommandToFd(fd, "Power Stats Times", {"/vendor/bin/sh", "-c",
302 "echo -n \"Boot: \" && /vendor/bin/uptime -s && "
303 "echo -n \"Now: \" && date"});
304
305 RunCommandToFd(fd, "ACPM stats", {"/vendor/bin/sh", "-c",
306 "for f in /sys/devices/platform/acpm_stats/*_stats ; do "
307 "echo \"\\n\\n$f\" ; cat $f ; "
308 "done"});
309
310 DumpFileToFd(fd, "CPU PM stats", "/sys/devices/system/cpu/cpupm/cpupm/time_in_state");
311
312 DumpFileToFd(fd, "GENPD summary", "/d/pm_genpd/pm_genpd_summary");
313
314 DumpFileToFd(fd, "Power supply property battery", "/sys/class/power_supply/battery/uevent");
315 DumpFileToFd(fd, "Power supply property dc", "/sys/class/power_supply/dc/uevent");
316 DumpFileToFd(fd, "Power supply property gcpm", "/sys/class/power_supply/gcpm/uevent");
317 DumpFileToFd(fd, "Power supply property gcpm_pps", "/sys/class/power_supply/gcpm_pps/uevent");
318 DumpFileToFd(fd, "Power supply property main-charger", "/sys/class/power_supply/main-charger/uevent");
319 if (!stat("/sys/class/power_supply/pca9468-mains/uevent", &buffer)) {
320 DumpFileToFd(fd, "Power supply property pca9468-mains", "/sys/class/power_supply/pca9468-mains/uevent");
321 } else {
322 DumpFileToFd(fd, "Power supply property pca94xx-mains", "/sys/class/power_supply/pca94xx-mains/uevent");
323 }
324 DumpFileToFd(fd, "Power supply property tcpm", "/sys/class/power_supply/tcpm-source-psy-i2c-max77759tcpc/uevent");
325 DumpFileToFd(fd, "Power supply property usb", "/sys/class/power_supply/usb/uevent");
326 DumpFileToFd(fd, "Power supply property wireless", "/sys/class/power_supply/wireless/uevent");
327 if (!stat("/sys/class/power_supply/maxfg", &buffer)) {
328 DumpFileToFd(fd, "Power supply property maxfg", "/sys/class/power_supply/maxfg/uevent");
329 DumpFileToFd(fd, "m5_state", "/sys/class/power_supply/maxfg/m5_model_state");
330 DumpFileToFd(fd, "maxfg", "/dev/logbuffer_maxfg");
331 DumpFileToFd(fd, "maxfg", "/dev/logbuffer_maxfg_monitor");
332 } else {
333 DumpFileToFd(fd, "Power supply property maxfg_base", "/sys/class/power_supply/maxfg_base/uevent");
334 DumpFileToFd(fd, "Power supply property maxfg_secondary", "/sys/class/power_supply/maxfg_secondary/uevent");
335 DumpFileToFd(fd, "m5_state", "/sys/class/power_supply/maxfg_base/m5_model_state");
336 DumpFileToFd(fd, "maxfg_base", "/dev/logbuffer_maxfg_base");
337 DumpFileToFd(fd, "maxfg_secondary", "/dev/logbuffer_maxfg_secondary");
338 DumpFileToFd(fd, "maxfg_base", "/dev/logbuffer_maxfg_base_monitor");
339 DumpFileToFd(fd, "maxfg_secondary", "/dev/logbuffer_maxfg_secondary_monitor");
340 DumpFileToFd(fd, "google_dual_batt", "/dev/logbuffer_dual_batt");
341 }
342
343 if (!stat("/dev/maxfg_history", &buffer)) {
344 DumpFileToFd(fd, "Maxim FG History", "/dev/maxfg_history");
345 }
346
347 if (!stat("/sys/class/power_supply/dock", &buffer)) {
348 DumpFileToFd(fd, "Power supply property dock", "/sys/class/power_supply/dock/uevent");
349 }
350
351 if (!stat("/dev/logbuffer_tcpm", &buffer)) {
352 DumpFileToFd(fd, "Logbuffer TCPM", "/dev/logbuffer_tcpm");
353 } else if (!PropertiesHelper::IsUserBuild()) {
354 if (!stat("/sys/kernel/debug/tcpm", &buffer)) {
355 RunCommandToFd(fd, "TCPM logs", {"/vendor/bin/sh", "-c", "cat /sys/kernel/debug/tcpm/*"});
356 } else {
357 RunCommandToFd(fd, "TCPM logs", {"/vendor/bin/sh", "-c", "cat /sys/kernel/debug/usb/tcpm*"});
358 }
359 }
360
361 RunCommandToFd(fd, "TCPC", {"/vendor/bin/sh", "-c",
362 "for f in /sys/devices/platform/10d60000.hsi2c/i2c-*/i2c-max77759tcpc;"
363 "do echo \"registers:\"; cat $f/registers;"
364 "echo \"frs:\"; cat $f/frs;"
365 "echo \"auto_discharge:\"; cat $f/auto_discharge;"
366 "echo \"bc12_enabled:\"; cat $f/bc12_enabled;"
367 "echo \"cc_toggle_enable:\"; cat $f/cc_toggle_enable;"
368 "echo \"contaminant_detection:\"; cat $f/contaminant_detection;"
369 "echo \"contaminant_detection_status:\"; cat $f/contaminant_detection_status; done"});
370
371 DumpFileToFd(fd, "PD Engine", "/dev/logbuffer_usbpd");
372 DumpFileToFd(fd, "POGO Transport", "/dev/logbuffer_pogo_transport");
373 DumpFileToFd(fd, "PPS-google_cpm", "/dev/logbuffer_cpm");
374 DumpFileToFd(fd, "PPS-dc", "/dev/logbuffer_pca9468");
375
376 DumpFileToFd(fd, "Battery Health", "/sys/class/power_supply/battery/health_index_stats");
377 DumpFileToFd(fd, "BMS", "/dev/logbuffer_ssoc");
378 DumpFileToFd(fd, "TTF", "/dev/logbuffer_ttf");
379 DumpFileToFd(fd, "TTF details", "/sys/class/power_supply/battery/ttf_details");
380 DumpFileToFd(fd, "TTF stats", "/sys/class/power_supply/battery/ttf_stats");
381 DumpFileToFd(fd, "aacr_state", "/sys/class/power_supply/battery/aacr_state");
382 DumpFileToFd(fd, "maxq", "/dev/logbuffer_maxq");
383 DumpFileToFd(fd, "TEMP/DOCK-DEFEND", "/dev/logbuffer_bd");
384
385 RunCommandToFd(fd, "TRICKLE-DEFEND Config", {"/vendor/bin/sh", "-c",
386 " cd /sys/devices/platform/google,battery/power_supply/battery/;"
387 " for f in `ls bd_*` ; do echo \"$f: `cat $f`\" ; done"});
388
389 RunCommandToFd(fd, "DWELL-DEFEND Config", {"/vendor/bin/sh", "-c",
390 " cd /sys/devices/platform/google,charger/;"
391 " for f in `ls charge_s*` ; do echo \"$f: `cat $f`\" ; done"});
392
393 RunCommandToFd(fd, "TEMP-DEFEND Config", {"/vendor/bin/sh", "-c",
394 " cd /sys/devices/platform/google,charger/;"
395 " for f in `ls bd_*` ; do echo \"$f: `cat $f`\" ; done"});
396
397 if (!PropertiesHelper::IsUserBuild()) {
398 DumpFileToFd(fd, "DC_registers dump", "/sys/class/power_supply/pca94xx-mains/device/registers_dump");
399 DumpFileToFd(fd, "max77759_chg registers dump", "/d/max77759_chg/registers");
400 DumpFileToFd(fd, "max77729_pmic registers dump", "/d/max77729_pmic/registers");
401 DumpFileToFd(fd, "Charging table dump", "/d/google_battery/chg_raw_profile");
402
403 RunCommandToFd(fd, "fg_model", {"/vendor/bin/sh", "-c",
404 "for f in /d/maxfg* ; do "
405 "regs=`cat $f/fg_model`; echo $f: ;"
406 "echo \"$regs\"; done"});
407
408 RunCommandToFd(fd, "fg_alo_ver", {"/vendor/bin/sh", "-c",
409 "for f in /d/maxfg* ; do "
410 "regs=`cat $f/algo_ver`; echo $f: ;"
411 "echo \"$regs\"; done"});
412
413 RunCommandToFd(fd, "fg_model_ok", {"/vendor/bin/sh", "-c",
414 "for f in /d/maxfg* ; do "
415 "regs=`cat $f/model_ok`; echo $f: ;"
416 "echo \"$regs\"; done"});
417
418 /* FG Registers */
419 RunCommandToFd(fd, "fg registers", {"/vendor/bin/sh", "-c",
420 "for f in /d/maxfg* ; do "
421 "regs=`cat $f/registers`; echo $f: ;"
422 "echo \"$regs\"; done"});
423
424 RunCommandToFd(fd, "Maxim FG NV RAM", {"/vendor/bin/sh", "-c",
425 "for f in /d/maxfg* ; do "
426 "regs=`cat $f/nv_registers`; echo $f: ;"
427 "echo \"$regs\"; done"});
428 }
429
430 /* EEPROM State */
431 if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-4/4-0050/eeprom", &buffer)) {
432 RunCommandToFd(fd, "Battery EEPROM", {"/vendor/bin/sh", "-c", "xxd /sys/devices/platform/10970000.hsi2c/i2c-4/4-0050/eeprom"});
433 } else if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-5/5-0050/eeprom", &buffer)) {
434 RunCommandToFd(fd, "Battery EEPROM", {"/vendor/bin/sh", "-c", "xxd /sys/devices/platform/10970000.hsi2c/i2c-5/5-0050/eeprom"});
435 } else if (!stat("/sys/devices/platform/10da0000.hsi2c/i2c-5/5-0050/eeprom", &buffer)) {
436 RunCommandToFd(fd, "Battery EEPROM", {"/vendor/bin/sh", "-c", "xxd /sys/devices/platform/10da0000.hsi2c/i2c-5/5-0050/eeprom"});
437 } else if (!stat("/sys/devices/platform/10da0000.hsi2c/i2c-6/6-0050/eeprom", &buffer)) {
438 RunCommandToFd(fd, "Battery EEPROM", {"/vendor/bin/sh", "-c", "xxd /sys/devices/platform/10da0000.hsi2c/i2c-6/6-0050/eeprom"});
439 } else if (!stat("/sys/devices/platform/10da0000.hsi2c/i2c-7/7-0050/eeprom", &buffer)) {
440 RunCommandToFd(fd, "Battery EEPROM", {"/vendor/bin/sh", "-c", "xxd /sys/devices/platform/10da0000.hsi2c/i2c-7/7-0050/eeprom"});
441 }
442
443 DumpFileToFd(fd, "Charger Stats", "/sys/class/power_supply/battery/charge_details");
444 if (!PropertiesHelper::IsUserBuild()) {
445 RunCommandToFd(fd, "Google Charger", {"/vendor/bin/sh", "-c", "cd /sys/kernel/debug/google_charger/; "
446 "for f in `ls pps_*` ; do echo \"$f: `cat $f`\" ; done"});
447 RunCommandToFd(fd, "Google Battery", {"/vendor/bin/sh", "-c", "cd /sys/kernel/debug/google_battery/; "
448 "for f in `ls ssoc_*` ; do echo \"$f: `cat $f`\" ; done"});
449 }
450
451 DumpFileToFd(fd, "WLC logs", "/dev/logbuffer_wireless");
452 DumpFileToFd(fd, "WLC VER", "/sys/class/power_supply/wireless/device/version");
453 DumpFileToFd(fd, "WLC STATUS", "/sys/class/power_supply/wireless/device/status");
454 DumpFileToFd(fd, "WLC FW Version", "/sys/class/power_supply/wireless/device/fw_rev");
455 DumpFileToFd(fd, "RTX", "/dev/logbuffer_rtx");
456
457 if (!PropertiesHelper::IsUserBuild()) {
458 RunCommandToFd(fd, "gvotables", {"/vendor/bin/sh", "-c", "cat /sys/kernel/debug/gvotables/*/status"});
459 }
460 DumpFileToFd(fd, "Lastmeal", "/data/vendor/mitigation/lastmeal.txt");
461 DumpFileToFd(fd, "Thismeal", "/data/vendor/mitigation/thismeal.txt");
462 RunCommandToFd(fd, "Mitigation Stats", {"/vendor/bin/sh", "-c", "echo \"Source\\t\\tCount\\tSOC\\tTime\\tVoltage\"; "
463 "for f in `ls /sys/devices/virtual/pmic/mitigation/last_triggered_count/*` ; "
464 "do count=`cat $f`; "
465 "a=${f/\\/sys\\/devices\\/virtual\\/pmic\\/mitigation\\/last_triggered_count\\//}; "
466 "b=${f/last_triggered_count/last_triggered_capacity}; "
467 "c=${f/last_triggered_count/last_triggered_timestamp/}; "
468 "d=${f/last_triggered_count/last_triggered_voltage/}; "
469 "cnt=`cat $f`; "
470 "cap=`cat ${b/count/cap}`; "
471 "ti=`cat ${c/count/time}`; "
472 "volt=`cat ${d/count/volt}`; "
473 "echo \"${a/_count/} "
474 "\\t$cnt\\t$cap\\t$ti\\t$volt\" ; done"});
475 RunCommandToFd(fd, "Clock Divider Ratio", {"/vendor/bin/sh", "-c", "echo \"Source\\t\\tRatio\"; "
476 "for f in `ls /sys/devices/virtual/pmic/mitigation/clock_ratio/*` ; "
477 "do ratio=`cat $f`; "
478 "a=${f/\\/sys\\/devices\\/virtual\\/pmic\\/mitigation\\/clock_ratio\\//}; "
479 "echo \"${a/_ratio/} \\t$ratio\" ; done"});
480 RunCommandToFd(fd, "Clock Stats", {"/vendor/bin/sh", "-c", "echo \"Source\\t\\tStats\"; "
481 "for f in `ls /sys/devices/virtual/pmic/mitigation/clock_stats/*` ; "
482 "do stats=`cat $f`; "
483 "a=${f/\\/sys\\/devices\\/virtual\\/pmic\\/mitigation\\/clock_stats\\//}; "
484 "echo \"${a/_stats/} \\t$stats\" ; done"});
485 RunCommandToFd(fd, "Triggered Level", {"/vendor/bin/sh", "-c", "echo \"Source\\t\\tLevel\"; "
486 "for f in `ls /sys/devices/virtual/pmic/mitigation/triggered_lvl/*` ; "
487 "do lvl=`cat $f`; "
488 "a=${f/\\/sys\\/devices\\/virtual\\/pmic\\/mitigation\\/triggered_lvl\\//}; "
489 "echo \"${a/_lvl/} \\t$lvl\" ; done"});
490 RunCommandToFd(fd, "Instruction", {"/vendor/bin/sh", "-c",
491 "for f in `ls /sys/devices/virtual/pmic/mitigation/instruction/*` ; "
492 "do val=`cat $f` ; "
493 "a=${f/\\/sys\\/devices\\/virtual\\/pmic\\/mitigation\\/instruction\\//}; "
494 "echo \"$a=$val\" ; done"});
495
496 }
497
498 // Dump items related to thermal
dumpThermalSection(int fd)499 void Dumpstate::dumpThermalSection(int fd) {
500 RunCommandToFd(fd, "Temperatures", {"/vendor/bin/sh", "-c",
501 "for f in /sys/class/thermal/thermal* ; do "
502 "type=`cat $f/type` ; temp=`cat $f/temp` ; echo \"$type: $temp\" ; "
503 "done"});
504 RunCommandToFd(fd, "Cooling Device Current State", {"/vendor/bin/sh", "-c",
505 "for f in /sys/class/thermal/cooling* ; do "
506 "type=`cat $f/type` ; temp=`cat $f/cur_state` ; echo \"$type: $temp\" ; "
507 "done"});
508 RunCommandToFd(fd, "Cooling Device User Vote State", {"/vendor/bin/sh", "-c",
509 "for f in /sys/class/thermal/cooling* ; do "
510 "if [ ! -f $f/user_vote ]; then continue; fi; "
511 "type=`cat $f/type` ; temp=`cat $f/user_vote` ; echo \"$type: $temp\" ; "
512 "done"});
513 RunCommandToFd(fd, "Cooling Device Time in State", {"/vendor/bin/sh", "-c", "for f in /sys/class/thermal/cooling* ; "
514 "do type=`cat $f/type` ; temp=`cat $f/stats/time_in_state_ms` ; echo \"$type:\n$temp\" ; done"});
515 RunCommandToFd(fd, "Cooling Device Trans Table", {"/vendor/bin/sh", "-c", "for f in /sys/class/thermal/cooling* ; "
516 "do type=`cat $f/type` ; temp=`cat $f/stats/trans_table` ; echo \"$type:\n$temp\" ; done"});
517 RunCommandToFd(fd, "Cooling Device State2Power Table", {"/vendor/bin/sh", "-c",
518 "for f in /sys/class/thermal/cooling* ; do "
519 "if [ ! -f $f/state2power_table ]; then continue; fi; "
520 "type=`cat $f/type` ; state2power_table=`cat $f/state2power_table` ; echo \"$type: $state2power_table\" ; "
521 "done"});
522 DumpFileToFd(fd, "TMU state:", "/sys/module/gs_thermal/parameters/tmu_reg_dump_state");
523 DumpFileToFd(fd, "TMU current temperature:", "/sys/module/gs_thermal/parameters/tmu_reg_dump_current_temp");
524 DumpFileToFd(fd, "TMU_TOP rise thresholds:", "/sys/module/gs_thermal/parameters/tmu_top_reg_dump_rise_thres");
525 DumpFileToFd(fd, "TMU_TOP fall thresholds:", "/sys/module/gs_thermal/parameters/tmu_top_reg_dump_fall_thres");
526 DumpFileToFd(fd, "TMU_SUB rise thresholds:", "/sys/module/gs_thermal/parameters/tmu_sub_reg_dump_rise_thres");
527 DumpFileToFd(fd, "TMU_SUB fall thresholds:", "/sys/module/gs_thermal/parameters/tmu_sub_reg_dump_fall_thres");
528 DumpFileToFd(fd, "Temperature Residency Metrics:", "/sys/kernel/metrics/temp_residency/temp_residency_all/stats");
529 }
530
531 // Dump items related to touch
dumpTouchSection(int fd)532 void Dumpstate::dumpTouchSection(int fd) {
533 const char stm_cmd_path[4][50] = {"/sys/class/spi_master/spi11/spi11.0",
534 "/proc/fts/driver_test",
535 "/sys/class/spi_master/spi6/spi6.0",
536 "/proc/fts_ext/driver_test"};
537 const char fst2_cmd_path[2][50] = {"/sys/class/spi_master/spi0/spi0.0",
538 "/proc/fts/driver_test"};
539 const char lsi_spi_path[] = "/sys/devices/virtual/sec/tsp";
540 const char syna_cmd_path[] = "/sys/class/spi_master/spi0/spi0.0/synaptics_tcm.0/sysfs";
541 const char focaltech_cmd_path[] = "/proc/focaltech_touch";
542 const char gti0_cmd_path[] = "/sys/devices/virtual/goog_touch_interface/gti.0";
543 const char gti0_procfs_path[] = "/proc/goog_touch_interface/gti.0";
544 char cmd[256];
545
546 if (!access(focaltech_cmd_path, R_OK)) {
547 ::android::base::WriteStringToFd("\n<<<<<< FOCALTECH >>>>>>\n\n", fd);
548
549 // Enable: force touch active
550 snprintf(cmd, sizeof(cmd), "echo 21 > %s/force_active", focaltech_cmd_path);
551 RunCommandToFd(fd, "Enable Force Touch Active", {"/vendor/bin/sh", "-c", cmd});
552
553 // Touch Firmware Version
554 snprintf(cmd, sizeof(cmd), "%s/FW_Version", focaltech_cmd_path);
555 DumpFileToFd(fd, "Touch Firmware Version", cmd);
556
557 // Touch INT PIN Test
558 snprintf(cmd, sizeof(cmd), "%s/INT_PIN", focaltech_cmd_path);
559 DumpFileToFd(fd, "Touch INT PIN Test", cmd);
560
561 // Get Raw Data - Delta
562 snprintf(cmd, sizeof(cmd), "%s/selftest/Panel_Differ", focaltech_cmd_path);
563 DumpFileToFd(fd, "Get Raw Data - Panel_Differ", cmd);
564
565 // Get Raw Data - Raw
566 snprintf(cmd, sizeof(cmd), "%s/selftest/Rawdata", focaltech_cmd_path);
567 DumpFileToFd(fd, "Get Raw Data - Raw", cmd);
568
569 // Get Raw Data - Baseline
570 snprintf(cmd, sizeof(cmd), "%s/selftest/Baseline", focaltech_cmd_path);
571 DumpFileToFd(fd, "Get Raw Data - Baseline", cmd);
572
573 // Get Raw Data - Noise
574 snprintf(cmd, sizeof(cmd), "%s/selftest/Noise", focaltech_cmd_path);
575 DumpFileToFd(fd, "Get Raw Data - Noise", cmd);
576
577 // Get Raw Data - Uniformity
578 snprintf(cmd, sizeof(cmd), "%s/selftest/Rawdata_Uniformity", focaltech_cmd_path);
579 DumpFileToFd(fd, "Get Raw Data - Uniformity", cmd);
580
581 // Get Scap_CB
582 snprintf(cmd, sizeof(cmd), "%s/selftest/Scap_CB", focaltech_cmd_path);
583 DumpFileToFd(fd, "Get Scap_CB", cmd);
584
585 // Get Scap_CB - Raw
586 snprintf(cmd, sizeof(cmd), "%s/selftest/Scap_Rawdata", focaltech_cmd_path);
587 DumpFileToFd(fd, "Get Scap_Rawdata", cmd);
588
589 // Get Short Test
590 snprintf(cmd, sizeof(cmd), "%s/selftest/Short", focaltech_cmd_path);
591 DumpFileToFd(fd, "Get Short Test", cmd);
592
593 // Get HeatMap(ms,ss)
594 snprintf(cmd, sizeof(cmd), "%s/selftest/Strength", focaltech_cmd_path);
595 DumpFileToFd(fd, "Get HeatMap(ms,ss)", cmd);
596
597 // Disable: force touch active
598 snprintf(cmd, sizeof(cmd), "echo 20 > %s/force_active", focaltech_cmd_path);
599 RunCommandToFd(fd, "Disable Force Touch Active", {"/vendor/bin/sh", "-c", cmd});
600 }
601
602 if (!access(syna_cmd_path, R_OK)) {
603 ::android::base::WriteStringToFd("\n<<<<<< SYNA >>>>>>\n\n", fd);
604
605 // Enable: force touch active
606 snprintf(cmd, sizeof(cmd), "echo 21 > %s/force_active", syna_cmd_path);
607 RunCommandToFd(fd, "Enable Force Touch Active", {"/vendor/bin/sh", "-c", cmd});
608
609 // Touch Firmware Information
610 snprintf(cmd, sizeof(cmd), "%s/info", syna_cmd_path);
611 DumpFileToFd(fd, "Touch Firmware Information", cmd);
612
613 // Get Raw Data - Delta
614 snprintf(cmd, sizeof(cmd),
615 "echo 12 > %s/get_raw_data && cat %s/get_raw_data", syna_cmd_path, syna_cmd_path);
616 RunCommandToFd(fd, "Get Raw Data - Delta", {"/vendor/bin/sh", "-c", cmd});
617
618 // Get Raw Data - Raw
619 snprintf(cmd, sizeof(cmd),
620 "echo 13 > %s/get_raw_data && cat %s/get_raw_data", syna_cmd_path, syna_cmd_path);
621 RunCommandToFd(fd, "Get Raw Data - Raw", {"/vendor/bin/sh", "-c", cmd});
622
623 // Get Raw Data - Baseline
624 snprintf(cmd, sizeof(cmd),
625 "echo 14 > %s/get_raw_data && cat %s/get_raw_data", syna_cmd_path, syna_cmd_path);
626 RunCommandToFd(fd, "Get Raw Data - Baseline", {"/vendor/bin/sh", "-c", cmd});
627
628 // Disable: force touch active
629 snprintf(cmd, sizeof(cmd), "echo 20 > %s/force_active", syna_cmd_path);
630 RunCommandToFd(fd, "Disable Force Touch Active", {"/vendor/bin/sh", "-c", cmd});
631 }
632
633 for (int i = 0; i < 4; i += 2) { // ftm5
634 snprintf(cmd, sizeof(cmd), "%s", stm_cmd_path[i]);
635 if (access(cmd, R_OK))
636 continue;
637 ::android::base::WriteStringToFd("\n<<<<<< FTM5 >>>>>>\n\n", fd);
638
639 snprintf(cmd, sizeof(cmd), "%s", stm_cmd_path[i + 1]);
640 if (!access(cmd, R_OK)) {
641 snprintf(cmd, sizeof(cmd), "echo A0 01 01 > %s", stm_cmd_path[i + 1]);
642 RunCommandToFd(fd, "Force Set AP as Bus Owner with Bugreport Flag",
643 {"/vendor/bin/sh", "-c", cmd});
644 }
645
646 snprintf(cmd, sizeof(cmd), "%s/appid", stm_cmd_path[i]);
647 if (!access(cmd, R_OK)) {
648 // Touch firmware version
649 DumpFileToFd(fd, "STM touch firmware version", cmd);
650
651 // Touch controller status
652 snprintf(cmd, sizeof(cmd), "%s/status", stm_cmd_path[i]);
653 DumpFileToFd(fd, "STM touch status", cmd);
654
655 // Mutual raw data
656 snprintf(cmd, sizeof(cmd),
657 "echo 13 00 01 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
658 stm_cmd_path[i], stm_cmd_path[i]);
659 RunCommandToFd(fd, "Mutual Raw", {"/vendor/bin/sh", "-c", cmd});
660
661 // Mutual strength data
662 snprintf(cmd, sizeof(cmd),
663 "echo 17 01 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
664 stm_cmd_path[i], stm_cmd_path[i]);
665 RunCommandToFd(fd, "Mutual Strength", {"/vendor/bin/sh", "-c", cmd});
666
667 // Self raw data
668 snprintf(cmd, sizeof(cmd),
669 "echo 15 00 01 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
670 stm_cmd_path[i], stm_cmd_path[i]);
671 RunCommandToFd(fd, "Self Raw", {"/vendor/bin/sh", "-c", cmd});
672 }
673
674 snprintf(cmd, sizeof(cmd), "%s", stm_cmd_path[i + 1]);
675 if (!access(cmd, R_OK)) {
676 snprintf(cmd, sizeof(cmd), "echo 23 00 > %s && cat %s",
677 stm_cmd_path[i + 1], stm_cmd_path[i + 1]);
678 RunCommandToFd(fd, "Mutual Raw Data",
679 {"/vendor/bin/sh", "-c", cmd});
680
681 snprintf(cmd, sizeof(cmd), "echo 23 03 > %s && cat %s",
682 stm_cmd_path[i + 1], stm_cmd_path[i + 1]);
683 RunCommandToFd(fd, "Mutual Baseline Data",
684 {"/vendor/bin/sh", "-c", cmd});
685
686 snprintf(cmd, sizeof(cmd), "echo 23 02 > %s && cat %s",
687 stm_cmd_path[i + 1], stm_cmd_path[i + 1]);
688 RunCommandToFd(fd, "Mutual Strength Data",
689 {"/vendor/bin/sh", "-c", cmd});
690
691 snprintf(cmd, sizeof(cmd), "echo 24 00 > %s && cat %s",
692 stm_cmd_path[i + 1], stm_cmd_path[i + 1]);
693 RunCommandToFd(fd, "Self Raw Data",
694 {"/vendor/bin/sh", "-c", cmd});
695
696 snprintf(cmd, sizeof(cmd), "echo 24 03 > %s && cat %s",
697 stm_cmd_path[i + 1], stm_cmd_path[i + 1]);
698 RunCommandToFd(fd, "Self Baseline Data",
699 {"/vendor/bin/sh", "-c", cmd});
700
701 snprintf(cmd, sizeof(cmd), "echo 24 02 > %s && cat %s",
702 stm_cmd_path[i + 1], stm_cmd_path[i + 1]);
703 RunCommandToFd(fd, "Self Strength Data",
704 {"/vendor/bin/sh", "-c", cmd});
705
706 snprintf(cmd, sizeof(cmd), "echo 32 10 > %s && cat %s",
707 stm_cmd_path[i + 1], stm_cmd_path[i + 1]);
708 RunCommandToFd(fd, "Mutual Compensation",
709 {"/vendor/bin/sh", "-c", cmd});
710
711 snprintf(cmd, sizeof(cmd), "echo 32 11 > %s && cat %s",
712 stm_cmd_path[i + 1], stm_cmd_path[i + 1]);
713 RunCommandToFd(fd, "Mutual Low Power Compensation",
714 {"/vendor/bin/sh", "-c", cmd});
715
716 snprintf(cmd, sizeof(cmd), "echo 33 12 > %s && cat %s",
717 stm_cmd_path[i + 1], stm_cmd_path[i + 1]);
718 RunCommandToFd(fd, "Self Compensation",
719 {"/vendor/bin/sh", "-c", cmd});
720
721 snprintf(cmd, sizeof(cmd), "echo 34 > %s && cat %s",
722 stm_cmd_path[i + 1], stm_cmd_path[i + 1]);
723 RunCommandToFd(fd, "Golden Mutual Raw Data",
724 {"/vendor/bin/sh", "-c", cmd});
725
726 snprintf(cmd, sizeof(cmd), "echo 01 FA 20 00 00 24 80 > %s",
727 stm_cmd_path[i + 1]);
728 RunCommandToFd(fd, "Packaging Plant - HW reset",
729 {"/vendor/bin/sh", "-c", cmd});
730 snprintf(cmd, sizeof(cmd), "echo 01 FA 20 00 00 68 08 > %s",
731 stm_cmd_path[i + 1]);
732 RunCommandToFd(fd, "Packaging Plant - Hibernate Memory",
733 {"/vendor/bin/sh", "-c", cmd});
734 snprintf(cmd, sizeof(cmd),
735 "echo 02 FB 00 04 3F D8 00 10 01 > %s && cat %s",
736 stm_cmd_path[i + 1], stm_cmd_path[i + 1]);
737 RunCommandToFd(fd, "Packaging Plant - Read 16 bytes from Address 0x00041FD8",
738 {"/vendor/bin/sh", "-c", cmd});
739 }
740
741 snprintf(cmd, sizeof(cmd), "%s/stm_fts_cmd", stm_cmd_path[i]);
742 if (!access(cmd, R_OK)) {
743 // ITO raw data
744 snprintf(cmd, sizeof(cmd),
745 "echo 01 > %s/stm_fts_cmd && cat %s/stm_fts_cmd",
746 stm_cmd_path[i], stm_cmd_path[i]);
747 RunCommandToFd(fd, "ITO Raw", {"/vendor/bin/sh", "-c", cmd});
748 }
749
750 snprintf(cmd, sizeof(cmd), "%s", stm_cmd_path[i + 1]);
751 if (!access(cmd, R_OK)) {
752 snprintf(cmd, sizeof(cmd), "echo A0 00 01 > %s", stm_cmd_path[i + 1]);
753 RunCommandToFd(fd, "Restore Bus Owner",
754 {"/vendor/bin/sh", "-c", cmd});
755 }
756 }
757
758 for (int i = 0; i < 2; i += 2) { // fst2
759 snprintf(cmd, sizeof(cmd), "%s", fst2_cmd_path[i]);
760 if (!access(cmd, R_OK)) {
761 ::android::base::WriteStringToFd("\n<<<<<< FST2 >>>>>>\n\n", fd);
762
763 snprintf(cmd, sizeof(cmd), "%s", fst2_cmd_path[i + 1]);
764 if (!access(cmd, R_OK)) {
765 // Enable: force touch active
766 snprintf(cmd, sizeof(cmd), "echo 21 01 > %s", fst2_cmd_path[i + 1]);
767 RunCommandToFd(fd, "Force Set AP as Bus Owner with Bugreport Flag",
768 {"/vendor/bin/sh", "-c", cmd});
769
770 // Golden Mutual Raw Data
771 snprintf(cmd, sizeof(cmd), "echo 0B 00 23 40 > %s;"
772 "echo 02 B7 00 10 04 E0 01 > %s ; cat %s;"
773 "echo 02 B7 04 F0 04 E0 01 > %s ; cat %s;",
774 fst2_cmd_path[i + 1], fst2_cmd_path[i + 1], fst2_cmd_path[i + 1],
775 fst2_cmd_path[i + 1], fst2_cmd_path[i + 1]);
776 RunCommandToFd(fd, "Golden Mutual Raw Data", {"/vendor/bin/sh", "-c", cmd});
777
778 // Restore Bus Owner
779 snprintf(cmd, sizeof(cmd), "echo 21 00 > %s", fst2_cmd_path[i + 1]);
780 RunCommandToFd(fd, "Restore Bus Owner", {"/vendor/bin/sh", "-c", cmd});
781 }
782 }
783 }
784
785 if (!access(lsi_spi_path, R_OK)) {
786 ::android::base::WriteStringToFd("\n<<<<<< LSI >>>>>>\n\n", fd);
787
788 // Enable: force touch active
789 snprintf(cmd, sizeof(cmd),
790 "echo %s > %s/cmd && cat %s/cmd_result",
791 "force_touch_active,1",
792 lsi_spi_path, lsi_spi_path);
793 RunCommandToFd(fd, "Force Touch Active", {"/vendor/bin/sh", "-c", cmd});
794
795 // Firmware info
796 snprintf(cmd, sizeof(cmd), "%s/fw_version", lsi_spi_path);
797 DumpFileToFd(fd, "LSI firmware version", cmd);
798
799 // Touch status
800 snprintf(cmd, sizeof(cmd), "%s/status", lsi_spi_path);
801 DumpFileToFd(fd, "LSI touch status", cmd);
802
803 // Calibration info
804 snprintf(cmd, sizeof(cmd),
805 "echo %s > %s/cmd && cat %s/cmd_result",
806 "get_mis_cal_info",
807 lsi_spi_path, lsi_spi_path);
808 RunCommandToFd(fd, "Calibration info", {"/vendor/bin/sh", "-c", cmd});
809
810 // Mutual strength
811 snprintf(cmd, sizeof(cmd),
812 "echo %s > %s/cmd && cat %s/cmd_result",
813 "run_delta_read_all",
814 lsi_spi_path, lsi_spi_path);
815 RunCommandToFd(fd, "Mutual Strength", {"/vendor/bin/sh", "-c", cmd});
816
817 // Self strength
818 snprintf(cmd, sizeof(cmd),
819 "echo %s > %s/cmd && cat %s/cmd_result",
820 "run_self_delta_read_all",
821 lsi_spi_path, lsi_spi_path);
822 RunCommandToFd(fd, "Self Strength", {"/vendor/bin/sh", "-c", cmd});
823
824 // Raw cap
825 snprintf(cmd, sizeof(cmd),
826 "echo %s > %s/cmd && cat %s/cmd_result",
827 "run_rawcap_read_all",
828 lsi_spi_path, lsi_spi_path);
829 RunCommandToFd(fd, "Mutual Raw Cap", {"/vendor/bin/sh", "-c", cmd});
830
831 // Self raw cap
832 snprintf(cmd, sizeof(cmd),
833 "echo %s > %s/cmd && cat %s/cmd_result",
834 "run_self_rawcap_read_all",
835 lsi_spi_path, lsi_spi_path);
836 RunCommandToFd(fd, "Self Raw Cap", {"/vendor/bin/sh", "-c", cmd});
837
838 // TYPE_AMBIENT_DATA
839 snprintf(cmd, sizeof(cmd),
840 "echo %s > %s/cmd && cat %s/cmd_result",
841 "run_rawdata_read_type,3",
842 lsi_spi_path, lsi_spi_path);
843 RunCommandToFd(fd, "TYPE_AMBIENT_DATA", {"/vendor/bin/sh", "-c", cmd});
844
845 // TYPE_DECODED_DATA
846 snprintf(cmd, sizeof(cmd),
847 "echo %s > %s/cmd && cat %s/cmd_result",
848 "run_rawdata_read_type,5",
849 lsi_spi_path, lsi_spi_path);
850 RunCommandToFd(fd, "TYPE_DECODED_DATA", {"/vendor/bin/sh", "-c", cmd});
851
852 // TYPE_NOI_P2P_MIN
853 snprintf(cmd, sizeof(cmd),
854 "echo %s > %s/cmd && cat %s/cmd_result",
855 "run_rawdata_read_type,30",
856 lsi_spi_path, lsi_spi_path);
857 RunCommandToFd(fd, "TYPE_NOI_P2P_MIN", {"/vendor/bin/sh", "-c", cmd});
858
859 // TYPE_NOI_P2P_MAX
860 snprintf(cmd, sizeof(cmd),
861 "echo %s > %s/cmd && cat %s/cmd_result",
862 "run_rawdata_read_type,31",
863 lsi_spi_path, lsi_spi_path);
864 RunCommandToFd(fd, "TYPE_NOI_P2P_MAX", {"/vendor/bin/sh", "-c", cmd});
865
866 // Disable: force touch active
867 snprintf(cmd, sizeof(cmd),
868 "echo %s > %s/cmd && cat %s/cmd_result",
869 "force_touch_active,0",
870 lsi_spi_path, lsi_spi_path);
871 RunCommandToFd(fd, "Force Touch Active", {"/vendor/bin/sh", "-c", cmd});
872 }
873
874 if (!access(gti0_cmd_path, R_OK)) {
875 const char *heatmap_path = gti0_cmd_path;
876
877 if (!access(gti0_procfs_path, R_OK))
878 heatmap_path = gti0_procfs_path;
879 ::android::base::WriteStringToFd("\n<<<<<< GTI0 >>>>>>\n\n", fd);
880
881 // Enable: force touch active
882 snprintf(cmd, sizeof(cmd), "echo 1 > %s/force_active", gti0_cmd_path);
883 RunCommandToFd(fd, "Force Touch Active", {"/vendor/bin/sh", "-c", cmd});
884
885 // Touch Firmware Version
886 snprintf(cmd, sizeof(cmd), "%s/fw_ver", gti0_cmd_path);
887 DumpFileToFd(fd, "Touch Firmware Version", cmd);
888
889 // Get Mutual Sensing Data - Baseline
890 snprintf(cmd, sizeof(cmd), "cat %s/ms_base", heatmap_path);
891 RunCommandToFd(fd, "Get Mutual Sensing Data - Baseline", {"/vendor/bin/sh", "-c", cmd});
892
893 // Get Mutual Sensing Data - Delta
894 snprintf(cmd, sizeof(cmd), "cat %s/ms_diff", heatmap_path);
895 RunCommandToFd(fd, "Get Mutual Sensing Data - Delta", {"/vendor/bin/sh", "-c", cmd});
896
897 // Get Mutual Sensing Data - Raw
898 snprintf(cmd, sizeof(cmd), "cat %s/ms_raw", heatmap_path);
899 RunCommandToFd(fd, "Get Mutual Sensing Data - Raw", {"/vendor/bin/sh", "-c", cmd});
900
901 // Get Self Sensing Data - Baseline
902 snprintf(cmd, sizeof(cmd), "cat %s/ss_base", heatmap_path);
903 RunCommandToFd(fd, "Get Self Sensing Data - Baseline", {"/vendor/bin/sh", "-c", cmd});
904
905 // Get Self Sensing Data - Delta
906 snprintf(cmd, sizeof(cmd), "cat %s/ss_diff", heatmap_path);
907 RunCommandToFd(fd, "Get Self Sensing Data - Delta", {"/vendor/bin/sh", "-c", cmd});
908
909 // Get Self Sensing Data - Raw
910 snprintf(cmd, sizeof(cmd), "cat %s/ss_raw", heatmap_path);
911 RunCommandToFd(fd, "Get Self Sensing Data - Raw", {"/vendor/bin/sh", "-c", cmd});
912
913 // Self Test
914 snprintf(cmd, sizeof(cmd), "cat %s/self_test", gti0_cmd_path);
915 RunCommandToFd(fd, "Self Test", {"/vendor/bin/sh", "-c", cmd});
916
917 // Disable: force touch active
918 snprintf(cmd, sizeof(cmd), "echo 0 > %s/force_active", gti0_cmd_path);
919 RunCommandToFd(fd, "Disable Force Touch Active", {"/vendor/bin/sh", "-c", cmd});
920 }
921 }
922
923 // Dump items related to SoC
dumpSocSection(int fd)924 void Dumpstate::dumpSocSection(int fd) {
925 DumpFileToFd(fd, "AP HW TUNE", "/sys/devices/system/chip-id/ap_hw_tune_str");
926 DumpFileToFd(fd, "EVT VERSION", "/sys/devices/system/chip-id/evt_ver");
927 DumpFileToFd(fd, "LOT ID", "/sys/devices/system/chip-id/lot_id");
928 DumpFileToFd(fd, "PRODUCT ID", "/sys/devices/system/chip-id/product_id");
929 DumpFileToFd(fd, "REVISION", "/sys/devices/system/chip-id/revision");
930 DumpFileToFd(fd, "RAW STR", "/sys/devices/system/chip-id/raw_str");
931 }
932
933 // Dump items related to CPUs
dumpCpuSection(int fd)934 void Dumpstate::dumpCpuSection(int fd) {
935 DumpFileToFd(fd, "CPU present", "/sys/devices/system/cpu/present");
936 DumpFileToFd(fd, "CPU online", "/sys/devices/system/cpu/online");
937 RunCommandToFd(fd, "CPU time-in-state", {"/vendor/bin/sh", "-c",
938 "for cpu in /sys/devices/system/cpu/cpu*; do "
939 "f=$cpu/cpufreq/stats/time_in_state; "
940 "if [ ! -f $f ]; then continue; fi; "
941 "echo $f:; cat $f; "
942 "done"});
943 RunCommandToFd(fd, "CPU cpuidle", {"/vendor/bin/sh", "-c",
944 "for cpu in /sys/devices/system/cpu/cpu*; do "
945 "for d in $cpu/cpuidle/state*; do "
946 "if [ ! -d $d ]; then continue; fi; "
947 "echo \"$d: `cat $d/name` `cat $d/desc` `cat $d/time` `cat $d/usage`\"; "
948 "done; "
949 "done"});
950 DumpFileToFd(fd, "INTERRUPTS", "/proc/interrupts");
951 }
952
953 // Dump items related to Devfreq & BTS
dumpDevfreqSection(int fd)954 void Dumpstate::dumpDevfreqSection(int fd) {
955 DumpFileToFd(fd, "MIF DVFS",
956 "/sys/devices/platform/17000010.devfreq_mif/devfreq/17000010.devfreq_mif/time_in_state");
957 DumpFileToFd(fd, "INT DVFS",
958 "/sys/devices/platform/17000020.devfreq_int/devfreq/17000020.devfreq_int/time_in_state");
959 DumpFileToFd(fd, "INTCAM DVFS",
960 "/sys/devices/platform/17000030.devfreq_intcam/devfreq/17000030.devfreq_intcam/time_in_state");
961 DumpFileToFd(fd, "DISP DVFS",
962 "/sys/devices/platform/17000040.devfreq_disp/devfreq/17000040.devfreq_disp/time_in_state");
963 DumpFileToFd(fd, "CAM DVFS",
964 "/sys/devices/platform/17000050.devfreq_cam/devfreq/17000050.devfreq_cam/time_in_state");
965 DumpFileToFd(fd, "TNR DVFS",
966 "/sys/devices/platform/17000060.devfreq_tnr/devfreq/17000060.devfreq_tnr/time_in_state");
967 DumpFileToFd(fd, "MFC DVFS",
968 "/sys/devices/platform/17000070.devfreq_mfc/devfreq/17000070.devfreq_mfc/time_in_state");
969 DumpFileToFd(fd, "BO DVFS",
970 "/sys/devices/platform/17000080.devfreq_bo/devfreq/17000080.devfreq_bo/time_in_state");
971 DumpFileToFd(fd, "BTS stats", "/sys/devices/platform/exynos-bts/bts_stats");
972 }
973
974 // Dump items related to memory
dumpMemorySection(int fd)975 void Dumpstate::dumpMemorySection(int fd) {
976 RunCommandToFd(fd, "ION HEAPS", {"/vendor/bin/sh", "-c",
977 "for d in $(ls -d /d/ion/*); do "
978 "if [ -f $d ]; then "
979 "echo --- $d; cat $d; "
980 "else "
981 "for f in $(ls $d); do "
982 "echo --- $d/$f; cat $d/$f; "
983 "done; "
984 "fi; "
985 "done"});
986 DumpFileToFd(fd, "dmabuf info", "/d/dma_buf/bufinfo");
987 DumpFileToFd(fd, "Page Pinner - longterm pin", "/sys/kernel/debug/page_pinner/buffer");
988 RunCommandToFd(fd, "CMA info", {"/vendor/bin/sh", "-c",
989 "for d in $(ls -d /d/cma/*); do "
990 "echo --- $d;"
991 "echo --- count; cat $d/count; "
992 "echo --- used; cat $d/used; "
993 "echo --- bitmap; cat $d/bitmap; "
994 "done"});
995 }
996
DumpF2FS(int fd)997 static void DumpF2FS(int fd) {
998 DumpFileToFd(fd, "F2FS", "/sys/kernel/debug/f2fs/status");
999 RunCommandToFd(fd, "F2FS - fsck time (ms)", {"/vendor/bin/sh", "-c", "getprop ro.boottime.init.fsck.data"});
1000 RunCommandToFd(fd, "F2FS - checkpoint=disable time (ms)", {"/vendor/bin/sh", "-c", "getprop ro.boottime.init.mount.data"});
1001 }
1002
DumpUFS(int fd)1003 static void DumpUFS(int fd) {
1004 DumpFileToFd(fd, "UFS model", "/sys/block/sda/device/model");
1005 DumpFileToFd(fd, "UFS rev", "/sys/block/sda/device/rev");
1006 DumpFileToFd(fd, "UFS size", "/sys/block/sda/size");
1007
1008 DumpFileToFd(fd, "UFS Slow IO Read", "/dev/sys/block/bootdevice/slowio_read_cnt");
1009 DumpFileToFd(fd, "UFS Slow IO Write", "/dev/sys/block/bootdevice/slowio_write_cnt");
1010 DumpFileToFd(fd, "UFS Slow IO Unmap", "/dev/sys/block/bootdevice/slowio_unmap_cnt");
1011 DumpFileToFd(fd, "UFS Slow IO Sync", "/dev/sys/block/bootdevice/slowio_sync_cnt");
1012
1013 RunCommandToFd(fd, "UFS err_stats", {"/vendor/bin/sh", "-c",
1014 "path=\"/dev/sys/block/bootdevice/err_stats\"; "
1015 "for node in `ls $path/* | grep -v reset_err_status`; do "
1016 "printf \"%s:%d\\n\" $(basename $node) $(cat $node); done;"});
1017
1018
1019 RunCommandToFd(fd, "UFS io_stats", {"/vendor/bin/sh", "-c",
1020 "path=\"/dev/sys/block/bootdevice/io_stats\"; "
1021 "printf \"\\t\\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
1022 "ReadCnt ReadBytes WriteCnt WriteBytes RWCnt RWBytes; "
1023 "str=$(cat $path/*_start); arr=($str); "
1024 "printf \"Started: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
1025 "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "
1026 "str=$(cat $path/*_complete); arr=($str); "
1027 "printf \"Completed: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
1028 "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "
1029 "str=$(cat $path/*_maxdiff); arr=($str); "
1030 "printf \"MaxDiff: \\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\\n\" "
1031 "${arr[1]} ${arr[0]} ${arr[5]} ${arr[4]} ${arr[3]} ${arr[2]}; "});
1032
1033 RunCommandToFd(fd, "UFS req_stats", {"/vendor/bin/sh", "-c",
1034 "path=\"/dev/sys/block/bootdevice/req_stats\"; "
1035 "printf \"\\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
1036 "All Write Read Security Flush Discard; "
1037 "str=$(cat $path/*_min); arr=($str); "
1038 "printf \"Min:\\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
1039 "${arr[0]} ${arr[5]} ${arr[3]} ${arr[4]} ${arr[2]} ${arr[1]}; "
1040 "str=$(cat $path/*_max); arr=($str); "
1041 "printf \"Max:\\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
1042 "${arr[0]} ${arr[5]} ${arr[3]} ${arr[4]} ${arr[2]} ${arr[1]}; "
1043 "str=$(cat $path/*_avg); arr=($str); "
1044 "printf \"Avg.:\\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\" "
1045 "${arr[0]} ${arr[5]} ${arr[3]} ${arr[4]} ${arr[2]} ${arr[1]}; "
1046 "str=$(cat $path/*_sum); arr=($str); "
1047 "printf \"Count:\\t%-10s %-10s %-10s %-10s %-10s %-10s\\n\\n\" "
1048 "${arr[0]} ${arr[5]} ${arr[3]} ${arr[4]} ${arr[2]} ${arr[1]};"});
1049
1050 std::string ufs_health = "for f in $(find /dev/sys/block/bootdevice/health_descriptor -type f); do if [[ -r $f && -f $f ]]; then echo --- $f; cat $f; echo ''; fi; done";
1051 RunCommandToFd(fd, "UFS health", {"/vendor/bin/sh", "-c", ufs_health.c_str()});
1052 }
1053
1054 // Dump items related to storage
dumpStorageSection(int fd)1055 void Dumpstate::dumpStorageSection(int fd) {
1056 DumpF2FS(fd);
1057 DumpUFS(fd);
1058 }
1059
1060 // Dump items related to display
dumpDisplaySection(int fd)1061 void Dumpstate::dumpDisplaySection(int fd) {
1062 // Dump counters for decon drivers
1063 const std::string decon_device_sysfs_path("/sys/class/drm/card0/device/");
1064 for(int i = 0; i <= 2; ++i){
1065 const std::string decon_num_str = std::to_string(i);
1066 const std::string decon_counter_path = decon_device_sysfs_path +
1067 "decon" + decon_num_str +
1068 "/counters";
1069 if (access(decon_counter_path.c_str(), R_OK) == 0){
1070 DumpFileToFd(fd, "DECON-" + decon_num_str + " counters",
1071 decon_counter_path);
1072 }
1073 else{
1074 ::android::base::WriteStringToFd("No counters for DECON-" +
1075 decon_num_str + " found at path (" + decon_counter_path + ")\n",
1076 fd);
1077 }
1078 }
1079 DumpFileToFd(fd, "CRTC-0 event log", "/sys/kernel/debug/dri/0/crtc-0/event");
1080 DumpFileToFd(fd, "CRTC-1 event log", "/sys/kernel/debug/dri/0/crtc-1/event");
1081 RunCommandToFd(fd, "libdisplaycolor", {"/vendor/bin/dumpsys", "displaycolor", "-v"},
1082 CommandOptions::WithTimeout(2).Build());
1083 DumpFileToFd(fd, "Primary panel name", "/sys/devices/platform/exynos-drm/primary-panel/panel_name");
1084 DumpFileToFd(fd, "Primary panel extra info", "/sys/devices/platform/exynos-drm/primary-panel/panel_extinfo");
1085 DumpFileToFd(fd, "Secondary panel name", "/sys/devices/platform/exynos-drm/secondary-panel/panel_name");
1086 DumpFileToFd(fd, "Secondary panel extra info", "/sys/devices/platform/exynos-drm/secondary-panel/panel_extinfo");
1087 }
1088
1089 // Dump items related to AoC
dumpAoCSection(int fd)1090 void Dumpstate::dumpAoCSection(int fd) {
1091 DumpFileToFd(fd, "AoC Service Status", "/sys/devices/platform/19000000.aoc/services");
1092 DumpFileToFd(fd, "AoC Restarts", "/sys/devices/platform/19000000.aoc/restart_count");
1093 DumpFileToFd(fd, "AoC Coredumps", "/sys/devices/platform/19000000.aoc/coredump_count");
1094 DumpFileToFd(fd, "AoC ring buf wake", "/sys/devices/platform/19000000.aoc/control/ring_buffer_wakeup");
1095 DumpFileToFd(fd, "AoC host ipc wake", "/sys/devices/platform/19000000.aoc/control/host_ipc_wakeup");
1096 DumpFileToFd(fd, "AoC usf wake", "/sys/devices/platform/19000000.aoc/control/usf_wakeup");
1097 DumpFileToFd(fd, "AoC audio wake", "/sys/devices/platform/19000000.aoc/control/audio_wakeup");
1098 DumpFileToFd(fd, "AoC logging wake", "/sys/devices/platform/19000000.aoc/control/logging_wakeup");
1099 DumpFileToFd(fd, "AoC hotword wake", "/sys/devices/platform/19000000.aoc/control/hotword_wakeup");
1100 RunCommandToFd(fd, "AoC memory exception wake",
1101 {"/vendor/bin/sh", "-c", "cat /sys/devices/platform/19000000.aoc/control/memory_exception"},
1102 CommandOptions::WithTimeout(2).Build());
1103 RunCommandToFd(fd, "AoC memory votes A32",
1104 {"/vendor/bin/sh", "-c", "cat /sys/devices/platform/19000000.aoc/control/memory_votes_a32"},
1105 CommandOptions::WithTimeout(2).Build());
1106 RunCommandToFd(fd, "AoC memory votes FF1",
1107 {"/vendor/bin/sh", "-c", "cat /sys/devices/platform/19000000.aoc/control/memory_votes_ff1"},
1108 CommandOptions::WithTimeout(2).Build());
1109 RunCommandToFd(fd, "AoC Heap Stats (A32)",
1110 {"/vendor/bin/sh", "-c", "echo 'dbg heap -c 1' > /dev/acd-debug; timeout 0.1 cat /dev/acd-debug"},
1111 CommandOptions::WithTimeout(1).Build());
1112 RunCommandToFd(fd, "AoC Heap Stats (F1)",
1113 {"/vendor/bin/sh", "-c", "echo 'dbg heap -c 2' > /dev/acd-debug; timeout 0.1 cat /dev/acd-debug"},
1114 CommandOptions::WithTimeout(1).Build());
1115 RunCommandToFd(fd, "AoC Heap Stats (HF0)",
1116 {"/vendor/bin/sh", "-c", "echo 'dbg heap -c 3' > /dev/acd-debug; timeout 0.1 cat /dev/acd-debug"},
1117 CommandOptions::WithTimeout(1).Build());
1118 RunCommandToFd(fd, "AoC Heap Stats (HF1)",
1119 {"/vendor/bin/sh", "-c", "echo 'dbg heap -c 4' > /dev/acd-debug; timeout 0.1 cat /dev/acd-debug"},
1120 CommandOptions::WithTimeout(1).Build());
1121 }
1122
1123 // Dump items related to sensors usf.
dumpSensorsUSFSection(int fd)1124 void Dumpstate::dumpSensorsUSFSection(int fd) {
1125 CommandOptions options = CommandOptions::WithTimeout(2).Build();
1126 RunCommandToFd(fd, "USF statistics",
1127 {"/vendor/bin/sh", "-c", "usf_stats get --all"},
1128 options);
1129 if (!PropertiesHelper::IsUserBuild()) {
1130 // Not a user build, if this is also not a production device dump the USF registry.
1131 std::string hwRev = ::android::base::GetProperty(HW_REVISION, "");
1132 if (hwRev.find("PROTO") != std::string::npos ||
1133 hwRev.find("EVT") != std::string::npos ||
1134 hwRev.find("DVT") != std::string::npos) {
1135 RunCommandToFd(fd, "USF Registry",
1136 {"/vendor/bin/sh", "-c", "usf_reg_edit save -"},
1137 options);
1138 RunCommandToFd(fd, "USF Last Stat Buffer",
1139 {"/vendor/bin/sh", "-c", "cat /data/vendor/sensors/debug/stats.history"},
1140 options);
1141 }
1142 }
1143 }
1144
1145 // Gzip binary data and dump to fd in base64 format. Cmd to decode is also attached.
dumpGzippedFileInBase64ToFd(int fd,const char * title,const char * file_path)1146 void dumpGzippedFileInBase64ToFd(int fd, const char* title, const char* file_path) {
1147 auto cmd = ::android::base::StringPrintf("echo 'base64 -d <<EOF | gunzip' ; "
1148 "/vendor/bin/gzip < \"%s\" | /vendor/bin/base64 ; "
1149 "echo 'EOF'", file_path);
1150 RunCommandToFd(fd, title,
1151 {"/vendor/bin/sh", "-c", cmd.c_str()},
1152 CommandOptions::WithTimeout(10).Build());
1153 }
1154
1155 struct abl_log_header {
1156 uint64_t i;
1157 uint64_t size;
1158 char buf[];
1159 } __attribute__((packed));
1160
1161 // Dump items related to ramdump.
dumpRamdumpSection(int fd)1162 void Dumpstate::dumpRamdumpSection(int fd) {
1163 std::string abl_log;
1164 if (::android::base::ReadFileToString("/mnt/vendor/ramdump/abl.log", &abl_log)) {
1165 const struct abl_log_header *header = (const struct abl_log_header*) abl_log.c_str();
1166 ::android::base::WriteStringToFd(::android::base::StringPrintf(
1167 "------ Ramdump misc file: abl.log (i:0x%" PRIx64 " size:0x%" PRIx64 ") ------\n%s\n",
1168 header->i, header->size, std::string(header->buf, header->i).c_str()), fd);
1169 } else {
1170 ::android::base::WriteStringToFd("*** Ramdump misc file: abl.log: File not found\n", fd);
1171 }
1172 dumpGzippedFileInBase64ToFd(
1173 fd, "Ramdump misc file: acpm.lst (gzipped in base64)", "/mnt/vendor/ramdump/acpm.lst");
1174 dumpGzippedFileInBase64ToFd(
1175 fd, "Ramdump misc file: s2d.lst (gzipped in base64)", "/mnt/vendor/ramdump/s2d.lst");
1176 }
1177
1178 // Dump items that don't fit well into any other section
dumpMiscSection(int fd)1179 void Dumpstate::dumpMiscSection(int fd) {
1180 RunCommandToFd(fd, "VENDOR PROPERTIES", {"/vendor/bin/getprop"});
1181 DumpFileToFd(fd, "VENDOR PROC DUMP", "/proc/vendor_sched/dump_task");
1182 }
1183
1184 // Dump items related to GSC
dumpGscSection(int fd)1185 void Dumpstate::dumpGscSection(int fd) {
1186 RunCommandToFd(fd, "Citadel VERSION", {"vendor/bin/hw/citadel_updater", "-lv"});
1187 RunCommandToFd(fd, "Citadel STATS", {"vendor/bin/hw/citadel_updater", "--stats"});
1188 RunCommandToFd(fd, "GSC DEBUG DUMP", {"vendor/bin/hw/citadel_updater", "-D"});
1189 }
1190
dumpTrustySection(int fd)1191 void Dumpstate::dumpTrustySection(int fd) {
1192 RunCommandToFd(fd, "Trusty TEE0 Logs", {"/vendor/bin/sh", "-c", "cat /dev/trusty-log0"}, CommandOptions::WithTimeout(1).Build());
1193 }
1194
1195 // Dump items related to LED
dumpLEDSection(int fd)1196 void Dumpstate::dumpLEDSection(int fd) {
1197 struct stat buffer;
1198
1199 if (!PropertiesHelper::IsUserBuild()) {
1200 if (!stat("/sys/class/leds/green", &buffer)) {
1201 DumpFileToFd(fd, "Green LED Brightness", "/sys/class/leds/green/brightness");
1202 DumpFileToFd(fd, "Green LED Max Brightness", "/sys/class/leds/green/max_brightness");
1203 }
1204 if (!stat("/mnt/vendor/persist/led/led_calibration_LUT.txt", &buffer)) {
1205 DumpFileToFd(fd, "LED Calibration Data", "/mnt/vendor/persist/led/led_calibration_LUT.txt");
1206 }
1207 }
1208 }
1209
dumpPCIeSection(int fd)1210 void Dumpstate::dumpPCIeSection(int fd) {
1211 DumpFileToFd(fd, "PCIe0 Logs", "/dev/logbuffer_pcie0");
1212 DumpFileToFd(fd, "PCIe1 Logs", "/dev/logbuffer_pcie1");
1213 RunCommandToFd(fd, "PCIe Link Statistics", {"/vendor/bin/sh", "-c",
1214 "for f in ls /sys/devices/platform/14520000.pcie/link_stats/* "
1215 " /sys/devices/platform/11920000.pcie/link_stats/*; do "
1216 " echo \"$f: `cat $f`\"; done"});
1217 }
1218
dumpModemSection(int fd)1219 void Dumpstate::dumpModemSection(int fd) {
1220 DumpFileToFd(fd, "Modem Stat", "/data/vendor/modem_stat/debug.txt");
1221 RunCommandToFd(fd, "Modem SSR history", {"/vendor/bin/sh", "-c",
1222 "for f in $(ls /data/vendor/ssrdump/crashinfo_modem*); do "
1223 "echo $f ; cat $f ; done"},
1224 CommandOptions::WithTimeout(2).Build());
1225 RunCommandToFd(fd, "RFSD error log", {"/vendor/bin/sh", "-c",
1226 "for f in $(ls /data/vendor/log/rfsd/rfslog_*); do "
1227 "echo $f ; cat $f ; done"},
1228 CommandOptions::WithTimeout(2).Build());
1229 }
1230
dumpModemLogs(int fd,const std::string & destDir)1231 void Dumpstate::dumpModemLogs(int fd, const std::string &destDir) {
1232 std::string extendedLogDir = MODEM_EXTENDED_LOG_DIRECTORY;
1233 std::string modemLogHistoryDir = MODEM_LOG_HISTORY_DIRECTORY;
1234
1235 dumpLogs(fd, extendedLogDir, destDir, 20, EXTENDED_LOG_PREFIX);
1236 dumpLogs(fd, modemLogHistoryDir, destDir, 2, "Logging");
1237 dumpModemEFS(destDir);
1238 }
1239
dumpRadioLogs(int fd,const std::string & destDir)1240 void Dumpstate::dumpRadioLogs(int fd, const std::string &destDir) {
1241 std::string tcpdumpLogDir = TCPDUMP_LOG_DIRECTORY;
1242 bool tcpdumpEnabled = ::android::base::GetBoolProperty(TCPDUMP_PERSIST_PROPERTY, false);
1243
1244 if (tcpdumpEnabled) {
1245 dumpLogs(fd, tcpdumpLogDir, destDir, ::android::base::GetIntProperty(TCPDUMP_NUMBER_BUGREPORT, 5), TCPDUMP_LOG_PREFIX);
1246 }
1247 dumpRilLogs(fd, destDir);
1248 dumpNetmgrLogs(destDir);
1249 }
1250
dumpGpsLogs(int fd,const std::string & destDir)1251 void Dumpstate::dumpGpsLogs(int fd, const std::string &destDir) {
1252 bool gpsLogEnabled = ::android::base::GetBoolProperty(GPS_LOGGING_STATUS_PROPERTY, false);
1253 if (!gpsLogEnabled) {
1254 ALOGD("gps logging is not running\n");
1255 return;
1256 }
1257 const std::string gpsLogDir = GPS_LOG_DIRECTORY;
1258 const std::string gpsTmpLogDir = gpsLogDir + "/.tmp";
1259 const std::string gpsDestDir = destDir + "/gps";
1260
1261 int maxFileNum = ::android::base::GetIntProperty(GPS_LOG_NUMBER_PROPERTY, 20);
1262
1263 RunCommandToFd(fd, "MKDIR GPS LOG", {"/vendor/bin/mkdir", "-p", gpsDestDir.c_str()},
1264 CommandOptions::WithTimeout(2).Build());
1265
1266 dumpLogs(fd, gpsTmpLogDir, gpsDestDir, 1, GPS_LOG_PREFIX);
1267 dumpLogs(fd, gpsLogDir, gpsDestDir, 3, GPS_MCU_LOG_PREFIX);
1268 dumpLogs(fd, gpsLogDir, gpsDestDir, maxFileNum, GPS_LOG_PREFIX);
1269 }
1270
dumpCameraLogs(int fd,const std::string & destDir)1271 void Dumpstate::dumpCameraLogs(int fd, const std::string &destDir) {
1272 bool cameraLogsEnabled = ::android::base::GetBoolProperty(
1273 "vendor.camera.debug.camera_performance_analyzer.attach_to_bugreport", true);
1274 if (!cameraLogsEnabled) {
1275 return;
1276 }
1277
1278 static const std::string kCameraLogDir = "/data/vendor/camera/profiler";
1279 const std::string cameraDestDir = destDir + "/camera";
1280
1281 RunCommandToFd(fd, "MKDIR CAMERA LOG", {"/vendor/bin/mkdir", "-p", cameraDestDir.c_str()},
1282 CommandOptions::WithTimeout(2).Build());
1283 // Attach multiple latest sessions (in case the user is running concurrent
1284 // sessions or starts a new session after the one with performance issues).
1285 dumpLogs(fd, kCameraLogDir, cameraDestDir, 10, "session-ended-");
1286 dumpLogs(fd, kCameraLogDir, cameraDestDir, 5, "high-drop-rate-");
1287 dumpLogs(fd, kCameraLogDir, cameraDestDir, 5, "watchdog-");
1288 dumpLogs(fd, kCameraLogDir, cameraDestDir, 5, "camera-ended-");
1289 }
1290
dumpGxpLogs(int fd,const std::string & destDir)1291 void Dumpstate::dumpGxpLogs(int fd, const std::string &destDir) {
1292 bool gxpDumpEnabled = ::android::base::GetBoolProperty("vendor.gxp.attach_to_bugreport", false);
1293
1294 if (gxpDumpEnabled) {
1295 const int maxGxpDebugDumps = 8;
1296 const std::string gxpCoredumpOutputDir = destDir + "/gxp_ssrdump";
1297 const std::string gxpCoredumpInputDir = "/data/vendor/ssrdump";
1298
1299 RunCommandToFd(fd, "MKDIR GXP COREDUMP", {"/vendor/bin/mkdir", "-p", gxpCoredumpOutputDir}, CommandOptions::WithTimeout(2).Build());
1300
1301 // Copy GXP coredumps and crashinfo to the output directory.
1302 dumpLogs(fd, gxpCoredumpInputDir + "/coredump", gxpCoredumpOutputDir, maxGxpDebugDumps, "coredump_gxp_platform");
1303 dumpLogs(fd, gxpCoredumpInputDir, gxpCoredumpOutputDir, maxGxpDebugDumps, "crashinfo_gxp_platform");
1304 }
1305 }
1306
dumpLogSection(int fd,int fd_bin)1307 void Dumpstate::dumpLogSection(int fd, int fd_bin)
1308 {
1309 std::string logDir = MODEM_LOG_DIRECTORY;
1310 const std::string logCombined = logDir + "/combined_logs.tar";
1311 const std::string logAllDir = logDir + "/all_logs";
1312
1313 RunCommandToFd(fd, "MKDIR LOG", {"/vendor/bin/mkdir", "-p", logAllDir.c_str()}, CommandOptions::WithTimeout(2).Build());
1314
1315 static const std::string sectionName = "modem DM log";
1316 auto startTime = startSection(fd, sectionName);
1317 bool modemLogEnabled = ::android::base::GetBoolProperty(MODEM_LOGGING_PERSIST_PROPERTY, false);
1318 if (modemLogEnabled && ::android::base::GetProperty(MODEM_LOGGING_PATH_PROPERTY, "") == MODEM_LOG_DIRECTORY) {
1319 bool modemLogStarted = ::android::base::GetBoolProperty(MODEM_LOGGING_STATUS_PROPERTY, false);
1320 int maxFileNum = ::android::base::GetIntProperty(MODEM_LOGGING_NUMBER_BUGREPORT_PROPERTY, 100);
1321
1322 if (modemLogStarted) {
1323 ::android::base::SetProperty(MODEM_LOGGING_PROPERTY, "false");
1324 ALOGD("Stopping modem logging...\n");
1325 } else {
1326 ALOGD("modem logging is not running\n");
1327 }
1328
1329 for (int i = 0; i < 15; i++) {
1330 if (!::android::base::GetBoolProperty(MODEM_LOGGING_STATUS_PROPERTY, false)) {
1331 ALOGD("modem logging stopped\n");
1332 sleep(1);
1333 break;
1334 }
1335 sleep(1);
1336 }
1337
1338 dumpLogs(fd, logDir, logAllDir, maxFileNum, MODEM_LOG_PREFIX);
1339
1340 if (modemLogStarted) {
1341 ALOGD("Restarting modem logging...\n");
1342 ::android::base::SetProperty(MODEM_LOGGING_PROPERTY, "true");
1343 }
1344 }
1345 endSection(fd, sectionName, startTime);
1346
1347 // Dump all module logs
1348 if (!PropertiesHelper::IsUserBuild()) {
1349 for (const auto §ion : mLogSections) {
1350 auto startTime = startSection(fd, section.first);
1351 section.second(fd, logAllDir);
1352 endSection(fd, section.first, startTime);
1353 }
1354 }
1355
1356 RunCommandToFd(fd, "TAR LOG", {"/vendor/bin/tar", "cvf", logCombined.c_str(), "-C", logAllDir.c_str(), "."}, CommandOptions::WithTimeout(20).Build());
1357 RunCommandToFd(fd, "CHG PERM", {"/vendor/bin/chmod", "a+w", logCombined.c_str()}, CommandOptions::WithTimeout(2).Build());
1358
1359 std::vector<uint8_t> buffer(65536);
1360 ::android::base::unique_fd fdLog(TEMP_FAILURE_RETRY(open(logCombined.c_str(), O_RDONLY | O_CLOEXEC | O_NONBLOCK)));
1361
1362 if (fdLog >= 0) {
1363 while (1) {
1364 ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fdLog, buffer.data(), buffer.size()));
1365
1366 if (bytes_read == 0) {
1367 break;
1368 } else if (bytes_read < 0) {
1369 ALOGD("read(%s): %s\n", logCombined.c_str(), strerror(errno));
1370 break;
1371 }
1372
1373 ssize_t result = TEMP_FAILURE_RETRY(write(fd_bin, buffer.data(), bytes_read));
1374
1375 if (result != bytes_read) {
1376 ALOGD("Failed to write %ld bytes, actually written: %ld", bytes_read, result);
1377 break;
1378 }
1379 }
1380 }
1381
1382 RunCommandToFd(fd, "RM LOG DIR", { "/vendor/bin/rm", "-r", logAllDir.c_str()}, CommandOptions::WithTimeout(2).Build());
1383 RunCommandToFd(fd, "RM LOG", { "/vendor/bin/rm", logCombined.c_str()}, CommandOptions::WithTimeout(2).Build());
1384 }
1385
dumpPixelTraceSection(int fd)1386 void Dumpstate::dumpPixelTraceSection(int fd) {
1387 DumpFileToFd(fd, "Pixel trace", "/sys/kernel/tracing/instances/pixel/trace");
1388 }
1389
dumpPerfMetricsSection(int fd)1390 void Dumpstate::dumpPerfMetricsSection(int fd) {
1391 DumpFileToFd(fd, "Long running IRQ metrics", "/sys/kernel/metrics/irq/long_irq_metrics");
1392 DumpFileToFd(fd, "Resume latency metrics", "/sys/kernel/metrics/resume_latency/resume_latency_metrics");
1393 }
1394
dumpstateBoard(const std::vector<::ndk::ScopedFileDescriptor> & in_fds,IDumpstateDevice::DumpstateMode in_mode,int64_t in_timeoutMillis)1395 ndk::ScopedAStatus Dumpstate::dumpstateBoard(const std::vector<::ndk::ScopedFileDescriptor>& in_fds,
1396 IDumpstateDevice::DumpstateMode in_mode,
1397 int64_t in_timeoutMillis) {
1398 // Unused arguments.
1399 (void) in_timeoutMillis;
1400
1401 if (in_fds.size() < 1) {
1402 ALOGE("no FDs\n");
1403 return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
1404 "No file descriptor");
1405 }
1406
1407 int fd = in_fds[0].get();
1408 if (fd < 0) {
1409 ALOGE("invalid FD: %d\n", fd);
1410 return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
1411 "Invalid file descriptor");
1412 }
1413
1414 if (in_mode == IDumpstateDevice::DumpstateMode::WEAR) {
1415 // We aren't a Wear device.
1416 ALOGE("Unsupported mode: %d\n", in_mode);
1417 return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(ERROR_UNSUPPORTED_MODE,
1418 "Unsupported mode");
1419 } else if (in_mode < IDumpstateDevice::DumpstateMode::FULL || in_mode > IDumpstateDevice::DumpstateMode::PROTO) {
1420 ALOGE("Invalid mode: %d\n", in_mode);
1421 return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
1422 "Invalid mode");
1423 }
1424
1425 if (in_fds.size() < 2) {
1426 ALOGE("no FD for dumpstate_board binary\n");
1427 } else {
1428 int fd_bin = in_fds[1].get();
1429 dumpLogSection(fd, fd_bin);
1430 }
1431
1432 dumpTextSection(fd, kAllSections);
1433
1434 return ndk::ScopedAStatus::ok();
1435 }
1436
setVerboseLoggingEnabled(bool in_enable)1437 ndk::ScopedAStatus Dumpstate::setVerboseLoggingEnabled(bool in_enable) {
1438 ::android::base::SetProperty(kVerboseLoggingProperty, in_enable ? "true" : "false");
1439 return ndk::ScopedAStatus::ok();
1440 }
1441
getVerboseLoggingEnabled(bool * _aidl_return)1442 ndk::ScopedAStatus Dumpstate::getVerboseLoggingEnabled(bool* _aidl_return) {
1443 *_aidl_return = ::android::base::GetBoolProperty(kVerboseLoggingProperty, false);
1444 return ndk::ScopedAStatus::ok();
1445 }
1446
1447 // Since AIDLs that support the dump() interface are automatically invoked during
1448 // bugreport generation and we don't want to generate a second copy of the same
1449 // data that will go into dumpstate_board.txt, this function will only do
1450 // something if it is called with an option, e.g.
1451 // dumpsys android.hardware.dumpstate.IDumpstateDevice/default all
1452 //
1453 // Also, note that sections which generate attachments and/or binary data when
1454 // included in a bugreport are not available through the dump() interface.
dump(int fd,const char ** args,uint32_t numArgs)1455 binder_status_t Dumpstate::dump(int fd, const char** args, uint32_t numArgs) {
1456
1457 if (numArgs != 1) {
1458 return STATUS_OK;
1459 }
1460
1461 dumpTextSection(fd, static_cast<std::string>(args[0]));
1462
1463 fsync(fd);
1464 return STATUS_OK;
1465 }
1466
1467 } // namespace dumpstate
1468 } // namespace hardware
1469 } // namespace android
1470 } // namespace aidl
1471