summaryrefslogtreecommitdiff
path: root/DuetPkg/EfiLdr
diff options
context:
space:
mode:
authorniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-23 08:31:18 +0000
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-23 08:31:18 +0000
commitb68b78e66cc7acdce3fdd571a6db71a9731117b1 (patch)
tree3503126e864baece1017dfef12b1e823818b78aa /DuetPkg/EfiLdr
parentf6bd06633df2811cbc8ae8f3c96e047164c41849 (diff)
downloadedk2-platforms-b68b78e66cc7acdce3fdd571a6db71a9731117b1.tar.xz
Change DUET DxeIpl to use SerialPort instead of manipulating serial port directly.
Signed-off-by: niruiyu Reviewed-by: jyao1 git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11876 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'DuetPkg/EfiLdr')
-rw-r--r--DuetPkg/EfiLdr/Debug.c89
-rw-r--r--DuetPkg/EfiLdr/Debug.h13
-rw-r--r--DuetPkg/EfiLdr/EfiLdr.h3
-rw-r--r--DuetPkg/EfiLdr/EfiLdr.inf7
-rw-r--r--DuetPkg/EfiLdr/EfiLoader.c144
5 files changed, 79 insertions, 177 deletions
diff --git a/DuetPkg/EfiLdr/Debug.c b/DuetPkg/EfiLdr/Debug.c
index a4a067ca6e..f4cd7c15ed 100644
--- a/DuetPkg/EfiLdr/Debug.c
+++ b/DuetPkg/EfiLdr/Debug.c
@@ -1,6 +1,6 @@
/*++
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
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
@@ -19,11 +19,11 @@ Revision History:
--*/
#include "EfiLdr.h"
#include "Debug.h"
-#include <Library/SerialPortLib.h>
UINT8 *mCursor;
UINT8 mHeaderIndex = 10;
+
VOID
PrintHeader (
CHAR8 Char
@@ -48,82 +48,25 @@ ClearScreen (
mCursor = (UINT8 *)(UINTN)(0x000b8000 + 160);
}
-
-VOID
-PrintU32Base10 (
- UINT32 Value
- )
-{
- UINT32 Index;
- CHAR8 Char;
- CHAR8 String[11];
- UINTN StringPos;
- UINT32 B10Div;
-
- B10Div = 1000000000;
- for (Index = 0, StringPos = 0; Index < 10; Index++) {
- Char = (UINT8) (((Value / B10Div) % 10) + '0');
- if ((StringPos > 0) || (Char != '0')) {
- String[StringPos] = Char;
- StringPos++;
- }
- B10Div = B10Div / 10;
- }
-
- if (StringPos == 0) {
- String[0] = '0';
- StringPos++;
- }
-
- String[StringPos] = '\0';
-
- PrintString (String);
-}
-
-
-VOID
-PrintValue (
- UINT32 Value
- )
-{
- UINT32 Index;
- CHAR8 Char;
- CHAR8 String[9];
-
- for (Index = 0; Index < 8; Index++) {
- Char = (UINT8)(((Value >> ((7 - Index) * 4)) & 0x0f) + '0');
- if (Char > '9') {
- Char = (UINT8) (Char - '0' - 10 + 'A');
- }
- String[Index] = Char;
- }
-
- String[sizeof (String) - 1] = '\0';
-
- PrintString (String);
-}
-
-VOID
-PrintValue64 (
- UINT64 Value
- )
-{
- PrintValue ((UINT32) RShiftU64 (Value, 32));
- PrintValue ((UINT32) Value);
-}
-
VOID
PrintString (
- CHAR8 *String
+ IN CONST CHAR8 *FormatString,
+ ...
)
{
- UINT32 Index;
+ UINTN Index;
+ CHAR8 PrintBuffer[256];
+ VA_LIST Marker;
+
+ VA_START (Marker, FormatString);
+ AsciiVSPrint (PrintBuffer, sizeof (PrintBuffer), FormatString, Marker);
+ VA_END (Marker);
- for (Index = 0; String[Index] != 0; Index++) {
- if (String[Index] == '\n') {
- mCursor = (UINT8 *)(UINTN)(0xb8000 + (((((UINTN)mCursor - 0xb8000) + 160) / 160) * 160));
+ for (Index = 0; PrintBuffer[Index] != 0; Index++) {
+ if (PrintBuffer[Index] == '\n') {
+ mCursor = (UINT8 *) (UINTN) (0xb8000 + (((((UINTN)mCursor - 0xb8000) + 160) / 160) * 160));
} else {
- *mCursor = String[Index];
+ *mCursor = (UINT8) PrintBuffer[Index];
mCursor += 2;
}
}
@@ -131,6 +74,6 @@ PrintString (
//
// All information also output to serial port.
//
- SerialPortWrite ((UINT8*) String, Index);
+ SerialPortWrite (PrintBuffer, Index);
}
diff --git a/DuetPkg/EfiLdr/Debug.h b/DuetPkg/EfiLdr/Debug.h
index cd1d5d951c..f6aa7a2cf7 100644
--- a/DuetPkg/EfiLdr/Debug.h
+++ b/DuetPkg/EfiLdr/Debug.h
@@ -26,19 +26,10 @@ PrintHeader (
CHAR8 Char
);
-VOID
-PrintValue (
- UINT32 Value
- );
-
VOID
-PrintValue64 (
- UINT64 Value
- );
-
-VOID
PrintString (
- CHAR8 *String
+ IN CONST CHAR8 *FormatString,
+ ...
);
VOID
diff --git a/DuetPkg/EfiLdr/EfiLdr.h b/DuetPkg/EfiLdr/EfiLdr.h
index 9434a780fc..665f405855 100644
--- a/DuetPkg/EfiLdr/EfiLdr.h
+++ b/DuetPkg/EfiLdr/EfiLdr.h
@@ -1,6 +1,6 @@
/*++
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
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
@@ -29,6 +29,7 @@ Revision History:
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/PrintLib.h>
+#include <Library/SerialPortLib.h>
#define INT15_E820_AddressRangeMemory 1
#define INT15_E820_AddressRangeReserved 2
diff --git a/DuetPkg/EfiLdr/EfiLdr.inf b/DuetPkg/EfiLdr/EfiLdr.inf
index ea3977d888..b5a46db870 100644
--- a/DuetPkg/EfiLdr/EfiLdr.inf
+++ b/DuetPkg/EfiLdr/EfiLdr.inf
@@ -1,6 +1,6 @@
## @file
#
-# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# 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
@@ -20,7 +20,6 @@
INF_VERSION = 0x00010005
BASE_NAME = EfiLoader
FILE_GUID = A9620E5C-5FA1-40b7-8B21-50B632F88F38
- #MODULE_TYPE = USER_DEFINED
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
@@ -53,8 +52,4 @@
gTianoCustomDecompressGuid
[BuildOptions]
- MSFT:*_*_IA32_CC_FLAGS = /nologo /W4 /WX /Gy /c /D UNICODE /O1ib2 /FI$(DEST_DIR_DEBUG)/AutoGen.h /EHs-c- /GF /Gs8192 /Zi /Gm /D _CRT_SECURE_NO_WARNINGS /D _CRT_SECURE_NO_DEPRECATE
- MSFT:*_*_IA32_PP_FLAGS == /nologo /E /TC /FI$(DEST_DIR_DEBUG)/AutoGen.h
- MSFT:*_*_IA32_ASM_FLAGS == /nologo /W3 /WX /c /coff /Cx /Zd /W0 /Zi
- MSFT:*_*_IA32_ASMLINK_FLAGS == /link /nologo /tiny
MSFT:*_*_*_DLINK_FLAGS = /BASE:0x10000
diff --git a/DuetPkg/EfiLdr/EfiLoader.c b/DuetPkg/EfiLdr/EfiLoader.c
index f10db53552..6913027650 100644
--- a/DuetPkg/EfiLdr/EfiLoader.c
+++ b/DuetPkg/EfiLdr/EfiLoader.c
@@ -1,6 +1,6 @@
/*++
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
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
@@ -25,12 +25,14 @@ Revision History:
#include "LzmaDecompress.h"
VOID
-SystemHang(
- VOID
+SystemHang (
+ CHAR8 *Message
)
{
- CHAR8 PrintBuffer[256];
- AsciiSPrint (PrintBuffer, 256, "## FATEL ERROR ##: Fail to load DUET images! System hang!\n");
+ PrintString (
+ "%s## FATAL ERROR ##: Fail to load DUET images! System hang!\n",
+ Message
+ );
CpuDeadLoop();
}
@@ -49,52 +51,45 @@ EfiLoader (
UINTN BfvPageNumber;
UINTN BfvBase;
EFI_MAIN_ENTRYPOINT EfiMainEntrypoint;
- CHAR8 PrintBuffer[256];
EFILDRHANDOFF Handoff;
+ UINTN Index;
ClearScreen();
PrintHeader ('A');
-
- AsciiSPrint (PrintBuffer, 256, "Enter DUET Loader...\n");
- PrintString (PrintBuffer);
-
- AsciiSPrint (PrintBuffer, 256, "BiosMemoryMapBaseAddress = 0x%x\n", BiosMemoryMapBaseAddress);
- PrintString (PrintBuffer);
+
+ PrintString ("Enter DUET Loader...\n");
+ PrintString ("BiosMemoryMapBaseAddress = %x\n", (UINTN) BiosMemoryMapBaseAddress);
//
// 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.
//
- BiosMemoryMap = (BIOS_MEMORY_MAP *)(UINTN)(BiosMemoryMapBaseAddress);
+ BiosMemoryMap = (BIOS_MEMORY_MAP *) (UINTN) BiosMemoryMapBaseAddress;
NumberOfMemoryMapEntries = 0;
GenMemoryMap (&NumberOfMemoryMapEntries, EfiMemoryDescriptor, BiosMemoryMap);
- AsciiSPrint (PrintBuffer, 256, "Get %d entries of memory map!\n", NumberOfMemoryMapEntries);
- PrintString (PrintBuffer);
+ PrintString ("Get %d entries of memory map!\n", NumberOfMemoryMapEntries);
//
// Get information on where the image is in memory
//
-
- //EFILDRHeader = (EFILDR_HEADER *)(UINTN)(EFILDR_HEADER_ADDRESS);
EFILDRImage = (EFILDR_IMAGE *)(UINTN)(EFILDR_HEADER_ADDRESS + sizeof(EFILDR_HEADER));
//
// Point to the 4th image (Bfv)
//
-
EFILDRImage += 3;
//
// Decompress the image
//
-
- AsciiSPrint (PrintBuffer, 256, "Decompress BFV image, Image Address=0x%x Offset=0x%x\n",
- (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
- EFILDRImage->Offset);
- PrintString (PrintBuffer);
+ PrintString (
+ "Decompress BFV image, Image Address = %x Offset = %x\n",
+ (UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
+ (UINTN) EFILDRImage->Offset
+ );
Status = LzmaUefiDecompressGetInfo (
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
EFILDRImage->Length,
@@ -103,14 +98,10 @@ EfiLoader (
);
if (EFI_ERROR (Status)) {
- AsciiSPrint (PrintBuffer, 256, "Fail to get decompress information for BFV!\n");
- PrintString (PrintBuffer);
- SystemHang();
+ SystemHang ("Failed to get decompress information for BFV!\n");
}
- AsciiSPrint (PrintBuffer, 256, "BFV decompress: DestinationSize=0x%X, ScratchSize=0x%X!\n",
- DestinationSize, ScratchSize);
- PrintString (PrintBuffer);
+ PrintString ("BFV decompress: DestinationSize = %x, ScratchSize = %x\n", (UINTN) DestinationSize, (UINTN) ScratchSize);
Status = LzmaUefiDecompress (
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
EFILDRImage->Length,
@@ -120,15 +111,13 @@ EfiLoader (
if (EFI_ERROR (Status)) {
- AsciiSPrint (PrintBuffer, 256, "Fail to decompress BFV!\n");
- PrintString (PrintBuffer);
- SystemHang();
+ SystemHang ("Failed to decompress BFV!\n");
}
BfvPageNumber = EFI_SIZE_TO_PAGES (DestinationSize);
BfvBase = (UINTN) FindSpace (BfvPageNumber, &NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesData, EFI_MEMORY_WB);
if (BfvBase == 0) {
- SystemHang();
+ SystemHang ("Failed to find free space to hold decompressed BFV\n");
}
ZeroMem ((VOID *)(UINTN)BfvBase, BfvPageNumber * EFI_PAGE_SIZE);
CopyMem ((VOID *)(UINTN)BfvBase, (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS, DestinationSize);
@@ -144,10 +133,11 @@ EfiLoader (
//
// Decompress the image
//
- AsciiSPrint (PrintBuffer, 256, "Decompress DxeIpl image, Image Address=0x%x Offset=0x%x\n",
- (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
- EFILDRImage->Offset);
- PrintString (PrintBuffer);
+ PrintString (
+ "Decompress DxeIpl image, Image Address = %x Offset = %x\n",
+ (UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
+ (UINTN) EFILDRImage->Offset
+ );
Status = LzmaUefiDecompressGetInfo (
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
@@ -156,9 +146,7 @@ EfiLoader (
&ScratchSize
);
if (EFI_ERROR (Status)) {
- AsciiSPrint (PrintBuffer, 256, "Fail to get decompress information for DxeIpl!\n");
- PrintString (PrintBuffer);
- SystemHang();
+ SystemHang ("Failed to get decompress information for DxeIpl!\n");
}
Status = LzmaUefiDecompress (
@@ -168,13 +156,10 @@ EfiLoader (
(VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)
);
if (EFI_ERROR (Status)) {
- AsciiSPrint (PrintBuffer, 256, "Fail to decompress DxeIpl image\n");
- PrintString (PrintBuffer);
- SystemHang();
+ SystemHang ("Failed to decompress DxeIpl image\n");
}
- AsciiSPrint (PrintBuffer, 256, "Start load DxeIpl PE image\n");
- PrintString (PrintBuffer);
+ PrintString ("Start load DxeIpl PE image\n");
//
// Load and relocate the EFI PE/COFF Firmware Image
@@ -186,33 +171,29 @@ EfiLoader (
EfiMemoryDescriptor
);
if (EFI_ERROR (Status)) {
- AsciiSPrint (PrintBuffer, 256, "Fail to load and relocate DxeIpl PE image!\n");
- PrintString (PrintBuffer);
- SystemHang();
+ SystemHang ("Failed to load and relocate DxeIpl PE image!\n");
}
- AsciiSPrint (PrintBuffer, 256, "DxeIpl PE image is successed loaded at 0x%x, entry=0x%x\n",
- (UINTN)DxeIplImage.ImageBasePage, (UINTN)DxeIplImage.EntryPoint);
- PrintString (PrintBuffer);
-
-// PrintString("Image.NoPages = ");
-// PrintValue(Image.NoPages);
-// PrintString("\n");
+ PrintString (
+ "DxeIpl PE image is successed loaded at %lx, entry=%p\n",
+ DxeIplImage.ImageBasePage,
+ DxeIplImage.EntryPoint
+ );
PrintHeader ('C');
//
// Point to the 3rd image (DxeMain)
//
-
EFILDRImage++;
//
// Decompress the image
//
- AsciiSPrint (PrintBuffer, 256, "Decompress DXEMain FV image, Image Address=0x%x! Offset=0x%x\n",
- (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
- EFILDRImage->Offset);
- PrintString (PrintBuffer);
+ PrintString (
+ "Decompress DxeMain FV image, Image Address = %x Offset = %x\n",
+ (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
+ (UINTN) EFILDRImage->Offset
+ );
Status = LzmaUefiDecompressGetInfo (
(VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),
@@ -221,9 +202,7 @@ PrintHeader ('C');
&ScratchSize
);
if (EFI_ERROR (Status)) {
- AsciiSPrint (PrintBuffer, 256, "Fail to get decompress information for DXEMain FV image!\n");
- PrintString (PrintBuffer);
- SystemHang();
+ SystemHang ("Failed to get decompress information for DxeMain FV image!\n");
}
Status = LzmaUefiDecompress (
@@ -233,7 +212,7 @@ PrintHeader ('C');
(VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)
);
if (EFI_ERROR (Status)) {
- SystemHang();
+ SystemHang ("Failed to decompress DxeMain FV image!\n");
}
//
@@ -246,33 +225,26 @@ PrintHeader ('C');
EfiMemoryDescriptor
);
if (EFI_ERROR (Status)) {
- SystemHang();
+ SystemHang ("Failed to load/relocate DxeMain!\n");
}
- AsciiSPrint (PrintBuffer, 256, "DxeCore PE image is successed loaded at 0x%x, entry=0x%x\n",
- (UINTN)DxeCoreImage.ImageBasePage, (UINTN)DxeCoreImage.EntryPoint);
- PrintString (PrintBuffer);
+ PrintString (
+ "DxeCore PE image is successed loaded at %lx, entry=%p\n",
+ DxeCoreImage.ImageBasePage,
+ DxeCoreImage.EntryPoint
+ );
PrintHeader ('E');
//
// Display the table of memory descriptors.
//
-
-// PrintString("\nEFI Memory Descriptors\n");
-/*
- {
- UINTN Index;
+ PrintString ("\nEFI Memory Descriptors\n");
for (Index = 0; Index < NumberOfMemoryMapEntries; Index++) {
- PrintString("Type = ");
- PrintValue(EfiMemoryDescriptor[Index].Type);
- PrintString(" Start = ");
- PrintValue((UINT32)(EfiMemoryDescriptor[Index].PhysicalStart));
- PrintString(" NumberOfPages = ");
- PrintValue((UINT32)(EfiMemoryDescriptor[Index].NumberOfPages));
- PrintString("\n");
- }
+ PrintString (
+ "Type = %x Start = %08lx NumberOfPages = %08lx\n",
+ EfiMemoryDescriptor[Index].Type, EfiMemoryDescriptor[Index].PhysicalStart, EfiMemoryDescriptor[Index].NumberOfPages
+ );
}
-*/
//
// Jump to EFI Firmware
@@ -290,10 +262,9 @@ PrintHeader ('E');
Handoff.DxeCoreImageSize = DxeCoreImage.NoPages * EFI_PAGE_SIZE;
Handoff.DxeCoreEntryPoint = (VOID *)(UINTN)DxeCoreImage.EntryPoint;
- AsciiSPrint (PrintBuffer, 256, "Transfer to DxeIpl ...Address=0x%x\n", (UINTN)DxeIplImage.EntryPoint);
- PrintString (PrintBuffer);
+ PrintString ("Transfer to DxeIpl ...EntryPoint = %p\n", DxeIplImage.EntryPoint);
- EfiMainEntrypoint = (EFI_MAIN_ENTRYPOINT)(UINTN)DxeIplImage.EntryPoint;
+ EfiMainEntrypoint = (EFI_MAIN_ENTRYPOINT) DxeIplImage.EntryPoint;
EfiMainEntrypoint (&Handoff);
}
@@ -303,7 +274,7 @@ PrintHeader ('F');
// There was a problem loading the image, so HALT the system.
//
- SystemHang();
+ SystemHang ("Failed to jump to DxeIpl!\n");
}
EFI_STATUS
@@ -312,6 +283,7 @@ _ModuleEntryPoint (
UINT32 BiosMemoryMapBaseAddress
)
{
+ SerialPortInitialize ();
EfiLoader(BiosMemoryMapBaseAddress);
return EFI_SUCCESS;
}