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