xref: /openbmc/pldm/fw-update/update.cpp (revision 6a3f9906a774644a8f0ca2978a81b769e948206f)
1 #include "update.hpp"
2 
3 #include "update_manager.hpp"
4 
5 namespace pldm
6 {
7 namespace fw_update
8 {
9 
startUpdate(sdbusplus::message::unix_fd image,ApplyTimeIntf::RequestedApplyTimes applyTime)10 sdbusplus::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
51