blob: ddf6f6e9009737b867f6c88b740a3427c411579e [file] [log] [blame]
Alexander Hansen8d9e6da2025-01-14 14:17:19 +01001#include "nopdevice.hpp"
2
3#include "common/include/device.hpp"
4#include "common/include/device_config.hpp"
5#include "common/include/software_manager.hpp"
6
7#include <phosphor-logging/lg2.hpp>
8#include <sdbusplus/asio/connection.hpp>
9#include <sdbusplus/asio/object_server.hpp>
10#include <sdbusplus/async.hpp>
11#include <sdbusplus/server.hpp>
12#include <xyz/openbmc_project/Association/Definitions/server.hpp>
13#include <xyz/openbmc_project/Software/Update/server.hpp>
14
15#include <memory>
16
17static long getRandomId()
18{
19 struct timespec ts;
20 clock_gettime(CLOCK_REALTIME, &ts);
21 unsigned int seed = ts.tv_nsec ^ getpid();
22 srandom(seed);
23 return random() % 10000;
24}
25
26// nop code updater needs unique suffix on dbus for parallel unit testing
27NopCodeUpdater::NopCodeUpdater(sdbusplus::async::context& ctx) :
28 NopCodeUpdater(ctx, getRandomId())
29{}
30
31NopCodeUpdater::NopCodeUpdater(sdbusplus::async::context& ctx,
32 long uniqueSuffix) :
33 SoftwareManager(ctx, "Nop" + std::to_string(uniqueSuffix), true)
34{}
35
36// NOLINTBEGIN
37sdbusplus::async::task<> NopCodeUpdater::getInitialConfigurationSingleDevice(
38 const std::string& /*unused*/, const std::string& /*unused*/,
39 DeviceConfig& /*unused*/)
40// NOLINTEND
41{
42 co_return;
43}
44
45NopDevice::NopDevice(sdbusplus::async::context& ctx, const DeviceConfig& config,
46 SoftwareManager* parent) :
47 Device(ctx, true, config, parent)
48{}
49NopDevice::NopDevice(sdbusplus::async::context& ctx, SoftwareManager* parent) :
50 Device(ctx, true,
51 DeviceConfig(exampleVendorIANA, exampleCompatible, "Nop",
52 exampleName),
53 parent)
54{}
55
56// NOLINTBEGIN
57sdbusplus::async::task<bool> NopDevice::updateDevice(
58 const uint8_t* /*unused*/, size_t compImageSize,
59 std::unique_ptr<SoftwareActivationProgress>& activationProgress)
60// NOLINTEND
61{
62 lg2::debug(
63 "[nop device] called device specific update function with image size {SIZE}",
64 "SIZE", compImageSize);
65
66 deviceSpecificUpdateFunctionCalled = true;
67
68 // Setting this property for demonstration purpose.
69 // For a real device, this could represent the
70 // percentage completion of writing the firmware,
71 // and any progress made in the update process within this function.
72 activationProgress->progress(30);
73
74 // There is no hard constraint on the values here,
75 // we do not have to reach any specific percentage.
76 // The percentage should be monotonic and increasing.
77 activationProgress->progress(90);
78
79 co_return true;
80}
81
82// NOLINTBEGIN
83sdbusplus::async::task<std::string> NopDevice::getInventoryItemObjectPath()
84// NOLINTEND
85{
86 // for a real device, it could find its inventory item via associations and
87 // the configuration interface, or go via the mapper to find the
88 // specific inventory item interface and then get the path from there.
89
90 co_return "/xyz/openbmc_project/inventory/item/my_nop_item";
91}