2021-06-08 15:11:18 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 Intel Corporation.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <types.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <boot.h>
|
|
|
|
#include <rtl.h>
|
|
|
|
#include <logmsg.h>
|
|
|
|
|
2021-10-29 14:58:39 +08:00
|
|
|
static struct acrn_boot_info acrn_bi = { 0 };
|
2021-06-08 15:11:18 +08:00
|
|
|
|
2021-06-01 14:17:18 +08:00
|
|
|
/**
|
|
|
|
* @pre (p_start != NULL) && (p_end != NULL)
|
|
|
|
*/
|
|
|
|
void get_boot_mods_range(uint64_t *p_start, uint64_t *p_end)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
uint64_t start = ~0UL, end = 0UL;
|
|
|
|
struct acrn_boot_info *abi = get_acrn_boot_info();
|
|
|
|
|
|
|
|
for (i = 0; i < abi->mods_count; i++) {
|
|
|
|
if (hva2hpa(abi->mods[i].start) < start) {
|
|
|
|
start = hva2hpa(abi->mods[i].start);
|
|
|
|
}
|
|
|
|
if (hva2hpa(abi->mods[i].start + abi->mods[i].size) > end) {
|
|
|
|
end = hva2hpa(abi->mods[i].start + abi->mods[i].size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*p_start = start;
|
|
|
|
*p_end = end;
|
|
|
|
}
|
|
|
|
|
2021-06-08 15:11:18 +08:00
|
|
|
void init_acrn_boot_info(uint32_t *registers)
|
|
|
|
{
|
|
|
|
(void)init_multiboot_info(registers);
|
|
|
|
/* TODO: add more boot protocol support here */
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t sanitize_acrn_boot_info(struct acrn_boot_info *abi)
|
|
|
|
{
|
|
|
|
int32_t abi_status = 0;
|
|
|
|
|
2021-06-08 15:17:50 +08:00
|
|
|
if (abi->mods_count == 0U) {
|
2021-06-08 15:11:18 +08:00
|
|
|
pr_err("no boot module info found");
|
|
|
|
abi_status = -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-06-08 15:22:46 +08:00
|
|
|
if (abi->mmap_entries == 0U) {
|
2021-06-08 15:11:18 +08:00
|
|
|
pr_err("no boot mmap info found");
|
|
|
|
abi_status = -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-06-08 16:23:08 +08:00
|
|
|
printf("%s environment detected.\n", boot_from_uefi(abi) ? "UEFI" : "Non-UEFI");
|
2021-09-22 10:28:33 +08:00
|
|
|
if (boot_from_uefi(abi) && ((abi->uefi_info.memmap == 0U) || (abi->uefi_info.memmap_hi != 0U))) {
|
|
|
|
pr_err("no efi memmap found below 4GB space!");
|
2021-06-03 21:13:26 +08:00
|
|
|
abi_status = -EINVAL;
|
|
|
|
}
|
2021-06-08 15:11:18 +08:00
|
|
|
|
2021-06-08 10:58:54 +08:00
|
|
|
if (abi->loader_name[0] == '\0') {
|
2021-06-08 15:11:18 +08:00
|
|
|
pr_err("no bootloader name found!");
|
|
|
|
abi_status = -EINVAL;
|
|
|
|
} else {
|
2021-06-08 10:58:54 +08:00
|
|
|
printf("%s Bootloader: %s\n", abi->protocol_name, abi->loader_name);
|
2021-06-08 15:11:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return abi_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @post retval != NULL
|
|
|
|
*/
|
|
|
|
struct acrn_boot_info *get_acrn_boot_info(void)
|
|
|
|
{
|
|
|
|
return &acrn_bi;
|
|
|
|
}
|