blob: e459c619ece6c2ea84f5127e22103e2fa2283540 [file] [log] [blame]
Patrick Venturefa6c4d92018-11-02 18:34:53 -07001#include "config.h"
2
Patrick Venturec7ca2912018-11-02 11:38:33 -07003#include "firmware_handler.hpp"
4
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 Venturefa6c4d92018-11-02 18:34:53 -070012std::vector<std::string> supportedFirmware = {
13 "/flash/hash",
14#ifdef ENABLE_STATIC_LAYOUT
15 "/flash/image",
16#endif
17};
18
Patrick Venture68cf64f2018-11-06 10:46:51 -080019std::unique_ptr<GenericBlobInterface>
20 FirmwareBlobHandler::CreateFirmwareBlobHandler()
21{
22 return std::make_unique<FirmwareBlobHandler>();
23}
24
Patrick Venturec7ca2912018-11-02 11:38:33 -070025bool FirmwareBlobHandler::canHandleBlob(const std::string& path)
26{
Patrick Venture53977962018-11-02 18:59:35 -070027 /* Check if the path is in our supported list (or active list). */
Patrick Venturec7ca2912018-11-02 11:38:33 -070028 return false;
29}
Patrick Venture53977962018-11-02 18:59:35 -070030
Patrick Venturec7ca2912018-11-02 11:38:33 -070031std::vector<std::string> FirmwareBlobHandler::getBlobIds()
32{
Patrick Venturefa6c4d92018-11-02 18:34:53 -070033 /*
34 * Grab the list of supported firmware.
35 * If there's an open session, add that to this list.
36 */
37 std::vector<std::string> blobs = supportedFirmware;
38
39 /*
40 * If there's an open firmware session, it'll add "/flash/active/image",
41 * and if the hash has started, "/flash/active/hash" regardless of
42 * mechanism.
43 */
44
45 return blobs;
Patrick Venturec7ca2912018-11-02 11:38:33 -070046}
Patrick Venture53977962018-11-02 18:59:35 -070047
Patrick Venturec7ca2912018-11-02 11:38:33 -070048bool FirmwareBlobHandler::deleteBlob(const std::string& path)
49{
Patrick Venture53977962018-11-02 18:59:35 -070050 /*
51 * Per the design, this mean abort, and this will trigger whatever
52 * appropriate actions are required to abort the process.
53 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070054 return false;
55}
Patrick Venture53977962018-11-02 18:59:35 -070056
Patrick Venturec7ca2912018-11-02 11:38:33 -070057bool FirmwareBlobHandler::stat(const std::string& path, struct BlobMeta* meta)
58{
Patrick Venture53977962018-11-02 18:59:35 -070059 /*
60 * Stat on the files will return information such as what supported
61 * transport mechanisms are available.
62 *
63 * Stat on an active file or hash will return information such as the size
64 * of the data cached, and any additional pertinent information. The
65 * blob_state on the active files will return the state of the update.
66 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070067 return false;
68}
Patrick Venture53977962018-11-02 18:59:35 -070069
Patrick Venturec7ca2912018-11-02 11:38:33 -070070bool FirmwareBlobHandler::open(uint16_t session, uint16_t flags,
71 const std::string& path)
72{
Patrick Venture53977962018-11-02 18:59:35 -070073 /*
74 * If you open /flash/image or /flash/tarball, or /flash/hash it will
75 * interpret the open flags and perform whatever actions are required for
76 * that update process. The session returned can be used immediately for
77 * sending data down, without requiring one to open the new active file.
78 *
79 * If you open the active flash image or active hash it will let you
80 * overwrite pieces, depending on the state.
81 * Once the verification process has started the active files cannot be
82 * opened.
83 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070084 return false;
85}
Patrick Venture53977962018-11-02 18:59:35 -070086
Patrick Venturec7ca2912018-11-02 11:38:33 -070087std::vector<uint8_t> FirmwareBlobHandler::read(uint16_t session,
88 uint32_t offset,
89 uint32_t requestedSize)
90{
Patrick Venture53977962018-11-02 18:59:35 -070091 /*
92 * Currently, the design does not provide this with a function, however,
93 * it will likely change to support reading data back.
94 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070095 return {};
96}
Patrick Venture53977962018-11-02 18:59:35 -070097
Patrick Venturec7ca2912018-11-02 11:38:33 -070098bool FirmwareBlobHandler::write(uint16_t session, uint32_t offset,
99 const std::vector<uint8_t>& data)
100{
Patrick Venture53977962018-11-02 18:59:35 -0700101 /*
102 * This will do whatever behavior is expected by mechanism - likely will
103 * just call the specific write handler.
104 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700105 return false;
106}
107bool FirmwareBlobHandler::writeMeta(uint16_t session, uint32_t offset,
108 const std::vector<uint8_t>& data)
109{
Patrick Venture53977962018-11-02 18:59:35 -0700110 /*
111 * If the active session (image or hash) is over LPC, this allows
112 * configuring it. This option is only available before you start
113 * writing data for the given item (image or hash). This will return
114 * false at any other part.
115 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700116 return false;
117}
118bool FirmwareBlobHandler::commit(uint16_t session,
119 const std::vector<uint8_t>& data)
120{
Patrick Venture53977962018-11-02 18:59:35 -0700121 /*
122 * If this command is called on the session for the hash image, it'll
123 * trigger a systemd service `verify_image.service` to attempt to verify
124 * the image. Before doing this, if the transport mechanism is not IPMI
125 * BT, it'll shut down the mechanism used for transport preventing the
126 * host from updating anything.
127 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700128 return false;
129}
130bool FirmwareBlobHandler::close(uint16_t session)
131{
Patrick Venture53977962018-11-02 18:59:35 -0700132 /*
133 * Close must be called on the firmware image before triggering
134 * verification via commit. Once the verification is complete, you can
135 * then close the hash file.
136 *
137 * If the `verify_image.service` returned success, closing the hash file
138 * will have a specific behavior depending on the update. If it's UBI,
139 * it'll perform the install. If it's static layout, it'll do nothing. The
140 * verify_image service in the static layout case is responsible for placing
141 * the file in the correct staging position.
142 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700143 return false;
144}
145bool FirmwareBlobHandler::stat(uint16_t session, struct BlobMeta* meta)
146{
Patrick Venture53977962018-11-02 18:59:35 -0700147 /*
148 * Return the supported mechanisms if it's the handler blob_id, versus
149 * the active one.
150 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700151 return false;
152}
153bool FirmwareBlobHandler::expire(uint16_t session)
154{
155 return false;
156}
157} // namespace blobs