stm32/Makefile: Make the generation of firmware.bin
explicit.
The file `$(BUILD)/firmware.bin` was used by the target `deploy-stlink` and `deploy-openocd` but it was generated indirectly by the target `firmware.dfu`. As this file could be used to program boards directly by a Mass Storage copy, it's better to make it explicitly generated. Additionally, some target are refactored to remove redundancy and be more explicit on dependencies.
This commit is contained in:
parent
a7932ae4e6
commit
b04240cb77
@ -564,15 +564,56 @@ CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
|
|||||||
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
|
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: deploy
|
define RUN_DFU
|
||||||
|
$(ECHO) "Writing $(1) to the board"
|
||||||
|
$(if $(filter $(USE_PYDFU),1),\
|
||||||
|
$(Q)$(PYTHON) $(PYDFU) --vid $(BOOTLOADER_DFU_USB_VID) --pid $(BOOTLOADER_DFU_USB_PID) -u $(1),
|
||||||
|
$(Q)$(DFU_UTIL) -a 0 -d $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) -D $(1))
|
||||||
|
endef
|
||||||
|
|
||||||
|
define RUN_STLINK
|
||||||
|
$(ECHO) "Writing $(1) to the board via ST-LINK"
|
||||||
|
$(Q)$(STFLASH) write $(1) $(2)
|
||||||
|
endef
|
||||||
|
|
||||||
|
define RUN_OPENOCD
|
||||||
|
$(ECHO) "Writing $(1) to the board via ST-LINK using OpenOCD"
|
||||||
|
$(Q)$(OPENOCD) -f $(OPENOCD_CONFIG) -c "stm_flash $(1) $(2) $(3) $(4)"
|
||||||
|
endef
|
||||||
|
|
||||||
|
define GENERATE_ELF
|
||||||
|
$(ECHO) "LINK $(1)"
|
||||||
|
$(Q)$(LD) $(LDFLAGS) -o $(1) $(2) $(LDFLAGS_MOD) $(LIBS)
|
||||||
|
$(Q)$(SIZE) $(1)
|
||||||
|
$(if $(filter-out $(TEXT0_ADDR),0x08000000), \
|
||||||
|
$(ECHO) "INFO: this build requires mboot to be installed first")
|
||||||
|
$(if $(filter $(TEXT1_ADDR),0x90000000), \
|
||||||
|
$(ECHO) "INFO: this build places firmware in external QSPI flash")
|
||||||
|
endef
|
||||||
|
|
||||||
|
define GENERATE_BIN
|
||||||
|
$(ECHO) "GEN $(1)"
|
||||||
|
$(Q)$(OBJCOPY) -O binary $(addprefix -j ,$(3)) $(2) $(1)
|
||||||
|
endef
|
||||||
|
|
||||||
|
define GENERATE_DFU
|
||||||
|
$(ECHO) "GEN $(1)"
|
||||||
|
$(Q)$(PYTHON) $(DFU) \
|
||||||
|
-D $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) \
|
||||||
|
$(if $(2),$(addprefix -b ,$(3):$(2))) \
|
||||||
|
$(if $(4),$(addprefix -b ,$(5):$(4))) \
|
||||||
|
$(1)
|
||||||
|
endef
|
||||||
|
|
||||||
|
define GENERATE_HEX
|
||||||
|
$(ECHO) "GEN $(1)"
|
||||||
|
$(Q)$(OBJCOPY) -O ihex $(2) $(1)
|
||||||
|
endef
|
||||||
|
|
||||||
|
.PHONY: deploy deploy-stlink deploy-openocd
|
||||||
|
|
||||||
deploy: $(BUILD)/firmware.dfu
|
deploy: $(BUILD)/firmware.dfu
|
||||||
$(ECHO) "Writing $< to the board"
|
$(call RUN_DFU,$^)
|
||||||
ifeq ($(USE_PYDFU),1)
|
|
||||||
$(Q)$(PYTHON) $(PYDFU) --vid $(BOOTLOADER_DFU_USB_VID) --pid $(BOOTLOADER_DFU_USB_PID) -u $<
|
|
||||||
else
|
|
||||||
$(Q)$(DFU_UTIL) -a 0 -d $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) -D $<
|
|
||||||
endif
|
|
||||||
|
|
||||||
# A board should specify TEXT0_ADDR if to use a different location than the
|
# A board should specify TEXT0_ADDR if to use a different location than the
|
||||||
# default for the firmware memory location. A board can also optionally define
|
# default for the firmware memory location. A board can also optionally define
|
||||||
@ -584,18 +625,17 @@ ifeq ($(TEXT1_ADDR),)
|
|||||||
|
|
||||||
TEXT0_SECTIONS ?= .isr_vector .text .data
|
TEXT0_SECTIONS ?= .isr_vector .text .data
|
||||||
|
|
||||||
deploy-stlink: $(BUILD)/firmware.dfu
|
deploy-stlink: $(BUILD)/firmware.bin
|
||||||
$(ECHO) "Writing $(BUILD)/firmware.bin to the board via ST-LINK"
|
$(call RUN_STLINK,$^,$(TEXT0_ADDR))
|
||||||
$(Q)$(STFLASH) write $(BUILD)/firmware.bin $(TEXT0_ADDR)
|
|
||||||
|
|
||||||
deploy-openocd: $(BUILD)/firmware.dfu
|
deploy-openocd: $(BUILD)/firmware.bin
|
||||||
$(ECHO) "Writing $(BUILD)/firmware.bin to the board via ST-LINK using OpenOCD"
|
$(call RUN_OPENOCD,$^,$(TEXT0_ADDR))
|
||||||
$(Q)$(OPENOCD) -f $(OPENOCD_CONFIG) -c "stm_flash $(BUILD)/firmware.bin $(TEXT0_ADDR)"
|
|
||||||
|
|
||||||
$(BUILD)/firmware.dfu: $(BUILD)/firmware.elf
|
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
|
||||||
$(ECHO) "Create $@"
|
$(call GENERATE_BIN,$@,$^,$(TEXT0_SECTIONS))
|
||||||
$(Q)$(OBJCOPY) -O binary $(addprefix -j ,$(TEXT0_SECTIONS)) $^ $(BUILD)/firmware.bin
|
|
||||||
$(Q)$(PYTHON) $(DFU) -D $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) -b $(TEXT0_ADDR):$(BUILD)/firmware.bin $@
|
$(BUILD)/firmware.dfu: $(BUILD)/firmware.bin
|
||||||
|
$(call GENERATE_DFU,$@,$^,$(TEXT0_ADDR))
|
||||||
|
|
||||||
else
|
else
|
||||||
# TEXT0_ADDR and TEXT1_ADDR are specified so split firmware between these locations
|
# TEXT0_ADDR and TEXT1_ADDR are specified so split firmware between these locations
|
||||||
@ -603,38 +643,28 @@ else
|
|||||||
TEXT0_SECTIONS ?= .isr_vector
|
TEXT0_SECTIONS ?= .isr_vector
|
||||||
TEXT1_SECTIONS ?= .text .data
|
TEXT1_SECTIONS ?= .text .data
|
||||||
|
|
||||||
deploy-stlink: $(BUILD)/firmware.dfu
|
deploy-stlink: $(BUILD)/firmware0.bin $(BUILD)/firmware1.bin
|
||||||
$(ECHO) "Writing $(BUILD)/firmware0.bin to the board via ST-LINK"
|
$(call RUN_STLINK,$(word 1,$^),$(TEXT0_ADDR))
|
||||||
$(Q)$(STFLASH) write $(BUILD)/firmware0.bin $(TEXT0_ADDR)
|
$(call RUN_STLINK,$(word 2,$^),$(TEXT1_ADDR))
|
||||||
$(ECHO) "Writing $(BUILD)/firmware1.bin to the board via ST-LINK"
|
|
||||||
$(Q)$(STFLASH) --reset write $(BUILD)/firmware1.bin $(TEXT1_ADDR)
|
|
||||||
|
|
||||||
deploy-openocd: $(BUILD)/firmware.dfu
|
deploy-openocd: $(BUILD)/firmware0.bin $(BUILD)/firmware1.bin
|
||||||
$(ECHO) "Writing $(BUILD)/firmware{0,1}.bin to the board via ST-LINK using OpenOCD"
|
$(call RUN_OPENOCD,$(word 1,$^),$(TEXT0_ADDR),$(word 2,$^),$(TEXT1_ADDR))
|
||||||
$(Q)$(OPENOCD) -f $(OPENOCD_CONFIG) -c "stm_flash $(BUILD)/firmware0.bin $(TEXT0_ADDR) $(BUILD)/firmware1.bin $(TEXT1_ADDR)"
|
|
||||||
|
|
||||||
$(BUILD)/firmware.dfu: $(BUILD)/firmware.elf
|
$(BUILD)/firmware0.bin: $(BUILD)/firmware.elf
|
||||||
$(ECHO) "GEN $@"
|
$(call GENERATE_BIN,$@,$^,$(TEXT0_SECTIONS))
|
||||||
$(Q)$(OBJCOPY) -O binary $(addprefix -j ,$(TEXT0_SECTIONS)) $^ $(BUILD)/firmware0.bin
|
|
||||||
$(Q)$(OBJCOPY) -O binary $(addprefix -j ,$(TEXT1_SECTIONS)) $^ $(BUILD)/firmware1.bin
|
|
||||||
$(Q)$(PYTHON) $(DFU) -D $(BOOTLOADER_DFU_USB_VID):$(BOOTLOADER_DFU_USB_PID) -b $(TEXT0_ADDR):$(BUILD)/firmware0.bin -b $(TEXT1_ADDR):$(BUILD)/firmware1.bin $@
|
|
||||||
|
|
||||||
|
$(BUILD)/firmware1.bin: $(BUILD)/firmware.elf
|
||||||
|
$(call GENERATE_BIN,$@,$^,$(TEXT1_SECTIONS))
|
||||||
|
|
||||||
|
$(BUILD)/firmware.dfu: $(BUILD)/firmware0.bin $(BUILD)/firmware1.bin
|
||||||
|
$(call GENERATE_DFU,$@,$(word 1,$^),$(TEXT0_ADDR),$(word 2,$^),$(TEXT1_ADDR))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
|
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
|
||||||
$(ECHO) "GEN $@"
|
$(call GENERATE_HEX,$@,$^)
|
||||||
$(Q)$(OBJCOPY) -O ihex $< $@
|
|
||||||
|
|
||||||
$(BUILD)/firmware.elf: $(OBJ)
|
$(BUILD)/firmware.elf: $(OBJ)
|
||||||
$(ECHO) "LINK $@"
|
$(call GENERATE_ELF,$@,$^)
|
||||||
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LDFLAGS_MOD) $(LIBS)
|
|
||||||
$(Q)$(SIZE) $@
|
|
||||||
ifneq ($(TEXT0_ADDR),0x08000000)
|
|
||||||
$(ECHO) "INFO: this build requires mboot to be installed first"
|
|
||||||
endif
|
|
||||||
ifeq ($(TEXT1_ADDR),0x90000000)
|
|
||||||
$(ECHO) "INFO: this build places firmware in external QSPI flash"
|
|
||||||
endif
|
|
||||||
|
|
||||||
PLLVALUES = boards/pllvalues.py
|
PLLVALUES = boards/pllvalues.py
|
||||||
MAKE_PINS = boards/make-pins.py
|
MAKE_PINS = boards/make-pins.py
|
||||||
|
Loading…
Reference in New Issue
Block a user