| 1 |
|
| 2 |
|
| 3 |
#include <stdint.h> |
| 4 |
#include <string.h> |
| 5 |
#include "ec.h" |
| 6 |
#include "ec_commands.h" |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
int google_chromeec_vstore_supported(void) |
| 12 |
{ |
| 13 |
return google_chromeec_check_feature(EC_FEATURE_VSTORE); |
| 14 |
} |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
int google_chromeec_vstore_info(uint32_t *locked) |
| 23 |
{ |
| 24 |
struct ec_response_vstore_info info; |
| 25 |
struct chromeec_command cmd = { |
| 26 |
.cmd_code = EC_CMD_VSTORE_INFO, |
| 27 |
.cmd_size_out = sizeof(info), |
| 28 |
.cmd_data_out = &info, |
| 29 |
}; |
| 30 |
|
| 31 |
if (google_chromeec_command(&cmd) != 0) |
| 32 |
return 0; |
| 33 |
|
| 34 |
if (locked) |
| 35 |
*locked = info.slot_locked; |
| 36 |
return info.slot_count; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
int google_chromeec_vstore_read(int slot, uint8_t *data) |
| 46 |
{ |
| 47 |
struct ec_params_vstore_read req = { |
| 48 |
.slot = slot, |
| 49 |
}; |
| 50 |
struct chromeec_command cmd = { |
| 51 |
.cmd_code = EC_CMD_VSTORE_READ, |
| 52 |
.cmd_size_in = sizeof(req), |
| 53 |
.cmd_data_in = &req, |
| 54 |
.cmd_size_out = EC_VSTORE_SLOT_SIZE, |
| 55 |
.cmd_data_out = data, |
| 56 |
}; |
| 57 |
|
| 58 |
if (!data || req.slot >= EC_VSTORE_SLOT_MAX) |
| 59 |
return -1; |
| 60 |
|
| 61 |
return google_chromeec_command(&cmd); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
int google_chromeec_vstore_write(int slot, uint8_t *data, size_t size) |
| 76 |
{ |
| 77 |
struct ec_params_vstore_write req = { |
| 78 |
.slot = slot, |
| 79 |
}; |
| 80 |
struct chromeec_command cmd = { |
| 81 |
.cmd_code = EC_CMD_VSTORE_WRITE, |
| 82 |
.cmd_size_in = sizeof(req), |
| 83 |
.cmd_data_in = &req, |
| 84 |
}; |
| 85 |
|
| 86 |
if (req.slot >= EC_VSTORE_SLOT_MAX || size > EC_VSTORE_SLOT_SIZE) |
| 87 |
return -1; |
| 88 |
|
| 89 |
memcpy(req.data, data, size); |
| 90 |
|
| 91 |
return google_chromeec_command(&cmd); |
| 92 |
} |