[PATCH] serial: stm32: restrict _debug_uart_init() usage

Gianluca Renzi gianlucarenzi at eurek.it
Thu Jan 30 14:49:42 CET 2025


This is awesome!

It should be great if the same approach should be done in OPTEE and TF-A 
too. All that stuff is using the device-tree mechanism, but the LOW 
LEVEL CONFIGURATION (early_init and other functions) is not linear and 
all register base and pin configuration must be done at Makefile 
variables level.

If I recall correctly, using a different UART instead of the EVK one, 
can cause some code to hang and configure the wrong PLL registers to 
continue booting and printing something on the correct UART device.

On 1/30/25 14:28, Patrick DELAUNAY wrote:
> Hi,
>
> On 1/30/25 12:57, Patrice Chotard wrote:
>> Since commit 948da7773e34 ("arm: Add new config option 
>> ARCH_VERY_EARLY_INIT")
>> debug_uart_init() is called respectively in crt0.S and crt0_64.S.
>> That means that _debug_uart_init() is called for all STM32MP platforms
>> even for those which doesn't support SPL_BUILD.
>>
>> So restrict _debug_uart_init() execution for platforms which can have
>> SPL_BUILD enabled (STM32MP1 platform only).
>>
>> It's more needed to call debug_uart_init() in stm32mp1/cpu.c.
>>
>> Signed-off-by: Patrice Chotard <patrice.chotard at foss.st.com>
>> ---
>>
>>   arch/arm/mach-stm32mp/stm32mp1/cpu.c |  2 --
>>   drivers/serial/serial_stm32.c        | 18 ++++++++++++------
>>   2 files changed, 12 insertions(+), 8 deletions(-)
>>
>> diff --git a/arch/arm/mach-stm32mp/stm32mp1/cpu.c 
>> b/arch/arm/mach-stm32mp/stm32mp1/cpu.c
>> index cb1b84c9af9..bc410128479 100644
>> --- a/arch/arm/mach-stm32mp/stm32mp1/cpu.c
>> +++ b/arch/arm/mach-stm32mp/stm32mp1/cpu.c
>> @@ -138,8 +138,6 @@ int mach_cpu_init(void)
>>       if (IS_ENABLED(CONFIG_CMD_STM32PROG_SERIAL) &&
>>           (boot_mode & TAMP_BOOT_DEVICE_MASK) == BOOT_SERIAL_UART)
>>           gd->flags |= GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE;
>> -    else if (IS_ENABLED(CONFIG_DEBUG_UART) && 
>> IS_ENABLED(CONFIG_XPL_BUILD))
>> -        debug_uart_init();
>>         return 0;
>>   }
>> diff --git a/drivers/serial/serial_stm32.c 
>> b/drivers/serial/serial_stm32.c
>> index 1ee58142b3f..1675a9cb9d1 100644
>> --- a/drivers/serial/serial_stm32.c
>> +++ b/drivers/serial/serial_stm32.c
>> @@ -299,13 +299,19 @@ static inline struct stm32_uart_info 
>> *_debug_uart_info(void)
>>     static inline void _debug_uart_init(void)
>>   {
>> -    void __iomem *base = (void __iomem *)CONFIG_VAL(DEBUG_UART_BASE);
>> -    struct stm32_uart_info *uart_info = _debug_uart_info();
>> +    void __maybe_unused __iomem *base = (void __iomem 
>> *)CONFIG_VAL(DEBUG_UART_BASE);
>> +    struct stm32_uart_info *uart_info __maybe_unused = 
>> _debug_uart_info();
>>   -    _stm32_serial_init(base, uart_info);
>> -    _stm32_serial_setbrg(base, uart_info,
>> -                 CONFIG_DEBUG_UART_CLOCK,
>> -                 CONFIG_BAUDRATE);
>> +    /*
>> +     * debug_uart_init() is only usable when SPL_BUILD is enabled
>> +     * (STM32MP1 case only)
>> +     */
>> +    if (IS_ENABLED(CONFIG_DEBUG_UART) && 
>> IS_ENABLED(CONFIG_SPL_BUILD)) {
>> +        _stm32_serial_init(base, uart_info);
>> +        _stm32_serial_setbrg(base, uart_info,
>> +                     CONFIG_DEBUG_UART_CLOCK,
>> +                     CONFIG_BAUDRATE);
>> +    }
>>   }
>>     static inline void _debug_uart_putc(int c)
>
>
> Reviewed-by: Patrick Delaunay <patrick.delaunay at foss.st.com>
>
> Thanks
> Patrick
>

-- 
Eurek s.r.l.                          |
Electronic Engineering                | http://www.eurek.it
via Celletta 8/B, 40026 Imola, Italy  | Phone: +39-(0)542-609120
p.iva 00690621206 - c.f. 04020030377  | Fax:   +39-(0)542-609212

Invito alla riservatezza:
La  presente richiesta di  quotazione tramite posta elettronica contiene
informazioni personali e riservate. E' vietato divulgarne il contenuto a
persone diverse  dal destinatario.  Si prega i riceventi non autorizzati
di  mantenere  il  riserbo,  di informare  tempestivamente  il  mittente
dell'errore di trasmissione e di eliminare quanto per  errore pervenuto,
ivi  compresi  eventuali  allegati.  La  diffusione,  distribuzione  e/o
copiatura  delle  informazioni  trasmesse da parte di qualsiasi soggetto
diverso  dal  destinatario  e' proibita, sia ai sensi dell'art. 616 c.p.
che  ai  sensi  del  D.Lgs.196/2003  e adeguamento del nuovo Regolamento
Europeo nr. 679/2016

Invitation to privacy:
This  request  for  an  e-mail  quote  includes   personal  and  private
information. Making its content known to anyone other than the recipient
is forbidden.  Unauthorized  recipients are kindly requested to maintain
secrecy,  promptly  inform  the sender of the wrong reception and delete
what   has   been  accidentally  received,  including  any  attachments.
Spreading,  distributing  and  /  or copying the provided information by
anyone  other  than  the  addressee  is  forbidden,  according  both  to
art. 616 C.P.  and  to  D.Lgs.196  /  2003  and adaptation of the new EU
Regulation n. 679/2016

  



More information about the U-Boot mailing list