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