public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] ArmPkg: add ArmCrashDumpDxe driver
@ 2017-09-05 18:22 Ard Biesheuvel
  2017-09-06 15:33 ` Leif Lindholm
  0 siblings, 1 reply; 3+ messages in thread
From: Ard Biesheuvel @ 2017-09-05 18:22 UTC (permalink / raw)
  To: edk2-devel, leif.lindholm; +Cc: Ard Biesheuvel

Even though RELEASE builds produce some diagnostics when a crash
occurs, they can be rather unhelpful:

  Synchronous Exception at 0x0000000000000000

and sometimes, it would be useful to get a full register dump from
a production machine without having to modify the firmware.

This can be achieved very easily by incorporating a DEBUG build of
ARM's DefaultExceptionHandlerLib into a DXE driver, and registering
its DefaultExceptionHandler entry point as the synchronous exception
handler, overriding the default one. If we then build this driver
using the UefiDebugLibConOut DebugLib implementation, we end up
with a module than can simply be loaded via the Shell on any system.

Shell> load fs0:ArmCrashDumpDxe.efi

As a bonus, the crash dump will also appear on the graphical display,
not only on the serial port.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.c   | 38 +++++++++++++
 ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.dsc | 56 ++++++++++++++++++++
 ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf | 40 ++++++++++++++
 3 files changed, 134 insertions(+)

diff --git a/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.c b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.c
new file mode 100644
index 000000000000..221798a26b22
--- /dev/null
+++ b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.c
@@ -0,0 +1,38 @@
+/** @file
+
+  Copyright (c) 2017, Linaro, Ltd. 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
+  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.
+
+**/
+
+#include <PiDxe.h>
+#include <Library/DebugLib.h>
+#include <Library/DefaultExceptionHandlerLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/Cpu.h>
+
+STATIC EFI_CPU_ARCH_PROTOCOL      *mCpu;
+
+EFI_STATUS
+EFIAPI
+ArmCrashDumpDxeInitialize (
+  IN EFI_HANDLE         ImageHandle,
+  IN EFI_SYSTEM_TABLE   *SystemTable
+  )
+{
+  EFI_STATUS      Status;
+
+  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&mCpu);
+  ASSERT_EFI_ERROR(Status);
+
+  return mCpu->RegisterInterruptHandler (mCpu,
+                                         EXCEPT_AARCH64_SYNCHRONOUS_EXCEPTIONS,
+                                         &DefaultExceptionHandler);
+}
diff --git a/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.dsc b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.dsc
new file mode 100644
index 000000000000..5bb27da14bd4
--- /dev/null
+++ b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.dsc
@@ -0,0 +1,56 @@
+#/** @file
+#
+#  Copyright (c) 2017, Linaro Ltd. 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
+#  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.
+#
+#**/
+
+################################################################################
+#
+# Defines Section - statements that will be processed to create a Makefile.
+#
+################################################################################
+[Defines]
+  PLATFORM_NAME                  = ArmCrashDumpDxe
+  PLATFORM_GUID                  = 8dc3c2f8-988e-4e32-8fb7-0df43f6d0d8a
+  PLATFORM_VERSION               = 0.1
+  DSC_SPECIFICATION              = 0x00010019
+  OUTPUT_DIRECTORY               = Build/ArmCrashDumpDxe
+  SUPPORTED_ARCHITECTURES        = AARCH64
+  BUILD_TARGETS                  = DEBUG
+  SKUID_IDENTIFIER               = DEFAULT
+
+[PcdsFixedAtBuild]
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x27
+
+[LibraryClasses]
+  ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
+  DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
+  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
+  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
+  SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+
+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+  NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf
+
+[Components.common]
+  ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf
diff --git a/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf
new file mode 100644
index 000000000000..828b23924920
--- /dev/null
+++ b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf
@@ -0,0 +1,40 @@
+#/** @file
+#
+#  Copyright (c) 2017, Linaro, Ltd. 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
+#  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.
+#
+#**/
+
+[Defines]
+  INF_VERSION                    = 0x00010018
+  BASE_NAME                      = ArmCrashDumpDxe
+  FILE_GUID                      = 0bda00b0-05d6-4bb8-bfc7-058ad13615cf
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = ArmCrashDumpDxeInitialize
+
+[Sources]
+  ArmCrashDumpDxe.c
+
+[Packages]
+  ArmPkg/ArmPkg.dec
+  MdePkg/MdePkg.dec
+
+[LibraryClasses]
+  DebugLib
+  DefaultExceptionHandlerLib
+  UefiBootServicesTableLib
+  UefiDriverEntryPoint
+
+[Protocols]
+  gEfiCpuArchProtocolGuid
+
+[Depex]
+  gEfiCpuArchProtocolGuid
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ArmPkg: add ArmCrashDumpDxe driver
  2017-09-05 18:22 [PATCH] ArmPkg: add ArmCrashDumpDxe driver Ard Biesheuvel
@ 2017-09-06 15:33 ` Leif Lindholm
  2017-09-06 16:48   ` Ard Biesheuvel
  0 siblings, 1 reply; 3+ messages in thread
From: Leif Lindholm @ 2017-09-06 15:33 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel

On Tue, Sep 05, 2017 at 07:22:49PM +0100, Ard Biesheuvel wrote:
> Even though RELEASE builds produce some diagnostics when a crash
> occurs, they can be rather unhelpful:
> 
>   Synchronous Exception at 0x0000000000000000
> 
> and sometimes, it would be useful to get a full register dump from
> a production machine without having to modify the firmware.
> 
> This can be achieved very easily by incorporating a DEBUG build of
> ARM's DefaultExceptionHandlerLib into a DXE driver, and registering
> its DefaultExceptionHandler entry point as the synchronous exception
> handler, overriding the default one. If we then build this driver
> using the UefiDebugLibConOut DebugLib implementation, we end up
> with a module than can simply be loaded via the Shell on any system.
> 
> Shell> load fs0:ArmCrashDumpDxe.efi
> 
> As a bonus, the crash dump will also appear on the graphical display,
> not only on the serial port.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Really useful thing.
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

> ---
>  ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.c   | 38 +++++++++++++
>  ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.dsc | 56 ++++++++++++++++++++
>  ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf | 40 ++++++++++++++
>  3 files changed, 134 insertions(+)
> 
> diff --git a/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.c b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.c
> new file mode 100644
> index 000000000000..221798a26b22
> --- /dev/null
> +++ b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.c
> @@ -0,0 +1,38 @@
> +/** @file
> +
> +  Copyright (c) 2017, Linaro, Ltd. 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
> +  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.
> +
> +**/
> +
> +#include <PiDxe.h>
> +#include <Library/DebugLib.h>
> +#include <Library/DefaultExceptionHandlerLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +#include <Protocol/Cpu.h>
> +
> +STATIC EFI_CPU_ARCH_PROTOCOL      *mCpu;
> +
> +EFI_STATUS
> +EFIAPI
> +ArmCrashDumpDxeInitialize (
> +  IN EFI_HANDLE         ImageHandle,
> +  IN EFI_SYSTEM_TABLE   *SystemTable
> +  )
> +{
> +  EFI_STATUS      Status;
> +
> +  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&mCpu);
> +  ASSERT_EFI_ERROR(Status);
> +
> +  return mCpu->RegisterInterruptHandler (mCpu,
> +                                         EXCEPT_AARCH64_SYNCHRONOUS_EXCEPTIONS,
> +                                         &DefaultExceptionHandler);
> +}
> diff --git a/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.dsc b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.dsc
> new file mode 100644
> index 000000000000..5bb27da14bd4
> --- /dev/null
> +++ b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.dsc
> @@ -0,0 +1,56 @@
> +#/** @file
> +#
> +#  Copyright (c) 2017, Linaro Ltd. 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
> +#  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.
> +#
> +#**/
> +
> +################################################################################
> +#
> +# Defines Section - statements that will be processed to create a Makefile.
> +#
> +################################################################################
> +[Defines]
> +  PLATFORM_NAME                  = ArmCrashDumpDxe
> +  PLATFORM_GUID                  = 8dc3c2f8-988e-4e32-8fb7-0df43f6d0d8a
> +  PLATFORM_VERSION               = 0.1
> +  DSC_SPECIFICATION              = 0x00010019
> +  OUTPUT_DIRECTORY               = Build/ArmCrashDumpDxe
> +  SUPPORTED_ARCHITECTURES        = AARCH64
> +  BUILD_TARGETS                  = DEBUG
> +  SKUID_IDENTIFIER               = DEFAULT
> +
> +[PcdsFixedAtBuild]
> +  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F
> +  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x27
> +
> +[LibraryClasses]
> +  ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf
> +  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
> +  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
> +  DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
> +  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
> +  DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf
> +  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
> +  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
> +  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
> +  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
> +  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
> +  SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
> +  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
> +  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
> +  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
> +  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
> +
> +  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
> +  NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf
> +
> +[Components.common]
> +  ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf
> diff --git a/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf
> new file mode 100644
> index 000000000000..828b23924920
> --- /dev/null
> +++ b/ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf
> @@ -0,0 +1,40 @@
> +#/** @file
> +#
> +#  Copyright (c) 2017, Linaro, Ltd. 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
> +#  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.
> +#
> +#**/
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010018
> +  BASE_NAME                      = ArmCrashDumpDxe
> +  FILE_GUID                      = 0bda00b0-05d6-4bb8-bfc7-058ad13615cf
> +  MODULE_TYPE                    = DXE_DRIVER
> +  VERSION_STRING                 = 1.0
> +  ENTRY_POINT                    = ArmCrashDumpDxeInitialize
> +
> +[Sources]
> +  ArmCrashDumpDxe.c
> +
> +[Packages]
> +  ArmPkg/ArmPkg.dec
> +  MdePkg/MdePkg.dec
> +
> +[LibraryClasses]
> +  DebugLib
> +  DefaultExceptionHandlerLib
> +  UefiBootServicesTableLib
> +  UefiDriverEntryPoint
> +
> +[Protocols]
> +  gEfiCpuArchProtocolGuid
> +
> +[Depex]
> +  gEfiCpuArchProtocolGuid
> -- 
> 2.11.0
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ArmPkg: add ArmCrashDumpDxe driver
  2017-09-06 15:33 ` Leif Lindholm
@ 2017-09-06 16:48   ` Ard Biesheuvel
  0 siblings, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2017-09-06 16:48 UTC (permalink / raw)
  To: Leif Lindholm; +Cc: edk2-devel@lists.01.org

On 6 September 2017 at 16:33, Leif Lindholm <leif.lindholm@linaro.org> wrote:
> On Tue, Sep 05, 2017 at 07:22:49PM +0100, Ard Biesheuvel wrote:
>> Even though RELEASE builds produce some diagnostics when a crash
>> occurs, they can be rather unhelpful:
>>
>>   Synchronous Exception at 0x0000000000000000
>>
>> and sometimes, it would be useful to get a full register dump from
>> a production machine without having to modify the firmware.
>>
>> This can be achieved very easily by incorporating a DEBUG build of
>> ARM's DefaultExceptionHandlerLib into a DXE driver, and registering
>> its DefaultExceptionHandler entry point as the synchronous exception
>> handler, overriding the default one. If we then build this driver
>> using the UefiDebugLibConOut DebugLib implementation, we end up
>> with a module than can simply be loaded via the Shell on any system.
>>
>> Shell> load fs0:ArmCrashDumpDxe.efi
>>
>> As a bonus, the crash dump will also appear on the graphical display,
>> not only on the serial port.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.1
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>
> Really useful thing.
> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
>

Thanks.

Pushed as a94081fb266b


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-09-06 16:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-05 18:22 [PATCH] ArmPkg: add ArmCrashDumpDxe driver Ard Biesheuvel
2017-09-06 15:33 ` Leif Lindholm
2017-09-06 16:48   ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox