1 #pragma once
2 
3 #include "item_updater.hpp"
4 
5 namespace openpower
6 {
7 namespace software
8 {
9 namespace updater
10 {
11 
12 class GardResetMMC : public GardReset
13 {
14   public:
15     using GardReset::GardReset;
16     virtual ~GardResetMMC() = default;
17 
18     /**
19      * @brief GARD factory reset - clears the PNOR GARD partition.
20      */
21     void reset() override;
22 
23   private:
24     /**
25      * @brief During host factory reset, host clears the guard records in the
26      * guard partition. BMC is not notified about host factory reset so
27      * it continues to disable the guarded items. Now modified to enable
28      * back CpuCore and DIMM items during factory reset.
29      */
30     void enableInventoryItems();
31 
32     /**
33      * @brief Helper function to set enable flag for all the subtree objects
34      * implementing the specified interface.
35      *
36      * @param[in] - service D-Bus service name
37      * @param[in] - intf find objects that implement this interface
38      * @param[in] - objPath find subtree objects from this object path
39      * @return none
40      */
41     void enableInventoryItemsHelper(const std::string& service,
42                                     const std::string& intf,
43                                     const std::string& objPath);
44 };
45 
46 /** @class ItemUpdaterMMC
47  *  @brief Manages the activation of the host version items for static layout
48  */
49 class ItemUpdaterMMC : public ItemUpdater
50 {
51   public:
52     ItemUpdaterMMC(sdbusplus::bus_t& bus, const std::string& path) :
53         ItemUpdater(bus, path)
54     {
55         processPNORImage();
56         gardReset = std::make_unique<GardResetMMC>(bus, GARD_PATH);
57         volatileEnable = std::make_unique<ObjectEnable>(bus, volatilePath);
58 
59         // Emit deferred signal.
60         emit_object_added();
61     }
62     virtual ~ItemUpdaterMMC() = default;
63 
64     void freePriority(uint8_t value, const std::string& versionId) override;
65 
66     void processPNORImage() override;
67 
68     void deleteAll() override;
69 
70     bool freeSpace() override;
71 
72     void updateFunctionalAssociation(const std::string& versionId) override;
73 
74     bool isVersionFunctional(const std::string& versionId) override;
75 
76   private:
77     /** @brief Create Activation object */
78     std::unique_ptr<Activation> createActivationObject(
79         const std::string& path, const std::string& versionId,
80         const std::string& extVersion,
81         sdbusplus::xyz::openbmc_project::Software::server::Activation::
82             Activations activationStatus,
83         AssociationList& assocs) override;
84 
85     /** @brief Create Version object */
86     std::unique_ptr<Version>
87         createVersionObject(const std::string& objPath,
88                             const std::string& versionId,
89                             const std::string& versionString,
90                             sdbusplus::xyz::openbmc_project::Software::server::
91                                 Version::VersionPurpose versionPurpose,
92                             const std::string& filePath) override;
93 
94     /** @brief Validate if image is valid or not */
95     bool validateImage(const std::string& path);
96 
97     /** @brief Host factory reset - clears PNOR partitions for each
98      * Activation D-Bus object */
99     void reset() override;
100 
101     /** @brief The functional version ID */
102     std::string functionalVersionId;
103 };
104 
105 } // namespace updater
106 } // namespace software
107 } // namespace openpower
108