Manojkiran Eda | d94bb83 | 2021-02-17 11:40:22 +0530 | [diff] [blame] | 1 | #include "file_io_type_progress_src.hpp" |
| 2 | |
| 3 | #include "common/utils.hpp" |
| 4 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 5 | #include <phosphor-logging/lg2.hpp> |
| 6 | |
| 7 | PHOSPHOR_LOG2_USING; |
| 8 | |
Manojkiran Eda | d94bb83 | 2021-02-17 11:40:22 +0530 | [diff] [blame] | 9 | namespace pldm |
| 10 | { |
| 11 | |
| 12 | namespace responder |
| 13 | { |
| 14 | |
| 15 | int ProgressCodeHandler::setRawBootProperty( |
| 16 | const std::tuple<uint64_t, std::vector<uint8_t>>& progressCodeBuffer) |
| 17 | { |
| 18 | static constexpr auto RawObjectPath = |
| 19 | "/xyz/openbmc_project/state/boot/raw0"; |
| 20 | static constexpr auto RawInterface = "xyz.openbmc_project.State.Boot.Raw"; |
| 21 | static constexpr auto FreedesktopInterface = |
| 22 | "org.freedesktop.DBus.Properties"; |
| 23 | static constexpr auto RawProperty = "Value"; |
| 24 | static constexpr auto SetMethod = "Set"; |
| 25 | |
| 26 | auto& bus = pldm::utils::DBusHandler::getBus(); |
| 27 | |
| 28 | try |
| 29 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 30 | auto service = pldm::utils::DBusHandler().getService(RawObjectPath, |
| 31 | RawInterface); |
Manojkiran Eda | d94bb83 | 2021-02-17 11:40:22 +0530 | [diff] [blame] | 32 | auto method = bus.new_method_call(service.c_str(), RawObjectPath, |
| 33 | FreedesktopInterface, SetMethod); |
| 34 | method.append(RawInterface, RawProperty, |
| 35 | std::variant<std::tuple<uint64_t, std::vector<uint8_t>>>( |
| 36 | progressCodeBuffer)); |
| 37 | |
| 38 | bus.call_noreply(method); |
| 39 | } |
| 40 | catch (const std::exception& e) |
| 41 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 42 | error( |
| 43 | "failed to make a d-bus call to host-postd daemon, ERROR={ERR_EXCEP}", |
| 44 | "ERR_EXCEP", e.what()); |
Manojkiran Eda | d94bb83 | 2021-02-17 11:40:22 +0530 | [diff] [blame] | 45 | return PLDM_ERROR; |
| 46 | } |
| 47 | |
| 48 | return PLDM_SUCCESS; |
| 49 | } |
| 50 | |
| 51 | int ProgressCodeHandler::write(const char* buffer, uint32_t /*offset*/, |
| 52 | uint32_t& length, |
| 53 | oem_platform::Handler* /*oemPlatformHandler*/) |
| 54 | { |
| 55 | static constexpr auto StartOffset = 40; |
| 56 | static constexpr auto EndOffset = 48; |
| 57 | if (buffer != nullptr) |
| 58 | { |
| 59 | // read the data from the pointed location |
| 60 | std::vector<uint8_t> secondaryCode(buffer, buffer + length); |
| 61 | |
| 62 | // Get the primary code from the offset 40 bytes in the received buffer |
| 63 | |
| 64 | std::vector<uint8_t> primaryCodeArray( |
| 65 | secondaryCode.begin() + StartOffset, |
| 66 | secondaryCode.begin() + EndOffset); |
| 67 | uint64_t primaryCode = 0; |
| 68 | |
| 69 | // form a uint64_t using uint8_t[8] |
| 70 | for (int i = 0; i < 8; i++) |
| 71 | primaryCode |= (uint64_t)primaryCodeArray[i] << 8 * i; |
| 72 | |
Manojkiran Eda | d94bb83 | 2021-02-17 11:40:22 +0530 | [diff] [blame] | 73 | return setRawBootProperty(std::make_tuple(primaryCode, secondaryCode)); |
| 74 | } |
| 75 | return PLDM_ERROR; |
| 76 | } |
| 77 | |
| 78 | } // namespace responder |
| 79 | } // namespace pldm |