2008-04-18 05:09:54 +02:00
|
|
|
/*++
|
|
|
|
|
2011-06-23 10:31:18 +02:00
|
|
|
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
2010-04-28 14:39:50 +02:00
|
|
|
This program and the accompanying materials
|
2008-04-18 05:09:54 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
Module Name:
|
|
|
|
EfiLoader.c
|
|
|
|
|
|
|
|
Abstract:
|
|
|
|
|
|
|
|
Revision History:
|
|
|
|
|
|
|
|
--*/
|
|
|
|
|
|
|
|
#include "EfiLdr.h"
|
|
|
|
#include "Support.h"
|
|
|
|
#include "Debug.h"
|
|
|
|
#include "PeLoader.h"
|
2009-05-06 05:44:47 +02:00
|
|
|
#include "LzmaDecompress.h"
|
2008-04-25 11:30:24 +02:00
|
|
|
|
|
|
|
VOID
|
2011-06-23 10:31:18 +02:00
|
|
|
SystemHang (
|
|
|
|
CHAR8 *Message
|
2008-04-25 11:30:24 +02:00
|
|
|
)
|
|
|
|
{
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString (
|
|
|
|
"%s## FATAL ERROR ##: Fail to load DUET images! System hang!\n",
|
|
|
|
Message
|
|
|
|
);
|
2008-04-25 11:30:24 +02:00
|
|
|
CpuDeadLoop();
|
|
|
|
}
|
2008-04-18 05:09:54 +02:00
|
|
|
|
|
|
|
VOID
|
|
|
|
EfiLoader (
|
|
|
|
UINT32 BiosMemoryMapBaseAddress
|
|
|
|
)
|
|
|
|
{
|
|
|
|
BIOS_MEMORY_MAP *BiosMemoryMap;
|
|
|
|
EFILDR_IMAGE *EFILDRImage;
|
|
|
|
EFI_MEMORY_DESCRIPTOR EfiMemoryDescriptor[EFI_MAX_MEMORY_DESCRIPTORS];
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN NumberOfMemoryMapEntries;
|
|
|
|
UINT32 DestinationSize;
|
|
|
|
UINT32 ScratchSize;
|
|
|
|
UINTN BfvPageNumber;
|
|
|
|
UINTN BfvBase;
|
|
|
|
EFI_MAIN_ENTRYPOINT EfiMainEntrypoint;
|
2010-10-16 20:51:21 +02:00
|
|
|
EFILDRHANDOFF Handoff;
|
2011-06-23 10:31:18 +02:00
|
|
|
UINTN Index;
|
2008-04-18 05:09:54 +02:00
|
|
|
|
|
|
|
ClearScreen();
|
2008-04-25 11:30:24 +02:00
|
|
|
|
|
|
|
PrintHeader ('A');
|
2011-06-23 10:31:18 +02:00
|
|
|
|
|
|
|
PrintString ("Enter DUET Loader...\n");
|
|
|
|
PrintString ("BiosMemoryMapBaseAddress = %x\n", (UINTN) BiosMemoryMapBaseAddress);
|
2008-04-18 05:09:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Add all EfiConventionalMemory descriptors to the table. If there are partial pages, then
|
|
|
|
// round the start address up to the next page, and round the length down to a page boundry.
|
|
|
|
//
|
2011-06-23 10:31:18 +02:00
|
|
|
BiosMemoryMap = (BIOS_MEMORY_MAP *) (UINTN) BiosMemoryMapBaseAddress;
|
2008-04-18 05:09:54 +02:00
|
|
|
NumberOfMemoryMapEntries = 0;
|
|
|
|
GenMemoryMap (&NumberOfMemoryMapEntries, EfiMemoryDescriptor, BiosMemoryMap);
|
|
|
|
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString ("Get %d entries of memory map!\n", NumberOfMemoryMapEntries);
|
2008-04-25 11:30:24 +02:00
|
|
|
|
2008-04-18 05:09:54 +02:00
|
|
|
//
|
|
|
|
// Get information on where the image is in memory
|
|
|
|
//
|
|
|
|
EFILDRImage = (EFILDR_IMAGE *)(UINTN)(EFILDR_HEADER_ADDRESS + sizeof(EFILDR_HEADER));
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Point to the 4th image (Bfv)
|
|
|
|
//
|
|
|
|
EFILDRImage += 3;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Decompress the image
|
|
|
|
//
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString (
|
|
|
|
"Decompress BFV image, Image Address = %x Offset = %x\n",
|
|
|
|
(UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
|
|
|
|
(UINTN) EFILDRImage->Offset
|
|
|
|
);
|
2009-05-06 05:44:47 +02:00
|
|
|
Status = LzmaUefiDecompressGetInfo (
|
2008-04-18 05:09:54 +02:00
|
|
|
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
|
|
|
|
EFILDRImage->Length,
|
|
|
|
&DestinationSize,
|
|
|
|
&ScratchSize
|
|
|
|
);
|
2008-04-25 11:30:24 +02:00
|
|
|
|
2008-04-18 05:09:54 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
2011-06-23 10:31:18 +02:00
|
|
|
SystemHang ("Failed to get decompress information for BFV!\n");
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
2009-01-13 08:41:23 +01:00
|
|
|
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString ("BFV decompress: DestinationSize = %x, ScratchSize = %x\n", (UINTN) DestinationSize, (UINTN) ScratchSize);
|
2009-05-06 05:44:47 +02:00
|
|
|
Status = LzmaUefiDecompress (
|
|
|
|
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
|
2010-01-15 13:39:20 +01:00
|
|
|
EFILDRImage->Length,
|
2009-05-06 05:44:47 +02:00
|
|
|
(VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,
|
|
|
|
(VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)
|
|
|
|
);
|
2009-01-13 08:41:23 +01:00
|
|
|
|
2008-04-25 11:30:24 +02:00
|
|
|
|
2008-04-18 05:09:54 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
2011-06-23 10:31:18 +02:00
|
|
|
SystemHang ("Failed to decompress BFV!\n");
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BfvPageNumber = EFI_SIZE_TO_PAGES (DestinationSize);
|
|
|
|
BfvBase = (UINTN) FindSpace (BfvPageNumber, &NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesData, EFI_MEMORY_WB);
|
|
|
|
if (BfvBase == 0) {
|
2011-06-23 10:31:18 +02:00
|
|
|
SystemHang ("Failed to find free space to hold decompressed BFV\n");
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
|
|
|
ZeroMem ((VOID *)(UINTN)BfvBase, BfvPageNumber * EFI_PAGE_SIZE);
|
|
|
|
CopyMem ((VOID *)(UINTN)BfvBase, (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS, DestinationSize);
|
|
|
|
|
2008-04-25 11:30:24 +02:00
|
|
|
PrintHeader ('B');
|
2008-04-18 05:09:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Point to the 2nd image (DxeIpl)
|
|
|
|
//
|
|
|
|
|
|
|
|
EFILDRImage -= 2;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Decompress the image
|
|
|
|
//
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString (
|
|
|
|
"Decompress DxeIpl image, Image Address = %x Offset = %x\n",
|
|
|
|
(UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
|
|
|
|
(UINTN) EFILDRImage->Offset
|
|
|
|
);
|
2008-04-18 05:09:54 +02:00
|
|
|
|
2009-05-06 05:44:47 +02:00
|
|
|
Status = LzmaUefiDecompressGetInfo (
|
2008-04-18 05:09:54 +02:00
|
|
|
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
|
|
|
|
EFILDRImage->Length,
|
|
|
|
&DestinationSize,
|
|
|
|
&ScratchSize
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2011-06-23 10:31:18 +02:00
|
|
|
SystemHang ("Failed to get decompress information for DxeIpl!\n");
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
|
|
|
|
2009-05-06 05:44:47 +02:00
|
|
|
Status = LzmaUefiDecompress (
|
2008-04-18 05:09:54 +02:00
|
|
|
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
|
2010-01-15 13:39:20 +01:00
|
|
|
EFILDRImage->Length,
|
2008-04-18 05:09:54 +02:00
|
|
|
(VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,
|
2009-05-06 05:44:47 +02:00
|
|
|
(VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)
|
2008-04-18 05:09:54 +02:00
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2011-06-23 10:31:18 +02:00
|
|
|
SystemHang ("Failed to decompress DxeIpl image\n");
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
|
|
|
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString ("Start load DxeIpl PE image\n");
|
2008-04-25 11:30:24 +02:00
|
|
|
|
2008-04-18 05:09:54 +02:00
|
|
|
//
|
|
|
|
// Load and relocate the EFI PE/COFF Firmware Image
|
|
|
|
//
|
|
|
|
Status = EfiLdrPeCoffLoadPeImage (
|
|
|
|
(VOID *)(UINTN)(EFI_DECOMPRESSED_BUFFER_ADDRESS),
|
|
|
|
&DxeIplImage,
|
|
|
|
&NumberOfMemoryMapEntries,
|
|
|
|
EfiMemoryDescriptor
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2011-06-23 10:31:18 +02:00
|
|
|
SystemHang ("Failed to load and relocate DxeIpl PE image!\n");
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString (
|
|
|
|
"DxeIpl PE image is successed loaded at %lx, entry=%p\n",
|
|
|
|
DxeIplImage.ImageBasePage,
|
|
|
|
DxeIplImage.EntryPoint
|
|
|
|
);
|
2008-04-18 05:09:54 +02:00
|
|
|
|
|
|
|
PrintHeader ('C');
|
|
|
|
|
|
|
|
//
|
|
|
|
// Point to the 3rd image (DxeMain)
|
|
|
|
//
|
|
|
|
EFILDRImage++;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Decompress the image
|
|
|
|
//
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString (
|
|
|
|
"Decompress DxeMain FV image, Image Address = %x Offset = %x\n",
|
|
|
|
(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
|
|
|
|
(UINTN) EFILDRImage->Offset
|
|
|
|
);
|
2008-04-18 05:09:54 +02:00
|
|
|
|
2009-05-06 05:44:47 +02:00
|
|
|
Status = LzmaUefiDecompressGetInfo (
|
2008-04-18 05:09:54 +02:00
|
|
|
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
|
|
|
|
EFILDRImage->Length,
|
|
|
|
&DestinationSize,
|
|
|
|
&ScratchSize
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2011-06-23 10:31:18 +02:00
|
|
|
SystemHang ("Failed to get decompress information for DxeMain FV image!\n");
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
|
|
|
|
2009-05-06 05:44:47 +02:00
|
|
|
Status = LzmaUefiDecompress (
|
2008-04-18 05:09:54 +02:00
|
|
|
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
|
2010-01-15 13:39:20 +01:00
|
|
|
EFILDRImage->Length,
|
2008-04-18 05:09:54 +02:00
|
|
|
(VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,
|
2009-05-06 05:44:47 +02:00
|
|
|
(VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)
|
2008-04-18 05:09:54 +02:00
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2011-06-23 10:31:18 +02:00
|
|
|
SystemHang ("Failed to decompress DxeMain FV image!\n");
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Load and relocate the EFI PE/COFF Firmware Image
|
|
|
|
//
|
|
|
|
Status = EfiLdrPeCoffLoadPeImage (
|
|
|
|
(VOID *)(UINTN)(EFI_DECOMPRESSED_BUFFER_ADDRESS),
|
|
|
|
&DxeCoreImage,
|
|
|
|
&NumberOfMemoryMapEntries,
|
|
|
|
EfiMemoryDescriptor
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2011-06-23 10:31:18 +02:00
|
|
|
SystemHang ("Failed to load/relocate DxeMain!\n");
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString (
|
|
|
|
"DxeCore PE image is successed loaded at %lx, entry=%p\n",
|
|
|
|
DxeCoreImage.ImageBasePage,
|
|
|
|
DxeCoreImage.EntryPoint
|
|
|
|
);
|
2008-04-18 05:09:54 +02:00
|
|
|
|
|
|
|
PrintHeader ('E');
|
|
|
|
|
|
|
|
//
|
|
|
|
// Display the table of memory descriptors.
|
|
|
|
//
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString ("\nEFI Memory Descriptors\n");
|
2008-04-18 05:09:54 +02:00
|
|
|
for (Index = 0; Index < NumberOfMemoryMapEntries; Index++) {
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString (
|
|
|
|
"Type = %x Start = %08lx NumberOfPages = %08lx\n",
|
|
|
|
EfiMemoryDescriptor[Index].Type, EfiMemoryDescriptor[Index].PhysicalStart, EfiMemoryDescriptor[Index].NumberOfPages
|
|
|
|
);
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Jump to EFI Firmware
|
|
|
|
//
|
|
|
|
|
|
|
|
if (DxeIplImage.EntryPoint != NULL) {
|
|
|
|
|
|
|
|
Handoff.MemDescCount = NumberOfMemoryMapEntries;
|
|
|
|
Handoff.MemDesc = EfiMemoryDescriptor;
|
|
|
|
Handoff.BfvBase = (VOID *)(UINTN)BfvBase;
|
|
|
|
Handoff.BfvSize = BfvPageNumber * EFI_PAGE_SIZE;
|
|
|
|
Handoff.DxeIplImageBase = (VOID *)(UINTN)DxeIplImage.ImageBasePage;
|
|
|
|
Handoff.DxeIplImageSize = DxeIplImage.NoPages * EFI_PAGE_SIZE;
|
|
|
|
Handoff.DxeCoreImageBase = (VOID *)(UINTN)DxeCoreImage.ImageBasePage;
|
|
|
|
Handoff.DxeCoreImageSize = DxeCoreImage.NoPages * EFI_PAGE_SIZE;
|
|
|
|
Handoff.DxeCoreEntryPoint = (VOID *)(UINTN)DxeCoreImage.EntryPoint;
|
|
|
|
|
2011-06-23 10:31:18 +02:00
|
|
|
PrintString ("Transfer to DxeIpl ...EntryPoint = %p\n", DxeIplImage.EntryPoint);
|
2008-04-28 07:23:22 +02:00
|
|
|
|
2011-06-23 10:31:18 +02:00
|
|
|
EfiMainEntrypoint = (EFI_MAIN_ENTRYPOINT) DxeIplImage.EntryPoint;
|
2008-04-18 05:09:54 +02:00
|
|
|
EfiMainEntrypoint (&Handoff);
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintHeader ('F');
|
|
|
|
|
|
|
|
//
|
|
|
|
// There was a problem loading the image, so HALT the system.
|
|
|
|
//
|
|
|
|
|
2011-06-23 10:31:18 +02:00
|
|
|
SystemHang ("Failed to jump to DxeIpl!\n");
|
2008-04-18 05:09:54 +02:00
|
|
|
}
|
|
|
|
|
2008-05-08 04:23:39 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
_ModuleEntryPoint (
|
|
|
|
UINT32 BiosMemoryMapBaseAddress
|
|
|
|
)
|
|
|
|
{
|
2011-06-23 10:31:18 +02:00
|
|
|
SerialPortInitialize ();
|
2008-05-08 04:23:39 +02:00
|
|
|
EfiLoader(BiosMemoryMapBaseAddress);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|