xref: /openbmc/openpower-pnor-code-mgmt/msl_verify.hpp (revision 4639e5508cff98afd452c636f95fa73e1d6bc3d0)
1 #pragma once
2 
3 #include <cstdint>
4 #include <string>
5 
6 namespace openpower
7 {
8 namespace software
9 {
10 namespace image
11 {
12 
13 /** @class MinimumShipLevel
14  *  @brief Contains minimum ship level verification functions.
15  */
16 class MinimumShipLevel
17 {
18   public:
19     MinimumShipLevel() = delete;
20     MinimumShipLevel(const MinimumShipLevel&) = delete;
21     MinimumShipLevel& operator=(const MinimumShipLevel&) = delete;
22     MinimumShipLevel(MinimumShipLevel&&) = default;
23     MinimumShipLevel& operator=(MinimumShipLevel&&) = default;
24     ~MinimumShipLevel() = default;
25 
26     /** @brief Constructs MinimumShipLevel.
27      *  @param[in] minShipLevel - Minimum Ship Level string
28      */
29     explicit MinimumShipLevel(const std::string& minShipLevel) :
30         minShipLevel(minShipLevel){};
31 
32     /** @brief Verify if the current PNOR version meets the min ship level
33      *  @return true if the verification succeeded, false otherwise
34      */
35     bool verify();
36 
37     /** @brief Version components */
38     struct Version
39     {
40         uint8_t major;
41         uint8_t minor;
42         uint8_t rev;
43     };
44 
45     /** @brief Get the functional PNOR version on the system
46      *  @details If the PNOR version file is not found, don't log an error since
47      *           all PNOR images may had been deleted. If there is an issue with
48      *           the VERSION partition, it should be caught by the host fw code.
49      *  @return The populated or empty version string
50      */
51     std::string getFunctionalVersion();
52 
53     /** @brief Parse the version components into a struct
54      *  @details Version format follows a git tag convention: vX.Y[.Z]
55      *          Reference:
56      *          https://github.com/open-power/op-build/blob/master/openpower/package/VERSION.readme
57      * @param[in]  versionStr - The version string to be parsed
58      * @param[out] version    - The version struct to be populated
59      */
60     void parse(const std::string& versionStr, Version& version);
61 
62     /** @brief Compare the versions provided
63      *  @param[in] a - The first version to compare
64      *  @param[in] b - The second version to compare
65      *  @return 1 if a > b
66      *          0 if a = b
67      *         -1 if a < b
68      */
69     int compare(const Version& a, const Version& b);
70 
71   private:
72     /** Minimum Ship Level to compare against */
73     std::string minShipLevel;
74 };
75 
76 } // namespace image
77 } // namespace software
78 } // namespace openpower
79