]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c
MdeModulePkg/Universal/StatusCodeHandler: Fix a bug about log lost
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / RuntimeDxe / SerialStatusCodeWorker.c
index 626772575152e42d60770fc7ce1033652fb96d86..348f55edba544c44ca18dd04c5e99f3e925a3f1c 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Serial I/O status code reporting worker.\r
 \r
-  Copyright (c) 2006 - 2010, 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
-                                                                                            \r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -16,7 +10,7 @@
 \r
 /**\r
   Convert status code value and extended data to readable ASCII string, send string to serial I/O device.\r
\r
+\r
   @param  CodeType         Indicates the type of status code being reported.\r
   @param  Value            Describes the current status of a hardware or software entity.\r
                            This included information about the class and subclass that is used to\r
@@ -46,7 +40,7 @@ SerialStatusCodeReportWorker (
   CHAR8           *Filename;\r
   CHAR8           *Description;\r
   CHAR8           *Format;\r
-  CHAR8           Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];\r
+  CHAR8           Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
   UINT32          ErrorLevel;\r
   UINT32          LineNumber;\r
   UINTN           CharCount;\r
@@ -73,9 +67,9 @@ SerialStatusCodeReportWorker (
     // Print DEBUG() information into output buffer.\r
     //\r
     CharCount = AsciiBSPrint (\r
-                  Buffer, \r
-                  sizeof (Buffer), \r
-                  Format, \r
+                  Buffer,\r
+                  sizeof (Buffer),\r
+                  Format,\r
                   Marker\r
                   );\r
   } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
@@ -83,17 +77,18 @@ SerialStatusCodeReportWorker (
     // Print ERROR information into output buffer.\r
     //\r
     CharCount = AsciiSPrint (\r
-                  Buffer, \r
-                  sizeof (Buffer), \r
-                  "ERROR: C%x:V%x I%x", \r
-                  CodeType, \r
-                  Value, \r
+                  Buffer,\r
+                  sizeof (Buffer),\r
+                  "ERROR: C%08x:V%08x I%x",\r
+                  CodeType,\r
+                  Value,\r
                   Instance\r
                   );\r
-   \r
+    ASSERT (CharCount > 0);\r
+\r
     if (CallerId != NULL) {\r
       CharCount += AsciiSPrint (\r
-                     &Buffer[CharCount - 1],\r
+                     &Buffer[CharCount],\r
                      (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
                      " %g",\r
                      CallerId\r
@@ -102,7 +97,7 @@ SerialStatusCodeReportWorker (
 \r
     if (Data != NULL) {\r
       CharCount += AsciiSPrint (\r
-                     &Buffer[CharCount - 1],\r
+                     &Buffer[CharCount],\r
                      (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
                      " %x",\r
                      Data\r
@@ -110,7 +105,7 @@ SerialStatusCodeReportWorker (
     }\r
 \r
     CharCount += AsciiSPrint (\r
-                   &Buffer[CharCount - 1],\r
+                   &Buffer[CharCount],\r
                    (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r
                    "\n\r"\r
                    );\r
@@ -119,10 +114,10 @@ SerialStatusCodeReportWorker (
     // Print PROGRESS information into output buffer.\r
     //\r
     CharCount = AsciiSPrint (\r
-                  Buffer, \r
-                  sizeof (Buffer), \r
-                  "PROGRESS CODE: V%x I%x\n\r", \r
-                  Value, \r
+                  Buffer,\r
+                  sizeof (Buffer),\r
+                  "PROGRESS CODE: V%08x I%x\n\r",\r
+                  Value,\r
                   Instance\r
                   );\r
   } else if (Data != NULL &&\r
@@ -134,7 +129,7 @@ SerialStatusCodeReportWorker (
     CharCount = AsciiSPrint (\r
                   Buffer,\r
                   sizeof (Buffer),\r
-                  "%a\n\r",\r
+                  "%a",\r
                   ((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii\r
                   );\r
   } else {\r
@@ -142,11 +137,11 @@ SerialStatusCodeReportWorker (
     // Code type is not defined.\r
     //\r
     CharCount = AsciiSPrint (\r
-                  Buffer, \r
-                  sizeof (Buffer), \r
-                  "Undefined: C%x:V%x I%x\n\r", \r
-                  CodeType, \r
-                  Value, \r
+                  Buffer,\r
+                  sizeof (Buffer),\r
+                  "Undefined: C%08x:V%08x I%x\n\r",\r
+                  CodeType,\r
+                  Value,\r
                   Instance\r
                   );\r
   }\r
@@ -156,6 +151,16 @@ SerialStatusCodeReportWorker (
   //\r
   SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
 \r
+  //\r
+  // If register an unregister function of gEfiEventExitBootServicesGuid,\r
+  // then some log called in ExitBootServices() will be lost,\r
+  // so unregister the handler after receive the value of exit boot service.\r
+  //\r
+  if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE &&\r
+      Value == (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)) {\r
+    UnregisterSerialBootTimeHandlers();\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r