Skip to content

Commit

Permalink
AmpereAltraPkg: Fix OS kernel crash if not call SetVirtualAddressMap()
Browse files Browse the repository at this point in the history
OS kernel avoided SetVirtualAddressMap() on arm64 due to commit d3549a93
("efi/arm64: libstub: avoid SetVirtualAddressMap() when possible").
Currently, RuntimeFlashLib in AmpereAltraPkg relies on function call
SetVirtualAddressMap() to determine whether it is in boot time or
run-time. At boot time, the code optimizes to avoid the use of temporary
buffer because the virtual address and physical address are identical.
If SetVirtualAddressMap() isn't called, it does not know when to switch.
As such, don't do that optimization and the physical address is always
known.

Signed-off-by: Chuong Tran <[email protected]>
  • Loading branch information
chuongtranle authored and nhivp committed Sep 14, 2023
1 parent 87e2414 commit 13b62c5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
11 changes: 3 additions & 8 deletions Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLibCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#define UEFI_MISC_SIZE 0x1000

BOOLEAN gFlashLibRuntime = FALSE;
UINT8 *gFlashLibPhysicalBuffer;
UINT8 *gFlashLibVirtualBuffer;

Expand All @@ -36,13 +35,9 @@ ConvertToPhysicalBuffer (
IN UINT32 Size
)
{
if (gFlashLibRuntime) {
ASSERT (VirtualPtr != NULL);
CopyMem (gFlashLibVirtualBuffer, VirtualPtr, Size);
return gFlashLibPhysicalBuffer;
}

return VirtualPtr;
ASSERT (VirtualPtr != NULL);
CopyMem (gFlashLibVirtualBuffer, VirtualPtr, Size);
return gFlashLibPhysicalBuffer;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ FlashLibAddressChangeEvent (
{
gRT->ConvertPointer (0x0, (VOID **)&gFlashLibVirtualBuffer);
gRT->ConvertPointer (0x0, (VOID **)&mMmCommunicationProtocol);

gFlashLibRuntime = TRUE;
}

/**
Expand Down

0 comments on commit 13b62c5

Please sign in to comment.