vboot2: Make struct vb2_working_data cpu architecture agnostic

this allows vb2_working_data to be accessed from stages running on different cpu
architectures.

BUG=none
TEST=Built firmware for Blaze with USE=+/-vboot2. Ran faft on Blaze.
BRANCH=none
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>

Original-Change-Id: Ife2844637af8bf9e0d032a50fb516d98b8f80497
Original-Reviewed-on: https://chromium-review.googlesource.com/217835
Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Original-Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
Original-Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
(cherry picked from commit 2b36749bc5a761003f00b7a0d17edb1629245b88)

Change-Id: Idc10f23ed2927717f5308f0112aa8113a683010e
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/8882
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
Daisuke Nojiri 2014-09-12 09:59:46 -07:00 committed by Aaron Durbin
parent efddcfbb52
commit 1bbac3fd24
5 changed files with 49 additions and 29 deletions

View File

@ -223,7 +223,7 @@ void *vboot_load_stage(int stage_index,
struct vboot_components *fw_info) struct vboot_components *fw_info)
{ {
struct cbfs_stage *stage; struct cbfs_stage *stage;
uint32_t fc_addr; uintptr_t fc_addr;
uint32_t fc_size; uint32_t fc_size;
if (stage_index >= fw_info->num_components) { if (stage_index >= fw_info->num_components) {
@ -267,18 +267,9 @@ struct vb2_working_data * const vboot_get_working_data(void)
return (struct vb2_working_data *)CONFIG_VBOOT_WORK_BUFFER_ADDRESS; return (struct vb2_working_data *)CONFIG_VBOOT_WORK_BUFFER_ADDRESS;
} }
int vboot_is_slot_selected(struct vb2_working_data *wd)
{
return wd->selected_region.size > 0;
}
int vboot_is_readonly_path(struct vb2_working_data *wd)
{
return wd->selected_region.size == 0;
}
void vboot_reboot(void) void vboot_reboot(void)
{ {
hard_reset(); hard_reset();
} }
#endif #endif

View File

@ -130,20 +130,42 @@ void vboot_reboot(void);
/* /*
* this is placed at the start of the vboot work buffer. selected_region is used * this is placed at the start of the vboot work buffer. selected_region is used
* for the verstage to return the location of the selected slot. buffer is used * for the verstage to return the location of the selected slot. buffer is used
* by the vboot2 core. * by the vboot2 core. Keep the struct cpu architecture agnostic as it crosses
* * stage boundaries.
* TODO: Make the sizes of the struct and its members independent of cpu
* architectures as it crosses stage boundaries.
*/ */
struct vb2_working_data { struct vb2_working_data {
struct vboot_region selected_region; uint32_t selected_region_offset;
size_t buffer_size; uint32_t selected_region_size;
uint8_t *buffer; uint64_t buffer_size;
uint64_t buffer;
}; };
struct vb2_working_data * const vboot_get_working_data(void); struct vb2_working_data * const vboot_get_working_data(void);
int vboot_is_slot_selected(struct vb2_working_data *wd);
int vboot_is_readonly_path(struct vb2_working_data *wd); static inline void vb2_get_selected_region(struct vb2_working_data *wd,
struct vboot_region *region)
{
region->offset_addr = wd->selected_region_offset;
region->size = wd->selected_region_size;
}
static inline void vb2_set_selected_region(struct vb2_working_data *wd,
struct vboot_region *region)
{
wd->selected_region_offset = region->offset_addr;
wd->selected_region_size = region->size;
}
static inline int vboot_is_slot_selected(struct vb2_working_data *wd)
{
return wd->selected_region_size > 0;
}
static inline int vboot_is_readonly_path(struct vb2_working_data *wd)
{
return wd->selected_region_size == 0;
}
#endif /* CONFIG_VBOOT2_VERIFY_FIRMWARE */ #endif /* CONFIG_VBOOT2_VERIFY_FIRMWARE */
#endif #endif

View File

@ -143,9 +143,10 @@ void *vboot_load_ramstage(void)
{ {
struct vboot_handoff *vh; struct vboot_handoff *vh;
struct vb2_shared_data *sd; struct vb2_shared_data *sd;
struct vboot_region fw_main;
struct vb2_working_data *wd = vboot_get_working_data(); struct vb2_working_data *wd = vboot_get_working_data();
sd = (struct vb2_shared_data *)wd->buffer; sd = (struct vb2_shared_data *)(uintptr_t)wd->buffer;
sd->workbuf_hash_offset = 0; sd->workbuf_hash_offset = 0;
sd->workbuf_hash_size = 0; sd->workbuf_hash_size = 0;
@ -167,5 +168,7 @@ void *vboot_load_ramstage(void)
printk(BIOS_INFO, printk(BIOS_INFO,
"loading ramstage from Slot %c\n", sd->fw_slot ? 'B' : 'A'); "loading ramstage from Slot %c\n", sd->fw_slot ? 'B' : 'A');
return load_ramstage(vh, &wd->selected_region); vb2_get_selected_region(wd, &fw_main);
return load_ramstage(vh, &fw_main);
} }

View File

@ -173,12 +173,13 @@ void verstage_main(void)
#endif /* CONFIG_RETURN_FROM_VERSTAGE */ #endif /* CONFIG_RETURN_FROM_VERSTAGE */
{ {
struct vb2_context ctx; struct vb2_context ctx;
struct vboot_region fw_main;
struct vb2_working_data *wd = vboot_get_working_data(); struct vb2_working_data *wd = vboot_get_working_data();
int rv; int rv;
/* Set up context and work buffer */ /* Set up context and work buffer */
memset(&ctx, 0, sizeof(ctx)); memset(&ctx, 0, sizeof(ctx));
ctx.workbuf = wd->buffer; ctx.workbuf = (uint8_t *)(uintptr_t)wd->buffer;
ctx.workbuf_size = wd->buffer_size; ctx.workbuf_size = wd->buffer_size;
/* Read nvdata from a non-volatile storage */ /* Read nvdata from a non-volatile storage */
@ -225,11 +226,11 @@ void verstage_main(void)
} }
printk(BIOS_INFO, "Phase 4\n"); printk(BIOS_INFO, "Phase 4\n");
rv = locate_firmware(&ctx, &wd->selected_region); rv = locate_firmware(&ctx, &fw_main);
if (rv) if (rv)
die("Failed to read FMAP to locate firmware"); die("Failed to read FMAP to locate firmware");
rv = hash_body(&ctx, &wd->selected_region); rv = hash_body(&ctx, &fw_main);
save_if_needed(&ctx); save_if_needed(&ctx);
if (rv) { if (rv) {
printk(BIOS_INFO, "Reboot requested (%x)\n", rv); printk(BIOS_INFO, "Reboot requested (%x)\n", rv);
@ -246,4 +247,5 @@ 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(wd, &fw_main);
} }

View File

@ -30,7 +30,7 @@ static struct vb2_working_data *init_vb2_working_data(void)
wd = vboot_get_working_data(); wd = vboot_get_working_data();
memset(wd, 0, CONFIG_VBOOT_WORK_BUFFER_SIZE); memset(wd, 0, CONFIG_VBOOT_WORK_BUFFER_SIZE);
/* 8-byte alignment for ARMv7 */ /* 8-byte alignment for ARMv7 */
wd->buffer = (uint8_t *)ALIGN_UP((uintptr_t)&wd[1], 8); wd->buffer = ALIGN_UP((uintptr_t)&wd[1], 8);
wd->buffer_size = CONFIG_VBOOT_WORK_BUFFER_SIZE + (uintptr_t)wd wd->buffer_size = CONFIG_VBOOT_WORK_BUFFER_SIZE + (uintptr_t)wd
- (uintptr_t)wd->buffer; - (uintptr_t)wd->buffer;
@ -74,12 +74,14 @@ void vboot2_verify_firmware(void)
entry = NULL; entry = NULL;
if (vboot_is_slot_selected(wd)) { if (vboot_is_slot_selected(wd)) {
/* RW A or B */ /* RW A or B */
struct vboot_components *fw_info = struct vboot_region fw_main;
vboot_locate_components(&wd->selected_region); struct vboot_components *fw_info;
vb2_get_selected_region(wd, &fw_main);
fw_info = vboot_locate_components(&fw_main);
if (fw_info == NULL) if (fw_info == NULL)
die("failed to locate firmware components\n"); die("failed to locate firmware components\n");
entry = vboot_load_stage(CONFIG_VBOOT_ROMSTAGE_INDEX, entry = vboot_load_stage(CONFIG_VBOOT_ROMSTAGE_INDEX,
&wd->selected_region, fw_info); &fw_main, fw_info);
} else if (vboot_is_readonly_path(wd)) { } else if (vboot_is_readonly_path(wd)) {
/* RO */ /* RO */
entry = cbfs_load_stage(CBFS_DEFAULT_MEDIA, entry = cbfs_load_stage(CBFS_DEFAULT_MEDIA,