Alexander Hansen | cc37235 | 2025-01-14 14:15:39 +0100 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include "common/pldm/package_parser.hpp" |
| 4 | #include "software.hpp" |
| 5 | #include "software_config.hpp" |
| 6 | |
| 7 | #include <sdbusplus/async/context.hpp> |
| 8 | #include <xyz/openbmc_project/Association/Definitions/aserver.hpp> |
| 9 | #include <xyz/openbmc_project/Software/Activation/aserver.hpp> |
| 10 | #include <xyz/openbmc_project/Software/Update/aserver.hpp> |
| 11 | #include <xyz/openbmc_project/Software/Version/aserver.hpp> |
| 12 | |
| 13 | #include <string> |
| 14 | |
| 15 | using ActivationInterface = |
| 16 | sdbusplus::common::xyz::openbmc_project::software::Activation; |
| 17 | |
| 18 | namespace phosphor::software::manager |
| 19 | { |
| 20 | class SoftwareManager; |
| 21 | }; |
| 22 | |
| 23 | namespace phosphor::software::device |
| 24 | { |
| 25 | |
| 26 | class Device |
| 27 | { |
| 28 | public: |
| 29 | Device(sdbusplus::async::context& ctx, |
| 30 | const phosphor::software::config::SoftwareConfig& deviceConfig, |
| 31 | phosphor::software::manager::SoftwareManager* parent, |
| 32 | std::set<RequestedApplyTimes> allowedApplyTimes); |
| 33 | |
| 34 | virtual ~Device() = default; |
| 35 | Device(const Device&) = delete; |
| 36 | Device& operator=(const Device&) = delete; |
| 37 | Device(Device&&) = delete; |
| 38 | Device& operator=(Device&&) = delete; |
| 39 | |
| 40 | // @brief Applies the image to the device |
| 41 | // @param image raw fw image without pldm header |
| 42 | // @param image_size size of 'image' |
| 43 | // @returns true if update was applied successfully. |
| 44 | // Should also return true if update was applied |
| 45 | // successfully, but the host failed to power |
| 46 | // on. |
| 47 | virtual sdbusplus::async::task<bool> updateDevice(const uint8_t* image, |
| 48 | size_t image_size) = 0; |
| 49 | |
| 50 | // @brief Set the ActivationProgress properties on dbus |
| 51 | // @param progress progress value |
| 52 | // @returns true on successful property update |
| 53 | bool setUpdateProgress(uint8_t progress) const; |
| 54 | |
| 55 | // @brief This coroutine is spawned to perform the |
| 56 | // async update of the device. |
| 57 | // @param image The memory fd with the pldm package |
| 58 | // @param applyTime When the update should be applied |
| 59 | // @param swid The software id to use |
| 60 | // @returns true if update was successfull |
| 61 | sdbusplus::async::task<bool> startUpdateAsync( |
| 62 | sdbusplus::message::unix_fd image, RequestedApplyTimes applyTime, |
| 63 | std::unique_ptr<Software> softwareUpdateExternal); |
| 64 | |
| 65 | // Value of 'Type' field for the configuration in EM exposes record |
| 66 | std::string getEMConfigType() const; |
| 67 | |
| 68 | protected: |
| 69 | // The apply times for updates which are supported by the device |
| 70 | // Override this if your device deviates from the default set of apply |
| 71 | // times. |
| 72 | std::set<RequestedApplyTimes> allowedApplyTimes; |
| 73 | |
| 74 | // software instance, identified by its swid |
| 75 | // The specific derived class also owns its dbus interfaces, |
| 76 | // which are destroyed when the instance is deleted. |
| 77 | std::unique_ptr<Software> softwareCurrent; |
| 78 | |
| 79 | // In case of apply time == OnReset, this contains the software version |
| 80 | // which has been written to the device, or should be written to it, |
| 81 | // but is not active yet. |
| 82 | std::unique_ptr<Software> softwarePending; |
| 83 | |
| 84 | // Resets the device, in whichever way is appropriate for the device. |
| 85 | // The reset must be capable to apply the firmware update which was done |
| 86 | // by 'deviceSpecificUpdateFunction', in case that function did not already |
| 87 | // apply it. This method is optional to implement for that reason. |
| 88 | virtual sdbusplus::async::task<bool> resetDevice(); |
| 89 | |
| 90 | // The common configuration that all devices share. |
| 91 | // We get this from EM configuration. |
| 92 | config::SoftwareConfig config; |
| 93 | |
| 94 | manager::SoftwareManager* parent; |
| 95 | |
| 96 | sdbusplus::async::context& ctx; |
| 97 | |
| 98 | private: |
| 99 | bool updateInProgress = false; |
| 100 | |
| 101 | // @param componentImage component image as extracted from update pkg |
| 102 | // @param componentImageSize size of 'componentImage' |
| 103 | // @param applyTime when the update should be applied |
| 104 | // @param softwarePendingIn the pending software instance |
| 105 | // @returns the return value of the device specific |
| 106 | // update function |
| 107 | sdbusplus::async::task<bool> continueUpdateWithMappedPackage( |
| 108 | const uint8_t* componentImage, size_t componentImageSize, |
| 109 | const std::string& componentVersion, RequestedApplyTimes applyTime, |
| 110 | const std::unique_ptr<Software>& softwarePendingIn); |
| 111 | |
| 112 | // @brief extracts the information we need from the pldm package |
| 113 | // @returns true on success |
| 114 | sdbusplus::async::task<bool> getImageInfo( |
| 115 | std::unique_ptr<void, std::function<void(void*)>>& pldmPackage, |
| 116 | size_t pldmPackageSize, uint8_t** matchingComponentImage, |
| 117 | size_t* componentImageSize, std::string& componentVersion); |
| 118 | |
| 119 | friend update::SoftwareUpdate; |
| 120 | friend Software; |
| 121 | }; |
| 122 | |
| 123 | }; // namespace phosphor::software::device |