Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "item_updater.hpp" |
| 4 | |
Andrew Geissler | ab139ce | 2020-05-16 13:22:09 -0500 | [diff] [blame] | 5 | #include <string> |
| 6 | |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 7 | namespace openpower |
| 8 | { |
| 9 | namespace software |
| 10 | { |
| 11 | namespace updater |
| 12 | { |
| 13 | |
Lei YU | 716de5b | 2019-03-01 16:03:53 +0800 | [diff] [blame] | 14 | class 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 YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 27 | /** @class ItemUpdaterUbi |
| 28 | * @brief Manages the activation of the host version items for ubi layout |
| 29 | */ |
| 30 | class ItemUpdaterUbi : public ItemUpdater |
| 31 | { |
| 32 | public: |
| 33 | ItemUpdaterUbi(sdbusplus::bus::bus& bus, const std::string& path) : |
| 34 | ItemUpdater(bus, path) |
| 35 | { |
| 36 | processPNORImage(); |
Lei YU | 716de5b | 2019-03-01 16:03:53 +0800 | [diff] [blame] | 37 | gardReset = std::make_unique<GardResetUbi>(bus, GARD_PATH); |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 38 | 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 YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 47 | void processPNORImage() override; |
| 48 | |
| 49 | bool erase(std::string entryId) override; |
| 50 | |
| 51 | void deleteAll() override; |
| 52 | |
Lei YU | 6da3dae | 2019-02-28 14:26:37 +0800 | [diff] [blame] | 53 | bool freeSpace() override; |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 54 | |
| 55 | bool isVersionFunctional(const std::string& versionId) override; |
| 56 | |
Lei YU | bee5140 | 2019-02-26 11:36:34 +0800 | [diff] [blame] | 57 | /** @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 YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 65 | private: |
Lei YU | a9ac927 | 2019-02-22 16:38:35 +0800 | [diff] [blame] | 66 | 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 YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 82 | |
| 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 YU | 1db9adf | 2019-03-05 16:02:31 +0800 | [diff] [blame] | 101 | void removeReadOnlyPartition(const std::string& versionId); |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 102 | |
| 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 YU | 1db9adf | 2019-03-05 16:02:31 +0800 | [diff] [blame] | 108 | void removeReadWritePartition(const std::string& versionId); |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 109 | |
| 110 | /** @brief Clears preserved PNOR partition */ |
| 111 | void removePreservedPartition(); |
| 112 | }; |
| 113 | |
| 114 | } // namespace updater |
| 115 | } // namespace software |
| 116 | } // namespace openpower |