1 /** @file
2   Hob command for EBL (Embedded Boot Loader)
3 
4   Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
5   Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6   (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
7 
8   This program and the accompanying materials
9   are licensed and made available under the terms and conditions of the BSD License
10   which accompanies this distribution.  The full text of the license may be found at
11   http://opensource.org/licenses/bsd-license.php
12 
13   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 
16   Module Name:  Hob.c
17 
18   Search/Replace Dir with the name of your new command
19 
20   Boot Mode:
21   ==========
22   BOOT_WITH_FULL_CONFIGURATION                  0x00
23   BOOT_WITH_MINIMAL_CONFIGURATION               0x01
24   BOOT_ASSUMING_NO_CONFIGURATION_CHANGES        0x02
25   BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS 0x03
26   BOOT_WITH_DEFAULT_SETTINGS                    0x04
27   BOOT_ON_S4_RESUME                             0x05
28   BOOT_ON_S5_RESUME                             0x06
29   BOOT_ON_S2_RESUME                             0x10
30   BOOT_ON_S3_RESUME                             0x11
31   BOOT_ON_FLASH_UPDATE                          0x12
32   BOOT_IN_RECOVERY_MODE                         0x20
33   BOOT_IN_RECOVERY_MODE_MASK                    0x40
34   BOOT_SPECIAL_MASK                             0x80
35 
36   Mem Alloc HOB Type:
37   ===================
38   typedef enum {
39     EfiReservedMemoryType       = 0x00
40     EfiLoaderCode               = 0x01
41     EfiLoaderData               = 0x02
42     EfiBootServicesCode         = 0x03
43     EfiBootServicesData         = 0x04
44     EfiRuntimeServicesCode      = 0x05
45     EfiRuntimeServicesData      = 0x06
46     EfiConventionalMemory       = 0x07
47     EfiUnusableMemory           = 0x08
48     EfiACPIReclaimMemory        = 0x09
49     EfiACPIMemoryNVS            = 0x0a
50     EfiMemoryMappedIO           = 0x0b
51     EfiMemoryMappedIOPortSpace  = 0x0c
52     EfiPalCode                  = 0x0d
53     EfiMaxMemoryType            = 0x0e
54   } EFI_MEMORY_TYPE;
55 
56   Resource Hob Tye:
57   =================
58   EFI_RESOURCE_SYSTEM_MEMORY          0
59   EFI_RESOURCE_MEMORY_MAPPED_IO       1
60   EFI_RESOURCE_IO                     2
61   EFI_RESOURCE_FIRMWARE_DEVICE        3
62   EFI_RESOURCE_MEMORY_MAPPED_IO_PORT  4
63   EFI_RESOURCE_MEMORY_RESERVED        5
64   EFI_RESOURCE_IO_RESERVED            6
65   EFI_RESOURCE_MAX_MEMORY_TYPE        7
66 
67   Resource Hob Attribute (last thing printed):
68   ============================================
69   EFI_RESOURCE_ATTRIBUTE_PRESENT                  0x00000001
70   EFI_RESOURCE_ATTRIBUTE_INITIALIZED              0x00000002
71   EFI_RESOURCE_ATTRIBUTE_TESTED                   0x00000004
72   EFI_RESOURCE_ATTRIBUTE_SINGLE_BIT_ECC           0x00000008
73   EFI_RESOURCE_ATTRIBUTE_MULTIPLE_BIT_ECC         0x00000010
74   EFI_RESOURCE_ATTRIBUTE_ECC_RESERVED_1           0x00000020
75   EFI_RESOURCE_ATTRIBUTE_ECC_RESERVED_2           0x00000040
76   EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED           0x00000080
77   EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED          0x00000100
78   EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED      0x00000200
79   EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE              0x00000400
80   EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE        0x00000800
81   EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE  0x00001000
82   EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE     0x00002000
83   EFI_RESOURCE_ATTRIBUTE_16_BIT_IO                0x00004000
84   EFI_RESOURCE_ATTRIBUTE_32_BIT_IO                0x00008000
85   EFI_RESOURCE_ATTRIBUTE_64_BIT_IO                0x00010000
86   EFI_RESOURCE_ATTRIBUTE_UNCACHED_EXPORTED        0x00020000
87 
88 **/
89 
90 #include "Ebl.h"
91 // BugBug: Autogen does not allow this to be included currently
92 //#include <EdkModulePkg/Include/EdkDxe.h>
93 
94 GLOBAL_REMOVE_IF_UNREFERENCED char *mHobResourceType[] = {
95   "Memory     ",
96   "MMIO       ",
97   "IO         ",
98   "Firmware   ",
99   "MMIO Port  ",
100   "Reserved   ",
101   "IO Reserved",
102   "Illegal    "
103 };
104 
105 
106 /**
107   Dump out the HOBs in the system. HOBs are defined in the PI specification
108   and they are used to hand off information from PEI to DXE.
109 
110   Argv[0] - "hob"
111 
112   @param  Argc   Number of command arguments in Argv
113   @param  Argv   Array of strings that represent the parsed command line.
114                  Argv[0] is the command name
115 
116   @return EFI_SUCCESS
117 
118 **/
119 EFI_STATUS
120 EFIAPI
EblHobCmd(IN UINTN Argc,IN CHAR8 ** Argv)121 EblHobCmd (
122   IN UINTN  Argc,
123   IN CHAR8  **Argv
124   )
125 {
126   UINTN                         CurrentRow;
127   EFI_PEI_HOB_POINTERS          Hob;
128   EFI_MEMORY_TYPE_INFORMATION   *EfiMemoryTypeInformation;
129   UINTN                         Index;
130 
131   CurrentRow = 0;
132   for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {
133     if (Hob.Header->HobType == EFI_HOB_TYPE_HANDOFF) {
134       AsciiPrint ("PHIT HOB Ver %x Boot Mode %02x Top %lx  Bottom %lx\n",
135         Hob.HandoffInformationTable->Version,
136         Hob.HandoffInformationTable->BootMode,
137         Hob.HandoffInformationTable->EfiMemoryTop,
138         Hob.HandoffInformationTable->EfiMemoryBottom
139         );
140 
141       if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) {
142         return EFI_SUCCESS;
143       }
144 
145       AsciiPrint ("    Free Top %lx Free Bottom %lx  End Of HOB %lx\n",
146         Hob.HandoffInformationTable->EfiFreeMemoryTop,
147         Hob.HandoffInformationTable->EfiFreeMemoryBottom,
148         Hob.HandoffInformationTable->EfiEndOfHobList
149         );
150 
151     } else if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
152       // mod(%) on array index is just to prevent buffer overrun
153       AsciiPrint ("Mem Alloc HOB %a %g %08lx:%lx\n",
154         (Hob.MemoryAllocation->AllocDescriptor.MemoryType < EfiMaxMemoryType) ? gMemMapType[Hob.MemoryAllocation->AllocDescriptor.MemoryType] : "ILLEGAL TYPE",
155         &Hob.MemoryAllocation->AllocDescriptor.Name,
156         Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress,
157         Hob.MemoryAllocation->AllocDescriptor.MemoryLength
158         );
159       if (CompareGuid (&gEfiHobMemoryAllocModuleGuid, &Hob.MemoryAllocation->AllocDescriptor.Name)) {
160         if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) {
161           return EFI_SUCCESS;
162         }
163         AsciiPrint ("    Module Name %g EntryPoint %lx\n", &Hob.MemoryAllocationModule->ModuleName, Hob.MemoryAllocationModule->EntryPoint);
164       }
165     } else if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
166       AsciiPrint ("Resource HOB %a %g %08lx:%lx\n    Attributes: %08x\n",
167         (Hob.ResourceDescriptor->ResourceType < EFI_RESOURCE_MAX_MEMORY_TYPE) ? mHobResourceType[Hob.ResourceDescriptor->ResourceType] : mHobResourceType[EFI_RESOURCE_MAX_MEMORY_TYPE],
168         &Hob.ResourceDescriptor->Owner,
169         Hob.ResourceDescriptor->PhysicalStart,
170         Hob.ResourceDescriptor->ResourceLength,
171         Hob.ResourceDescriptor->ResourceAttribute
172         );
173         if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) {
174           return EFI_SUCCESS;
175         }
176     } else if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) {
177       AsciiPrint ("GUID HOB %g\n", &Hob.Guid->Name);
178       if (CompareGuid (&gEfiMemoryTypeInformationGuid, &Hob.Guid->Name)) {
179         EfiMemoryTypeInformation = GET_GUID_HOB_DATA (Hob.Guid);
180         for (Index = 0; Index < (GET_GUID_HOB_DATA_SIZE (Hob.Guid)/sizeof (EFI_MEMORY_TYPE_INFORMATION)); Index++, EfiMemoryTypeInformation++) {
181           if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) {
182             return EFI_SUCCESS;
183           }
184           AsciiPrint ("    %a 0x%08x\n",
185             (EfiMemoryTypeInformation->Type < EfiMaxMemoryType) ? gMemMapType[EfiMemoryTypeInformation->Type] : "END       ",
186             EfiMemoryTypeInformation->NumberOfPages
187             );
188        }
189       }
190     } else if (Hob.Header->HobType == EFI_HOB_TYPE_FV) {
191       AsciiPrint ("FV HOB %08lx:%08lx\n", Hob.FirmwareVolume->BaseAddress, Hob.FirmwareVolume->Length);
192     } else if (Hob.Header->HobType == EFI_HOB_TYPE_CPU) {
193       AsciiPrint ("CPU HOB: Mem %x IO %x\n", Hob.Cpu->SizeOfMemorySpace, Hob.Cpu->SizeOfIoSpace);
194     } else if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_POOL) {
195       AsciiPrint ("Mem Pool HOB:\n");
196 /* Not in PI
197     } else if (Hob.Header->HobType == EFI_HOB_TYPE_CV) {
198       AsciiPrint ("CV HOB: %08lx:%08lx\n", Hob.CapsuleVolume->BaseAddress, Hob.CapsuleVolume->Length);
199  */
200     }
201 
202     if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) {
203       break;
204     }
205   }
206 
207   return EFI_SUCCESS;
208 }
209 
210 
211 GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mCmdHobTemplate[] =
212 {
213   {
214     "hob",
215     "; dump HOBs",
216     NULL,
217     EblHobCmd
218   }
219 };
220 
221 
222 /**
223   Initialize the commands in this in this file
224 **/
225 VOID
EblInitializeHobCmd(VOID)226 EblInitializeHobCmd (
227   VOID
228   )
229 {
230   if (FeaturePcdGet (PcdEmbeddedHobCmd)) {
231     EblAddCommands (mCmdHobTemplate, sizeof (mCmdHobTemplate)/sizeof (EBL_COMMAND_TABLE));
232   }
233 }
234 
235