|
| 1 | +include ../py/mkenv.mk |
| 2 | + |
| 3 | +# qstr definitions (must come before including py.mk) |
| 4 | +QSTR_DEFS = qstrdefsport.h #$(BUILD)/pins_qstr.h |
| 5 | + |
| 6 | +# include py core make definitions |
| 7 | +include ../py/py.mk |
| 8 | + |
| 9 | +ifeq ($(ESP_SDK),) |
| 10 | +$(error ESP_SDK must be set) |
| 11 | +endif |
| 12 | + |
| 13 | +CROSS_COMPILE = xtensa-lx106-elf- |
| 14 | + |
| 15 | +INC = -I. |
| 16 | +INC += -I$(PY_SRC) |
| 17 | +INC += -I../stmhal |
| 18 | +INC += -I$(BUILD) |
| 19 | +INC += -I$(ESP_SDK)/include |
| 20 | + |
| 21 | +CFLAGS_XTENSA = -fsingle-precision-constant -Wdouble-promotion \ |
| 22 | + -D__ets__ -DICACHE_FLASH \ |
| 23 | + -fno-inline-functions \ |
| 24 | + -Wl,-EL -mlongcalls -mtext-section-literals \ |
| 25 | + |
| 26 | +CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_XTENSA) $(COPT) |
| 27 | + |
| 28 | +LDFLAGS = -nostdlib -T esp8266.ld -Map=$(@:.elf=.map) --cref |
| 29 | +LIBS = -L$(ESP_SDK)/lib -lmain -ljson -llwip -lpp -lnet80211 -lwpa -lphy -lnet80211 |
| 30 | + |
| 31 | +LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) |
| 32 | +LIBS += -L $(dir $(LIBGCC_FILE_NAME)) -lgcc |
| 33 | + |
| 34 | +# Debugging/Optimization |
| 35 | +ifeq ($(DEBUG), 1) |
| 36 | +CFLAGS += -g |
| 37 | +COPT = -O0 |
| 38 | +else |
| 39 | +CFLAGS += -fdata-sections -ffunction-sections |
| 40 | +COPT += -Os -DNDEBUG |
| 41 | +LDFLAGS += --gc-sections |
| 42 | +endif |
| 43 | + |
| 44 | +SRC_C = \ |
| 45 | + main.c \ |
| 46 | + esp_mphal.c \ |
| 47 | + gccollect.c \ |
| 48 | + pybstdio.c \ |
| 49 | + uart.c \ |
| 50 | + modpyb.c \ |
| 51 | + |
| 52 | +STM_SRC_C = $(addprefix stmhal/,\ |
| 53 | + printf.c \ |
| 54 | + string0.c \ |
| 55 | + pyexec.c \ |
| 56 | + readline.c \ |
| 57 | + ) |
| 58 | + |
| 59 | +SRC_S = \ |
| 60 | + gchelper.s \ |
| 61 | + |
| 62 | +OBJ = |
| 63 | +OBJ += $(PY_O) |
| 64 | +OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) |
| 65 | +OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) |
| 66 | +OBJ += $(addprefix $(BUILD)/, $(STM_SRC_C:.c=.o)) |
| 67 | +#OBJ += $(BUILD)/pins_$(BOARD).o |
| 68 | + |
| 69 | +all: $(BUILD)/firmware-combined.bin |
| 70 | + |
| 71 | +.PHONY: deploy |
| 72 | + |
| 73 | +deploy: $(BUILD)/firmware-combined.bin |
| 74 | + $(ECHO) "Writing $< to the board" |
| 75 | + $(Q)esptool.py --port /dev/ttyACM0 write_flash 0 $< |
| 76 | + #$(Q)esptool.py --port /dev/ttyACM0 write_flash 0 $(BUILD)/firmware.elf-0x00000.bin |
| 77 | + #$(Q)esptool.py --port /dev/ttyACM0 write_flash 0x10000 $(BUILD)/firmware.elf-0x10000.bin |
| 78 | + |
| 79 | +$(BUILD)/firmware-combined.bin: $(BUILD)/firmware.elf |
| 80 | + $(ECHO) "Create $@" |
| 81 | + $(Q)esptool.py elf2image $^ |
| 82 | + $(Q)$(PYTHON) makeimg.py $(BUILD)/firmware.elf-0x00000.bin $(BUILD)/firmware.elf-0x10000.bin $@ |
| 83 | + |
| 84 | +$(BUILD)/firmware.elf: $(OBJ) |
| 85 | + $(ECHO) "LINK $@" |
| 86 | + $(Q)$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) |
| 87 | + $(Q)$(SIZE) $@ |
| 88 | + |
| 89 | +#MAKE_PINS = boards/make-pins.py |
| 90 | +#BOARD_PINS = boards/$(BOARD)/pins.csv |
| 91 | +#AF_FILE = boards/stm32f4xx_af.csv |
| 92 | +#PREFIX_FILE = boards/stm32f4xx_prefix.c |
| 93 | +#GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c |
| 94 | +#GEN_PINS_HDR = $(HEADER_BUILD)/pins.h |
| 95 | +#GEN_PINS_QSTR = $(BUILD)/pins_qstr.h |
| 96 | +#GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h |
| 97 | +#GEN_PINS_AF_PY = $(BUILD)/pins_af.py |
| 98 | + |
| 99 | +# Making OBJ use an order-only depenedency on the generated pins.h file |
| 100 | +# has the side effect of making the pins.h file before we actually compile |
| 101 | +# any of the objects. The normal dependency generation will deal with the |
| 102 | +# case when pins.h is modified. But when it doesn't exist, we don't know |
| 103 | +# which source files might need it. |
| 104 | +#$(OBJ): | $(HEADER_BUILD)/pins.h |
| 105 | + |
| 106 | +# Use a pattern rule here so that make will only call make-pins.py once to make |
| 107 | +# both pins_$(BOARD).c and pins.h |
| 108 | +#$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/%_qstr.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD) |
| 109 | +# $(ECHO) "Create $@" |
| 110 | +# $(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) --af-const $(GEN_PINS_AF_CONST) --af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC) |
| 111 | +# |
| 112 | +#$(BUILD)/pins_$(BOARD).o: $(BUILD)/pins_$(BOARD).c |
| 113 | +# $(call compile_c) |
| 114 | + |
| 115 | +include ../py/mkrules.mk |
0 commit comments