-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcerberus_utility_commands_internal.c
290 lines (242 loc) · 8.26 KB
/
cerberus_utility_commands_internal.c
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "cerberus_utility_common.h"
#include "cerberus_utility_interface.h"
#include "cerberus_utility_commands_internal.h"
#include "cerberus_utility_cerberus_protocol.h"
#include "cerberus_utility_status_codes.h"
extern const char *spi_filter_messages_str[];
extern const char *manifest_cmd_statuses_str[];
/**
* Retrieve and optionally print Cerberus manifest update status
*
* @param intf The Cerberus interface to utilize
* @param manifest Type of manifest to get update status for
* @param update_status Output buffer for the update status
*
* @return STATUS_SUCCESS if operation completed successfully or an error code.
*/
int cerberus_get_manifest_update_status (struct cerberus_interface *intf,
struct cerberus_manifest_request *manifest, struct cerberus_fw_update_status *update_status)
{
char manifest_string[8];
char errorstr[CERBERUS_MAX_MSG_LEN] = "";
uint32_t manifest_update_status;
int status;
if (intf == NULL) {
return STATUS_INVALID_INPUT;
}
if ((manifest == NULL) || (update_status == NULL)) {
cerberus_print_error (intf->cmd_err_msg, sizeof (intf->cmd_err_msg), __func__, __LINE__,
cerberus_utility_get_errors_str (STATUS_INVALID_INPUT));
return STATUS_INVALID_INPUT;
}
switch (manifest->manifest_type) {
case CERBERUS_MANIFEST_PFM:
intf->cmd_buf[0] = CERBERUS_PFM_UPDATE_STATUS;
intf->cmd_buf[1] = manifest->port;
strcpy (manifest_string, "PFM");
break;
case CERBERUS_MANIFEST_CFM:
intf->cmd_buf[0] = CERBERUS_CFM_UPDATE_STATUS;
strcpy (manifest_string, "CFM");
break;
case CERBERUS_MANIFEST_PCD:
intf->cmd_buf[0] = CERBERUS_PCD_UPDATE_STATUS;
strcpy (manifest_string, "PCD");
break;
default:
cerberus_print_error (intf->cmd_err_msg, sizeof (intf->cmd_err_msg), __func__, __LINE__,
cerberus_utility_get_errors_str (STATUS_INVALID_INPUT));
return STATUS_INVALID_INPUT;
}
status = cerberus_protocol_send_and_read_rsp (intf, __func__, __LINE__,
CERBERUS_PROTOCOL_GET_UPDATE_STATUS, intf->params->device_eid, sizeof (uint32_t), false,
intf->cmd_buf, sizeof (uint8_t) + sizeof (manifest->port));
if (status != STATUS_SUCCESS) {
return status;
}
memcpy (&manifest_update_status, intf->cmd_buf, sizeof (uint32_t));
update_status->status_code = manifest_update_status & 0xFF;
update_status->status_code_module = manifest_update_status >> 8;
if (update_status->status_code < NUM_MANIFEST_CMD_STATUS) {
snprintf (errorstr, sizeof (errorstr),
manifest_cmd_statuses_str[update_status->status_code],
update_status->status_code_module);
snprintf (update_status->status_str, sizeof (update_status->status_str), "%s", errorstr);
}
else {
snprintf (update_status->status_str, sizeof (update_status->status_str), "0x%x",
manifest_update_status);
}
if (intf->params->debug_level & CERBERUS_DEBUG_CMD) {
cerberus_print_info ("%s update status: %i\n", manifest_string, manifest_update_status);
}
return STATUS_SUCCESS;
}
/**
* Complete a Cerberus PFM update.
*
* @param intf The Cerberus interface to utilize
* @param pfm_port The struct containing port and activate setting. Set activate_setting 0 to
* activate PFM after host reboot, 1 to activate immediately
* @param suppress_msg Flag indicating if PFM messages need to be suppressed
* @param update_status Output buffer to be filled with update status
*
* @return STATUS_SUCCESS if operation completed successfully or an error code.
*/
int cerberus_validate_host_update (struct cerberus_interface *intf,
struct cerberus_pfm_activate *pfm, bool suppress_msg,
struct cerberus_fw_update_status *update_status)
{
struct cerberus_manifest_request manifest;
uint32_t flash_error_status_code = 0;
uint32_t status_code;
unsigned long start_time;
bool flash_error = false;
bool started_activating = false;
int status;
intf->cmd_buf[0] = pfm->port;
intf->cmd_buf[1] = pfm->activate_setting;
status = cerberus_protocol_send_no_rsp (intf, __func__, __LINE__,
CERBERUS_PROTOCOL_COMPLETE_PFM_UPDATE, intf->params->device_eid, false, intf->cmd_buf, 2);
if (status != STATUS_SUCCESS) {
return status;
}
start_time = cerberus_common_get_cpu_time_ms ();
manifest.port = pfm->port;
manifest.manifest_type = CERBERUS_MANIFEST_PFM;
while (1) {
status = cerberus_get_manifest_update_status (intf, &manifest, update_status);
if (status != STATUS_SUCCESS) {
return status;
}
status_code = update_status->status_code_module;
switch (update_status->status_code) {
case MANIFEST_CMD_STATUS_SUCCESS:
if (!suppress_msg) {
snprintf (intf->cmd_err_msg, sizeof (intf->cmd_err_msg),
"PFM update completed successfully\n");
}
return STATUS_SUCCESS;
case MANIFEST_CMD_STATUS_STARTING:
case MANIFEST_CMD_STATUS_VALIDATION:
if (!pfm->activate_setting &&
cerberus_common_timeout_expired (start_time,
CERBERUS_CMD_TIMEOUT_VAL_S * 1000)) {
cerberus_print_error (intf->cmd_err_msg, sizeof (intf->cmd_err_msg),
__func__, __LINE__,
cerberus_utility_get_errors_str (STATUS_OPERATION_TIMEOUT));
return STATUS_OPERATION_TIMEOUT;
}
cerberus_common_sleep_ms (50);
continue;
case MANIFEST_CMD_STATUS_ACTIVATING:
if (!started_activating && !suppress_msg) {
cerberus_print_info ("Starting runtime activation of PFM.\n");
started_activating = true;
}
flash_error = false;
cerberus_common_sleep_ms (50);
continue;
case MANIFEST_CMD_STATUS_ACTIVATION_PENDING:
snprintf (intf->cmd_err_msg, sizeof (intf->cmd_err_msg),
"PFM update completed successfully, activation requires host reboot.\n");
return STATUS_SUCCESS;
case MANIFEST_CMD_STATUS_ACTIVATION_FLASH_ERROR:
if (!flash_error || (status_code != flash_error_status_code)) {
flash_error = true;
flash_error_status_code = status_code;
if (!suppress_msg) {
cerberus_print_info (
"%s. Attempting to correct error, please do not exit utility as that will keep ME in recovery mode.\n",
update_status->status_str);
}
else {
cerberus_print_info ("%s\n", update_status->status_str);
}
cerberus_common_sleep_ms (50);
}
start_time = cerberus_common_get_cpu_time_ms ();
continue;
default:
if (!suppress_msg || (status_code != 0x1d09)) {
snprintf (intf->cmd_err_msg, sizeof (intf->cmd_err_msg),
"PFM update failed: %s", update_status->status_str);
return STATUS_UPDATE_FAILURE;
}
else {
snprintf (update_status->status_str, sizeof (update_status->status_str),
"No PFM available. No update verification could be performed.");
return STATUS_SUCCESS;
}
}
}
return status;
}
/**
* Parse the SPI filter configuration log entry and generate the message.
*
* @param port The port identifier.
* @param config The bit field indicating the filter configuration.
* @param message Output buffer for the formatted message.
* @param max_message Size of the message buffer.
*/
void cerberus_format_filter_config_entry (uint32_t port, uint32_t config, char *message,
size_t max_message)
{
const char *bypass = "disabled";
const char *addr = "";
const char *mode = "";
switch (config & (3U << 12)) {
case (1U << 12):
bypass = "full CS0";
break;
case (1U << 13):
bypass = "full CS1";
break;
default:
if (config & (1U << 14)) {
bypass = "R/W";
}
break;
}
switch (config & ((1U << 10) | (1U << 15))) {
case 0:
addr = "3-byte";
break;
case (1U << 10):
addr = "4-byte";
break;
case (1U << 15):
addr = "fixed 3-byte";
break;
case ((1U << 10) | (1U << 15)):
addr = "fixed 4-byte";
break;
}
switch (config & (7U << 18)) {
case 0:
mode = "dual";
break;
case (1U << 18):
case (2U << 18):
mode = "bypass";
break;
case (3U << 18):
mode = "single CS0";
break;
case (4U << 18):
mode = "single CS1";
break;
}
snprintf (message, max_message, spi_filter_messages_str[SPI_FILTER_LOGGING_FILTER_CONFIG], port,
(config & 0xff), (config & (1U << 8)) ? "enabled" : "disabled", !!(config & (1U << 9)),
addr, (config & (1U << 16)) ? "4-byte" : "3-byte", !!(config & (1U << 17)),
!!(config & (1U << 11)), bypass, mode, (config & (1U << 21)) ? "full" : "R/W only");
}