From: "Pete Batard" <pete@akeo.ie>
To: devel@edk2.groups.io
Cc: ard.biesheuvel@arm.com, leif@nuviainc.com, awarkentin@vmware.com
Subject: [edk2-platforms][PATCH 0/3] Platform/RPi: Fix compatibility with recent start.elf
Date: Mon, 4 May 2020 12:15:45 +0100 [thread overview]
Message-ID: <20200504111548.11112-1-pete@akeo.ie> (raw)
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
next reply other threads:[~2020-05-04 11:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-04 11:15 Pete Batard [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200504111548.11112-1-pete@akeo.ie \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox