blob: 183daac553999dff11e3cb32dab157ddf0c6f24c [file] [log] [blame]
Lei YUf3ce4332019-02-21 14:09:49 +08001#pragma once
2
3#include "item_updater.hpp"
4
5namespace openpower
6{
7namespace software
8{
9namespace updater
10{
11
Lei YU716de5b2019-03-01 16:03:53 +080012class GardResetUbi : public GardReset
13{
14 public:
15 using GardReset::GardReset;
16 virtual ~GardResetUbi() = default;
17
18 protected:
19 /**
20 * @brief GARD factory reset - clears the PNOR GARD partition.
21 */
22 void reset() override;
23};
24
Lei YUf3ce4332019-02-21 14:09:49 +080025/** @class ItemUpdaterUbi
26 * @brief Manages the activation of the host version items for ubi layout
27 */
28class ItemUpdaterUbi : public ItemUpdater
29{
30 public:
31 ItemUpdaterUbi(sdbusplus::bus::bus& bus, const std::string& path) :
32 ItemUpdater(bus, path)
33 {
34 processPNORImage();
Lei YU716de5b2019-03-01 16:03:53 +080035 gardReset = std::make_unique<GardResetUbi>(bus, GARD_PATH);
Lei YUf3ce4332019-02-21 14:09:49 +080036 volatileEnable = std::make_unique<ObjectEnable>(bus, volatilePath);
37
38 // Emit deferred signal.
39 emit_object_added();
40 }
41 virtual ~ItemUpdaterUbi() = default;
42
43 void freePriority(uint8_t value, const std::string& versionId) override;
44
Lei YUf3ce4332019-02-21 14:09:49 +080045 void processPNORImage() override;
46
47 bool erase(std::string entryId) override;
48
49 void deleteAll() override;
50
Lei YU6da3dae2019-02-28 14:26:37 +080051 bool freeSpace() override;
Lei YUf3ce4332019-02-21 14:09:49 +080052
53 bool isVersionFunctional(const std::string& versionId) override;
54
Lei YUbee51402019-02-26 11:36:34 +080055 /** @brief Determine the software version id
56 * from the symlink target (e.g. /media/ro-2a1022fe).
57 *
58 * @param[in] symlinkPath - The path of the symlink.
59 * @param[out] id - The version id as a string.
60 */
61 static std::string determineId(const std::string& symlinkPath);
62
Lei YUf3ce4332019-02-21 14:09:49 +080063 private:
Lei YUa9ac9272019-02-22 16:38:35 +080064 std::unique_ptr<Activation> createActivationObject(
65 const std::string& path, const std::string& versionId,
66 const std::string& extVersion,
67 sdbusplus::xyz::openbmc_project::Software::server::Activation::
68 Activations activationStatus,
69 AssociationList& assocs) override;
70
71 std::unique_ptr<Version>
72 createVersionObject(const std::string& objPath,
73 const std::string& versionId,
74 const std::string& versionString,
75 sdbusplus::xyz::openbmc_project::Software::server::
76 Version::VersionPurpose versionPurpose,
77 const std::string& filePath) override;
78
79 bool validateImage(const std::string& path) override;
Lei YUf3ce4332019-02-21 14:09:49 +080080
81 /** @brief Host factory reset - clears PNOR partitions for each
82 * Activation D-Bus object */
83 void reset() override;
84
85 /**
86 * @brief Validates the presence of SquashFS image in the image dir.
87 *
88 * @param[in] filePath - The path to the SquashFS image.
89 * @param[out] result - 0 --> if validation was successful
90 * - -1--> Otherwise
91 */
92 static int validateSquashFSImage(const std::string& filePath);
93
94 /** @brief Clears read only PNOR partition for
95 * given Activation D-Bus object
96 *
97 * @param[in] versionId - The id of the ro partition to remove.
98 */
Lei YU1db9adf2019-03-05 16:02:31 +080099 void removeReadOnlyPartition(const std::string& versionId);
Lei YUf3ce4332019-02-21 14:09:49 +0800100
101 /** @brief Clears read write PNOR partition for
102 * given Activation D-Bus object
103 *
104 * @param[in] versionId - The id of the rw partition to remove.
105 */
Lei YU1db9adf2019-03-05 16:02:31 +0800106 void removeReadWritePartition(const std::string& versionId);
Lei YUf3ce4332019-02-21 14:09:49 +0800107
108 /** @brief Clears preserved PNOR partition */
109 void removePreservedPartition();
110};
111
112} // namespace updater
113} // namespace software
114} // namespace openpower