vboot: rename symbols for better consistency
Symbols prefixed with vb2_ should be reserved for internal vboot library use. Anything outside of that may choose some other prefix. Here, we choose vboot_ instead. Also, add some documentation to security/vboot/misc.h, which provides headers for a number of different C files. BUG=b:124141368 TEST=Build and deploy to eve TEST=util/lint/checkpatch.pl -g origin/master..HEAD TEST=util/abuild/abuild -B -e -y -c 50 -p none -x TEST=make clean && make test-abuild BRANCH=none Change-Id: I5d9154fd2d5df25ee254bd5ce4a173afaa6588be Signed-off-by: Joel Kitching <kitching@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/31886 Reviewed-by: Julius Werner <jwerner@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
725369fd0c
commit
af8471c2b6
|
@ -23,23 +23,23 @@
|
||||||
#include <security/vboot/vbnv.h>
|
#include <security/vboot/vbnv.h>
|
||||||
#include <security/vboot/vboot_common.h>
|
#include <security/vboot/vboot_common.h>
|
||||||
|
|
||||||
static int vb2_get_recovery_reason_shared_data(void)
|
static int vboot_get_recovery_reason_shared_data(void)
|
||||||
{
|
{
|
||||||
/* Shared data does not exist for Ramstage and Post-CAR stage. */
|
/* Shared data does not exist for Ramstage and Post-CAR stage. */
|
||||||
if (ENV_RAMSTAGE || ENV_POSTCAR)
|
if (ENV_RAMSTAGE || ENV_POSTCAR)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
struct vb2_shared_data *sd = vb2_get_shared_data();
|
struct vb2_shared_data *sd = vboot_get_shared_data();
|
||||||
assert(sd);
|
assert(sd);
|
||||||
return sd->recovery_reason;
|
return sd->recovery_reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vb2_save_recovery_reason_vbnv(void)
|
void vboot_save_recovery_reason_vbnv(void)
|
||||||
{
|
{
|
||||||
if (!CONFIG(VBOOT_SAVE_RECOVERY_REASON_ON_REBOOT))
|
if (!CONFIG(VBOOT_SAVE_RECOVERY_REASON_ON_REBOOT))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int reason = vb2_get_recovery_reason_shared_data();
|
int reason = vboot_get_recovery_reason_shared_data();
|
||||||
if (!reason)
|
if (!reason)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -128,9 +128,9 @@ int vboot_check_recovery_request(void)
|
||||||
* verification is already complete and no slot was selected
|
* verification is already complete and no slot was selected
|
||||||
* i.e. recovery path was requested.
|
* i.e. recovery path was requested.
|
||||||
*/
|
*/
|
||||||
if (vboot_possibly_executed() && vb2_logic_executed() &&
|
if (vboot_possibly_executed() && vboot_logic_executed() &&
|
||||||
!vb2_is_slot_selected())
|
!vboot_is_slot_selected())
|
||||||
return vb2_get_recovery_reason_shared_data();
|
return vboot_get_recovery_reason_shared_data();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ struct selected_region {
|
||||||
* by the vboot2 core. Keep the struct CPU architecture agnostic as it crosses
|
* by the vboot2 core. Keep the struct CPU architecture agnostic as it crosses
|
||||||
* stage boundaries.
|
* stage boundaries.
|
||||||
*/
|
*/
|
||||||
struct vb2_working_data {
|
struct vboot_working_data {
|
||||||
struct selected_region selected_region;
|
struct selected_region selected_region;
|
||||||
/* offset of the buffer from the start of this struct */
|
/* offset of the buffer from the start of this struct */
|
||||||
uint32_t buffer_offset;
|
uint32_t buffer_offset;
|
||||||
|
@ -44,7 +44,7 @@ struct vb2_working_data {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* TODO(kitching): Use VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE instead. */
|
/* TODO(kitching): Use VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE instead. */
|
||||||
static size_t vb2_working_data_size(void)
|
static size_t vboot_working_data_size(void)
|
||||||
{
|
{
|
||||||
if (CONFIG(VBOOT_STARTS_IN_ROMSTAGE))
|
if (CONFIG(VBOOT_STARTS_IN_ROMSTAGE))
|
||||||
return 12 * KiB;
|
return 12 * KiB;
|
||||||
|
@ -56,64 +56,64 @@ static size_t vb2_working_data_size(void)
|
||||||
die("impossible!");
|
die("impossible!");
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct vb2_working_data * const vb2_get_working_data(void)
|
static struct vboot_working_data * const vboot_get_working_data(void)
|
||||||
{
|
{
|
||||||
struct vb2_working_data *wd = NULL;
|
struct vboot_working_data *wd = NULL;
|
||||||
|
|
||||||
if (cbmem_possibly_online())
|
if (cbmem_possibly_online())
|
||||||
wd = cbmem_find(CBMEM_ID_VBOOT_WORKBUF);
|
wd = cbmem_find(CBMEM_ID_VBOOT_WORKBUF);
|
||||||
|
|
||||||
if (wd == NULL && CONFIG(VBOOT_STARTS_IN_BOOTBLOCK) &&
|
if (wd == NULL && CONFIG(VBOOT_STARTS_IN_BOOTBLOCK) &&
|
||||||
preram_symbols_available())
|
preram_symbols_available())
|
||||||
wd = (struct vb2_working_data *)_vboot2_work;
|
wd = (struct vboot_working_data *)_vboot2_work;
|
||||||
|
|
||||||
assert(wd != NULL);
|
assert(wd != NULL);
|
||||||
|
|
||||||
return wd;
|
return wd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vb2_init_work_context(struct vb2_context *ctx)
|
void vboot_init_work_context(struct vb2_context *ctx)
|
||||||
{
|
{
|
||||||
struct vb2_working_data *wd;
|
struct vboot_working_data *wd;
|
||||||
|
|
||||||
/* First initialize the working data struct. */
|
/* First initialize the working data struct. */
|
||||||
wd = vb2_get_working_data();
|
wd = vboot_get_working_data();
|
||||||
memset(wd, 0, sizeof(struct vb2_working_data));
|
memset(wd, 0, sizeof(struct vboot_working_data));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vboot prefers 16-byte alignment. This takes away 16 bytes
|
* vboot prefers 16-byte alignment. This takes away 16 bytes
|
||||||
* from the VBOOT2_WORK region, but the vboot devs said that's okay.
|
* from the VBOOT2_WORK region, but the vboot devs said that's okay.
|
||||||
*/
|
*/
|
||||||
wd->buffer_offset = ALIGN_UP(sizeof(*wd), 16);
|
wd->buffer_offset = ALIGN_UP(sizeof(*wd), 16);
|
||||||
wd->buffer_size = vb2_working_data_size() - wd->buffer_offset;
|
wd->buffer_size = vboot_working_data_size() - wd->buffer_offset;
|
||||||
|
|
||||||
/* Initialize the vb2_context. */
|
/* Initialize the vb2_context. */
|
||||||
memset(ctx, 0, sizeof(*ctx));
|
memset(ctx, 0, sizeof(*ctx));
|
||||||
ctx->workbuf = (void *)vb2_get_shared_data();
|
ctx->workbuf = (void *)vboot_get_shared_data();
|
||||||
ctx->workbuf_size = wd->buffer_size;
|
ctx->workbuf_size = wd->buffer_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vb2_finalize_work_context(struct vb2_context *ctx)
|
void vboot_finalize_work_context(struct vb2_context *ctx)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Shrink buffer_size so that vb2_migrate_cbmem knows how much
|
* Shrink buffer_size so that vboot_migrate_cbmem knows how
|
||||||
* of vb2_working_data needs to be copied into CBMEM (if applicable),
|
* much of vboot_working_data needs to be copied into CBMEM
|
||||||
* and so that downstream users know how much of the workbuf is
|
* (if applicable), and so that downstream users know how much
|
||||||
* currently used.
|
* of the workbuf is currently used.
|
||||||
*/
|
*/
|
||||||
vb2_get_working_data()->buffer_size = ctx->workbuf_used;
|
vboot_get_working_data()->buffer_size = ctx->workbuf_used;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vb2_shared_data *vb2_get_shared_data(void)
|
struct vb2_shared_data *vboot_get_shared_data(void)
|
||||||
{
|
{
|
||||||
struct vb2_working_data *wd = vb2_get_working_data();
|
struct vboot_working_data *wd = vboot_get_working_data();
|
||||||
return (void *)((uintptr_t)wd + wd->buffer_offset);
|
return (void *)((uintptr_t)wd + wd->buffer_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int vb2_get_selected_region(struct region *region)
|
int vboot_get_selected_region(struct region *region)
|
||||||
{
|
{
|
||||||
const struct selected_region *reg =
|
const struct selected_region *reg =
|
||||||
&vb2_get_working_data()->selected_region;
|
&vboot_get_working_data()->selected_region;
|
||||||
|
|
||||||
if (reg == NULL)
|
if (reg == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -127,9 +127,10 @@ int vb2_get_selected_region(struct region *region)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vb2_set_selected_region(const struct region *region)
|
void vboot_set_selected_region(const struct region *region)
|
||||||
{
|
{
|
||||||
struct selected_region *reg = &vb2_get_working_data()->selected_region;
|
struct selected_region *reg =
|
||||||
|
&vboot_get_working_data()->selected_region;
|
||||||
|
|
||||||
assert(reg != NULL);
|
assert(reg != NULL);
|
||||||
|
|
||||||
|
@ -137,9 +138,10 @@ void vb2_set_selected_region(const struct region *region)
|
||||||
reg->size = region_sz(region);
|
reg->size = region_sz(region);
|
||||||
}
|
}
|
||||||
|
|
||||||
int vb2_is_slot_selected(void)
|
int vboot_is_slot_selected(void)
|
||||||
{
|
{
|
||||||
struct selected_region *reg = &vb2_get_working_data()->selected_region;
|
struct selected_region *reg =
|
||||||
|
&vboot_get_working_data()->selected_region;
|
||||||
|
|
||||||
assert(reg != NULL);
|
assert(reg != NULL);
|
||||||
|
|
||||||
|
@ -151,29 +153,29 @@ int vb2_is_slot_selected(void)
|
||||||
* For platforms that do not employ VBOOT_STARTS_IN_ROMSTAGE, vboot
|
* For platforms that do not employ VBOOT_STARTS_IN_ROMSTAGE, vboot
|
||||||
* verification occurs before CBMEM is brought online, using pre-RAM.
|
* verification occurs before CBMEM is brought online, using pre-RAM.
|
||||||
* In order to make vboot data structures available downstream, copy
|
* In order to make vboot data structures available downstream, copy
|
||||||
* vb2_working_data from SRAM/CAR into CBMEM on platforms where this
|
* vboot_working_data from SRAM/CAR into CBMEM on platforms where this
|
||||||
* memory later becomes unavailable.
|
* memory later becomes unavailable.
|
||||||
*/
|
*/
|
||||||
static void vb2_migrate_cbmem(int unused)
|
static void vboot_migrate_cbmem(int unused)
|
||||||
{
|
{
|
||||||
const struct vb2_working_data *wd_preram =
|
const struct vboot_working_data *wd_preram =
|
||||||
(struct vb2_working_data *)_vboot2_work;
|
(struct vboot_working_data *)_vboot2_work;
|
||||||
size_t cbmem_size = wd_preram->buffer_offset + wd_preram->buffer_size;
|
size_t cbmem_size = wd_preram->buffer_offset + wd_preram->buffer_size;
|
||||||
struct vb2_working_data *wd_cbmem =
|
struct vboot_working_data *wd_cbmem =
|
||||||
cbmem_add(CBMEM_ID_VBOOT_WORKBUF, cbmem_size);
|
cbmem_add(CBMEM_ID_VBOOT_WORKBUF, cbmem_size);
|
||||||
printk(BIOS_DEBUG,
|
printk(BIOS_DEBUG,
|
||||||
"VBOOT: copying vb2_working_data (%zu bytes) to CBMEM...\n",
|
"VBOOT: copying vboot_working_data (%zu bytes) to CBMEM...\n",
|
||||||
cbmem_size);
|
cbmem_size);
|
||||||
memcpy(wd_cbmem, wd_preram, cbmem_size);
|
memcpy(wd_cbmem, wd_preram, cbmem_size);
|
||||||
assert(wd_cbmem != NULL);
|
assert(wd_cbmem != NULL);
|
||||||
}
|
}
|
||||||
ROMSTAGE_CBMEM_INIT_HOOK(vb2_migrate_cbmem)
|
ROMSTAGE_CBMEM_INIT_HOOK(vboot_migrate_cbmem)
|
||||||
#elif CONFIG(VBOOT_STARTS_IN_ROMSTAGE)
|
#elif CONFIG(VBOOT_STARTS_IN_ROMSTAGE)
|
||||||
static void vb2_setup_cbmem(int unused)
|
static void vboot_setup_cbmem(int unused)
|
||||||
{
|
{
|
||||||
struct vb2_working_data *wd_cbmem =
|
struct vboot_working_data *wd_cbmem =
|
||||||
cbmem_add(CBMEM_ID_VBOOT_WORKBUF, vb2_working_data_size());
|
cbmem_add(CBMEM_ID_VBOOT_WORKBUF, vboot_working_data_size());
|
||||||
assert(wd_cbmem != NULL);
|
assert(wd_cbmem != NULL);
|
||||||
}
|
}
|
||||||
ROMSTAGE_CBMEM_INIT_HOOK(vb2_setup_cbmem)
|
ROMSTAGE_CBMEM_INIT_HOOK(vboot_setup_cbmem)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,18 +21,32 @@
|
||||||
struct vb2_context;
|
struct vb2_context;
|
||||||
struct vb2_shared_data;
|
struct vb2_shared_data;
|
||||||
|
|
||||||
void vboot_fill_handoff(void);
|
/*
|
||||||
|
* Source: security/vboot/common.c
|
||||||
void vb2_init_work_context(struct vb2_context *ctx);
|
*/
|
||||||
void vb2_finalize_work_context(struct vb2_context *ctx);
|
void vboot_init_work_context(struct vb2_context *ctx);
|
||||||
struct vb2_shared_data *vb2_get_shared_data(void);
|
void vboot_finalize_work_context(struct vb2_context *ctx);
|
||||||
|
struct vb2_shared_data *vboot_get_shared_data(void);
|
||||||
|
|
||||||
/* Returns 0 on success. < 0 on failure. */
|
/* Returns 0 on success. < 0 on failure. */
|
||||||
int vb2_get_selected_region(struct region *region);
|
int vboot_get_selected_region(struct region *region);
|
||||||
void vb2_set_selected_region(const struct region *region);
|
|
||||||
int vb2_is_slot_selected(void);
|
|
||||||
int vb2_logic_executed(void);
|
|
||||||
|
|
||||||
void vb2_save_recovery_reason_vbnv(void);
|
void vboot_set_selected_region(const struct region *region);
|
||||||
|
int vboot_is_slot_selected(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Source: security/vboot/vboot_handoff.c
|
||||||
|
*/
|
||||||
|
void vboot_fill_handoff(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Source: security/vboot/vboot_loader.c
|
||||||
|
*/
|
||||||
|
int vboot_logic_executed(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Source: security/vboot/bootmode.c
|
||||||
|
*/
|
||||||
|
void vboot_save_recovery_reason_vbnv(void);
|
||||||
|
|
||||||
#endif /* __VBOOT_MISC_H__ */
|
#endif /* __VBOOT_MISC_H__ */
|
||||||
|
|
|
@ -162,7 +162,7 @@ uint32_t vboot_measure_cbfs_hook(struct cbfsf *fh, const char *name)
|
||||||
struct region_device rdev;
|
struct region_device rdev;
|
||||||
char tcpa_metadata[TCPA_PCR_HASH_NAME];
|
char tcpa_metadata[TCPA_PCR_HASH_NAME];
|
||||||
|
|
||||||
if (!vb2_logic_executed())
|
if (!vboot_logic_executed())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
cbfsf_file_type(fh, &cbfs_type);
|
cbfsf_file_type(fh, &cbfs_type);
|
||||||
|
|
|
@ -141,7 +141,7 @@ void vboot_fill_handoff(void)
|
||||||
struct vboot_handoff *vh;
|
struct vboot_handoff *vh;
|
||||||
struct vb2_shared_data *sd;
|
struct vb2_shared_data *sd;
|
||||||
|
|
||||||
sd = vb2_get_shared_data();
|
sd = vboot_get_shared_data();
|
||||||
sd->workbuf_hash_offset = 0;
|
sd->workbuf_hash_offset = 0;
|
||||||
sd->workbuf_hash_size = 0;
|
sd->workbuf_hash_size = 0;
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ static int verstage_should_load(void)
|
||||||
|
|
||||||
static int vboot_executed CAR_GLOBAL;
|
static int vboot_executed CAR_GLOBAL;
|
||||||
|
|
||||||
int vb2_logic_executed(void)
|
int vboot_logic_executed(void)
|
||||||
{
|
{
|
||||||
/* If we are in a stage that would load the verstage or execute the
|
/* If we are in a stage that would load the verstage or execute the
|
||||||
vboot logic directly, we store the answer in a global. */
|
vboot logic directly, we store the answer in a global. */
|
||||||
|
@ -91,7 +91,7 @@ static void vboot_prepare(void)
|
||||||
/* Note: this path is not used for VBOOT_RETURN_FROM_VERSTAGE */
|
/* Note: this path is not used for VBOOT_RETURN_FROM_VERSTAGE */
|
||||||
verstage_main();
|
verstage_main();
|
||||||
car_set_var(vboot_executed, 1);
|
car_set_var(vboot_executed, 1);
|
||||||
vb2_save_recovery_reason_vbnv();
|
vboot_save_recovery_reason_vbnv();
|
||||||
} else if (verstage_should_load()) {
|
} else if (verstage_should_load()) {
|
||||||
struct cbfsf file;
|
struct cbfsf file;
|
||||||
struct prog verstage =
|
struct prog verstage =
|
||||||
|
@ -138,10 +138,10 @@ static int vboot_locate(struct cbfs_props *props)
|
||||||
struct region selected_region;
|
struct region selected_region;
|
||||||
|
|
||||||
/* Don't honor vboot results until the vboot logic has run. */
|
/* Don't honor vboot results until the vboot logic has run. */
|
||||||
if (!vb2_logic_executed())
|
if (!vboot_logic_executed())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (vb2_get_selected_region(&selected_region))
|
if (vboot_get_selected_region(&selected_region))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
props->offset = region_offset(&selected_region);
|
props->offset = region_offset(&selected_region);
|
||||||
|
|
|
@ -297,7 +297,7 @@ void verstage_main(void)
|
||||||
timestamp_add_now(TS_START_VBOOT);
|
timestamp_add_now(TS_START_VBOOT);
|
||||||
|
|
||||||
/* Set up context and work buffer */
|
/* Set up context and work buffer */
|
||||||
vb2_init_work_context(&ctx);
|
vboot_init_work_context(&ctx);
|
||||||
|
|
||||||
/* Initialize and read nvdata from non-volatile storage. */
|
/* Initialize and read nvdata from non-volatile storage. */
|
||||||
vbnv_init(ctx.nvdata);
|
vbnv_init(ctx.nvdata);
|
||||||
|
@ -437,7 +437,7 @@ void verstage_main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
printk(BIOS_INFO, "Slot %c is selected\n", is_slot_a(&ctx) ? 'A' : 'B');
|
printk(BIOS_INFO, "Slot %c is selected\n", is_slot_a(&ctx) ? 'A' : 'B');
|
||||||
vb2_set_selected_region(region_device_region(&fw_main));
|
vboot_set_selected_region(region_device_region(&fw_main));
|
||||||
vb2_finalize_work_context(&ctx);
|
vboot_finalize_work_context(&ctx);
|
||||||
timestamp_add_now(TS_END_VBOOT);
|
timestamp_add_now(TS_END_VBOOT);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue