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 ItemUpdaterUbi
13  *  @brief Manages the activation of the host version items for ubi layout
14  */
15 class ItemUpdaterUbi : public ItemUpdater
16 {
17   public:
18     ItemUpdaterUbi(sdbusplus::bus::bus& bus, const std::string& path) :
19         ItemUpdater(bus, path)
20     {
21         processPNORImage();
22         gardReset = std::make_unique<GardReset>(bus, GARD_PATH);
23         volatileEnable = std::make_unique<ObjectEnable>(bus, volatilePath);
24 
25         // Emit deferred signal.
26         emit_object_added();
27     }
28     virtual ~ItemUpdaterUbi() = default;
29 
30     void freePriority(uint8_t value, const std::string& versionId) override;
31 
32     void processPNORImage() override;
33 
34     bool erase(std::string entryId) override;
35 
36     void deleteAll() override;
37 
38     void freeSpace() override;
39 
40     bool isVersionFunctional(const std::string& versionId) override;
41 
42     /** @brief Determine the software version id
43      *         from the symlink target (e.g. /media/ro-2a1022fe).
44      *
45      * @param[in] symlinkPath - The path of the symlink.
46      * @param[out] id - The version id as a string.
47      */
48     static std::string determineId(const std::string& symlinkPath);
49 
50   private:
51     std::unique_ptr<Activation> createActivationObject(
52         const std::string& path, const std::string& versionId,
53         const std::string& extVersion,
54         sdbusplus::xyz::openbmc_project::Software::server::Activation::
55             Activations activationStatus,
56         AssociationList& assocs) override;
57 
58     std::unique_ptr<Version>
59         createVersionObject(const std::string& objPath,
60                             const std::string& versionId,
61                             const std::string& versionString,
62                             sdbusplus::xyz::openbmc_project::Software::server::
63                                 Version::VersionPurpose versionPurpose,
64                             const std::string& filePath) override;
65 
66     bool validateImage(const std::string& path) override;
67 
68     /** @brief Host factory reset - clears PNOR partitions for each
69      * Activation D-Bus object */
70     void reset() override;
71 
72     /**
73      * @brief Validates the presence of SquashFS image in the image dir.
74      *
75      * @param[in]  filePath - The path to the SquashFS image.
76      * @param[out] result    - 0 --> if validation was successful
77      *                       - -1--> Otherwise
78      */
79     static int validateSquashFSImage(const std::string& filePath);
80 
81     /** @brief Clears read only PNOR partition for
82      *  given Activation D-Bus object
83      *
84      * @param[in]  versionId - The id of the ro partition to remove.
85      */
86     void removeReadOnlyPartition(std::string versionId);
87 
88     /** @brief Clears read write PNOR partition for
89      *  given Activation D-Bus object
90      *
91      *  @param[in]  versionId - The id of the rw partition to remove.
92      */
93     void removeReadWritePartition(std::string versionId);
94 
95     /** @brief Clears preserved PNOR partition */
96     void removePreservedPartition();
97 };
98 
99 } // namespace updater
100 } // namespace software
101 } // namespace openpower
102