]> git.proxmox.com Git - mirror_edk2.git/blobdiff - DuetPkg/EfiLdr/EfiLoader.c
SecurityPkg: Add TPM PTP support in TPM2 device lib.
[mirror_edk2.git] / DuetPkg / EfiLdr / EfiLoader.c
index c69a97f01f1196f262bc5b92383c2177fef67a73..b23966e5ee1a473edc220761f888a010f1e8487d 100644 (file)
@@ -1,7 +1,7 @@
 /*++\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
 http://opensource.org/licenses/bsd-license.php                                            \r
@@ -24,13 +24,18 @@ Revision History:
 #include "PeLoader.h"\r
 #include "LzmaDecompress.h"\r
 \r
+EFILDR_LOADED_IMAGE    DxeCoreImage;\r
+EFILDR_LOADED_IMAGE    DxeIplImage;\r
+\r
 VOID\r
-SystemHang(\r
-  VOID\r
+SystemHang (\r
+  CHAR8        *Message\r
   )\r
 {\r
-  CHAR8 PrintBuffer[256];\r
-  AsciiSPrint (PrintBuffer, 256, "## FATEL ERROR ##: Fail to load DUET images! System hang!\n");\r
+  PrintString (\r
+    "%s## FATAL ERROR ##: Fail to load DUET images! System hang!\n",\r
+    Message\r
+    );\r
   CpuDeadLoop();\r
 }\r
 \r
@@ -49,52 +54,45 @@ EfiLoader (
   UINTN                 BfvPageNumber;\r
   UINTN                 BfvBase;\r
   EFI_MAIN_ENTRYPOINT   EfiMainEntrypoint;\r
-  CHAR8                 PrintBuffer[256];\r
-  STATIC EFILDRHANDOFF  Handoff;\r
+  EFILDRHANDOFF         Handoff;\r
+  UINTN                 Index;\r
 \r
   ClearScreen();\r
   \r
   PrintHeader ('A');\r
-  
-  AsciiSPrint (PrintBuffer, 256, "Enter DUET Loader ...\n", BiosMemoryMapBaseAddress);\r
-  PrintString (PrintBuffer);\r
-\r
-  AsciiSPrint (PrintBuffer, 256, "BiosMemoryMapBaseAddress = 0x%x\n", BiosMemoryMapBaseAddress);\r
-  PrintString (PrintBuffer);\r
+  \r
+  PrintString ("Enter DUET Loader...\n");\r
+  PrintString ("BiosMemoryMapBaseAddress = %x\n", (UINTN) BiosMemoryMapBaseAddress);\r
 \r
   //\r
   // Add all EfiConventionalMemory descriptors to the table.  If there are partial pages, then\r
   // round the start address up to the next page, and round the length down to a page boundry.\r
   //\r
-  BiosMemoryMap = (BIOS_MEMORY_MAP *)(UINTN)(BiosMemoryMapBaseAddress);\r
+  BiosMemoryMap = (BIOS_MEMORY_MAP *) (UINTN) BiosMemoryMapBaseAddress;\r
   NumberOfMemoryMapEntries = 0;\r
   GenMemoryMap (&NumberOfMemoryMapEntries, EfiMemoryDescriptor, BiosMemoryMap);\r
 \r
-  AsciiSPrint (PrintBuffer, 256, "Get %d entries of memory map!\n", NumberOfMemoryMapEntries);\r
-  PrintString (PrintBuffer);\r
+  PrintString ("Get %d entries of memory map!\n", NumberOfMemoryMapEntries);\r
 \r
   //\r
   // Get information on where the image is in memory\r
   //\r
-\r
-  //EFILDRHeader = (EFILDR_HEADER *)(UINTN)(EFILDR_HEADER_ADDRESS);\r
   EFILDRImage  = (EFILDR_IMAGE *)(UINTN)(EFILDR_HEADER_ADDRESS + sizeof(EFILDR_HEADER));\r
 \r
 \r
   //\r
   // Point to the 4th image (Bfv)\r
   //\r
-    \r
   EFILDRImage += 3;\r
 \r
   //\r
   // Decompress the image\r
   //\r
-\r
-  AsciiSPrint (PrintBuffer, 256, "Decompress BFV image, Image Address=0x%x Offset=0x%x\n", \r
-               (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
-               EFILDRImage->Offset);\r
-  PrintString (PrintBuffer);\r
+  PrintString (\r
+    "Decompress BFV image, Image Address = %x Offset = %x\n", \r
+    (UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
+    (UINTN) EFILDRImage->Offset\r
+    );\r
   Status = LzmaUefiDecompressGetInfo (\r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
              EFILDRImage->Length,\r
@@ -103,14 +101,10 @@ EfiLoader (
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    AsciiSPrint (PrintBuffer, 256, "Fail to get decompress information for BFV!\n");\r
-    PrintString (PrintBuffer);\r
-    SystemHang();\r
+    SystemHang ("Failed to get decompress information for BFV!\n");\r
   }\r
   \r
-  AsciiSPrint (PrintBuffer, 256, "BFV decompress: DestinationSize=0x%X, ScratchSize=0x%X!\n",\r
-               DestinationSize, ScratchSize);\r
-  PrintString (PrintBuffer);\r
+  PrintString ("BFV decompress: DestinationSize = %x, ScratchSize = %x\n", (UINTN) DestinationSize, (UINTN) ScratchSize);\r
   Status =  LzmaUefiDecompress (\r
     (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
     EFILDRImage->Length,\r
@@ -120,15 +114,13 @@ EfiLoader (
   \r
 \r
   if (EFI_ERROR (Status)) {\r
-    AsciiSPrint (PrintBuffer, 256, "Fail to decompress BFV!\n");\r
-    PrintString (PrintBuffer);\r
-    SystemHang();\r
+    SystemHang ("Failed to decompress BFV!\n");\r
   }\r
 \r
   BfvPageNumber = EFI_SIZE_TO_PAGES (DestinationSize);\r
   BfvBase = (UINTN) FindSpace (BfvPageNumber, &NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesData, EFI_MEMORY_WB);\r
   if (BfvBase == 0) {\r
-    SystemHang();\r
+    SystemHang ("Failed to find free space to hold decompressed BFV\n");\r
   }\r
   ZeroMem ((VOID *)(UINTN)BfvBase, BfvPageNumber * EFI_PAGE_SIZE);\r
   CopyMem ((VOID *)(UINTN)BfvBase, (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS, DestinationSize);\r
@@ -144,10 +136,11 @@ EfiLoader (
   //\r
   // Decompress the image\r
   //\r
-  AsciiSPrint (PrintBuffer, 256, "Decompress DxeIpl image, Image Address=0x%x Offset=0x%x\n", \r
-               (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
-               EFILDRImage->Offset);\r
-  PrintString (PrintBuffer);\r
+  PrintString (\r
+    "Decompress DxeIpl image, Image Address = %x Offset = %x\n", \r
+    (UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
+    (UINTN) EFILDRImage->Offset\r
+    );\r
 \r
   Status = LzmaUefiDecompressGetInfo (\r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
@@ -156,9 +149,7 @@ EfiLoader (
              &ScratchSize\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    AsciiSPrint (PrintBuffer, 256, "Fail to get decompress information for DxeIpl!\n");\r
-    PrintString (PrintBuffer);\r
-    SystemHang();\r
+    SystemHang ("Failed to get decompress information for DxeIpl!\n");\r
   }\r
 \r
   Status = LzmaUefiDecompress (\r
@@ -168,13 +159,10 @@ EfiLoader (
              (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    AsciiSPrint (PrintBuffer, 256, "Fail to decompress DxeIpl image\n");\r
-    PrintString (PrintBuffer);\r
-    SystemHang();\r
+    SystemHang ("Failed to decompress DxeIpl image\n");\r
   }\r
 \r
-  AsciiSPrint (PrintBuffer, 256, "Start load DxeIpl PE image\n");\r
-  PrintString (PrintBuffer);  \r
+  PrintString ("Start load DxeIpl PE image\n");  \r
 \r
   //\r
   // Load and relocate the EFI PE/COFF Firmware Image \r
@@ -186,33 +174,29 @@ EfiLoader (
              EfiMemoryDescriptor\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    AsciiSPrint (PrintBuffer, 256, "Fail to load and relocate DxeIpl PE image!\n");\r
-    PrintString (PrintBuffer);\r
-    SystemHang();\r
+    SystemHang ("Failed to load and relocate DxeIpl PE image!\n");\r
   }\r
-  AsciiSPrint (PrintBuffer, 256, "DxeIpl PE image is successed loaded at 0x%x, entry=0x%x\n",\r
-               (UINTN)DxeIplImage.ImageBasePage, (UINTN)DxeIplImage.EntryPoint);\r
-  PrintString (PrintBuffer);  \r
-\r
-//  PrintString("Image.NoPages = ");   \r
-//  PrintValue(Image.NoPages);\r
-//  PrintString("\n");\r
+  PrintString (\r
+    "DxeIpl PE image is successed loaded at %lx, entry=%p\n",\r
+    DxeIplImage.ImageBasePage,\r
+    DxeIplImage.EntryPoint\r
+    );\r
 \r
 PrintHeader ('C');\r
 \r
   //\r
   // Point to the 3rd image (DxeMain)\r
   //\r
-    \r
   EFILDRImage++;\r
 \r
   //\r
   // Decompress the image\r
   //\r
-  AsciiSPrint (PrintBuffer, 256, "Decompress DXEMain FV image, Image Address=0x%x! Offset=0x%x\n", \r
-               (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
-               EFILDRImage->Offset);\r
-  PrintString (PrintBuffer);\r
+  PrintString (\r
+    "Decompress DxeMain FV image, Image Address = %x Offset = %x\n",\r
+    (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
+    (UINTN) EFILDRImage->Offset\r
+    );\r
 \r
   Status = LzmaUefiDecompressGetInfo (\r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
@@ -221,9 +205,7 @@ PrintHeader ('C');
              &ScratchSize\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    AsciiSPrint (PrintBuffer, 256, "Fail to get decompress information for DXEMain FV image!\n");\r
-    PrintString (PrintBuffer);\r
-    SystemHang();\r
+    SystemHang ("Failed to get decompress information for DxeMain FV image!\n");\r
   }\r
 \r
   Status = LzmaUefiDecompress (\r
@@ -233,7 +215,7 @@ PrintHeader ('C');
              (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    SystemHang();\r
+    SystemHang ("Failed to decompress DxeMain FV image!\n");\r
   }\r
 \r
   //\r
@@ -246,33 +228,26 @@ PrintHeader ('C');
              EfiMemoryDescriptor\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    SystemHang();\r
+    SystemHang ("Failed to load/relocate DxeMain!\n");\r
   }\r
-  AsciiSPrint (PrintBuffer, 256, "DxeCore PE image is successed loaded at 0x%x, entry=0x%x\n",\r
-               (UINTN)DxeCoreImage.ImageBasePage, (UINTN)DxeCoreImage.EntryPoint);\r
-  PrintString (PrintBuffer);  \r
+  PrintString (\r
+    "DxeCore PE image is successed loaded at %lx, entry=%p\n",\r
+    DxeCoreImage.ImageBasePage,\r
+    DxeCoreImage.EntryPoint\r
+    );\r
 \r
 PrintHeader ('E');\r
 \r
   //\r
   // Display the table of memory descriptors.\r
   //\r
-\r
-//  PrintString("\nEFI Memory Descriptors\n");   \r
-/*\r
-  {\r
-  UINTN Index;\r
+  PrintString ("\nEFI Memory Descriptors\n");   \r
   for (Index = 0; Index < NumberOfMemoryMapEntries; Index++) {\r
-    PrintString("Type = ");   \r
-    PrintValue(EfiMemoryDescriptor[Index].Type);\r
-    PrintString("  Start = ");   \r
-    PrintValue((UINT32)(EfiMemoryDescriptor[Index].PhysicalStart));\r
-    PrintString("  NumberOfPages = ");   \r
-    PrintValue((UINT32)(EfiMemoryDescriptor[Index].NumberOfPages));\r
-    PrintString("\n");\r
-  }\r
+    PrintString (\r
+      "Type = %x Start = %08lx NumberOfPages = %08lx\n",\r
+      EfiMemoryDescriptor[Index].Type, EfiMemoryDescriptor[Index].PhysicalStart, EfiMemoryDescriptor[Index].NumberOfPages\r
+      );\r
   }\r
-*/\r
 \r
   //\r
   // Jump to EFI Firmware\r
@@ -290,10 +265,9 @@ PrintHeader ('E');
     Handoff.DxeCoreImageSize  = DxeCoreImage.NoPages * EFI_PAGE_SIZE;\r
     Handoff.DxeCoreEntryPoint = (VOID *)(UINTN)DxeCoreImage.EntryPoint;\r
 \r
-    AsciiSPrint (PrintBuffer, 256, "Transfer to DxeIpl ...Address=0x%x\n", (UINTN)DxeIplImage.EntryPoint);\r
-    PrintString (PrintBuffer);\r
+    PrintString ("Transfer to DxeIpl ...EntryPoint = %p\n", DxeIplImage.EntryPoint);\r
     \r
-    EfiMainEntrypoint = (EFI_MAIN_ENTRYPOINT)(UINTN)DxeIplImage.EntryPoint;\r
+    EfiMainEntrypoint = (EFI_MAIN_ENTRYPOINT) DxeIplImage.EntryPoint;\r
     EfiMainEntrypoint (&Handoff);\r
   }\r
 \r
@@ -303,7 +277,7 @@ PrintHeader ('F');
   // There was a problem loading the image, so HALT the system.\r
   //\r
 \r
-  SystemHang();\r
+  SystemHang ("Failed to jump to DxeIpl!\n");\r
 }\r
 \r
 EFI_STATUS\r
@@ -312,6 +286,7 @@ _ModuleEntryPoint (
   UINT32    BiosMemoryMapBaseAddress\r
   )\r
 {\r
+  SerialPortInitialize ();\r
   EfiLoader(BiosMemoryMapBaseAddress);\r
   return EFI_SUCCESS;\r
 }\r