forked from kenr/bitsery-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdfu_types.h
263 lines (234 loc) · 6.12 KB
/
sdfu_types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#pragma once
#include <cstdint>
#include <optional>
#include <variant>
#include <vector>
namespace NRFDL::SDFU
{
/**
* @brief DFU object types.
*/
enum class DfuObjecType : uint8_t
{
NRF_DFU_OBJ_TYPE_INVALID,
NRF_DFU_OBJ_TYPE_COMMAND,
NRF_DFU_OBJ_TYPE_DATA,
};
/**
* @brief DFU protocol operation.
*/
enum class DfuOpcode : uint8_t
{
NRF_DFU_OP_PROTOCOL_VERSION = 0x00,
NRF_DFU_OP_OBJECT_CREATE = 0x01,
NRF_DFU_OP_RECEIPT_NOTIF_SET = 0x02,
NRF_DFU_OP_CRC_GET = 0x03,
NRF_DFU_OP_OBJECT_EXECUTE = 0x04,
NRF_DFU_OP_OBJECT_SELECT = 0x06,
NRF_DFU_OP_MTU_GET = 0x07,
NRF_DFU_OP_OBJECT_WRITE = 0x08,
NRF_DFU_OP_PING = 0x09,
NRF_DFU_OP_HARDWARE_VERSION = 0x0A,
NRF_DFU_OP_FIRMWARE_VERSION = 0x0B,
NRF_DFU_OP_ABORT = 0x0C,
NRF_DFU_OP_RESPONSE = 0x60,
NRF_DFU_OP_INVALID = 0xFF,
};
/**
* @brief DFU operation result code.
*/
enum class DfuResult : uint8_t
{
NRF_DFU_RES_CODE_INVALID = 0x00,
NRF_DFU_RES_CODE_SUCCESS = 0x01,
NRF_DFU_RES_CODE_OP_CODE_NOT_SUPPORTED = 0x02,
NRF_DFU_RES_CODE_INVALID_PARAMETER = 0x03,
NRF_DFU_RES_CODE_INSUFFICIENT_RESOURCES = 0x04,
NRF_DFU_RES_CODE_INVALID_OBJECT = 0x05,
NRF_DFU_RES_CODE_UNSUPPORTED_TYPE = 0x07,
NRF_DFU_RES_CODE_OPERATION_NOT_PERMITTED = 0x08,
NRF_DFU_RES_CODE_OPERATION_FAILED = 0x0A,
NRF_DFU_RES_CODE_EXT_ERROR = 0x0B
};
enum class DfuFirmwareType : uint8_t
{
NRF_DFU_FIRMWARE_TYPE_SOFTDEVICE = 0x00,
NRF_DFU_FIRMWARE_TYPE_APPLICATION = 0x01,
NRF_DFU_FIRMWARE_TYPE_BOOTLOADER = 0x02,
NRF_DFU_FIRMWARE_TYPE_UNKNOWN = 0xFF,
};
/**
* @brief @ref NRF_DFU_OP_PROTOCOL_VERSION response details.
*/
struct DfuResponseProtocol
{
uint8_t version;
};
struct DfuResponseHardwareMemory
{
uint32_t rom_size;
uint32_t ram_size;
uint32_t rom_page_size;
};
/**
* @brief @ref NRF_DFU_OP_HARDWARE_VERSION response details.
*/
struct DfuResponseHardware
{
uint32_t part;
uint32_t variant;
DfuResponseHardwareMemory memory;
};
/**
* @brief @ref NRF_DFU_OP_FIRMWARE_VERSION response details.
*/
struct DfuResponseFirmware
{
DfuFirmwareType type;
uint32_t version;
uint32_t addr;
uint32_t len;
};
/**
* @brief @ref NRF_DFU_OP_OBJECT_SELECT response details.
*/
struct DfuResponseSelect
{
uint32_t offset;
uint32_t crc;
uint32_t max_size;
};
/**
* @brief @ref NRF_DFU_OP_OBJECT_CREATE response details.
*/
struct DfuResponseCreate
{
uint32_t offset;
uint32_t crc;
};
/**
* @brief @ref NRF_DFU_OP_OBJECT_WRITE response details.
*/
struct DfuResponseWrite
{
uint32_t offset;
uint32_t crc;
};
/**
* @brief @ref NRF_DFU_OP_CRC_GET response details.
*/
struct DfuResponseCrc
{
uint32_t offset;
uint32_t crc;
};
/**
* @brief @ref NRF_DFU_OP_PING response details.
*/
struct DfuResponsePing
{
uint8_t id;
};
/**
* @brief @ref NRF_DFU_OP_MTU_GET response details.
*/
struct DfuResponseMtu
{
uint16_t size;
};
using DfuResponseType = std::variant<DfuResponseProtocol,
DfuResponseHardware,
DfuResponseFirmware,
DfuResponseSelect,
DfuResponseCreate,
DfuResponseWrite,
DfuResponseCrc,
DfuResponsePing,
DfuResponseMtu>;
/**
* @brief DFU response message.
*/
struct DfuResponse
{
DfuResponse() = default;
~DfuResponse() = default;
DfuOpcode opcode;
DfuResult result;
std::optional<DfuResponseType> response;
};
struct DfuResponseWrapper
{
DfuResponse rsp;
};
/**
* @brief @ref NRF_DFU_OP_FIRMWARE_VERSION request details.
*/
struct DfuRequestFirmware
{
uint8_t image_number;
};
/**
* @brief @ref NRF_DFU_OP_OBJECT_SELECT request details.
*/
struct DfuRequestSelect
{
uint32_t object_type;
};
/**
* @brief @ref NRF_DFU_OP_OBJECT_CREATE request details.
*/
struct DfuRequestCreate
{
uint32_t object_type;
uint32_t object_size;
};
/**
* @brief @ref NRF_DFU_OP_OBJECT_WRITE request details.
*/
struct DfuRequestWrite
{
DfuRequestWrite(){};
std::vector<uint8_t> data;
uint16_t len;
};
/**
* @brief @ref NRF_DFU_OP_PING request details.
*/
struct DfuRequestPing
{
uint8_t id;
};
/**
* @brief @ref NRF_DFU_OP_MTU_GET request details.
*/
struct DfuRequestMtu
{
uint16_t size;
};
/**
* @brief @ref NRF_DFU_OP_RECEIPT_NOTIF_SET request details.
*/
struct DfuRequestPrn
{
uint32_t target;
};
using DfuRequestType = std::variant<DfuRequestFirmware,
DfuRequestSelect,
DfuRequestCreate,
DfuRequestWrite,
DfuRequestPing,
DfuRequestMtu,
DfuRequestPrn>;
/**
*@brief DFU request.
*/
struct DfuRequest
{
DfuOpcode opcode;
std::optional<DfuRequestType> request;
};
struct DfuRequestWrapper
{
DfuRequest req;
};
} // namespace NRFDL::SDFU