Parse how to write flash in uefi shell.

Step:

1.     Enable

2.     Read

3.     Write

4.     Disable

FI_GUID gEfiSFlashProtocolGuid = FLASH_PROTOCOL_GUID;
FLASH_PROTOCOL*  pFlashProtocol;
EFI_PHYSICAL_ADDRESS        Flash4GBMapStart;
EFI_STATUS   Status;
UINT8        *StrBuffer;
 
Status = pBootServices->LocateProtocol( &gEfiSFlashProtocolGuid, NULL, &pFlashProtocol);
 
Status = pBootServices->AllocatePool(//start: allocate mem  check point hear
             EfiBootServicesData,
             sizeof(UINT8) * FLASH_BLOCK_SIZE,
             (VOID*)&StrBuffer);
if (EFI_ERROR(Status) || StrBuffer == NULL) {
        error code here…..
      }
 
MemSet(StrBuffer, (sizeof(UINT8) * FLASH_BLOCK_SIZE), 0);
Flash4GBMapStart = 0xFFFFFFFF - FLASH_SIZE + 1;
      
//Enable DeviceWrite to read real Flash address, not memory mapping.
Status = pFlashProtocol->DeviceWriteEnable();//step1. enable
 if (EFI_ERROR(Status)) {
               error code here…..
 } 
 Status = pFlashProtocol->Read(//step2. Read
                   (VOID*)Flash4GBMapStart,
                   FLASH_BLOCK_SIZE,
                   (VOID*)StrBuffer);
                
 *(StrBuffer+PcieLaneSettingAddr) = PcieLaneSetting;          
Status = pFlashProtocol->Write(//step3. Update or write
 (VOID*)Flash4GBMapStart,
FLASH_BLOCK_SIZE,
 (VOID*)StrBuffer);       

 pFlashProtocol->DeviceWriteDisable();  //step4. Disable
pBootServices->FreePool(StrBuffer);//end: free memory
原文地址:https://www.cnblogs.com/qintangtao/p/3303034.html