blob: 4c076deb2a762a6171f58d229050ec5d50144bb5 [file] [log] [blame]
Patrick Venturec7ca2912018-11-02 11:38:33 -07001#include "firmware_handler.hpp"
2
Patrick Venture137ad2c2018-11-06 11:30:43 -08003#include <algorithm>
Patrick Venture192d60f2018-11-06 11:11:59 -08004#include <cstdint>
Patrick Venture68cf64f2018-11-06 10:46:51 -08005#include <memory>
Patrick Venturefa6c4d92018-11-02 18:34:53 -07006#include <string>
7#include <vector>
8
Patrick Venturec7ca2912018-11-02 11:38:33 -07009namespace blobs
10{
11
Patrick Venture68cf64f2018-11-06 10:46:51 -080012std::unique_ptr<GenericBlobInterface>
Patrick Venture148cd652018-11-06 10:59:47 -080013 FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture192d60f2018-11-06 11:11:59 -080014 const std::vector<std::string>& firmwares, std::uint32_t transports)
Patrick Venture68cf64f2018-11-06 10:46:51 -080015{
Patrick Venture192d60f2018-11-06 11:11:59 -080016 return std::make_unique<FirmwareBlobHandler>(firmwares, transports);
Patrick Venture68cf64f2018-11-06 10:46:51 -080017}
18
Patrick Venturec7ca2912018-11-02 11:38:33 -070019bool FirmwareBlobHandler::canHandleBlob(const std::string& path)
20{
Patrick Venture53977962018-11-02 18:59:35 -070021 /* Check if the path is in our supported list (or active list). */
Patrick Venture137ad2c2018-11-06 11:30:43 -080022 if (std::count(firmwares.begin(), firmwares.end(), path))
23 {
24 return true;
25 }
26
Patrick Venturec7ca2912018-11-02 11:38:33 -070027 return false;
28}
Patrick Venture53977962018-11-02 18:59:35 -070029
Patrick Venturec7ca2912018-11-02 11:38:33 -070030std::vector<std::string> FirmwareBlobHandler::getBlobIds()
31{
Patrick Venturefa6c4d92018-11-02 18:34:53 -070032 /*
33 * Grab the list of supported firmware.
Patrick Venture137ad2c2018-11-06 11:30:43 -080034 *
35 * If there's an open firmware session, it'll already be present in the
36 * list as "/flash/active/image", and if the hash has started,
37 * "/flash/active/hash" regardless of mechanism. This is done in the open
38 * comamnd, no extra work is required here.
Patrick Venturefa6c4d92018-11-02 18:34:53 -070039 */
Patrick Venture137ad2c2018-11-06 11:30:43 -080040 return firmwares;
Patrick Venturec7ca2912018-11-02 11:38:33 -070041}
Patrick Venture53977962018-11-02 18:59:35 -070042
Patrick Venturec7ca2912018-11-02 11:38:33 -070043bool FirmwareBlobHandler::deleteBlob(const std::string& path)
44{
Patrick Venture53977962018-11-02 18:59:35 -070045 /*
46 * Per the design, this mean abort, and this will trigger whatever
47 * appropriate actions are required to abort the process.
48 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070049 return false;
50}
Patrick Venture53977962018-11-02 18:59:35 -070051
Patrick Venturec7ca2912018-11-02 11:38:33 -070052bool FirmwareBlobHandler::stat(const std::string& path, struct BlobMeta* meta)
53{
Patrick Venture53977962018-11-02 18:59:35 -070054 /*
55 * Stat on the files will return information such as what supported
56 * transport mechanisms are available.
57 *
58 * Stat on an active file or hash will return information such as the size
59 * of the data cached, and any additional pertinent information. The
60 * blob_state on the active files will return the state of the update.
61 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070062 return false;
63}
Patrick Venture53977962018-11-02 18:59:35 -070064
Patrick Venturec7ca2912018-11-02 11:38:33 -070065bool FirmwareBlobHandler::open(uint16_t session, uint16_t flags,
66 const std::string& path)
67{
Patrick Venture53977962018-11-02 18:59:35 -070068 /*
69 * If you open /flash/image or /flash/tarball, or /flash/hash it will
70 * interpret the open flags and perform whatever actions are required for
71 * that update process. The session returned can be used immediately for
72 * sending data down, without requiring one to open the new active file.
73 *
74 * If you open the active flash image or active hash it will let you
75 * overwrite pieces, depending on the state.
76 * Once the verification process has started the active files cannot be
77 * opened.
78 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070079 return false;
80}
Patrick Venture53977962018-11-02 18:59:35 -070081
Patrick Venturec7ca2912018-11-02 11:38:33 -070082std::vector<uint8_t> FirmwareBlobHandler::read(uint16_t session,
83 uint32_t offset,
84 uint32_t requestedSize)
85{
Patrick Venture53977962018-11-02 18:59:35 -070086 /*
87 * Currently, the design does not provide this with a function, however,
88 * it will likely change to support reading data back.
89 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070090 return {};
91}
Patrick Venture53977962018-11-02 18:59:35 -070092
Patrick Venturec7ca2912018-11-02 11:38:33 -070093bool FirmwareBlobHandler::write(uint16_t session, uint32_t offset,
94 const std::vector<uint8_t>& data)
95{
Patrick Venture53977962018-11-02 18:59:35 -070096 /*
97 * This will do whatever behavior is expected by mechanism - likely will
98 * just call the specific write handler.
99 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700100 return false;
101}
102bool FirmwareBlobHandler::writeMeta(uint16_t session, uint32_t offset,
103 const std::vector<uint8_t>& data)
104{
Patrick Venture53977962018-11-02 18:59:35 -0700105 /*
106 * If the active session (image or hash) is over LPC, this allows
107 * configuring it. This option is only available before you start
108 * writing data for the given item (image or hash). This will return
109 * false at any other part.
110 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700111 return false;
112}
113bool FirmwareBlobHandler::commit(uint16_t session,
114 const std::vector<uint8_t>& data)
115{
Patrick Venture53977962018-11-02 18:59:35 -0700116 /*
117 * If this command is called on the session for the hash image, it'll
118 * trigger a systemd service `verify_image.service` to attempt to verify
119 * the image. Before doing this, if the transport mechanism is not IPMI
120 * BT, it'll shut down the mechanism used for transport preventing the
121 * host from updating anything.
122 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700123 return false;
124}
125bool FirmwareBlobHandler::close(uint16_t session)
126{
Patrick Venture53977962018-11-02 18:59:35 -0700127 /*
128 * Close must be called on the firmware image before triggering
129 * verification via commit. Once the verification is complete, you can
130 * then close the hash file.
131 *
132 * If the `verify_image.service` returned success, closing the hash file
133 * will have a specific behavior depending on the update. If it's UBI,
134 * it'll perform the install. If it's static layout, it'll do nothing. The
135 * verify_image service in the static layout case is responsible for placing
136 * the file in the correct staging position.
137 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700138 return false;
139}
140bool FirmwareBlobHandler::stat(uint16_t session, struct BlobMeta* meta)
141{
Patrick Venture53977962018-11-02 18:59:35 -0700142 /*
143 * Return the supported mechanisms if it's the handler blob_id, versus
144 * the active one.
145 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700146 return false;
147}
148bool FirmwareBlobHandler::expire(uint16_t session)
149{
150 return false;
151}
152} // namespace blobs