@@ -36,6 +36,12 @@ include $(BOARD_DIR)/mpconfigboard.mk
36
36
# A board can set MBOOT_TEXT0_ADDR to a custom location where mboot should reside.
37
37
MBOOT_TEXT0_ADDR ?= 0x08000000
38
38
39
+ # The string in MBOOT_VERSION (default defined in version.c if not defined by a
40
+ # board) will be stored in the final MBOOT_VERSION_ALLOCATED_BYTES bytes of mboot flash.
41
+ # A board can change the size of this region by defining MBOOT_VERSION_ALLOCATED_BYTES.
42
+ MBOOT_VERSION_ALLOCATED_BYTES ?= 64
43
+ MBOOT_VERSION_INCLUDE_OPTIONS ?= 1 # if set to 1, this will append build options to version string (see version.c)
44
+
39
45
USBDEV_DIR =usbdev
40
46
DFU =$(TOP ) /tools/dfu.py
41
47
PYDFU ?= $(TOP ) /tools/pydfu.py
@@ -78,9 +84,14 @@ CFLAGS += -DBUILDING_MBOOT=$(BUILDING_MBOOT)
78
84
CFLAGS += -DMICROPY_HW_STM32WB_FLASH_SYNCRONISATION=0
79
85
CFLAGS += -DUSBD_ENABLE_VENDOR_DEVICE_REQUESTS=1
80
86
CFLAGS += -DBOOTLOADER_DFU_USB_VID=$(BOOTLOADER_DFU_USB_VID ) -DBOOTLOADER_DFU_USB_PID=$(BOOTLOADER_DFU_USB_PID )
87
+ ifdef MBOOT_VERSION
88
+ CFLAGS += -DMBOOT_VERSION=\"$(MBOOT_VERSION ) \"
89
+ endif
90
+ CFLAGS += -DMBOOT_VERSION_ALLOCATED_BYTES=$(MBOOT_VERSION_ALLOCATED_BYTES ) -DMBOOT_VERSION_INCLUDE_OPTIONS=$(MBOOT_VERSION_INCLUDE_OPTIONS )
81
91
82
92
MBOOT_LD_FILES ?= stm32_memory.ld stm32_sections.ld
83
93
LDFLAGS += -nostdlib -L . $(addprefix -T,$(MBOOT_LD_FILES ) ) -Map=$(@:.elf=.map ) --cref
94
+ LDFLAGS += --defsym mboot_version_len=$(MBOOT_VERSION_ALLOCATED_BYTES )
84
95
LIBS += $(shell $(CC ) $(CFLAGS ) -print-libgcc-file-name)
85
96
86
97
# Remove uncalled code from the final image.
@@ -121,6 +132,7 @@ SRC_C += \
121
132
vfs_fat.c \
122
133
vfs_lfs.c \
123
134
vfs_raw.c \
135
+ version.c \
124
136
drivers/bus/softspi.c \
125
137
drivers/bus/softqspi.c \
126
138
drivers/memory/spiflash.c \
@@ -206,7 +218,7 @@ deploy-stlink: $(BUILD)/firmware.dfu
206
218
207
219
$(BUILD ) /firmware.dfu : $(BUILD ) /firmware.elf
208
220
$(ECHO ) " Create $@ "
209
- $(Q )$(OBJCOPY ) -O binary -j .isr_vector -j .text -j .data $^ $(BUILD ) /firmware.bin
221
+ $(Q )$(OBJCOPY ) -O binary -j .isr_vector -j .text -j .data -j .mboot_version_text $^ $(BUILD ) /firmware.bin
210
222
$(Q )$(PYTHON ) $(DFU ) -b $(MBOOT_TEXT0_ADDR ) :$(BUILD ) /firmware.bin $@
211
223
212
224
$(BUILD ) /firmware.hex : $(BUILD ) /firmware.elf
@@ -231,8 +243,9 @@ GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
231
243
GEN_PINS_HDR = $(HEADER_BUILD ) /pins.h
232
244
GEN_PINS_AF_CONST = $(HEADER_BUILD ) /pins_af_const.h
233
245
GEN_PINS_AF_DEFS = $(HEADER_BUILD ) /pins_af_defs.h
246
+ GEN_MPVERSION = $(HEADER_BUILD ) /mpversion.h
234
247
235
- $(OBJ ) : $(GEN_QSTRDEFS_GENERATED ) $(GEN_ROOT_POINTERS ) $(GEN_PINS_AF_DEFS )
248
+ $(OBJ ) : $(GEN_QSTRDEFS_GENERATED ) $(GEN_ROOT_POINTERS ) $(GEN_PINS_AF_DEFS ) $( GEN_MPVERSION )
236
249
237
250
$(HEADER_BUILD ) :
238
251
$(MKDIR ) -p $(BUILD ) /genhdr
@@ -250,6 +263,9 @@ $(GEN_PINS_AF_DEFS): $(BOARD_PINS) $(MAKE_PINS) ../$(AF_FILE) $(PREFIX_FILE) | $
250
263
--output-af-const $(GEN_PINS_AF_CONST ) --output-af-defs $(GEN_PINS_AF_DEFS ) \
251
264
--mboot-mode
252
265
266
+ $(GEN_MPVERSION ) : | $(HEADER_BUILD )
267
+ $(PYTHON ) ../../../py/makeversionhdr.py $@
268
+
253
269
# ########################################
254
270
255
271
vpath % .S . $(TOP )
0 commit comments