public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-platforms][PATCH 0/3] Platform/RPi: Fix compatibility with recent start.elf
@ 2020-05-04 11:15 Pete Batard
  2020-05-04 11:15 ` [edk2-platforms][PATCH 1/3] Platform/RPi: Fortify mailbox code Pete Batard
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Pete Batard @ 2020-05-04 11:15 UTC (permalink / raw)
  To: devel; +Cc: ard.biesheuvel, leif, awarkentin

As per https://github.com/raspberrypi/firmware/issues/1376 we found two
issues with recent versions of the Raspberry Pi Foundation's start.elf
on the Pi 3:

1. Our timeout delay for mbox reply was too short, leading to loss of
   USB due to USB mbox power state request not being applied.
2. The MiniUART baudrate shifted from the expected value due to the
   Raspberry Pi Foundation deviating from their official documentation
   and increasing the default core clock (which the MiniUART bases its
   baudrate divisor on) to 400 MHz, instead using a fixed 250 MHz,
   when 'enable_uart=1' is in effect.

Fixing the first issue is fairly straightforward, and is done in patch
1/3, where we also take this opportunity to improve the overall mbox
code.

Fixing the second issue requires a little more involvement as we want
to ensure that we no longer depend on a fixed PCD clock rate to derive
the MiniUART baudrate divisor, but instead use the actual core clock
frequency retreived from mbox. However, because there basically exists
two instances of DualSerialLib in the firmware (one in PEI phase and
one in DXE) and the serial initialization is done very early, we have
to use the following process:

1. ArmPlatformPeiBootAction set the core clock of the PEI instance of
   DualSerialLib, which enables the PEI serial instance to be set 
   with a proper baudrate.
2. A newly introduced PlatformPeiLib provides a PlatformPeim () call
   that reads the global value from the PEI serial instance and
   stores it into a GUID Hob.
3. In DXE phase, when the DXE instance of DualSerialLib attempts to
   read the core clock value for the first time, it detects that it
   has not been set and sets its value from the GUID Hob.

It needs to be pointed out however that we can't use HobLib helper
functions such as GetFirstGuidHob () or even GetHobList () directly
because DualSerialLib gets instantiated before the DXE version of
HobLib. However we work around that by using PrePeiGetHobList ().

This serial baudrate fixup is accomplished in patch 2/3. We also
take this opportunity to improve the Pi 4 code, which currently
doesn't use the core clock frequency at all, andt instead applies
a variable 12.12 fixed divisor (which we can always access without
mbox transactions) onto a 1 GHz fixed clock.

It should be noted that, with 2/3 applied, users of the Pi firmware
have the new capability of being able to override the core frequency
to whichever value they like (by adding 'core_freq=###' in their
'config.txt') without losing MiniUART baudrate, as was the case
without this patch.

Finally, considering that the knowing the actual core frequency
the system booted with can be useful during early init, we add
patch 3/3 to display this value for DEBUG builds.


Andrei Warkentin (2):
  Platform/RPi: Fortify mailbox code
  Platform/RPi/DualSerialPortLib: Fix miniUART serial divisor
    computation

Pete Batard (1):
  Platform/RPi: Report core clock frequency during early init

 Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c         |  11 +-
 Platform/RaspberryPi/Include/Guid/DualSerialPortLibHobGuid.h         |  22 ++++
 Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h              |  11 +-
 Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c   | 106 +++++++++++++++++---
 Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.inf |   6 ++
 Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S |  83 ++++++++-------
 Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c            |   8 +-
 Platform/RaspberryPi/Library/PlatformPeiLib/PlatformPeiLib.c         |  33 ++++++
 Platform/RaspberryPi/Library/PlatformPeiLib/PlatformPeiLib.inf       |  47 +++++++++
 Platform/RaspberryPi/RPi3/RPi3.dsc                                   |   8 +-
 Platform/RaspberryPi/RPi4/RPi4.dsc                                   |   9 +-
 Platform/RaspberryPi/RaspberryPi.dec                                 |   1 +
 12 files changed, 278 insertions(+), 67 deletions(-)
 create mode 100644 Platform/RaspberryPi/Include/Guid/DualSerialPortLibHobGuid.h
 create mode 100644 Platform/RaspberryPi/Library/PlatformPeiLib/PlatformPeiLib.c
 create mode 100644 Platform/RaspberryPi/Library/PlatformPeiLib/PlatformPeiLib.inf

-- 
2.21.0.windows.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-05-06 12:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-04 11:15 [edk2-platforms][PATCH 0/3] Platform/RPi: Fix compatibility with recent start.elf Pete Batard
2020-05-04 11:15 ` [edk2-platforms][PATCH 1/3] Platform/RPi: Fortify mailbox code Pete Batard
2020-05-06 12:39   ` Ard Biesheuvel
2020-05-04 11:15 ` [edk2-platforms][PATCH 2/3] Platform/RPi/DualSerialPortLib: Fix miniUART serial divisor computation Pete Batard
2020-05-05 10:05   ` Ard Biesheuvel
2020-05-05 11:54     ` Pete Batard
2020-05-05 12:05       ` Ard Biesheuvel
2020-05-05 12:09         ` Pete Batard
2020-05-04 11:15 ` [edk2-platforms][PATCH 3/3] Platform/RPi: Report core clock frequency during early init Pete Batard
2020-05-04 11:37   ` [edk2-devel] " Philippe Mathieu-Daudé
2020-05-05  6:04   ` Andrei Warkentin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox