Joel Kitching has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/31329
Change subject: vboot: copy data structures to cbmem for downstream use ......................................................................
vboot: copy data structures to cbmem for downstream use
For platforms that do not employ VBOOT_STARTS_IN_ROMSTAGE, vboot verification occurs before cbmem is brought online. In order to make vboot data structures available downstream, copy vb2_working_data from SRAM into cbmem when cbmem comes online.
BUG=b:124141368, b:124192753 TEST=Build locally TEST=util/lint/checkpatch.pl --ignore GERRIT_CHANGE_ID -g origin/master..HEAD TEST=util/abuild/abuild -B -e -y -c 50 -p none -x BRANCH=none
Change-Id: I62c11268a83927bc00ae9bd93b1b31363b38e8cf Signed-off-by: Joel Kitching kitching@google.com --- M src/security/vboot/common.c 1 file changed, 32 insertions(+), 51 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/29/31329/1
diff --git a/src/security/vboot/common.c b/src/security/vboot/common.c index 747644a..8b73697 100644 --- a/src/security/vboot/common.c +++ b/src/security/vboot/common.c @@ -40,47 +40,32 @@ uint32_t buffer_size; };
-static const size_t vb_work_buf_size = 16 * KiB; +static struct vb2_working_data *vb2_wd = NULL;
static struct vb2_working_data * const vboot_get_working_data(void) { - if (IS_ENABLED(CONFIG_VBOOT_STARTS_IN_ROMSTAGE)) - /* cbmem_add() does a cbmem_find() first. */ - return cbmem_add(CBMEM_ID_VBOOT_WORKBUF, vb_work_buf_size); - else - return (struct vb2_working_data *)_vboot2_work; + if (vb2_wd == NULL) { +#if ENV_POSTCAR || ENV_RAMSTAGE + /* cbmem_find is linked from romstage onward */ + vb2_wd = cbmem_find(CBMEM_ID_VBOOT_WORKBUF); +#else + /* _vboot2_work is accessible until end of romstage */ + vb2_wd = (struct vb2_working_data *)_vboot2_work; +#endif + } + assert(vb2_wd != NULL); + return vb2_wd; }
static size_t vb2_working_data_size(void) { - if (IS_ENABLED(CONFIG_VBOOT_STARTS_IN_ROMSTAGE)) - return vb_work_buf_size; - else - return _vboot2_work_size; + /* _vboot2_work_size is accessible until end of romstage */ + return _vboot2_work_size; }
static struct selected_region *vb2_selected_region(void) { - struct selected_region *sel_reg = NULL; - - /* Ramstage and postcar always uses cbmem as a source of truth. */ - if (ENV_RAMSTAGE || ENV_POSTCAR) - sel_reg = cbmem_find(CBMEM_ID_VBOOT_SEL_REG); - else if (ENV_ROMSTAGE) { - /* Try cbmem first. Fall back on working data if not found. */ - sel_reg = cbmem_find(CBMEM_ID_VBOOT_SEL_REG); - - if (sel_reg == NULL) { - struct vb2_working_data *wd = vboot_get_working_data(); - sel_reg = &wd->selected_region; - } - } else { - /* Stages such as bootblock and verstage use working data. */ - struct vb2_working_data *wd = vboot_get_working_data(); - sel_reg = &wd->selected_region; - } - - return sel_reg; + return &vboot_get_working_data()->selected_region; }
void vb2_init_work_context(struct vb2_context *ctx) @@ -104,7 +89,6 @@ memset(ctx, 0, sizeof(*ctx)); ctx->workbuf = (void *)vb2_get_shared_data(); ctx->workbuf_size = wd->buffer_size; - }
struct vb2_shared_data *vb2_get_shared_data(void) @@ -148,33 +132,30 @@ return reg->size > 0; }
-void vb2_store_selected_region(void) +void vb2_store_working_data(void) { - const struct vb2_working_data *wd; - struct selected_region *sel_reg; + struct vb2_working_data *wd; + struct vb2_working_data *wd_cbmem;
- /* Always use the working data in this path since it's the object - * which has the result.. */ + wd_cbmem = cbmem_add(CBMEM_ID_VBOOT_WORKBUF, vb2_working_data_size()); + assert(wd_cbmem != NULL); + +#if !IS_ENABLED(CONFIG_VBOOT_STARTS_IN_ROMSTAGE) wd = vboot_get_working_data(); + /* No data to copy yet on platforms with VBOOT_STARTS_IN_ROMSTAGE. */ + memcpy(wd_cbmem, wd, vb2_working_data_size()); +#endif
- sel_reg = cbmem_add(CBMEM_ID_VBOOT_SEL_REG, sizeof(*sel_reg)); - - assert(sel_reg != NULL); - - sel_reg->offset = wd->selected_region.offset; - sel_reg->size = wd->selected_region.size; + vb2_wd = wd_cbmem; }
/* - * For platforms that employ VBOOT_STARTS_IN_ROMSTAGE, the vboot - * verification doesn't happen until after cbmem is brought online. - * Therefore, the selected region contents would not be initialized - * so don't automatically add results when cbmem comes online. + * For platforms that do not employ VBOOT_STARTS_IN_ROMSTAGE, vboot verification + * occurs before cbmem is brought online. In order to make vboot data + * structures available downstream, copy vb2_working_data from SRAM into cbmem. */ -#if !IS_ENABLED(CONFIG_VBOOT_STARTS_IN_ROMSTAGE) -static void vb2_store_selected_region_cbmem(int unused) +static void vb2_store_cbmem(int unused) { - vb2_store_selected_region(); + vb2_store_working_data(); } -ROMSTAGE_CBMEM_INIT_HOOK(vb2_store_selected_region_cbmem) -#endif +ROMSTAGE_CBMEM_INIT_HOOK(vb2_store_cbmem)