]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Fixed issue that firmware cannot boot if no USB debug cable connection.
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 30 Sep 2011 02:19:28 +0000 (02:19 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 30 Sep 2011 02:19:28 +0000 (02:19 +0000)
2. Fixed issue that Ovmf with debug agent cannot boot if HOST software was not connected.

Signed-off-by: vanjeff
Reviewed-by: geekboy15a
Reviewed-by: erictian
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12486 6f19259b-4bc3-4df7-8a09-765794883524

SourceLevelDebugPkg/Include/TransferProtocol.h
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf
SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c
SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf
SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.inf

index b7e1143aa0a06002a7ff23b5387586495c100667..e0b3d7e7b77b61765e44dfa22c6f8ac4b72df55a 100644 (file)
@@ -2,7 +2,7 @@
   Transfer protocol defintions used by debug agent and host. It is only\r
   intended to be used by Debug related module implementation.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 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
@@ -102,7 +102,7 @@ typedef struct {
 \r
 #define DEBUG_COMMAND_SET_DEBUG_FLAG              (DEBUG_COMMAND_REQUEST | 38) // 38\r
 \r
-#define DEBUG_COMMAND_GET_REVISION                (DEBUG_COMMAND_REQUEST | 39) // 30\r
+#define DEBUG_COMMAND_GET_REVISION                (DEBUG_COMMAND_REQUEST | 39) // 39\r
 \r
 #define DEBUG_COMMAND_GET_EXCEPTION               (DEBUG_COMMAND_REQUEST | 40) // 40\r
 \r
index 9671ca4efe39e31ec70a83579a0684e1f09d3edc..2636050825ca6e978c19be929efcb455afba6507 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Command header of for Debug Agent library instance.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 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
@@ -29,6 +29,7 @@
 #include <Library/PcdLib.h>\r
 #include <Library/SynchronizationLib.h>\r
 #include <Library/LocalApicLib.h>\r
+#include <Library/DebugLib.h>\r
 \r
 #include <TransferProtocol.h>\r
 #include <ImageDebugSupport.h>\r
index 0d4169ccc7a3abd574627b7efdcc28665761427c..b14d6eb92a401fdfd5bcc591bd2acfbec729f3cd 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SEC Core Debug Agent Library instance implementition.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 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
@@ -196,14 +196,36 @@ InitializeDebugAgent (
   DEBUG_AGENT_PHASE2_CONTEXT       Phase2Context;\r
   DEBUG_AGENT_CONTEXT_POSTMEM_SEC  *DebugAgentContext;\r
 \r
-  if (InitFlag != DEBUG_AGENT_INIT_PREMEM_SEC &&\r
-      InitFlag != DEBUG_AGENT_INIT_POSTMEM_SEC) {\r
-    return;\r
-  }\r
-\r
   DisableInterrupts ();\r
 \r
-  if (InitFlag == DEBUG_AGENT_INIT_POSTMEM_SEC) {\r
+  switch (InitFlag) {\r
+\r
+  case DEBUG_AGENT_INIT_PREMEM_SEC:\r
+\r
+    InitializeDebugIdt ();\r
+\r
+    Mailbox = &MailboxInStack;\r
+    ZeroMem ((VOID *) Mailbox, sizeof (DEBUG_AGENT_MAILBOX));\r
+\r
+    //\r
+    // Get and save debug port handle and set the length of memory block.\r
+    //\r
+    SetMailboxPointerInIdtEntry ((VOID *) Mailbox);\r
+\r
+    InitializeDebugTimer ();\r
+\r
+    Phase2Context.Context  = Context;\r
+    Phase2Context.Function = Function;\r
+    DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2);\r
+\r
+    //\r
+    // If reaches here, it means Debug Port initialization failed.\r
+    //\r
+    DEBUG ((EFI_D_ERROR, "Debug Agent: Debug port initialization failed.\n"));\r
+\r
+    break;\r
+\r
+  case DEBUG_AGENT_INIT_POSTMEM_SEC:\r
 \r
     //\r
     // Memory has been ready\r
@@ -227,31 +249,25 @@ InitializeDebugAgent (
 \r
     EnableInterrupts ();\r
 \r
-    if (Function != NULL) {\r
-      Function (Context);\r
-    }\r
-\r
-    return;\r
+    break;\r
 \r
-  } else {\r
-\r
-    InitializeDebugIdt ();\r
-\r
-    Mailbox = &MailboxInStack;\r
-    ZeroMem ((VOID *) Mailbox, sizeof (DEBUG_AGENT_MAILBOX));\r
+  default:\r
 \r
     //\r
-    // Get and save debug port handle and set the length of memory block.\r
+    // Only DEBUG_AGENT_INIT_PREMEM_SEC and DEBUG_AGENT_INIT_POSTMEM_SEC are allowed for this \r
+    // Debug Agent library instance.\r
     //\r
-    SetMailboxPointerInIdtEntry ((VOID *) Mailbox);\r
+    DEBUG ((EFI_D_ERROR, "Debug Agent: The InitFlag value is not allowed!\n"));\r
+    CpuDeadLoop ();\r
+    break;\r
 \r
-    InitializeDebugTimer ();\r
-\r
-    Phase2Context.Context  = Context;\r
-    Phase2Context.Function = Function;\r
-    DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2);\r
+  }\r
 \r
-    return;\r
+  //\r
+  // If Function is not NULL, invoke it always whatever debug agent was initialized sucesssfully or not.\r
+  //\r
+  if (Function != NULL) {\r
+    Function (Context);\r
   }\r
 }\r
 \r
@@ -289,7 +305,7 @@ InitializeDebugAgentPhase2 (
   //\r
   Phase2Context = (DEBUG_AGENT_PHASE2_CONTEXT *) Context;\r
   SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Phase2Context->Context;\r
-  if ((UINTN)SecCoreData->TemporaryRamBase < BASE_128MB) {\r
+  if ((UINTN)SecCoreData->TemporaryRamBase < BASE_128MB && IsHostConnected ()) {\r
     TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);\r
   }\r
 \r
@@ -299,7 +315,7 @@ InitializeDebugAgentPhase2 (
   EnableInterrupts ();\r
 \r
   //\r
-  // Call continuation function is it is not NULL.\r
+  // Call continuation function if it is not NULL.\r
   //\r
   if (Phase2Context->Function != NULL) {\r
     Phase2Context->Function (Phase2Context->Context);\r
index e2b8ad60aff094b84a36fe0a1dbea7c6067616e8..4d8fc71aaddcc5491a97ddc2106372dcda928020 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Debug Agent library instance for SEC Core and PEI modules.\r
 #\r
-#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -71,6 +71,7 @@
   DebugCommunicationLib\r
   SynchronizationLib\r
   LocalApicLib\r
+  DebugLib\r
 \r
 [Guids]\r
   gEfiDebugAgentGuid                            ## PRODUCES ## HOB\r
index ed1a35bd96f86453f1b7aa00f0542d78dd89ae93..dd88e7d6938013cac1b65fd9045115f17b4d88b7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Debug Port Library implementation based on serial port.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 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
@@ -17,6 +17,7 @@
 #include <Library/DebugCommunicationLib.h>\r
 #include <Library/SerialPortLib.h>\r
 #include <Library/TimerLib.h>\r
+#include <Library/DebugLib.h>\r
 \r
 /**\r
   Initialize the debug port.\r
@@ -61,7 +62,12 @@ DebugPortInitialize (
   IN DEBUG_PORT_CONTINUE  Function\r
   )\r
 {\r
-  SerialPortInitialize ();\r
+  RETURN_STATUS      Status;\r
+\r
+  Status = SerialPortInitialize ();\r
+  if (RETURN_ERROR(Status)) {\r
+    DEBUG ((EFI_D_ERROR, "Debug Serial Port: Initialization failed!\n")); \r
+  }\r
 \r
   if (Function != NULL) {\r
     Function (Context, NULL);\r
index dff0fc92b10b276e58f2d81d3b8ef7c91996a2cc..6d36cefd7476565db201c391d15a8385491bdcc1 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Debug Communication Library instance based on serila port.\r
 #\r
-#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -35,4 +35,5 @@
 [LibraryClasses]\r
   SerialPortLib\r
   TimerLib\r
+  DebugLib\r
   \r
index 3dd1e3a62c4286ab74adf8858ecfbd211f28b02b..7fb671eb4b31368ff55a9a14b9589911ed409f51 100644 (file)
@@ -22,6 +22,7 @@
 #include <Library/DebugCommunicationLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
 \r
 #define SETUP_PID            0x2D\r
 #define INPUT_PID            0x69\r
@@ -108,7 +109,7 @@ typedef struct _USB_DEBUG_PORT_HANDLE{
   // The usb debug port memory BAR number in EHCI configuration space.\r
   //\r
   UINT8        DebugPortBarNumber;\r
-  UINT8        Reserved;\r
+  BOOLEAN      Initialized;\r
   //\r
   // The offset of usb debug port registers in EHCI memory range.\r
   //\r
@@ -723,6 +724,13 @@ DebugPortReadBuffer (
     UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;\r
   }\r
 \r
+  //\r
+  // Check if debug port is ready\r
+  //\r
+  if (!UsbDebugPortHandle->Initialized) {\r
+    return 0;\r
+  }\r
+\r
   if (NeedReinitializeHardware(UsbDebugPortHandle)) {\r
     Status = InitializeUsbDebugHardware (UsbDebugPortHandle);\r
     if (RETURN_ERROR(Status)) {\r
@@ -868,6 +876,13 @@ DebugPortWriteBuffer (
     UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;\r
   }\r
 \r
+  //\r
+  // Check if debug port is ready\r
+  //\r
+  if (!UsbDebugPortHandle->Initialized) {\r
+    return 0;\r
+  }\r
+\r
   if (NeedReinitializeHardware(UsbDebugPortHandle)) {\r
     Status = InitializeUsbDebugHardware (UsbDebugPortHandle);\r
     if (RETURN_ERROR(Status)) {\r
@@ -940,6 +955,13 @@ DebugPortPollBuffer (
     UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;\r
   }\r
 \r
+  //\r
+  // Check if debug port is ready\r
+  //\r
+  if (!UsbDebugPortHandle->Initialized) {\r
+    return 0;\r
+  }\r
+\r
   if (NeedReinitializeHardware(UsbDebugPortHandle)) {\r
     Status = InitializeUsbDebugHardware(UsbDebugPortHandle);\r
     if (RETURN_ERROR(Status)) {\r
@@ -1046,7 +1068,8 @@ DebugPortInitialize (
 \r
   Status = CalculateUsbDebugPortBar(&Handle.DebugPortOffset, &Handle.DebugPortBarNumber);\r
   if (RETURN_ERROR (Status)) {\r
-    return NULL;\r
+    DEBUG ((EFI_D_ERROR, "USB Debug Port: EHCI host controller does not support debug port capability!\n"));\r
+    goto Exit;\r
   }\r
 \r
   Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);\r
@@ -1071,9 +1094,17 @@ DebugPortInitialize (
 \r
   Status = InitializeUsbDebugHardware (&Handle);\r
   if (RETURN_ERROR(Status)) {\r
-    return NULL;\r
+    DEBUG ((EFI_D_ERROR, "USB Debug Port: Initialization failed, please check if USB debug cable is plugged into EHCI debug port correctly!\n"));\r
+    goto Exit;\r
   }\r
 \r
+  //\r
+  // Set debug port initialized successfully flag\r
+  //\r
+  Handle.Initialized = TRUE;\r
+\r
+Exit:\r
+\r
   if (Function != NULL) {\r
     Function (Context, &Handle);\r
   } else {\r