diff --git a/fboss/platform/platform_manager/PlatformExplorer.cpp b/fboss/platform/platform_manager/PlatformExplorer.cpp index d3ff2b74d02f0..ead835997d92b 100644 --- a/fboss/platform/platform_manager/PlatformExplorer.cpp +++ b/fboss/platform/platform_manager/PlatformExplorer.cpp @@ -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()); diff --git a/fboss/platform/platform_manager/tests/PlatformExplorerTest.cpp b/fboss/platform/platform_manager/tests/PlatformExplorerTest.cpp index 7f75572dd652d..5acd0db0e35b7 100644 --- a/fboss/platform/platform_manager/tests/PlatformExplorerTest.cpp +++ b/fboss/platform/platform_manager/tests/PlatformExplorerTest.cpp @@ -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] = ""; @@ -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(); @@ -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