8000 Allow boards to override the default machine.bootloader behavior. by iabdalkader · Pull Request #8590 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

Allow boards to override the default machine.bootloader behavior. #8590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ports/nrf/modules/machine/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ STATIC mp_obj_t machine_disable_irq(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq);

NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
while (1) {
;
}
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);

STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_umachine) },
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) },
Expand Down Expand Up @@ -242,6 +250,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
#if defined(NRF52_SERIES)
{ MP_ROM_QSTR(MP_QSTR_NFC_RESET), MP_ROM_INT(PYB_RESET_NFC) },
#endif
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) },
};

STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table);
Expand Down
1 change: 1 addition & 0 deletions ports/nrf/modules/machine/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_lightsleep_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_deepsleep_obj);
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);

#endif // __MICROPY_INCLUDED_NRF5_MODMACHINE_H__
4 changes: 4 additions & 0 deletions ports/nrf/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,7 @@ extern const struct _mp_obj_module_t music_module;
#ifndef MP_NEED_LOG2
#define MP_NEED_LOG2 (1)
#endif

#ifndef MICROPY_BOARD_ENTER_BOOTLOADER
#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args)
#endif
4 changes: 4 additions & 0 deletions ports/renesas-ra/boardctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#define MICROPY_BOARD_STARTUP powerctrl_check_enter_bootloader
#endif

#ifndef MICROPY_BOARD_ENTER_BOOTLOADER
#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args)
#endif

#ifndef MICROPY_BOARD_EARLY_INIT
#define MICROPY_BOARD_EARLY_INIT()
#endif
Expand Down
5 changes: 4 additions & 1 deletion ports/renesas-ra/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "gccollect.h"
#include "irq.h"
#include "powerctrl.h"
#include "boardctrl.h"
#include "pybthread.h"
#include "storage.h"
#include "pin.h"
Expand Down Expand Up @@ -182,13 +183,15 @@ STATIC mp_obj_t machine_soft_reset(void) {
MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset);

// Activate the bootloader without BOOT* pins.
STATIC NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
#if MICROPY_HW_ENABLE_STORAGE
storage_flush();
#endif

__disable_irq();

MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);

#if MICROPY_HW_USES_BOOTLOADER
// ToDo: need to review how to implement

Expand Down
1 change: 1 addition & 0 deletions ports/renesas-ra/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void machine_deinit(void);
void machine_pin_init(void);
void machine_pin_deinit(void);
void machine_i2s_init0(void);
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);

MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj);
Expand Down
9 changes: 6 additions & 3 deletions ports/rp2/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ STATIC mp_obj_t machine_reset_cause(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);

STATIC mp_obj_t machine_bootloader(void) {
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
MICROPY_BOARD_ENTER_BOOTLOADER(n_args, args);
reset_usb_boot(0, 0);
return mp_const_none;
while (1) {
;
}
}
MP_DEFINE_CONST_FUN_OBJ_0(machine_bootloader_obj, machine_bootloader);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader);

STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
Expand Down
1 change: 1 addition & 0 deletions ports/rp2/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ void machine_pin_deinit(void);
void machine_i2s_init0(void);

struct _machine_spi_obj_t *spi_from_mp_obj(mp_obj_t o);
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);

#endif // MICROPY_INCLUDED_RP2_MODMACHINE_H
4 changes: 4 additions & 0 deletions ports/rp2/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
#define mp_type_textio mp_type_vfs_lfs2_textio
#endif

#ifndef MICROPY_BOARD_ENTER_BOOTLOADER
#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args)
#endif

#if MICROPY_PY_NETWORK
#define NETWORK_ROOT_POINTERS mp_obj_list_t mod_network_nic_list;
#else
Expand Down
4 changes: 4 additions & 0 deletions ports/stm32/boardctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#define MICROPY_BOARD_STARTUP powerctrl_check_enter_bootloader
#endif

#ifndef MICROPY_BOARD_ENTER_BOOTLOADER
#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args)
#endif

#ifndef MICROPY_BOARD_EARLY_INIT
#define MICROPY_BOARD_EARLY_INIT()
#endif
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/boards/ARDUINO_PORTENTA_H7/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void PORTENTA_board_startup(void);
#define MICROPY_BOARD_EARLY_INIT PORTENTA_board_early_init
void PORTENTA_board_early_init(void);

#define MICROPY_BOARD_ENTER_BOOTLOADER PORTENTA_board_enter_bootloader
#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) PORTENTA_board_enter_bootloader()
void PORTENTA_board_enter_bootloader(void);

void PORTENTA_board_low_power(int mode);
Expand Down
5 changes: 4 additions & 1 deletion ports/stm32/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "gccollect.h"
#include "irq.h"
#include "powerctrl.h"
#include "boardctrl.h"
#include "pybthread.h"
#include "rng.h"
#include "storage.h"
Expand Down Expand Up @@ -270,7 +271,7 @@ STATIC mp_obj_t machine_soft_reset(void) {
MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset);

// Activate the bootloader without BOOT* pins.
STATIC NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) {
#if MICROPY_HW_ENABLE_USB
pyb_usb_dev_deinit();
#endif
Expand All @@ -280,6 +281,8 @@ STATIC NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args)

__disable_irq();

MICROPY_BOARD_ENTER_BOOTLOADER(n_args, 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)
Expand Down
1 change: 1 addition & 0 deletions ports/stm32/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern const mp_obj_type_t machine_i2s_type;
void machine_init(void);
void machine_deinit(void);
void machine_i2s_init0();
NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args);

MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_info_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj);
Expand Down
0