From nobody Tue Feb 10 10:04:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+79722+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+79722+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1629730270; cv=none; d=zohomail.com; s=zohoarc; b=gTCS322+yKcVC/St9P+vHQdRRR0ppF2GdJ0E/1yrZCoFria7ZoeP/x8rY8IVO1rcaFQVmPkVGVbuQhz7WfMxUs0flsiwK3d9VmfCW2euPx+ArvblMScXOzE7YB8ighMOEveigU1f+Xd2YFwLB23+i36OxWNYphLRfdDQWbJFh+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629730270; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=SI8PtaEEtdl7QugeaWy3Rlrvs7vKPl/JRLegh6GeZ0k=; b=YGIkrjVW8UuCOChYS7X/aFi/tlBiAB8i0cKMnN4D2MuO2KKjH1NgXW1gbM/gRA5L4p8lV29vyMaR5evt+TrpkfAyL2FZir2vl3wA1nUP3t6Q/Ujx3S1YbpJPW1SHbAKxbQpEmKXXQQOCAv25snPJZ3bttONBFpsowpjBlRGob+w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+79722+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1629730270187954.6196914819963; Mon, 23 Aug 2021 07:51:10 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id KqR7YY1788612xI5E0iekF9I; Mon, 23 Aug 2021 07:51:09 -0700 X-Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by mx.groups.io with SMTP id smtpd.web12.20220.1629700415344016069 for ; Sun, 22 Aug 2021 23:33:35 -0700 X-Received: by mail-pf1-f202.google.com with SMTP id g17-20020aa781910000b0290360a5312e3eso8169617pfi.7 for ; Sun, 22 Aug 2021 23:33:34 -0700 (PDT) X-Gm-Message-State: 2bOU0Po0QfMiRdshgCJdeMupx1787277AA= X-Google-Smtp-Source: ABdhPJxk+rJSm2ErlxCrms34J1gdIhf5UmZ7i1I1aXA6Gxkyv+kNy4ATX111qe/mAt7K8cfHMnWh472pcSxarybm X-Received: from ratho96.c.googlers.com ([fda3:e722:ac3:cc00:3:22c1:c0a8:aae]) (user=chengchieh job=sendgmr) by 2002:a17:90a:702:: with SMTP id l2mr525935pjl.0.1629700413688; Sun, 22 Aug 2021 23:33:33 -0700 (PDT) Date: Mon, 23 Aug 2021 06:33:09 +0000 In-Reply-To: <20210823063312.2323801-1-chengchieh@google.com> Message-Id: <20210823063312.2323801-2-chengchieh@google.com> Mime-Version: 1.0 References: <20210823063312.2323801-1-chengchieh@google.com> Subject: [edk2-devel] [PATCH v3 1/4] UefiPayloadPkg: Add LINUXBOOT payload target From: "Cheng-Chieh Huang via groups.io" To: devel@edk2.groups.io Cc: Cheng-Chieh Huang , Daniel Schaefer , Trammell Hudson , Maurice Ma , Guo Dong , Benjamin You , Ray Ni Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,chengchieh@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1629730269; bh=6K8Ymbuv6ygC9ryoaiYJzEHyrkF7gm6nV1FHAOq4gMo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=xb005Kiae6TIpk1wUIXescKefh40ZPJNKyWzIUCoePBaIXEvXFoGJtSVkkJ6QEi1TFU ddg8weEZ8clbEA/lLO3UQGpXf71zRK7t5DS0ckh0HUrSaIE7cymxpyf6WZY7CHJHgpGEC SCTTn+G4XIW9UiiYBaZtN/P+0YWfp/Qaxzg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1629730271513100005 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Initial commit to support linuxboot payload. Signed-off-by: Cheng-Chieh Huang Cc: Cheng-Chieh Huang Cc: Daniel Schaefer Cc: Trammell Hudson Cc: Maurice Ma Cc: Guo Dong Cc: Benjamin You Cc: Ray Ni --- UefiPayloadPkg/UefiPayloadPkg.dsc | 16 +- .../Library/LbParseLib/LbParseLib.inf | 39 ++++ UefiPayloadPkg/Library/LbParseLib/Linuxboot.h | 47 +++++ .../Library/LbParseLib/LbParseLib.c | 187 ++++++++++++++++++ .../PciHostBridgeLib/PciHostBridgeSupport.c | 6 +- 5 files changed, 288 insertions(+), 7 deletions(-) create mode 100644 UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf create mode 100644 UefiPayloadPkg/Library/LbParseLib/Linuxboot.h create mode 100644 UefiPayloadPkg/Library/LbParseLib/LbParseLib.c diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayload= Pkg.dsc index bcedf1c746b4..54576ba485b7 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -33,6 +33,7 @@ [Defines] # # SBL: UEFI payload for Slim Bootloader # COREBOOT: UEFI payload for coreboot + # LINUXBOOT: UEFI payload for linuxboot # DEFINE BOOTLOADER =3D SBL =20 @@ -93,6 +94,9 @@ [Defines] =20 [BuildOptions] *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES +!if $(BOOTLOADER) =3D=3D "LINUXBOOT" + *_*_*_CC_FLAGS =3D -D LINUXBOOT_PAYLOAD +!endif GCC:*_UNIXGCC_*_CC_FLAGS =3D -DMDEPKG_NDEBUG GCC:RELEASE_*_*_CC_FLAGS =3D -DMDEPKG_NDEBUG INTEL:RELEASE_*_*_CC_FLAGS =3D /D MDEPKG_NDEBUG @@ -222,11 +226,13 @@ [LibraryClasses] !endif PlatformSupportLib|UefiPayloadPkg/Library/PlatformSupportLibNull/Platfor= mSupportLibNull.inf !if $(UNIVERSAL_PAYLOAD) =3D=3D FALSE - !if $(BOOTLOADER) =3D=3D "COREBOOT" - BlParseLib|UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf - !else - BlParseLib|UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf - !endif + !if $(BOOTLOADER) =3D=3D "COREBOOT" + BlParseLib|UefiPayloadPkg/Library/CbParseLib/CbParseLib.inf + !elseif $(BOOTLOADER) =3D=3D "LINUXBOOT" + BlParseLib|UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf + !else + BlParseLib|UefiPayloadPkg/Library/SblParseLib/SblParseLib.inf + !endif !endif =20 DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf diff --git a/UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf b/UefiPayload= Pkg/Library/LbParseLib/LbParseLib.inf new file mode 100644 index 000000000000..d75ba8db8cf3 --- /dev/null +++ b/UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf @@ -0,0 +1,39 @@ +## @file +# Linuxboot Table Parse Library. +# +# Copyright (c) 2021, the u-root Authors. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D LbParseLib + FILE_GUID =3D DBA15E1E-4C16-47DF-93C0-AB5888ED14C3 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D BlParseLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + LbParseLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiPayloadPkg/UefiPayloadPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + IoLib + DebugLib + PcdLib + +[Pcd] + gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemBase diff --git a/UefiPayloadPkg/Library/LbParseLib/Linuxboot.h b/UefiPayloadPkg= /Library/LbParseLib/Linuxboot.h new file mode 100644 index 000000000000..b3b7e70a7ccb --- /dev/null +++ b/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__ diff --git a/UefiPayloadPkg/Library/LbParseLib/LbParseLib.c b/UefiPayloadPk= g/Library/LbParseLib/LbParseLib.c new file mode 100644 index 000000000000..48d174dfc078 --- /dev/null +++ b/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.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Retrieve UefiPayloadConfig from Linuxboot's uefiboot +UefiPayloadConfig* +GetUefiPayLoadConfig() +{ + UefiPayloadConfig *Config; + Config =3D (UefiPayloadConfig*)(UINTN)(PcdGet32(PcdPayloadFdMemBase) - S= IZE_64KB); + if (Config->Version !=3D 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 =3D ALIGN_VALUE(start, SIZE_4KB); + AlignedEnd =3D ALIGN_VALUE(end, SIZE_4KB); + // Conservative adjustment on Memory map. This should happen when bootin= g from + // non UEFI bios and it may report a memory region less than 4KB. + if (AlignedStart > start && type !=3D LINUXBOOT_MEM_RAM) { + AlignedStart -=3D SIZE_4KB; + } + if (AlignedEnd > end + 1 && type =3D=3D LINUXBOOT_MEM_RAM) { + AlignedEnd -=3D SIZE_4KB; + } + MemoryMap.Base =3D AlignedStart; + MemoryMap.Size =3D AlignedEnd - AlignedStart; + MemoryMap.Type =3D type; + MemoryMap.Flag =3D 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 =3D GetUefiPayLoadConfig(); + + DEBUG((DEBUG_INFO, "MemoryMap #entries: %d\n", Config->NumMemoryMapEntri= es)); + + entry =3D &Config->MemoryMapEntries[0]; + for (Index =3D 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 =3D GetUefiPayLoadConfig(); + SystemTableInfo->AcpiTableBase =3D Config->AcpiBase; + SystemTableInfo->AcpiTableSize =3D Config->AcpiSize; + + SystemTableInfo->SmbiosTableBase =3D Config->SmbiosBase; + SystemTableInfo->SmbiosTableSize =3D 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 =3D GetUefiPayLoadConfig(); + + SerialPortInfo->BaseAddr =3D Config->SerialConfig.BaseAddr; + SerialPortInfo->RegWidth =3D Config->SerialConfig.RegWidth; + SerialPortInfo->Type =3D Config->SerialConfig.Type; + SerialPortInfo->Baud =3D Config->SerialConfig.Baud; + SerialPortInfo->InputHertz =3D Config->SerialConfig.InputHertz; + SerialPortInfo->UartPciAddr =3D Config->SerialConfig.UartPciAddr; + + return RETURN_SUCCESS; +} + +/** + Find the video frame buffer information + + @param GfxInfo Pointer to the EFI_PEI_GRAPHICS_INFO_HOB str= ucture + + @retval RETURN_SUCCESS Successfully find the video frame buffer +information. + @retval RETURN_NOT_FOUND Failed to find the video frame buffer informa= tion . + +**/ +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_H= OB +structure + + @retval RETURN_SUCCESS Successfully find the video frame buffer +information. + @retval RETURN_NOT_FOUND Failed to find the video frame buffer informa= tion. + +**/ +RETURN_STATUS +EFIAPI +ParseGfxDeviceInfo ( + OUT EFI_PEI_GRAPHICS_DEVICE_INFO_HOB* GfxDeviceInfo + ) { + return RETURN_NOT_FOUND; +} diff --git a/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c= b/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c index b0268f05069c..a4f714f765ea 100644 --- a/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c +++ b/UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c @@ -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 @@ -80,7 +81,7 @@ AdjustRootBridgeResource ( PMemAbove4G->Base =3D MAX_UINT64; PMemAbove4G->Limit =3D 0; } - +#ifndef LINUXBOOT_PAYLOAD // // Align IO resource at 4K boundary // @@ -98,6 +99,7 @@ AdjustRootBridgeResource ( if (Mem->Base !=3D MAX_UINT64) { Mem->Base &=3D ~Mask; } +#endif } =20 /** --=20 2.33.0.rc2.250.ged5fa647cd-goog -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#79722): https://edk2.groups.io/g/devel/message/79722 Mute This Topic: https://groups.io/mt/85086924/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-