cpld: lattice: to align with new EM Type scheme
Update CPLD Lattice code updater to align with new EM Type scheme
https://gerrit.openbmc.org/c/openbmc/entity-manager/+/81063
Tested on Harma MB cpld:
1. Check CPLD version
root@bmc:~# curl -u root:0penBmc -k -X GET
https://.../Harma_MB_CPLD_6845
{
"@odata.id": "/.../Harma_MB_CPLD_6845",
"@odata.type": "#SoftwareInventory.v1_1_0.SoftwareInventory",
"Description": "Unknown image",
"Id": "Harma_MB_CPLD_6845",
"Name": "Software Inventory",
"Status": {
"Health": "Warning",
"HealthRollup": "OK",
"State": "Disabled"
},
"Updateable": true,
"Version": "00000220"
}
2. Trigger update firmware
curl -k -H "X-Auth-Token: $token"
-H "Content-Type:multipart/form-data"
-X POST -F UpdateParameters="{
\"Targets\":[
\"/redfish/v1/UpdateService/FirmwareInventory/Harma_MB_CPLD_6845\"],
\"@Redfish.OperationApplyTime\":\"Immediate\"};type=application/json"
-F "UpdateFile=@mb_cpld_v224.pldm;type=application/octet-stream"
https://${bmc}/redfish/v1/UpdateService/update
{
"@odata.id": "/redfish/v1/TaskService/Tasks/0",
"@odata.type": "#Task.v1_4_3.Task",
"Id": "0",
"TaskState": "Running",
"TaskStatus": "OK"
}
root@bmc:~# curl -u root:0penBmc -k -X GET
https://localhost/redfish/v1/TaskService/Tasks/0
{
"@odata.id": "/redfish/v1/TaskService/Tasks/0",
"@odata.type": "#Task.v1_4_3.Task",
"EndTime": "2025-06-13T06:19:25+00:00",
"HidePayload": false,
"Id": "0",
"Messages": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The task with Id '0' has started.",
"MessageArgs": [
"0"
],
"MessageId": "TaskEvent.1.0.TaskStarted",
"MessageSeverity": "OK",
"Resolution": "None."
},
{
"@odata.type": "#Message.v1_1_1.Message",
"Message":
"The task with Id '0' has changed to progress 10 percent complete.",
"MessageArgs": [
"0",
"10"
],
"MessageId": "TaskEvent.1.0.TaskProgressChanged",
"MessageSeverity": "OK",
"Resolution": "None."
},
...
{
"@odata.type": "#Message.v1_1_1.Message",
"Message":
"The task with Id '0' has changed to progress 90 percent complete.",
"MessageArgs": [
"0",
"90"
],
"MessageId": "TaskEvent.1.0.TaskProgressChanged",
"MessageSeverity": "OK",
"Resolution": "None."
},
{
"@odata.type": "#Message.v1_1_1.Message",
"Message":
"The task with Id '0' has changed to progress 100 percent complete.",
"MessageArgs": [
"0",
"100"
],
"MessageId": "TaskEvent.1.0.TaskProgressChanged",
"MessageSeverity": "OK",
"Resolution": "None."
},
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The task with Id '0' has completed.",
"MessageArgs": [
"0"
],
"MessageId": "TaskEvent.1.0.TaskCompletedOK",
"MessageSeverity": "OK",
"Resolution": "None."
}
],
"Name": "Task 0",
"Payload": {
"HttpHeaders": [],
"HttpOperation": "POST",
"JsonBody": "null",
"TargetUri": "/redfish/v1/UpdateService/update"
},
"PercentComplete": 100,
"StartTime": "2025-06-13T06:19:13+00:00",
"TaskMonitor": "/redfish/v1/TaskService/TaskMonitors/0",
"TaskState": "Completed",
"TaskStatus": "OK"
}
3. Check version again after ac cycle
root@bmc:~# curl -u root:0penBmc -k -X GET
https://localhost/.../Harma_MB_CPLD_2181
{
"@odata.id": "/.../Harma_MB_CPLD_2181",
"@odata.type": "#SoftwareInventory.v1_1_0.SoftwareInventory",
"Description": "Unknown image",
"Id": "Harma_MB_CPLD_2181",
"Name": "Software Inventory",
"Status": {
"Health": "Warning",
"HealthRollup": "OK",
"State": "Disabled"
},
"Updateable": true,
"Version": "00000224"
}
Change-Id: I33b6f211a375a47a2139164347e697a2d0aba419
Signed-off-by: Daniel Hsu <Daniel-Hsu@quantatw.com>
diff --git a/cpld/README.md b/cpld/README.md
index db8af3d..3f97c0b 100644
--- a/cpld/README.md
+++ b/cpld/README.md
@@ -12,10 +12,10 @@
"Address": "0x40",
"Bus": 5,
"FirmwareInfo": {
- "CompatibleHardware": "com.meta.Hardware.CPLD",
+ "CompatibleHardware": "com.meta.Hardware.Harma.CPLD.LCMXO3LF_4300C_mb",
"VendorIANA": 40981
},
- "Name": "LCMXO3LF_4300C",
- "Type": "LatticeXO3Firmware"
+ "Name": "Harma_MB_CPLD",
+ "Type": "LatticeLCMXO3LF_4300CFirmware"
}
```
diff --git a/cpld/cpld_interface.cpp b/cpld/cpld_interface.cpp
index a67e03e..85d357c 100644
--- a/cpld/cpld_interface.cpp
+++ b/cpld/cpld_interface.cpp
@@ -11,16 +11,16 @@
return factory;
}
-void CPLDFactory::registerCPLD(const std::string& vendorName, Creator creator)
+void CPLDFactory::registerCPLD(const std::string& chipType, Creator creator)
{
- creators[vendorName] = std::move(creator);
+ creators[chipType] = std::move(creator);
}
std::unique_ptr<CPLDInterface> CPLDFactory::create(
- const std::string& vendorName, sdbusplus::async::context& ctx,
+ const std::string& chipType, sdbusplus::async::context& ctx,
const std::string& chipName, uint16_t bus, uint8_t address) const
{
- auto it = creators.find(vendorName);
+ auto it = creators.find(chipType);
if (it != creators.end())
{
return (it->second)(ctx, chipName, bus, address);
diff --git a/cpld/cpld_interface.hpp b/cpld/cpld_interface.hpp
index 6dec356..7f3f690 100644
--- a/cpld/cpld_interface.hpp
+++ b/cpld/cpld_interface.hpp
@@ -41,16 +41,16 @@
{
public:
using Creator = std::function<std::unique_ptr<CPLDInterface>(
- sdbusplus::async::context& ctx, const std::string& chipName,
+ sdbusplus::async::context& ctx, const std::string& chipType,
uint16_t bus, uint8_t address)>;
using ConfigProvider = std::function<std::vector<std::string>()>;
static CPLDFactory& instance();
- void registerCPLD(const std::string& vendorName, Creator creator);
+ void registerCPLD(const std::string& chipType, Creator creator);
std::unique_ptr<CPLDInterface> create(
- const std::string& vendorName, sdbusplus::async::context& ctx,
+ const std::string& chipType, sdbusplus::async::context& ctx,
const std::string& chipName, uint16_t bus, uint8_t address) const;
std::vector<std::string> getConfigs();
diff --git a/cpld/lattice/interface.cpp b/cpld/lattice/interface.cpp
index 21663f0..b2734ce 100644
--- a/cpld/lattice/interface.cpp
+++ b/cpld/lattice/interface.cpp
@@ -7,11 +7,6 @@
namespace phosphor::software::cpld
{
-const std::vector<std::string> supportedTypes = {
- "LatticeXO2Firmware",
- "LatticeXO3Firmware",
-};
-
sdbusplus::async::task<bool> LatticeCPLD::updateFirmware(
bool /*force*/, const uint8_t* image, size_t imageSize,
std::function<bool(int)> progressCallBack)
@@ -45,15 +40,16 @@
// Register all the CPLD type with the CPLD factory
const bool vendorRegistered = [] {
- for (const auto& type : supportedTypes)
+ for (const auto& [type, info] : supportedDeviceMap)
{
+ auto typeStr = std::string(type);
CPLDFactory::instance().registerCPLD(
- type,
- [](sdbusplus::async::context& ctx, const std::string& chipname,
- uint16_t bus, uint8_t address) {
+ type, [info](sdbusplus::async::context& ctx,
+ const std::string& /*chipName*/, uint16_t bus,
+ uint8_t address) {
// Create and return a LatticeCPLD instance
// Pass the parameters to the constructor
- return std::make_unique<LatticeCPLD>(ctx, chipname, bus,
+ return std::make_unique<LatticeCPLD>(ctx, info.chipName, bus,
address);
});
}
diff --git a/cpld/lattice/lattice.cpp b/cpld/lattice/lattice.cpp
index 48e2479..87ae2f0 100644
--- a/cpld/lattice/lattice.cpp
+++ b/cpld/lattice/lattice.cpp
@@ -49,14 +49,6 @@
return b;
}
-const std::map<std::string, std::vector<uint8_t>> xo2xo3DeviceIdMap = {
- {"LCMXO3LF-4300C", {0x61, 0x2b, 0xc0, 0x43}},
- {"LCMXO3LF-4300", {0x61, 0x2b, 0xc0, 0x43}},
- {"LCMXO3LF-6900", {0x61, 0x2b, 0xd0, 0x43}},
- {"LCMXO3D-4300", {0x01, 0x2e, 0x20, 0x43}},
- {"LCMXO3D-9400", {0x21, 0x2e, 0x30, 0x43}},
-};
-
static int findNumberSize(const std::string& end, const std::string& start,
const std::string& line)
{
@@ -150,7 +142,7 @@
}
else
{
- lg2::debug("STOP UPDATEING: The image not match with chip.");
+ lg2::debug("Abort update as image doesn't match the chip name");
return false;
}
}
@@ -351,10 +343,14 @@
co_return false;
}
- auto chipWantToUpdate = xo2xo3DeviceIdMap.find(chip);
+ auto chipWantToUpdate =
+ std::find_if(supportedDeviceMap.begin(), supportedDeviceMap.end(),
+ [this](const auto& pair) {
+ return pair.second.chipName == this->chip;
+ });
- if (chipWantToUpdate != xo2xo3DeviceIdMap.end() &&
- chipWantToUpdate->second == readData)
+ if (chipWantToUpdate != supportedDeviceMap.end() &&
+ chipWantToUpdate->second.deviceId == readData)
{
if (chip.rfind("LCMXO3D", 0) == 0)
{
@@ -371,12 +367,7 @@
co_return true;
}
- lg2::error(
- "The device id not match with chip. Only the following chip names are supported: ");
- for (const auto& chip : xo2xo3DeviceIdMap)
- {
- lg2::error(chip.first.c_str());
- }
+ lg2::error("The device id doesn't match with chip.");
co_return false;
}
@@ -828,12 +819,7 @@
sdbusplus::async::task<bool> CpldLatticeManager::updateFirmware(
std::function<bool(int)> progressCallBack)
{
- if (xo2xo3DeviceIdMap.find(chip) != xo2xo3DeviceIdMap.end())
- {
- co_return co_await XO2XO3FamilyUpdate(progressCallBack);
- }
- lg2::error("Unsupported chip type: {CHIP}", "CHIP", chip);
- co_return false;
+ co_return co_await XO2XO3FamilyUpdate(progressCallBack);
}
sdbusplus::async::task<bool> CpldLatticeManager::getVersion(
diff --git a/cpld/lattice/lattice.hpp b/cpld/lattice/lattice.hpp
index 0bdc2bb..b585eb8 100644
--- a/cpld/lattice/lattice.hpp
+++ b/cpld/lattice/lattice.hpp
@@ -6,6 +6,19 @@
#include <string_view>
#include <utility>
+struct cpldInfo
+{
+ std::string chipName;
+ std::vector<uint8_t> deviceId;
+};
+
+const std::map<std::string, cpldInfo> supportedDeviceMap = {
+ {"LatticeLCMXO3LF_2100CFirmware",
+ {"LCMXO3LF-2100C", {0x61, 0x2b, 0xb0, 0x43}}},
+ {"LatticeLCMXO3LF_4300CFirmware",
+ {"LCMXO3LF-4300C", {0x61, 0x2b, 0xc0, 0x43}}},
+};
+
struct cpldI2cInfo
{
unsigned long int QF; // Quantity of Fuses