Re: [PATCH] serial: amba-pl011: Enable UART in earlycon setup
From: Peter Maydell
Date: Tue Feb 10 2026 - 08:49:58 EST
On Tue, 10 Feb 2026 at 13:23, Arnd Bergmann <arnd@xxxxxxxx> wrote:
>
> On Tue, Feb 10, 2026, at 13:50, Peter Maydell wrote:
> > Currently the PL011 driver only enables the UART (by setting UARTEN
> > in REG_CR) in pl011_startup(), so if it is used for earlycon it is
> > relying on the bootrom/firmware having left the UART enabled.
> >
> > There's no particular reason not to actively enable the UART before
> > using it for earlycon, and the earlycon handling for e.g. the 8250
> > UART sets up the UART in its setup function, so follow that in the
> > PL011.
> >
> > This allows use of earlycon with a UART that the firmware hasn't
> > already been using for its own output, but the main motivation is
> > that QEMU will otherwise log a message complaining that the guest is
> > trying to write to a UART it never enabled.
> >
> > Signed-off-by: Peter Maydell <peter.maydell@xxxxxxxxxx>
> > ---
> > NB: I have tested this under QEMU, but I do not have any real
> > PL011-using hardware to hand to test with.
>
> Looks good to me,
>
> Acked-by: Arnd Bergmann <arnd@xxxxxxxx>
>
> One more question: what is the symptom without this patch with
> qemu? You mentioned on IRC that qemu may warn about attempting
> to write to the uart when it is disabled. Would we still get
> the correct early console output before the uart is enabled?
The symptom is that if you run QEMU with '-d guest_errors' to ask
it to log things the guest does that it thinks are bugs in the
guest, then you get a lot of "PL011 data written to disabled UART"
warnings. The guest still boots fine, and assuming you directed
the logging to a file rather than stdout you see the guest output.
(This is because for PL011 we have deliberately not emulated the
hardware behaviour of discarding data when the UART isn't initialized,
because we think there is a lot of "my first bare metal hello
world program" type code out there that was written against older
QEMU versions and not tested on hardware and never enables the
PL011, and we figured that making all that code break wasn't a
sensible tradeoff for theoretically increased emulation fidelity.
For newer UART models where we modelled the enable flag correctly
from the start, you would have to explicitly enable. The CMSDK
UART model is one example of that.)
I have also sent a QEMU patch to restrict the complaint to
"print this once" rather than "print this every time the
guest writes to the UART TX register".
thanks
-- PMM