您的位置:首页 > 运维架构 > Shell

Parse how to write flash in uefi shell.

2013-09-05 12:26 411 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: