Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: split ftw writes if they span blocks r35.6 #115

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 66 additions & 9 deletions Silicon/NVIDIA/Drivers/FvbDxe/FvbDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

Fvb Driver

Copyright (c) 2018-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>

SPDX-FileCopyrightText: Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

**/
Expand Down Expand Up @@ -866,13 +865,71 @@ FtwWrite (
IN VOID *Buffer
)
{
return Private->FvbInstance.Write (
&Private->FvbInstance,
Lba,
Offset,
&Length,
Buffer
);
EFI_STATUS Status;
UINTN BytesRemaining;
UINTN CurOffset;
UINT32 BlockSize;
UINTN WriteSize;
UINTN ActualWriteSize;
EFI_LBA CurLba;
VOID *BufferPtr;

BlockSize = Private->BlockIo->Media->BlockSize;

if (Offset >= BlockSize) {
DEBUG ((DEBUG_ERROR, "%a: Invalid Offset value %u BlockSize %u\n", __FUNCTION__, Offset, BlockSize));
return EFI_BAD_BUFFER_SIZE;
}

BytesRemaining = Length;
CurOffset = Offset;
CurLba = Lba;
BufferPtr = Buffer;
Status = EFI_SUCCESS;

while (BytesRemaining > 0) {
/* Ensure Writes don't cross Block boundaries.*/
if ((CurOffset + BytesRemaining) > BlockSize) {
WriteSize = (BlockSize - CurOffset);
} else {
WriteSize = BytesRemaining;
}

ActualWriteSize = WriteSize;
Status = Private->FvbInstance.Write (
&Private->FvbInstance,
CurLba,
CurOffset,
&ActualWriteSize,
BufferPtr
);
if (EFI_ERROR (Status) || (ActualWriteSize != WriteSize)) {
DEBUG ((
DEBUG_ERROR,
"%a: WriteFailed(%r): LBA %lu Offset %u Actual/Expected:%u/%u\n",
__FUNCTION__,
Status,
CurLba,
CurOffset,
ActualWriteSize,
WriteSize
));

if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Setting Return To BAD BUFFER SIZE\n"));
Status = EFI_BAD_BUFFER_SIZE;
}

break;
}

CurOffset = 0;
BytesRemaining -= WriteSize;
CurLba++;
BufferPtr = ((UINT8 *)BufferPtr + WriteSize);
}

return Status;
}

/**
Expand Down