Yu-Ping Wu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/36845 )
Change subject: security/vboot: Remove vboot_set_selected_region() ......................................................................
security/vboot: Remove vboot_set_selected_region()
Since we already have pre-RAM cache for FMAP (CB:36657), calling load_firmware() multiple times is no longer a problem. This patch replaces vboot_get_selected_region() usage with vboot_locate_firmware(), which locates the firmware by reading from the CBMEM cache.
BRANCH=none BUG=chromium:1021452 TEST=emerge-kukui coreboot
Change-Id: I27cb1a2175beb189053fc3e44b17b60aba474bb0 Signed-off-by: Yu-Ping Wu yupingso@chromium.org --- M src/security/vboot/common.c M src/security/vboot/misc.h M src/security/vboot/vboot_loader.c M src/security/vboot/vboot_logic.c 4 files changed, 32 insertions(+), 45 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/45/36845/1
diff --git a/src/security/vboot/common.c b/src/security/vboot/common.c index ea22bdf..68960c9 100644 --- a/src/security/vboot/common.c +++ b/src/security/vboot/common.c @@ -83,23 +83,6 @@ return *vboot_ctx_ptr; }
-int vboot_get_selected_region(struct region *region) -{ - const struct selected_region *reg = - &vboot_get_working_data()->selected_region; - - if (reg == NULL) - return -1; - - if (reg->offset == 0 && reg->size == 0) - return -1; - - region->offset = reg->offset; - region->size = reg->size; - - return 0; -} - void vboot_set_selected_region(const struct region *region) { struct selected_region *reg = @@ -121,6 +104,24 @@ return reg->size > 0; }
+int vboot_is_slot_a(const struct vb2_context *ctx) +{ + return !(ctx->flags & VB2_CONTEXT_FW_SLOT_B); +} + +int vboot_locate_firmware(const struct vb2_context *ctx, + struct region_device *fw) +{ + const char *name; + + if (vboot_is_slot_a(ctx)) + name = "FW_MAIN_A"; + else + name = "FW_MAIN_B"; + + return vboot_named_region_device(name, fw); +} + #if CONFIG(VBOOT_STARTS_IN_BOOTBLOCK) /* * For platforms that do not employ VBOOT_STARTS_IN_ROMSTAGE, vboot diff --git a/src/security/vboot/misc.h b/src/security/vboot/misc.h index 6141674..6d40f16 100644 --- a/src/security/vboot/misc.h +++ b/src/security/vboot/misc.h @@ -47,12 +47,13 @@ struct vboot_working_data *vboot_get_working_data(void); struct vb2_context *vboot_get_context(void);
-/* Returns 0 on success. < 0 on failure. */ -int vboot_get_selected_region(struct region *region); - void vboot_set_selected_region(const struct region *region); int vboot_is_slot_selected(void);
+int vboot_is_slot_a(const struct vb2_context *ctx); +int vboot_locate_firmware(const struct vb2_context *ctx, + struct region_device *fw); + /* * Source: security/vboot/vboot_handoff.c */ diff --git a/src/security/vboot/vboot_loader.c b/src/security/vboot/vboot_loader.c index 3aac48d..016e9a5 100644 --- a/src/security/vboot/vboot_loader.c +++ b/src/security/vboot/vboot_loader.c @@ -73,17 +73,20 @@
static int vboot_locate(struct cbfs_props *props) { - struct region selected_region; + const struct vb2_context *ctx = vboot_get_context(); + struct region_device fw_main; + const struct region *selected_region;
/* Don't honor vboot results until the vboot logic has run. */ if (!vboot_logic_executed()) return -1;
- if (vboot_get_selected_region(&selected_region)) + if (!vboot_locate_firmware(ctx, &fw_main)) return -1;
- props->offset = region_offset(&selected_region); - props->size = region_sz(&selected_region); + selected_region = region_device_region(&fw_main); + props->offset = region_offset(selected_region); + props->size = region_sz(selected_region);
return 0; } diff --git a/src/security/vboot/vboot_logic.c b/src/security/vboot/vboot_logic.c index c4389a9..42771e4 100644 --- a/src/security/vboot/vboot_logic.c +++ b/src/security/vboot/vboot_logic.c @@ -34,11 +34,6 @@
#define TODO_BLOCK_SIZE 1024
-static int is_slot_a(struct vb2_context *ctx) -{ - return !(ctx->flags & VB2_CONTEXT_FW_SLOT_B); -} - /* exports */
void vb2ex_printf(const char *func, const char *fmt, ...) @@ -69,7 +64,7 @@ name = "GBB"; break; case VB2_RES_FW_VBLOCK: - if (is_slot_a(ctx)) + if (vboot_is_slot_a(ctx)) name = "VBLOCK_A"; else name = "VBLOCK_B"; @@ -255,19 +250,6 @@ return VB2_SUCCESS; }
-static int locate_firmware(struct vb2_context *ctx, - struct region_device *fw_main) -{ - const char *name; - - if (is_slot_a(ctx)) - name = "FW_MAIN_A"; - else - name = "FW_MAIN_B"; - - return vboot_named_region_device(name, fw_main); -} - /** * Save non-volatile and/or secure data if needed. */ @@ -416,7 +398,7 @@ }
printk(BIOS_INFO, "Phase 4\n"); - rv = locate_firmware(ctx, &fw_main); + rv = vboot_locate_firmware(ctx, &fw_main); if (rv) die_with_post_code(POST_INVALID_ROM, "Failed to read FMAP to locate firmware"); @@ -467,7 +449,7 @@ } }
- printk(BIOS_INFO, "Slot %c is selected\n", is_slot_a(ctx) ? 'A' : 'B'); + printk(BIOS_INFO, "Slot %c is selected\n", vboot_is_slot_a(ctx) ? 'A' : 'B'); vboot_set_selected_region(region_device_region(&fw_main));
verstage_main_exit: