blob: db7765eba9acc1e3df0ac0fecda57acdb3f4a37b [file] [log] [blame]
Patrick Venture3d1786b2018-08-01 11:19:24 -07001#pragma once
2
Patrick Venture79e131f2018-08-01 13:34:35 -07003#include <vector>
4
Patrick Venture54c3b532018-08-01 11:45:49 -07005#include "host-ipmid/ipmid-api.h"
6
7/* Clearer way to represent the subcommand size. */
8#define SUBCMD_SZ sizeof(uint8_t)
9
Patrick Venture3d1786b2018-08-01 11:19:24 -070010/*
11 * flashStartTransfer -- starts file upload.
12 * flashDataBlock -- adds data to image file.
13 * flashDataFinish -- closes the file.
14 *
15 * flashStartHash -- starts uploading hash.
16 * flashDataHash -- adds data to the hash.
17 * flashDataVerify -- triggers verification.
18 *
19 * flashAbort -- abort everything.
20 *
21 * flashVerifyCheck -- Check if the verification has completed.
22 *
23 * flashVersion -- Get the version of this OEM Handler.
24 *
25 * flashRequestRegion -- Request the physical address for decode (bridge)
26 * flashDataExtBlock -- Provide image data via a bridge
27 * flashHashExtData -- Provide hash data via a bridge
28 */
29enum FlashSubCmds
30{
31 /* Start a transfer. */
32 flashStartTransfer = 0,
33 /* Data block. */
34 flashDataBlock = 1,
35 /* Close file. */
36 flashDataFinish = 2,
37
38 /* Start a hash transfer. */
39 flashStartHash = 3,
40 /* Add data to the hash. */
41 flashHashData = 4,
42 /* Close out the hash file. */
43 flashHashFinish = 5,
44
45 /* Verify the flash image against the hast sent. */
46 flashDataVerify = 6,
47
48 /* Abort. */
49 flashAbort = 7,
50
51 /*
52 * Check if the verification is ready and was successful.
53 * If the response from the IPMI command is OK, check the
54 * response bytes to know if it's ready or still computing,
55 * or failed.
56 */
57 flashVerifyCheck = 8,
58
59 flashVersion = 9,
60 flashRequestRegion = 10,
61 flashDataExtBlock = 11,
62 flashHashExtData = 12,
63 flashMapRegionLpc = 13,
64};
Patrick Venture54c3b532018-08-01 11:45:49 -070065
66/*
67 * StartTransfer expects a basic structure providing some information.
68 */
69struct StartTx
70{
71 uint8_t cmd;
72 uint32_t length; /* Maximum image length is 4GiB (little-endian) */
73} __attribute__((packed));
74
Patrick Venture79e131f2018-08-01 13:34:35 -070075struct ChunkHdr
76{
77 uint8_t cmd;
78 uint32_t offset; /* 0-based write offset */
79 uint8_t data[];
80} __attribute__((packed));
81
Patrick Venture54c3b532018-08-01 11:45:49 -070082class UpdateInterface
83{
84 public:
85 virtual ~UpdateInterface() = default;
86
87 virtual bool start(uint32_t length) = 0;
Patrick Venture79e131f2018-08-01 13:34:35 -070088 virtual bool flashData(uint32_t offset,
89 const std::vector<uint8_t>& bytes) = 0;
Patrick Venture54c3b532018-08-01 11:45:49 -070090};
91
92class FlashUpdate : public UpdateInterface
93{
94 public:
95 FlashUpdate() = default;
96 ~FlashUpdate() = default;
97 FlashUpdate(const FlashUpdate&) = default;
98 FlashUpdate& operator=(const FlashUpdate&) = default;
99 FlashUpdate(FlashUpdate&&) = default;
100 FlashUpdate& operator=(FlashUpdate&&) = default;
101
102 /**
103 * Prepare to receive a BMC image and then a signature.
104 *
105 * @param[in] length - the size of the flash image.
106 * @return true on success, false otherwise.
107 */
108 bool start(uint32_t length) override;
109
Patrick Venture79e131f2018-08-01 13:34:35 -0700110 /**
111 * Attempt to write the bytes at the offset.
112 *
113 * @param[in] offset - the 0-based byte offset into the flash image.
114 * @param[in] bytes - the bytes to write.
115 * @return true on success, false otherwise.
116 */
117 bool flashData(uint32_t offset, const std::vector<uint8_t>& bytes) override;
118
Patrick Venture54c3b532018-08-01 11:45:49 -0700119 private:
120 /**
121 * Tries to close out and delete anything staged.
122 */
123 void abortEverything();
124
125 /**
126 * Open all staged file handles you expect to use.
127 *
128 * @return false on failure.
129 */
130 bool openEverything();
131};