stm32/mboot: Allow mboot to be placed at any location in flash.
A board can now define MBOOT_TEXT0_ADDR to place mboot at a location other than 0x08000000. This can be useful if, for example, there is already a different bootloader on the device. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
58be5a5aa3
commit
37494b8c8a
@ -27,6 +27,10 @@ MICROPY_ROM_TEXT_COMPRESSION ?= 1
|
||||
# File containing description of content to be frozen into firmware.
|
||||
FROZEN_MANIFEST ?= boards/manifest.py
|
||||
|
||||
# Location of mboot (or other bootloader) if the device has one.
|
||||
# Used by machine.bootloader().
|
||||
MBOOT_TEXT0_ADDR ?= 0x08000000
|
||||
|
||||
# include py core make definitions
|
||||
include $(TOP)/py/py.mk
|
||||
|
||||
@ -101,6 +105,7 @@ CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
|
||||
CFLAGS += $(COPT)
|
||||
CFLAGS += -I$(BOARD_DIR)
|
||||
CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES)xx_hal.h>'
|
||||
CFLAGS += -DMBOOT_VTOR=$(MBOOT_TEXT0_ADDR)
|
||||
CFLAGS += -DMICROPY_HW_VTOR=$(TEXT0_ADDR)
|
||||
|
||||
# Configure for nan-boxing object model if requested
|
||||
|
@ -29,6 +29,9 @@ BUILDING_MBOOT = 1
|
||||
include ../../../py/mkenv.mk
|
||||
include $(BOARD_DIR)/mpconfigboard.mk
|
||||
|
||||
# A board can set MBOOT_TEXT0_ADDR to a custom location where mboot should reside.
|
||||
MBOOT_TEXT0_ADDR ?= 0x08000000
|
||||
|
||||
MCU_SERIES_UPPER = $(shell echo $(MCU_SERIES) | tr '[:lower:]' '[:upper:]')
|
||||
CMSIS_MCU_LOWER = $(shell echo $(CMSIS_MCU) | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
@ -77,6 +80,7 @@ CFLAGS += $(COPT)
|
||||
CFLAGS += -I$(BOARD_DIR)
|
||||
CFLAGS += -DSTM32_HAL_H='<stm32$(MCU_SERIES)xx_hal.h>'
|
||||
CFLAGS += -DBOARD_$(BOARD)
|
||||
CFLAGS += -DMBOOT_VTOR=$(MBOOT_TEXT0_ADDR)
|
||||
CFLAGS += -DAPPLICATION_ADDR=$(TEXT0_ADDR)
|
||||
CFLAGS += -DFFCONF_H=\"ports/stm32/mboot/ffconf.h\"
|
||||
CFLAGS += -DLFS1_NO_MALLOC -DLFS1_NO_DEBUG -DLFS1_NO_WARN -DLFS1_NO_ERROR -DLFS1_NO_ASSERT
|
||||
@ -181,20 +185,18 @@ $(TOP)/lib/stm32lib/README.md:
|
||||
|
||||
.PHONY: deploy deploy-stlink
|
||||
|
||||
FLASH_ADDR = 0x08000000
|
||||
|
||||
deploy: $(BUILD)/firmware.dfu
|
||||
$(ECHO) "Writing $< to the board"
|
||||
$(Q)$(PYTHON) $(PYDFU) -u $<
|
||||
|
||||
deploy-stlink: $(BUILD)/firmware.dfu
|
||||
$(ECHO) "Writing $< to the board via ST-LINK"
|
||||
$(Q)$(STFLASH) write $(BUILD)/firmware.bin $(FLASH_ADDR)
|
||||
$(Q)$(STFLASH) write $(BUILD)/firmware.bin $(MBOOT_TEXT0_ADDR)
|
||||
|
||||
$(BUILD)/firmware.dfu: $(BUILD)/firmware.elf
|
||||
$(ECHO) "Create $@"
|
||||
$(Q)$(OBJCOPY) -O binary -j .isr_vector -j .text -j .data $^ $(BUILD)/firmware.bin
|
||||
$(Q)$(PYTHON) $(DFU) -b $(FLASH_ADDR):$(BUILD)/firmware.bin $@
|
||||
$(Q)$(PYTHON) $(DFU) -b $(MBOOT_TEXT0_ADDR):$(BUILD)/firmware.bin $@
|
||||
|
||||
$(BUILD)/firmware.hex: $(BUILD)/firmware.elf
|
||||
$(ECHO) "Create $@"
|
||||
|
@ -1358,7 +1358,7 @@ void stm32_main(int initial_r0) {
|
||||
#endif
|
||||
|
||||
// Make sure IRQ vector table points to flash where this bootloader lives.
|
||||
SCB->VTOR = FLASH_BASE;
|
||||
SCB->VTOR = MBOOT_VTOR;
|
||||
|
||||
// Enable 8-byte stack alignment for IRQ handlers, in accord with EABI
|
||||
SCB->CCR |= SCB_CCR_STKALIGN_Msk;
|
||||
|
@ -270,16 +270,16 @@ STATIC NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args)
|
||||
#if MICROPY_HW_USES_BOOTLOADER
|
||||
if (n_args == 0 || !mp_obj_is_true(args[0])) {
|
||||
// By default, with no args given, we enter the custom bootloader (mboot)
|
||||
powerctrl_enter_bootloader(0x70ad0000, 0x08000000);
|
||||
powerctrl_enter_bootloader(0x70ad0000, MBOOT_VTOR);
|
||||
}
|
||||
|
||||
if (n_args == 1 && mp_obj_is_str_or_bytes(args[0])) {
|
||||
// With a string/bytes given, pass its data to the custom bootloader
|
||||
size_t len;
|
||||
const char *data = mp_obj_str_get_data(args[0], &len);
|
||||
void *mboot_region = (void *)*((volatile uint32_t *)0x08000000);
|
||||
void *mboot_region = (void *)*((volatile uint32_t *)MBOOT_VTOR);
|
||||
memmove(mboot_region, data, len);
|
||||
powerctrl_enter_bootloader(0x70ad0080, 0x08000000);
|
||||
powerctrl_enter_bootloader(0x70ad0080, MBOOT_VTOR);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user