]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - EmbeddedPkg/TemplateBds/FirmwareVolume.c
Fix VS2003 cast issue
[mirror_edk2.git] / EmbeddedPkg / TemplateBds / FirmwareVolume.c
... / ...
CommitLineData
1/** @file\r
2 The entry of the embedded BDS. This BDS does not follow the Boot Manager requirements \r
3 of the UEFI specification as it is designed to implement an embedded systmes \r
4 propriatary boot scheme.\r
5\r
6 This template assume a DXE driver produces a SerialIo protocol not using the EFI \r
7 driver module and it will attempt to connect a console on top of this.\r
8\r
9 Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
10 \r
11 All rights reserved. This program and the accompanying materials\r
12 are licensed and made available under the terms and conditions of the BSD License\r
13 which accompanies this distribution. The full text of the license may be found at\r
14 http://opensource.org/licenses/bsd-license.php\r
15\r
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
18\r
19**/\r
20\r
21#include "BdsEntry.h"\r
22\r
23\r
24EFI_STATUS\r
25FindApplicationMatchingUiSection (\r
26 IN CHAR16 *UiString,\r
27 OUT EFI_HANDLE *FvHandle,\r
28 OUT EFI_GUID **NameGuid\r
29 )\r
30{\r
31 EFI_STATUS Status;\r
32 EFI_STATUS NextStatus;\r
33 UINTN NoHandles;\r
34 EFI_HANDLE *Buffer;\r
35 UINTN Index;\r
36 EFI_FV_FILETYPE FileType;\r
37 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
38 VOID *Key;\r
39 EFI_FV_FILE_ATTRIBUTES Attributes;\r
40 UINTN Size;\r
41 UINTN UiStringLen;\r
42 CHAR16 *UiSection;\r
43 UINT32 Authentication;\r
44 \r
45 \r
46 UiStringLen = 0;\r
47 if (UiString != NULL) {\r
48 UiStringLen = StrLen (UiString);\r
49 }\r
50 \r
51 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NoHandles, &Buffer);\r
52 if (!EFI_ERROR (Status)) {\r
53 for (Index = 0; Index < NoHandles; Index++) {\r
54 Status = gBS->HandleProtocol (Buffer[Index], &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Fv);\r
55 if (!EFI_ERROR (Status)) {\r
56 Key = AllocatePool (Fv->KeySize);\r
57 FileType = EFI_FV_FILETYPE_APPLICATION;\r
58 \r
59 do {\r
60 NextStatus = Fv->GetNextFile (Fv, Key, &FileType, *NameGuid, &Attributes, &Size);\r
61 if (!EFI_ERROR (NextStatus)) {\r
62 if (UiString == NULL) {\r
63 //\r
64 // If UiString is NULL match first application we find.\r
65 //\r
66 *FvHandle = Buffer[Index];\r
67 FreePool (Key);\r
68 return Status;\r
69 }\r
70 \r
71 UiSection = NULL;\r
72 Status = Fv->ReadSection (\r
73 Fv, \r
74 *NameGuid, \r
75 EFI_SECTION_USER_INTERFACE, \r
76 0,\r
77 (VOID **)&UiSection,\r
78 &Size,\r
79 &Authentication\r
80 );\r
81 if (!EFI_ERROR (Status)) {\r
82 if (StrnCmp (UiString, UiSection, UiStringLen)) {\r
83 //\r
84 // We found a UiString match. \r
85 //\r
86 *FvHandle = Buffer[Index];\r
87 FreePool (Key);\r
88 FreePool (UiSection);\r
89 return Status;\r
90 }\r
91 FreePool (UiSection);\r
92 }\r
93 }\r
94 } while (!EFI_ERROR (NextStatus));\r
95 \r
96 FreePool (Key);\r
97 }\r
98 }\r
99 \r
100 FreePool (Buffer);\r
101 }\r
102\r
103 return EFI_NOT_FOUND;\r
104}\r
105\r
106\r
107EFI_DEVICE_PATH *\r
108FvFileDevicePath (\r
109 IN EFI_HANDLE FvHandle,\r
110 IN EFI_GUID *NameGuid\r
111 )\r
112{ \r
113 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
114 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH NewNode;\r
115\r
116 DevicePath = DevicePathFromHandle (FvHandle);\r
117\r
118 EfiInitializeFwVolDevicepathNode (&NewNode, NameGuid);\r
119 \r
120 return AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&NewNode);\r
121}\r
122\r
123\r
124\r
125EFI_STATUS\r
126LoadPeCoffSectionFromFv (\r
127 IN EFI_HANDLE FvHandle, \r
128 IN EFI_GUID *NameGuid\r
129 )\r
130{\r
131 EFI_STATUS Status;\r
132 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
133 VOID *Buffer;\r
134 UINTN BufferSize;\r
135 UINT32 Authentication;\r
136 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
137 EFI_HANDLE ImageHandle;\r
138\r
139 Status = gBS->HandleProtocol (FvHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Fv);\r
140 if (EFI_ERROR (Status)) {\r
141 return Status;\r
142 }\r
143\r
144 Status = Fv->ReadSection (Fv, NameGuid, EFI_SECTION_PE32, 0, &Buffer, &BufferSize, &Authentication);\r
145 if (!EFI_ERROR (Status)) {\r
146 DevicePath = FvFileDevicePath (FvHandle, NameGuid);\r
147 Status = gBS->LoadImage (TRUE, gImageHandle, DevicePath, Buffer, BufferSize, &ImageHandle);\r
148 if (!EFI_ERROR (Status)) {\r
149 // ExitData is NULL so we need to pass in a size of zero\r
150 BufferSize = 0;\r
151 Status = gBS->StartImage (ImageHandle, &BufferSize, NULL);\r
152 }\r
153 \r
154 FreePool (Buffer);\r
155 }\r
156\r
157 \r
158 return Status;\r
159}\r
160 \r