Daniel Hsu | f6470b5 | 2025-02-26 15:03:47 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | #include "common/include/i2c/i2c.hpp" |
| 3 | |
| 4 | #include <chrono> |
| 5 | #include <iostream> |
| 6 | #include <string_view> |
| 7 | #include <utility> |
| 8 | |
Daniel Hsu | 61e1267 | 2025-06-12 19:20:46 +0800 | [diff] [blame^] | 9 | struct cpldInfo |
| 10 | { |
| 11 | std::string chipName; |
| 12 | std::vector<uint8_t> deviceId; |
| 13 | }; |
| 14 | |
| 15 | const std::map<std::string, cpldInfo> supportedDeviceMap = { |
| 16 | {"LatticeLCMXO3LF_2100CFirmware", |
| 17 | {"LCMXO3LF-2100C", {0x61, 0x2b, 0xb0, 0x43}}}, |
| 18 | {"LatticeLCMXO3LF_4300CFirmware", |
| 19 | {"LCMXO3LF-4300C", {0x61, 0x2b, 0xc0, 0x43}}}, |
| 20 | }; |
| 21 | |
Daniel Hsu | f6470b5 | 2025-02-26 15:03:47 +0800 | [diff] [blame] | 22 | struct cpldI2cInfo |
| 23 | { |
| 24 | unsigned long int QF; // Quantity of Fuses |
| 25 | unsigned int* UFM; // User Flash Memory |
| 26 | unsigned int version; |
| 27 | unsigned int checksum; |
| 28 | std::vector<uint8_t> cfgData; |
| 29 | std::vector<uint8_t> ufmData; |
| 30 | }; |
| 31 | |
| 32 | class CpldLatticeManager |
| 33 | { |
| 34 | public: |
| 35 | CpldLatticeManager(sdbusplus::async::context& ctx, const uint16_t bus, |
| 36 | const uint8_t address, const uint8_t* image, |
| 37 | size_t imageSize, const std::string& chip, |
| 38 | const std::string& target, const bool debugMode) : |
| 39 | ctx(ctx), image(image), imageSize(imageSize), chip(chip), |
| 40 | target(target), debugMode(debugMode), |
| 41 | i2cInterface(phosphor::i2c::I2C(bus, address)) |
| 42 | {} |
| 43 | sdbusplus::async::task<bool> updateFirmware( |
| 44 | std::function<bool(int)> progressCallBack); |
| 45 | sdbusplus::async::task<bool> getVersion(std::string& version); |
| 46 | |
| 47 | private: |
| 48 | sdbusplus::async::context& ctx; |
| 49 | cpldI2cInfo fwInfo{}; |
| 50 | const uint8_t* image; |
| 51 | size_t imageSize; |
| 52 | std::string chip; |
| 53 | std::string target; |
| 54 | bool isLCMXO3D = false; |
| 55 | bool debugMode = false; |
| 56 | phosphor::i2c::I2C i2cInterface; |
| 57 | |
| 58 | sdbusplus::async::task<bool> XO2XO3FamilyUpdate( |
| 59 | std::function<bool(int)> progressCallBack); |
| 60 | |
| 61 | int indexof(const char* str, const char* ptn); |
| 62 | bool jedFileParser(); |
| 63 | bool verifyChecksum(); |
| 64 | sdbusplus::async::task<bool> readDeviceId(); |
| 65 | sdbusplus::async::task<bool> enableProgramMode(); |
| 66 | sdbusplus::async::task<bool> eraseFlash(); |
| 67 | sdbusplus::async::task<bool> resetConfigFlash(); |
| 68 | sdbusplus::async::task<bool> writeProgramPage(); |
| 69 | sdbusplus::async::task<bool> programUserCode(); |
| 70 | sdbusplus::async::task<bool> programDone(); |
| 71 | sdbusplus::async::task<bool> disableConfigInterface(); |
| 72 | sdbusplus::async::task<bool> readBusyFlag(uint8_t& busyFlag); |
| 73 | sdbusplus::async::task<bool> readStatusReg(uint8_t& statusReg); |
| 74 | sdbusplus::async::task<bool> waitBusyAndVerify(); |
| 75 | sdbusplus::async::task<bool> readUserCode(uint32_t& userCode); |
| 76 | }; |