i2c-vr: xdpe1x2xx: Improve update flow
Changes:
- Use strtoul instead of strtol to correctly handle large hex values
- Replace nested switch-case logic with std::map for better
readability and scalability
'''
Tested on harma:
<7> Found configuration interface at xyz.openbmc_project.EntityManager, /xyz/openbmc_project/inventory/system/board/Harma_MB/Harma_MB_VR_cpu0_vcore0
<7> [config] Voltage regulator device type: XDPE1X2XXFirmware on Bus: 28 at Address: 100
<7> Harma_MB_VR_cpu0_vcore0_610: created dbus interfaces on path /xyz/openbmc_project/software/Harma_MB_VR_cpu0_vcore0_610
<7> Harma_MB_VR_cpu0_vcore0_610: set version 1152932050
<7> [Software] enabling update of /xyz/openbmc_project/software/Harma_MB_VR_cpu0_vcore0_610 (adding the update interface)
<7> Done with initial configuration
<7> Requesting Image update with 11
<7> started asynchronous update with fd 11
<7> starting async update with FD: 12
<7> Harma_MB_VR_cpu0_vcore0_3294: created dbus interfaces on path /xyz/openbmc_project/software/Harma_MB_VR_cpu0_vcore0_3294
<7> starting the async update with memfd 12
<7> open fd 12
<7> file size: 4325
<7> parsing package header
<7> parsing package, pkg header size: 161
<7> Harma_MB_VR_cpu0_vcore0_3294: set version 4C366CF2
34Z 0x4C366CF2/XV0 Config
0000000sing: //XV0 PMBus LoopA User
50505055ing: //XV0 PMBus LoopB User
07> Parsing: //XV0 FW SVI3 LoopA
07> Parsing: //XV0 FW SVI3 LoopB
00000000ing: [End Configuration Data]
<7> Scratchpad Address: 0x2005e000
<7> CRC before programming: 0x44b858d2
<7> CRC of configuration: 0x4c366cf2
<7> VR Device ID: 0x96
<7> VR Device Rev: 0x1
<7> Remaining write cycles of VR: 19
<7> Invalidate current Configuration
<7> Programming section: 0
<7> Section Type: 0x4
<7> Invalidating section type: 4
<7> Setting scratchpad address: 0x2005e000
<7> Upload from scratch pad to OTP with soak time: 1600ms
<7> Programming section: 1
<7> Section Type: 0x7
<7> Invalidating section type: 7
<7> Setting scratchpad address: 0x2005e000
<7> Upload from scratch pad to OTP with soak time: 700ms
<7> Programming section: 2
<7> Section Type: 0x9
<7> Invalidating section type: 9
<7> Setting scratchpad address: 0x2005e000
<7> Upload from scratch pad to OTP with soak time: 700ms
<7> Programming section: 3
<7> Section Type: 0xd
<7> Invalidating section type: 13
<7> Setting scratchpad address: 0x2005e000
<7> Upload from scratch pad to OTP with soak time: 300ms
<7> Programming section: 4
<7> Section Type: 0xe
<7> Invalidating section type: 14
<7> Setting scratchpad address: 0x2005e000
<7> Upload from scratch pad to OTP with soak time: 300ms
<6> Successfully updated VR Harma_MB_VR_cpu0_vcore0
after ac-cycle:
<7> Found configuration interface at xyz.openbmc_project.EntityManager, /xyz/openbmc_project/inventory/system/board/Harma_MB/Harma_MB_VR_cpu0_vcore0
<7> [config] Voltage regulator device type: XDPE1X2XXFirmware on Bus: 28 at Address: 100
<7> Harma_MB_VR_cpu0_vcore0_8864: created dbus interfaces on path /xyz/openbmc_project/software/Harma_MB_VR_cpu0_vcore0_8864
<7> Harma_MB_VR_cpu0_vcore0_8864: set version 1278635250
<7> [Software] enabling update of /xyz/openbmc_project/software/Harma_MB_VR_cpu0_vcore0_8864 (adding the update interface)
'''
Change-Id: I8cfaa32318d35e68c3dc83416678c96623364b1b
Signed-off-by: Daniel Hsu <Daniel-Hsu@quantatw.com>
diff --git a/i2c-vr/xdpe1x2xx/xdpe1x2xx.cpp b/i2c-vr/xdpe1x2xx/xdpe1x2xx.cpp
index 25a4f26..51e0352 100644
--- a/i2c-vr/xdpe1x2xx/xdpe1x2xx.cpp
+++ b/i2c-vr/xdpe1x2xx/xdpe1x2xx.cpp
@@ -46,8 +46,9 @@
constexpr uint8_t MFRFwCmdOTPConfSTO = 0x11;
constexpr uint8_t MFRFwCmdOTPFileInvd = 0x12;
constexpr uint8_t MFRFwCmdGetCRC = 0x2D;
-constexpr int XDPE15284CConfSize = 1344;
-constexpr int XDPE19283BConfSize = 1416;
+constexpr int XDPE152XXConfSize = 1344;
+constexpr int XDPE152XXDConfSize = 1312;
+constexpr int XDPE192XXBConfSize = 1416; // Config(728) + PMBus(568) + SVID(120)
constexpr uint8_t VRWarnRemaining = 3;
constexpr uint8_t SectTrim = 0x02;
@@ -196,27 +197,24 @@
int XDPE1X2XX::getConfigSize(uint8_t deviceId, uint8_t revision)
{
- int size = -1;
+ static const std::map<std::pair<uint8_t, uint8_t>, int> configSizeMap = {
+ {{ProductIDXDPE19283AC, REV_B}, XDPE192XXBConfSize},
+ {{ProductIDXDPE15284, REV_A}, XDPE152XXConfSize},
+ {{ProductIDXDPE15284, REV_B}, XDPE152XXConfSize},
+ {{ProductIDXDPE15284, REV_C}, XDPE152XXConfSize},
+ {{ProductIDXDPE15284, REV_D}, XDPE152XXDConfSize},
+ {{ProductIDXDPE192C3AC, REV_B}, XDPE192XXBConfSize},
+ };
- switch (deviceId)
+ auto it = configSizeMap.find({deviceId, revision});
+ if (it != configSizeMap.end())
{
- case ProductIDXDPE19283AC:
- if (revision == REV_B)
- {
- size = XDPE19283BConfSize;
- }
- break;
- case ProductIDXDPE15284:
- size = XDPE15284CConfSize;
- break;
- default:
- error(
- "Failed to get configuration size of {DEVID} with revision {REV}",
- "DEVID", deviceId, "REV", revision);
- return -1;
+ return it->second;
}
- return size;
+ error("Failed to get configuration size of {DEVID} with revision {REV}",
+ "DEVID", deviceId, "REV", revision);
+ return -1;
}
sdbusplus::async::task<bool> XDPE1X2XX::getCRC(uint32_t* checksum)
@@ -521,7 +519,7 @@
for (int i = 1; i < tokenSize; i++)
{
- dWord = (uint32_t)strtol(tokenList[i], NULL, 16);
+ dWord = (uint32_t)strtoul(tokenList[i], NULL, 16);
if ((offset == 0x0) && (i == 1))
{
sectType = (uint8_t)dWord;