security/vboot: Remove selected_region from struct vboot_working_data

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.

In addition, returning false from vboot_is_slot_selected() implies the
recovery path was requested, i.e., vb2_shared_data.recovery_reason was
set. Therefore, we simply remove the vboot_is_slot_selected() check from
vboot_check_recovery_request().

BRANCH=none
BUG=chromium:1021452
TEST=emerge-kukui coreboot

Change-Id: I27cb1a2175beb189053fc3e44b17b60aba474bb0
Signed-off-by: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/36845
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Yu-Ping Wu
2019-11-14 15:42:25 +08:00
committed by Patrick Georgi
parent ea544574d0
commit aeb652a4a0
5 changed files with 39 additions and 77 deletions

View File

@ -35,11 +35,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, ...)
@ -70,7 +65,7 @@ vb2_error_t vb2ex_read_resource(struct vb2_context *ctx,
name = "GBB";
break;
case VB2_RES_FW_VBLOCK:
if (is_slot_a(ctx))
if (vboot_is_firmware_slot_a(ctx))
name = "VBLOCK_A";
else
name = "VBLOCK_B";
@ -256,19 +251,6 @@ static vb2_error_t hash_body(struct vb2_context *ctx,
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 fmap_locate_area_as_rdev(name, fw_main);
}
/**
* Save non-volatile and/or secure data if needed.
*/
@ -417,7 +399,7 @@ void verstage_main(void)
}
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");
@ -468,8 +450,8 @@ void verstage_main(void)
}
}
printk(BIOS_INFO, "Slot %c is selected\n", is_slot_a(ctx) ? 'A' : 'B');
vboot_set_selected_region(region_device_region(&fw_main));
printk(BIOS_INFO, "Slot %c is selected\n",
vboot_is_firmware_slot_a(ctx) ? 'A' : 'B');
verstage_main_exit:
/* If CBMEM is not up yet, let the ROMSTAGE_CBMEM_INIT_HOOK take care