/** @file\r
PlatformHelperLib function prototype definitions.\r
\r
-Copyright (c) 2013 Intel Corporation.\r
+Copyright (c) 2013 - 2016 Intel Corporation.
\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
IN CONST BOOLEAN PreBootPolicy\r
);\r
\r
-/**\r
- Erase and Write to platform flash.\r
-\r
- Routine accesses one flash block at a time, each access consists\r
- of an erase followed by a write of FLASH_BLOCK_SIZE. One or both\r
- of DoErase & DoWrite params must be TRUE.\r
-\r
- Limitations:-\r
- CpuWriteAddress must be aligned to FLASH_BLOCK_SIZE.\r
- DataSize must be a multiple of FLASH_BLOCK_SIZE.\r
-\r
- @param Smst If != NULL then InSmm and use to locate\r
- SpiProtocol.\r
- @param CpuWriteAddress Address in CPU memory map of flash region.\r
- @param Data The buffer containing the data to be written.\r
- @param DataSize Amount of data to write.\r
- @param DoErase Earse each block.\r
- @param DoWrite Write to each block.\r
-\r
- @retval EFI_SUCCESS Operation successful.\r
- @retval EFI_NOT_READY Required resources not setup.\r
- @retval EFI_INVALID_PARAMETER Invalid parameter.\r
- @retval Others Unexpected error happened.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PlatformFlashEraseWrite (\r
- IN VOID *Smst,\r
- IN UINTN CpuWriteAddress,\r
- IN UINT8 *Data,\r
- IN UINTN DataSize,\r
- IN BOOLEAN DoErase,\r
- IN BOOLEAN DoWrite\r
- );\r
-\r
/** Check if System booted with recovery Boot Stage1 image.\r
\r
@retval TRUE If system booted with recovery Boot Stage1 image.\r
}\r
}\r
\r
-/**\r
- Erase and Write to platform flash.\r
-\r
- Routine accesses one flash block at a time, each access consists\r
- of an erase followed by a write of FLASH_BLOCK_SIZE. One or both\r
- of DoErase & DoWrite params must be TRUE.\r
-\r
- Limitations:-\r
- CpuWriteAddress must be aligned to FLASH_BLOCK_SIZE.\r
- DataSize must be a multiple of FLASH_BLOCK_SIZE.\r
-\r
- @param Smst If != NULL then InSmm and use to locate\r
- SpiProtocol.\r
- @param CpuWriteAddress Address in CPU memory map of flash region.\r
- @param Data The buffer containing the data to be written.\r
- @param DataSize Amount of data to write.\r
- @param DoErase Earse each block.\r
- @param DoWrite Write to each block.\r
-\r
- @retval EFI_SUCCESS Operation successful.\r
- @retval EFI_NOT_READY Required resources not setup.\r
- @retval EFI_INVALID_PARAMETER Invalid parameter.\r
- @retval Others Unexpected error happened.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PlatformFlashEraseWrite (\r
- IN VOID *Smst,\r
- IN UINTN CpuWriteAddress,\r
- IN UINT8 *Data,\r
- IN UINTN DataSize,\r
- IN BOOLEAN DoErase,\r
- IN BOOLEAN DoWrite\r
- )\r
-{\r
- EFI_STATUS Status;\r
- UINT64 CpuBaseAddress;\r
- SPI_INIT_INFO *SpiInfo;\r
- UINT8 *WriteBuf;\r
- UINTN Index;\r
- UINTN SpiWriteAddress;\r
- EFI_SPI_PROTOCOL *SpiProtocol;\r
-\r
- if (!DoErase && !DoWrite) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if (DoWrite && Data == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if ((CpuWriteAddress % FLASH_BLOCK_SIZE) != 0) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- if ((DataSize % FLASH_BLOCK_SIZE) != 0) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- SpiProtocol = LocateSpiProtocol ((EFI_SMM_SYSTEM_TABLE2 *)Smst);\r
- if (SpiProtocol == NULL) {\r
- return EFI_NOT_READY;\r
- }\r
-\r
- //\r
- // Find info to allow usage of SpiProtocol->Execute.\r
- //\r
- Status = SpiProtocol->Info (\r
- SpiProtocol,\r
- &SpiInfo\r
- );\r
- if (EFI_ERROR(Status)) {\r
- return Status;\r
- }\r
- ASSERT (SpiInfo->InitTable != NULL);\r
- ASSERT (SpiInfo->EraseOpcodeIndex < SPI_NUM_OPCODE);\r
- ASSERT (SpiInfo->ProgramOpcodeIndex < SPI_NUM_OPCODE);\r
-\r
- CpuBaseAddress = PcdGet32 (PcdFlashAreaBaseAddress) - (UINT32)SpiInfo->InitTable->BiosStartOffset;\r
- ASSERT(CpuBaseAddress >= (SIZE_4GB - SIZE_8MB));\r
- if (CpuWriteAddress < CpuBaseAddress) {\r
- return (EFI_INVALID_PARAMETER);\r
- }\r
-\r
- SpiWriteAddress = CpuWriteAddress - ((UINTN) CpuBaseAddress);\r
- WriteBuf = Data;\r
- DEBUG (\r
- (EFI_D_INFO, "PlatformFlashWrite:SpiWriteAddress=%08x EraseIndex=%d WriteIndex=%d\n",\r
- SpiWriteAddress,\r
- (UINTN) SpiInfo->EraseOpcodeIndex,\r
- (UINTN) SpiInfo->ProgramOpcodeIndex\r
- ));\r
- for (Index =0; Index < DataSize / FLASH_BLOCK_SIZE; Index++) {\r
- if (DoErase) {\r
- DEBUG (\r
- (EFI_D_INFO, "PlatformFlashWrite:Erase[%04x] SpiWriteAddress=%08x\n",\r
- Index,\r
- SpiWriteAddress\r
- ));\r
- Status = SpiProtocol->Execute (\r
- SpiProtocol,\r
- SpiInfo->EraseOpcodeIndex,// OpcodeIndex\r
- 0, // PrefixOpcodeIndex\r
- FALSE, // DataCycle\r
- TRUE, // Atomic\r
- FALSE, // ShiftOut\r
- SpiWriteAddress, // Address\r
- 0, // Data Number\r
- NULL,\r
- EnumSpiRegionAll // SPI_REGION_TYPE\r
- );\r
- if (EFI_ERROR(Status)) {\r
- return Status;\r
- }\r
- }\r
-\r
- if (DoWrite) {\r
- DEBUG (\r
- (EFI_D_INFO, "PlatformFlashWrite:Write[%04x] SpiWriteAddress=%08x\n",\r
- Index,\r
- SpiWriteAddress\r
- ));\r
- Status = SpiProtocol->Execute (\r
- SpiProtocol,\r
- SpiInfo->ProgramOpcodeIndex, // OpcodeIndex\r
- 0, // PrefixOpcodeIndex\r
- TRUE, // DataCycle\r
- TRUE, // Atomic\r
- TRUE, // ShiftOut\r
- SpiWriteAddress, // Address\r
- FLASH_BLOCK_SIZE, // Data Number\r
- WriteBuf,\r
- EnumSpiRegionAll\r
- );\r
- if (EFI_ERROR(Status)) {\r
- return Status;\r
- }\r
- WriteBuf+=FLASH_BLOCK_SIZE;\r
- }\r
- SpiWriteAddress+=FLASH_BLOCK_SIZE;\r
- }\r
- return EFI_SUCCESS;\r
-}\r
-\r
/** Check if System booted with recovery Boot Stage1 image.\r
\r
@retval TRUE If system booted with recovery Boot Stage1 image.\r