summaryrefslogtreecommitdiff
path: root/common/pstore_commands.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-07-11 11:18:17 -0700
committerGerrit <chrome-bot@google.com>2012-07-11 14:46:30 -0700
commit07ca0977fe554696288048c5c691aa5b9cfa7ac8 (patch)
treeaade5d33536338c2baa869c1865e4eb11b390e3e /common/pstore_commands.c
parent61e0e5508a559cc9935951be4f68455809300a2e (diff)
downloadchrome-ec-07ca0977fe554696288048c5c691aa5b9cfa7ac8.tar.gz
Refactor API for host commands, and handle variable length data better
Added version mask field to DECLARE_HOST_COMMAND() because it's convenient to do so when I'm touching all host command implementations, but all commands simply declare version 0 and nothing checks it yet. Will add version support in a followup CL. This change is internal to the EC; it does not change the data sent over the host interface. BUG=chrome-os-partner:11275 TEST=manual ectool version && ectool echash; should get sane data from both ectool flashread 0x80 0x40 /tmp/foo && od -tx1 /tmp/foo should match data from offset 0x80 of ec.bin (od -j128 -n64 -tx1 ec.bin) Change-Id: I5699f72b8d5e1ac23929353c9a34158d76c44206 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/27172 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'common/pstore_commands.c')
-rw-r--r--common/pstore_commands.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/common/pstore_commands.c b/common/pstore_commands.c
index fdd0eaf26c..9717d3ccdb 100644
--- a/common/pstore_commands.c
+++ b/common/pstore_commands.c
@@ -5,42 +5,40 @@
/* Persistent storage commands for Chrome EC */
-#include "board.h"
+#include "common.h"
#include "eeprom.h"
#include "host_command.h"
#include "util.h"
-
-int pstore_command_get_info(uint8_t *data, int *resp_size)
+int pstore_command_get_info(struct host_cmd_handler_args *args)
{
struct ec_response_pstore_info *r =
- (struct ec_response_pstore_info *)data;
+ (struct ec_response_pstore_info *)args->response;
ASSERT(EEPROM_BLOCK_START_PSTORE + EEPROM_BLOCK_COUNT_PSTORE <=
eeprom_get_block_count());
r->pstore_size = EEPROM_BLOCK_COUNT_PSTORE * eeprom_get_block_size();
r->access_size = sizeof(uint32_t);
- *resp_size = sizeof(struct ec_response_pstore_info);
+ args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PSTORE_INFO, pstore_command_get_info);
-
+DECLARE_HOST_COMMAND(EC_CMD_PSTORE_INFO,
+ pstore_command_get_info,
+ EC_VER_MASK(0));
-int pstore_command_read(uint8_t *data, int *resp_size)
+int pstore_command_read(struct host_cmd_handler_args *args)
{
- struct ec_params_pstore_read *p =
- (struct ec_params_pstore_read *)data;
- struct ec_response_pstore_read *r =
- (struct ec_response_pstore_read *)data;
- char *dest = r->data;
+ const struct ec_params_pstore_read *p =
+ (const struct ec_params_pstore_read *)args->params;
+ char *dest = args->response;
int block_size = eeprom_get_block_size();
int block = p->offset / block_size + EEPROM_BLOCK_COUNT_PSTORE;
int offset = p->offset % block_size;
int bytes_left = p->size;
- if (p->size > sizeof(r->data))
- return EC_RES_ERROR;
+ if (p->size > sizeof(EC_PARAM_SIZE))
+ return EC_RES_INVALID_PARAM;
while (bytes_left) {
/* Read what we can from the current block */
@@ -60,16 +58,17 @@ int pstore_command_read(uint8_t *data, int *resp_size)
dest += bytes_this;
}
- *resp_size = sizeof(struct ec_response_pstore_read);
+ args->response_size = p->size;
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PSTORE_READ, pstore_command_read);
-
+DECLARE_HOST_COMMAND(EC_CMD_PSTORE_READ,
+ pstore_command_read,
+ EC_VER_MASK(0));
-int pstore_command_write(uint8_t *data, int *resp_size)
+int pstore_command_write(struct host_cmd_handler_args *args)
{
- struct ec_params_pstore_write *p =
- (struct ec_params_pstore_write *)data;
+ const struct ec_params_pstore_write *p =
+ (const struct ec_params_pstore_write *)args->params;
const char *src = p->data;
int block_size = eeprom_get_block_size();
@@ -100,4 +99,6 @@ int pstore_command_write(uint8_t *data, int *resp_size)
return EC_RES_SUCCESS;
}
-DECLARE_HOST_COMMAND(EC_CMD_PSTORE_WRITE, pstore_command_write);
+DECLARE_HOST_COMMAND(EC_CMD_PSTORE_WRITE,
+ pstore_command_write,
+ EC_VER_MASK(0));