]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Disk/CdExpressPei/PeiCdExpress.h
MdeModulePkg/CdExpressPei: Fix capsule size mismatch issue.
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / CdExpressPei / PeiCdExpress.h
1 /** @file
2 Header file for CD recovery PEIM
3
4 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 #ifndef _PEI_CD_EXPRESS_H_
18 #define _PEI_CD_EXPRESS_H_
19
20
21 #include <PiPei.h>
22
23 #include <Ppi/BlockIo.h>
24 #include <Ppi/BlockIo2.h>
25 #include <Guid/RecoveryDevice.h>
26 #include <Ppi/DeviceRecoveryModule.h>
27
28 #include <Library/DebugLib.h>
29 #include <Library/PcdLib.h>
30 #include <Library/PeimEntryPoint.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/PeiServicesTablePointerLib.h>
33 #include <Library/PeiServicesLib.h>
34 #include <Library/MemoryAllocationLib.h>
35
36
37 #pragma pack(1)
38
39 #define PEI_CD_EXPRESS_MAX_BLOCK_IO_PPI 8
40 #define PEI_CD_EXPRESS_MAX_CAPSULE_NUMBER 16
41
42 #define PEI_CD_BLOCK_SIZE 0x800
43 #define PEI_MEMMORY_PAGE_SIZE 0x1000
44
45 //
46 // Recovery file name (in root directory)
47 //
48 #define PEI_RECOVERY_FILE_NAME "FVMAIN.FV"
49
50 //
51 // Following are defined according to ISO-9660 specification
52 //
53 #define PEI_CD_STANDARD_ID "CD001"
54 #define PEI_CD_EXPRESS_STANDARD_ID_SIZE 5
55
56 #define PEI_CD_EXPRESS_VOLUME_TYPE_OFFSET 0
57 #define PEI_CD_EXPRESS_STANDARD_ID_OFFSET 1
58 #define PEI_CD_EXPRESS_VOLUME_SPACE_OFFSET 80
59 #define PEI_CD_EXPRESS_ROOT_DIR_RECORD_OFFSET 156
60
61 #define PEI_CD_EXPRESS_VOLUME_TYPE_PRIMARY 1
62 #define PEI_CD_EXPRESS_VOLUME_TYPE_TERMINATOR 255
63
64 #define PEI_CD_EXPRESS_DIR_FILE_REC_FLAG_ISDIR 0x02
65
66 typedef struct {
67 UINTN CapsuleStartLBA;
68 UINTN CapsuleSize;
69 UINTN CapsuleBlockAlignedSize;
70 UINTN IndexBlock;
71 EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIo;
72 EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2;
73 } PEI_CD_EXPRESS_CAPSULE_DATA;
74
75 #define PEI_CD_EXPRESS_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('p', 'c', 'd', 'e')
76
77 typedef struct {
78
79 UINTN Signature;
80 EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
81 EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
82 EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor;
83 EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor2;
84
85 UINT8 *BlockBuffer;
86 UINTN CapsuleCount;
87 PEI_CD_EXPRESS_CAPSULE_DATA CapsuleData[PEI_CD_EXPRESS_MAX_CAPSULE_NUMBER];
88
89 } PEI_CD_EXPRESS_PRIVATE_DATA;
90
91 #define PEI_CD_EXPRESS_PRIVATE_DATA_FROM_THIS(a) \
92 CR (a, \
93 PEI_CD_EXPRESS_PRIVATE_DATA, \
94 DeviceRecoveryPpi, \
95 PEI_CD_EXPRESS_PRIVATE_DATA_SIGNATURE \
96 )
97
98 typedef struct {
99 UINT8 Length;
100 UINT8 ExtendedAttributeRecordLength;
101 UINT32 LocationOfExtent[2];
102 UINT32 DataLength[2];
103 UINT8 DateTime[7];
104 UINT8 Flag;
105 UINT8 FileUnitSize;
106 UINT8 InterleaveGapSize;
107 UINT32 VolumeSequenceNumber;
108 UINT8 FileIDLength;
109 UINT8 FileID[1];
110 } PEI_CD_EXPRESS_DIR_FILE_RECORD;
111
112 /**
113 BlockIo installation notification function.
114
115 This function finds out all the current Block IO PPIs in the system and add them
116 into private data.
117
118 @param PeiServices Indirect reference to the PEI Services Table.
119 @param NotifyDescriptor Address of the notification descriptor data structure.
120 @param Ppi Address of the PPI that was installed.
121
122 @retval EFI_SUCCESS The function completes successfully.
123
124 **/
125 EFI_STATUS
126 EFIAPI
127 BlockIoNotifyEntry (
128 IN EFI_PEI_SERVICES **PeiServices,
129 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
130 IN VOID *Ppi
131 );
132
133 /**
134 Finds out all the current Block IO PPIs in the system and add them into private data.
135
136 @param PrivateData The private data structure that contains recovery module information.
137 @param BlockIo2 Boolean to show whether using BlockIo2 or BlockIo.
138
139 @retval EFI_SUCCESS The blocks and volumes are updated successfully.
140
141 **/
142 EFI_STATUS
143 UpdateBlocksAndVolumes (
144 IN OUT PEI_CD_EXPRESS_PRIVATE_DATA *PrivateData,
145 IN BOOLEAN BlockIo2
146 );
147
148 /**
149 Returns the number of DXE capsules residing on the device.
150
151 This function searches for DXE capsules from the associated device and returns
152 the number and maximum size in bytes of the capsules discovered. Entry 1 is
153 assumed to be the highest load priority and entry N is assumed to be the lowest
154 priority.
155
156 @param[in] PeiServices General-purpose services that are available
157 to every PEIM
158 @param[in] This Indicates the EFI_PEI_DEVICE_RECOVERY_MODULE_PPI
159 instance.
160 @param[out] NumberRecoveryCapsules Pointer to a caller-allocated UINTN. On
161 output, *NumberRecoveryCapsules contains
162 the number of recovery capsule images
163 available for retrieval from this PEIM
164 instance.
165
166 @retval EFI_SUCCESS One or more capsules were discovered.
167 @retval EFI_DEVICE_ERROR A device error occurred.
168 @retval EFI_NOT_FOUND A recovery DXE capsule cannot be found.
169
170 **/
171 EFI_STATUS
172 EFIAPI
173 GetNumberRecoveryCapsules (
174 IN EFI_PEI_SERVICES **PeiServices,
175 IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
176 OUT UINTN *NumberRecoveryCapsules
177 );
178
179 /**
180 Returns the size and type of the requested recovery capsule.
181
182 This function gets the size and type of the capsule specified by CapsuleInstance.
183
184 @param[in] PeiServices General-purpose services that are available to every PEIM
185 @param[in] This Indicates the EFI_PEI_DEVICE_RECOVERY_MODULE_PPI
186 instance.
187 @param[in] CapsuleInstance Specifies for which capsule instance to retrieve
188 the information. This parameter must be between
189 one and the value returned by GetNumberRecoveryCapsules()
190 in NumberRecoveryCapsules.
191 @param[out] Size A pointer to a caller-allocated UINTN in which
192 the size of the requested recovery module is
193 returned.
194 @param[out] CapsuleType A pointer to a caller-allocated EFI_GUID in which
195 the type of the requested recovery capsule is
196 returned. The semantic meaning of the value
197 returned is defined by the implementation.
198
199 @retval EFI_SUCCESS One or more capsules were discovered.
200 @retval EFI_DEVICE_ERROR A device error occurred.
201 @retval EFI_NOT_FOUND A recovery DXE capsule cannot be found.
202
203 **/
204 EFI_STATUS
205 EFIAPI
206 GetRecoveryCapsuleInfo (
207 IN EFI_PEI_SERVICES **PeiServices,
208 IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
209 IN UINTN CapsuleInstance,
210 OUT UINTN *Size,
211 OUT EFI_GUID *CapsuleType
212 );
213
214 /**
215 Loads a DXE capsule from some media into memory.
216
217 This function, by whatever mechanism, retrieves a DXE capsule from some device
218 and loads it into memory. Note that the published interface is device neutral.
219
220 @param[in] PeiServices General-purpose services that are available
221 to every PEIM
222 @param[in] This Indicates the EFI_PEI_DEVICE_RECOVERY_MODULE_PPI
223 instance.
224 @param[in] CapsuleInstance Specifies which capsule instance to retrieve.
225 @param[out] Buffer Specifies a caller-allocated buffer in which
226 the requested recovery capsule will be returned.
227
228 @retval EFI_SUCCESS The capsule was loaded correctly.
229 @retval EFI_DEVICE_ERROR A device error occurred.
230 @retval EFI_NOT_FOUND A requested recovery DXE capsule cannot be found.
231
232 **/
233 EFI_STATUS
234 EFIAPI
235 LoadRecoveryCapsule (
236 IN EFI_PEI_SERVICES **PeiServices,
237 IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
238 IN UINTN CapsuleInstance,
239 OUT VOID *Buffer
240 );
241
242 /**
243 Finds out the recovery capsule in the current volume.
244
245 @param PrivateData The private data structure that contains recovery module information.
246
247 @retval EFI_SUCCESS The recovery capsule is successfully found in the volume.
248 @retval EFI_NOT_FOUND The recovery capsule is not found in the volume.
249
250 **/
251 EFI_STATUS
252 EFIAPI
253 FindRecoveryCapsules (
254 IN OUT PEI_CD_EXPRESS_PRIVATE_DATA *PrivateData
255 );
256
257 /**
258 Retrieves the recovery capsule in root directory of the current volume.
259
260 @param PrivateData The private data structure that contains recovery module information.
261 @param BlockIoPpi The Block IO PPI used to access the volume.
262 @param BlockIo2Ppi The Block IO 2 PPI used to access the volume.
263 @param IndexBlockDevice The index of current block device.
264 @param Lba The starting logic block address to retrieve capsule.
265
266 @retval EFI_SUCCESS The recovery capsule is successfully found in the volume.
267 @retval EFI_NOT_FOUND The recovery capsule is not found in the volume.
268 @retval Others
269
270 **/
271 EFI_STATUS
272 EFIAPI
273 RetrieveCapsuleFileFromRoot (
274 IN OUT PEI_CD_EXPRESS_PRIVATE_DATA *PrivateData,
275 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIoPpi,
276 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2Ppi,
277 IN UINTN IndexBlockDevice,
278 IN UINT32 Lba
279 );
280
281
282 /**
283 This function compares two ASCII strings in case sensitive/insensitive way.
284
285 @param Source1 The first string.
286 @param Source2 The second string.
287 @param Size The maximum comparison length.
288 @param CaseSensitive Flag to indicate whether the comparison is case sensitive.
289
290 @retval TRUE The two strings are the same.
291 @retval FALSE The two string are not the same.
292
293 **/
294 BOOLEAN
295 StringCmp (
296 IN UINT8 *Source1,
297 IN UINT8 *Source2,
298 IN UINTN Size,
299 IN BOOLEAN CaseSensitive
300 );
301
302 #pragma pack()
303
304 #endif