diff --git a/hypervisor/boot/guest/vboot_wrapper.c b/hypervisor/boot/guest/vboot_wrapper.c index 8f403f526..6c711f6bf 100644 --- a/hypervisor/boot/guest/vboot_wrapper.c +++ b/hypervisor/boot/guest/vboot_wrapper.c @@ -13,7 +13,16 @@ #include #include +#define BOOTLOADER_NUM 4U +#define BOOTLOADER_NAME_SIZE 20U + +struct vboot_bootloader_map { + const char bootloader_name[BOOTLOADER_NAME_SIZE]; + enum vboot_mode mode; +}; + static struct vboot_operations *vboot_ops; +static enum vboot_mode sos_boot_mode; /** * @pre: this function is called during detect mode which is very early stage, @@ -25,18 +34,25 @@ void init_vboot_operations(void) struct multiboot_info *mbi; uint32_t i; - const struct vboot_candidates vboot_candidates[NUM_VBOOT_SUPPORTING] = { - {"Slim BootLoader", 15U, get_direct_boot_ops}, - {"Intel IOTG/TSD ABL", 18U, get_direct_boot_ops}, - {"ACRN UEFI loader", 16U, get_deprivilege_boot_ops}, - {"GRUB", 4U, get_direct_boot_ops}, + const struct vboot_bootloader_map vboot_bootloader_maps[BOOTLOADER_NUM] = { + {"Slim BootLoader", DIRECT_BOOT_MODE}, + {"Intel IOTG/TSD ABL", DIRECT_BOOT_MODE}, + {"ACRN UEFI loader", DEPRI_BOOT_MODE}, + {"GRUB", DIRECT_BOOT_MODE}, }; mbi = (struct multiboot_info *)hpa2hva((uint64_t)boot_regs[1]); - for (i = 0U; i < NUM_VBOOT_SUPPORTING; i++) { - if (strncmp(hpa2hva(mbi->mi_loader_name), vboot_candidates[i].name, - vboot_candidates[i].name_sz) == 0) { - vboot_ops = vboot_candidates[i].ops(); + for (i = 0U; i < BOOTLOADER_NUM; i++) { + if (strncmp(hpa2hva(mbi->mi_loader_name), vboot_bootloader_maps[i].bootloader_name, + strnlen_s(vboot_bootloader_maps[i].bootloader_name, BOOTLOADER_NAME_SIZE)) == 0) { + /* Only support two vboot mode */ + if (vboot_bootloader_maps[i].mode == DEPRI_BOOT_MODE) { + vboot_ops = get_deprivilege_boot_ops(); + sos_boot_mode = DEPRI_BOOT_MODE; + } else { + vboot_ops = get_direct_boot_ops(); + sos_boot_mode = DIRECT_BOOT_MODE; + } break; } } @@ -51,6 +67,12 @@ void init_vboot(void) vboot_ops->init(); } +/* @pre: vboot_ops != NULL */ +enum vboot_mode get_sos_boot_mode(void) +{ + return sos_boot_mode; +} + /* @pre: vboot_ops->get_ap_trampoline != NULL */ uint64_t get_ap_trampoline_buf(void) { diff --git a/hypervisor/boot/include/guest/vboot.h b/hypervisor/boot/include/guest/vboot.h index 4fb1c0bc5..51b8a96c9 100644 --- a/hypervisor/boot/include/guest/vboot.h +++ b/hypervisor/boot/include/guest/vboot.h @@ -8,7 +8,10 @@ #define VBOOT_H -#define NUM_VBOOT_SUPPORTING 4U +enum vboot_mode { + DIRECT_BOOT_MODE, + DEPRI_BOOT_MODE +}; struct acrn_vm; struct vboot_operations { @@ -19,12 +22,6 @@ struct vboot_operations { int32_t (*init_vboot_info)(struct acrn_vm *vm); }; -struct vboot_candidates { - const char name[20]; - size_t name_sz; - struct vboot_operations *(*ops)(void); -}; - void init_vboot_operations(void); void init_vboot(void); void init_vboot_irq(void); @@ -32,6 +29,7 @@ int32_t init_vm_boot_info(struct acrn_vm *vm); uint64_t get_ap_trampoline_buf(void); void *get_rsdp_ptr(void); +enum vboot_mode get_sos_boot_mode(void); int32_t parse_hv_cmdline(void); #endif /* end of include guard: VBOOT_H */