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

@ -9,20 +9,23 @@ LD = arm-none-eabi-gcc
SIZE = arm-none-eabi-size
MAKE = make
CFLAGS += -ffreestanding -mthumb -mcpu=cortex-m3
CFLAGS += -Wall -Wextra -Wshadow -Wno-unused-value
ifeq ($(PICOLIBC), 1)
CFLAGS += --specs=picolibc.specs -DPICOLIBC_INTEGER_PRINTF_SCANF
endif
CFLAGS += -mthumb -mcpu=cortex-m3 -ffreestanding
CFLAGS += -g3 -Os -ffunction-sections -fdata-sections
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT $@
#CFLAGS += -std=c99
#CFLAGS += -Wpedantic -fanalyzer
#CFLAGS += -flto
CFLAGS += -Wall -Wextra -Wshadow -Wno-unused-value
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT $@
CFLAGS += $(INCLUDE_DIRS)
LDFLAGS = -T ./mps2_m3.ld
LDFLAGS += -Xlinker -Map=$(OUTPUT_DIR)/RTOSDemo.map
LDFLAGS += -Xlinker --gc-sections
LDFLAGS += -nostartfiles
LDFLAGS += -specs=nano.specs -specs=nosys.specs # -specs=rdimon.specs
#LDFLAGS += -Xlinker --print-gc-sections
ifneq ($(PICOLIBC), 1)
LDFLAGS += -nostartfiles -specs=nano.specs -specs=nosys.specs # -specs=rdimon.specs
endif
#
# Kernel build.
@ -99,7 +102,7 @@ VPATH += $(TRACERECORDER_DIR)
VPATH += $(TRACERECORDER_DIR)/kernelports/FreeRTOS
VPATH += $(TRACERECORDER_DIR)/streamports/RingBuffer
INCLUDE_DIRS += -I$(TRACERECORDER_CFG_DIR)
INCLUDE_DIRS += -I$(TRACERECORDER_DIR)/include
INCLUDE_DIRS += -I$(TRACERECORDER_DIR)/include
INCLUDE_DIRS += -I$(TRACERECORDER_DIR)/kernelports/FreeRTOS/include
INCLUDE_DIRS += -I$(TRACERECORDER_DIR)/streamports/RingBuffer/include
SOURCE_FILES += (TRACERECORDER_DIR)/kernelports/FreeRTOS/trcKernelPort.c

View file

@ -79,7 +79,7 @@ const uint32_t* isr_vector[] __attribute__((section(".isr_vector"), used)) =
void Reset_Handler( void )
{
main();
(void) main();
}
/* Variables used to store the value of registers at the time a hardfault

View file

@ -103,7 +103,7 @@ static void prvUARTInit( void );
/*-----------------------------------------------------------*/
void main( void )
int main( void )
{
/* See https://www.freertos.org/freertos-on-qemu-mps2-an385-model.html for
* instructions. */
@ -141,6 +141,7 @@ void main( void )
main_full();
}
#endif
return 0;
}
/*-----------------------------------------------------------*/
@ -313,6 +314,25 @@ static void prvUARTInit( void )
}
/*-----------------------------------------------------------*/
#ifdef __PICOLIBC__
int
_uart_putc(char c, FILE *file)
{
( void ) file;
while( ( UART0_STATE & TX_BUFFER_MASK ) != 0 )
{
}
UART0_DATA = 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
/*-----------------------------------------------------------*/
int __write( int iFile,
char * pcString,
int iStringLength )
@ -351,3 +371,4 @@ void * malloc( size_t size )
{
}
}
#endif

View file

@ -35,29 +35,29 @@ INCLUDE_DIRS += -I$(FREERTOS_DIR)/Demo/CORTEX_MPU_M3_MPS2_QEMU_GCC/C
INCLUDE_DIRS += -I$(KERNEL_DIR)/include
INCLUDE_DIRS += -I$(KERNEL_DIR)/portable/GCC/ARM_CM3_MPU
DEFINES := -DHEAP4
CPPFLAGS += $(DEFINES)
CPPFLAGS += -DHEAP4
ifeq ($(PICOLIBC), 1)
CFLAGS += --specs=picolibc.specs -DPICOLIBC_INTEGER_PRINTF_SCANF
endif
CFLAGS += -mthumb -mcpu=cortex-m3
ifeq ($(DEBUG), 1)
CFLAGS += -g3 -Og -ffunction-sections -fdata-sections -save-temps=obj
else
CFLAGS += -Os -ffunction-sections -fdata-sections
endif
#CFLAGS += -flto
CFLAGS += -Wall -Wextra -Wshadow -Wno-unused-parameter
#CFLAGS += -Wpedantic -fanalyzer
CFLAGS += $(INCLUDE_DIRS)
LDFLAGS = -T ./scripts/mps2_m3.ld
LDFLAGS += -Xlinker -Map=${BUILD_DIR}/output.map
LDFLAGS += -Xlinker --gc-sections
LDFLAGS += -nostartfiles -nostdlib -nolibc -nodefaultlibs
#LDFLAGS += -Xlinker --print-gc-sections
#LDFLAGS += -nostartfiles -nostdlib -nolibc -nodefaultlibs
LDFLAGS += -nostdlib
ifeq ($(DEBUG), 1)
CFLAGS += -g3 -Og -ffunction-sections -fdata-sections -save-temps=obj
else
CFLAGS += -Os -ffunction-sections -fdata-sections
endif
ifeq ($(PICOLIBC), 1)
CFLAGS += --specs=picolibc.specs -DPICOLIBC_INTEGER_PRINTF_SCANF
LDFLAGS += --specs=picolibc.specs -DPICOLIBC_INTEGER_PRINTF_SCANF
endif
OBJ_FILES := $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.o)

View file

@ -66,7 +66,8 @@ SECTIONS
*(privileged_functions)
. = ALIGN(4);
FILL(0xDEAD);
/* Ensure that un-privileged code is placed after the region reserved 4 * for privileged kernel code. */
/* Ensure that un-privileged code is placed after the region reserved
* for privileged kernel code. */
/* Note that dot (.) actually refers to the byte offset from the start
* of the current section (.privileged_functions in this case). As a
* result, setting dot (.) to a value sets the size of the section. */

View file

@ -76,7 +76,7 @@ _uart_putc(char c, FILE *file)
static FILE __stdio = FDEV_SETUP_STREAM(_uart_putc, NULL, NULL, _FDEV_SETUP_WRITE);
FILE *const stdout = &__stdio;
__attribute__( ( used ) ) FILE *const stdout = &__stdio;
#else