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