blob: 89c78913b84c9a2bf6b1f196506cf977412a5cb9 [file] [log] [blame]
Patrick Venturec7ca2912018-11-02 11:38:33 -07001#include "firmware_handler.hpp"
2
Patrick Venture68cf64f2018-11-06 10:46:51 -08003#include <memory>
Patrick Venturefa6c4d92018-11-02 18:34:53 -07004#include <string>
5#include <vector>
6
Patrick Venturec7ca2912018-11-02 11:38:33 -07007namespace blobs
8{
9
Patrick Venture68cf64f2018-11-06 10:46:51 -080010std::unique_ptr<GenericBlobInterface>
Patrick Venture148cd652018-11-06 10:59:47 -080011 FirmwareBlobHandler::CreateFirmwareBlobHandler(
12 const std::vector<std::string>& firmwares)
Patrick Venture68cf64f2018-11-06 10:46:51 -080013{
Patrick Venture148cd652018-11-06 10:59:47 -080014 return std::make_unique<FirmwareBlobHandler>(firmwares);
Patrick Venture68cf64f2018-11-06 10:46:51 -080015}
16
Patrick Venturec7ca2912018-11-02 11:38:33 -070017bool FirmwareBlobHandler::canHandleBlob(const std::string& path)
18{
Patrick Venture53977962018-11-02 18:59:35 -070019 /* Check if the path is in our supported list (or active list). */
Patrick Venturec7ca2912018-11-02 11:38:33 -070020 return false;
21}
Patrick Venture53977962018-11-02 18:59:35 -070022
Patrick Venturec7ca2912018-11-02 11:38:33 -070023std::vector<std::string> FirmwareBlobHandler::getBlobIds()
24{
Patrick Venturefa6c4d92018-11-02 18:34:53 -070025 /*
26 * Grab the list of supported firmware.
27 * If there's an open session, add that to this list.
28 */
Patrick Venture148cd652018-11-06 10:59:47 -080029 std::vector<std::string> blobs = baseFirmwares;
Patrick Venturefa6c4d92018-11-02 18:34:53 -070030
31 /*
32 * If there's an open firmware session, it'll add "/flash/active/image",
33 * and if the hash has started, "/flash/active/hash" regardless of
34 * mechanism.
35 */
36
37 return blobs;
Patrick Venturec7ca2912018-11-02 11:38:33 -070038}
Patrick Venture53977962018-11-02 18:59:35 -070039
Patrick Venturec7ca2912018-11-02 11:38:33 -070040bool FirmwareBlobHandler::deleteBlob(const std::string& path)
41{
Patrick Venture53977962018-11-02 18:59:35 -070042 /*
43 * Per the design, this mean abort, and this will trigger whatever
44 * appropriate actions are required to abort the process.
45 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070046 return false;
47}
Patrick Venture53977962018-11-02 18:59:35 -070048
Patrick Venturec7ca2912018-11-02 11:38:33 -070049bool FirmwareBlobHandler::stat(const std::string& path, struct BlobMeta* meta)
50{
Patrick Venture53977962018-11-02 18:59:35 -070051 /*
52 * Stat on the files will return information such as what supported
53 * transport mechanisms are available.
54 *
55 * Stat on an active file or hash will return information such as the size
56 * of the data cached, and any additional pertinent information. The
57 * blob_state on the active files will return the state of the update.
58 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070059 return false;
60}
Patrick Venture53977962018-11-02 18:59:35 -070061
Patrick Venturec7ca2912018-11-02 11:38:33 -070062bool FirmwareBlobHandler::open(uint16_t session, uint16_t flags,
63 const std::string& path)
64{
Patrick Venture53977962018-11-02 18:59:35 -070065 /*
66 * If you open /flash/image or /flash/tarball, or /flash/hash it will
67 * interpret the open flags and perform whatever actions are required for
68 * that update process. The session returned can be used immediately for
69 * sending data down, without requiring one to open the new active file.
70 *
71 * If you open the active flash image or active hash it will let you
72 * overwrite pieces, depending on the state.
73 * Once the verification process has started the active files cannot be
74 * opened.
75 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070076 return false;
77}
Patrick Venture53977962018-11-02 18:59:35 -070078
Patrick Venturec7ca2912018-11-02 11:38:33 -070079std::vector<uint8_t> FirmwareBlobHandler::read(uint16_t session,
80 uint32_t offset,
81 uint32_t requestedSize)
82{
Patrick Venture53977962018-11-02 18:59:35 -070083 /*
84 * Currently, the design does not provide this with a function, however,
85 * it will likely change to support reading data back.
86 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070087 return {};
88}
Patrick Venture53977962018-11-02 18:59:35 -070089
Patrick Venturec7ca2912018-11-02 11:38:33 -070090bool FirmwareBlobHandler::write(uint16_t session, uint32_t offset,
91 const std::vector<uint8_t>& data)
92{
Patrick Venture53977962018-11-02 18:59:35 -070093 /*
94 * This will do whatever behavior is expected by mechanism - likely will
95 * just call the specific write handler.
96 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070097 return false;
98}
99bool FirmwareBlobHandler::writeMeta(uint16_t session, uint32_t offset,
100 const std::vector<uint8_t>& data)
101{
Patrick Venture53977962018-11-02 18:59:35 -0700102 /*
103 * If the active session (image or hash) is over LPC, this allows
104 * configuring it. This option is only available before you start
105 * writing data for the given item (image or hash). This will return
106 * false at any other part.
107 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700108 return false;
109}
110bool FirmwareBlobHandler::commit(uint16_t session,
111 const std::vector<uint8_t>& data)
112{
Patrick Venture53977962018-11-02 18:59:35 -0700113 /*
114 * If this command is called on the session for the hash image, it'll
115 * trigger a systemd service `verify_image.service` to attempt to verify
116 * the image. Before doing this, if the transport mechanism is not IPMI
117 * BT, it'll shut down the mechanism used for transport preventing the
118 * host from updating anything.
119 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700120 return false;
121}
122bool FirmwareBlobHandler::close(uint16_t session)
123{
Patrick Venture53977962018-11-02 18:59:35 -0700124 /*
125 * Close must be called on the firmware image before triggering
126 * verification via commit. Once the verification is complete, you can
127 * then close the hash file.
128 *
129 * If the `verify_image.service` returned success, closing the hash file
130 * will have a specific behavior depending on the update. If it's UBI,
131 * it'll perform the install. If it's static layout, it'll do nothing. The
132 * verify_image service in the static layout case is responsible for placing
133 * the file in the correct staging position.
134 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700135 return false;
136}
137bool FirmwareBlobHandler::stat(uint16_t session, struct BlobMeta* meta)
138{
Patrick Venture53977962018-11-02 18:59:35 -0700139 /*
140 * Return the supported mechanisms if it's the handler blob_id, versus
141 * the active one.
142 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700143 return false;
144}
145bool FirmwareBlobHandler::expire(uint16_t session)
146{
147 return false;
148}
149} // namespace blobs