forked from Mindgrove-Technologies/micropython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
310 lines (283 loc) · 7.51 KB
/
Copy pathMakefile
File metadata and controls
310 lines (283 loc) · 7.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# Include the core environment definitions; this will set $(TOP).
#$(TOP) = ../..
include ../../py/mkenv.mk
#include $(TOP)/py/qstrdefs.mk
#CFLAGS += -I$(TOP)/py -I$(TOP)/extmod -I$(TOP)/shared
# Include py core make definitions.
include $(TOP)/py/py.mk
include $(TOP)/extmod/extmod.mk
QSTR_DEFS = \
$(TOP)/py/qstrdefs.h \
$(TOP)/ports/minimal_new/qstrdefsport.h
QSTR_GLOBAL_DEPENDENCIES = mpconfigport.h
CROSS_COMPILE ?= riscv64-unknown-elf-
# Set CFLAGS and libraries.
#CFLAGS += -march=rv64imac -mabi=lp64
#Incase of soft float enable
CFLAGS += -march=rv64imafd -mabi=lp64d
#CFLAGS += -mno-c
CFLAGS += -fno-builtin-printf
CFLAGS += -fno-builtin-memcpy
CFLAGS += -fno-builtin-malloc
CFLAGS += -Wall -Wcomment -Og -ggdb
CFLAGS += -mcmodel=medany -static -g
CFLAGS += -std=gnu99
CFLAGS += -fstack-protector-all -D_FORTIFY_SOURCE=2 -g
#For hard float enabled
CFLAGS += -I. -I$(BUILD) -I$(TOP)
# Add after existing CFLAGS
CFLAGS += -I$(TOP)/py -I$(TOP)/extmod -I$(TOP)/shared
#Since I have already put extmod I guess there is no need to add it separately.
#INC+= -I$(TOP)/lib/oofatfs
# Add after existing CFLAGS
#CFLAGS += -I$(TOP)
#CFLAGS += -I$(TOP)/py -I$(TOP)/extmod -I$(TOP)/shared
INC += -I$(TOP)/shared/runtime
#CFLAGS += -I$(TOP)/ports/minimal/build/genhdr
CFLAGS += -I$(BUILD)/genhdr
CFLAGS += $(INC)
LIBS += -lm
# Define the required source files.
# ../../py/objcomplex.c \
../../py/objfloat.c \ --> Linking two times in the source it is aldready included in the source files
SRC_C = \
$(PY_CORE_SRC) \
$(EXTMOD_SRC) \
$(SHARED_SRC_C) \
py/modbuiltins.c \
py/modsys.c \
py/modgc.c \
py/modmicropython.c \
main.c \
mphalport.c \
time.c \
delay.c \
uart_driver.c \
machine_uart.c \
machine_wdt.c \
machine_pin_new.c \
machine_i2c.c \
machine_spi.c \
machine_pwm.c \
machine_uart.c \
modmachine.c \
modtime.c \
random_module.c \
i2c_driver.c \
RTC_driver.c \
pinmux_driver.c \
uart_core.c \
util.c \
plic_driver.c \
init.c \
log.c \
traps.c \
stub.c \
reader_stub.c \
io.c \
dummy_io.c\
wdtimer_driver.c \
gpio_driver.c \
gptimer_driver.c \
spi_driver.c \
pwm_driver.c \
shared/readline/readline.c \
shared/runtime/gchelper_generic.c \
shared/runtime/pyexec.c \
shared/runtime/sys_stdio_mphal.c \
shared/runtime/stdout_helpers.c \
string_functions.c \
math_functions.c \
memory_functions.c \
module.c \
scipy/integrate/integrate.c \
scipy/linalg/linalg.c \
scipy/optimize/optimize.c \
scipy/signal/signal.c \
scipy/special/special.c \
ndarray_operators.c \
ulab.c \
ulab_tools.c \
ndarray.c \
numpy/ndarray/ndarray_iter.c \
ndarray_properties.c \
numpy/approx.c \
numpy/bitwise.c \
numpy/compare.c \
numpy/carray/carray.c \
numpy/carray/carray_tools.c \
numpy/create.c \
numpy/fft/fft.c \
numpy/fft/fft_tools.c \
numpy/filter.c \
numpy/io/io.c \
numpy/linalg/linalg_tools.c \
numpy/linalg/linalg.c \
numpy/numerical.c \
numpy/poly.c \
numpy/random/random.c \
numpy/stats.c \
numpy/transform.c \
numpy/vector.c \
numpy/numpy.c \
scipy/scipy.c \
scipy/integrate/integrate.c \
user/user.c \
utils/utils.c \
py/modmath.c \
#no issues with adding modmath module as well --> for math functionality
# py/objcomplex.c \
#SRC_C += genhdr/qstrdefs.generated.c
#SOURCES += genhdr/qstrdefs.generated.c
#SRC_C += $(BUILD)/genhdr/qstrdefs.generated.c //not needed pola
# SRC_C += $(PY_CORE_SRC)
# SRC_C += $(EXTMOD_SRC)
#SRC_C += ../../py/modbuiltins.c -->redundant
#SRC_C += $(TOP)/py/modio.c #--> 2 new files due to change in version
LIBS += -lgcc
SRC_S = start.S trap.S
LDFLAGS += -T link_ram.ld -Wl,--gc-sections # Use custom linker script
LDFLAGS += -L$(shell dirname $(shell $(CC) -print-libgcc-file-name))
# Source files containing qstrs.
#SRC_QSTR += shared/readline/readline.c shared/runtime/pyexec.c
SRC_QSTR += ../../ports/minimal_new/qstrdefsport.h
SRC_QSTR += \
$(PY_CORE_SRC) \
$(EXTMOD_SRC) \
$(SHARED_SRC_C) \
py/modbuiltins.c \
py/objexcept.c \
py/modsys.c \
py/modgc.c \
py/modmicropython.c \
main.c \
mphalport.c \
time.c \
delay.c \
machine_wdt.c \
machine_pin_new.c \
machine_i2c.c \
machine_spi.c \
machine_pwm.c \
machine_uart.c \
modmachine.c \
modtime.c \
random_module.c \
uart_driver.c \
i2c_driver.c \
RTC_driver.c \
spi_driver.c \
gptimer_driver.c \
pinmux_driver.c \
uart_core.c \
util.c \
plic_driver.c \
init.c \
log.c \
traps.c \
stub.c \
reader_stub.c \
io.c \
string_functions.c \
math_functions.c \
memory_functions.c \
module.c \
wdtimer_driver.c \
gpio_driver.c \
pwm_driver.c \
scipy/integrate/integrate.c \
scipy/linalg/linalg.c \
scipy/optimize/optimize.c \
scipy/signal/signal.c \
scipy/special/special.c \
ndarray_operators.c \
ulab_tools.c \
ndarray.c \
numpy/ndarray/ndarray_iter.c \
ndarray_properties.c \
numpy/approx.c \
numpy/bitwise.c \
numpy/compare.c \
numpy/carray/carray.c \
numpy/carray/carray_tools.c \
numpy/create.c \
numpy/fft/fft.c \
numpy/fft/fft_tools.c \
numpy/filter.c \
numpy/io/io.c \
numpy/linalg/linalg_tools.c \
numpy/linalg/linalg.c \
numpy/numerical.c \
numpy/poly.c \
numpy/random/random.c \
numpy/stats.c \
numpy/transform.c \
numpy/vector.c \
numpy/numpy.c \
scipy/scipy.c \
ports/minimal_new/scipy/integrate/integrate.c \
user/user.c \
utils/utils.c \
ulab.c \
../../py/objcomplex.c \
../../py/objfloat.c \
py/modmath.c \
#QSTR_GLOBAL_DEPENDENCIES = mpconfigport.h
LIBS += -lm -lgcc
SHARED_SRC_C = $(addprefix shared/,\
libc/__errno.c \
libc/string0.c \
netutils/netutils.c \
readline/readline.c \
runtime/interrupt_char.c \
runtime/pyexec.c \
runtime/stdout_helpers.c \
runtime/sys_stdio_mphal.c \
timeutils/timeutils.c \
)
CFLAGS += -I./numpy
CFLAGS += -I./numpy/ndarray
CFLAGS += -I./scipy
CFLAGS += -I./utils
OBJ += $(addprefix $(BUILD)/, $(SHARED_SRC_C:.c=.o))
# Define object files.
OBJ = $(PY_CORE_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.S=.o)) #| $(BUILD)/genhdr/qstrdefs.generated.h
include $(TOP)/py/mkrules.mk
# # Add this to make sure qstrdefs.generated.c is built
# $(BUILD)/genhdr/qstrdefs.generated.c: $(BUILD)/genhdr/qstrdefs.generated.h
# python3 ../../py/makeqstrdata.py $< > $@
build/genhdr/qstrdefs.generated.c: build/genhdr/qstrdefs.preprocessed.h
python3 ../../py/makeqstrdata.py build/genhdr/qstrdefs.preprocessed.h > build/genhdr/qstrdefs.generated.c
# Top-level target: build ELF and BIN
all: $(BUILD)/firmware.elf $(BUILD)/firmware.bin
# Link firmware.elf
$(BUILD)/firmware.elf: $(OBJ) #$(BUILD)/genhdr/qstrdefs.generated.c
echo $(TOP)
$(ECHO) "LINK $@"
$(Q)$(CC) -nostartfiles $(LDFLAGS) -o $@ $^ $(LIBS)
$(Q)$(SIZE) $@
# Generate binary image for flashing
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
$(Q)$(OBJCOPY) -O binary $< $@
# Run using QEMU
run: $(BUILD)/firmware.elf
@echo "Ctrl-A C for QEMU console, then 'quit' to exit"
qemu-system-riscv64 -nographic -serial mon:stdio -machine virt -kernel $(BUILD)/firmware.elf
# Clean build files
clean:
$(Q)rm -f $(OBJ) $(BUILD)/firmware.elf $(BUILD)/firmware.bin
#$(BUILD)/genhdr/qstrdefs.generated.h $(BUILD)/genhdr/qstrdefs.collected.hash
# Size of firmware
size: $(BUILD)/firmware.elf
@echo "Finding the size of the file firmware.elf"
size $(BUILD)/firmware.elf
# dump: $(BUILD)/firmware.elf
# @echo "Generating The obj.dump file from firmware.elf code"
# riscv64-unknown-elf-objdump -D -S $(BUILD)/firmware.elf >> $(BUILD)/firmware.dump
# cat $(BUILD)/firmware.dump
# # Clean build files
# clean:
# $(Q)rm -f $(OBJ) $(BUILD)/firmware.elf $(BUILD)/firmware.bin
# size: $(BUILD)/firmware.elf
# @echo "Finding the size of the file firmware.elf"
# size $(BUILD)/firmware.elf I