Skip to content

Commit

Permalink
Fix hwmon+fw_ver handling when publishing firmware versions
Browse files Browse the repository at this point in the history
Summary: Previously missed a case where fw_ver is under hwmon directory. Simple fix to reorder logic and check for hwmon before checking for fw_ver.

Reviewed By: alandau

Differential Revision: D62774963

fbshipit-source-id: 8023d7308d9360f434ba84341232b07d6baaf689
  • Loading branch information
rationalis authored and facebook-github-bot committed Sep 16, 2024
1 parent 161341a commit 0d0821e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
28 changes: 14 additions & 14 deletions fboss/platform/platform_manager/PlatformExplorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,26 +699,26 @@ void PlatformExplorer::publishFirmwareVersions() {
const auto deviceName = linkPathParts.back();
std::string versionString;
int odsValue = 0;
std::string verDirPath = linkPath;
// Check for and handle hwmon case. e.g.
// /run/devmap/cplds/FAN0_CPLD/hwmon/hwmon20/
auto hwmonSubdirPath = std::filesystem::path(linkPath) / "hwmon";
if (platformFsUtils_->exists(hwmonSubdirPath)) {
for (const auto& entry : platformFsUtils_->ls(hwmonSubdirPath)) {
if (entry.is_directory() &&
entry.path().filename().string().starts_with("hwmon")) {
verDirPath = hwmonSubdirPath / entry.path().filename();
break;
}
}
}
// New-style fw_ver
auto fwVerFilePath = std::filesystem::path(linkPath) / "fw_ver";
auto fwVerFilePath = std::filesystem::path(verDirPath) / "fw_ver";
if (platformFsUtils_->exists(fwVerFilePath)) {
auto version = readVersionString(fwVerFilePath, platformFsUtils_.get());
versionString = version.first;
odsValue = version.second;
} else {
std::string verDirPath = linkPath;
// Check for and handle hwmon case. e.g.
// /run/devmap/cplds/FAN0_CPLD/hwmon/hwmon20/
auto hwmonSubdirPath = std::filesystem::path(linkPath) / "hwmon";
if (platformFsUtils_->exists(hwmonSubdirPath)) {
for (const auto& entry : platformFsUtils_->ls(hwmonSubdirPath)) {
if (entry.is_directory() &&
entry.path().filename().string().starts_with("hwmon")) {
verDirPath = hwmonSubdirPath / entry.path().filename();
break;
}
}
}
const auto version = readVersionNumber(
fmt::format("{}/{}_ver", verDirPath, deviceType),
platformFsUtils_.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ TEST(PlatformExplorerTest, PublishFirmwareVersions) {
std::string cpldBadFwVerPath = "/run/devmap/cplds/TEST_CPLD_BADFWVER";
EXPECT_TRUE(platformFsUtils->writeStringToFile(
"123.456.789 // comment", fmt::format("{}/fw_ver", cpldBadFwVerPath)));
// Case with fw_ver under hwmon
std::string cpldHwmonFwVerPath = "/run/devmap/cplds/FAN0_CPLD_FWVER";
EXPECT_TRUE(platformFsUtils->writeStringToFile(
"1.2.3", fmt::format("{}/hwmon/hwmon20/fw_ver", cpldHwmonFwVerPath)));

PlatformConfig platformConfig;
platformConfig.symbolicLinkToDevicePath()[fpgaPath] = "";
Expand All @@ -82,6 +86,7 @@ TEST(PlatformExplorerTest, PublishFirmwareVersions) {
platformConfig.symbolicLinkToDevicePath()[fpgaFwVerPath] = "";
platformConfig.symbolicLinkToDevicePath()[cpldFwVerPath] = "";
platformConfig.symbolicLinkToDevicePath()[cpldBadFwVerPath] = "";
platformConfig.symbolicLinkToDevicePath()[cpldHwmonFwVerPath] = "";

PlatformExplorer explorer(platformConfig, platformFsUtils);
explorer.publishFirmwareVersions();
Expand All @@ -95,6 +100,7 @@ TEST(PlatformExplorerTest, PublishFirmwareVersions) {
expectVersions("TEST_FPGA_FWVER", "1.2", 1'002'000);
expectVersions("TEST_CPLD_FWVER", "123.456.789", 123456789);
expectVersions("TEST_CPLD_BADFWVER", "ERROR_INVALID_STRING", 0);
expectVersions("FAN0_CPLD_FWVER", "1.2.3", 1'002'003);
}

} // namespace facebook::fboss::platform::platform_manager

0 comments on commit 0d0821e

Please sign in to comment.