Skip to content

Commit d364d35

Browse files
JasonChenCJEddie Dong
authored andcommitted
reshuffle struct vboot_candidates
struct vboot_candidates is private, so move it into source file, and change it to a more suitable name vboot_bootloader_map. this patch also add sos_boot_mode to indicate if the sos boot is using de-privilege or direct boot mode. Tracked-On: #1842 Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com>
1 parent 41ac9e5 commit d364d35

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

hypervisor/boot/guest/vboot_wrapper.c

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313
#include <direct_boot.h>
1414
#include <deprivilege_boot.h>
1515

16+
#define BOOTLOADER_NUM 4U
17+
#define BOOTLOADER_NAME_SIZE 20U
18+
19+
struct vboot_bootloader_map {
20+
const char bootloader_name[BOOTLOADER_NAME_SIZE];
21+
enum vboot_mode mode;
22+
};
23+
1624
static struct vboot_operations *vboot_ops;
25+
static enum vboot_mode sos_boot_mode;
1726

1827
/**
1928
* @pre: this function is called during detect mode which is very early stage,
@@ -25,18 +34,25 @@ void init_vboot_operations(void)
2534
struct multiboot_info *mbi;
2635
uint32_t i;
2736

28-
const struct vboot_candidates vboot_candidates[NUM_VBOOT_SUPPORTING] = {
29-
{"Slim BootLoader", 15U, get_direct_boot_ops},
30-
{"Intel IOTG/TSD ABL", 18U, get_direct_boot_ops},
31-
{"ACRN UEFI loader", 16U, get_deprivilege_boot_ops},
32-
{"GRUB", 4U, get_direct_boot_ops},
37+
const struct vboot_bootloader_map vboot_bootloader_maps[BOOTLOADER_NUM] = {
38+
{"Slim BootLoader", DIRECT_BOOT_MODE},
39+
{"Intel IOTG/TSD ABL", DIRECT_BOOT_MODE},
40+
{"ACRN UEFI loader", DEPRI_BOOT_MODE},
41+
{"GRUB", DIRECT_BOOT_MODE},
3342
};
3443

3544
mbi = (struct multiboot_info *)hpa2hva((uint64_t)boot_regs[1]);
36-
for (i = 0U; i < NUM_VBOOT_SUPPORTING; i++) {
37-
if (strncmp(hpa2hva(mbi->mi_loader_name), vboot_candidates[i].name,
38-
vboot_candidates[i].name_sz) == 0) {
39-
vboot_ops = vboot_candidates[i].ops();
45+
for (i = 0U; i < BOOTLOADER_NUM; i++) {
46+
if (strncmp(hpa2hva(mbi->mi_loader_name), vboot_bootloader_maps[i].bootloader_name,
47+
strnlen_s(vboot_bootloader_maps[i].bootloader_name, BOOTLOADER_NAME_SIZE)) == 0) {
48+
/* Only support two vboot mode */
49+
if (vboot_bootloader_maps[i].mode == DEPRI_BOOT_MODE) {
50+
vboot_ops = get_deprivilege_boot_ops();
51+
sos_boot_mode = DEPRI_BOOT_MODE;
52+
} else {
53+
vboot_ops = get_direct_boot_ops();
54+
sos_boot_mode = DIRECT_BOOT_MODE;
55+
}
4056
break;
4157
}
4258
}
@@ -51,6 +67,12 @@ void init_vboot(void)
5167
vboot_ops->init();
5268
}
5369

70+
/* @pre: vboot_ops != NULL */
71+
enum vboot_mode get_sos_boot_mode(void)
72+
{
73+
return sos_boot_mode;
74+
}
75+
5476
/* @pre: vboot_ops->get_ap_trampoline != NULL */
5577
uint64_t get_ap_trampoline_buf(void)
5678
{

hypervisor/boot/include/guest/vboot.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
#define VBOOT_H
1010

11-
#define NUM_VBOOT_SUPPORTING 4U
11+
enum vboot_mode {
12+
DIRECT_BOOT_MODE,
13+
DEPRI_BOOT_MODE
14+
};
1215

1316
struct acrn_vm;
1417
struct vboot_operations {
@@ -19,19 +22,14 @@ struct vboot_operations {
1922
int32_t (*init_vboot_info)(struct acrn_vm *vm);
2023
};
2124

22-
struct vboot_candidates {
23-
const char name[20];
24-
size_t name_sz;
25-
struct vboot_operations *(*ops)(void);
26-
};
27-
2825
void init_vboot_operations(void);
2926
void init_vboot(void);
3027
void init_vboot_irq(void);
3128
int32_t init_vm_boot_info(struct acrn_vm *vm);
3229
uint64_t get_ap_trampoline_buf(void);
3330
void *get_rsdp_ptr(void);
3431

32+
enum vboot_mode get_sos_boot_mode(void);
3533
int32_t parse_hv_cmdline(void);
3634

3735
#endif /* end of include guard: VBOOT_H */

0 commit comments

Comments
 (0)