Skip to content

Commit 55d7a01

Browse files
committed
ArmPkg: Flush the FIFO when initializing the PL011 Serial Lib (#227)
Adds logic to the PL011 initialization that will flush the FIFO. Without this change it's possible for garbage or stale data to be read from the UART which can causes unexpected behavior or hangs during boot. - [x] Impacts functionality? - [ ] Impacts security? - [ ] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? Tested on physical and virtual platform N/A
1 parent 852a5e5 commit 55d7a01

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.c

+21-9
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,34 @@ SerialPortInitialize (
3434
EFI_PARITY_TYPE Parity;
3535
UINT8 DataBits;
3636
EFI_STOP_BITS_TYPE StopBits;
37+
EFI_STATUS Status;
38+
UINT8 Scratch;
3739

3840
BaudRate = FixedPcdGet64 (PcdUartDefaultBaudRate);
3941
ReceiveFifoDepth = 0; // Use default FIFO depth
4042
Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity);
4143
DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);
4244
StopBits = (EFI_STOP_BITS_TYPE)FixedPcdGet8 (PcdUartDefaultStopBits);
4345

44-
return PL011UartInitializePort (
45-
(UINTN)PcdGet64 (PcdSerialRegisterBase),
46-
PL011UartClockGetFreq (),
47-
&BaudRate,
48-
&ReceiveFifoDepth,
49-
&Parity,
50-
&DataBits,
51-
&StopBits
52-
);
46+
// MU_CHANGE START: Flush FIFO when initializing the UART.
47+
Status = PL011UartInitializePort (
48+
(UINTN)PcdGet64 (PcdSerialRegisterBase),
49+
PL011UartClockGetFreq (),
50+
&BaudRate,
51+
&ReceiveFifoDepth,
52+
&Parity,
53+
&DataBits,
54+
&StopBits
55+
);
56+
57+
// Flush the FIFO.
58+
if (!EFI_ERROR (Status)) {
59+
while (SerialPortRead (&Scratch, sizeof (Scratch)) != 0) {
60+
}
61+
}
62+
63+
return Status;
64+
// MU_CHANGE END
5365
}
5466

5567
/**

0 commit comments

Comments
 (0)