-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.micropython
161 lines (116 loc) · 4.22 KB
/
Makefile.micropython
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
# TODO: fix clean behaviour
# TOP directory points to the micropython directory
TOP := test-build/micropython
# Include the core environment definitions; this will set $(TOP).
include $(TOP)/py/mkenv.mk
# Include py core make definitions.
include $(TOP)/py/py.mk
# Source files
SRC_DIR := src/ports/bare-arm
LIB_DIR += test-build/toolchain/aarch64-elf/lib
# Set makefile-level MicroPython feature configurations.
LDSCRIPT = $(SRC_DIR)/linker-mpy.ld
# Define toolchain and other tools.
CROSS_COMPILE = aarch64-elf-
CC := $(CROSS_COMPILE)gcc
AS := $(CROSS_COMPILE)as
LD := $(CROSS_COMPILE)ld
OBJCOPY := $(CROSS_COMPILE)objcopy
SIZE := $(CROSS_COMPILE)size
# Set the architecture-specific flags
ARCH_FLAGS := -march=armv8-a -mcpu=cortex-a57 -mtune=cortex-a57
DFU = $(TOP)/tools/dfu.py
PYDFU = $(TOP)/tools/pydfu.py
# Set CFLAGS.
CFLAGS += -Isrc/include -Isrc/include/bare-arm -I$(PREFIX)/aarch64-elf/include -I$(TOP) -I$(BUILD) -I$(TOP)/shared/runtime
# For MicroPython REPL
ifeq ($(MICROPY_USE_READLINE),1)
INC += -I$(TOP)/shared/readline
CFLAGS += -DMICROPY_USE_READLINE=1
SHARED_SRC_C_EXTRA += readline/readline.c
endif
CFLAGS += $(ARCH_FLAGS) -std=gnu99 -nostdlib #-std=c99 is not compatible with asm, must use __asm__
# Configure floating point support
ifeq ($(MICROPY_FLOAT_IMPL),double)
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_DOUBLE
else ifeq ($(MICROPY_FLOAT_IMPL),none)
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_NONE
else
CFLAGS += -DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_FLOAT
CFLAGS += -fsingle-precision-constant
endif
# Select debugging or optimization build.
ifeq ($(DEBUG), 1)
CFLAGS += -Og -ffreestanding -g -Wall -fno-builtin -fverbose-asm -Werror
MICROPY_ROM_TEXT_COMPRESSION = 0
else
CFLAGS += -Os -DNDEBUG -ffreestanding
CFLAGS += -fdata-sections -ffunction-sections
endif
# Set linker flags.
LDFLAGS += -nostdlib -T$(LDSCRIPT) --gc-sections
LDFLAGS += -static
ASFLAGS := $(ARCH_FLAGS)
# Define the required source files.
SRC_C += $(SRC_DIR)/main.c $(SRC_DIR)/lib.c $(SRC_DIR)/system.c $(SRC_DIR)/../../sys/errno.c $(SRC_DIR)/gccollect.c
SRC_C += $(SRC_DIR)/help.c
SRC_C += $(TOP)/shared/readline/readline.c $(TOP)/shared/runtime/pyexec.c $(TOP)/shared/runtime/stdout_helpers.c $(TOP)/shared/libc/printf.c
SRC_C += $(TOP)/shared/runtime/gchelper_generic.c
# List of sources for qstr extraction
#SRC_QSTR += $(TOP)/shared/runtime/pyexec.c $(TOP)/shared/readline/readline.c
SRC_QSTR += $(TOP)/shared/readline/readline.c $(TOP)/shared/runtime/pyexec.c
ifeq ($(CROSS), 1)
SRC_C += $(TOP)/shared/libc/string0.c
endif
ifneq ($(FROZEN_MANIFEST),)
CFLAGS += -DMPZ_DIG_SIZE=16 # force 16 bits to work on both 32 and 64 bit archs
endif
# Define float implementation
ifeq ($(MICROPY_FLOAT_IMPL),double)
LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_C)
ifeq ($(SUPPORTS_HARDWARE_FP_DOUBLE),1)
LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_SQRT_HW_C)
else
LIBM_SRC_C += $(SRC_LIB_LIBM_DBL_SQRT_SW_C)
endif
else
LIBM_SRC_C += $(SRC_LIB_LIBM_C)
ifeq ($(SUPPORTS_HARDWARE_FP_SINGLE),1)
LIBM_SRC_C += $(SRC_LIB_LIBM_SQRT_HW_C)
else
LIBM_SRC_C += $(SRC_LIB_LIBM_SQRT_SW_C)
endif
endif
# Define assembly source files
SRC_ASM += $(SRC_DIR)/startup.S
# Define the required object files.
OBJ += $(PY_CORE_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(LIBM_SRC_C:.c=.o))
OBJ += $(SRC_ASM:.S=.o)
OBJ_RUN =
OBJ_RUN += $(addprefix $(BUILD)/, $(SRC_RUN_C:.c=.o))
ALL_OBJ_RUN = $(OBJ) $(OBJ_RUN)
# Include remaining core make rules.
include $(TOP)/py/mkrules.mk
.PHONY: all clean
# Define the top-level target, the main firmware.
all: $(BUILD)/firmware.bin
$(BUILD)/%.o: %.S | $(BUILD)
$(AS) $(ASFLAGS) $< -o $@
$(BUILD)/firmware.elf: $(ALL_OBJ_RUN)
$(ECHO) "LINK $@"
$(Q)$(LD) $(LDFLAGS) -o $@ $^ -L$(LIB_DIR) -lm
$(Q)$(SIZE) $@
$(Q)$(OBJCOPY) -O binary $(BUILD)/firmware.elf kernel.img
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
$(ECHO) "Create $@"
$(Q)$(OBJCOPY) -O binary -j .isr_vector -j .text -j .data $^ $@
$(BUILD)/firmware.dfu: $(BUILD)/firmware.bin
$(ECHO) "Create $@"
$(Q)$(PYTHON) $(DFU) -b 0x08000000:$^ $@
deploy: $(BUILD)/firmware.dfu
$(Q)$(PYTHON) $(PYDFU) -u $^
debug: $(BUILD)/firmware.elf
qemu-system-aarch64 -M virt -cpu cortex-a53 -kernel $< -S -s &
aarch64-elf-gdb $< -ex "target remote localhost:1234"