blob: 0e26ab2fb4aa9467fb7221d26bf96309b1c41927 [file] [log] [blame]
Patrick Venturec7ca2912018-11-02 11:38:33 -07001#include "firmware_handler.hpp"
2
Patrick Venture192d60f2018-11-06 11:11:59 -08003#include <cstdint>
Patrick Venture68cf64f2018-11-06 10:46:51 -08004#include <memory>
Patrick Venturefa6c4d92018-11-02 18:34:53 -07005#include <string>
6#include <vector>
7
Patrick Venturec7ca2912018-11-02 11:38:33 -07008namespace blobs
9{
10
Patrick Venture68cf64f2018-11-06 10:46:51 -080011std::unique_ptr<GenericBlobInterface>
Patrick Venture148cd652018-11-06 10:59:47 -080012 FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture192d60f2018-11-06 11:11:59 -080013 const std::vector<std::string>& firmwares, std::uint32_t transports)
Patrick Venture68cf64f2018-11-06 10:46:51 -080014{
Patrick Venture192d60f2018-11-06 11:11:59 -080015 return std::make_unique<FirmwareBlobHandler>(firmwares, transports);
Patrick Venture68cf64f2018-11-06 10:46:51 -080016}
17
Patrick Venturec7ca2912018-11-02 11:38:33 -070018bool FirmwareBlobHandler::canHandleBlob(const std::string& path)
19{
Patrick Venture53977962018-11-02 18:59:35 -070020 /* Check if the path is in our supported list (or active list). */
Patrick Venturec7ca2912018-11-02 11:38:33 -070021 return false;
22}
Patrick Venture53977962018-11-02 18:59:35 -070023
Patrick Venturec7ca2912018-11-02 11:38:33 -070024std::vector<std::string> FirmwareBlobHandler::getBlobIds()
25{
Patrick Venturefa6c4d92018-11-02 18:34:53 -070026 /*
27 * Grab the list of supported firmware.
28 * If there's an open session, add that to this list.
29 */
Patrick Venture148cd652018-11-06 10:59:47 -080030 std::vector<std::string> blobs = baseFirmwares;
Patrick Venturefa6c4d92018-11-02 18:34:53 -070031
32 /*
33 * If there's an open firmware session, it'll add "/flash/active/image",
34 * and if the hash has started, "/flash/active/hash" regardless of
35 * mechanism.
36 */
37
38 return blobs;
Patrick Venturec7ca2912018-11-02 11:38:33 -070039}
Patrick Venture53977962018-11-02 18:59:35 -070040
Patrick Venturec7ca2912018-11-02 11:38:33 -070041bool FirmwareBlobHandler::deleteBlob(const std::string& path)
42{
Patrick Venture53977962018-11-02 18:59:35 -070043 /*
44 * Per the design, this mean abort, and this will trigger whatever
45 * appropriate actions are required to abort the process.
46 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070047 return false;
48}
Patrick Venture53977962018-11-02 18:59:35 -070049
Patrick Venturec7ca2912018-11-02 11:38:33 -070050bool FirmwareBlobHandler::stat(const std::string& path, struct BlobMeta* meta)
51{
Patrick Venture53977962018-11-02 18:59:35 -070052 /*
53 * Stat on the files will return information such as what supported
54 * transport mechanisms are available.
55 *
56 * Stat on an active file or hash will return information such as the size
57 * of the data cached, and any additional pertinent information. The
58 * blob_state on the active files will return the state of the update.
59 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070060 return false;
61}
Patrick Venture53977962018-11-02 18:59:35 -070062
Patrick Venturec7ca2912018-11-02 11:38:33 -070063bool FirmwareBlobHandler::open(uint16_t session, uint16_t flags,
64 const std::string& path)
65{
Patrick Venture53977962018-11-02 18:59:35 -070066 /*
67 * If you open /flash/image or /flash/tarball, or /flash/hash it will
68 * interpret the open flags and perform whatever actions are required for
69 * that update process. The session returned can be used immediately for
70 * sending data down, without requiring one to open the new active file.
71 *
72 * If you open the active flash image or active hash it will let you
73 * overwrite pieces, depending on the state.
74 * Once the verification process has started the active files cannot be
75 * opened.
76 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070077 return false;
78}
Patrick Venture53977962018-11-02 18:59:35 -070079
Patrick Venturec7ca2912018-11-02 11:38:33 -070080std::vector<uint8_t> FirmwareBlobHandler::read(uint16_t session,
81 uint32_t offset,
82 uint32_t requestedSize)
83{
Patrick Venture53977962018-11-02 18:59:35 -070084 /*
85 * Currently, the design does not provide this with a function, however,
86 * it will likely change to support reading data back.
87 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070088 return {};
89}
Patrick Venture53977962018-11-02 18:59:35 -070090
Patrick Venturec7ca2912018-11-02 11:38:33 -070091bool FirmwareBlobHandler::write(uint16_t session, uint32_t offset,
92 const std::vector<uint8_t>& data)
93{
Patrick Venture53977962018-11-02 18:59:35 -070094 /*
95 * This will do whatever behavior is expected by mechanism - likely will
96 * just call the specific write handler.
97 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070098 return false;
99}
100bool FirmwareBlobHandler::writeMeta(uint16_t session, uint32_t offset,
101 const std::vector<uint8_t>& data)
102{
Patrick Venture53977962018-11-02 18:59:35 -0700103 /*
104 * If the active session (image or hash) is over LPC, this allows
105 * configuring it. This option is only available before you start
106 * writing data for the given item (image or hash). This will return
107 * false at any other part.
108 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700109 return false;
110}
111bool FirmwareBlobHandler::commit(uint16_t session,
112 const std::vector<uint8_t>& data)
113{
Patrick Venture53977962018-11-02 18:59:35 -0700114 /*
115 * If this command is called on the session for the hash image, it'll
116 * trigger a systemd service `verify_image.service` to attempt to verify
117 * the image. Before doing this, if the transport mechanism is not IPMI
118 * BT, it'll shut down the mechanism used for transport preventing the
119 * host from updating anything.
120 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700121 return false;
122}
123bool FirmwareBlobHandler::close(uint16_t session)
124{
Patrick Venture53977962018-11-02 18:59:35 -0700125 /*
126 * Close must be called on the firmware image before triggering
127 * verification via commit. Once the verification is complete, you can
128 * then close the hash file.
129 *
130 * If the `verify_image.service` returned success, closing the hash file
131 * will have a specific behavior depending on the update. If it's UBI,
132 * it'll perform the install. If it's static layout, it'll do nothing. The
133 * verify_image service in the static layout case is responsible for placing
134 * the file in the correct staging position.
135 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700136 return false;
137}
138bool FirmwareBlobHandler::stat(uint16_t session, struct BlobMeta* meta)
139{
Patrick Venture53977962018-11-02 18:59:35 -0700140 /*
141 * Return the supported mechanisms if it's the handler blob_id, versus
142 * the active one.
143 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700144 return false;
145}
146bool FirmwareBlobHandler::expire(uint16_t session)
147{
148 return false;
149}
150} // namespace blobs