msl_verify: Initial commit

Create a new binary that checks the msl (minimum ship level)
of the PNOR and logs an error message if the version on the
system is older. The msl can be specified via a config flag.

Change-Id: I6f477400f7a8cf56557bd0caf5d6e08d73320028
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/msl_verify.hpp b/msl_verify.hpp
new file mode 100644
index 0000000..59f4017
--- /dev/null
+++ b/msl_verify.hpp
@@ -0,0 +1,77 @@
+#pragma once
+
+#include <string>
+
+namespace openpower
+{
+namespace software
+{
+namespace image
+{
+
+/** @class MinimumShipLevel
+ *  @brief Contains minimum ship level verification functions.
+ */
+class MinimumShipLevel
+{
+  public:
+    MinimumShipLevel() = delete;
+    MinimumShipLevel(const MinimumShipLevel&) = delete;
+    MinimumShipLevel& operator=(const MinimumShipLevel&) = delete;
+    MinimumShipLevel(MinimumShipLevel&&) = default;
+    MinimumShipLevel& operator=(MinimumShipLevel&&) = default;
+    ~MinimumShipLevel() = default;
+
+    /** @brief Constructs MinimumShipLevel.
+     *  @param[in] minShipLevel - Minimum Ship Level string
+     */
+    MinimumShipLevel(const std::string& minShipLevel) :
+        minShipLevel(minShipLevel){};
+
+    /** @brief Verify if the current PNOR version meets the min ship level
+     *  @return true if the verification succeeded, false otherwise
+     */
+    bool verify();
+
+    /** @brief Version components */
+    struct Version
+    {
+        uint8_t major;
+        uint8_t minor;
+        uint8_t rev;
+    };
+
+    /** @brief Get the functional PNOR version on the system
+     *  @details If the PNOR version file is not found, don't log an error since
+     *           all PNOR images may had been deleted. If there is an issue with
+     *           the VERSION partition, it should be caught by the host fw code.
+     *  @return The populated or empty version string
+     */
+    std::string getFunctionalVersion();
+
+    /** @brief Parse the version components into a struct
+     *  @details Version format follows a git tag convention: vX.Y[.Z]
+     *          Reference:
+     *          https://github.com/open-power/op-build/blob/master/openpower/package/VERSION.readme
+     * @param[in]  versionStr - The version string to be parsed
+     * @param[out] version    - The version struct to be populated
+     */
+    void parse(const std::string& versionStr, Version& version);
+
+    /** @brief Compare the versions provided
+     *  @param[in] a - The first version to compare
+     *  @param[in] b - The second version to compare
+     *  @return 1 if a > b
+     *          0 if a = b
+     *         -1 if a < b
+     */
+    int compare(const Version& a, const Version& b);
+
+  private:
+    /** Minimum Ship Level to compare against */
+    std::string minShipLevel;
+};
+
+} // namespace image
+} // namespace software
+} // namespace openpower