13CHAR8 *mRecoveryFileName;
14UINTN mRecoveryFileNameSize;
42 if (PrivateData ==
NULL) {
43 return EFI_OUT_OF_RESOURCES;
46 mRecoveryFileNameSize =
PcdGetSize (PcdRecoveryFileName) /
sizeof (CHAR16);
47 mRecoveryFileName =
AllocatePool (mRecoveryFileNameSize);
48 if (mRecoveryFileName ==
NULL) {
49 return EFI_OUT_OF_RESOURCES;
53 if (EFI_ERROR (Status)) {
60 ZeroMem (PrivateData,
sizeof (*PrivateData));
61 PrivateData->Signature = PEI_CD_EXPRESS_PRIVATE_DATA_SIGNATURE;
64 if (PrivateData->BlockBuffer ==
NULL) {
65 return EFI_OUT_OF_RESOURCES;
68 PrivateData->CapsuleCount = 0;
79 PrivateData->PpiDescriptor.
Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
80 PrivateData->PpiDescriptor.
Guid = &gEfiPeiDeviceRecoveryModulePpiGuid;
81 PrivateData->PpiDescriptor.
Ppi = &PrivateData->DeviceRecoveryPpi;
84 if (EFI_ERROR (Status)) {
85 return EFI_OUT_OF_RESOURCES;
91 mPrivateData = PrivateData;
96 PrivateData->NotifyDescriptor.
Flags =
98 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
100 PrivateData->NotifyDescriptor.
Guid = &gEfiPeiVirtualBlockIoPpiGuid;
103 PrivateData->NotifyDescriptor2.
Flags =
105 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
106 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
108 PrivateData->NotifyDescriptor2.
Guid = &gEfiPeiVirtualBlockIo2PpiGuid;
135 if (
CompareGuid (NotifyDescriptor->Guid, &gEfiPeiVirtualBlockIo2PpiGuid)) {
161 UINTN BlockIoPpiInstance;
164 UINTN NumberBlockDevices;
165 UINTN IndexBlockDevice;
170 IndexBlockDevice = 0;
177 for (BlockIoPpiInstance = 0; BlockIoPpiInstance < PEI_CD_EXPRESS_MAX_BLOCK_IO_PPI; BlockIoPpiInstance++) {
180 &gEfiPeiVirtualBlockIo2PpiGuid,
183 (VOID **)&BlockIo2Ppi
187 &gEfiPeiVirtualBlockIoPpiGuid,
194 if (EFI_ERROR (Status)) {
216 if (EFI_ERROR (Status) || (NumberBlockDevices == 0)) {
223 for (IndexBlockDevice = 1; IndexBlockDevice <= NumberBlockDevices && PrivateData->CapsuleCount < PEI_CD_EXPRESS_MAX_CAPSULE_NUMBER; IndexBlockDevice++) {
231 if (EFI_ERROR (Status) ||
242 DEBUG ((DEBUG_INFO,
"PeiCdExpress BlockSize is 0x%x\n", Media2.
BlockSize));
250 if (EFI_ERROR (Status) ||
259 DEBUG ((DEBUG_INFO,
"PeiCdExpress DeviceType is %d\n", Media.
DeviceType));
261 DEBUG ((DEBUG_INFO,
"PeiCdExpress BlockSize is 0x%x\n", Media.
BlockSize));
264 DEBUG ((DEBUG_INFO,
"PeiCdExpress Status is %d\n", Status));
266 DEBUG ((DEBUG_INFO,
"IndexBlockDevice is %d\n", IndexBlockDevice));
267 PrivateData->CapsuleData[PrivateData->CapsuleCount].IndexBlock = IndexBlockDevice;
269 PrivateData->CapsuleData[PrivateData->CapsuleCount].BlockIo2 = BlockIo2Ppi;
271 PrivateData->CapsuleData[PrivateData->CapsuleCount].BlockIo = BlockIoPpi;
275 DEBUG ((DEBUG_INFO,
"Status is %d\n", Status));
277 if (EFI_ERROR (Status)) {
281 PrivateData->CapsuleCount++;
313 UINTN VolumeSpaceSize;
314 BOOLEAN StartOfVolume;
316 UINTN IndexBlockDevice;
318 Buffer = PrivateData->BlockBuffer;
319 BufferSize = PEI_CD_BLOCK_SIZE;
325 IndexBlockDevice = PrivateData->CapsuleData[PrivateData->CapsuleCount].IndexBlock;
326 BlockIoPpi = PrivateData->CapsuleData[PrivateData->CapsuleCount].BlockIo;
327 BlockIo2Ppi = PrivateData->CapsuleData[PrivateData->CapsuleCount].BlockIo2;
330 StartOfVolume =
TRUE;
334 SetMem (Buffer, BufferSize, 0);
335 if (BlockIo2Ppi !=
NULL) {
355 if (EFI_ERROR (Status)) {
359 StandardID = (UINT8 *)(Buffer + PEI_CD_EXPRESS_STANDARD_ID_OFFSET);
360 if (!
StringCmp (StandardID, (UINT8 *)PEI_CD_STANDARD_ID, PEI_CD_EXPRESS_STANDARD_ID_SIZE,
TRUE)) {
366 StartOfVolume =
FALSE;
369 Type = *(UINT8 *)(Buffer + PEI_CD_EXPRESS_VOLUME_TYPE_OFFSET);
370 if (Type == PEI_CD_EXPRESS_VOLUME_TYPE_TERMINATOR) {
371 if (VolumeSpaceSize == 0) {
374 Lba = (OriginalLBA + VolumeSpaceSize);
376 StartOfVolume =
TRUE;
381 if (Type != PEI_CD_EXPRESS_VOLUME_TYPE_PRIMARY) {
386 VolumeSpaceSize = *(UINT32 *)(Buffer + PEI_CD_EXPRESS_VOLUME_SPACE_OFFSET);
389 RootDirLBA = RoorDirRecord->LocationOfExtent[0];
392 if (!EFI_ERROR (Status)) {
402 return EFI_NOT_FOUND;
435 Buffer = PrivateData->BlockBuffer;
436 BufferSize = PEI_CD_BLOCK_SIZE;
438 SetMem (Buffer, BufferSize, 0);
440 if (BlockIo2Ppi !=
NULL) {
441 Status = BlockIo2Ppi->ReadBlocks (
450 Status = BlockIoPpi->ReadBlocks (
460 if (EFI_ERROR (Status)) {
467 if (FileRecord->Length == 0) {
474 if ((FileRecord->Flag & PEI_CD_EXPRESS_DIR_FILE_REC_FLAG_ISDIR) != 0) {
475 Buffer += FileRecord->Length;
479 for (Index = 0; Index < FileRecord->FileIDLength; Index++) {
480 if (FileRecord->FileID[Index] ==
';') {
485 if (Index != mRecoveryFileNameSize - 1) {
486 Buffer += FileRecord->Length;
490 if (!
StringCmp (FileRecord->FileID, (UINT8 *)mRecoveryFileName, mRecoveryFileNameSize - 1,
FALSE)) {
491 Buffer += FileRecord->Length;
495 PrivateData->CapsuleData[PrivateData->CapsuleCount].CapsuleStartLBA = FileRecord->LocationOfExtent[0];
496 PrivateData->CapsuleData[PrivateData->CapsuleCount].CapsuleBlockAlignedSize =
498 FileRecord->DataLength[0] /
503 PrivateData->CapsuleData[PrivateData->CapsuleCount].CapsuleSize = FileRecord->DataLength[0];
508 return EFI_NOT_FOUND;
544 PrivateData = PEI_CD_EXPRESS_PRIVATE_DATA_FROM_THIS (This);
547 *NumberRecoveryCapsules = PrivateData->CapsuleCount;
549 if (*NumberRecoveryCapsules == 0) {
550 return EFI_NOT_FOUND;
592 UINTN NumberRecoveryCapsules;
597 if (EFI_ERROR (Status)) {
601 if ((CapsuleInstance == 0) || (CapsuleInstance > NumberRecoveryCapsules)) {
602 return EFI_NOT_FOUND;
605 PrivateData = PEI_CD_EXPRESS_PRIVATE_DATA_FROM_THIS (This);
607 *Size = PrivateData->CapsuleData[CapsuleInstance - 1].CapsuleSize;
610 &gRecoveryOnDataCdGuid,
649 UINTN NumberRecoveryCapsules;
653 if (EFI_ERROR (Status)) {
657 if ((CapsuleInstance == 0) || (CapsuleInstance > NumberRecoveryCapsules)) {
658 return EFI_NOT_FOUND;
661 PrivateData = PEI_CD_EXPRESS_PRIVATE_DATA_FROM_THIS (This);
662 BlockIoPpi = PrivateData->CapsuleData[CapsuleInstance - 1].BlockIo;
663 BlockIo2Ppi = PrivateData->CapsuleData[CapsuleInstance - 1].BlockIo2;
665 if (BlockIo2Ppi !=
NULL) {
669 PrivateData->CapsuleData[CapsuleInstance - 1].IndexBlock,
670 PrivateData->CapsuleData[CapsuleInstance - 1].CapsuleStartLBA,
671 PrivateData->CapsuleData[CapsuleInstance - 1].CapsuleBlockAlignedSize,
678 PrivateData->CapsuleData[CapsuleInstance - 1].IndexBlock,
679 PrivateData->CapsuleData[CapsuleInstance - 1].CapsuleStartLBA,
680 PrivateData->CapsuleData[CapsuleInstance - 1].CapsuleBlockAlignedSize,
705 IN BOOLEAN CaseSensitive
711 for (Index = 0; Index < Size; Index++) {
712 if (Source1[Index] == Source2[Index]) {
716 if (!CaseSensitive) {
717 Dif = (UINT8)((Source1[Index] > Source2[Index]) ? (Source1[Index] - Source2[Index]) : (Source2[Index] - Source1[Index]));
718 if (Dif == (
'a' -
'A')) {
CONST EFI_PEI_SERVICES **EFIAPI GetPeiServicesTablePointer(VOID)
RETURN_STATUS EFIAPI UnicodeStrToAsciiStrS(IN CONST CHAR16 *Source, OUT CHAR8 *Destination, IN UINTN DestMax)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI PeiServicesNotifyPpi(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
EFI_STATUS EFIAPI PeiServicesRegisterForShadow(IN EFI_PEI_FILE_HANDLE FileHandle)
#define DEBUG(Expression)
@ IdeCDROM
The recovery device is an IDE CD-ROM.
@ UsbMassStorage
The recovery device is a USB Mass Storage device.
#define PcdGetSize(TokenName)
#define PcdGetPtr(TokenName)
EFI_STATUS UpdateBlocksAndVolumes(IN OUT PEI_CD_EXPRESS_PRIVATE_DATA *PrivateData, IN BOOLEAN BlockIo2)
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)
EFI_STATUS EFIAPI FindRecoveryCapsules(IN OUT PEI_CD_EXPRESS_PRIVATE_DATA *PrivateData)
EFI_STATUS EFIAPI GetNumberRecoveryCapsules(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This, OUT UINTN *NumberRecoveryCapsules)
EFI_STATUS EFIAPI BlockIoNotifyEntry(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
EFI_STATUS EFIAPI LoadRecoveryCapsule(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This, IN UINTN CapsuleInstance, OUT VOID *Buffer)
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)
BOOLEAN StringCmp(IN UINT8 *Source1, IN UINT8 *Source2, IN UINTN Size, IN BOOLEAN CaseSensitive)
EFI_STATUS EFIAPI CdExpressPeimEntry(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
VOID * EFI_PEI_FILE_HANDLE
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
#define EFI_SIZE_TO_PAGES(Size)
EFI_PEI_DEVICE_GET_NUMBER_RECOVERY_CAPSULE GetNumberRecoveryCapsules
Returns the number of DXE capsules residing on the device.
EFI_PEI_DEVICE_LOAD_RECOVERY_CAPSULE LoadRecoveryCapsule
Loads a DXE capsule from some media into memory.
EFI_PEI_DEVICE_GET_RECOVERY_CAPSULE_INFO GetRecoveryCapsuleInfo
Returns the size and type of the requested recovery capsule.
EFI_PEIM_NOTIFY_ENTRY_POINT Notify
EFI_PEI_READ_BLOCKS2 ReadBlocks
EFI_PEI_GET_DEVICE_MEDIA_INFORMATION2 GetBlockDeviceMediaInfo
EFI_PEI_GET_NUMBER_BLOCK_DEVICES2 GetNumberOfBlockDevices
EFI_PEI_READ_BLOCKS ReadBlocks
EFI_PEI_GET_NUMBER_BLOCK_DEVICES GetNumberOfBlockDevices
EFI_PEI_GET_DEVICE_MEDIA_INFORMATION GetBlockDeviceMediaInfo
EFI_PEI_BLOCK_DEVICE_TYPE DeviceType