blob: 9bcdd39b8c58c0c86d16862e9d37609e38aee8c6 [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 Venture21be45a2018-11-06 12:08:52 -080012const std::string FirmwareBlobHandler::hashBlobID = "/flash/hash";
Patrick Venture4cceb8e2018-11-06 11:56:48 -080013
Patrick Venture68cf64f2018-11-06 10:46:51 -080014std::unique_ptr<GenericBlobInterface>
Patrick Venture148cd652018-11-06 10:59:47 -080015 FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture192d60f2018-11-06 11:11:59 -080016 const std::vector<std::string>& firmwares, std::uint32_t transports)
Patrick Venture68cf64f2018-11-06 10:46:51 -080017{
Patrick Venture52854622018-11-06 12:30:00 -080018 /* There must be at least one. */
19 if (!firmwares.size())
20 {
21 return nullptr;
22 }
23
Patrick Venture4cceb8e2018-11-06 11:56:48 -080024 std::vector<std::string> blobs = firmwares;
25 blobs.push_back(hashBlobID);
26
27 return std::make_unique<FirmwareBlobHandler>(blobs, transports);
Patrick Venture68cf64f2018-11-06 10:46:51 -080028}
29
Patrick Venturec7ca2912018-11-02 11:38:33 -070030bool FirmwareBlobHandler::canHandleBlob(const std::string& path)
31{
Patrick Venture53977962018-11-02 18:59:35 -070032 /* Check if the path is in our supported list (or active list). */
Patrick Venture4cceb8e2018-11-06 11:56:48 -080033 if (std::count(blobIDs.begin(), blobIDs.end(), path))
Patrick Venture137ad2c2018-11-06 11:30:43 -080034 {
35 return true;
36 }
37
Patrick Venturec7ca2912018-11-02 11:38:33 -070038 return false;
39}
Patrick Venture53977962018-11-02 18:59:35 -070040
Patrick Venturec7ca2912018-11-02 11:38:33 -070041std::vector<std::string> FirmwareBlobHandler::getBlobIds()
42{
Patrick Venturefa6c4d92018-11-02 18:34:53 -070043 /*
44 * Grab the list of supported firmware.
Patrick Venture137ad2c2018-11-06 11:30:43 -080045 *
46 * If there's an open firmware session, it'll already be present in the
47 * list as "/flash/active/image", and if the hash has started,
48 * "/flash/active/hash" regardless of mechanism. This is done in the open
49 * comamnd, no extra work is required here.
Patrick Venturefa6c4d92018-11-02 18:34:53 -070050 */
Patrick Venture4cceb8e2018-11-06 11:56:48 -080051 return blobIDs;
Patrick Venturec7ca2912018-11-02 11:38:33 -070052}
Patrick Venture53977962018-11-02 18:59:35 -070053
Patrick Venturec7ca2912018-11-02 11:38:33 -070054bool FirmwareBlobHandler::deleteBlob(const std::string& path)
55{
Patrick Venture53977962018-11-02 18:59:35 -070056 /*
57 * Per the design, this mean abort, and this will trigger whatever
58 * appropriate actions are required to abort the process.
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::stat(const std::string& path, struct BlobMeta* meta)
64{
Patrick Venture53977962018-11-02 18:59:35 -070065 /*
66 * Stat on the files will return information such as what supported
67 * transport mechanisms are available.
68 *
69 * Stat on an active file or hash will return information such as the size
70 * of the data cached, and any additional pertinent information. The
71 * blob_state on the active files will return the state of the update.
72 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070073 return false;
74}
Patrick Venture53977962018-11-02 18:59:35 -070075
Patrick Venturec7ca2912018-11-02 11:38:33 -070076bool FirmwareBlobHandler::open(uint16_t session, uint16_t flags,
77 const std::string& path)
78{
Patrick Venture53977962018-11-02 18:59:35 -070079 /*
80 * If you open /flash/image or /flash/tarball, or /flash/hash it will
81 * interpret the open flags and perform whatever actions are required for
82 * that update process. The session returned can be used immediately for
83 * sending data down, without requiring one to open the new active file.
84 *
85 * If you open the active flash image or active hash it will let you
86 * overwrite pieces, depending on the state.
87 * Once the verification process has started the active files cannot be
88 * opened.
89 */
Patrick Venturec7ca2912018-11-02 11:38:33 -070090 return false;
91}
Patrick Venture53977962018-11-02 18:59:35 -070092
Patrick Venturec7ca2912018-11-02 11:38:33 -070093std::vector<uint8_t> FirmwareBlobHandler::read(uint16_t session,
94 uint32_t offset,
95 uint32_t requestedSize)
96{
Patrick Venture53977962018-11-02 18:59:35 -070097 /*
98 * Currently, the design does not provide this with a function, however,
99 * it will likely change to support reading data back.
100 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700101 return {};
102}
Patrick Venture53977962018-11-02 18:59:35 -0700103
Patrick Venturec7ca2912018-11-02 11:38:33 -0700104bool FirmwareBlobHandler::write(uint16_t session, uint32_t offset,
105 const std::vector<uint8_t>& data)
106{
Patrick Venture53977962018-11-02 18:59:35 -0700107 /*
108 * This will do whatever behavior is expected by mechanism - likely will
109 * just call the specific write handler.
110 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700111 return false;
112}
113bool FirmwareBlobHandler::writeMeta(uint16_t session, uint32_t offset,
114 const std::vector<uint8_t>& data)
115{
Patrick Venture53977962018-11-02 18:59:35 -0700116 /*
117 * If the active session (image or hash) is over LPC, this allows
118 * configuring it. This option is only available before you start
119 * writing data for the given item (image or hash). This will return
120 * false at any other part.
121 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700122 return false;
123}
124bool FirmwareBlobHandler::commit(uint16_t session,
125 const std::vector<uint8_t>& data)
126{
Patrick Venture53977962018-11-02 18:59:35 -0700127 /*
128 * If this command is called on the session for the hash image, it'll
129 * trigger a systemd service `verify_image.service` to attempt to verify
130 * the image. Before doing this, if the transport mechanism is not IPMI
131 * BT, it'll shut down the mechanism used for transport preventing the
132 * host from updating anything.
133 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700134 return false;
135}
136bool FirmwareBlobHandler::close(uint16_t session)
137{
Patrick Venture53977962018-11-02 18:59:35 -0700138 /*
139 * Close must be called on the firmware image before triggering
140 * verification via commit. Once the verification is complete, you can
141 * then close the hash file.
142 *
143 * If the `verify_image.service` returned success, closing the hash file
144 * will have a specific behavior depending on the update. If it's UBI,
145 * it'll perform the install. If it's static layout, it'll do nothing. The
146 * verify_image service in the static layout case is responsible for placing
147 * the file in the correct staging position.
148 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700149 return false;
150}
151bool FirmwareBlobHandler::stat(uint16_t session, struct BlobMeta* meta)
152{
Patrick Venture53977962018-11-02 18:59:35 -0700153 /*
154 * Return the supported mechanisms if it's the handler blob_id, versus
155 * the active one.
156 */
Patrick Venturec7ca2912018-11-02 11:38:33 -0700157 return false;
158}
159bool FirmwareBlobHandler::expire(uint16_t session)
160{
161 return false;
162}
163} // namespace blobs