]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/Pei/PeiLib/FindFv.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Pei / PeiLib / FindFv.c
CommitLineData
3eb9473e 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12\r
13Module Name:\r
14 \r
15 FindFv.c\r
16 \r
17Abstract:\r
18\r
19 Library function to find fv by hob.\r
20\r
21--*/\r
22\r
23#include "Tiano.h"\r
24#include "Pei.h"\r
25#include "PeiLib.h"\r
26#include "PeiHobLib.h"\r
27#include "EfiCommonLib.h"\r
28#include EFI_GUID_DEFINITION (FirmwareFileSystem)\r
29\r
30static\r
31VOID *\r
32GetHob (\r
33 IN UINT16 Type,\r
34 IN VOID *HobStart\r
35 )\r
36/*++\r
37\r
38Routine Description:\r
39\r
40 This function returns the first instance of a HOB type in a HOB list.\r
41 \r
42Arguments:\r
43\r
44 Type The HOB type to return.\r
45 HobStart The first HOB in the HOB list.\r
46 \r
47Returns:\r
48\r
49 HobStart There were no HOBs found with the requested type.\r
50 else Returns the first HOB with the matching type.\r
51\r
52--*/\r
53{\r
54 EFI_PEI_HOB_POINTERS Hob;\r
55\r
56 Hob.Raw = HobStart;\r
57 //\r
58 // Return input if not found\r
59 //\r
60 if (HobStart == NULL) {\r
61 return HobStart;\r
62 }\r
63\r
64 //\r
65 // Parse the HOB list, stop if end of list or matching type found.\r
66 //\r
67 while (!END_OF_HOB_LIST (Hob)) {\r
68\r
69 if (Hob.Header->HobType == Type) {\r
70 break;\r
71 }\r
72\r
73 Hob.Raw = GET_NEXT_HOB (Hob);\r
74 }\r
75 \r
76 //\r
77 // Return input if not found\r
78 //\r
79 if (END_OF_HOB_LIST (Hob)) {\r
80 return HobStart;\r
81 }\r
82\r
83 return (VOID *) (Hob.Raw);\r
84}\r
85\r
86EFI_STATUS\r
87FindFv (\r
88 IN EFI_FIND_FV_PPI *This,\r
89 IN EFI_PEI_SERVICES **PeiServices,\r
90 IN OUT UINT8 *FvNumber,\r
91 IN OUT EFI_FIRMWARE_VOLUME_HEADER **FvAddress\r
92 )\r
93/*++\r
94\r
95Routine Description:\r
96\r
97 Search Fv which supports FFS.\r
98\r
99Arguments:\r
100 \r
101 This - Interface pointer that implement the Find Fv PPI\r
102 \r
103 PeiServices - Pointer to the PEI Service Table\r
104 \r
105 FvNumber - On input, the number of the fireware volume which supports FFS to locate\r
106 On output, the next FV number which supports FFS.\r
107 \r
108 FVAddress - The address of the volume which supports FFS to discover\r
109\r
110Returns:\r
111\r
112 EFI_SUCCESS - An addtional FV which supports FFS found\r
113 EFI_OUT_OF_RESOURCES - There are no fireware volume which supports FFS for given fvnumber\r
114 EFI_INVALID_PARAMETER - FvAddress is NULL\r
115\r
116--*/\r
117{\r
118 EFI_STATUS Status;\r
119 EFI_PEI_HOB_POINTERS HobStart;\r
120 EFI_PEI_HOB_POINTERS Hob;\r
121 EFI_HOB_FIRMWARE_VOLUME *FvHob;\r
122 UINT8 FvIndex;\r
123\r
124 if (FvAddress == NULL){\r
125 return EFI_INVALID_PARAMETER;\r
126 }\r
127\r
128 Hob.Raw = NULL;\r
129 FvIndex = 0;\r
130\r
131 //\r
132 // Get the Hob table pointer\r
133 //\r
134 Status = (*PeiServices)->GetHobList (\r
135 PeiServices,\r
136 &HobStart.Raw\r
137 );\r
138\r
139 if (EFI_ERROR (Status)) {\r
140 return EFI_OUT_OF_RESOURCES;\r
141 }\r
142 \r
143 //\r
144 // Loop to search the wanted FirmwareVolume which supports FFS\r
145 //\r
146 //\r
147 while (FvIndex <= *FvNumber) {\r
148 \r
149 Hob.Raw = GetHob (EFI_HOB_TYPE_FV, HobStart.Raw); \r
150 \r
151 //\r
152 // If the Hob is not EFI_HOB_TYPE_FV, it indicates that\r
153 // we have finished all FV volumes search, and there is no\r
154 // the FFS FV specified by FvNumber.\r
155 //\r
156 if (Hob.Header->HobType != EFI_HOB_TYPE_FV) {\r
157 *FvNumber = 0;\r
158 return EFI_OUT_OF_RESOURCES;\r
159 }\r
160 \r
161 HobStart.Raw = Hob.Raw + Hob.Header->HobLength;\r
162 FvHob = Hob.FirmwareVolume;\r
163 *FvAddress = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvHob->BaseAddress);\r
164 //\r
165 // Check if the FV supports FFS\r
166 //\r
167 if (EfiCompareGuid (&((*FvAddress)->FileSystemGuid), &gEfiFirmwareFileSystemGuid)) {\r
168 FvIndex++;\r
169 }\r
170 }\r
171 \r
172 //\r
173 // Return the next FV number which supports FFS.\r
174 //\r
175 (*FvNumber)++;\r
176 \r
177 return EFI_SUCCESS;\r
178\r
179}\r