From 84ad9250daf05b3799658c1ae9e99c652b9e27e7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 2 Mar 2023 11:48:13 -0800 Subject: [PATCH] Demo/RISC-V_RV32_QEMU_VIRT_GCC: Add option to build with picolibc When built with PICOLIBC=1, selects picolibc as the C library, uses semihosting to display messages and uses picolibc stdio for output. Signed-off-by: Keith Packard --- .../build/gcc/Makefile | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/build/gcc/Makefile b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/build/gcc/Makefile index 4ea218cdfd..e4d8ca9580 100644 --- a/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/build/gcc/Makefile +++ b/FreeRTOS/Demo/RISC-V_RV32_QEMU_VIRT_GCC/build/gcc/Makefile @@ -11,11 +11,22 @@ MAKE = make CFLAGS += $(INCLUDE_DIRS) -DportasmHANDLE_INTERRUPT=handle_trap -fmessage-length=0 \ -march=rv32imac_zicsr -mabi=ilp32 -mcmodel=medlow -ffunction-sections -fdata-sections \ - --specs=nano.specs -fno-builtin-printf -Wno-unused-parameter -nostartfiles -g3 -Os + -Wno-unused-parameter -nostartfiles -g3 -Os +ifeq ($(PICOLIBC),1) +CFLAGS += --specs=picolibc.specs -DPICOLIBC_INTEGER_PRINTF_SCANF +else +CFLAGS += --specs=nano.specs -fno-builtin-printf +endif + LDFLAGS += -nostartfiles -Xlinker --gc-sections -Wl,-Map,$(OUTPUT_DIR)/RTOSDemo.map \ -T./fake_rom.ld -march=rv32imac -mabi=ilp32 -mcmodel=medlow -Xlinker \ - --defsym=__stack_size=350 -Wl,--start-group -Wl,--end-group -Wl,--wrap=malloc \ + --defsym=__stack_size=350 -Wl,--start-group -Wl,--end-group + +ifeq ($(PICOLIBC),1) +LDFLAGS += --specs=picolibc.specs --oslib=semihost --crt0=minimal -DPICOLIBC_INTEGER_PRINTF_SCANF +else +LDFLAGS += -Wl,--wrap=malloc \ -Wl,--wrap=free -Wl,--wrap=open -Wl,--wrap=lseek -Wl,--wrap=read -Wl,--wrap=write \ -Wl,--wrap=fstat -Wl,--wrap=stat -Wl,--wrap=close -Wl,--wrap=link -Wl,--wrap=unlink \ -Wl,--wrap=execve -Wl,--wrap=fork -Wl,--wrap=getpid -Wl,--wrap=kill -Wl,--wrap=wait \ @@ -24,6 +35,7 @@ LDFLAGS += -nostartfiles -Xlinker --gc-sections -Wl,-Map,$(OUTPUT_DIR)/RTOSDemo. -Wl,--wrap=_fstat -Wl,--wrap=_stat -Wl,--wrap=_close -Wl,--wrap=_link -Wl,--wrap=_unlink \ -Wl,--wrap=_execve -Wl,--wrap=_fork -Wl,--wrap=_getpid -Wl,--wrap=_kill -Wl,--wrap=_wait \ -Wl,--wrap=_isatty -Wl,--wrap=_times -Wl,--wrap=_sbrk -Wl,--wrap=__exit -Wl,--wrap=_puts +endif # -Wl,--wrap=_exit # @@ -92,7 +104,9 @@ SOURCE_FILES += (DEMO_PROJECT)/main_full.c SOURCE_FILES += (DEMO_PROJECT)/ns16550.c SOURCE_FILES += (DEMO_PROJECT)/riscv-virt.c # Lightweight print formatting to use in place of the heavier GCC equivalent. +ifneq ($(PICOLIBC),1) SOURCE_FILES += ./printf-stdarg.c +endif ASM_SOURCE_FILES += ./start.S ASM_SOURCE_FILES += ./RegTest.S ASM_SOURCE_FILES += ./vector.S