]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Library/EblCmdLib/EblCmdLib.c
ArmPlatformPkg/EblCmdLib: Added the command 'dumpfdt'
[mirror_edk2.git] / ArmPlatformPkg / Library / EblCmdLib / EblCmdLib.c
index 92894447561e0cfd92cb501806bb17a5c307a8bc..8f7ea65e7b2639534e9752ec08c53128fa91c0da 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
 *  \r
 *  This program and the accompanying materials                          \r
 *  are licensed and made available under the terms and conditions of the BSD License         \r
 #include <Library/PeCoffGetEntryPointLib.h>\r
 #include <Library/PerformanceLib.h>\r
 #include <Library/TimerLib.h>\r
+#include <Library/BdsLib.h>\r
 \r
 #include <Guid/DebugImageInfoTable.h>\r
 \r
 #include <Protocol/DebugSupport.h>\r
 #include <Protocol/LoadedImage.h>\r
+#include <Protocol/DevicePathToText.h>\r
 \r
 EFI_STATUS\r
 EblDumpMmu (\r
   IN UINTN  Argc,\r
   IN CHAR8  **Argv\r
   );\r
+  \r
+EFI_STATUS\r
+EblDumpFdt (\r
+  IN UINTN  Argc,\r
+  IN CHAR8  **Argv\r
+  );\r
 \r
 /**\r
   Simple arm disassembler via a library\r
@@ -50,7 +58,7 @@ EblDumpMmu (
 \r
   @param  Argc   Number of command arguments in Argv\r
   @param  Argv   Array of strings that represent the parsed command line. \r
-                 Argv[0] is the comamnd name\r
+                 Argv[0] is the command name\r
 \r
   @return EFI_SUCCESS\r
 \r
@@ -73,7 +81,11 @@ EblSymbolTable (
   \r
   // Need to add lots of error checking on the passed in string\r
   // Default string is for RealView debugger\r
+#if (__ARMCC_VERSION < 500000)\r
   Format = (Argc > 1) ? Argv[1] : "load /a /ni /np %a &0x%x";\r
+#else\r
+  Format = (Argc > 1) ? Argv[1] : "add-symbol-file %a 0x%x";\r
+#endif\r
   Elf = (Argc > 2) ? FALSE : TRUE;\r
   \r
   Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&DebugImageTableHeader);\r
@@ -118,7 +130,7 @@ EblSymbolTable (
 \r
   @param  Argc   Number of command arguments in Argv\r
   @param  Argv   Array of strings that represent the parsed command line. \r
-                 Argv[0] is the comamnd name\r
+                 Argv[0] is the command name\r
 \r
   @return EFI_SUCCESS\r
 \r
@@ -183,7 +195,7 @@ ImageHandleToPdbFileName (
 }\r
 \r
 \r
-CHAR8 *mTokenList[] = {\r
+STATIC CHAR8 *mTokenList[] = {\r
   /*"SEC",*/\r
   "PEI",\r
   "DXE",\r
@@ -200,7 +212,7 @@ CHAR8 *mTokenList[] = {
 \r
   @param  Argc   Number of command arguments in Argv\r
   @param  Argv   Array of strings that represent the parsed command line. \r
-                 Argv[0] is the comamnd name\r
+                 Argv[0] is the command name\r
 \r
   @return EFI_SUCCESS\r
 \r
@@ -217,8 +229,14 @@ EblPerformance (
   UINT64      Start, Stop, TimeStamp;\r
   UINT64      Delta, TicksPerSecond, Milliseconds, Microseconds;\r
   UINTN       Index;\r
+  BOOLEAN     CountUp;\r
 \r
-  TicksPerSecond = GetPerformanceCounterProperties (NULL, NULL);\r
+  TicksPerSecond = GetPerformanceCounterProperties (&Start, &Stop);\r
+  if (Start < Stop) {\r
+    CountUp = TRUE;\r
+  } else {\r
+    CountUp = FALSE;\r
+  }\r
 \r
   Key       = 0;\r
   do {\r
@@ -229,7 +247,7 @@ EblPerformance (
           // The entry for EBL is still running so the stop time will be zero. Skip it\r
           AsciiPrint ("   running     %a\n", ImageHandleToPdbFileName ((EFI_HANDLE)Handle));\r
         } else {\r
-          Delta = Start - Stop;\r
+          Delta =  CountUp?(Stop - Start):(Start - Stop);\r
           Microseconds = DivU64x64Remainder (MultU64x32 (Delta, 1000000), TicksPerSecond, NULL);\r
           AsciiPrint ("%10ld us  %a\n", Microseconds, ImageHandleToPdbFileName ((EFI_HANDLE)Handle));\r
         }\r
@@ -246,7 +264,7 @@ EblPerformance (
     if (Key != 0) {\r
       for (Index = 0; mTokenList[Index] != NULL; Index++) {\r
         if (AsciiStriCmp (mTokenList[Index], Token) == 0) {\r
-          Delta = Start - Stop;\r
+          Delta =  CountUp?(Stop - Start):(Start - Stop);\r
           TimeStamp += Delta;\r
           Milliseconds = DivU64x64Remainder (MultU64x32 (Delta, 1000), TicksPerSecond, NULL);\r
           AsciiPrint ("%6a %6ld ms\n", Token, Milliseconds);\r
@@ -269,76 +287,112 @@ EblDumpGcd (
   IN CHAR8  **Argv\r
   )\r
 {\r
-    EFI_STATUS                        Status;\r
-    UINTN                           NumberOfDescriptors;\r
-    UINTN i;\r
-    EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;\r
-    EFI_GCD_IO_SPACE_DESCRIPTOR *IoSpaceMap;\r
-\r
-    Status = gDS->GetMemorySpaceMap(&NumberOfDescriptors,&MemorySpaceMap);\r
-    if (EFI_ERROR (Status)) {\r
-        return Status;\r
-    }\r
-    AsciiPrint ("    Address Range       Image     Device   Attributes\n");\r
-    AsciiPrint ("__________________________________________________________\n");\r
-    for (i=0; i < NumberOfDescriptors; i++) {\r
-        //AsciiPrint ("%016lx - %016lx",MemorySpaceMap[i].BaseAddress,MemorySpaceMap[i].BaseAddress+MemorySpaceMap[i].Length);\r
-        AsciiPrint ("MEM %08lx - %08lx",(UINT64)MemorySpaceMap[i].BaseAddress,MemorySpaceMap[i].BaseAddress+MemorySpaceMap[i].Length-1);\r
-        AsciiPrint (" %08x %08x",MemorySpaceMap[i].ImageHandle,MemorySpaceMap[i].DeviceHandle);\r
-\r
-        if (MemorySpaceMap[i].Attributes & EFI_MEMORY_RUNTIME)\r
-            AsciiPrint (" RUNTIME");\r
-        if (MemorySpaceMap[i].Attributes & EFI_MEMORY_PORT_IO)\r
-            AsciiPrint (" PORT_IO");\r
-\r
-        if (MemorySpaceMap[i].Attributes & EFI_MEMORY_UC)\r
-            AsciiPrint (" MEM_UC");\r
-        if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WC)\r
-            AsciiPrint (" MEM_WC");\r
-        if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WT)\r
-            AsciiPrint (" MEM_WT");\r
-        if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WB)\r
-            AsciiPrint (" MEM_WB");\r
-        if (MemorySpaceMap[i].Attributes & EFI_MEMORY_UCE)\r
-            AsciiPrint (" MEM_UCE");\r
-        if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WP)\r
-            AsciiPrint (" MEM_WP");\r
-        if (MemorySpaceMap[i].Attributes & EFI_MEMORY_RP)\r
-            AsciiPrint (" MEM_RP");\r
-        if (MemorySpaceMap[i].Attributes & EFI_MEMORY_XP)\r
-            AsciiPrint (" MEM_XP");\r
-\r
-        if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeNonExistent)\r
-            AsciiPrint (" TYPE_NONEXISTENT");\r
-        if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeReserved)\r
-            AsciiPrint (" TYPE_RESERVED");\r
-        if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeSystemMemory)\r
-            AsciiPrint (" TYPE_SYSMEM");\r
-        if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeMemoryMappedIo)\r
-            AsciiPrint (" TYPE_MEMMAP");\r
-\r
-        AsciiPrint ("\n");\r
-    }\r
+  EFI_STATUS                        Status;\r
+  UINTN                           NumberOfDescriptors;\r
+  UINTN i;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;\r
+  EFI_GCD_IO_SPACE_DESCRIPTOR *IoSpaceMap;\r
 \r
-    Status = gDS->GetIoSpaceMap(&NumberOfDescriptors,&IoSpaceMap);\r
-    if (EFI_ERROR (Status)) {\r
-        return Status;\r
-    }\r
-    for (i=0; i < NumberOfDescriptors; i++) {\r
-        AsciiPrint ("IO  %08lx - %08lx",IoSpaceMap[i].BaseAddress,IoSpaceMap[i].BaseAddress+IoSpaceMap[i].Length);\r
-        AsciiPrint ("\t%08x %08x",IoSpaceMap[i].ImageHandle,IoSpaceMap[i].DeviceHandle);\r
-\r
-        if (IoSpaceMap[i].GcdIoType & EfiGcdMemoryTypeNonExistent)\r
-            AsciiPrint (" TYPE_NONEXISTENT");\r
-        if (IoSpaceMap[i].GcdIoType & EfiGcdMemoryTypeReserved)\r
-            AsciiPrint (" TYPE_RESERVED");\r
-        if (IoSpaceMap[i].GcdIoType & EfiGcdIoTypeIo)\r
-            AsciiPrint (" TYPE_IO");\r
-\r
-        AsciiPrint ("\n");\r
-    }\r
+  Status = gDS->GetMemorySpaceMap(&NumberOfDescriptors,&MemorySpaceMap);\r
+  if (EFI_ERROR (Status)) {\r
+      return Status;\r
+  }\r
+  AsciiPrint ("    Address Range       Image     Device   Attributes\n");\r
+  AsciiPrint ("__________________________________________________________\n");\r
+  for (i=0; i < NumberOfDescriptors; i++) {\r
+    AsciiPrint ("MEM %016lx - %016lx",(UINT64)MemorySpaceMap[i].BaseAddress,MemorySpaceMap[i].BaseAddress+MemorySpaceMap[i].Length-1);\r
+    AsciiPrint (" %08x %08x",MemorySpaceMap[i].ImageHandle,MemorySpaceMap[i].DeviceHandle);\r
+\r
+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_RUNTIME)\r
+        AsciiPrint (" RUNTIME");\r
+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_PORT_IO)\r
+        AsciiPrint (" PORT_IO");\r
+\r
+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_UC)\r
+        AsciiPrint (" MEM_UC");\r
+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WC)\r
+        AsciiPrint (" MEM_WC");\r
+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WT)\r
+        AsciiPrint (" MEM_WT");\r
+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WB)\r
+        AsciiPrint (" MEM_WB");\r
+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_UCE)\r
+        AsciiPrint (" MEM_UCE");\r
+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_WP)\r
+        AsciiPrint (" MEM_WP");\r
+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_RP)\r
+        AsciiPrint (" MEM_RP");\r
+    if (MemorySpaceMap[i].Attributes & EFI_MEMORY_XP)\r
+        AsciiPrint (" MEM_XP");\r
+\r
+    if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeNonExistent)\r
+        AsciiPrint (" TYPE_NONEXISTENT");\r
+    if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeReserved)\r
+        AsciiPrint (" TYPE_RESERVED");\r
+    if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeSystemMemory)\r
+        AsciiPrint (" TYPE_SYSMEM");\r
+    if (MemorySpaceMap[i].GcdMemoryType & EfiGcdMemoryTypeMemoryMappedIo)\r
+        AsciiPrint (" TYPE_MEMMAP");\r
+\r
+    AsciiPrint ("\n");\r
+  }\r
+\r
+  Status = gDS->GetIoSpaceMap(&NumberOfDescriptors,&IoSpaceMap);\r
+  if (EFI_ERROR (Status)) {\r
+      return Status;\r
+  }\r
+  for (i=0; i < NumberOfDescriptors; i++) {\r
+    AsciiPrint ("IO  %08lx - %08lx",IoSpaceMap[i].BaseAddress,IoSpaceMap[i].BaseAddress+IoSpaceMap[i].Length);\r
+    AsciiPrint ("\t%08x %08x",IoSpaceMap[i].ImageHandle,IoSpaceMap[i].DeviceHandle);\r
+\r
+    if (IoSpaceMap[i].GcdIoType & EfiGcdMemoryTypeNonExistent)\r
+        AsciiPrint (" TYPE_NONEXISTENT");\r
+    if (IoSpaceMap[i].GcdIoType & EfiGcdMemoryTypeReserved)\r
+        AsciiPrint (" TYPE_RESERVED");\r
+    if (IoSpaceMap[i].GcdIoType & EfiGcdIoTypeIo)\r
+        AsciiPrint (" TYPE_IO");\r
+\r
+    AsciiPrint ("\n");\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EblDevicePaths (\r
+  IN UINTN  Argc,\r
+  IN CHAR8  **Argv\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  UINTN                              HandleCount;\r
+  EFI_HANDLE                         *HandleBuffer;\r
+  UINTN                              Index;\r
+  CHAR16*                            String;\r
+  EFI_DEVICE_PATH_PROTOCOL*          DevicePathProtocol;\r
+  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL*  DevicePathToTextProtocol;\r
+\r
+  BdsConnectAllDrivers();\r
 \r
+  Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
+  if (EFI_ERROR (Status)) {\r
+    AsciiPrint ("Did not find the DevicePathToTextProtocol.\n");\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiDevicePathProtocolGuid, NULL, &HandleCount, &HandleBuffer);\r
+  if (EFI_ERROR (Status)) {\r
+    AsciiPrint ("No device path found\n");\r
     return EFI_SUCCESS;\r
+  }\r
+\r
+  for (Index = 0; Index < HandleCount; Index++) {\r
+    Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID **)&DevicePathProtocol);\r
+    String = DevicePathToTextProtocol->ConvertDevicePathToText(DevicePathProtocol,TRUE,TRUE);\r
+    Print (L"[0x%X] %s\n",(UINT32)HandleBuffer[Index], String);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mLibCmdTemplate[] =\r
@@ -372,6 +426,18 @@ GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mLibCmdTemplate[] =
     " dump MMU Table",\r
     NULL,\r
     EblDumpMmu\r
+  },\r
+  {\r
+    "devicepaths",\r
+    " list all the Device Paths",\r
+    NULL,\r
+    EblDevicePaths\r
+  },\r
+  {\r
+    "dumpfdt",\r
+    " dump the current fdt or the one defined in the arguments",\r
+    NULL,\r
+    EblDumpFdt\r
   }\r
 };\r
 \r