| 1 |
|
| 2 |
|
| 3 |
#ifndef __VBOOT_MISC_H__ |
| 4 |
#define __VBOOT_MISC_H__ |
| 5 |
|
| 6 |
#include <assert.h> |
| 7 |
#include <security/vboot/vboot_common.h> |
| 8 |
#include <vb2_api.h> |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
struct vb2_context *vboot_get_context(void); |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
static inline int vboot_is_firmware_slot_a(struct vb2_context *ctx) |
| 19 |
{ |
| 20 |
return !(ctx->flags & VB2_CONTEXT_FW_SLOT_B); |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
static inline bool vboot_is_gbb_flag_set(enum vb2_gbb_flag flag) |
| 27 |
{ |
| 28 |
return !!(vb2api_gbb_get_flags(vboot_get_context()) & flag); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
int vboot_locate_firmware(struct vb2_context *ctx, struct region_device *fw); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
static inline int verification_should_run(void) |
| 44 |
{ |
| 45 |
if (CONFIG(VBOOT_SEPARATE_VERSTAGE)) |
| 46 |
return ENV_SEPARATE_VERSTAGE; |
| 47 |
else if (CONFIG(VBOOT_STARTS_IN_ROMSTAGE)) |
| 48 |
return ENV_RAMINIT; |
| 49 |
else if (CONFIG(VBOOT_STARTS_IN_BOOTBLOCK)) |
| 50 |
return ENV_BOOTBLOCK; |
| 51 |
else |
| 52 |
dead_code(); |
| 53 |
} |
| 54 |
|
| 55 |
static inline int verstage_should_load(void) |
| 56 |
{ |
| 57 |
if (CONFIG(VBOOT_SEPARATE_VERSTAGE) && !CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK)) |
| 58 |
return ENV_BOOTBLOCK; |
| 59 |
else |
| 60 |
return 0; |
| 61 |
} |
| 62 |
|
| 63 |
static inline int vboot_logic_executed(void) |
| 64 |
{ |
| 65 |
extern int vboot_executed; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
if (verification_should_run() || |
| 71 |
(verstage_should_load() && CONFIG(VBOOT_RETURN_FROM_VERSTAGE))) |
| 72 |
return vboot_executed; |
| 73 |
|
| 74 |
if (CONFIG(VBOOT_STARTS_IN_BOOTBLOCK)) { |
| 75 |
|
| 76 |
return !ENV_BOOTBLOCK; |
| 77 |
} else if (CONFIG(VBOOT_STARTS_IN_ROMSTAGE)) { |
| 78 |
|
| 79 |
return !ENV_ROMSTAGE_OR_BEFORE; |
| 80 |
} else if (CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK)) { |
| 81 |
return !ENV_SEPARATE_VERSTAGE; |
| 82 |
} else { |
| 83 |
dead_code(); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
static inline bool vboot_hwcrypto_allowed(void) |
| 88 |
{ |
| 89 |
|
| 90 |
if (!CONFIG(VBOOT)) |
| 91 |
return 1; |
| 92 |
|
| 93 |
|
| 94 |
if (!vboot_logic_executed()) |
| 95 |
return 0; |
| 96 |
|
| 97 |
|
| 98 |
return vb2api_hwcrypto_allowed(vboot_get_context()); |
| 99 |
} |
| 100 |
|
| 101 |
#endif |