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