@@ -8,20 +8,20 @@ QSTR_DEFS = qstrdefsport.h
88# MicroPython feature configurations
99MICROPY_ROM_TEXT_COMPRESSION ?= 1
1010
11- # Mode selection (default to REPL_SYSCALL for backwards compatibility)
12- # Valid values: REPL_SYSCALL , HEADLESS, UART
13- MODE ?= REPL_SYSCALL
11+ # Mode selection (default to REPL_NEWLIB for backwards compatibility)
12+ # Valid values: REPL_NEWLIB , HEADLESS, REPL_UART
13+ MODE ?= REPL_NEWLIB
1414
15- # Frozen module support for HEADLESS and UART modes
15+ # Frozen module support for HEADLESS and REPL_UART modes
1616# The frozen script is always named startup.py
1717ifeq ($(MODE ) ,HEADLESS)
1818 FROZEN_ENABLED = 1
19- else ifeq ($(MODE),UART )
19+ else ifeq ($(MODE),REPL_UART )
2020 FROZEN_ENABLED = 1
21- else ifeq ($(MODE),REPL_SYSCALL )
21+ else ifeq ($(MODE),REPL_NEWLIB )
2222 FROZEN_ENABLED = 0
2323else
24- $(error Invalid MODE=$(MODE ) . Valid values : REPL_SYSCALL , HEADLESS, UART )
24+ $(error Invalid MODE=$(MODE ) . Valid values : REPL_NEWLIB , HEADLESS, REPL_UART )
2525endif
2626
2727ifeq ($(FROZEN_ENABLED ) ,1)
@@ -45,7 +45,12 @@ MPY_CROSS ?= $(TOP)/mpy-cross/build/mpy-cross
4545MPY_TOOL ?= $(PYTHON ) $(TOP ) /tools/mpy-tool.py
4646# Flags for mpy-cross and mpy-tool to match port configuration
4747MPY_CROSS_FLAGS += -msmall-int-bits=31
48- MPY_TOOL_FLAGS += -mlongint-impl=longlong
48+ ifeq ($(MODE ) ,REPL_NEWLIB)
49+ MPY_TOOL_FLAGS += -mlongint-impl=longlong
50+ else
51+ # HEADLESS and REPL_UART use minimal integer implementation
52+ MPY_TOOL_FLAGS += -mlongint-impl=none
53+ endif
4954
5055# Extension options - set to 1 to enable, 0 to disable
5156# Note: the toolchain might not support all combinations
@@ -65,17 +70,45 @@ INC += -I$(BUILD)
6570ifeq ($(CROSS ) , 1)
6671DFU = $(TOP ) /tools/dfu.py
6772PYDFU = $(TOP ) /tools/pydfu.py
68- CFLAGS_RISCV = -march=$(MARCH ) -mabi=ilp32 -D_REENT_SMALL
73+
74+ # Base RISC-V flags (bare-metal)
75+ CFLAGS_RISCV = -march=$(MARCH ) -mabi=ilp32
76+
77+ # Define MODE constants for use in C and assembly
78+ CFLAGS_RISCV += -DMODE_REPL_NEWLIB=1 -DMODE_HEADLESS=2 -DMODE_REPL_UART=3
79+
80+ # Add Newlib-specific flags for REPL_NEWLIB mode
81+ ifeq ($(MODE ) ,REPL_NEWLIB)
82+ CFLAGS_RISCV += -D_REENT_SMALL
83+ endif
84+
6985CFLAGS += $(INC ) -Wall -Werror -std=c99 $(CFLAGS_RISCV ) $(COPT ) -DMICROPY_PORT_MODE=MODE_$(MODE )
70- LDFLAGS += -nostartfiles -static -Tlinker_newlib.ld --specs=nosys.specs
86+
87+ # Linker flags
88+ LDFLAGS += -nostartfiles -static -Tmicropython.ld
89+ ifeq ($(MODE ) ,REPL_NEWLIB)
90+ LDFLAGS += --specs=nosys.specs
91+ else
92+ LDFLAGS += -nostdlib
93+ endif
7194else
7295UNAME_S := $(shell uname -s)
7396LD = $(CC )
7497CFLAGS += $(INC ) -Wall -Werror -Wdouble-promotion -Wfloat-conversion -std=c99 $(COPT ) -DMICROPY_PORT_MODE=MODE_$(MODE )
7598ifeq ($(UNAME_S ) ,Linux)
76- LDFLAGS += -nostartfiles -Wl,--gc-sections -static -Tlinker_newlib.ld --specs=nano.specs -Wl,-map,$@ .map -Wl,-dead_strip
99+ LDFLAGS += -nostartfiles -Wl,--gc-sections -static -Tmicropython.ld -Wl,-map,$@ .map -Wl,-dead_strip
100+ ifeq ($(MODE ) ,REPL_NEWLIB)
101+ LDFLAGS += --specs=nano.specs
102+ else
103+ LDFLAGS += -nostdlib
104+ endif
77105else ifeq ($(UNAME_S),Darwin)
78- LDFLAGS += -nostartfiles -Wl,--gc-sections -static -Tlinker_newlib.ld --specs=nano.specs -Wl,-map,$@ .map -Wl,-dead_strip
106+ LDFLAGS += -nostartfiles -Wl,--gc-sections -static -Tmicropython.ld -Wl,-map,$@ .map -Wl,-dead_strip
107+ ifeq ($(MODE ) ,REPL_NEWLIB)
108+ LDFLAGS += --specs=nano.specs
109+ else
110+ LDFLAGS += -nostdlib
111+ endif
79112endif
80113endif
81114
@@ -99,7 +132,14 @@ endif
99132# Flags for optional C++ source code
100133CXXFLAGS += $(filter-out -std=c99,$(CFLAGS ) )
101134
102- LIBS = -lm
135+ # Libraries based on mode
136+ ifeq ($(MODE ) ,REPL_NEWLIB)
137+ # REPL_NEWLIB: Full Newlib with float support
138+ LIBS = -lm
139+ else
140+ # HEADLESS and REPL_UART: Minimal config (no floats, no long ints) - only libgcc
141+ LIBS = -lgcc
142+ endif
103143
104144# Common source files for all build modes
105145SRC_C = \
@@ -115,19 +155,24 @@ SRC_C = \
115155 extmod/machine_mem.c \
116156 extmod/moductypes.c
117157
158+ # Base assembly files (bare-metal)
118159SRC_S = \
119- start_newlib.S \
120- syscalls_newlib.S \
160+ start.S \
121161 gchelper_rv32i.S
122162
163+ # Add syscall stubs for REPL_NEWLIB mode
164+ ifeq ($(MODE ) ,REPL_NEWLIB)
165+ SRC_S += syscalls_newlib.S
166+ endif
167+
123168# Select HAL based on build mode
124- ifeq ($(MODE ) ,REPL_SYSCALL )
169+ ifeq ($(MODE ) ,REPL_NEWLIB )
125170 # Mode 1: syscall-based I/O
126171 SRC_C += mphalport.c
127172else ifeq ($(MODE),HEADLESS)
128173 # Mode 2: headless (no stdio)
129174 SRC_C += mphalport_headless.c
130- else ifeq ($(MODE),UART )
175+ else ifeq ($(MODE),REPL_UART )
131176 # Mode 3: UART MMIO I/O
132177 SRC_C += mphalport_uart.c
133178endif
0 commit comments