blob: 1a9e8b020038e3d5fc5b15300b811bd31bdce312 [file] [log] [blame]
Patrick Venturec7ca2912018-11-02 11:38:33 -07001#pragma once
2
Patrick Venturea78e39f2018-11-06 18:37:06 -08003#include "image_handler.hpp"
4
Patrick Venturec7ca2912018-11-02 11:38:33 -07005#include <blobs-ipmid/blobs.hpp>
Patrick Venture192d60f2018-11-06 11:11:59 -08006#include <cstdint>
Patrick Venture68cf64f2018-11-06 10:46:51 -08007#include <memory>
Patrick Venture148cd652018-11-06 10:59:47 -08008#include <string>
9#include <vector>
Patrick Venturec7ca2912018-11-02 11:38:33 -070010
11namespace blobs
12{
13
Patrick Venturedf3e6ae2018-11-02 17:37:18 -070014enum class FirmwareUpdateFlags
15{
16 bt = (1 << 8), /* Expect to send contents over IPMI BlockTransfer. */
17 p2a = (1 << 9), /* Expect to send contents over P2A bridge. */
18 lpc = (1 << 10), /* Expect to send contents over LPC bridge. */
19};
20
Patrick Venturec7ca2912018-11-02 11:38:33 -070021/**
22 * Register only one firmware blob handler that will manage all sessions.
23 */
24class FirmwareBlobHandler : public GenericBlobInterface
25{
26 public:
Patrick Venture137ad2c2018-11-06 11:30:43 -080027 /**
28 * Create a FirmwareBlobHandler.
29 *
Patrick Venture4cceb8e2018-11-06 11:56:48 -080030 * @param[in] firmwares - list of firmware blob_ids to support.
Patrick Venture137ad2c2018-11-06 11:30:43 -080031 * @param[in] transports - bitmask of transports to support.
32 */
Patrick Venture148cd652018-11-06 10:59:47 -080033 static std::unique_ptr<GenericBlobInterface>
Patrick Venturea78e39f2018-11-06 18:37:06 -080034 CreateFirmwareBlobHandler(const std::vector<HandlerPack>& firmwares,
Patrick Venture46637c82018-11-06 15:20:24 -080035 std::uint16_t transports);
Patrick Venture68cf64f2018-11-06 10:46:51 -080036
Patrick Venture137ad2c2018-11-06 11:30:43 -080037 /**
38 * Create a FirmwareBlobHandler.
39 *
Patrick Venturea78e39f2018-11-06 18:37:06 -080040 * @param[in] blobs - list of blobs_ids to support and their image handlers.
Patrick Venture137ad2c2018-11-06 11:30:43 -080041 * @param[in] transports - bitmask of transports to support.
42 */
Patrick Venturea78e39f2018-11-06 18:37:06 -080043 FirmwareBlobHandler(const std::vector<HandlerPack>& firmwares,
44 const std::vector<std::string>& blobs,
Patrick Venture46637c82018-11-06 15:20:24 -080045 std::uint16_t transports) :
Patrick Venturea78e39f2018-11-06 18:37:06 -080046 handlers(firmwares),
47 blobIDs(blobs), transports(transports)
Patrick Venture148cd652018-11-06 10:59:47 -080048 {
49 }
Patrick Venturec7ca2912018-11-02 11:38:33 -070050 ~FirmwareBlobHandler() = default;
51 FirmwareBlobHandler(const FirmwareBlobHandler&) = default;
52 FirmwareBlobHandler& operator=(const FirmwareBlobHandler&) = default;
53 FirmwareBlobHandler(FirmwareBlobHandler&&) = default;
54 FirmwareBlobHandler& operator=(FirmwareBlobHandler&&) = default;
55
56 bool canHandleBlob(const std::string& path) override;
57 std::vector<std::string> getBlobIds() override;
58 bool deleteBlob(const std::string& path) override;
59 bool stat(const std::string& path, struct BlobMeta* meta) override;
60 bool open(uint16_t session, uint16_t flags,
61 const std::string& path) override;
62 std::vector<uint8_t> read(uint16_t session, uint32_t offset,
63 uint32_t requestedSize) override;
64 bool write(uint16_t session, uint32_t offset,
65 const std::vector<uint8_t>& data) override;
66 bool writeMeta(uint16_t session, uint32_t offset,
67 const std::vector<uint8_t>& data) override;
68 bool commit(uint16_t session, const std::vector<uint8_t>& data) override;
69 bool close(uint16_t session) override;
70 bool stat(uint16_t session, struct BlobMeta* meta) override;
71 bool expire(uint16_t session) override;
Patrick Venture148cd652018-11-06 10:59:47 -080072
Patrick Venture21be45a2018-11-06 12:08:52 -080073 static const std::string hashBlobID;
Patrick Venture7b9256f2018-11-06 15:06:04 -080074 static const std::string activeImageBlobID;
75 static const std::string activeHashBlobID;
Patrick Venture21be45a2018-11-06 12:08:52 -080076
Patrick Venture148cd652018-11-06 10:59:47 -080077 private:
Patrick Venturea78e39f2018-11-06 18:37:06 -080078 /** List of handlers by type. */
79 std::vector<HandlerPack> handlers;
80
Patrick Venturec02849b2018-11-06 17:31:15 -080081 /** Active list of blobIDs. */
Patrick Venture4cceb8e2018-11-06 11:56:48 -080082 std::vector<std::string> blobIDs;
Patrick Venturec02849b2018-11-06 17:31:15 -080083
84 /** The bits set indicate what transport mechanisms are supported. */
Patrick Venture46637c82018-11-06 15:20:24 -080085 std::uint16_t transports;
Patrick Venturec02849b2018-11-06 17:31:15 -080086
87 /** Temporary variable to track whether a blob is open. */
88 bool fileOpen = false;
Patrick Venturec7ca2912018-11-02 11:38:33 -070089};
90
91} // namespace blobs