Tim Wawrzynczak has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 333 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/1
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index 7c294b6..0c9f3ab 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -33,6 +33,7 @@ #include "ec_commands.h"
#define INVALID_HCMD 0xFF +#define EC_VER_MASK(version) BIT(version)
/* * Map UHEPI masks to non UHEPI commands in order to support old EC FW @@ -498,6 +499,299 @@ return r.flags[feature / 32] & EC_FEATURE_MASK_0(feature); }
+int google_chromeec_get_cmd_versions(int command, uint32_t *pmask) +{ + struct chromeec_command cmd; + struct ec_params_get_cmd_versions_v1 params = { + .cmd = command, + }; + struct ec_response_get_cmd_versions resp; + + *pmask = 0; + + cmd.cmd_code = EC_CMD_GET_CMD_VERSIONS; + cmd.cmd_version = 1; + cmd.cmd_size_in = sizeof(params); + cmd.cmd_data_in = ¶ms; + cmd.cmd_size_out = sizeof(resp); + cmd.cmd_data_out = &resp; + cmd.cmd_dev_index = 0; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + *pmask = resp.version_mask; + return 0; +} + +/** + * Return non-zero if the EC supports the command and version + * + * @param cmd Command to check + * @param ver Version to check + * @return non-zero if command version supported; 0 if not. + */ +static int cmd_version_supported(int cmd, int ver) +{ + uint32_t mask = 0; + + if (google_chromeec_get_cmd_versions(cmd, &mask)) + return 0; + + return (mask & EC_VER_MASK(ver)) ? 1 : 0; +} + +int google_chromeec_get_vboot_hash(u32 offset, + struct ec_response_vboot_hash *resp) +{ + struct chromeec_command cmd; + struct ec_params_vboot_hash params = { + .cmd = EC_VBOOT_HASH_GET, + .offset = offset, + }; + + cmd.cmd_code = EC_CMD_VBOOT_HASH; + cmd.cmd_version = 0; + cmd.cmd_size_in = sizeof(params); + cmd.cmd_data_in = ¶ms; + cmd.cmd_size_out = sizeof(*resp); + cmd.cmd_data_out = resp; + cmd.cmd_dev_index = 0; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + return 0; +} + +int google_chromeec_start_vboot_hash(enum ec_vboot_hash_type hash_type, + u32 hash_offset, + struct ec_response_vboot_hash *resp) +{ + struct chromeec_command cmd; + struct ec_params_vboot_hash params = { + .cmd = EC_VBOOT_HASH_START, + .hash_type = hash_type, + .nonce_size = 0, + .offset = hash_offset, + }; + + cmd.cmd_code = EC_CMD_VBOOT_HASH; + cmd.cmd_version = 0; + cmd.cmd_size_in = sizeof(params); + cmd.cmd_data_in = ¶ms; + cmd.cmd_size_out = sizeof(*resp); + cmd.cmd_data_out = resp; + cmd.cmd_dev_index = 0; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + return 0; +} + +int google_chromeec_flash_protect(u32 mask, u32 flags, + struct ec_response_flash_protect *resp) +{ + struct chromeec_command cmd; + struct ec_params_flash_protect params = { + .mask = mask, + .flags = flags, + }; + + cmd.cmd_code = EC_CMD_FLASH_PROTECT; + cmd.cmd_version = EC_VER_FLASH_PROTECT; + cmd.cmd_size_in = sizeof(params); + cmd.cmd_data_in = ¶ms; + cmd.cmd_size_out = sizeof(*resp); + cmd.cmd_data_out = resp; + cmd.cmd_dev_index = 0; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + return 0; +} + +int google_chromeec_flash_region_info(enum ec_flash_region region, u32 *offset, + u32 *size) +{ + struct chromeec_command cmd; + struct ec_params_flash_region_info params = { + .region = region, + }; + struct ec_response_flash_region_info resp; + + cmd.cmd_code = EC_CMD_FLASH_REGION_INFO; + cmd.cmd_version = EC_VER_FLASH_REGION_INFO; + cmd.cmd_size_in = sizeof(params); + cmd.cmd_data_in = ¶ms; + cmd.cmd_size_out = sizeof(resp); + cmd.cmd_data_out = &resp; + cmd.cmd_dev_index = 0; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + if (offset) + *offset = resp.offset; + if (size) + *size = resp.size; + + return 0; +} + +int google_chromeec_flash_erase(u32 region_offset, u32 region_size) +{ + struct chromeec_command cmd; + struct ec_params_flash_erase params = { + .offset = region_offset, + .size = region_size, + }; + + cmd.cmd_code = EC_CMD_FLASH_ERASE; + cmd.cmd_version = 0; + cmd.cmd_size_in = sizeof(params); + cmd.cmd_data_in = ¶ms; + cmd.cmd_size_out = 0; + cmd.cmd_data_out = NULL; + cmd.cmd_dev_index = 0; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + return 0; +} + +int google_chromeec_flash_info(struct ec_response_flash_info *info) +{ + struct chromeec_command cmd; + + cmd.cmd_code = EC_CMD_FLASH_INFO; + cmd.cmd_version = 0; + cmd.cmd_size_in = 0; + cmd.cmd_data_in = NULL; + cmd.cmd_size_out = sizeof(*info); + cmd.cmd_data_out = info; + cmd.cmd_dev_index = 0; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + return 0; +} + +int google_chromeec_flash_write_burst_size(void) +{ + struct ec_response_flash_info info; + uint32_t pdata_max_size = (EC_LPC_HOST_PACKET_SIZE - + sizeof(struct ec_params_flash_write)) - + sizeof(struct ec_host_request); + + /* + * Determine whether we can use version 1 of the command with more + * data, or only version 0. + */ + if (!cmd_version_supported(EC_CMD_FLASH_WRITE, EC_VER_FLASH_WRITE)) + return EC_FLASH_WRITE_VER0_SIZE; + + /* + * Determine step size. This must be a multiple of the write block + * size, and must also fit into the host parameter buffer. + */ + if (google_chromeec_flash_info(&info)) + return 0; + + return (pdata_max_size / info.write_block_size) * info.write_block_size; +} + +/* Write a block into EC flash */ +int google_chromeec_flash_write_block(const u8 *data, u32 offset, u32 size) +{ + uint8_t *buf; + struct ec_params_flash_write *p; + uint32_t bufsize = sizeof(*p) + size; + int rv; + struct chromeec_command cmd; + + assert(data); + + /* Make sure request fits in the allowed packet size */ + if (bufsize > EC_LPC_HOST_PACKET_SIZE) + return -1; + + buf = crosec_get_buffer(bufsize, 0); + if (buf == NULL) + return -1; + + p = (struct ec_params_flash_write *)buf; + p->offset = offset; + p->size = size; + memcpy(p + 1, data, size); + + cmd.cmd_code = EC_CMD_FLASH_WRITE; + cmd.cmd_version = EC_VER_FLASH_WRITE; + cmd.cmd_size_in = bufsize; + cmd.cmd_data_in = buf; + cmd.cmd_size_out = 0; + cmd.cmd_data_out = NULL; + cmd.cmd_dev_index = 0; + + rv = google_chromeec_command(&cmd); + + return rv; +} + +/* EFS verification of flash */ +int google_chromeec_efs_verify(enum ec_flash_region region) +{ + struct chromeec_command cmd; + struct ec_params_efs_verify params = { + .region = region, + }; + int rv; + + cmd.cmd_code = EC_CMD_EFS_VERIFY; + cmd.cmd_version = 0; + cmd.cmd_size_in = sizeof(params); + cmd.cmd_data_in = ¶ms; + cmd.cmd_size_out = 0; + cmd.cmd_data_out = NULL; + cmd.cmd_dev_index = 0; + + /* It's okay if the EC doesn't support EFS */ + rv = google_chromeec_command(&cmd); + if (rv != 0 && (cmd.cmd_code == EC_RES_INVALID_COMMAND)) { + return 0; + } + + return rv; +} + +int google_chromeec_test(void) +{ + struct chromeec_command cmd; + struct ec_params_hello params = { + .in_data = 0x12345678, + }; + struct ec_response_hello resp = {}; + int rv; + + cmd.cmd_code = EC_CMD_HELLO; + cmd.cmd_version = 0; + cmd.cmd_size_in = sizeof(params); + cmd.cmd_data_in = ¶ms; + cmd.cmd_size_out = sizeof(resp); + cmd.cmd_data_out = &resp; + cmd.cmd_dev_index = 0; + + rv = google_chromeec_command(&cmd); + if (rv || (resp.out_data != params.in_data + 0x01020304)) + return -1; + + return 0; +} + int google_chromeec_set_sku_id(u32 skuid) { struct chromeec_command cmd; diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h index 019f9c1..20e5bec 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -178,4 +178,43 @@ /* Log host events to eventlog based on the mask provided. */ void google_chromeec_log_events(uint64_t mask);
+/* + * The following functions are for vboot EC software sync. + * They return 0 on success, non-zero for failure. + */ + +/* Protect/un-protect EC flash regions */ +int google_chromeec_flash_protect(u32 mask, u32 flags, + struct ec_response_flash_protect *resp); +/* Calculate image hash for vboot */ +int google_chromeec_start_vboot_hash(enum ec_vboot_hash_type hash_type, + u32 offset, + struct ec_response_vboot_hash *resp); +/* Return the vboot image hash */ +int google_chromeec_get_vboot_hash(u32 offset, + struct ec_response_vboot_hash *resp); +/* Get offset and size of the specified flash region */ +int google_chromeec_flash_region_info(enum ec_flash_region region, u32 *offset, + u32 *size); +/* Erase a region of flash */ +int google_chromeec_flash_erase(u32 region_offset, u32 region_size); + +/* Return information about the entire flash */ +int google_chromeec_flash_info(struct ec_response_flash_info *info); + +/* Verify flash using EFS if available */ +int google_chromeec_efs_verify(enum ec_flash_region region); + +/* Get available versions of the specified command */ +int google_chromeec_get_cmd_versions(int command, uint32_t *pmask); + +/* Test if the EC is responding */ +int google_chromeec_test(void); + +/* Get the EC's flash write burst size */ +int google_chromeec_flash_write_burst_size(void); + +/* Write a block into EC flash */ +int google_chromeec_flash_write_block(const u8 *data, u32 offset, u32 size); + #endif /* _EC_GOOGLE_CHROMEEC_EC_H */
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36207
to look at the new patch set (#2).
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 333 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/2
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 764: if (rv != 0 && (cmd.cmd_code == EC_RES_INVALID_COMMAND)) { braces {} are not necessary for single statement blocks
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 2:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 720: EC_LPC_HOST_PACKET_SIZE You can't check an LPC-specific constant in common code.
The depthcharge version we run EC_CMD_GET_PROTOCOL_INFO to figure out the maximum buffer size, and you must do the same. In some cases it may be smaller than you expect (e.g. some SPI NPCX have a bug with returning data after the 256th byte, so we have to restrict the response packet size to that or end up getting errors).
In general, I think we have an overall problem with request/response buffers which it would be better to solve first. Right now we just have a static array to copy into in most drivers (and you're trying to add one for LPC as well), which is inefficient in both speed and memory use. It would be much better if we could just send data from and receive it into the buffer used by the upper application layer directly. We already have the command and the data separated in most parts of the API, it's just create_proto3_request() where the data is copied behind the command in the end. There should be really no need for that... for all our transfer protocols, it doesn't matter whether you send one big buffer or two small ones. If we pull the handling of the data buffers into the individual protocol handlers, we shouldn't need the intermediary transfer buffer anymore, we can directly send from and receive into what we were given.
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 771: int google_chromeec_test(void) There's already a google_chromeec_hello().
Joel Kitching has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 2:
(4 comments)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h File src/ec/google/chromeec/ec.h:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h... PS2, Line 189: /* Please be consistent with line breaks in between function headers.
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h... PS2, Line 191: u32 o Arguments should line up with "(".
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h... PS2, Line 198: u32 I'm not totally sure if coreboot specifies that u32 or uint32_t format should be used, but seems like the latter is more common in this file?
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 36: EC_VER_MASK I don't see "ver" as a very common abbreviation; how about just EC_VERSION_MASK?
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 2:
(3 comments)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 36: EC_VER_MASK
I don't see "ver" as a very common abbreviation; how about just EC_VERSION_MASK?
Done
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 720: EC_LPC_HOST_PACKET_SIZE
You can't check an LPC-specific constant in common code.
Ack. I missed that, my bad.
The depthcharge version...
Understood, will add support for that.
In general...
I understand what you're saying here. However, the LPC driver does actually use the "command" buffer the user provides directly, and does not invoke crosec_proto; google_chromeec_command() passes the struct chromeec_command* directly to google_chromeec_command_v3 for example, which calls write_bytes(), which directly writes to the LPC port, no copying involved. The SPI and I2C drivers do use crosec_proto which does the copying you reference. This seems like an issue with the crosec_proto driver in particular, not this code. Let me spend a little time looking this over.
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 771: int google_chromeec_test(void)
There's already a google_chromeec_hello().
That's fair, I'll remove the static declaration and add the check that it returns the correct modification to 'in_data'.
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 2:
(3 comments)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h File src/ec/google/chromeec/ec.h:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h... PS2, Line 189: /*
Please be consistent with line breaks in between function headers.
Sure, my bad.
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h... PS2, Line 191: u32 o
Arguments should line up with "(".
Ugh, I need to fix my emacs indentation setup.
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h... PS2, Line 198: u32
I'm not totally sure if coreboot specifies that u32 or uint32_t format should be used, but seems lik […]
This file already used both styles (see google_chromeec_i2c_xfer vs. google_chromeec_set_sku_id). I'll pick one and clean it up.
Karthik Ramasubramanian has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 2:
(3 comments)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h File src/ec/google/chromeec/ec.h:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h... PS2, Line 183: non-zero Is it non-zero or less than 0? I believe it is < 0, since that will align well with what google_chromeec_flash_write_burst_size() can return.
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 504: cmd; Can you please initialize all the command/request & response with either either zero or some safe value? That will avoid any surprises, especially EC might use some fields to tailor the response. Same goes for all the commands here.
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 510: *pmask = 0; Prefer to set the pmask only if there is a valid response. Otherwise we can leave it as is. The return code will help caller identify there was an error.
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 2:
(3 comments)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h File src/ec/google/chromeec/ec.h:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h... PS2, Line 198: u32
This file already used both styles (see google_chromeec_i2c_xfer vs. google_chromeec_set_sku_id). […]
It's okay to use either but consistency within the same file is appreciated.
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 504: cmd;
Can you please initialize all the command/request & response with either either zero or some safe va […]
This follows existing practice in this file but I agree that it's a bit dicey. Maybe we should just fix the whole file to use static initializer notation rather than assigning members individually? That guarantees that unspecified fields will be 0.
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 720: EC_LPC_HOST_PACKET_SIZE
You can't check an LPC-specific constant in common code. […]
Hmm... yeah, I guess that's more of a tangential problem with the I2C and SPI drivers. The real problem here is that you have to prepend 8 bytes of data in front of the transfer buffer and the API doesn't really let you do that. (The way you're using crosec_get_buffer() here is really wrong btw, that would blow up for SPI and I2C. create_proto3_request() expects to be able to use that buffer for the whole packet, including command header.)
I just don't like adding extra static buffers in pre-RAM environments when we can avoid it. Maybe a simple option for now would be to alloca() the packet buffer on the stack (enforcing a reasonable max limit, like 1K)? Really, the right way to solve it would be to overhaul this whole API so that you can pass a sequence of at least 2 data pointers which will be sent back to back by the transfer function, but I guess that would be a bigger task. (Also, why does the LPC driver not use crosec_proto.c? It's just reimplementing the same protocol again, would be really useful if we could merge that somehow...)
The depthcharge version...
Understood, will add support for that.
So thinking about this a bit more, one of the problems in coreboot is always that we can't (easily) persist global variables across stage transitions. This means that if we were to query the transfer buffer size dynamically, we would have to query it again in every stage, which is a bunch of unnecessary overhead. Really, other than flashing I don't think we do any EC transfers larger than 256 bytes (which is the default that should work for all ECs).
So I think we should implement support for GET_PROTOCOL_INFO (because it should make flashing faster), but I think we should only use it for flashing and we should stick with the default transfer size in all other cases. We should not always run it immediately on initialization like depthcharge.
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 2:
(3 comments)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 504: cmd;
This follows existing practice in this file but I agree that it's a bit dicey. […]
Good idea, I like the static init notation, I'll switch to that.
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 510: *pmask = 0;
Prefer to set the pmask only if there is a valid response. Otherwise we can leave it as is. […]
Ack
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 720: EC_LPC_HOST_PACKET_SIZE
I just don't like adding extra...
I can appreciate that. I'm fine with using alloca() for the buffer. Makes me curious what the stack size is in romstage for newer archs, I'll have to look at that. I also agree some API changes would make everything cleaner. You can absolutely feel free to file feature requests and assign them to me, I would be happy to work on code cleanup as I have time.
So I think we should...
Ack.
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 2:
(4 comments)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 36: EC_VER_MASK
Done
This is already defined in https://review.coreboot.org/cgit/coreboot.git/tree/src/ec/google/chromeec/ec.... Can we just use that directly?
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 502: int Probably okay to make this static? I believe it will be used only by the functions in this file just like cmd_version_supported()
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 544: offset It will be helpful to have comments indicating what the params mean for this and the other functions you are adding.
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 720: EC_LPC_HOST_PACKET_SIZE
Really, the right way to solve it would be to overhaul this whole API so that you can pass a sequence of at least 2 data pointers which will be sent back to back by the transfer function, but I guess that would be a bigger task
We can potentially add a google_chromeec_command_data_arr() [Sorry, couldn't think of a better name right now] that takes as input array of data_in pointers and size pointers and does the same work that crosec_proto or ec_lpc is doing i.e. package bytes correctly or write bytes to LPC port by iterating over the data pointer array. google_chromeec_command() can be moved to ec.c and that can call the same function(google_chromeec_command_data_arr) with a single element array for data_in and size_in. But yeah, that can be done separately.
I'm fine with using alloca() for the buffer. Makes me curious what the stack size is in romstage for newer archs, I'll have to look at that.
For the stack, you can find details in Kconfig for CML: https://review.coreboot.org/cgit/coreboot.git/tree/src/soc/intel/cannonlake/...
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 2:
(5 comments)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h File src/ec/google/chromeec/ec.h:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h... PS2, Line 183: non-zero
Is it non-zero or less than 0? I believe it is < 0, since that will align well with what google_chro […]
I'll just add docs for each one individually, how about that :)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 36: EC_VER_MASK
This is already defined in https://review.coreboot.org/cgit/coreboot. […]
Ah yes, of course. Wonder why I didn't get a warning for a duplicate #define then...
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 502: int
Probably okay to make this static? I believe it will be used only by the functions in this file just […]
Done
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 544: offset
It will be helpful to have comments indicating what the params mean for this and the other functions […]
Next version has header comments in the .h file for all the functions I added :)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 720: EC_LPC_HOST_PACKET_SIZE
For the stack, you ...
Yeah, I remember that change to CML :-) 129KiB! IIRC Intel measured ~400 bytes when FSP-M got called.
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h File src/ec/google/chromeec/ec.h:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.h... PS2, Line 183: non-zero
Is it non-zero or less than 0? I believe it is < 0, since that will align well with what google_chro […]
How about I just document them all individually :)
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36207
to look at the new patch set (#3).
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 374 insertions(+), 23 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/3
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36207
to look at the new patch set (#4).
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 374 insertions(+), 23 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/4
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36207
to look at the new patch set (#5).
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 365 insertions(+), 6 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/5
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36207
to look at the new patch set (#6).
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 457 insertions(+), 19 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/6
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36207
to look at the new patch set (#7).
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 457 insertions(+), 19 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/7
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 7:
(6 comments)
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 692: EC_LPC_HOST_PACKET_SIZE Still need to use GET_PROTOCOL_INFO for this.
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 701: return EC_FLASH_WRITE_VER0_SIZE; We don't really need to support this anymore, all ECs that will use this code have the new version.
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 810: if (rv == -EC_RES_INVALID_PARAM || rv == -EC_RES_INVALID_COMMAND) { This too... all current and future ECs support this.
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 1408: static enum ec_current_image ec_image_type; Please initialize explicitly to = EC_IMAGE_UNKNOWN if you want to rely on that, for clarity.
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 1409: google_chromeec_get_current_image Still not really happy how this works... now you'd just call it twice.
I would suggest doing something like this:
enum ec_current_image google_chromeec_get_current_image_type(void) { MAYBE_STATIC_BSS enum type = EC_IMAGE_UNKNOWN;
if (type != EC_IMAGE_UNKNOWN) return type;
...do the whole command to initialize 'type'... }
Then you don't have to be careful with the call sequence order, you can just implement google_ec_running_ro() as (google_chromeec_get_current_image_type() == EC_IMAGE_RO) and it will only run the command once.
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 1442: google_chromeec_get_current_image(); This wouldn't need to be here then (and honestly, we don't really need to do hello() here either...).
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 7:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 1474: for (i = 0; i < resp.num_ports; i++) { : struct ec_params_usb_pd_get_mode_request params; : struct ec_params_usb_pd_get_mode_response resp2; : int svid_idx = 0; : : do { : /* Reset cmd in each iteration in case : google_chromeec_command changes it. */ : params.port = i; : params.svid_idx = svid_idx; : cmd.cmd_code = EC_CMD_USB_PD_GET_AMODE; : cmd.cmd_version = 0; : cmd.cmd_data_in = ¶ms; : cmd.cmd_size_in = sizeof(params); : cmd.cmd_data_out = &resp2; : cmd.cmd_size_out = sizeof(resp2); : cmd.cmd_dev_index = 0; : : if (google_chromeec_command(&cmd) < 0) : return -1; : if (resp2.svid == svid) : return 1; : svid_idx++; : } while (resp2.svid); Was this supposed to be put into the previous CL?
Karthik Ramasubramanian has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 7:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.h File src/ec/google/chromeec/ec.h:
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.h... PS7, Line 153: google_chromeec_hello Function header/documentation?
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 694: sizeof(struct ec_host_request); Looks like an inconsistent indentation.
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 7:
(10 comments)
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.h File src/ec/google/chromeec/ec.h:
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.h... PS7, Line 153: google_chromeec_hello
Function header/documentation?
Done
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/2/src/ec/google/chromeec/ec.c... PS2, Line 720: EC_LPC_HOST_PACKET_SIZE
For the stack, you ... […]
Done
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 692: EC_LPC_HOST_PACKET_SIZE
Still need to use GET_PROTOCOL_INFO for this.
Done
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 694: sizeof(struct ec_host_request);
Looks like an inconsistent indentation.
Done
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 701: return EC_FLASH_WRITE_VER0_SIZE;
We don't really need to support this anymore, all ECs that will use this code have the new version.
Done
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 810: if (rv == -EC_RES_INVALID_PARAM || rv == -EC_RES_INVALID_COMMAND) {
This too... all current and future ECs support this.
Done
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 1408: static enum ec_current_image ec_image_type;
Please initialize explicitly to = EC_IMAGE_UNKNOWN if you want to rely on that, for clarity.
Done
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 1409: google_chromeec_get_current_image
Still not really happy how this works... now you'd just call it twice. […]
Done
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 1442: google_chromeec_get_current_image();
This wouldn't need to be here then (and honestly, we don't really need to do hello() here either... […]
Done
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... PS7, Line 1474: for (i = 0; i < resp.num_ports; i++) { : struct ec_params_usb_pd_get_mode_request params; : struct ec_params_usb_pd_get_mode_response resp2; : int svid_idx = 0; : : do { : /* Reset cmd in each iteration in case : google_chromeec_command changes it. */ : params.port = i; : params.svid_idx = svid_idx; : cmd.cmd_code = EC_CMD_USB_PD_GET_AMODE; : cmd.cmd_version = 0; : cmd.cmd_data_in = ¶ms; : cmd.cmd_size_in = sizeof(params); : cmd.cmd_data_out = &resp2; : cmd.cmd_size_out = sizeof(resp2); : cmd.cmd_dev_index = 0; : : if (google_chromeec_command(&cmd) < 0) : return -1; : if (resp2.svid == svid) : return 1; : svid_idx++; : } while (resp2.svid);
Was this supposed to be put into the previous CL?
Done
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36207
to look at the new patch set (#8).
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 432 insertions(+), 20 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/8
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 8: Code-Review+2
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 8:
Thank you for taking the time to review this Julius. As I said, if you have any further cleanups you would like to see, file them as feature requests and assign them to me. I've already got 1 or 2 planned.
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36207
to look at the new patch set (#9).
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 432 insertions(+), 20 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/9
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36207
to look at the new patch set (#10).
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 432 insertions(+), 20 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/10
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36207
to look at the new patch set (#11).
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 432 insertions(+), 20 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/11
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36207
to look at the new patch set (#12).
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 432 insertions(+), 20 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/36207/12
Patrick Georgi has submitted this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
ec/google/chromeec: Add EC driver support for software sync
Quite a few new functions added here in order to support the use-case of performing EC software sync within coreboot.
Most of these functions are related to retrieving the EC's hash, and writing a new image into the EC's flash.
BUG=b:112198832 BRANCH=none TEST=With whole patch series, successfully performed EC software sync
Change-Id: I0d3c5184dbe96f04b92878f2c19c7875503a910a Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org Reviewed-on: https://review.coreboot.org/c/coreboot/+/36207 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Julius Werner jwerner@chromium.org --- M src/ec/google/chromeec/ec.c M src/ec/google/chromeec/ec.h 2 files changed, 432 insertions(+), 20 deletions(-)
Approvals: build bot (Jenkins): Verified Julius Werner: Looks good to me, approved
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index 32f06bb..2715e0b 100644 --- a/src/ec/google/chromeec/ec.c +++ b/src/ec/google/chromeec/ec.c @@ -483,7 +483,6 @@
/* Clear wake event mask. */ google_chromeec_set_wake_mask(0); - }
int google_chromeec_check_feature(int feature) @@ -507,16 +506,295 @@ return resp.flags[feature / 32] & EC_FEATURE_MASK_0(feature); }
+int google_chromeec_get_cmd_versions(int command, uint32_t *pmask) +{ + struct ec_params_get_cmd_versions_v1 params = { + .cmd = command, + }; + struct ec_response_get_cmd_versions resp = {}; + struct chromeec_command cmd = { + .cmd_code = EC_CMD_GET_CMD_VERSIONS, + .cmd_version = 1, + .cmd_size_in = sizeof(params), + .cmd_data_in = ¶ms, + .cmd_size_out = sizeof(resp), + .cmd_data_out = &resp, + .cmd_dev_index = 0, + }; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + *pmask = resp.version_mask; + return 0; +} + +int google_chromeec_get_vboot_hash(uint32_t offset, + struct ec_response_vboot_hash *resp) +{ + struct ec_params_vboot_hash params = { + .cmd = EC_VBOOT_HASH_GET, + .offset = offset, + }; + struct chromeec_command cmd = { + .cmd_code = EC_CMD_VBOOT_HASH, + .cmd_version = 0, + .cmd_size_in = sizeof(params), + .cmd_data_in = ¶ms, + .cmd_size_out = sizeof(*resp), + .cmd_data_out = resp, + .cmd_dev_index = 0, + }; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + return 0; +} + +int google_chromeec_start_vboot_hash(enum ec_vboot_hash_type hash_type, + uint32_t hash_offset, + struct ec_response_vboot_hash *resp) +{ + struct ec_params_vboot_hash params = { + .cmd = EC_VBOOT_HASH_START, + .hash_type = hash_type, + .nonce_size = 0, + .offset = hash_offset, + }; + struct chromeec_command cmd = { + .cmd_code = EC_CMD_VBOOT_HASH, + .cmd_version = 0, + .cmd_size_in = sizeof(params), + .cmd_data_in = ¶ms, + .cmd_size_out = sizeof(*resp), + .cmd_data_out = resp, + .cmd_dev_index = 0, + }; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + return 0; +} + +int google_chromeec_flash_protect(uint32_t mask, uint32_t flags, + struct ec_response_flash_protect *resp) +{ + struct ec_params_flash_protect params = { + .mask = mask, + .flags = flags, + }; + struct chromeec_command cmd = { + .cmd_code = EC_CMD_FLASH_PROTECT, + .cmd_version = EC_VER_FLASH_PROTECT, + .cmd_size_in = sizeof(params), + .cmd_data_in = ¶ms, + .cmd_size_out = sizeof(*resp), + .cmd_data_out = resp, + .cmd_dev_index = 0, + }; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + return 0; +} + +int google_chromeec_flash_region_info(enum ec_flash_region region, + uint32_t *offset, uint32_t *size) +{ + struct ec_params_flash_region_info params = { + .region = region, + }; + struct ec_response_flash_region_info resp = {}; + struct chromeec_command cmd = { + .cmd_code = EC_CMD_FLASH_REGION_INFO, + .cmd_version = EC_VER_FLASH_REGION_INFO, + .cmd_size_in = sizeof(params), + .cmd_data_in = ¶ms, + .cmd_size_out = sizeof(resp), + .cmd_data_out = &resp, + .cmd_dev_index = 0, + }; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + if (offset) + *offset = resp.offset; + if (size) + *size = resp.size; + + return 0; +} + +int google_chromeec_flash_erase(uint32_t offset, uint32_t size) +{ + struct ec_params_flash_erase params = { + .offset = offset, + .size = size, + }; + struct chromeec_command cmd = { + .cmd_code = EC_CMD_FLASH_ERASE, + .cmd_version = 0, + .cmd_size_in = sizeof(params), + .cmd_data_in = ¶ms, + .cmd_size_out = 0, + .cmd_data_out = NULL, + .cmd_dev_index = 0, + }; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + return 0; +} + +int google_chromeec_flash_info(struct ec_response_flash_info *info) +{ + struct chromeec_command cmd; + + cmd.cmd_code = EC_CMD_FLASH_INFO; + cmd.cmd_version = 0; + cmd.cmd_size_in = 0; + cmd.cmd_data_in = NULL; + cmd.cmd_size_out = sizeof(*info); + cmd.cmd_data_out = info; + cmd.cmd_dev_index = 0; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + return 0; +} + +/* + * Write a block into EC flash. Expects params_data to be a buffer where + * the first N bytes are a struct ec_params_flash_write, and the rest of it + * is the data to write to flash. +*/ +int google_chromeec_flash_write_block(const uint8_t *params_data, + uint32_t bufsize) +{ + struct chromeec_command cmd = { + .cmd_code = EC_CMD_FLASH_WRITE, + .cmd_version = EC_VER_FLASH_WRITE, + .cmd_size_out = 0, + .cmd_data_out = NULL, + .cmd_size_in = bufsize, + .cmd_data_in = params_data, + .cmd_dev_index = 0, + }; + + assert(params_data); + + return google_chromeec_command(&cmd); +} + +/* + * EFS verification of flash. + */ +int google_chromeec_efs_verify(enum ec_flash_region region) +{ + struct ec_params_efs_verify params = { + .region = region, + }; + struct chromeec_command cmd = { + .cmd_code = EC_CMD_EFS_VERIFY, + .cmd_version = 0, + .cmd_size_in = sizeof(params), + .cmd_data_in = ¶ms, + .cmd_size_out = 0, + .cmd_data_out = NULL, + .cmd_dev_index = 0, + }; + int rv; + + /* It's okay if the EC doesn't support EFS */ + rv = google_chromeec_command(&cmd); + if (rv != 0 && (cmd.cmd_code == EC_RES_INVALID_COMMAND)) + return 0; + else if (rv != 0) + return -1; + + return 0; +} + +int google_chromeec_battery_cutoff(uint8_t flags) +{ + struct ec_params_battery_cutoff params = { + .flags = flags, + }; + struct chromeec_command cmd = { + .cmd_code = EC_CMD_BATTERY_CUT_OFF, + .cmd_version = 1, + .cmd_size_in = sizeof(params), + .cmd_data_in = ¶ms, + .cmd_data_out = NULL, + .cmd_size_out = 0, + .cmd_dev_index = 0, + }; + + if (google_chromeec_command(&cmd) != 0) + return -1; + + return 0; +} + +int google_chromeec_read_limit_power_request(int *limit_power) +{ + struct ec_params_charge_state params = { + .cmd = CHARGE_STATE_CMD_GET_PARAM, + .get_param.param = CS_PARAM_LIMIT_POWER, + }; + struct ec_response_charge_state resp = {}; + struct chromeec_command cmd = { + .cmd_code = EC_CMD_CHARGE_STATE, + .cmd_version = 0, + .cmd_size_in = sizeof(params), + .cmd_data_in = ¶ms, + .cmd_size_out = sizeof(resp), + .cmd_data_out = &resp, + .cmd_dev_index = 0, + }; + + if (google_chromeec_command(&cmd)) + return -1; + + *limit_power = resp.get_param.value; + return 0; +} + +int google_chromeec_get_protocol_info( + struct ec_response_get_protocol_info *resp) +{ + struct chromeec_command cmd = { + .cmd_code = EC_CMD_GET_PROTOCOL_INFO, + .cmd_version = 0, + .cmd_size_in = 0, + .cmd_data_in = NULL, + .cmd_data_out = resp, + .cmd_size_out = sizeof(*resp), + .cmd_dev_index = 0, + }; + + if (google_chromeec_command(&cmd)) + return -1; + + return 0; +} + int google_chromeec_set_sku_id(uint32_t skuid) { - struct ec_sku_id_info set_skuid = { + struct ec_sku_id_info params = { .sku_id = skuid }; struct chromeec_command cmd = { .cmd_code = EC_CMD_SET_SKU_ID, .cmd_version = 0, - .cmd_size_in = sizeof(set_skuid), - .cmd_data_in = &set_skuid, + .cmd_size_in = sizeof(params), + .cmd_data_in = ¶ms, .cmd_data_out = NULL, .cmd_size_out = 0, .cmd_dev_index = 0, @@ -944,7 +1222,7 @@ return google_chromeec_command(&cmd); }
-static int google_chromeec_hello(void) +int google_chromeec_hello(void) { struct ec_params_hello params = { .in_data = 0x10203040, @@ -963,6 +1241,10 @@ int rv = google_chromeec_command(&cmd); if (rv) return -1; + + if (resp.out_data != (params.in_data + 0x01020304)) + return -1; + return 0; }
@@ -1087,10 +1369,14 @@ printk(BIOS_DEBUG, "\n"); }
-static int ec_image_type; /* Cached EC image type (ro or rw). */ - -void google_chromeec_init(void) +/* Cache and retrieve the EC image type (ro or rw) */ +enum ec_current_image google_chromeec_get_current_image(void) { + MAYBE_STATIC_BSS enum ec_current_image ec_image_type = EC_IMAGE_UNKNOWN; + + if (ec_image_type != EC_IMAGE_UNKNOWN) + return ec_image_type; + struct ec_response_get_version resp = {}; struct chromeec_command cmd = { .cmd_code = EC_CMD_GET_VERSION, @@ -1101,7 +1387,6 @@ .cmd_dev_index = 0, };
- google_chromeec_hello(); google_chromeec_command(&cmd);
if (cmd.cmd_code) { @@ -1116,12 +1401,18 @@ ec_image_type = resp.current_image; }
+ /* Will still be UNKNOWN if command failed */ + return ec_image_type; +} + +void google_chromeec_init(void) +{ google_chromeec_log_uptimeinfo(); }
int google_ec_running_ro(void) { - return (ec_image_type == EC_IMAGE_RO); + return (google_chromeec_get_current_image() == EC_IMAGE_RO); }
/** @@ -1148,29 +1439,29 @@ return -1;
for (i = 0; i < resp.num_ports; i++) { - struct ec_params_usb_pd_get_mode_request p; - struct ec_params_usb_pd_get_mode_response res; + struct ec_params_usb_pd_get_mode_request params; + struct ec_params_usb_pd_get_mode_response resp2; int svid_idx = 0;
do { /* Reset cmd in each iteration in case google_chromeec_command changes it. */ - p.port = i; - p.svid_idx = svid_idx; + params.port = i; + params.svid_idx = svid_idx; cmd.cmd_code = EC_CMD_USB_PD_GET_AMODE; cmd.cmd_version = 0; - cmd.cmd_data_in = &p; - cmd.cmd_size_in = sizeof(p); - cmd.cmd_data_out = &res; - cmd.cmd_size_out = sizeof(res); + cmd.cmd_data_in = ¶ms; + cmd.cmd_size_in = sizeof(params); + cmd.cmd_data_out = &resp2; + cmd.cmd_size_out = sizeof(resp2); cmd.cmd_dev_index = 0;
if (google_chromeec_command(&cmd) < 0) return -1; - if (res.svid == svid) + if (resp2.svid == svid) return 1; svid_idx++; - } while (res.svid); + } while (resp2.svid); }
return 0; diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h index 25c7775..9fb9c39 100644 --- a/src/ec/google/chromeec/ec.h +++ b/src/ec/google/chromeec/ec.h @@ -35,6 +35,7 @@ /* Check if EC supports feature EC_FEATURE_UNIFIED_WAKE_MASKS */ bool google_chromeec_is_uhepi_supported(void); int google_ec_running_ro(void); +enum ec_current_image google_chromeec_get_current_image(void); void google_chromeec_init(void); int google_chromeec_pd_get_amode(uint16_t svid); int google_chromeec_wait_for_displayport(long timeout); @@ -150,6 +151,13 @@ crosec_io_t crosec_io, void *context);
/** + * Performs light verification of the EC<->AP communcation channel. + * + * @return 0 on success, -1 on error + */ +int google_chromeec_hello(void); + +/** * Send a command to a CrOS EC * * @param cec_command: CrOS EC command to send @@ -178,4 +186,117 @@ /* Log host events to eventlog based on the mask provided. */ void google_chromeec_log_events(uint64_t mask);
+/** + * Protect/un-protect EC flash regions. + * + * @param mask Set/clear the requested bits in 'flags' + * @param flags Flash protection flags + * @param resp Pointer to response structure + * @return 0 on success, -1 on error + */ +int google_chromeec_flash_protect(uint32_t mask, uint32_t flags, + struct ec_response_flash_protect *resp); +/** + * Calculate image hash for vboot. + * + * @param hash_type The hash types supported by the EC for vboot + * @param offset The offset to start hashing in flash + * @param resp Pointer to response structure + * @return 0 on success, -1 on error + */ +int google_chromeec_start_vboot_hash(enum ec_vboot_hash_type hash_type, + uint32_t offset, + struct ec_response_vboot_hash *resp); +/** + * Return the EC's vboot image hash. + * + * @param offset Get hash for flash region beginning here + * @param resp Pointer to response structure + * @return 0 on success, -1 on error + * + */ +int google_chromeec_get_vboot_hash(uint32_t offset, + struct ec_response_vboot_hash *resp); + +/** + * Get offset and size of the specified EC flash region. + * + * @param region Which region of EC flash + * @param offset Gets filled with region's offset + * @param size Gets filled with region's size + * @return 0 on success, -1 on error + */ +int google_chromeec_flash_region_info(enum ec_flash_region region, + uint32_t *offset, uint32_t *size); +/** + * Erase a region of EC flash. + * + * @param offset Where to begin erasing + * @param size Size of area to erase + * @return 0 on success, -1 on error + */ +int google_chromeec_flash_erase(uint32_t region_offset, uint32_t region_size); + +/** + * Return information about the entire flash. + * + * @param info Pointer to response structure + * @return 0 on success, -1 on error + */ +int google_chromeec_flash_info(struct ec_response_flash_info *info); + +/** + * Write a block into EC flash. + * + * @param data Pointer to data to write to flash, prefixed by a + * struct ec_params_flash_write + * @param offset Offset to begin writing data + * @param size Number of bytes to be written to flash from data + * @return 0 on success, -1 on error + */ +int google_chromeec_flash_write_block(const uint8_t *data, uint32_t size); + +/** + * Verify flash using EFS if available. + * + * @param region Which flash region to verify + * @return 0 on success, -1 on error + */ +int google_chromeec_efs_verify(enum ec_flash_region region); + +/** + * Command EC to perform battery cutoff. + * + * @param flags Flags to pass to the EC + * @return 0 on success, -1 on error + */ +int google_chromeec_battery_cutoff(uint8_t flags); + +/** + * Check if the EC is requesting the system to limit input power. + * + * @param limit_power If successful, limit_power is 1 if EC is requesting + * input power limits, otherwise 0. + * @return 0 on success, -1 on error + */ +int google_chromeec_read_limit_power_request(int *limit_power); + +/** + * Get information about the protocol that the EC speaks. + * + * @param resp Filled with host command protocol information. + * @return 0 on success, -1 on error + */ +int google_chromeec_get_protocol_info( + struct ec_response_get_protocol_info *resp); + +/** + * Get available versions of the specified command. + * + * @param command Command ID + * @param pmask Pointer to version mask + * @return 0 on success, -1 on error + */ +int google_chromeec_get_cmd_versions(int command, uint32_t *pmask); + #endif /* _EC_GOOGLE_CHROMEEC_EC_H */
Matt DeVillier has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... File src/ec/google/chromeec/ec.h:
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... PS13, Line 253: * @param offset Offset to begin writing data looks like this is now contained within the ec_params struct at the start of *data
Matt DeVillier has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... PS13, Line 682: EC_VER_FLASH_WRITE don't we need to check if EC_VER_FLASH_WRITE is supported first? IIRC, older devices like LINK only support version 0.
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... PS13, Line 682: EC_VER_FLASH_WRITE
don't we need to check if EC_VER_FLASH_WRITE is supported first? IIRC, older devices like LINK only […]
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c...
Matt DeVillier has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... PS13, Line 682: EC_VER_FLASH_WRITE
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c...
so what is the cutoff then? as the earlier implementation showed, it's pretty trivial to support "legacy" EC's which require the smaller burst data size and version 0 write command
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... PS13, Line 682: EC_VER_FLASH_WRITE
https://review.coreboot.org/c/coreboot/+/36207/7/src/ec/google/chromeec/ec.c... […]
We're doing this as an optional new feature for future Chrome OS boards, we weren't really intending to backport it to any existing ones. Even if you fix this there may be other dependencies hidden somewhere that make it not work on older boards.
That said, if you really want this to support older boards for some reason, I won't object to adding some version fallback code here (although we should make it a little more clever than the depthcharge version... e.g. don't explicitly ask for the version, just try the new one and fall back if it returns EC_RES_INVALID_VERSION, and save that version in a static variable for the next block).
I'm not sure why anyone building "unofficial" images would really want EC software sync though. If you're building your own images you'd presumably just flash the EC once to what you want it to be. Software sync is really just needed when you want automatic updates from somewhere.
Matt DeVillier has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... PS13, Line 682: EC_VER_FLASH_WRITE
That said, if you really want this to support older boards for some reason <snip>
I've been using a ported version of the depthcharge/vboot code for ~3yrs now to update devices running my upstream coreboot builds, so it would be nice if the newly upstreamed code wasn't less functional. I'll do a diff and push some patches for review once the entire set is merged. If it's usable great, otherwise I'll just keep it in my tree as I have been doing.
I'm not sure why anyone building "unofficial" images would really want EC software sync though. If you're building your own images you'd presumably just flash the EC once to what you want it to be. Software sync is really just needed when you want automatic updates from somewhere.
well, EC SWS provides an easy way to perform that update from coreboot though; otherwise one would have to reinvent the wheel, so to speak.
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... PS13, Line 682: EC_VER_FLASH_WRITE
That said, if you really want this to support older boards for some reason <snip> […]
I don't see how you think this is less functional; coreboot has never performed EC software sync before, and currently depthcharge still handles EC software sync as well (intended for those devices that have the "slow" EC update so that a screen can be shown to the user). Please add us on your proposed patches.
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... PS13, Line 682: EC_VER_FLASH_WRITE
well, EC SWS provides an easy way to perform that update from coreboot though; otherwise one would have to reinvent the wheel, so to speak.
Just use flashrom -p ec? That's how we update our EC manually (both RO and RW).
Matt DeVillier has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36207 )
Change subject: ec/google/chromeec: Add EC driver support for software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... File src/ec/google/chromeec/ec.c:
https://review.coreboot.org/c/coreboot/+/36207/13/src/ec/google/chromeec/ec.... PS13, Line 682: EC_VER_FLASH_WRITE
Just use flashrom -p ec? That's how we update our EC manually (both RO and RW).
sure, but not sure I want to risk updating the active EC firmware on a live system - at least not someone else's. Much easier and safer just to check/reboot into RO, then update and jump into RW as part of AP boot :)