dumpstate: gs101: fix dump path

- Add missing change ag/25268925
- Correct FG reg dump path in sysfs
- Correct battery EEPROM dump path
- Correct main/dc charger dump path in sysfs
- Correct tcpm dump path
- Add charger dump path in debugfs
- Add swelling data dump in dumpBatteryHealth
- Remove function not for gs101

Bug: 376080915
Test: all paths were correctly dumped, but debugfs need sepolicy
Flag: EXEMPT bugfix
Change-Id: I398ef1554aa10a41c54290394e918478e2216cfe
Signed-off-by: Spade Lee <spadelee@google.com>
This commit is contained in:
Spade Lee 2024-10-29 16:07:29 +00:00
parent ecb4cc2682
commit 7bbc59eec1

View file

@ -44,9 +44,19 @@ int getCommandOutput(const char *cmd, std::string *output) {
return 0;
}
bool isValidFile(const char *file) {
if (!access(file, R_OK)) {
FILE *fp = fopen(file, "r");
if (fp != NULL) {
fclose(fp);
return true;
}
return false;
}
bool isValidDir(const char *directory) {
DIR *dir = opendir(directory);
if (dir == NULL)
return false;
closedir(dir);
return true;
}
bool isUserBuild() {
@ -123,8 +133,8 @@ void dumpPowerSupplyStats() {
{"Power supply property gcpm", "/sys/class/power_supply/gcpm/uevent"},
{"Power supply property gcpm_pps", "/sys/class/power_supply/gcpm_pps/uevent"},
{"Power supply property main-charger", "/sys/class/power_supply/main-charger/uevent"},
{"Power supply property dc-mains", "/sys/class/power_supply/dc-mains/uevent"},
{"Power supply property tcpm", "/sys/class/power_supply/tcpm-source-psy-8-0025/uevent"},
{"Power supply property pca9486-mains", "/sys/class/power_supply/pca9486-mains/uevent"},
{"Power supply property tcpm", "/sys/class/power_supply/tcpm-source-psy-i2c-max77759tcpc/uevent"},
{"Power supply property usb", "/sys/class/power_supply/usb/uevent"},
{"Power supply property wireless", "/sys/class/power_supply/wireless/uevent"},
};
@ -137,12 +147,15 @@ void dumpMaxFg() {
const char *maxfg [][2] = {
{"Power supply property maxfg", "/sys/class/power_supply/maxfg/uevent"},
{"m5_state", "/sys/class/power_supply/maxfg/m5_model_state"},
{"maxfg registers", "/sys/class/power_supply/maxfg/registers_dump"},
{"maxfg", "/dev/logbuffer_maxfg"},
{"maxfg", "/dev/logbuffer_maxfg_monitor"},
};
const char *maxfgFlip [][2] = {
{"Power supply property maxfg_base", "/sys/class/power_supply/maxfg_base/uevent"},
{"Power supply property maxfg_flip", "/sys/class/power_supply/maxfg_flip/uevent"},
{"maxfg_base registers", "/sys/class/power_supply/maxfg_base/registers_dump"},
{"maxfg_secondary registers", "/sys/class/power_supply/maxfg_secondary/registers_dump"},
{"m5_state", "/sys/class/power_supply/maxfg_base/m5_model_state"},
{"maxfg_base", "/dev/logbuffer_maxfg_base"},
{"maxfg_flip", "/dev/logbuffer_maxfg_flip"},
@ -152,7 +165,7 @@ void dumpMaxFg() {
const char *maxfgHistoryName = "Maxim FG History";
const char *maxfgHistoryDir = "/dev/maxfg_history";
std::string content;
if (isValidFile(maxfgLoc)) {
if (isValidDir(maxfgLoc)) {
for (const auto &row : maxfg) {
dumpFileContent(row[0], row[1]);
}
@ -231,19 +244,10 @@ void dumpPdEngine() {
dumpFileContent(row[0], row[1]);
}
}
void dumpWc68() {
const char* wc68Title = "WC68";
const char* wc68File = "/dev/logbuffer_wc68";
dumpFileContent(wc68Title, wc68File);
}
void dumpLn8411() {
const char* ln8411Title = "LN8411";
const char* ln8411File = "/dev/logbuffer_ln8411";
dumpFileContent(ln8411Title, ln8411File);
}
void dumpBatteryHealth() {
const char* batteryHealth [][2] {
{"Battery Health", "/sys/class/power_supply/battery/health_index_stats"},
{"Battery Health SoC Residency", "/sys/class/power_supply/battery/swelling_data"},
{"BMS", "/dev/logbuffer_ssoc"},
{"TTF", "/dev/logbuffer_ttf"},
{"TTF details", "/sys/class/power_supply/battery/ttf_details"},
@ -282,7 +286,7 @@ void dumpBatteryDefend() {
sort(files.begin(), files.end());
for (auto &file : files) {
fileLocation = std::string(config[1]) + std::string(file);
if (!android::base::ReadFileToString(fileLocation, &content)) {
if (!android::base::ReadFileToString(fileLocation, &content) || content.empty()) {
content = "\n";
}
printf("%s: %s", file.c_str(), content.c_str());
@ -292,15 +296,113 @@ void dumpBatteryDefend() {
files.clear();
}
}
void printValuesOfDirectory(const char *directory, std::string debugfs, const char *strMatch) {
std::vector<std::string> files;
auto info = directory;
std::string content;
struct dirent *entry;
DIR *dir = opendir(debugfs.c_str());
if (dir == NULL)
return;
printTitle((debugfs + std::string(strMatch) + "/" + std::string(info)).c_str());
while ((entry = readdir(dir)) != NULL)
if (std::string(entry->d_name).find(strMatch) != std::string::npos)
files.push_back(entry->d_name);
closedir(dir);
sort(files.begin(), files.end());
for (auto &file : files) {
std::string fileDirectory = debugfs + file;
std::string fileLocation = fileDirectory + "/" + std::string(info);
if (!android::base::ReadFileToString(fileLocation, &content)) {
content = "\n";
}
printf("%s:\n%s", fileDirectory.c_str(), content.c_str());
if (content.back() != '\n')
printf("\n");
}
files.clear();
}
void dumpChg() {
const std::string pmic_bus = "/sys/devices/platform/10cb0000.hsi2c/i2c-11/11-0066";
const char* chg_reg_dump_file = "/sys/class/power_supply/main-charger/device/registers_dump";
const std::string chg_name_cmd = "/sys/class/power_supply/main-charger/device/name";
const std::string pmic_name_cmd = pmic_bus + "/name";
const std::string pmic_reg_dump_file = pmic_bus + "/registers_dump";
const std::string reg_dump_str = " registers dump";
const char* chgConfig [][2] {
{"DC_registers dump", "/sys/class/power_supply/pca9468-mains/device/registers_dump"},
};
std::string chg_name;
std::string pmic_name;
printf("\n");
int ret = android::base::ReadFileToString(chg_name_cmd, &chg_name);
if (ret && !chg_name.empty()) {
chg_name.erase(chg_name.length() - 1); // remove new line
const std::string chg_reg_dump_title = chg_name + reg_dump_str;
/* CHG reg dump */
dumpFileContent(chg_reg_dump_title.c_str(), chg_reg_dump_file);
}
ret = android::base::ReadFileToString(pmic_name_cmd, &pmic_name);
if (ret && !pmic_name.empty()) {
pmic_name.erase(pmic_name.length() - 1); // remove new line
const std::string pmic_reg_dump_title = pmic_name + reg_dump_str;
/* PMIC reg dump */
dumpFileContent(pmic_reg_dump_title.c_str(), pmic_reg_dump_file.c_str());
}
for (auto &config : chgConfig) {
dumpFileContent(config[0], config[1]);
}
}
void dumpChgUserDebug() {
const std::string debugfs = "/d/";
const char *maxFgDir = "/d/maxfg";
const char *maxFgStrMatch = "maxfg";
const char *maxFg77779StrMatch = "max77779fg";
const char *chgTblName = "Charging table dump";
const char *chgTblDir = "/d/google_battery/chg_raw_profile";
const char *maxFgInfo [] {
"fg_model",
"algo_ver",
"model_ok",
};
const char *max77779FgInfo [] {
"fg_model",
"algo_ver",
"model_ok",
};
if (isUserBuild())
return;
dumpFileContent(chgTblName, chgTblDir);
if (isValidDir(maxFgDir)) {
for (auto & directory : maxFgInfo) {
printValuesOfDirectory(directory, debugfs, maxFgStrMatch);
}
} else {
for (auto & directory : max77779FgInfo) {
printValuesOfDirectory(directory, debugfs, maxFg77779StrMatch);
}
}
}
void dumpBatteryEeprom() {
const char *title = "Battery EEPROM";
const char *files[] {
"/sys/devices/platform/10970000.hsi2c/i2c-4/4-0050/eeprom",
"/sys/devices/platform/10970000.hsi2c/i2c-5/5-0050/eeprom",
"/sys/devices/platform/10da0000.hsi2c/i2c-6/6-0050/eeprom",
"/sys/devices/platform/10da0000.hsi2c/i2c-7/7-0050/eeprom",
"/sys/devices/platform/10c90000.hsi2c/i2c-7/7-0050/eeprom",
"/sys/devices/platform/10c90000.hsi2c/i2c-6/6-0050/eeprom",
"/sys/devices/platform/10970000.hsi2c/i2c-8/8-0050/eeprom",
};
std::string result;
std::string xxdCmd;
@ -326,7 +428,7 @@ void dumpChargerStats() {
std::string content;
struct dirent *entry;
dumpFileContent(chgStatsTitle, chgStatsLocation);
if (!isUserBuild())
if (isUserBuild())
return;
for (auto &stat : chargerStats) {
DIR *dir = opendir(stat[1]);
@ -371,7 +473,7 @@ void dumpGvoteables() {
std::string content;
std::vector<std::string> files;
int ret;
if (!isUserBuild())
if (isUserBuild())
return;
ret = getFilesInDir(directory, &files);
if (ret < 0)
@ -659,10 +761,10 @@ int main() {
dumpLogBufferTcpm();
dumpTcpc();
dumpPdEngine();
dumpWc68();
dumpLn8411();
dumpBatteryHealth();
dumpBatteryDefend();
dumpChg();
dumpChgUserDebug();
dumpBatteryEeprom();
dumpChargerStats();
dumpWlcLogs();