Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linuxbootsupport v3 #1873

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
187 changes: 187 additions & 0 deletions UefiPayloadPkg/Library/LbParseLib/LbParseLib.c
@@ -0,0 +1,187 @@
/** @file
This library will parse the linuxboot table in memory and extract those required
information.

Copyright (c) 2021, the u-root Authors. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/


#include <IndustryStandard/Acpi.h>
#include <IndustryStandard/SmBios.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BlParseLib.h>
#include <Library/DebugLib.h>
#include <Library/IoLib.h>
#include <Library/PcdLib.h>
#include <Linuxboot.h>
#include <Uefi/UefiBaseType.h>

// Retrieve UefiPayloadConfig from Linuxboot's uefiboot
UefiPayloadConfig*
GetUefiPayLoadConfig()
{
UefiPayloadConfig *Config;
Config = (UefiPayloadConfig*)(UINTN)(PcdGet32(PcdPayloadFdMemBase) - SIZE_64KB);
if (Config->Version != UEFI_PAYLOAD_CONFIG_VERSION) {
DEBUG((DEBUG_ERROR, "Expect payload Config version: %d, but get %d\n",
UEFI_PAYLOAD_CONFIG_VERSION, Config->Version));
CpuDeadLoop ();
}
return Config;
}

// Align the address and add memory rang to MemInfoCallback
VOID
AddMemoryRange (
IN BL_MEM_INFO_CALLBACK MemInfoCallback,
IN UINTN start,
IN UINTN end,
IN int type
) {
MEMROY_MAP_ENTRY MemoryMap;
UINTN AlignedStart;
UINTN AlignedEnd;
AlignedStart = ALIGN_VALUE(start, SIZE_4KB);
AlignedEnd = ALIGN_VALUE(end, SIZE_4KB);
// Conservative adjustment on Memory map. This should happen when booting from
// non UEFI bios and it may report a memory region less than 4KB.
if (AlignedStart > start && type != LINUXBOOT_MEM_RAM) {
AlignedStart -= SIZE_4KB;
}
if (AlignedEnd > end + 1 && type == LINUXBOOT_MEM_RAM) {
AlignedEnd -= SIZE_4KB;
}
MemoryMap.Base = AlignedStart;
MemoryMap.Size = AlignedEnd - AlignedStart;
MemoryMap.Type = type;
MemoryMap.Flag = 0;
MemInfoCallback(&MemoryMap, NULL);
}

/**
Acquire the memory information from the linuxboot table in memory.

@param MemInfoCallback The callback routine
@param Params Pointer to the callback routine parameter

@retval RETURN_SUCCESS Successfully find out the memory information.
@retval RETURN_NOT_FOUND Failed to find the memory information.

**/
RETURN_STATUS
EFIAPI
ParseMemoryInfo (
IN BL_MEM_INFO_CALLBACK MemInfoCallback,
IN VOID* Params
) {
UefiPayloadConfig *Config;
MemoryMapEntry* entry;
int Index;

Config = GetUefiPayLoadConfig();

DEBUG((DEBUG_INFO, "MemoryMap #entries: %d\n", Config->NumMemoryMapEntries));

entry = &Config->MemoryMapEntries[0];
for (Index = 0; Index < Config->NumMemoryMapEntries; Index++) {
DEBUG((DEBUG_INFO, "Start: 0x%lx End: 0x%lx Type:%d\n", entry->Start,
entry->End, entry->Type));
AddMemoryRange(MemInfoCallback, entry->Start, entry->End, entry->Type);
entry++;
}
return RETURN_SUCCESS;
}

/**
Acquire acpi table and smbios table from linuxboot

@param SystemTableInfo Pointer to the system table info

@retval RETURN_SUCCESS Successfully find out the tables.
@retval RETURN_NOT_FOUND Failed to find the tables.

**/
RETURN_STATUS
EFIAPI
ParseSystemTable (
OUT SYSTEM_TABLE_INFO* SystemTableInfo
) {
UefiPayloadConfig *Config;

Config = GetUefiPayLoadConfig();
SystemTableInfo->AcpiTableBase = Config->AcpiBase;
SystemTableInfo->AcpiTableSize = Config->AcpiSize;

SystemTableInfo->SmbiosTableBase = Config->SmbiosBase;
SystemTableInfo->SmbiosTableSize = Config->SmbiosSize;

return RETURN_SUCCESS;
}

/**
Find the serial port information

@param SERIAL_PORT_INFO Pointer to serial port info structure

@retval RETURN_SUCCESS Successfully find the serial port information.
@retval RETURN_NOT_FOUND Failed to find the serial port information .

**/
RETURN_STATUS
EFIAPI
ParseSerialInfo (
OUT SERIAL_PORT_INFO* SerialPortInfo
) {
UefiPayloadConfig *Config;
Config = GetUefiPayLoadConfig();

SerialPortInfo->BaseAddr = Config->SerialConfig.BaseAddr;
SerialPortInfo->RegWidth = Config->SerialConfig.RegWidth;
SerialPortInfo->Type = Config->SerialConfig.Type;
SerialPortInfo->Baud = Config->SerialConfig.Baud;
SerialPortInfo->InputHertz = Config->SerialConfig.InputHertz;
SerialPortInfo->UartPciAddr = Config->SerialConfig.UartPciAddr;

return RETURN_SUCCESS;
}

/**
Find the video frame buffer information

@param GfxInfo Pointer to the EFI_PEI_GRAPHICS_INFO_HOB structure

@retval RETURN_SUCCESS Successfully find the video frame buffer
information.
@retval RETURN_NOT_FOUND Failed to find the video frame buffer information .

**/
RETURN_STATUS
EFIAPI
ParseGfxInfo (
OUT EFI_PEI_GRAPHICS_INFO_HOB* GfxInfo
) {
// Not supported
return RETURN_NOT_FOUND;
}

/**
Find the video frame buffer device information

@param GfxDeviceInfo Pointer to the EFI_PEI_GRAPHICS_DEVICE_INFO_HOB
structure

@retval RETURN_SUCCESS Successfully find the video frame buffer
information.
@retval RETURN_NOT_FOUND Failed to find the video frame buffer information.

**/
RETURN_STATUS
EFIAPI
ParseGfxDeviceInfo (
OUT EFI_PEI_GRAPHICS_DEVICE_INFO_HOB* GfxDeviceInfo
) {
return RETURN_NOT_FOUND;
}
39 changes: 39 additions & 0 deletions UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf
@@ -0,0 +1,39 @@
## @file
# Linuxboot Table Parse Library.
#
# Copyright (c) 2021, the u-root Authors. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = LbParseLib
FILE_GUID = DBA15E1E-4C16-47DF-93C0-AB5888ED14C3
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = BlParseLib

#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
#

[Sources]
LbParseLib.c

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiPayloadPkg/UefiPayloadPkg.dec

[LibraryClasses]
BaseLib
BaseMemoryLib
IoLib
DebugLib
PcdLib

[Pcd]
gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemBase
47 changes: 47 additions & 0 deletions UefiPayloadPkg/Library/LbParseLib/Linuxboot.h
@@ -0,0 +1,47 @@
/** @file
LinuxBoot PEI module include file.
**/
#ifndef __LINUXBOOT_PEI_H_INCLUDED__
#define __LINUXBOOT_PEI_H_INCLUDED__

#if defined(_MSC_VER)
#pragma warning(disable : 4200)
#endif

#pragma pack(1)
typedef struct SerialPortConfigStruct {
UINT32 Type;
UINT32 BaseAddr;
UINT32 Baud;
UINT32 RegWidth;
UINT32 InputHertz;
UINT32 UartPciAddr;
} SerialPortConfig;

typedef struct MemoryMapEntryStruct {
UINT64 Start;
UINT64 End;
UINT32 Type;
} MemoryMapEntry;

typedef struct UefiPayloadConfigStruct {
UINT64 Version;
UINT64 AcpiBase;
UINT64 AcpiSize;
UINT64 SmbiosBase;
UINT64 SmbiosSize;
SerialPortConfig SerialConfig;
UINT32 NumMemoryMapEntries;
MemoryMapEntry MemoryMapEntries[0];
} UefiPayloadConfig;
#pragma pack()

#define UEFI_PAYLOAD_CONFIG_VERSION 1

#define LINUXBOOT_MEM_RAM 1
#define LINUXBOOT_MEM_DEFAULT 2
#define LINUXBOOT_MEM_ACPI 3
#define LINUXBOOT_MEM_NVS 4
#define LINUXBOOT_MEM_RESERVED 5

#endif // __LINUXBOOT_PEI_H_INCLUDED__
Expand Up @@ -40,8 +40,9 @@ AdjustRootBridgeResource (
IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G
)
{
#ifndef LINUXBOOT_PAYLOAD
UINT64 Mask;

#endif
//
// For now try to downgrade everything into MEM32 since
// - coreboot does not assign resource above 4GB
Expand Down Expand Up @@ -80,7 +81,7 @@ AdjustRootBridgeResource (
PMemAbove4G->Base = MAX_UINT64;
PMemAbove4G->Limit = 0;
}

#ifndef LINUXBOOT_PAYLOAD
//
// Align IO resource at 4K boundary
//
Expand All @@ -98,6 +99,7 @@ AdjustRootBridgeResource (
if (Mem->Base != MAX_UINT64) {
Mem->Base &= ~Mask;
}
#endif
}

/**
Expand Down
4 changes: 4 additions & 0 deletions UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
Expand Up @@ -517,6 +517,10 @@ BuildGenericHob (

// The UEFI payload FV
BuildMemoryAllocationHob (PcdGet32 (PcdPayloadFdMemBase), PcdGet32 (PcdPayloadFdMemSize), EfiBootServicesData);
#ifdef LINUXBOOT_PAYLOAD
// The UEFI payload config FV
BuildMemoryAllocationHob (PcdGet32 (PcdPayloadFdMemBase) - SIZE_64KB, SIZE_64KB, EfiRuntimeServicesData);
#endif

//
// Build CPU memory space and IO space hob
Expand Down
24 changes: 18 additions & 6 deletions UefiPayloadPkg/UefiPayloadPkg.dsc
Expand Up @@ -33,13 +33,14 @@
#
# SBL: UEFI payload for Slim Bootloader
# COREBOOT: UEFI payload for coreboot
# LINUXBOOT: UEFI payload for linuxboot
#
DEFINE BOOTLOADER = SBL

#
# CPU options
#
DEFINE MAX_LOGICAL_PROCESSORS = 64
DEFINE MAX_LOGICAL_PROCESSORS = 256

#
# PCI options
Expand Down Expand Up @@ -102,6 +103,9 @@

[BuildOptions]
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
!if $(BOOTLOADER) == "LINUXBOOT"
*_*_*_CC_FLAGS = -D LINUXBOOT_PAYLOAD
!endif
GCC:*_UNIXGCC_*_CC_FLAGS = -DMDEPKG_NDEBUG
GCC:RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG
INTEL:RELEASE_*_*_CC_FLAGS = /D MDEPKG_NDEBUG
Expand Down Expand Up @@ -231,11 +235,13 @@
!endif
PlatformSupportLib|UefiPayloadPkg/Library/PlatformSupportLibNull/PlatformSupportLibNull.inf
!if $(UNIVERSAL_PAYLOAD) == FALSE
!if $(BOOTLOADER) == "COREBOOT"
BlParseLib|UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf
!else
BlParseLib|UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf
!endif
!if $(BOOTLOADER) == "COREBOOT"
BlParseLib|UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf
!elseif $(BOOTLOADER) == "LINUXBOOT"
BlParseLib|UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf
!else
BlParseLib|UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf
!endif
!endif

DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
Expand Down Expand Up @@ -453,7 +459,13 @@
NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf
}

!if $(BOOTLOADER) == "LINUXBOOT"
OvmfPkg/8254TimerDxe/8254Timer.inf
OvmfPkg/8259InterruptControllerDxe/8259.inf
!else
PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf
!endif

MdeModulePkg/Universal/Metronome/Metronome.inf
MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
Expand Down
5 changes: 5 additions & 0 deletions UefiPayloadPkg/UefiPayloadPkg.fdf
Expand Up @@ -101,7 +101,12 @@ INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
INF UefiCpuPkg/CpuDxe/CpuDxe.inf
INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
INF MdeModulePkg/Application/UiApp/UiApp.inf
!if $(BOOTLOADER) != "LINUXBOOT"
INF PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf
!else
INF OvmfPkg/8254TimerDxe/8254Timer.inf
INF OvmfPkg/8259InterruptControllerDxe/8259.inf
!endif
INF MdeModulePkg/Universal/Metronome/Metronome.inf
INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
Expand Down