|
| 1 | +# This file is part of the MicroPython project, http://micropython.org/ |
| 2 | +# |
| 3 | +# The MIT License (MIT) |
| 4 | +# |
| 5 | +# Copyright (c) 2019 Scott Shawcroft for Adafruit Industries |
| 6 | +# |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +# of this software and associated documentation files (the "Software"), to deal |
| 9 | +# in the Software without restriction, including without limitation the rights |
| 10 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +# copies of the Software, and to permit persons to whom the Software is |
| 12 | +# furnished to do so, subject to the following conditions: |
| 13 | +# |
| 14 | +# The above copyright notice and this permission notice shall be included in |
| 15 | +# all copies or substantial portions of the Software. |
| 16 | +# |
| 17 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | +# THE SOFTWARE. |
| 24 | + |
| 25 | +# Select the board to build for. |
| 26 | +ifeq ($(BOARD),) |
| 27 | + $(error You must provide a BOARD parameter) |
| 28 | +else |
| 29 | + ifeq ($(wildcard boards/$(BOARD)/.),) |
| 30 | + $(error Invalid BOARD specified) |
| 31 | + endif |
| 32 | +endif |
| 33 | + |
| 34 | +# If the build directory is not given, make it reflect the board name. |
| 35 | +BUILD ?= build-$(BOARD) |
| 36 | + |
| 37 | +include ../../py/mkenv.mk |
| 38 | +# Board-specific |
| 39 | +include boards/$(BOARD)/mpconfigboard.mk |
| 40 | +# Port-specific |
| 41 | +include mpconfigport.mk |
| 42 | + |
| 43 | +# CircuitPython-specific |
| 44 | +include $(TOP)/py/circuitpy_mpconfig.mk |
| 45 | + |
| 46 | +# qstr definitions (must come before including py.mk) |
| 47 | +QSTR_DEFS = qstrdefsport.h |
| 48 | + |
| 49 | +# include py core make definitions |
| 50 | +include $(TOP)/py/py.mk |
| 51 | + |
| 52 | +include $(TOP)/supervisor/supervisor.mk |
| 53 | + |
| 54 | +# Include make rules and variables common across CircuitPython builds. |
| 55 | +include $(TOP)/py/circuitpy_defns.mk |
| 56 | + |
| 57 | +CROSS_COMPILE = riscv64-unknown-elf- |
| 58 | + |
| 59 | +####################################### |
| 60 | +# CFLAGS |
| 61 | +####################################### |
| 62 | + |
| 63 | +INC += -I. |
| 64 | +INC += -I../.. |
| 65 | +INC += -I$(BUILD) |
| 66 | +INC += -I$(BUILD)/genhdr |
| 67 | +INC += -I./boards |
| 68 | +INC += -I./boards/$(BOARD) |
| 69 | +INC += -I./peripherals |
| 70 | +INC += -I../../lib/mp-readline |
| 71 | +INC += -I../../lib/tinyusb/src |
| 72 | +INC += -I../../supervisor/shared/usb |
| 73 | + |
| 74 | + |
| 75 | +#Debugging/Optimization |
| 76 | +ifeq ($(DEBUG), 1) |
| 77 | + CFLAGS += -ggdb |
| 78 | + # You may want to enable these flags to make setting breakpoints easier. |
| 79 | + CFLAGS += -fno-inline -fno-ipa-sra |
| 80 | +else |
| 81 | + CFLAGS += -Os -DNDEBUG -ggdb3 |
| 82 | + # TODO: Test with -flto |
| 83 | + ### CFLAGS += -flto |
| 84 | +endif |
| 85 | + |
| 86 | +CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) |
| 87 | + |
| 88 | +# TODO: check this |
| 89 | +CFLAGS += -D__START=main -DFOMU |
| 90 | + |
| 91 | +LD_FILE := boards/$(BOARD)/$(BOARD)-spi.ld |
| 92 | + |
| 93 | +LDFLAGS = $(CFLAGS) -fshort-enums -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs -Wl,-melf32lriscv |
| 94 | +LIBS := -lgcc -lc |
| 95 | + |
| 96 | + |
| 97 | +LDFLAGS += -flto -ffreestanding -nostartfiles -Wl,--gc-section -Wl,-Bstatic -Wl,-melf32lriscv -nostartfiles \ |
| 98 | + -Wl,--no-warn-mismatch \ |
| 99 | + -Wl,--build-id=none |
| 100 | + |
| 101 | +# Use toolchain libm if we're not using our own. |
| 102 | +ifndef INTERNAL_LIBM |
| 103 | +LIBS += -lm |
| 104 | +endif |
| 105 | + |
| 106 | +# TinyUSB defines |
| 107 | +CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_VALENTYUSB_EPTRI -DCFG_TUD_CDC_RX_BUFSIZE=1024 -DCFG_TUD_CDC_TX_BUFSIZE=1024 -DCFG_TUD_MSC_BUFSIZE=4096 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_MIDI_TX_BUFSIZE=128 |
| 108 | + |
| 109 | + |
| 110 | +###################################### |
| 111 | +# source |
| 112 | +###################################### |
| 113 | + |
| 114 | + |
| 115 | +SRC_C += \ |
| 116 | + background.c \ |
| 117 | + fatfs_port.c \ |
| 118 | + mphalport.c \ |
| 119 | + tick.c \ |
| 120 | + boards/$(BOARD)/board.c \ |
| 121 | + boards/$(BOARD)/pins.c \ |
| 122 | + lib/libc/string0.c \ |
| 123 | + lib/mp-readline/readline.c \ |
| 124 | + lib/oofatfs/ff.c \ |
| 125 | + lib/oofatfs/option/ccsbcs.c \ |
| 126 | + lib/timeutils/timeutils.c \ |
| 127 | + lib/utils/buffer_helper.c \ |
| 128 | + lib/utils/context_manager_helpers.c \ |
| 129 | + lib/utils/interrupt_char.c \ |
| 130 | + lib/utils/pyexec.c \ |
| 131 | + lib/utils/stdout_helpers.c \ |
| 132 | + lib/utils/sys_stdio_mphal.c \ |
| 133 | + supervisor/shared/memory.c |
| 134 | + |
| 135 | +ifneq ($(USB),FALSE) |
| 136 | +SRC_C += lib/tinyusb/src/portable/valentyusb/eptri/dcd_eptri.c |
| 137 | +endif |
| 138 | + |
| 139 | +SRC_S = \ |
| 140 | + crt0-vexriscv.S |
| 141 | + |
| 142 | +SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ |
| 143 | + $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ |
| 144 | + $(addprefix common-hal/, $(SRC_COMMON_HAL)) |
| 145 | + |
| 146 | +SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ |
| 147 | + $(addprefix shared-module/, $(SRC_SHARED_MODULE)) \ |
| 148 | + $(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL)) |
| 149 | + |
| 150 | + |
| 151 | +ifneq ($(FROZEN_MPY_DIR),) |
| 152 | +FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py') |
| 153 | +FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy)) |
| 154 | +endif |
| 155 | + |
| 156 | +OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) |
| 157 | +OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o)) |
| 158 | +OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o)) |
| 159 | +ifeq ($(INTERNAL_LIBM),1) |
| 160 | +OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o)) |
| 161 | +endif |
| 162 | +OBJ += $(addprefix $(BUILD)/, $(SRC_S:.S=.o)) |
| 163 | +OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o)) |
| 164 | + |
| 165 | +$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os |
| 166 | +$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os |
| 167 | + |
| 168 | +# List of sources for qstr extraction |
| 169 | +SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) |
| 170 | +# Sources that only hold QSTRs after pre-processing. |
| 171 | +SRC_QSTR_PREPROCESSOR += |
| 172 | + |
| 173 | + |
| 174 | +all: $(BUILD)/firmware.bin $(BUILD)/firmware.dfu |
| 175 | + |
| 176 | +$(BUILD)/firmware.elf: $(OBJ) |
| 177 | + $(STEPECHO) "LINK $@" |
| 178 | + $(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group |
| 179 | + $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(LD_FILE) |
| 180 | + |
| 181 | +$(BUILD)/firmware.bin: $(BUILD)/firmware.elf |
| 182 | + $(STEPECHO) "Create $@" |
| 183 | + $(Q)$(OBJCOPY) -O binary $^ $@ |
| 184 | +# $(Q)$(OBJCOPY) -O binary -j .vectors -j .text -j .data $^ $@ |
| 185 | + |
| 186 | +$(BUILD)/firmware.hex: $(BUILD)/firmware.elf |
| 187 | + $(STEPECHO) "Create $@" |
| 188 | + $(Q)$(OBJCOPY) -O ihex $^ $@ |
| 189 | +# $(Q)$(OBJCOPY) -O ihex -j .vectors -j .text -j .data $^ $@ |
| 190 | + |
| 191 | +$(BUILD)/firmware.dfu: $(BUILD)/firmware.bin |
| 192 | + $(ECHO) "Create $@" |
| 193 | + $(PYTHON3) $(TOP)/tools/dfu.py -b $^ -D 0x1209:0x5bf0 "$(BUILD)/firmware.dfu" |
| 194 | + |
| 195 | +include $(TOP)/py/mkrules.mk |
| 196 | + |
| 197 | +# Print out the value of a make variable. |
| 198 | +# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile |
| 199 | +print-%: |
| 200 | + @echo $* = $($*) |
0 commit comments