Various Qemu Cortex M3 ports now support picolibc (#1364)

* Various Qemu Cortex M3 ports now support picolibc

Allow various Qemu Cortex M3 ports to compile against
picolibc. Also support "-flto" to work correctly.
Tested with picolibc in current Debian 13.
Just use "PICOLIBC=1 make" to switch over from default newlib.

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>

* Add ffreestanding

Signed-off-by: Ubuntu <ubuntu@ip-172-31-15-241.ap-south-1.compute.internal>

* Fix formatting check

Signed-off-by: Ubuntu <ubuntu@ip-172-31-15-241.ap-south-1.compute.internal>

---------

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
Signed-off-by: Ubuntu <ubuntu@ip-172-31-15-241.ap-south-1.compute.internal>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
Co-authored-by: Ubuntu <ubuntu@ip-172-31-15-241.ap-south-1.compute.internal>
This commit is contained in:
Florian La Roche 2025-08-13 16:45:54 +02:00 committed by GitHub
parent 51467d89e0
commit 1aa47857a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 96 additions and 34 deletions

View file

@ -30,6 +30,7 @@ extern "C" {
#include <sys/types.h>
void uart_init( void );
#ifndef __PICOLIBC__
__attribute__( ( used ) ) int _fstat( int file );
int _read( int file,
char * buf,
@ -39,6 +40,7 @@ int _write( int file,
int len );
void * _sbrk( int incr );
#endif
typedef struct UART_t
{
@ -55,10 +57,12 @@ typedef struct UART_t
#define UART_CTRL_TX_EN ( 1 << 0 )
#ifndef __PICOLIBC__
extern unsigned long _heap_bottom;
extern unsigned long _heap_top;
static char * heap_end = ( char * ) &_heap_bottom;
#endif
/**
* @brief initializes the UART emulated hardware
@ -69,6 +73,24 @@ void uart_init( void )
UART0_ADDR->CTRL = UART_CTRL_TX_EN;
}
#ifdef __PICOLIBC__
#include <stdio.h>
int
_uart_putc(char c, FILE *file)
{
( void ) file;
UART_DR( UART0_ADDR ) = c;
return (unsigned char) c;
}
static FILE __stdio = FDEV_SETUP_STREAM(_uart_putc, NULL, NULL, _FDEV_SETUP_WRITE);
__attribute__( ( used ) ) FILE *const stdout = &__stdio;
#else
/**
* @brief not used anywhere in the code
* @todo implement if necessary
@ -138,6 +160,7 @@ void * _sbrk( int incr )
return prev_heap_end;
}
#endif
#ifdef __cplusplus
}