i2c-vr: mps: extend MPS image parser to support multiple formats
Different MPS VR modules use varying image formats. This change
enhances the common MPS image parser to handle multiple image types,
improving its flexibility and reusability.
- Add support for 7-column ATE images without write/read command info.
- Add support for 8-column ATE images with write/read command info,
which specifying byte, word, block, or process call operations.
Tested successfully by updating Yosemite5 VRs.
Change-Id: I9b60634c3a051c30ab2f56b895c2ef8db047ad13
Signed-off-by: Kevin Tung <kevin.tung.openbmc@gmail.com>
diff --git a/i2c-vr/mps/mps.hpp b/i2c-vr/mps/mps.hpp
index 73361af..078cdf5 100644
--- a/i2c-vr/mps/mps.hpp
+++ b/i2c-vr/mps/mps.hpp
@@ -32,6 +32,23 @@
colCount,
};
+/**
+ * @brief Represents the format of an MPS configuration image.
+ *
+ * type0: 7-columns ATE image without write/read command information.
+ *
+ * type1: 8-columns ATE image that includes write/read command information,
+ * specifying byte, word, block, or process call operations.
+ *
+ * typeUnknown: Unknown or unsupported image format.
+ */
+enum class MPSImageType : uint8_t
+{
+ type0 = 0,
+ type1,
+ typeUnknown = 0xFF
+};
+
enum class MPSPage : uint8_t
{
page0 = 0,
@@ -68,6 +85,7 @@
class TokenizedLines
{
public:
+ TokenizedLines() = default;
TokenizedLines(const uint8_t* d, size_t s) :
data(reinterpret_cast<const char*>(d), s)
{}
@@ -177,9 +195,12 @@
class MPSImageParser
{
public:
- MPSImageParser(const uint8_t* image, size_t imageSize) :
- lineTokens(image, imageSize)
- {}
+ MPSImageParser() = default;
+ virtual ~MPSImageParser() = default;
+ MPSImageParser(const MPSImageParser&) = delete;
+ MPSImageParser& operator=(const MPSImageParser&) = delete;
+ MPSImageParser(MPSImageParser&&) = default;
+ MPSImageParser& operator=(MPSImageParser&&) = default;
template <typename>
inline static constexpr bool always_false = false;
@@ -236,16 +257,17 @@
static bool isValidDataTokens(const std::vector<std::string_view>& tokens);
/**
- * @brief Convert tokenized line into MPSData structure.
+ * @brief Parse image buffer into a list of MPSData entries.
*/
- MPSData extractData(const std::vector<std::string_view>& tokens);
-
- /**
- * @brief Collect all register data entries from the parsed image.
- */
- std::vector<MPSData> getRegistersData();
+ virtual std::vector<MPSData> parse(
+ const uint8_t* image, size_t imageSize,
+ MPSImageType imageType = MPSImageType::typeUnknown);
TokenizedLines lineTokens;
+
+ private:
+ MPSData extractType0Data(const std::vector<std::string_view>& tokens);
+ MPSData extractType1Data(const std::vector<std::string_view>& tokens);
};
/**
@@ -271,8 +293,9 @@
* @param imageSize Size of the image data
* @return async task returning true if parsing succeeds
*/
- sdbusplus::async::task<bool> parseImage(const uint8_t* image,
- size_t imageSize);
+ sdbusplus::async::task<bool> parseImage(
+ const uint8_t* image, size_t imageSize,
+ MPSImageType imageType = MPSImageType::typeUnknown);
/**
* @brief Group register data by page, optionally masked and shifted.
@@ -285,7 +308,7 @@
protected:
phosphor::i2c::I2C i2cInterface;
- std::unique_ptr<MPSImageParser> parser;
+ std::unique_ptr<MPSImageParser> parser = std::make_unique<MPSImageParser>();
std::unique_ptr<MPSConfig> configuration;
};