acrn-hypervisor/hypervisor/boot/guest/vboot_wrapper.c
Victor Sun 52f26cba8a hv: a few fixes for multiboot2 boot
- need to specify the load_addr in the multiboot2 address tag. GRUB needs
  it to correctly calculate the ACRN binary's load size if load_end_addr is
  a non-zero value.

- multiboot2 can be enabled if hypervisor relocation is disabled.

- print the name of the boot loader. This might be helpful if the boot
  loader, e.g. GRUB, inludes its version in the name string.

Tracked-On: #4441
Signed-off-by: Victor Sun <victor.sun@intel.com>
Signed-off-by: Zide Chen <zide.chen@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
2020-03-24 08:44:20 +08:00

92 lines
2.2 KiB
C

/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <vm.h>
#include <types.h>
#include <pgtable.h>
#include <acpi.h>
#include <boot.h>
#include <vboot.h>
#include <direct_boot.h>
#include <deprivilege_boot.h>
#include <logmsg.h>
#define BOOTLOADER_NUM 5U
#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,
* other exported interfaces should not be called beforehand.
*/
void init_vboot(void)
{
struct acrn_multiboot_info *mbi = get_multiboot_info();
uint32_t i;
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},
{"PXELINUX", DIRECT_BOOT_MODE},
};
printf("Detect bootloader: %s\n", mbi->mi_loader_name);
for (i = 0U; i < BOOTLOADER_NUM; i++) {
if (strncmp(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;
}
}
/*
* vboot_ops is mandatory and it will be initialized correctly.
* The vboot_ops->init is called to assure that the boot env is
* initialized before calling other vboot_ops interface.
*/
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)
{
return vboot_ops->get_ap_trampoline();
}
/* @pre: vboot_ops->get_rsdp != NULL */
void *get_rsdp_ptr(void)
{
return vboot_ops->get_rsdp();
}
/* @pre: vboot_ops->init_irq != NULL */
void init_vboot_irq(void)
{
return vboot_ops->init_irq();
}