stm32/mboot: Pass initial_r0 to early-init and get-reset-mode funcs.

This allows a board to modify initial_r0 if needed.

Also make default board behaviour functions always available, named as
mboot_get_reset_mode_default and mboot_state_change_default.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2022-06-01 20:59:11 +10:00
parent e64947dc90
commit 87fbceef26
6 changed files with 29 additions and 28 deletions

View File

@ -133,7 +133,7 @@ void board_mboot_led_state(int led, int state) {
hub_display_update(); hub_display_update();
} }
int board_mboot_get_reset_mode(void) { int board_mboot_get_reset_mode(uint32_t *initial_r0) {
board_button_init(); board_button_init();
int reset_mode = BOARDCTRL_RESET_MODE_NORMAL; int reset_mode = BOARDCTRL_RESET_MODE_NORMAL;
if (board_button_state()) { if (board_button_state()) {

View File

@ -127,7 +127,7 @@ extern struct _spi_bdev_t spi_bdev;
#define MBOOT_BOARD_LED_INIT board_mboot_led_init #define MBOOT_BOARD_LED_INIT board_mboot_led_init
#define MBOOT_BOARD_LED_STATE board_mboot_led_state #define MBOOT_BOARD_LED_STATE board_mboot_led_state
#define MBOOT_BOARD_EARLY_INIT board_init #define MBOOT_BOARD_EARLY_INIT(initial_r0) board_init()
#define MBOOT_BOARD_CLEANUP board_mboot_cleanup #define MBOOT_BOARD_CLEANUP board_mboot_cleanup
#define MBOOT_BOARD_GET_RESET_MODE board_mboot_get_reset_mode #define MBOOT_BOARD_GET_RESET_MODE board_mboot_get_reset_mode
@ -138,5 +138,5 @@ void board_init(void);
void board_mboot_cleanup(int reset_mode); void board_mboot_cleanup(int reset_mode);
void board_mboot_led_init(void); void board_mboot_led_init(void);
void board_mboot_led_state(int led, int state); void board_mboot_led_state(int led, int state);
int board_mboot_get_reset_mode(void); int board_mboot_get_reset_mode(uint32_t *initial_r0);
void *btstack_chipset_cc256x_instance(void); void *btstack_chipset_cc256x_instance(void);

View File

@ -221,5 +221,5 @@ extern struct _spi_bdev_t spi_bdev2;
#define MBOOT_SPIFLASH2_SPIFLASH (&spi_bdev2.spiflash) #define MBOOT_SPIFLASH2_SPIFLASH (&spi_bdev2.spiflash)
#define MBOOT_SPIFLASH2_CONFIG (&spiflash2_config) #define MBOOT_SPIFLASH2_CONFIG (&spiflash2_config)
#define MBOOT_BOARD_EARLY_INIT mboot_board_early_init #define MBOOT_BOARD_EARLY_INIT(initial_r0) mboot_board_early_init()
void mboot_board_early_init(void); void mboot_board_early_init(void);

View File

@ -1346,9 +1346,7 @@ void stm32_main(uint32_t initial_r0) {
SCB_EnableDCache(); SCB_EnableDCache();
#endif #endif
#if defined(MBOOT_BOARD_EARLY_INIT) MBOOT_BOARD_EARLY_INIT(&initial_r0);
MBOOT_BOARD_EARLY_INIT();
#endif
#ifdef MBOOT_BOOTPIN_PIN #ifdef MBOOT_BOOTPIN_PIN
mp_hal_pin_config(MBOOT_BOOTPIN_PIN, MP_HAL_PIN_MODE_INPUT, MBOOT_BOOTPIN_PULL, 0); mp_hal_pin_config(MBOOT_BOOTPIN_PIN, MP_HAL_PIN_MODE_INPUT, MBOOT_BOOTPIN_PULL, 0);
@ -1361,7 +1359,7 @@ void stm32_main(uint32_t initial_r0) {
goto enter_bootloader; goto enter_bootloader;
} }
int reset_mode = mboot_get_reset_mode(); int reset_mode = MBOOT_BOARD_GET_RESET_MODE(&initial_r0);
if (reset_mode != BOARDCTRL_RESET_MODE_BOOTLOADER) { if (reset_mode != BOARDCTRL_RESET_MODE_BOOTLOADER) {
// Bootloader mode was not selected so try to enter the application, // Bootloader mode was not selected so try to enter the application,
// passing through the reset_mode. This will return if the application // passing through the reset_mode. This will return if the application

View File

@ -38,8 +38,20 @@
#define NORETURN __attribute__((noreturn)) #define NORETURN __attribute__((noreturn))
#define MP_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define MP_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#ifndef MBOOT_BOARD_EARLY_INIT
#define MBOOT_BOARD_EARLY_INIT(initial_r0)
#endif
#ifndef MBOOT_BOARD_ENTRY_INIT #ifndef MBOOT_BOARD_ENTRY_INIT
#define MBOOT_BOARD_ENTRY_INIT mboot_entry_init #define MBOOT_BOARD_ENTRY_INIT(initial_r0) mboot_entry_init_default()
#endif
#ifndef MBOOT_BOARD_GET_RESET_MODE
#define MBOOT_BOARD_GET_RESET_MODE(initial_r0) mboot_get_reset_mode_default()
#endif
#ifndef MBOOT_BOARD_STATE_CHANGE
#define MBOOT_BOARD_STATE_CHANGE(state, arg) mboot_state_change_default((state), (arg))
#endif #endif
#ifndef MBOOT_ADDRESS_SPACE_64BIT #ifndef MBOOT_ADDRESS_SPACE_64BIT
@ -154,7 +166,7 @@ int do_write(uint32_t addr, const uint8_t *src8, size_t len, bool dry_run);
const uint8_t *elem_search(const uint8_t *elem, uint8_t elem_id); const uint8_t *elem_search(const uint8_t *elem, uint8_t elem_id);
int fsload_process(void); int fsload_process(void);
static inline void mboot_entry_init(uint32_t *initial_r0) { static inline void mboot_entry_init_default(void) {
// Init subsystems (mboot_get_reset_mode() may call these, calling them again is ok) // Init subsystems (mboot_get_reset_mode() may call these, calling them again is ok)
led_init(); led_init();
@ -167,20 +179,15 @@ static inline void mboot_entry_init(uint32_t *initial_r0) {
#endif #endif
} }
#if defined(MBOOT_BOARD_GET_RESET_MODE) int mboot_get_reset_mode_default(void);
static inline int mboot_get_reset_mode(void) { void mboot_state_change_default(mboot_state_t state, uint32_t arg);
return MBOOT_BOARD_GET_RESET_MODE();
}
#else
int mboot_get_reset_mode(void);
#endif
#if defined(MBOOT_BOARD_STATE_CHANGE)
static inline void mboot_state_change(mboot_state_t state, uint32_t arg) { static inline void mboot_state_change(mboot_state_t state, uint32_t arg) {
#if defined(MBOOT_BOARD_STATE_CHANGE)
return MBOOT_BOARD_STATE_CHANGE(state, arg); return MBOOT_BOARD_STATE_CHANGE(state, arg);
#else
return mboot_state_change_default(state, arg);
#endif
} }
#else
void mboot_state_change(mboot_state_t state, uint32_t arg);
#endif
#endif // MICROPY_INCLUDED_STM32_MBOOT_MBOOT_H #endif // MICROPY_INCLUDED_STM32_MBOOT_MBOOT_H

View File

@ -136,7 +136,7 @@ void led0_update(void) {
/******************************************************************************/ /******************************************************************************/
// User button // User button
#if !defined(MBOOT_BOARD_GET_RESET_MODE) #ifdef MICROPY_HW_USRSW_PIN
#define RESET_MODE_NUM_STATES (4) #define RESET_MODE_NUM_STATES (4)
#define RESET_MODE_TIMEOUT_CYCLES (8) #define RESET_MODE_TIMEOUT_CYCLES (8)
@ -158,7 +158,7 @@ static int usrbtn_state(void) {
return mp_hal_pin_read(MICROPY_HW_USRSW_PIN) == MICROPY_HW_USRSW_PRESSED; return mp_hal_pin_read(MICROPY_HW_USRSW_PIN) == MICROPY_HW_USRSW_PRESSED;
} }
int mboot_get_reset_mode(void) { int mboot_get_reset_mode_default(void) {
usrbtn_init(); usrbtn_init();
int reset_mode = BOARDCTRL_RESET_MODE_NORMAL; int reset_mode = BOARDCTRL_RESET_MODE_NORMAL;
if (usrbtn_state()) { if (usrbtn_state()) {
@ -198,9 +198,7 @@ int mboot_get_reset_mode(void) {
/******************************************************************************/ /******************************************************************************/
// State change // State change
#if !defined(MBOOT_BOARD_STATE_CHANGE) void mboot_state_change_default(mboot_state_t state, uint32_t arg) {
void mboot_state_change(mboot_state_t state, uint32_t arg) {
switch (state) { switch (state) {
case MBOOT_STATE_DFU_START: case MBOOT_STATE_DFU_START:
led_state_all(0); led_state_all(0);
@ -255,5 +253,3 @@ void mboot_state_change(mboot_state_t state, uint32_t arg) {
break; break;
} }
} }
#endif