1
+ # ###############################################################################
2
+ # Initial setup of Makefile environment
3
+
1
4
BOARD ?= MPS2_AN385
2
5
3
6
# Make the build directory reflect the board.
@@ -14,16 +17,79 @@ QSTR_DEFS = qstrdefsport.h
14
17
15
18
# MicroPython feature configurations
16
19
MICROPY_ROM_TEXT_COMPR
10000
ESSION ?= 1
20
+
21
+ ifeq ($(QEMU_ARCH ) ,arm)
17
22
FROZEN_MANIFEST ?= "freeze('test-frzmpy')"
23
+ endif
24
+ ifeq ($(QEMU_ARCH ) ,riscv32)
25
+ FROZEN_MANIFEST ?= "freeze('test-frzmpy', ('frozen_const.py', 'frozen_viper.py', 'native_frozen_align.py'))"
26
+ endif
18
27
19
28
# include py core make definitions
20
29
include $(TOP ) /py/py.mk
21
30
include $(TOP ) /extmod/extmod.mk
22
31
32
+ # ###############################################################################
33
+ # ARM specific settings
34
+
35
+ ifeq ($(QEMU_ARCH ) ,arm)
36
+
23
37
CROSS_COMPILE ?= arm-none-eabi-
24
38
39
+ LDFLAGS += -nostdlib
40
+ LIBS = $(shell $(CC ) $(CFLAGS ) -print-libgcc-file-name)
41
+
42
+ SRC_C += \
43
+ mcu/arm/startup.c \
44
+ shared/runtime/semihosting_arm.c \
45
+
46
+ endif
47
+
48
+ # ###############################################################################
49
+ # RISC-V 32-bit specific settings
50
+
51
+ ifeq ($(QEMU_ARCH ) ,riscv32)
52
+
53
+ CROSS_COMPILE ?= riscv64-unknown-elf-
54
+
55
+ GCC_VERSION = $(word 1, $(subst ., , $(shell $(CC ) -dumpversion) ) )
56
+
57
+ RV32_ABI = ilp32
58
+
59
+ QEMU_ARGS += -bios none
60
+
61
+ # GCC 10 and lower do not recognise the Zicsr extension in the architecture name.
62
+ ifeq ($(shell test $(GCC_VERSION ) -le 10; echo $$? ) ,0)
63
+ RV32_ARCH ?= rv32imac
64
+ else
65
+ # Recent GCC versions explicitly require to declare extensions.
66
+ RV32_ARCH ?= rv32imac_zicsr
67
+ endif
68
+
69
+ AFLAGS += -mabi=$(RV32_ABI ) -march=$(RV32_ARCH )
70
+ CFLAGS += $(AFLAGS )
71
+ LDFLAGS += -mabi=$(RV32_ABI ) -march=$(RV32_ARCH ) -Wl,-EL
72
+
73
+ SRC_C += \
74
+ mcu/rv32/interrupts.c \
75
+ mcu/rv32/startup.c \
76
+
77
+ SRC_BOARD_O += mcu/rv32/entrypoint.o
78
+
79
+ endif
80
+
81
+ # ###############################################################################
82
+ # Project specific settings and compiler/linker flags
83
+
25
84
QEMU_SYSTEM = qemu-system-$(QEMU_ARCH )
26
85
QEMU_ARGS += -machine $(QEMU_MACHINE ) -nographic -monitor null -semihosting
86
+ QEMU_ARGS += $(QEMU_EXTRA )
87
+
88
+ # Specifying QEMU_DEBUG=1 will block qemu until a debugger is connected.
89
+ ifeq ($(QEMU_DEBUG ) ,1)
90
+ QEMU_DEBUG_ARGS ?= -s
91
+ QEMU_ARGS += -S $(QEMU_DEBUG_ARGS ) $(QEMU_DEBUG_EXTRA )
92
+ endif
27
93
28
94
INC += -I.
29
95
INC += -I$(TOP )
@@ -34,6 +100,8 @@ CFLAGS += $(INC) -Wall -Wpointer-arith -Wdouble-promotion -Wfloat-conversion -We
34
100
-ffunction-sections -fdata-sections
35
101
CFLAGS += $(CFLAGS_EXTRA )
36
102
103
+ LDFLAGS += -T $(LDSCRIPT ) -Wl,--gc-sections -Wl,-Map=$(@:.elf=.map )
104
+
37
105
# Debugging/Optimization
38
106
ifeq ($(DEBUG ) , 1)
39
107
CFLAGS += -g
@@ -42,25 +110,31 @@ else
42
110
COPT += -Os -DNDEBUG
43
111
endif
44
112
45
- # # With CoudeSourcery it's actually a little different, you just need `-T generic-m-hosted.ld`.
46
- # # Although for some reason `$(LD)` will not find that linker script, it works with `$(CC)`.
47
- # # It turns out that this is specific to CoudeSourcery, and ARM version of GCC ships something
48
- # # else instead and according to the following files, this is what we need to pass to `$(CC).
49
- # # - gcc-arm-none-eabi-4_8-2014q1/share/gcc-arm-none-eabi/samples/src/makefile.conf
50
- # # - gcc-arm-none-eabi-4_8-2014q1/share/gcc-arm-none-eabi/samples/src/qemu/Makefile
51
- LDFLAGS = -T $(LDSCRIPT ) --gc-sections -Map=$(@:.elf=.map )
52
- LIBS = $(shell $(CC ) $(CFLAGS ) -print-libgcc-file-name)
113
+ # If Picolibc is available then select it explicitly. Ubuntu 22.04 ships its
114
+ # bare metal RISC-V toolchain with Picolibc rather than Newlib, and the default
115
+ # is "nosys" so a value must be provided. To avoid having per-distro
116
+ # workarounds, always select Picolibc if available.
117
+ PICOLIBC_SPECS = $(shell $(CC ) --print-file-name=picolibc.specs)
118
+ ifeq ($(PICOLIBC_SPECS ) ,picolibc.specs)
119
+ # Picolibc was not found.
120
+ else
121
+ $(info picolibc used $(PICOLIBC_SPECS))
122
+ SPECS_FRAGMENT = --specs=$(PICOLIBC_SPECS )
123
+ CFLAGS += $(SPECS_FRAGMENT )
124
+ LDFLAGS += $(SPECS_FRAGMENT )
125
+ endif
53
126
54
- SRC_C = \
127
+ # ###############################################################################
128
+ # Source files and libraries
129
+
130
+ SRC_C += \
55
131
main.c \
56
- startup.c \
57
132
uart.c \
58
133
mphalport.c \
59
134
shared/libc/string0.c \
60
135
shared/readline/readline.c \
61
136
shared/runtime/interrupt_char.c \
62
137
shared/runtime/pyexec.c \
63
- shared/runtime/semihosting_arm.c \
64
138
shared/runtime/stdout_helpers.c \
65
139
shared/runtime/sys_stdio_mphal.c \
66
140
@@ -75,6 +149,9 @@ OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
75
149
# List of sources for qstr extraction
76
150
SRC_QSTR += $(SRC_C ) $(LIB_SRC_C )
77
151
152
+ # ###############################################################################
153
+ # Main targets
154
+
78
155
all : $(BUILD ) /firmware.elf
79
156
80
157
.PHONY : repl
@@ -91,9 +168,11 @@ test: $(BUILD)/firmware.elf
91
168
$(eval DIRNAME=ports/$(notdir $(CURDIR ) ) )
92
169
cd $(TOP ) /tests && ./run-tests.py --target qemu-arm --device execpty:" $( QEMU_SYSTEM) $( QEMU_ARGS) -serial pty -kernel ../$( DIRNAME) /$<" $(RUN_TESTS_ARGS ) $(RUN_TESTS_EXTRA )
93
170
94
- # # `$(LD)` doesn't seem to like `--specs` for some reason, but we can just use `$(CC)` here.
95
171
$(BUILD ) /firmware.elf : $(LDSCRIPT ) $(OBJ )
96
- $(Q )$(LD ) $(LDFLAGS ) -o $@ $(OBJ ) $(LIBS )
172
+ $(Q )$(CC ) $(LDFLAGS ) -o $@ $(OBJ ) $(LIBS )
97
173
$(Q )$(SIZE ) $@
98
174
175
+ # ###############################################################################
176
+ # Remaining make rules
177
+
99
178
include $(TOP ) /py/mkrules.mk
0 commit comments