mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-28 16:14:04 +02:00
OvmfPkg/VirtNorFlashDxe: move DoErase code block into new function
Move the DoErase code block into a separate function, call the function instead of jumping around with goto. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Message-Id: <20240116171105.37831-7-kraxel@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
parent
735d0a5e2e
commit
b481b00f59
@ -502,6 +502,38 @@ NorFlashRead (
|
|||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATIC
|
||||||
|
EFI_STATUS
|
||||||
|
NorFlashWriteSingleBlockWithErase (
|
||||||
|
IN NOR_FLASH_INSTANCE *Instance,
|
||||||
|
IN EFI_LBA Lba,
|
||||||
|
IN UINTN Offset,
|
||||||
|
IN OUT UINTN *NumBytes,
|
||||||
|
IN UINT8 *Buffer
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
// Read NOR Flash data into shadow buffer
|
||||||
|
Status = NorFlashReadBlocks (Instance, Lba, Instance->BlockSize, Instance->ShadowBuffer);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
// Return one of the pre-approved error statuses
|
||||||
|
return EFI_DEVICE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put the data at the appropriate location inside the buffer area
|
||||||
|
CopyMem ((VOID *)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumBytes);
|
||||||
|
|
||||||
|
// Write the modified buffer back to the NorFlash
|
||||||
|
Status = NorFlashWriteBlocks (Instance, Lba, Instance->BlockSize, Instance->ShadowBuffer);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
// Return one of the pre-approved error statuses
|
||||||
|
return EFI_DEVICE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Write a full or portion of a block. It must not span block boundaries; that is,
|
Write a full or portion of a block. It must not span block boundaries; that is,
|
||||||
Offset + *NumBytes <= Instance->BlockSize.
|
Offset + *NumBytes <= Instance->BlockSize.
|
||||||
@ -607,7 +639,14 @@ NorFlashWriteSingleBlock (
|
|||||||
// that we want to set. In that case, we will need to erase the block first.
|
// that we want to set. In that case, we will need to erase the block first.
|
||||||
for (CurOffset = 0; CurOffset < *NumBytes; CurOffset++) {
|
for (CurOffset = 0; CurOffset < *NumBytes; CurOffset++) {
|
||||||
if (~(UINT32)OrigData[CurOffset] & (UINT32)Buffer[CurOffset]) {
|
if (~(UINT32)OrigData[CurOffset] & (UINT32)Buffer[CurOffset]) {
|
||||||
goto DoErase;
|
Status = NorFlashWriteSingleBlockWithErase (
|
||||||
|
Instance,
|
||||||
|
Lba,
|
||||||
|
Offset,
|
||||||
|
NumBytes,
|
||||||
|
Buffer
|
||||||
|
);
|
||||||
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
OrigData[CurOffset] = Buffer[CurOffset];
|
OrigData[CurOffset] = Buffer[CurOffset];
|
||||||
@ -636,33 +675,22 @@ NorFlashWriteSingleBlock (
|
|||||||
goto Exit;
|
goto Exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
Exit:
|
Status = NorFlashWriteSingleBlockWithErase (
|
||||||
// Put device back into Read Array mode
|
Instance,
|
||||||
SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
|
Lba,
|
||||||
|
Offset,
|
||||||
|
NumBytes,
|
||||||
|
Buffer
|
||||||
|
);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
DoErase:
|
Exit:
|
||||||
// Read NOR Flash data into shadow buffer
|
// Put device back into Read Array mode
|
||||||
Status = NorFlashReadBlocks (Instance, Lba, BlockSize, Instance->ShadowBuffer);
|
SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
// Return one of the pre-approved error statuses
|
|
||||||
return EFI_DEVICE_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put the data at the appropriate location inside the buffer area
|
return Status;
|
||||||
CopyMem ((VOID *)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumBytes);
|
|
||||||
|
|
||||||
// Write the modified buffer back to the NorFlash
|
|
||||||
Status = NorFlashWriteBlocks (Instance, Lba, BlockSize, Instance->ShadowBuffer);
|
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
// Return one of the pre-approved error statuses
|
|
||||||
return EFI_DEVICE_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user