blob: 2bfcac72a17dae9d80ce4bd4c6c583d119930130 [file] [log] [blame]
Alexander Hansen0119cd72025-01-14 14:15:39 +01001#pragma once
2
3#include "common/pldm/package_parser.hpp"
4#include "device_config.hpp"
5#include "software.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
15using ActivationInterface =
16 sdbusplus::common::xyz::openbmc_project::software::Activation;
17
18class SoftwareManager;
19
20class Device
21{
22 public:
23 Device(sdbusplus::async::context& ctx, bool dryRun,
24 const DeviceConfig& deviceConfig, SoftwareManager* parent);
25
26 virtual ~Device() = default;
27 Device(const Device&) = delete;
28 Device& operator=(const Device&) = delete;
29 Device(Device&&) = delete;
30 Device& operator=(Device&&) = delete;
31
32 // we provide the pointer to the dbus interface so the device specific
33 // implementation can give percentage progress updates
34 // @param image raw fw image without pldm header
35 // @param image_size size of 'image'
36 // @param activationProgress dbus interface for progress reporting
37 // @returns true if update was applied successfully.
38 // Should also return true if update was applied
39 // successfully, but the host failed to power
40 // on.
41 virtual sdbusplus::async::task<bool> updateDevice(
42 const uint8_t* image, size_t image_size,
43 std::unique_ptr<SoftwareActivationProgress>& activationProgress) = 0;
44
45 // @returns the object path of the inventory item which
46 // can be associated with this device.
47 virtual sdbusplus::async::task<std::string>
48 getInventoryItemObjectPath() = 0;
49
50 // Returns the apply times for updates which are supported by the device
51 // Override this if your device deviates from the default set of apply
52 // times.
53 virtual std::set<RequestedApplyTimes> allowedApplyTimes();
54
55 // @param image the memory fd with the pldm package
56 // @param applyTime when the update should be applied
57 // @param swid the software id to use
58 // @returns true if update was successfull
59 sdbusplus::async::task<bool> startUpdateAsync(
60 sdbusplus::message::unix_fd image, RequestedApplyTimes applyTime,
61 std::unique_ptr<Software> softwareUpdate);
62
63 // Value of 'Type' field for the configuration in EM exposes record
64 std::string getEMConfigType() const;
65
66 // software instance, identified by its swid
67 // The specific derived class also owns its dbus interfaces,
68 // which are destroyed when the instance is deleted.
69 std::unique_ptr<Software> softwareCurrent;
70
71 protected:
72 // Resets the device, in whichever way is appropriate for the device.
73 // The reset must be capable to apply the firmware update which was done
74 // by 'deviceSpecificUpdateFunction', in case that function did not already
75 // apply it. This method is optional to implement for that reason.
76 virtual void resetDevice();
77
78 // The common configuration that all devices share.
79 // We get this from EM configuration.
80 DeviceConfig config;
81
82 SoftwareManager* parent;
83 bool dryRun;
84
85 sdbusplus::async::context& ctx;
86
87 private:
88 // @param pldm_pkg raw pldm package
89 // @param pldm_pkg_size size of 'pldm_pkg'
90 // @param applyTime when the update should be applied
91 // @returns the return value of the device specific
92 // update function
93 sdbusplus::async::task<bool> continueUpdateWithMappedPackage(
94 void* pldm_pkg,
95 const std::shared_ptr<pldm::fw_update::PackageParser>& packageParser,
96 sdbusplus::common::xyz::openbmc_project::software::ApplyTime::
97 RequestedApplyTimes applyTime,
98 const std::unique_ptr<Software>& softwareUpdate);
99
100 friend SoftwareUpdate;
101 friend Software;
102};