Skip to content

Commit

Permalink
UefiPayloadPkg: Add AARCH64 support
Browse files Browse the repository at this point in the history
Add basic support for FIT image on the AARCH64 architecture, reuse
exsitting DSC and FDF files for IA32, X64 and AARCH64 architectures.

Introduce new PCD: PcdUseUniversalPayloadSerialPort to indicate
which serial port module is used due to some serial port parameters
are fixed for ARM SoC and Platform.

Please use following command to build AARCH64 UPL FIT image:
"
 export GCC5_AARCH64_PREFIX=aarch64-linux-gnu-
 python UefiPayloadPkg/UniversalPayloadBuild.py -a AARCH64
        -t GCC5 -b DEBUG --Fit
"

Signed-off-by: Amos Bu <[email protected]>
Signed-off-by: Ajan Zhong <[email protected]>
  • Loading branch information
amosbu authored and AjanZhong committed Dec 22, 2024
1 parent 896930e commit 15d6e39
Show file tree
Hide file tree
Showing 14 changed files with 716 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
[Guids]
gUefiAcpiBoardInfoGuid
gUplPciSegmentInfoHobGuid
gUniversalPayloadPciRootBridgeInfoGuid

[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration
4 changes: 4 additions & 0 deletions UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ PlatformHookSerialPortInitialize (
return Status;
}

#if FixedPcdGetBool (PcdUseUniversalPayloadSerialPort) == 1

Status = PcdSet32S (PcdSerialBaudRate, SerialPortInfo->BaudRate);
if (RETURN_ERROR (Status)) {
return Status;
}

#endif

return RETURN_SUCCESS;
}

Expand Down
69 changes: 69 additions & 0 deletions UefiPayloadPkg/UefiPayloadEntry/AArch64/DxeHandoff.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/** @file
Generic version of arch-specific functionality for DxeLoad.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
Copyright 2024 Google LLC
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <PiPei.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/HobLib.h>

#include "UefiPayloadEntry.h"

#define STACK_SIZE 0x20000

/**
Transfers control to DxeCore.
This function performs a CPU architecture specific operations to execute
the entry point of DxeCore with the parameters of HobList.
It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase.
@param DxeCoreEntryPoint The entry point of DxeCore.
@param HobList The start of HobList passed to DxeCore.
**/
VOID
HandOffToDxeCore (
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
IN EFI_PEI_HOB_POINTERS HobList
)
{
VOID *BaseOfStack;
VOID *TopOfStack;

//
// Allocate 128KB for the Stack
//
BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));
ASSERT (BaseOfStack != NULL);

//
// Compute the top of the stack we were allocated. Pre-allocate a UINTN
// for safety.
//
TopOfStack = (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);

//
// Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
//
UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);

//
// Transfer the control to the entry point of DxeCore.
//
SwitchStack (
(SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
HobList.Raw,
NULL,
TopOfStack
);
}
26 changes: 26 additions & 0 deletions UefiPayloadPkg/UefiPayloadEntry/AArch64/DxeLoadFuncFit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @file
aarch64-specifc functionality for Module Entry Point.
Copyright 2024 Google LLC
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include "UefiPayloadEntry.h"

/**
Entry point to the C language phase of UEFI payload.
@param[in] FdtBaseAddr Pointer to the FDT
@param[in] AdditionalPara Not used yet
@retval It will not return if SUCCESS, and return error
when passing bootloader parameter.
**/
EFI_STATUS
EFIAPI
_ModuleEntryPoint (
IN UINTN FdtBaseAddr,
IN UINTN AddtionalPara
)
{
return FitUplEntryPoint (FdtBaseAddr);
}
17 changes: 17 additions & 0 deletions UefiPayloadPkg/UefiPayloadEntry/AArch64/StubLib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @file
Null instance of CPU related Library for AArch64 specific services.
Copyright 2024 Google LLC
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include "UefiPayloadEntry.h"

VOID
EFIAPI
InitializeFloatingPointUnits (
VOID
)
{
}
9 changes: 7 additions & 2 deletions UefiPayloadPkg/UefiPayloadEntry/FitUniversalPayloadEntry.inf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# This is the first module for UEFI payload.
#
# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
# Copyright 2024 Google LLC
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
Expand All @@ -17,7 +18,7 @@
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
# VALID_ARCHITECTURES = IA32 X64 AARCH64
#

[Sources]
Expand All @@ -42,6 +43,10 @@
RiscV64/DxeLoadFunc.c
RiscV64/DxeLoadFuncFit.c

[Sources.AARCH64]
AArch64/DxeHandoff.c
AArch64/DxeLoadFuncFit.c

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
Expand Down Expand Up @@ -86,7 +91,7 @@
[FeaturePcd.X64]
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplBuildPageTables ## CONSUMES

[Pcd.IA32,Pcd.X64,Pcd.RISCV64]
[Pcd.IA32,Pcd.X64,Pcd.RISCV64,Pcd.AARCH64]
gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile
gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ## CONSUMES
Expand Down
2 changes: 2 additions & 0 deletions UefiPayloadPkg/UefiPayloadEntry/PrintHob.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ PrintMemoryTypeInfoGuidHob (
//
GUID_HOB_PRINT_HANDLE GuidHobPrintHandleTable[] = {
{ &gUniversalPayloadAcpiTableGuid, PrintAcpiGuidHob, "gUniversalPayloadAcpiTableGuid(ACPI table Guid)" },
#if FixedPcdGetBool (PcdUseUniversalPayloadSerialPort) == 1
{ &gUniversalPayloadSerialPortInfoGuid, PrintSerialGuidHob, "gUniversalPayloadSerialPortInfoGuid(Serial Port Info)" },
#endif
{ &gUniversalPayloadSmbios3TableGuid, PrintSmbios3GuidHob, "gUniversalPayloadSmbios3TableGuid(SmBios Guid)" },
{ &gUniversalPayloadSmbiosTableGuid, PrintSmbiosTablGuidHob, "gUniversalPayloadSmbiosTableGuid(SmBios Guid)" },
{ &gUefiAcpiBoardInfoGuid, PrintAcpiBoardInfoGuidHob, "gUefiAcpiBoardInfoGuid(Acpi Guid)" },
Expand Down
6 changes: 6 additions & 0 deletions UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,10 @@ UplEntryPoint (
IN UINTN BootloaderParameter
);

VOID
EFIAPI
InitializeFloatingPointUnits (
VOID
);

#endif
9 changes: 7 additions & 2 deletions UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
# VALID_ARCHITECTURES = IA32 X64 AARCH64
#

[Sources]
Expand All @@ -38,6 +38,11 @@
X64/VirtualMemory.c
X64/DxeLoadFunc.c

[Sources.AARCH64]
AArch64/DxeHandoff.c
AArch64/DxeLoadFuncFit.c
AArch64/StubLib.c

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
Expand Down Expand Up @@ -73,7 +78,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplBuildPageTables ## CONSUMES


[Pcd.IA32,Pcd.X64]
[Pcd.IA32,Pcd.X64,Pcd.AARCH64]
gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ## CONSUMES
Expand Down
8 changes: 6 additions & 2 deletions UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
# VALID_ARCHITECTURES = IA32 X64 AARCH64
#
[Sources]
UniversalPayloadEntry.c
Expand All @@ -32,6 +32,10 @@
X64/VirtualMemory.h
X64/VirtualMemory.c
X64/DxeLoadFunc.c
[Sources.AARCH64]
AArch64/DxeHandoff.c
AArch64/DxeLoadFuncFit.c
AArch64/StubLib.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
Expand Down Expand Up @@ -67,7 +71,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ## CONSUMES
[FeaturePcd.X64]
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplBuildPageTables ## CONSUMES
[Pcd.IA32,Pcd.X64]
[Pcd.IA32,Pcd.X64,Pcd.AARCH64]
gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile
gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ## CONSUMES
Expand Down
5 changes: 5 additions & 0 deletions UefiPayloadPkg/UefiPayloadPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,8 @@ gUefiPayloadPkgTokenSpaceGuid.PcdPciReservedPMemAbove4GBLimit|0x0000000000000000

gUefiPayloadPkgTokenSpaceGuid.SizeOfIoSpace|0|UINT8|0x0000002B
gUefiPayloadPkgTokenSpaceGuid.PcdFDTPageSize|8|UINT8|0x0000002C

## Indicates if Universal Payload Serial Port feature is used
#- PcdUseUniversalPayloadSerialPort is TRUE, Serial Port parameters will be updated
#- PcdUseUniversalPayloadSerialPort is FALSE, Serial Port parameters are fixed
gUefiPayloadPkgTokenSpaceGuid.PcdUseUniversalPayloadSerialPort|TRUE|BOOLEAN|0x0000002D
Loading

0 comments on commit 15d6e39

Please sign in to comment.