24#define STACK_SIZE 0x20000
27 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
28 &gUplReadyToPayloadPpiGuid,
33 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
34 &gEfiEndOfPeiSignalPpiGuid,
38#if (FixedPcdGetBool (PcdHandOffFdtEnable) == 0)
68 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
69 &gEfiEndOfPeiSignalPpiGuid,
91 OUT UINT64 *ImageSizeArg OPTIONAL,
93 OUT UINT32 *AuthenticationState
106 #if (FixedPcdGetBool (PcdHandOffFdtEnable))
118 if (EFI_ERROR (Status)) {
122 ZeroMem (&Context,
sizeof (Context));
124 }
while (EFI_ERROR (Status));
126 if (EFI_ERROR (Status)) {
134 "Before Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 0x%08x\n",
135 Context.PayloadBaseAddress,
137 Context.PayloadEntryPoint
143 CopyMem ((VOID *)Context.PayloadBaseAddress, Binary, Context.PayloadSize);
145 if (Context.PayloadBaseAddress > Context.PayloadLoadAddress) {
146 Delta = Context.PayloadBaseAddress - Context.PayloadLoadAddress;
147 Context.PayloadEntryPoint += Delta;
148 for (Index = 0; Index < Context.RelocateTableCount; Index++) {
149 if ((RelocateTable[Index].RelocateType == 10) || (RelocateTable[Index].RelocateType == 3)) {
150 *((UINT64 *)(Context.PayloadBaseAddress + RelocateTable[Index].Offset)) = *((UINT64 *)(Context.PayloadBaseAddress + RelocateTable[Index].Offset)) + Delta;
154 Delta = Context.PayloadLoadAddress - Context.PayloadBaseAddress;
155 Context.PayloadEntryPoint -= Delta;
156 for (Index = 0; Index < Context.RelocateTableCount; Index++) {
157 if ((RelocateTable[Index].RelocateType == 10) || (RelocateTable[Index].RelocateType == 3)) {
158 *((UINT64 *)(Context.PayloadBaseAddress + RelocateTable[Index].Offset)) = *((UINT64 *)(Context.PayloadBaseAddress + RelocateTable[Index].Offset)) - Delta;
166 "After Rebase Payload File Base: 0x%08x, File Size: 0x%08X, EntryPoint: 0x%08x\n",
167 Context.PayloadBaseAddress,
169 Context.PayloadEntryPoint
175 &gUniversalPayloadBaseGuid,
180 *ImageAddressArg = Context.PayloadBaseAddress;
181 *ImageSizeArg = Context.PayloadSize;
182 *EntryPoint = Context.PayloadEntryPoint;
201 ASSERT (BaseOfStack !=
NULL);
215 (VOID *)(Fdt->DeviceTreeAddress),
232 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
233 &gEfiPeiLoadFilePpiGuid,
237#if (FixedPcdGetBool (PcdHandOffFdtEnable))
249FdtPpiNotifyCallback (
257 (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
258 &gUplReadyToPayloadPpiGuid,
279 DEBUG ((DEBUG_ERROR,
"FDT DTB data:"));
282 DEBUG ((DEBUG_ERROR,
"\n"));
285 DEBUG ((DEBUG_ERROR,
"%02x ", *Fdt));
288 DEBUG ((DEBUG_ERROR,
"\n"));
302#if (FixedPcdGetBool (PcdHandOffFdtEnable))
314FdtPpiNotifyCallback (
328 FdtSize =
PcdGet8 (PcdFDTPageSize) * EFI_PAGE_SIZE;
331 if (FdtBase ==
NULL) {
332 DEBUG ((DEBUG_ERROR,
"%a: AllocatePages failed\n", __func__));
333 return EFI_NOT_FOUND;
337 if (EFI_ERROR (Status)) {
338 DEBUG ((DEBUG_ERROR,
"%a: cannot create FDT\n", __func__));
343 Status =
FdtSetProperty (FdtBase, 0,
"#address-cells", &Data32,
sizeof (UINT32));
344 Status =
FdtSetProperty (FdtBase, 0,
"#size-cells", &Data32,
sizeof (UINT32));
353 DEBUG ((DEBUG_ERROR,
"%a: Build FDT Hob failed\n", __func__));
354 return EFI_NOT_FOUND;
359 "%a: fdt at 0x%x (size %d)\n",
365 Fdt->Header.Revision = UNIVERSAL_PAYLOAD_DEVICE_TREE_REVISION;
367 Fdt->DeviceTreeAddress = (UINT64)FdtBase;
392 #if (FixedPcdGetBool (PcdHandOffFdtEnable))
#define CPU_STACK_ALIGNMENT
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
VOID *EFIAPI BuildGuidHob(IN CONST EFI_GUID *Guid, IN UINTN DataLength)
VOID EFIAPI SwitchStack(IN SWITCH_STACK_ENTRY_POINT EntryPoint, IN VOID *Context1 OPTIONAL, IN VOID *Context2 OPTIONAL, IN VOID *NewStack,...)
VOID(EFIAPI * SWITCH_STACK_ENTRY_POINT)(IN VOID *Context1 OPTIONAL, IN VOID *Context2 OPTIONAL)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI PeiServicesNotifyPpi(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
INT32 EFIAPI FdtSetProperty(IN VOID *Fdt, IN INT32 NodeOffset, IN CONST CHAR8 *Name, IN CONST VOID *Value, IN UINT32 Length)
UINT32 EFIAPI CpuToFdt32(IN UINT32 Value)
UINT32 EFIAPI Fdt32ToCpu(IN UINT32 Value)
INT32 EFIAPI FdtCreateEmptyTree(IN VOID *Buffer, IN UINT32 BufferSize)
EFI_STATUS EFIAPI ParseFitImage(IN VOID *ImageBase, OUT FIT_IMAGE_CONTEXT *Context)
EFI_STATUS EFIAPI PeiLoadFileLoadPayload(IN CONST EFI_PEI_LOAD_FILE_PPI *This, IN EFI_PEI_FILE_HANDLE FileHandle, OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg OPTIONAL, OUT UINT64 *ImageSizeArg OPTIONAL, OUT EFI_PHYSICAL_ADDRESS *EntryPoint, OUT UINT32 *AuthenticationState)
EFI_STATUS EFIAPI EndOfPeiPpiNotifyCallback(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
VOID PrintFdt(IN VOID *FdtBase)
EFI_STATUS EFIAPI InitializeFitPayloadLoaderPeim(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS BuildFdtForUPL(IN VOID *FdtBase)
#define ALIGN_POINTER(Pointer, Alignment)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define PcdGet8(TokenName)
#define FixedPcdGetBool(TokenName)
EFI_STATUS EFIAPI PeiServicesFfsFindSectionData3(IN EFI_SECTION_TYPE SectionType, IN UINTN SectionInstance, IN EFI_PEI_FILE_HANDLE FileHandle, OUT VOID **SectionData, OUT UINT32 *AuthenticationStatus)
VOID * EFI_PEI_FILE_HANDLE
VOID *EFIAPI AllocatePages(IN UINTN Pages)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_SIZE_TO_PAGES(Size)