blob: 23b0925629e33993b5f3dc3346b80a962c79ec90 [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 Venture4cceb8e2018-11-06 11:56:48 -080012static std::string hashBlobID = "/flash/hash";
13
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 Venture4cceb8e2018-11-06 11:56:48 -080018 std::vector<std::string> blobs = firmwares;
19 blobs.push_back(hashBlobID);
20
21 return std::make_unique<FirmwareBlobHandler>(blobs, transports);
Patrick Venture68cf64f2018-11-06 10:46:51 -080022}
23
Patrick Venturec7ca2912018-11-02 11:38:33 -070024bool FirmwareBlobHandler::canHandleBlob(const std::string& path)
25{
Patrick Venture53977962018-11-02 18:59:35 -070026 /* Check if the path is in our supported list (or active list). */
Patrick Venture4cceb8e2018-11-06 11:56:48 -080027 if (std::count(blobIDs.begin(), blobIDs.end(), path))
Patrick Venture137ad2c2018-11-06 11:30:43 -080028 {
29 return true;
30 }
31
Patrick Venturec7ca2912018-11-02 11:38:33 -070032 return false;
33}
Patrick Venture53977962018-11-02 18:59:35 -070034
Patrick Venturec7ca2912018-11-02 11:38:33 -070035std::vector<std::string> FirmwareBlobHandler::getBlobIds()
36{
Patrick Venturefa6c4d92018-11-02 18:34:53 -070037 /*
38 * Grab the list of supported firmware.
Patrick Venture137ad2c2018-11-06 11:30:43 -080039 *
40 * If there's an open firmware session, it'll already be present in the
41 * list as "/flash/active/image", and if the hash has started,
42 * "/flash/active/hash" regardless of mechanism. This is done in the open
43 * comamnd, no extra work is required here.
Patrick Venturefa6c4d92018-11-02 18:34:53 -070044 */
Patrick Venture4cceb8e2018-11-06 11:56:48 -080045 return blobIDs;
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