public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Cheng-Chieh Huang <chengchieh@google.com>
To: devel@edk2.groups.io
Cc: Cheng-Chieh Huang <chengchieh@google.com>
Subject: [PATCH v1 1/6] UefiPayloadPkg: Add LINUXBOOT payload target
Date: Wed, 21 Jul 2021 13:23:23 +0000	[thread overview]
Message-ID: <20210721132328.1415485-2-chengchieh@google.com> (raw)
In-Reply-To: <20210721132328.1415485-1-chengchieh@google.com>

Initial commit to support linuxboot payload.

Signed-off-by: Cheng-Chieh Huang <chengchieh@google.com>
---
 UefiPayloadPkg/UefiPayloadPkg.dsc                              |  16 +-
 UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf               |  39 +++++
 UefiPayloadPkg/Include/Linuxboot.h                             |  47 ++++++
 UefiPayloadPkg/Library/LbParseLib/LbParseLib.c                 | 168 ++++++++++++++++++++
 UefiPayloadPkg/Library/PciHostBridgeLib/PciHostBridgeSupport.c |   6 +-
 CryptoPkg/Library/OpensslLib/openssl                           |   2 +-
 6 files changed, 270 insertions(+), 8 deletions(-)

diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.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 = SBL
 
@@ -93,6 +94,9 @@ [Defines]
 
 [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
@@ -222,11 +226,13 @@ [LibraryClasses]
 !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
diff --git a/UefiPayloadPkg/Library/LbParseLib/LbParseLib.inf b/UefiPayloadPkg/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.<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
diff --git a/UefiPayloadPkg/Include/Linuxboot.h b/UefiPayloadPkg/Include/Linuxboot.h
new file mode 100644
index 000000000000..34ca18069983
--- /dev/null
+++ b/UefiPayloadPkg/Include/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/UefiPayloadPkg/Library/LbParseLib/LbParseLib.c
new file mode 100644
index 000000000000..34bfb6a1073f
--- /dev/null
+++ b/UefiPayloadPkg/Library/LbParseLib/LbParseLib.c
@@ -0,0 +1,168 @@
+/** @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 =
+      (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;
+  int i;
+
+  config = GetUefiPayLoadConfig();
+
+  DEBUG((DEBUG_INFO, "MemoryMap #entries: %d\n", config->NumMemoryMapEntries));
+
+  MemoryMapEntry* entry = &config->MemoryMapEntries[0];
+  for (i = 0; i < config->NumMemoryMapEntries; i++) {
+    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;
+}
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  = MAX_UINT64;
     PMemAbove4G->Limit = 0;
   }
-
+#ifndef LINUXBOOT_PAYLOAD
   //
   // Align IO  resource at 4K  boundary
   //
@@ -98,6 +99,7 @@ AdjustRootBridgeResource (
   if (Mem->Base != MAX_UINT64) {
     Mem->Base &= ~Mask;
   }
+#endif
 }
 
 /**
diff --git a/CryptoPkg/Library/OpensslLib/openssl b/CryptoPkg/Library/OpensslLib/openssl
index 52c587d60be6..e2e09d9fba11 160000
--- a/CryptoPkg/Library/OpensslLib/openssl
+++ b/CryptoPkg/Library/OpensslLib/openssl
@@ -1 +1 @@
-Subproject commit 52c587d60be67c337364b830dd3fdc15404a2f04
+Subproject commit e2e09d9fba1187f8d6aafaa34d4172f56f1ffb72
-- 
2.32.0.402.g57bb445576-goog


  reply	other threads:[~2021-07-21 13:24 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-21 13:23 [PATCH 0/6] UefiPayloadPkg: LinuxBoot Support in UefiPayload Cheng-Chieh Huang
2021-07-21 13:23 ` Cheng-Chieh Huang [this message]
2021-08-04  2:41   ` [edk2-devel] [PATCH v1 1/6] UefiPayloadPkg: Add LINUXBOOT payload target Guo Dong
2021-07-21 13:23 ` [PATCH v1 2/6] UefiPayloadPkg: Use legacy timer in Linuxboot payload Cheng-Chieh Huang
2021-08-04  2:22   ` [edk2-devel] " Guo Dong
     [not found]   ` <1697F93BEFA774AB.32148@groups.io>
2021-08-04  2:52     ` Guo Dong
2021-07-21 13:23 ` [PATCH v1 3/6] UefiPayloadPkg: Update maximum logic processor to 256 Cheng-Chieh Huang
2021-08-04  2:22   ` [edk2-devel] " Guo Dong
     [not found]   ` <1697F92B243CA725.1963@groups.io>
2021-08-04  2:51     ` Guo Dong
2021-07-21 13:23 ` [PATCH v1 4/6] UefiPayloadPkg: Reserve Payload config in runtime services data Cheng-Chieh Huang
2021-08-04  2:44   ` [edk2-devel] " Guo Dong
2021-08-04  6:23     ` Cheng-Chieh Huang
2021-08-04 13:37       ` Guo Dong
2021-07-21 13:23 ` [PATCH v1 5/6] UefiPayloadPkg: Add DISABLE_MMX_SSE to avoid generating floating points operation Cheng-Chieh Huang
2021-07-21 16:34   ` [edk2-devel] " Michael D Kinney
2021-07-21 17:42     ` Cheng-Chieh Huang
2021-07-22  1:28       ` 回复: " gaoliming
2021-07-22  2:35         ` Cheng-Chieh Huang
2021-07-23 10:28           ` 回复: " gaoliming
2021-07-23 11:16             ` Cheng-Chieh Huang
2021-07-23 16:45               ` Michael D Kinney
2021-07-23 17:17                 ` Cheng-Chieh Huang
2021-07-23 18:38                   ` Michael D Kinney
2021-07-21 13:23 ` [PATCH v1 6/6] UefiPayloadPkg: LinuxBoot: use a text format for the configuration block Cheng-Chieh Huang
2021-07-21 17:09   ` [edk2-devel] " Marvin Häuser
2021-07-22 13:48     ` Cheng-Chieh Huang
2021-08-04  3:00   ` Guo Dong
2021-08-07 13:53     ` Cheng-Chieh Huang
2021-07-22  1:29 ` 回复: [edk2-devel] [PATCH 0/6] UefiPayloadPkg: LinuxBoot Support in UefiPayload gaoliming
2021-07-22  3:40   ` Cheng-Chieh Huang
2021-07-22  1:44 ` Ni, Ray
2021-07-22  1:58   ` Daniel Schaefer
2021-07-22  2:48     ` Cheng-Chieh Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210721132328.1415485-2-chengchieh@google.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox