Tim Wawrzynczak has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- A src/security/vboot/sync_ec.c A src/security/vboot/sync_ec.h 2 files changed, 468 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/1
diff --git a/src/security/vboot/sync_ec.c b/src/security/vboot/sync_ec.c new file mode 100644 index 0000000..f40934b --- /dev/null +++ b/src/security/vboot/sync_ec.c @@ -0,0 +1,443 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2019 Google LLC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <assert.h> +#include <2constants.h> +#include <cbfs.h> +#include <console/console.h> +#include <delay.h> +#include <ec/google/chromeec/ec.h> +#include <ec_sync.h> +#include <security/vboot/misc.h> +#include <security/vboot/sync_ec.h> +#include <security/vboot/vbnv.h> +#include <timer.h> +#include <timestamp.h> +#include <vb2_api.h> + +#define _EC_FILENAME(select, suffix) \ + (select == VB_SELECT_FIRMWARE_READONLY ? "ecro" suffix : "ecrw" suffix) +#define EC_IMAGE_FILENAME(select) _EC_FILENAME(select, "") +#define EC_HASH_FILENAME(select) _EC_FILENAME(select, ".hash") + +#define EC_PRIMARY_IDX 0 + +static const int CROS_EC_HASH_CHECK_DELAY_MS = 10; +static const int CROS_EC_HASH_TIMEOUT_MS = 2000; + +/* Required for ec_update_image */ +static uint8_t read_buffer[EC_LPC_HOST_PACKET_SIZE]; +static struct region_device fw_image_region; + +/* + * The external API for EC software sync. This function calls into + * vboot, which kicks off the process. Vboot runs the verified boot + * logic, and requires the client program to provide callbacks which + * perform the work. + */ +int vboot_sync_ec(void) +{ + static uint8_t temp_workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]; + struct vb2_context ctx; + struct vboot_working_data *wd; + vb2_error_t retval = 0; + uint8_t *p; + + /* Init workspace, VBNB, etc. */ + ctx.workbuf_size = VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE; + ctx.workbuf = temp_workbuf; + wd = vboot_get_working_data(); + + p = (uint8_t *)wd + wd->buffer_offset; + memcpy(ctx.workbuf, (void *)p, wd->buffer_size); + + ctx.flags |= VB2_CONTEXT_EC_SYNC_SUPPORTED; + ctx.flags &= ~VB2_CONTEXT_EC_SYNC_SLOW; + vbnv_init(ctx.nvdata); + + /* Perform software sync */ + retval = vb2api_ec_software_sync(&ctx); + if (retval != VB2_SUCCESS) + printk(BIOS_ERR, "Software sync on EC failed (%d)\n", (int)retval); + + vboot_finalize_work_context(&ctx); + + return retval; +} + +/* Convert firmware image type into a Flash offset */ +static uint32_t get_vboot_hash_offset(enum VbSelectFirmware_t select) +{ + switch (select) { + case VB_SELECT_FIRMWARE_READONLY: + return EC_VBOOT_HASH_OFFSET_RO; + case VB_SELECT_FIRMWARE_EC_UPDATE: + return EC_VBOOT_HASH_OFFSET_UPDATE; + default: + return EC_VBOOT_HASH_OFFSET_ACTIVE; + } +} + +/* + * Asks the EC to calculate a hash of the specified firmware image, and + * returns the information in **hash and *hash_size. + */ +static vb2_error_t ec_hash_image(enum VbSelectFirmware_t select, + const uint8_t **hash, int *hash_size) +{ + static struct ec_response_vboot_hash resp; + uint32_t hash_offset; + int recalc_requested = 0; + struct stopwatch sw; + int rv; + + hash_offset = get_vboot_hash_offset(select); + + stopwatch_init_msecs_expire(&sw, CROS_EC_HASH_TIMEOUT_MS); + do { + rv = google_chromeec_get_vboot_hash(hash_offset, &resp); + if (rv) + return VB2_ERROR_UNKNOWN; + + switch (resp.status) { + case EC_VBOOT_HASH_STATUS_NONE: + /* We have no valid hash - let's request a recalc + * if we haven't done so yet. */ + if (recalc_requested != 0) + break; + + printk(BIOS_WARNING, + "%s: No valid hash (status=%d size=%d). " + "Computing...\n", __func__, resp.status, + resp.size); + + rv = google_chromeec_start_vboot_hash( + EC_VBOOT_HASH_TYPE_SHA256, hash_offset, &resp); + if (rv) + return VB2_ERROR_UNKNOWN; + + recalc_requested = 1; + /* Expect status to be busy (and don't break while) + * since we just sent a recalc request. */ + resp.status = EC_VBOOT_HASH_STATUS_BUSY; + break; + case EC_VBOOT_HASH_STATUS_BUSY: + /* Hash is still calculating. */ + mdelay(CROS_EC_HASH_CHECK_DELAY_MS); + printk(BIOS_INFO, "."); + break; + case EC_VBOOT_HASH_STATUS_DONE: + default: + /* We have a valid hash. */ + break; + } + } while (resp.status == EC_VBOOT_HASH_STATUS_BUSY && + !stopwatch_expired(&sw)); + + if (resp.status != EC_VBOOT_HASH_STATUS_DONE) { + printk(BIOS_ERR, "%s: Hash status not done: %d\n", __func__, + resp.status); + return VB2_ERROR_UNKNOWN; + } + if (resp.hash_type != EC_VBOOT_HASH_TYPE_SHA256) { + printk(BIOS_ERR, "EC hash was the wrong type.\n"); + return VB2_ERROR_UNKNOWN; + } + + *hash = resp.hash_digest; + *hash_size = resp.digest_size; + + return VB2_SUCCESS; +} + +/* + * Asks the EC to protect or unprotect the specified Flash region. + */ +static vb2_error_t ec_protect_flash(enum VbSelectFirmware_t select, int enable) +{ + struct ec_response_flash_protect resp; + uint32_t protected_region = EC_FLASH_PROTECT_ALL_NOW; + const uint32_t mask = EC_FLASH_PROTECT_ALL_NOW | EC_FLASH_PROTECT_ALL_AT_BOOT; + + if (select == VB_SELECT_FIRMWARE_READONLY) + protected_region = EC_FLASH_PROTECT_RO_NOW; + + if (google_chromeec_flash_protect(mask, enable ? mask : 0, &resp) != 0) + return VB2_ERROR_UNKNOWN; + + if (!enable) { + /* If protection is still enabled, need reboot */ + if (resp.flags & protected_region) + return VBERROR_EC_REBOOT_TO_RO_REQUIRED; + + return VB2_SUCCESS; + } + + /* + * If write protect and ro-at-boot aren't both asserted, don't expect + * protection enabled. + */ + if ((~resp.flags) & (EC_FLASH_PROTECT_GPIO_ASSERTED | + EC_FLASH_PROTECT_RO_AT_BOOT)) + return VB2_SUCCESS; + + /* If flash is protected now, success */ + if (resp.flags & EC_FLASH_PROTECT_ALL_NOW) + return VB2_SUCCESS; + + /* If RW will be protected at boot but not now, need a reboot */ + if (resp.flags & EC_FLASH_PROTECT_ALL_AT_BOOT) { + return VBERROR_EC_REBOOT_TO_RO_REQUIRED; + } + + /* Otherwise, it's an error */ + return VB2_ERROR_UNKNOWN; +} + +/* Convert a firmware image type to an EC Flash region */ +static enum ec_flash_region vboot_to_ec_region(enum VbSelectFirmware_t select) +{ + switch (select) { + case VB_SELECT_FIRMWARE_READONLY: + return EC_FLASH_REGION_WP_RO; + case VB_SELECT_FIRMWARE_EC_UPDATE: + return EC_FLASH_REGION_UPDATE; + default: + return EC_FLASH_REGION_ACTIVE; + } +} + +/* + * Read the EC's burst size bytes at a time from CBFS, and then send + * the chunk to the EC for it to write into its Flash. + */ +static int ec_flash_write(const uint8_t *image, uint32_t region_offset, + int image_size) +{ + u32 burst = google_chromeec_flash_write_burst_size(); + u32 end, off; + int ret; + + if (!burst) + return -1; + + end = region_offset + image_size; + for (off = region_offset; off < end; off += burst) { + uint32_t todo = MIN(end - off, burst); + + /* Read todo bytes into the buffer */ + if (rdev_readat(&fw_image_region, read_buffer, + off - region_offset, todo) == todo) { + ret = google_chromeec_flash_write_block(read_buffer, off, todo); + if (ret) + return ret; + } else { + printk(BIOS_ERR, "Failed to read EC FW image!\n"); + return -1; + } + } + + return 0; +} + +/* + * The logic for updating an EC firmware image. + */ +static vb2_error_t ec_update_image(enum VbSelectFirmware_t select, + const uint8_t *image, int image_size) +{ + uint32_t region_offset, region_size; + enum ec_flash_region region; + vb2_error_t rv; + + /* Un-protect the flash region */ + rv = ec_protect_flash(select, 0); + if (rv == VBERROR_EC_REBOOT_TO_RO_REQUIRED || rv != VB2_SUCCESS) + return rv; + + /* Convert vboot region into an EC region */ + region = vboot_to_ec_region(select); + + /* Get information about the flash region */ + if (google_chromeec_flash_region_info(region, ®ion_offset, + ®ion_size)) + return VB2_ERROR_UNKNOWN; + + /* Bail if our image is too large */ + if (image_size > region_size) + return VB2_ERROR_INVALID_PARAMETER; + + /* Erase the region */ + if (google_chromeec_flash_erase(region_offset, region_size)) + return VB2_ERROR_UNKNOWN; + + /* Write the image into the region */ + if (ec_flash_write(image, region_offset, image_size)) + return VB2_ERROR_UNKNOWN; + + /* Verify the image */ + if (google_chromeec_efs_verify(region)) + return VB2_ERROR_UNKNOWN; + + return VB2_SUCCESS; +} + +/*********************************************************************** + * Vboot Callbacks + ***********************************************************************/ + +/* Unsupported */ +vb2_error_t VbExDisplayScreen(uint32_t screen_type, uint32_t locale, + const VbScreenData *data) +{ + return VB2_ERROR_UNKNOWN; +} + +/* Unsupported */ +vb2_error_t VbExNvStorageWrite(const uint8_t *buf) +{ + return VB2_ERROR_UNKNOWN; +} + +/* Report whether the EC is in RW or not */ +vb2_error_t VbExEcRunningRW(int devidx, int *in_rw) +{ + assert(devidx == 0); + + /* Re-init to get RW/RO information */ + google_chromeec_init(); + if (google_ec_running_ro()) { + *in_rw = 0; + } else { + *in_rw = 1; + } + + return VB2_SUCCESS; +} + +/* Callback for when Vboot is finished */ +vb2_error_t VbExEcVbootDone(int in_recovery) +{ + return VB2_SUCCESS; +} + +/* Unsupported */ +vb2_error_t VbExEcBatteryCutOff(void) +{ + return VB2_ERROR_UNKNOWN; +} + +/* Vboot callback for EC image hash */ +vb2_error_t VbExEcHashImage(int devidx, enum VbSelectFirmware_t select, + const uint8_t **hash, int *hash_size) +{ + assert(devidx == 0); + return ec_hash_image(select, hash, hash_size); +} + +/* Vboot callback for EC flash protection */ +vb2_error_t VbExEcProtect(int devidx, enum VbSelectFirmware_t select) +{ + assert(devidx == 0); + return ec_protect_flash(select, 1); +} + +/* Get hash for image */ +vb2_error_t VbExEcGetExpectedImageHash(int devidx, + enum VbSelectFirmware_t select, + const uint8_t **hash, int *hash_size) +{ + size_t size; + const char *filename = EC_HASH_FILENAME(select); + uint8_t *file = cbfs_boot_map_with_leak(filename, CBFS_TYPE_RAW, &size); + + if (file == NULL) + return VB2_ERROR_UNKNOWN; + + *hash = file; + *hash_size = (int)size; + + return VB2_SUCCESS; +} + +/* Disable sysjump */ +vb2_error_t VbExEcDisableJump(int devidx) +{ + int rv; + assert(devidx == 0); + + rv = google_chromeec_reboot(EC_PRIMARY_IDX, EC_REBOOT_DISABLE_JUMP, 0); + if (rv) + return VB2_ERROR_UNKNOWN; + + return VB2_SUCCESS; +} + +/* Update EC image */ +vb2_error_t VbExEcUpdateImage(int devidx, enum VbSelectFirmware_t select, + const uint8_t *image, int image_size) +{ + assert(devidx == 0); + + return ec_update_image(select, image, image_size); +} + +/* Vboot callback for retrieving the expected image */ +vb2_error_t VbExEcGetExpectedImage(int devidx, enum VbSelectFirmware_t select, + const uint8_t **image, int *image_size) +{ + const char *filename = EC_IMAGE_FILENAME(select); + struct cbfsf fh; + int rv = cbfs_boot_locate(&fh, filename, NULL); + if (rv) + return VB2_ERROR_UNKNOWN; + + cbfs_file_data(&fw_image_region, &fh); + + *image = read_buffer; + *image_size = (int)region_device_sz(&fh.data); + return VB2_SUCCESS; +} + +/* Vboot callback for commanding EC to sysjump to RW */ +vb2_error_t VbExEcJumpToRW(int devidx) +{ + struct stopwatch outer; + + assert(devidx == 0); + if (google_chromeec_reboot(EC_PRIMARY_IDX, EC_REBOOT_JUMP_RW, 0)) { + return VB2_ERROR_UNKNOWN; + } + + /* Give the EC 3 seconds to sysjump */ + stopwatch_init_msecs_expire(&outer, 3000); + + /* Default delay to wait after EC reboot */ + mdelay(50); + while (google_chromeec_test()) { + if (stopwatch_expired(&outer)) { + printk(BIOS_ERR, "EC did not return from reboot after %lus\n", + stopwatch_duration_usecs(&outer)); + return -1; + } + + mdelay(5); + } + + printk(BIOS_INFO, "\nEC returned from reboot after %lus, and ", + stopwatch_duration_usecs(&outer)); + + return VB2_SUCCESS; +} diff --git a/src/security/vboot/sync_ec.h b/src/security/vboot/sync_ec.h new file mode 100644 index 0000000..038f179 --- /dev/null +++ b/src/security/vboot/sync_ec.h @@ -0,0 +1,25 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2019 Google LLC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __VBOOT_SECURITY_SYNC_EC_H__ +#define __VBOOT_SECURITY_SYNC_EC_H__ + +/* + * The external API for performing EC software sync. The return code + * comes directly from vboot, coerced to an int. + */ +int vboot_sync_ec(void); + +#endif /* __VBOOT_SECURITY_SYNC_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/+/36208
to look at the new patch set (#2).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- A src/security/vboot/sync_ec.c A src/security/vboot/sync_ec.h 2 files changed, 468 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/2
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 2:
(13 comments)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.h:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 21: coerced to an int If you're returning a vb2_error_t, you should make that the return type.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 17: #include <2constants.h> This is chain-included from <vb2_api.h> and shouldn't need to be included directly.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 41: EC_LPC_HOST_PACKET_SIZE Again, you shouldn't use this constant here. Probably want some sort of API to get the dynamically determined max request size.
Also, maybe allocate on the stack to save pre-RAM memory? (Should limit it to max 1KB then. Alternatively, I guess you could use the vboot work buffer too.)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 52: static uint8_t temp_workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]; Yeah, this isn't gonna work. You need to get the real workbuffer, you can't just make a new one.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 64: memcpy(ctx.workbuf, (void *)p, wd->buffer_size); I have no idea what you're trying to do here...?
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 68: vbnv_init(ctx.nvdata); I hope we can get Joel's persistent context work in before this, because as written here this is all pretty awkward...
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 309: vb2_error_t VbExNvStorageWrite(const uint8_t *buf) Need to implement this (it's essentially just save_vbnv(buf)).
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 320: google_chromeec_init(); This is very awkward. google_chromeec_init() has always been kinda weird in coreboot in that only some platforms run it and only in some stages. We should either make that more consistent so that we always know it will run in romstage, or get rid of it and make functions which need version information run EC_CMD_GET_VERSION directly.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 331: vb2_error_t VbExEcVbootDone(int in_recovery) This will need to do the same "wait until EC has power" dance as it does in depthcharge.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 336: /* Unsupported */ We'll need to support this too.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 398: vb2_error_t VbExEcGetExpectedImage(int devidx, enum VbSelectFirmware_t select, We should really get rid of this callback in vboot before doing this.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 417: outer nit: weird name? (If you don't want to make up something specific, we usually just call it 'sw'.)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 439: %lus, and " ...and what?
Joel Kitching has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 2:
(6 comments)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 3: * : * Copyright 2019 Google LLC : * : * This program is free software; you can redistribute it and/or modify : * it under the terms of the GNU General Public License as published by : * the Free Software Foundation; version 2 of the License. : * : * This program is distributed in the hope that it will be useful, : * but WITHOUT ANY WARRANTY; without even the implied warranty of : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the : * GNU General Public License for more details. : */ I thought we decided in the last vote to stop putting full copyright notices?
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 17: #include <2constants.h>
This is chain-included from <vb2_api.h> and shouldn't need to be included directly.
In fact it *shouldn't* be. If you only want the constants and not the full API, then vb2_constants.h is provided.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 50: vboot_sync_ec With persistent context, we don't even need this function.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 68: vbnv_init(ctx.nvdata);
I hope we can get Joel's persistent context work in before this, because as written here this is all […]
Yeah, I think we can consider that a blocker at this point. I don't think it makes sense to re-initialize vb2_context here.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 73: %d %#x
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 73: (int) No need to cast.
Joel Kitching has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 2:
(3 comments)
To be honest, I'm a little bit worried that we're adding so much code here without any unit testing...
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
PS2: We might want to call this file ec_sync.c instead to be more consistent with vboot_reference naming.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 35: #define EC_PRIMARY_IDX 0 Can we just get rid of the concept of "primary" and "alternate" EC altogether? There will only ever be one EC going forward.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 80: Flash Probably no good reason to capitalize Flash here (and in below comments).
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 2:
(21 comments)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.h:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 21: coerced to an int
If you're returning a vb2_error_t, you should make that the return type.
Yeah, I forget the reason that I did that. Done.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
PS2:
We might want to call this file ec_sync.c instead to be more consistent with vboot_reference naming.
That makes sense. Doing it this way made it easier to keep myself from getting confused as to which ec_sync file I had open at the time :). Done.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 3: * : * Copyright 2019 Google LLC : * : * This program is free software; you can redistribute it and/or modify : * it under the terms of the GNU General Public License as published by : * the Free Software Foundation; version 2 of the License. : * : * This program is distributed in the hope that it will be useful, : * but WITHOUT ANY WARRANTY; without even the implied warranty of : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the : * GNU General Public License for more details. : */
I thought we decided in the last vote to stop putting full copyright notices?
vote? I can take it out if it's not supposed to be there anymore. I didn't know.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 17: #include <2constants.h>
In fact it *shouldn't* be. If you only want the constants and not the full API, then vb2_constants. […]
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 35: #define EC_PRIMARY_IDX 0
Can we just get rid of the concept of "primary" and "alternate" EC altogether? There will only ever […]
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 41: EC_LPC_HOST_PACKET_SIZE
Again, you shouldn't use this constant here. […]
That's true, we could use the stack; isn't the stack in CAR as well ?
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 50: vboot_sync_ec
With persistent context, we don't even need this function.
Understood, is persistent context implemented yet?
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 52: static uint8_t temp_workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE];
Yeah, this isn't gonna work. You need to get the real workbuffer, you can't just make a new one.
See below.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 64: memcpy(ctx.workbuf, (void *)p, wd->buffer_size);
I have no idea what you're trying to do here... […]
I wasn't sure if it was okay to reuse the work buffer directly (does depthcharge need data from it?) , so this creating a new one and copying the old data into it.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 68: vbnv_init(ctx.nvdata);
Yeah, I think we can consider that a blocker at this point. […]
Any idea on when persistent context will be ready? We're trying to move forward with this as the solution for the hatch platform's booting from low/dead battery issue.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 73: %d
%#x
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 73: (int)
No need to cast.
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 80: Flash
Probably no good reason to capitalize Flash here (and in below comments).
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 201: if (resp.flags & EC_FLASH_PROTECT_ALL_AT_BOOT) {
braces {} are not necessary for single statement blocks
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 309: vb2_error_t VbExNvStorageWrite(const uint8_t *buf)
Need to implement this (it's essentially just save_vbnv(buf)).
Gotcha. Missed that one.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 320: google_chromeec_init();
This is very awkward. […]
That's a fair point. I'll split that up.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 331: vb2_error_t VbExEcVbootDone(int in_recovery)
This will need to do the same "wait until EC has power" dance as it does in depthcharge.
Won't depthcharge handle that aspect when it does its EC sync routine? It should notice the hash matches immediately, and then invoke its VbootDone ?
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 336: /* Unsupported */
We'll need to support this too.
Depthcharge won't be able to notice this still needs to be done and take care of it?
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 398: vb2_error_t VbExEcGetExpectedImage(int devidx, enum VbSelectFirmware_t select,
We should really get rid of this callback in vboot before doing this.
I'll look into that.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 417: outer
nit: weird name? (If you don't want to make up something specific, we usually just call it 'sw'. […]
Yeah, missed that. The mdelay was originally an "inner" stopwatch, and so that one was the "outer" one :). Done.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 439: %lus, and "
... […]
and I don't remember now :) Done.
Karthik Ramasubramanian has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 3: * : * Copyright 2019 Google LLC : * : * This program is free software; you can redistribute it and/or modify : * it under the terms of the GNU General Public License as published by : * the Free Software Foundation; version 2 of the License. : * : * This program is distributed in the hope that it will be useful, : * but WITHOUT ANY WARRANTY; without even the implied warranty of : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the : * GNU General Public License for more details. : */
vote? I can take it out if it's not supposed to be there anymore. I didn't know.
The last I remember, we should use "Copyright 2019 The coreboot project Authors." and not Google LLC
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 2:
(5 comments)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 41: EC_LPC_HOST_PACKET_SIZE
That's true, we could use the stack; isn't the stack in CAR as well ?
Yes, on x86 the stack is in CAR. The difference is that we already allocate a stack anyway, whereas allocating static buffers increases the size of the stage image (and particularly on SRAM systems that may sometimes make us hit the limit). So it's generally always better to allocate things on the stack, but you need to of course be careful to not blow it. (We used to say that stacks may be as small as 2KB for some really restricted boards, although I think we never actually went that low on any board, and everything this will run on should probably at least use 4K or more. The compiler enforces individual functions to not use more than 1.5K as a vague heuristic, but it can't stack how many functions with big allocations we chain together.)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 64: memcpy(ctx.workbuf, (void *)p, wd->buffer_size);
I wasn't sure if it was okay to reuse the work buffer directly (does depthcharge need data from it?) […]
The workbuffer *has* to be the same across all calls to vboot, otherwise all sorts of things inside vboot won't work. With persistent context, this will work automatically. (If possible, I'd suggest you wait working on this particular part for now and hopefully Joel can get his stuff in sometime soon, then all of this should become way easier.)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 68: vbnv_init(ctx.nvdata);
Any idea on when persistent context will be ready? We're trying to move forward with this as the so […]
Let's move schedule discussions to the bug (b/112198832).
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 331: vb2_error_t VbExEcVbootDone(int in_recovery)
Won't depthcharge handle that aspect when it does its EC sync routine? It should notice the hash ma […]
Yes, but the intention there was to run that check as soon as the EC is in RW. This is part of the same brownout problem... it makes sure we wait until the EC confirms it has negotiated a PD contract or charged the battery far enough or done whatever it thinks it needs to do to proceed to the more power-hungry parts of boot.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 336: /* Unsupported */
Depthcharge won't be able to notice this still needs to be done and take care of it?
I don't think the goal here should be to permanently leave vestigial parts of EC software sync running in depthcharge. Once this work is finished and running on all future platforms we can remove the respective stuff from depthcharge and the kernel verification flow. So this should do everything that EC software sync in depthcharge is currently doing (and for the battery cutoff stuff I don't see any reason not to pull it forward to here).
Joel Kitching has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 2:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 50: vboot_sync_ec
Understood, is persistent context implemented yet?
Not yet.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 64: memcpy(ctx.workbuf, (void *)p, wd->buffer_size);
The workbuffer *has* to be the same across all calls to vboot, otherwise all sorts of things inside […]
See bug for timeline.
Patrick Georgi has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 3: * : * Copyright 2019 Google LLC : * : * This program is free software; you can redistribute it and/or modify : * it under the terms of the GNU General Public License as published by : * the Free Software Foundation; version 2 of the License. : * : * This program is distributed in the hope that it will be useful, : * but WITHOUT ANY WARRANTY; without even the implied warranty of : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the : * GNU General Public License for more details. : */
The last I remember, we should use "Copyright 2019 The coreboot project Authors. […]
There's a cleanup effort going on that will also replace the text here with a simple SPDX header. See https://review.coreboot.org/c/coreboot/+/36176 for an example of that proposal.
In the meantime, I wouldn't hold myself up on the details for too long because Martin is going through the entire tree with a fine comb (like in https://review.coreboot.org/c/coreboot/+/35184)
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 2:
(9 comments)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 3: * : * Copyright 2019 Google LLC : * : * This program is free software; you can redistribute it and/or modify : * it under the terms of the GNU General Public License as published by : * the Free Software Foundation; version 2 of the License. : * : * This program is distributed in the hope that it will be useful, : * but WITHOUT ANY WARRANTY; without even the implied warranty of : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the : * GNU General Public License for more details. : */
There's a cleanup effort going on that will also replace the text here with a simple SPDX header. […]
I talked with Martin and he said it's ok to just use this w/o the 'Copyright' line for now.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 41: EC_LPC_HOST_PACKET_SIZE
Yes, on x86 the stack is in CAR. […]
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 50: vboot_sync_ec
Not yet.
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 52: static uint8_t temp_workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE];
See below.
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 64: memcpy(ctx.workbuf, (void *)p, wd->buffer_size);
See bug for timeline.
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 68: vbnv_init(ctx.nvdata);
Let's move schedule discussions to the bug (b/112198832).
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 331: vb2_error_t VbExEcVbootDone(int in_recovery)
Yes, but the intention there was to run that check as soon as the EC is in RW. […]
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 336: /* Unsupported */
I don't think the goal here should be to permanently leave vestigial parts of EC software sync runni […]
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 398: vb2_error_t VbExEcGetExpectedImage(int devidx, enum VbSelectFirmware_t select,
I'll look into that.
Done
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 2:
(10 comments)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.h:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 23: vboot_sync_ec Since this will most likely be the only function in this header file, can it be instead added to vboot_common.h?
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 135: break; Should we just fall through to allow the mdelay() before calling google_chromeec_get_vboot_hash() again?
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 241: rdev_readat If you use cbfs_boot_locate() --> rdev_mmap() --> actions --> rdev_munmap() then you wouldn't need the local storage in this file at all. For systems using memory mapped SPI flash, you will read directly from memory mapped region. For systems without memory mapped SPI flash, rdev_mmap() will ensure that it maps to cbfs_cache and reads hit that cache. So, readat to a local buffer would be eliminated in this function.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 267: rv == VBERROR_EC_REBOOT_TO_RO_REQUIRED || rv != VB2_SUCCESS Shouldn't this just be: if (rv != VB2_SUCCESS) return rv;
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 320: google_chromeec_init();
That's a fair point. I'll split that up.
Yeah this function seems really weird. Do we really need it here? I know it is named init, but it doesn't really seem to initialize anything.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 321: if (google_ec_running_ro()) { : *in_rw = 0; : } else { : *in_rw = 1; : } *in_rw = !google_ec_running_ro();
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 336: /* Unsupported */
Done
We will probably have to look at this on a case-by-case basis to see if every board is okay with moving SW sync to depthcharge. Mostly I would think so unless we have some corner cases where EC SW sync is taking a super long time.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 364: cbfs_boot_map_with_leak This wouldn't work for non-x86 systems. See my comment about using cbfs_boot_locate(), etc.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 419: assert(devidx == 0); Probably goes away once you update vboot.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 433: -1 VB2_ERROR_UNKNOWN?
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 2:
(6 comments)
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 267: rv == VBERROR_EC_REBOOT_TO_RO_REQUIRED || rv != VB2_SUCCESS
Shouldn't this just be: […]
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 320: google_chromeec_init();
Yeah this function seems really weird. […]
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 321: if (google_ec_running_ro()) { : *in_rw = 0; : } else { : *in_rw = 1; : }
*in_rw = !google_ec_running_ro();
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 364: cbfs_boot_map_with_leak
This wouldn't work for non-x86 systems. See my comment about using cbfs_boot_locate(), etc.
Yeah this is changed in the next patchset.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 419: assert(devidx == 0);
Probably goes away once you update vboot.
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 433: -1
VB2_ERROR_UNKNOWN?
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/+/36208
to look at the new patch set (#3).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 2 files changed, 486 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/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/+/36208
to look at the new patch set (#4).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 2 files changed, 486 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/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/+/36208
to look at the new patch set (#5).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 2 files changed, 486 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/5
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 5:
(10 comments)
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 14: #include <2ec_sync.h> Joel would know better but I think you're not supposed to do this (should be chain-included from vb2_api.h instead, and maybe defined in 2api.h instead of 2ec_sync.h).
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 27: #define alloca(size) __builtin_alloca(size) Please put this in commonlib/include/commonlib/helpers.h in a separate patch.
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 38: static void *ec_image_mapping; Please don't use globals to pass parameters around. You should instead pass a (struct region_device *) parameter into ec_flash_write() and do the mmap/unmap inside that function.
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 136: break; I agree with Furquan, I think the fall-through here would be a good idea.
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 233: uint8_t *file_buf = (uint8_t *)ec_image_mapping; No, I think you misunderstood what Furquan meant. If you rdev_mmap_full() the whole thing on a non-x86 device, it will blow the CBFS cache immediately. You need to only map one burst size at a time (with rdev_mmap()) and then unmap it again before you map the next chunk.
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 353: * so we just use the 32-byte buffer for reading the hash I think for 32 bytes it's okay to just use cbfs_boot_map_with_leak(). We can afford that much.
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 379: /* Unsupported */ nit: should explain why this cannot happen.
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 464: while (google_chromeec_hello()) { This is going to be somewhat problematic on SPI devices, because the coreboot ec_spi.c driver doesn't yet have the improvements that were made to depthcharge in CL:371642. That doesn't block this patch but it would be great if you could pull that over later once you got this working for LPC devices.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 241: rdev_readat
If you use cbfs_boot_locate() --> rdev_mmap() --> actions --> rdev_munmap() then you wouldn't need t […]
That's just sorta pushing the problem around for SRAM systems... either you put it on the stack or in the CBFS cache, but both of them might be pretty small and run out. But okay, we can try the mmap() method first and see how well that works once we have SRAM platforms actually using this.
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 336: /* Unsupported */
unless we have some corner cases where EC SW sync is taking a super long time.
Well, Wilco is one of those cases, apparently. So at least for that we'll need to keep the depthcharge path around for a while. Let's hope we can get rid of Wilco ECs soon. (But yeah, for everything else we should make the romstage sync the new default.)
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 5:
(7 comments)
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 27: #define alloca(size) __builtin_alloca(size)
Please put this in commonlib/include/commonlib/helpers.h in a separate patch.
Done
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 38: static void *ec_image_mapping;
Please don't use globals to pass parameters around. […]
Done
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 136: break;
I agree with Furquan, I think the fall-through here would be a good idea.
-Wimplicit-fallthrough is enabled, I'll just add the mdelay here, too.
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 233: uint8_t *file_buf = (uint8_t *)ec_image_mapping;
No, I think you misunderstood what Furquan meant. […]
Ah, I see. Yes, I did misunderstand. Will update.
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 353: * so we just use the 32-byte buffer for reading the hash
I think for 32 bytes it's okay to just use cbfs_boot_map_with_leak(). We can afford that much.
Done
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 379: /* Unsupported */
nit: should explain why this cannot happen.
Done
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 464: while (google_chromeec_hello()) {
This is going to be somewhat problematic on SPI devices, because the coreboot ec_spi. […]
b/143381650
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/+/36208
to look at the new patch set (#6).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 2 files changed, 475 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/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/+/36208
to look at the new patch set (#7).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 2 files changed, 521 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/7
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 7:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/7/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/7/src/security/vboot/ec_sync.... PS7, Line 395: while(1) { space required before the open parenthesis '('
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/+/36208
to look at the new patch set (#8).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 2 files changed, 521 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/8
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 8:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/7/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/7/src/security/vboot/ec_sync.... PS7, Line 395: while(1) {
space required before the open parenthesis '('
Done
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 8:
(7 comments)
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 136: break;
-Wimplicit-fallthrough is enabled, I'll just add the mdelay here, too.
What that means is that you have to put a comment like /* fall-through */ there, it doesn't mean you're not allowed to do fall-throughs at all.
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 14: #include <2api.h> vb2_api.h
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 37: LIMIT_POWER_WAIT_TIMEOUT Please suffix this with a unit (e.g. _MS).
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 39: #define LIMIT_POWER_POLL_SLEEP 10 This too
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 236: MIN(1024 I think we may need to move this into google_chromeec_flash_write_burst_size(), because we still need to write a whole write block at a time. (Also, it currently doesn't take the struct ec_params_flash_write size into account, which I think it should.)
Maybe you'll need to move the whole burst size function into this file (and make it static) so the compiler can inline it and guarantee statically that the stack size is capped.
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 398: "flag.\n"); No need to break?
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 416: limit_power_wait_time += LIMIT_POWER_POLL_SLEEP; nit: Would be better to solve this with the stopwatch API
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 8:
(5 comments)
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 99: static Why is this static?
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 232: int vb2_error_t
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 244: -1 VB2_ERROR_UNKNOWN
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 270: -1 VB2_ERROR_UNKNOWN
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 273: 0 VB2_SUCCESS
Joel Kitching has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 8:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 232: int
vb2_error_t
To be honest, I'm not sure if there's a point in using vb2_error_t, if the only return values being used are VB2_SUCCESS and VB2_UNKNOWN_ERROR. Seems like a lot of functions are doing that. If there are useful return values that could be bubbled up, we should add them to 2return_codes.h. If not, maybe it doesn't make sense to use vb2_error_t.
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 8:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 232: int
To be honest, I'm not sure if there's a point in using vb2_error_t, if the only return values being […]
I am fine either ways. I think it is just important to be consistent. We probably need the vb2_error_t for piping it back to vboot, so it might be just easy to have the functions return that and not always update the return types in callback functions. But, I don't see a big problem either ways as long as we are consistent.
Joel Kitching has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 8:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 232: int
I am fine either ways. I think it is just important to be consistent. […]
Note that we have a similar discussion going on here: https://chromium-review.googlesource.com/c/chromiumos/platform/depthcharge/+...
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 8:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 232: int
Note that we have a similar discussion going on here: […]
I think it makes sense to be consistent per-file. This file is vboot-specific so there's nothing wrong with still using vboot errors in here (and in some cases it's relevant, for the REBOOT_TO_RO_REQUIRED stuff).
Karthik Ramasubramanian has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 8:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 99: static
Why is this static?
I think it is static because the address of hash_digest buffer from the response is returned/assigned to **hash parameter.
I am not sure if it cannot be copied over instead of returning the address.
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 119: (recalc_requested) Since we have set EC_VBOOT_HASH_STATUS_BUSY and checking against that explicitly, at what point is this check required?
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 8:
(12 comments)
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 14: #include <2api.h>
vb2_api. […]
Done
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 37: LIMIT_POWER_WAIT_TIMEOUT
Please suffix this with a unit (e.g. _MS).
Done
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 39: #define LIMIT_POWER_POLL_SLEEP 10
This too
Done
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 99: static
I think it is static because the address of hash_digest buffer from the response is returned/assigne […]
Exactly, there is no information in the API about the required lifetime of the "returned" buffer (resp.hash_digest), so this way there is no concern.
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 119: (recalc_requested)
Since we have set EC_VBOOT_HASH_STATUS_BUSY and checking against that explicitly, at what point is t […]
Excellent point, this was ported straight from depthcharge w/ as few changes as possible. But that looks completely unnecessary. Will eliminate it.
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 232: int
I think it makes sense to be consistent per-file. […]
Done
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 236: MIN(1024
I think we may need to move this into google_chromeec_flash_write_burst_size(), because we still nee […]
I've removed that function in the next patch and integrated the logic into ec_flash_write().
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 244: -1
VB2_ERROR_UNKNOWN
Done
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 270: -1
VB2_ERROR_UNKNOWN
Done
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 273: 0
VB2_SUCCESS
Done
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 398: "flag.\n");
No need to break?
Was a return next line, see next CL for a refactor.
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 416: limit_power_wait_time += LIMIT_POWER_POLL_SLEEP;
nit: Would be better to solve this with the stopwatch API
Done
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 8:
(4 comments)
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 14: #include <2ec_sync.h>
Joel would know better but I think you're not supposed to do this (should be chain-included from vb2 […]
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.h:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 23: vboot_sync_ec
Since this will most likely be the only function in this header file, can it be instead added to vbo […]
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... File src/security/vboot/sync_ec.c:
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 135: break;
Should we just fall through to allow the mdelay() before calling google_chromeec_get_vboot_hash() ag […]
Done
https://review.coreboot.org/c/coreboot/+/36208/2/src/security/vboot/sync_ec.... PS2, Line 241: rdev_readat
That's just sorta pushing the problem around for SRAM systems... […]
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/+/36208
to look at the new patch set (#9).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 561 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/9
Tim Wawrzynczak has abandoned this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Abandoned
Squashed into 32607
Tim Wawrzynczak has restored this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Restored
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 9:
(9 comments)
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/Kconfig File src/security/vboot/Kconfig:
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/Kconfig@... PS9, Line 230: depends on CHROMEOS Why? (If anything, I'd say it depends on EC_GOOGLE_CHROMEEC.)
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 119: (recalc_requested)
Excellent point, this was ported straight from depthcharge w/ as few changes as possible. […]
Isn't resp.status re-read from the EC on every loop iteration? We just set it to BUSY so we don't exit the loop, but then it might already be something else again by the time we get back here. This looks to me like it's intended to avoid us spamming the EC with new START_HASH requests too quickly before it has a chance to process one of those requests far enough to switch its internal hash status to BUSY. I'm not sure if that's really a concern in practice with the current EC code, but from a purely AP point of view it's not just dead code.
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 113: case EC_VBOOT_HASH_STATUS_NONE: Like mentioned in the other patch set I think we should keep the recalc_requested unless someone can say for certain from the EC sources that it's not needed.
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 235: if (google_chromeec_get_protocol_info(&resp_proto)) nit: might be worth an error message
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 245: return 0; This should be an error (right?) and should probably also print something.
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 258: burst -= sizeof(struct ec_host_request); No, this... isn't this all wrong? 'burst' *must* be an exact multiple of write_block_size, and the total size of the packet (n * burst + headers) must be smaller or equal to both pdata_max_size and 1024.
I think what you want is
/* Hard limit packet buffer stack allocation size to 1K. */ pdata_max_size = MIN(1024, resp_proto.max_request_packet_size);
burst = pdata_max_size - sizeof(*p); burst = (burst / resp_flash.write_block_size) * resp_flash.write_block_size;
p = alloca(burst + sizeof(*p));
(I don't think you need to count ec_host_request? That's generated separately by the EC command handler, it's not on the alloca buffer.)
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 261: bufsize = MIN(1024, burst); ...uhhh... and here you're potentially shrinking the buffer to a smaller size but still using the larger size in the code that fills it below? Bad idea. See above.
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 427: "flag.\n"); I think you misunderstood my comment here, I meant there seems to be no need for a line break in this string
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 428: rv = VB2_ERROR_UNKNOWN; (I think the immediate return here was fine btw)
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Martin Roth, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#10).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 581 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/10
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 10:
(9 comments)
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/Kconfig File src/security/vboot/Kconfig:
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/Kconfig@... PS9, Line 230: depends on CHROMEOS
Why? (If anything, I'd say it depends on EC_GOOGLE_CHROMEEC. […]
Ah, I missed that one. That fits better.
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/8/src/security/vboot/ec_sync.... PS8, Line 119: (recalc_requested)
Isn't resp. […]
Sure, I assumed that was the case too, it was to avoid asking for it too quickly, hence it would grab the response the next time around, after the initial delay. In depthcharge, there is no initial delay, but there is here (see line 140). 5 or 10 ms ought to be plenty of time for the EC to switch that status indicator, but fair point, I'll leave it in.
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 113: case EC_VBOOT_HASH_STATUS_NONE:
Like mentioned in the other patch set I think we should keep the recalc_requested unless someone can […]
Yeah thinking about it more, I'll just keep it in.
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 235: if (google_chromeec_get_protocol_info(&resp_proto))
nit: might be worth an error message
Done
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 245: return 0;
This should be an error (right?) and should probably also print something.
Yeah that's an error. Fixed.
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 258: burst -= sizeof(struct ec_host_request);
No, this... […]
Yes, I think I got myself tangled up here. Your'e right about the ec_host_request as well, the lpc/i2c/spi drivers take care of that.
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 261: bufsize = MIN(1024, burst);
...uhhh... […]
Done
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 427: "flag.\n");
I think you misunderstood my comment here, I meant there seems to be no need for a line break in thi […]
Just for the 80-character line limit.
https://review.coreboot.org/c/coreboot/+/36208/9/src/security/vboot/ec_sync.... PS9, Line 428: rv = VB2_ERROR_UNKNOWN;
(I think the immediate return here was fine btw)
Ack
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Martin Roth, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#11).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 581 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/11
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 11:
(5 comments)
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... PS11, Line 269: burst = pdata_max_size - sizeof(*params); This could go negative for weird edge cases, so lets make burst an int or ssize_t to be safe.
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... PS11, Line 273: if (burst <= sizeof(struct ec_params_flash_write)) { This check doesn't make much sense now because 'burst' doesn't include actually the space for the params. Really all you want to check at this point is that burst is larger than zero.
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... PS11, Line 280: read_buffer = alloca(bufsize); nit: not sure why you need that extra variable rather than doing
params = alloca(bufsize);
directly
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... PS11, Line 300: - noop for a memory region (Not sure what this means, I think you're thinking of memory-mapped SPI which is explicitly not really "a memory region". CBFS cache *is* a memory region but there this is not a no-op. I'm not sure you really need a comment at all here, the rdev API is pretty ubiquitous and well-understood across coreboot.)
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... PS11, Line 307: printk(BIOS_ERR, "EC failed flash write command!\n"); nit: maybe print offset?
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 11:
(5 comments)
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... PS11, Line 269: burst = pdata_max_size - sizeof(*params);
This could go negative for weird edge cases, so lets make burst an int or ssize_t to be safe.
Hmm, I suppose it could... ssize_t it is.
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... PS11, Line 273: if (burst <= sizeof(struct ec_params_flash_write)) {
This check doesn't make much sense now because 'burst' doesn't include actually the space for the pa […]
Ack
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... PS11, Line 280: read_buffer = alloca(bufsize);
nit: not sure why you need that extra variable rather than doing […]
That's fair, it isn't really necessary.
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... PS11, Line 300: - noop for a memory region
(Not sure what this means, I think you're thinking of memory-mapped SPI which is explicitly not real […]
Ok, it wasn't familiar to me when I started this :)
https://review.coreboot.org/c/coreboot/+/36208/11/src/security/vboot/ec_sync... PS11, Line 307: printk(BIOS_ERR, "EC failed flash write command!\n");
nit: maybe print offset?
Done
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Martin Roth, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#12).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 579 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/12
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Martin Roth, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#13).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 579 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/13
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 13:
Okay, I think this looks good now, other than the context stuff where we're still waiting on Joel.
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 13:
Patch Set 13:
Okay, I think this looks good now, other than the context stuff where we're still waiting on Joel.
Great, thanks for your reviews!
Karthik Ramasubramanian has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... PS13, Line 64: ctx.flags |= VB2_CONTEXT_EC_SYNC_SUPPORTED; Probably need static initialization of ctx, so that flags don't contain unexpected flags set.
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... PS13, Line 64: ctx.flags |= VB2_CONTEXT_EC_SYNC_SUPPORTED;
Probably need static initialization of ctx, so that flags don't contain unexpected flags set.
The initialization of all of the context, etc. will change once Joel gets the persistent vboot context work done. This patch is blocked on those changes.
Karthik Ramasubramanian has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... PS13, Line 279: bufsize bufsize is not initialized. Probably pdata_max_size and bufsize can be dropped?
Karthik Ramasubramanian has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... PS13, Line 303: read_buffer I believe it is params
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 13:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... PS13, Line 279: bufsize
bufsize is not initialized. […]
Oops, good catch. Yeah bufsize should be burst.
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... PS13, Line 303: read_buffer
I believe it is params
Yep, thanks.
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... PS13, Line 268: burst = pdata_max_size - sizeof(*params); Actually, this does have to take into account sizeof(struct ec_host_request). See https://review.coreboot.org/cgit/coreboot.git/tree/src/ec/google/chromeec/ec..., where the ec_params_* and any extra data gets put into the LPC port space after the EC host request structure, so 256 bytes is all that can be sent over LPC at one time.
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Martin Roth, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#14).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 578 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/14
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 14:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/14/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/14/src/security/vboot/ec_sync... PS14, Line 302: if (google_chromeec_flash_write_block((const uint8_t*)params, todo)) { "(foo*)" should be "(foo *)"
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Martin Roth, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#15).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 579 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/15
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 15:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/14/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/14/src/security/vboot/ec_sync... PS14, Line 302: if (google_chromeec_flash_write_block((const uint8_t*)params, todo)) {
"(foo*)" should be "(foo *)"
Done
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 15:
(6 comments)
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... PS13, Line 268: burst = pdata_max_size - sizeof(*params);
Actually, this does have to take into account sizeof(struct ec_host_request). See https://review. […]
Sorry, yes, I wasn't thinking right. It *does* matter for the EC max packet size, but not for the stack-allocated buffer. So need to pull those two things apart a bit again.
https://review.coreboot.org/c/coreboot/+/36208/13/src/security/vboot/ec_sync... PS13, Line 279: bufsize
Oops, good catch. Yeah bufsize should be burst.
burst + sizeof(*params), to be precise
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/ec_sync... PS15, Line 26: nit: why?
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/ec_sync... PS15, Line 267: burst = (pdata_max_size - sizeof(*params)) - sizeof(struct ec_host_request); Well, you're throwing away a bit of stack space here now. Instead, I would just change the line above to
pdata_max_size = MIN(1024, resp_proto.max_request_packet_size - sizeof(struct ec_host_request));
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/ec_sync... PS15, Line 295: file_buf += todo; This doesn't do anything anymore now (in fact it would probably break the munmap() below on a platform where that's not a no-op).
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/ec_sync... PS15, Line 301: todo += sizeof(struct ec_params_flash_write); nit: This just threw me for a loop a bit, I think it would be easier to follow if you just write 'sizeof(*params) + todo' explicitly below.
Joel Kitching has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 15:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/Kconfig File src/security/vboot/Kconfig:
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/Kconfig... PS15, Line 236: is already : currently performed later in the boot flow. will be performed later in the boot flow if it is disabled here.
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/3/src/security/vboot/ec_sync.... PS3, Line 14: #include <2ec_sync.h>
Done
And also it should be ordered alphabetically -- i.e. after vb2_constants.h. Also, since we're adding vb2_api.h, we don't need to include vb2_constants.h anymore.
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 15:
(5 comments)
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/Kconfig File src/security/vboot/Kconfig:
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/Kconfig... PS15, Line 236: is already : currently performed later in the boot flow.
will be performed later in the boot flow if it is disabled here.
Done
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/ec_sync... PS15, Line 26:
nit: why?
Auto-indent :) Changed back.
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/ec_sync... PS15, Line 267: burst = (pdata_max_size - sizeof(*params)) - sizeof(struct ec_host_request);
Well, you're throwing away a bit of stack space here now. […]
Yeah that's true. Updated.
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/ec_sync... PS15, Line 295: file_buf += todo;
This doesn't do anything anymore now (in fact it would probably break the munmap() below on a platfo […]
Done
https://review.coreboot.org/c/coreboot/+/36208/15/src/security/vboot/ec_sync... PS15, Line 301: todo += sizeof(struct ec_params_flash_write);
nit: This just threw me for a loop a bit, I think it would be easier to follow if you just write 'si […]
Done
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Martin Roth, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#16).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 581 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/16
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 16:
(3 comments)
https://review.coreboot.org/c/coreboot/+/36208/16/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/16/src/security/vboot/ec_sync... PS16, Line 264: sizeof(struct ec_host_request)); nit: might be nice to align with 'resp...'?
https://review.coreboot.org/c/coreboot/+/36208/16/src/security/vboot/ec_sync... PS16, Line 285: uint32_t block_size = todo + sizeof(*params); nit: block_size sounds quite weird because that makes me think of the flash block. maybe xfer_size?
https://review.coreboot.org/c/coreboot/+/36208/16/src/security/vboot/ec_sync... PS16, Line 432: int in_recovery = !!sd->recovery_reason; Here too please check the context flag instead.
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Martin Roth, Furquan Shaikh, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#17).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 581 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/17
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 17:
(3 comments)
https://review.coreboot.org/c/coreboot/+/36208/16/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/16/src/security/vboot/ec_sync... PS16, Line 264: sizeof(struct ec_host_request));
nit: might be nice to align with 'resp... […]
Done
https://review.coreboot.org/c/coreboot/+/36208/16/src/security/vboot/ec_sync... PS16, Line 285: uint32_t block_size = todo + sizeof(*params);
nit: block_size sounds quite weird because that makes me think of the flash block. […]
Fair point, done.
https://review.coreboot.org/c/coreboot/+/36208/16/src/security/vboot/ec_sync... PS16, Line 432: int in_recovery = !!sd->recovery_reason;
Here too please check the context flag instead.
Done
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 17:
(9 comments)
https://review.coreboot.org/c/coreboot/+/36208/17//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/36208/17//COMMIT_MSG@12 PS17, Line 12: This patch assumes that the EC image is added to CBFS : uncompressed. How is this guaranteed in Chrome OS build? Are you adding a new USE flag which ensures that it selects VBOOT_EARLY_EC_SYNC in coreboot and adds the ecrw image uncompressed when building chromeos-bootimage?
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/Kconfig File src/security/vboot/Kconfig:
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/Kconfig... PS17, Line 233: nit: extra space
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... PS17, Line 108: rv = google_chromeec_get_vboot_hash(hash_offset, &resp); : if (rv) : return VB2_ERROR_UNKNOWN; nit:
if (google_chromeec_get_vboot_hash(hash_offset, &resp)) return VB2_ERROR_UNKNOWN;
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... PS17, Line 167: nit: I think it would be helpful to print out how long it took to get the hash calculations using stopwatch_duration_usecs(). I know you are adding some new timestamps (have to check the latest revision of that CL). If this is already covered somewhere, please feel free to ignore.
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... PS17, Line 268: (burst / resp_flash.write_block_size) * : resp_flash.write_block_size; ALIGN_DOWN(burst, resp_flash.write_block_size);
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... PS17, Line 362: rv = VB2_ERROR_UNKNOWN Did you intend to do: return VB2_ERROR_UNKNOWN;
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... PS17, Line 373: uint8_t const
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... PS17, Line 417: google_chromeec_get_current_image Why is this call required? google_ec_running_ro() calls google_chromeec_get_current_image() internally.
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... PS17, Line 541: 3000 nit: Probably good to define this as macros at the start of the file just like other timeout values?
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Martin Roth, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#18).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 585 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/18
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 18:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36208/17//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/36208/17//COMMIT_MSG@12 PS17, Line 12: This patch assumes that the EC image is added to CBFS : uncompressed.
I have been waiting for these changes to land so that the Kconfig name is set, but the ebuild looks […]
Oh okay. Cool. Thanks!
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... PS17, Line 268: (burst / resp_flash.write_block_size) * : resp_flash.write_block_size;
Doesn't that mean that resp_flash.write_block_size must be a power of two?
Yes, that is the requirement.
Is there a guarantee of that in the EC?
Write block size seems to be the minimum number of bytes required in a write which currently seems to be a power of 2 in the EC. But, I don't see anything enforcing that check in the EC.
It might be okay just leaving this as is. If you use ALIGN_DOWN(), it would be good to at least add an assert() ensuring that the write_block_size is a power of 2.
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 18:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... PS17, Line 268: (burst / resp_flash.write_block_size) * : resp_flash.write_block_size;
Doesn't that mean that resp_flash.write_block_size must be a power of two? […]
Depthcharge never made this assumption, and even though this does save a multiply and a divide that have a RAW dependency, it's only called once per boot. Hmm, but it's probably a safe assumption that Flash will always use power-of-2 sized pages... Unless you feel strongly about this, I'd rather leave it this way.
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 18:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/17/src/security/vboot/ec_sync... PS17, Line 268: (burst / resp_flash.write_block_size) * : resp_flash.write_block_size;
Depthcharge never made this assumption, and even though this does save a multiply and a divide that […]
I am okay with leaving it as is.
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Martin Roth, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#19).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 585 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/19
Joel Kitching has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 19:
(4 comments)
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/ec_sync... PS19, Line 73: x %#x
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/ec_sync... PS19, Line 73: Software sync on EC EC software sync
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/ec_sync... PS19, Line 75: /* TODO: vboot persistent context */ : vboot_finalize_work_context(&ctx); Note that this can just be removed after persistent context is merged.
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/vboot_c... File src/security/vboot/vboot_common.h:
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/vboot_c... PS19, Line 91: VBERROR_ VB2_ERROR_*
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 19:
(4 comments)
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/ec_sync... PS19, Line 73: x
%#x
Done
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/ec_sync... PS19, Line 73: Software sync on EC
EC software sync
Done
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/ec_sync... PS19, Line 75: /* TODO: vboot persistent context */ : vboot_finalize_work_context(&ctx);
Note that this can just be removed after persistent context is merged.
Ack
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/vboot_c... File src/security/vboot/vboot_common.h:
https://review.coreboot.org/c/coreboot/+/36208/19/src/security/vboot/vboot_c... PS19, Line 91: VBERROR_
VB2_ERROR_*
Done
Joel Kitching has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 19: Code-Review+1
LGTM. Just waiting on https://review.coreboot.org/c/coreboot/+/36300
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Martin Roth, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#20).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h 4 files changed, 576 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/20
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 20:
(6 comments)
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 54: /* Set up context and work buffer */ nit: They're already set up you're just fetching them. (In general, I don't really think you need comments for lines with a single function call when the function name is already pretty clear about what it does.)
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 58: ctx->flags &= ~VB2_CONTEXT_EC_SYNC_SLOW; There should be no way this could be set here, so no need to clear it.
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 61: vbnv_init(ctx->nvdata); No, persistent context takes care of that already now.
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 66: printk(BIOS_ERR, "EC software sync failed (%#x)\n", retval); We actually need to reboot into recovery mode on error, not just print and move on. Also, we need to write back nvdata if necessary. So you should do something like
retval = vb2api_ec_sync(ctx);
assert(!(ctx->flags & (VB2_CONTEXT_SECDATA_FIRMWARE_CHANGED | VB2_CONTEXT_SECDATA_KERNEL_CHANGED))); if (ctx->flags & VB2_CONTEXT_NVDATA_CHANGED) { save_vbnv(ctx->nvdata); ctx->flags &= ~VB2_CONTEXT_NVDATA_CHANGED; }
if (retval != VB2_SUCCESS) { printk(BIOS_ERR, "EC software sync failed (%#x), rebooting\n", retval); vboot_reboot(); }
We'll probably want to factor the saving nvdata stuff out and also use it in save_if_needed() in vboot_logic.c. (The reason I don't want the secdata saving code here is because it shouldn't be necessary and it will bloat the romstage with a bunch of TPM code that otherwise doesn't need to be there.)
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 68: return retval; Probably doesn't need a return value, then.
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 156: nit: maybe personal preference but I tend to not make a space between number and unit. (couple more times below, too)
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 20:
(6 comments)
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 54: /* Set up context and work buffer */
nit: They're already set up you're just fetching them. […]
Ack
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 58: ctx->flags &= ~VB2_CONTEXT_EC_SYNC_SLOW;
There should be no way this could be set here, so no need to clear it.
Paranoia, I guess. Will remove.
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 61: vbnv_init(ctx->nvdata);
No, persistent context takes care of that already now.
Because it's already done in verstage, correct?
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 66: printk(BIOS_ERR, "EC software sync failed (%#x)\n", retval);
We actually need to reboot into recovery mode on error, not just print and move on. […]
Gotcha, same logic as in vboot_logic.c. I'll add a refactor for the data saving. +1 to the assert.
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 68: return retval;
Probably doesn't need a return value, then.
I suppose not.
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 156:
nit: maybe personal preference but I tend to not make a space between number and unit. […]
Doesn't matter to me, I can remove the spaces.
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Martin Roth, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#21).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h M src/security/vboot/vboot_logic.c 5 files changed, 588 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/21
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 21:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36208/21/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/21/src/security/vboot/ec_sync... PS21, Line 61: trailing whitespace
https://review.coreboot.org/c/coreboot/+/36208/21/src/security/vboot/vboot_c... File src/security/vboot/vboot_common.h:
https://review.coreboot.org/c/coreboot/+/36208/21/src/security/vboot/vboot_c... PS21, Line 94: * "slow" updates or Auxilliary FW sync. 'Auxilliary' may be misspelled - perhaps 'Auxiliary'?
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Martin Roth, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#22).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h M src/security/vboot/vboot_logic.c 5 files changed, 588 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/22
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 22:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36208/21/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/21/src/security/vboot/ec_sync... PS21, Line 61:
trailing whitespace
Done
https://review.coreboot.org/c/coreboot/+/36208/21/src/security/vboot/vboot_c... File src/security/vboot/vboot_common.h:
https://review.coreboot.org/c/coreboot/+/36208/21/src/security/vboot/vboot_c... PS21, Line 94: * "slow" updates or Auxilliary FW sync.
'Auxilliary' may be misspelled - perhaps 'Auxiliary'?
Done
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 22:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/20/src/security/vboot/ec_sync... PS20, Line 61: vbnv_init(ctx->nvdata);
Because it's already done in verstage, correct?
Right.
https://review.coreboot.org/c/coreboot/+/36208/22/src/security/vboot/vboot_c... File src/security/vboot/vboot_common.h:
https://review.coreboot.org/c/coreboot/+/36208/22/src/security/vboot/vboot_c... PS22, Line 90: void save_secdata_if_needed(struct vb2_context *ctx); These need to be namespaced properly (e.g. vboot_save_nvdata()). I'd maybe consider making them vboot_save_nvdata_only() and vboot_save_data(), since we'd normally want to either save everything or only save nvdata when we're confident that secdata cannot change at that point (since saving nvdata is cheap and doesn't pull in much extra code anyway). Then you could also move that assert that secdata didn't change into vboot_save_nvdata_only().
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 22:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/22/src/security/vboot/vboot_c... File src/security/vboot/vboot_common.h:
https://review.coreboot.org/c/coreboot/+/36208/22/src/security/vboot/vboot_c... PS22, Line 90: void save_secdata_if_needed(struct vb2_context *ctx);
These need to be namespaced properly (e.g. vboot_save_nvdata()). […]
Gotcha, that all makes sense.
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Martin Roth, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#23).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h M src/security/vboot/vboot_logic.c 5 files changed, 590 insertions(+), 12 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/23
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 23:
(1 comment)
https://review.coreboot.org/c/coreboot/+/36208/23/src/security/vboot/vboot_c... File src/security/vboot/vboot_common.h:
https://review.coreboot.org/c/coreboot/+/36208/23/src/security/vboot/vboot_c... PS23, Line 94: * "slow" updates or Auxilliary FW sync. 'Auxilliary' may be misspelled - perhaps 'Auxiliary'?
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Martin Roth, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#24).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h M src/security/vboot/vboot_logic.c 5 files changed, 590 insertions(+), 12 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/24
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 24:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36208/24/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/24/src/security/vboot/ec_sync... PS24, Line 58: vboot_save_nvdata_only(); Forgot the argument.
https://review.coreboot.org/c/coreboot/+/36208/24/src/security/vboot/vboot_l... File src/security/vboot/vboot_logic.c:
https://review.coreboot.org/c/coreboot/+/36208/24/src/security/vboot/vboot_l... PS24, Line 274: VB2_CONTEXT_SECDATA_KERNEL_CHANGED))); nit: align better?
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 24:
(2 comments)
https://review.coreboot.org/c/coreboot/+/36208/24/src/security/vboot/ec_sync... File src/security/vboot/ec_sync.c:
https://review.coreboot.org/c/coreboot/+/36208/24/src/security/vboot/ec_sync... PS24, Line 58: vboot_save_nvdata_only();
Forgot the argument.
Done
https://review.coreboot.org/c/coreboot/+/36208/24/src/security/vboot/vboot_l... File src/security/vboot/vboot_logic.c:
https://review.coreboot.org/c/coreboot/+/36208/24/src/security/vboot/vboot_l... PS24, Line 274: VB2_CONTEXT_SECDATA_KERNEL_CHANGED)));
nit: align better?
Done
Hello Aaron Durbin, Karthik Ramasubramanian, Julius Werner, Duncan Laurie, Shelley Chen, build bot (Jenkins), Joel Kitching, Furquan Shaikh, Martin Roth, Patrick Georgi,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/36208
to look at the new patch set (#25).
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h M src/security/vboot/vboot_logic.c 5 files changed, 590 insertions(+), 12 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/25
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 25: Code-Review+2
Aaron Durbin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 25:
We'll need to rebase this or the other set of patches (starting from https://review.coreboot.org/c/coreboot/+/3684). I can do it if anyone wants me to. Let me know. Or we land this set first, and I or Yu-Ping can rebase the other set. I have a feeling it's pretty straight forward.
Aaron Durbin has uploaded a new patch set (#26) to the change originally created by Tim Wawrzynczak. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h M src/security/vboot/vboot_logic.c 5 files changed, 590 insertions(+), 12 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/36208/26
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
Patch Set 26: Code-Review+2
Patrick Georgi has submitted this change. ( https://review.coreboot.org/c/coreboot/+/36208 )
Change subject: security/vboot: Add vboot callbacks to support EC software sync ......................................................................
security/vboot: Add vboot callbacks to support EC software sync
Use the new functions introduced into the EC driver to support performing EC software sync via vboot callbacks.
NOTE: This patch assumes that the EC image is added to CBFS uncompressed. Streaming decompression of the image will be added in a future patch.
Also adds a new Kconfig option VBOOT_EARLY_EC_SYNC. The new Kconfig option compiles EC software sync into romstage, dependent upon having a CrOS EC.
BUG=b:112198832 BRANCH=none TEST=Successful EC software sync
Change-Id: I9b1458a45ab3ed5623af50f78036c4f88461b226 Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org Reviewed-on: https://review.coreboot.org/c/coreboot/+/36208 Reviewed-by: Julius Werner jwerner@chromium.org Tested-by: build bot (Jenkins) no-reply@coreboot.org --- M src/security/vboot/Kconfig M src/security/vboot/Makefile.inc A src/security/vboot/ec_sync.c M src/security/vboot/vboot_common.h M src/security/vboot/vboot_logic.c 5 files changed, 590 insertions(+), 12 deletions(-)
Approvals: build bot (Jenkins): Verified Julius Werner: Looks good to me, approved
diff --git a/src/security/vboot/Kconfig b/src/security/vboot/Kconfig index 89e1232..df1b7e4 100644 --- a/src/security/vboot/Kconfig +++ b/src/security/vboot/Kconfig @@ -242,6 +242,18 @@ When this option is enabled cbfs_boot_locate will look for a file in the RO (COREBOOT) region if it isn't available in the active RW region.
+config VBOOT_EARLY_EC_SYNC + bool + default n + depends on EC_GOOGLE_CHROMEEC + help + Enables CrOS EC software sync in romstage, before memory training + runs. This is useful mainly as a way to achieve full USB-PD + negotiation earlier in the boot flow, as the EC will only do this once + it has made the sysjump to its RW firmware. It should not + significantly impact boot time, as this operation will be performed + later in the boot flow if it is disabled here. + menu "GBB configuration"
config GBB_HWID diff --git a/src/security/vboot/Makefile.inc b/src/security/vboot/Makefile.inc index 3e5956c..87cd91c 100644 --- a/src/security/vboot/Makefile.inc +++ b/src/security/vboot/Makefile.inc @@ -37,6 +37,8 @@ romstage-y += vbnv.c ramstage-y += vbnv.c
+romstage-$(CONFIG_VBOOT_EARLY_EC_SYNC) += ec_sync.c + bootblock-$(CONFIG_VBOOT_VBNV_CMOS) += vbnv_cmos.c verstage-$(CONFIG_VBOOT_VBNV_CMOS) += vbnv_cmos.c romstage-$(CONFIG_VBOOT_VBNV_CMOS) += vbnv_cmos.c diff --git a/src/security/vboot/ec_sync.c b/src/security/vboot/ec_sync.c new file mode 100644 index 0000000..ec048aa --- /dev/null +++ b/src/security/vboot/ec_sync.c @@ -0,0 +1,549 @@ +/* + * This file is part of the coreboot project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <assert.h> +#include <cbfs.h> +#include <console/console.h> +#include <delay.h> +#include <ec/google/chromeec/ec.h> +#include <security/vboot/misc.h> +#include <security/vboot/vbnv.h> +#include <security/vboot/vboot_common.h> +#include <timer.h> +#include <vb2_api.h> + +#define _EC_FILENAME(select, suffix) \ + (select == VB_SELECT_FIRMWARE_READONLY ? "ecro" suffix : "ecrw" suffix) +#define EC_IMAGE_FILENAME(select) _EC_FILENAME(select, "") +#define EC_HASH_FILENAME(select) _EC_FILENAME(select, ".hash") + +/* Wait 10 ms between attempts to check if EC's hash is ready */ +#define CROS_EC_HASH_CHECK_DELAY_MS 10 +/* Give the EC 2 seconds to finish calculating its hash */ +#define CROS_EC_HASH_TIMEOUT_MS 2000 + +/* Wait 3 seconds after software sync for EC to clear the limit power flag. */ +#define LIMIT_POWER_WAIT_TIMEOUT_MS 3000 +/* Check the limit power flag every 10 ms while waiting. */ +#define LIMIT_POWER_POLL_SLEEP_MS 10 + +/* Wait 3 seconds for EC to sysjump to RW */ +#define CROS_EC_SYSJUMP_TIMEOUT_MS 3000 + +/* + * The external API for EC software sync. This function calls into + * vboot, which kicks off the process. Vboot runs the verified boot + * logic, and requires the client program to provide callbacks which + * perform the work. + */ +void vboot_sync_ec(void) +{ + vb2_error_t retval = VB2_SUCCESS; + struct vb2_context *ctx; + + ctx = vboot_get_context(); + ctx->flags |= VB2_CONTEXT_EC_SYNC_SUPPORTED; + + retval = vb2api_ec_sync(ctx); + vboot_save_nvdata_only(ctx); + + if (retval != VB2_SUCCESS) { + printk(BIOS_ERR, "EC software sync failed (%#x), rebooting\n", retval); + vboot_reboot(); + } +} + +/* Convert firmware image type into a flash offset */ +static uint32_t get_vboot_hash_offset(enum vb2_firmware_selection select) +{ + switch (select) { + case VB_SELECT_FIRMWARE_READONLY: + return EC_VBOOT_HASH_OFFSET_RO; + case VB_SELECT_FIRMWARE_EC_UPDATE: + return EC_VBOOT_HASH_OFFSET_UPDATE; + default: + return EC_VBOOT_HASH_OFFSET_ACTIVE; + } +} + +/* + * Asks the EC to calculate a hash of the specified firmware image, and + * returns the information in **hash and *hash_size. + */ +static vb2_error_t ec_hash_image(enum vb2_firmware_selection select, + const uint8_t **hash, int *hash_size) +{ + static struct ec_response_vboot_hash resp; + uint32_t hash_offset; + int recalc_requested = 0; + struct stopwatch sw; + + hash_offset = get_vboot_hash_offset(select); + + stopwatch_init_msecs_expire(&sw, CROS_EC_HASH_TIMEOUT_MS); + do { + if (google_chromeec_get_vboot_hash(hash_offset, &resp)) + return VB2_ERROR_UNKNOWN; + + switch (resp.status) { + case EC_VBOOT_HASH_STATUS_NONE: + /* + * There is no hash available right now. + * Request a recalc if it hasn't been done yet. + */ + if (recalc_requested) + break; + + printk(BIOS_WARNING, + "%s: No valid hash (status=%d size=%d). " + "Computing...\n", __func__, resp.status, + resp.size); + + if (google_chromeec_start_vboot_hash( + EC_VBOOT_HASH_TYPE_SHA256, hash_offset, &resp)) + return VB2_ERROR_UNKNOWN; + + recalc_requested = 1; + + /* + * Expect status to be busy since we just sent + * a recalc request. + */ + resp.status = EC_VBOOT_HASH_STATUS_BUSY; + + /* Hash just started calculating, let it go for a bit */ + mdelay(CROS_EC_HASH_CHECK_DELAY_MS); + break; + + case EC_VBOOT_HASH_STATUS_BUSY: + /* Hash is still calculating. */ + mdelay(CROS_EC_HASH_CHECK_DELAY_MS); + break; + + case EC_VBOOT_HASH_STATUS_DONE: /* intentional fallthrough */ + default: + /* Hash is ready! */ + break; + } + } while (resp.status == EC_VBOOT_HASH_STATUS_BUSY && + !stopwatch_expired(&sw)); + + if (resp.status != EC_VBOOT_HASH_STATUS_DONE) { + printk(BIOS_ERR, "%s: Hash status not done: %d\n", __func__, + resp.status); + return VB2_ERROR_UNKNOWN; + } + if (resp.hash_type != EC_VBOOT_HASH_TYPE_SHA256) { + printk(BIOS_ERR, "EC hash was the wrong type.\n"); + return VB2_ERROR_UNKNOWN; + } + + printk(BIOS_INFO, "EC took %luus to calculate image hash\n", + stopwatch_duration_usecs(&sw)); + + *hash = resp.hash_digest; + *hash_size = resp.digest_size; + + return VB2_SUCCESS; +} + +/* + * Asks the EC to protect or unprotect the specified flash region. + */ +static vb2_error_t ec_protect_flash(enum vb2_firmware_selection select, int enable) +{ + struct ec_response_flash_protect resp; + uint32_t protected_region = EC_FLASH_PROTECT_ALL_NOW; + const uint32_t mask = EC_FLASH_PROTECT_ALL_NOW | EC_FLASH_PROTECT_ALL_AT_BOOT; + + if (select == VB_SELECT_FIRMWARE_READONLY) + protected_region = EC_FLASH_PROTECT_RO_NOW; + + if (google_chromeec_flash_protect(mask, enable ? mask : 0, &resp) != 0) + return VB2_ERROR_UNKNOWN; + + if (!enable) { + /* If protection is still enabled, need reboot */ + if (resp.flags & protected_region) + return VBERROR_EC_REBOOT_TO_RO_REQUIRED; + + return VB2_SUCCESS; + } + + /* + * If write protect and ro-at-boot aren't both asserted, don't expect + * protection enabled. + */ + if ((~resp.flags) & (EC_FLASH_PROTECT_GPIO_ASSERTED | + EC_FLASH_PROTECT_RO_AT_BOOT)) + return VB2_SUCCESS; + + /* If flash is protected now, success */ + if (resp.flags & EC_FLASH_PROTECT_ALL_NOW) + return VB2_SUCCESS; + + /* If RW will be protected at boot but not now, need a reboot */ + if (resp.flags & EC_FLASH_PROTECT_ALL_AT_BOOT) + return VBERROR_EC_REBOOT_TO_RO_REQUIRED; + + /* Otherwise, it's an error */ + return VB2_ERROR_UNKNOWN; +} + +/* Convert a firmware image type to an EC flash region */ +static enum ec_flash_region vboot_to_ec_region(enum vb2_firmware_selection select) +{ + switch (select) { + case VB_SELECT_FIRMWARE_READONLY: + return EC_FLASH_REGION_WP_RO; + case VB_SELECT_FIRMWARE_EC_UPDATE: + return EC_FLASH_REGION_UPDATE; + default: + return EC_FLASH_REGION_ACTIVE; + } +} + +/* + * Read the EC's burst size bytes at a time from CBFS, and then send + * the chunk to the EC for it to write into its flash. + */ +static vb2_error_t ec_flash_write(struct region_device *image_region, + uint32_t region_offset, int image_size) +{ + struct ec_response_get_protocol_info resp_proto; + struct ec_response_flash_info resp_flash; + ssize_t pdata_max_size; + ssize_t burst; + uint8_t *file_buf; + struct ec_params_flash_write *params; + uint32_t end, off; + + /* + * Get EC's protocol information, so that we can figure out how much + * data can be sent in one message. + */ + if (google_chromeec_get_protocol_info(&resp_proto)) { + printk(BIOS_ERR, "Failed to get EC protocol information; " + "skipping flash write\n"); + return VB2_ERROR_UNKNOWN; + } + + /* + * Determine burst 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(&resp_flash)) { + printk(BIOS_ERR, "Failed to get EC flash information; " + "skipping flash write\n"); + return VB2_ERROR_UNKNOWN; + } + + /* Limit the potential buffer stack allocation to 1K */ + pdata_max_size = MIN(1024, resp_proto.max_request_packet_size - + sizeof(struct ec_host_request)); + + /* Round burst to a multiple of the flash write block size */ + burst = pdata_max_size - sizeof(*params); + burst = (burst / resp_flash.write_block_size) * + resp_flash.write_block_size; + + /* Buffer too small */ + if (burst <= 0) { + printk(BIOS_ERR, "Flash write buffer too small! skipping " + "flash write\n"); + return VB2_ERROR_UNKNOWN; + } + + /* Allocate buffer on the stack */ + params = alloca(burst + sizeof(*params)); + + /* Fill up the buffer */ + end = region_offset + image_size; + for (off = region_offset; off < end; off += burst) { + uint32_t todo = MIN(end - off, burst); + uint32_t xfer_size = todo + sizeof(*params); + + /* Map 'todo' bytes into memory */ + file_buf = rdev_mmap(image_region, off - region_offset, todo); + if (file_buf == NULL) + return VB2_ERROR_UNKNOWN; + + params->offset = off; + params->size = todo; + + /* Read todo bytes into the buffer */ + memcpy(params + 1, file_buf, todo); + + if (rdev_munmap(image_region, file_buf)) + return VB2_ERROR_UNKNOWN; + + /* Make sure to add back in the size of the parameters */ + if (google_chromeec_flash_write_block( + (const uint8_t *)params, xfer_size)) { + printk(BIOS_ERR, "EC failed flash write command, " + "relative offset %u!\n", off - region_offset); + return VB2_ERROR_UNKNOWN; + } + } + + return VB2_SUCCESS; +} + +/* + * The logic for updating an EC firmware image. + */ +static vb2_error_t ec_update_image(enum vb2_firmware_selection select) +{ + uint32_t region_offset, region_size; + enum ec_flash_region region; + vb2_error_t rv; + size_t image_size; + struct cbfsf fh; + const char *filename; + struct region_device image_region; + + /* Un-protect the flash region */ + rv = ec_protect_flash(select, 0); + if (rv != VB2_SUCCESS) + return rv; + + /* Convert vboot region into an EC region */ + region = vboot_to_ec_region(select); + + /* Get information about the flash region */ + if (google_chromeec_flash_region_info(region, ®ion_offset, + ®ion_size)) + return VB2_ERROR_UNKNOWN; + + /* Locate the CBFS file */ + filename = EC_IMAGE_FILENAME(select); + if (cbfs_boot_locate(&fh, filename, NULL)) + return VB2_ERROR_UNKNOWN; + + /* Get the file size and the region struct */ + image_size = region_device_sz(&fh.data); + cbfs_file_data(&image_region, &fh); + + /* Bail if the image is too large */ + if (image_size > region_size) + return VB2_ERROR_INVALID_PARAMETER; + + /* Erase the region */ + if (google_chromeec_flash_erase(region_offset, region_size)) + return VB2_ERROR_UNKNOWN; + + /* Write the image into the region */ + if (ec_flash_write(&image_region, region_offset, image_size)) + return VB2_ERROR_UNKNOWN; + + /* Verify the image */ + if (google_chromeec_efs_verify(region)) + return VB2_ERROR_UNKNOWN; + + return VB2_SUCCESS; +} + +static vb2_error_t ec_get_expected_hash(enum vb2_firmware_selection select, + const uint8_t **hash, + int *hash_size) +{ + size_t size; + const char *filename = EC_HASH_FILENAME(select); + const uint8_t *file = cbfs_boot_map_with_leak(filename, CBFS_TYPE_RAW, &size); + + if (file == NULL) + return VB2_ERROR_UNKNOWN; + + *hash = file; + *hash_size = (int)size; + + return VB2_SUCCESS; +} + +/*********************************************************************** + * Vboot Callbacks + ***********************************************************************/ + +/* + * Unsupported. + * + * coreboot does not support the graphics initialization needed to + * display the vboot "wait" screens, etc., because the use case for + * supporting software sync early in the boot flow is to be able to + * quickly update the EC and/or sysjump to RW earlier so that USB-PD + * power (> 15 W) can be negotiated for earlier. + */ +vb2_error_t VbExDisplayScreen(uint32_t screen_type, uint32_t locale, + const VbScreenData *data) +{ + return VB2_ERROR_UNKNOWN; +} + +/* + * Write opaque data into NV storage region. + */ +vb2_error_t VbExNvStorageWrite(const uint8_t *buf) +{ + save_vbnv(buf); + return VB2_SUCCESS; +} + +/* + * Report whether the EC is in RW or not. + */ +vb2_error_t vb2ex_ec_running_rw(int *in_rw) +{ + *in_rw = !google_ec_running_ro(); + return VB2_SUCCESS; +} + +/* + * Callback for when Vboot is finished. + */ +vb2_error_t vb2ex_ec_vboot_done(struct vb2_context *ctx) +{ + int limit_power = 0; + bool message_printed = false; + struct stopwatch sw; + vb2_error_t rv = VB2_SUCCESS; + int in_recovery = !!(ctx->flags & VB2_CONTEXT_RECOVERY_MODE); + + /* + * Do not wait for the limit power flag to be cleared in + * recovery mode since we didn't just sysjump. + */ + if (in_recovery) + return VB2_SUCCESS; + + stopwatch_init_msecs_expire(&sw, LIMIT_POWER_WAIT_TIMEOUT_MS); + + /* Ensure we have enough power to continue booting */ + while (1) { + if (google_chromeec_read_limit_power_request(&limit_power)) { + printk(BIOS_ERR, "Failed to check EC limit power" + "flag.\n"); + rv = VB2_ERROR_UNKNOWN; + break; + } + + if (!limit_power || stopwatch_expired(&sw)) + break; + + if (!message_printed) { + printk(BIOS_SPEW, + "Waiting for EC to clear limit power flag.\n"); + message_printed = true; + } + + mdelay(LIMIT_POWER_POLL_SLEEP_MS); + } + + if (limit_power) { + printk(BIOS_INFO, + "EC requests limited power usage. Request shutdown.\n"); + rv = VBERROR_SHUTDOWN_REQUESTED; + } else { + printk(BIOS_INFO, "Waited %luus to clear limit power flag.\n", + stopwatch_duration_usecs(&sw)); + } + + return rv; +} + +/* + * Support battery cutoff if required. + */ +vb2_error_t vb2ex_ec_battery_cutoff(void) +{ + if (google_chromeec_battery_cutoff(EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN)) + return VB2_ERROR_UNKNOWN; + + return VB2_SUCCESS; +} + +/* + * Vboot callback for calculating an EC image's hash. + */ +vb2_error_t vb2ex_ec_hash_image(enum vb2_firmware_selection select, + const uint8_t **hash, int *hash_size) +{ + return ec_hash_image(select, hash, hash_size); +} + +/* + * Vboot callback for EC flash protection. + */ +vb2_error_t vb2ex_ec_protect(enum vb2_firmware_selection select) +{ + return ec_protect_flash(select, 1); +} + +/* + * Get hash for image. + */ +vb2_error_t vb2ex_ec_get_expected_image_hash(enum vb2_firmware_selection select, + const uint8_t **hash, + int *hash_size) +{ + return ec_get_expected_hash(select, hash, hash_size); +} + +/* + * Disable further sysjumps (i.e., stay in RW until next reboot) + */ +vb2_error_t vb2ex_ec_disable_jump(void) +{ + if (google_chromeec_reboot(0, EC_REBOOT_DISABLE_JUMP, 0)) + return VB2_ERROR_UNKNOWN; + + return VB2_SUCCESS; +} + +/* + * Update EC image. + */ +vb2_error_t vb2ex_ec_update_image(enum vb2_firmware_selection select) +{ + return ec_update_image(select); +} + +/* + * Vboot callback for commanding EC to sysjump to RW. + */ +vb2_error_t vb2ex_ec_jump_to_rw(void) +{ + struct stopwatch sw; + + if (google_chromeec_reboot(0, EC_REBOOT_JUMP_RW, 0)) + return VB2_ERROR_UNKNOWN; + + /* Give the EC 3 seconds to sysjump */ + stopwatch_init_msecs_expire(&sw, CROS_EC_SYSJUMP_TIMEOUT_MS); + + /* Default delay to wait after EC reboot */ + mdelay(50); + while (google_chromeec_hello()) { + if (stopwatch_expired(&sw)) { + printk(BIOS_ERR, "EC did not return from reboot after %luus\n", + stopwatch_duration_usecs(&sw)); + return VB2_ERROR_UNKNOWN; + } + + mdelay(5); + } + + printk(BIOS_INFO, "\nEC returned from reboot after %luus\n", + stopwatch_duration_usecs(&sw)); + + return VB2_SUCCESS; +} diff --git a/src/security/vboot/vboot_common.h b/src/security/vboot/vboot_common.h index a20ab62..d296574 100644 --- a/src/security/vboot/vboot_common.h +++ b/src/security/vboot/vboot_common.h @@ -80,4 +80,13 @@ static inline void vboot_run_logic(void) {} #endif
+void vboot_save_nvdata_only(struct vb2_context *ctx); +void vboot_save_data(struct vb2_context *ctx); + +/* + * The API for performing EC software sync. Does not support + * "slow" updates or Auxiliary FW sync. + */ +void vboot_sync_ec(void); + #endif /* __VBOOT_VBOOT_COMMON_H__ */ diff --git a/src/security/vboot/vboot_logic.c b/src/security/vboot/vboot_logic.c index 6ee4d94..ccce148 100644 --- a/src/security/vboot/vboot_logic.c +++ b/src/security/vboot/vboot_logic.c @@ -251,21 +251,27 @@ return VB2_SUCCESS; }
-/** - * Save non-volatile and/or secure data if needed. - */ -static void save_if_needed(struct vb2_context *ctx) +void vboot_save_nvdata_only(struct vb2_context *ctx) { + assert(!(ctx->flags & (VB2_CONTEXT_SECDATA_FIRMWARE_CHANGED | + VB2_CONTEXT_SECDATA_KERNEL_CHANGED))); + if (ctx->flags & VB2_CONTEXT_NVDATA_CHANGED) { printk(BIOS_INFO, "Saving nvdata\n"); save_vbnv(ctx->nvdata); ctx->flags &= ~VB2_CONTEXT_NVDATA_CHANGED; } +} + +void vboot_save_data(struct vb2_context *ctx) +{ if (ctx->flags & VB2_CONTEXT_SECDATA_CHANGED) { printk(BIOS_INFO, "Saving secdata\n"); antirollback_write_space_firmware(ctx); ctx->flags &= ~VB2_CONTEXT_SECDATA_CHANGED; } + + vboot_save_nvdata_only(ctx); }
static uint32_t extend_pcrs(struct vb2_context *ctx) @@ -368,13 +374,13 @@ */ if (rv == VB2_ERROR_API_PHASE1_RECOVERY) { printk(BIOS_INFO, "Recovery requested (%x)\n", rv); - save_if_needed(ctx); + vboot_save_data(ctx); extend_pcrs(ctx); /* ignore failures */ goto verstage_main_exit; }
printk(BIOS_INFO, "Reboot requested (%x)\n", rv); - save_if_needed(ctx); + vboot_save_data(ctx); vboot_reboot(); }
@@ -383,7 +389,7 @@ rv = vb2api_fw_phase2(ctx); if (rv) { printk(BIOS_INFO, "Reboot requested (%x)\n", rv); - save_if_needed(ctx); + vboot_save_data(ctx); vboot_reboot(); }
@@ -394,7 +400,7 @@ timestamp_add_now(TS_END_VERIFY_SLOT); if (rv) { printk(BIOS_INFO, "Reboot requested (%x)\n", rv); - save_if_needed(ctx); + vboot_save_data(ctx); vboot_reboot(); }
@@ -405,7 +411,7 @@ "Failed to read FMAP to locate firmware");
rv = hash_body(ctx, &fw_main); - save_if_needed(ctx); + vboot_save_data(ctx); if (rv) { printk(BIOS_INFO, "Reboot requested (%x)\n", rv); vboot_reboot(); @@ -419,7 +425,7 @@ printk(BIOS_WARNING, "Failed to extend TPM PCRs (%#x)\n", rv); vb2api_fail(ctx, VB2_RECOVERY_RO_TPM_U_ERROR, rv); - save_if_needed(ctx); + vboot_save_data(ctx); vboot_reboot(); } timestamp_add_now(TS_END_TPMPCR); @@ -432,7 +438,7 @@ if (rv) { printk(BIOS_INFO, "Failed to lock TPM (%x)\n", rv); vb2api_fail(ctx, VB2_RECOVERY_RO_TPM_L_ERROR, 0); - save_if_needed(ctx); + vboot_save_data(ctx); vboot_reboot(); } timestamp_add_now(TS_END_TPMLOCK); @@ -445,7 +451,7 @@ rv); vb2api_fail(ctx, VB2_RECOVERY_RO_TPM_REC_HASH_L_ERROR, 0); - save_if_needed(ctx); + vboot_save_data(ctx); vboot_reboot(); } }