blob: 5423cf86fef1ad69553bef6f2e90c14f46043fe4 [file] [log] [blame]
P Arun Kumar Reddy6a3f9902025-03-26 10:23:06 +05301#include "update.hpp"
2
3#include "update_manager.hpp"
4
5namespace pldm
6{
7namespace fw_update
8{
9
10sdbusplus::message::object_path Update::startUpdate(
11 sdbusplus::message::unix_fd image,
12 ApplyTimeIntf::RequestedApplyTimes applyTime [[maybe_unused]])
13{
14 namespace software = sdbusplus::xyz::openbmc_project::Software::server;
15 // If a firmware activation of a package is in progress, don't proceed with
16 // package processing
17 if (updateManager->activation)
18 {
19 if (updateManager->activation->activation() ==
20 software::Activation::Activations::Activating)
21 {
22 throw sdbusplus::xyz::openbmc_project::Common::Error::Unavailable();
23 }
24 else
25 {
26 updateManager->clearActivationInfo();
27 }
28 }
29
30 info("Starting update for image {FD}", "FD", image.fd);
31 char buffer[4096];
32 ssize_t bytesRead;
33 imageStream.str(std::string());
34
35 while ((bytesRead = read(image, buffer, sizeof(buffer))) > 0)
36 {
37 imageStream.write(buffer, bytesRead);
38 }
39
40 if (bytesRead < 0)
41 {
42 throw std::runtime_error("Failed to read image file descriptor");
43 }
44
45 return sdbusplus::message::object_path(updateManager->processStreamDefer(
46 imageStream, imageStream.str().size()));
47}
48
49} // namespace fw_update
50} // namespace pldm