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