| 1 |
|
| 2 |
|
| 3 |
#include <assert.h> |
| 4 |
#include <cbmem.h> |
| 5 |
#include <console/console.h> |
| 6 |
#include <fmap.h> |
| 7 |
#include <vb2_api.h> |
| 8 |
#include <security/vboot/misc.h> |
| 9 |
#include <security/vboot/symbols.h> |
| 10 |
#include <security/vboot/vboot_common.h> |
| 11 |
|
| 12 |
static struct vb2_context *vboot_ctx; |
| 13 |
|
| 14 |
static void *vboot_get_workbuf(void) |
| 15 |
{ |
| 16 |
void *wb = NULL; |
| 17 |
|
| 18 |
if (ENV_HAS_CBMEM) |
| 19 |
wb = cbmem_find(CBMEM_ID_VBOOT_WORKBUF); |
| 20 |
|
| 21 |
if (!wb && !CONFIG(VBOOT_STARTS_IN_ROMSTAGE) && preram_symbols_available()) |
| 22 |
wb = _vboot2_work; |
| 23 |
|
| 24 |
assert(wb); |
| 25 |
|
| 26 |
return wb; |
| 27 |
} |
| 28 |
|
| 29 |
struct vb2_context *vboot_get_context(void) |
| 30 |
{ |
| 31 |
void *wb; |
| 32 |
vb2_error_t rv; |
| 33 |
|
| 34 |
|
| 35 |
if (vboot_ctx) |
| 36 |
return vboot_ctx; |
| 37 |
|
| 38 |
wb = vboot_get_workbuf(); |
| 39 |
|
| 40 |
|
| 41 |
if (vboot_logic_executed()) { |
| 42 |
rv = vb2api_reinit(wb, &vboot_ctx); |
| 43 |
if (rv != VB2_SUCCESS) |
| 44 |
die("%s: vb2api_reinit returned %#x\n", __func__, rv); |
| 45 |
return vboot_ctx; |
| 46 |
} |
| 47 |
|
| 48 |
assert(verification_should_run()); |
| 49 |
|
| 50 |
|
| 51 |
rv = vb2api_init(wb, VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE, &vboot_ctx); |
| 52 |
assert(rv == VB2_SUCCESS); |
| 53 |
|
| 54 |
return vboot_ctx; |
| 55 |
} |
| 56 |
|
| 57 |
int vboot_locate_firmware(struct vb2_context *ctx, struct region_device *fw) |
| 58 |
{ |
| 59 |
const char *name; |
| 60 |
|
| 61 |
if (vboot_is_firmware_slot_a(ctx)) |
| 62 |
name = "FW_MAIN_A"; |
| 63 |
else |
| 64 |
name = "FW_MAIN_B"; |
| 65 |
|
| 66 |
int ret = fmap_locate_area_as_rdev(name, fw); |
| 67 |
if (ret) |
| 68 |
return ret; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
if (!CONFIG(VBOOT_CBFS_INTEGRATION)) |
| 77 |
return rdev_chain(fw, fw, 0, vb2api_get_firmware_size(ctx)); |
| 78 |
|
| 79 |
return 0; |
| 80 |
} |
| 81 |
|
| 82 |
static void vboot_setup_cbmem(int unused) |
| 83 |
{ |
| 84 |
vb2_error_t rv; |
| 85 |
const size_t cbmem_size = VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE; |
| 86 |
void *wb_cbmem = cbmem_add(CBMEM_ID_VBOOT_WORKBUF, cbmem_size); |
| 87 |
assert(wb_cbmem); |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
if (!CONFIG(VBOOT_STARTS_IN_ROMSTAGE)) |
| 104 |
rv = vb2api_relocate(wb_cbmem, _vboot2_work, cbmem_size, |
| 105 |
&vboot_ctx); |
| 106 |
else |
| 107 |
rv = vb2api_init(wb_cbmem, cbmem_size, &vboot_ctx); |
| 108 |
|
| 109 |
assert(rv == VB2_SUCCESS); |
| 110 |
} |
| 111 |
CBMEM_CREATION_HOOK(vboot_setup_cbmem); |