mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
ports/mimxrt: Refactor common boot code.
This commit is contained in:
parent
2fe47234b3
commit
861ee0b9b2
@ -50,7 +50,6 @@
|
|||||||
|
|
||||||
#include "extmod/vfs.h"
|
#include "extmod/vfs.h"
|
||||||
#include "extmod/vfs_fat.h"
|
#include "extmod/vfs_fat.h"
|
||||||
#include "common/factoryreset.h"
|
|
||||||
|
|
||||||
#include "omv_boardconfig.h"
|
#include "omv_boardconfig.h"
|
||||||
#include "framebuffer.h"
|
#include "framebuffer.h"
|
||||||
@ -60,36 +59,11 @@
|
|||||||
#include "fb_alloc.h"
|
#include "fb_alloc.h"
|
||||||
#include "dma_alloc.h"
|
#include "dma_alloc.h"
|
||||||
#include "file_utils.h"
|
#include "file_utils.h"
|
||||||
|
#include "boot_utils.h"
|
||||||
#include "mimxrt_hal.h"
|
#include "mimxrt_hal.h"
|
||||||
|
|
||||||
extern uint8_t _sstack, _estack, _heap_start, _heap_end;
|
extern uint8_t _sstack, _estack, _heap_start, _heap_end;
|
||||||
|
|
||||||
void exec_boot_script(const char *path, bool interruptible) {
|
|
||||||
nlr_buf_t nlr;
|
|
||||||
bool interrupted = false;
|
|
||||||
if (nlr_push(&nlr) == 0) {
|
|
||||||
// Enable IDE interrupts if allowed.
|
|
||||||
if (interruptible) {
|
|
||||||
usbdbg_set_irq_enabled(true);
|
|
||||||
usbdbg_set_script_running(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse, compile and execute the script.
|
|
||||||
pyexec_file_if_exists(path, true);
|
|
||||||
nlr_pop();
|
|
||||||
} else {
|
|
||||||
interrupted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable IDE interrupts
|
|
||||||
usbdbg_set_irq_enabled(false);
|
|
||||||
usbdbg_set_script_running(false);
|
|
||||||
|
|
||||||
if (interrupted) {
|
|
||||||
mp_obj_print_exception(&mp_plat_print, (mp_obj_t) nlr.ret_val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
bool sdcard_detected = false;
|
bool sdcard_detected = false;
|
||||||
bool sdcard_mounted = false;
|
bool sdcard_mounted = false;
|
||||||
@ -101,9 +75,7 @@ int main(void) {
|
|||||||
pendsv_init();
|
pendsv_init();
|
||||||
|
|
||||||
soft_reset:
|
soft_reset:
|
||||||
#if defined(MICROPY_HW_LED1)
|
|
||||||
led_init();
|
led_init();
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialise stack extents and GC heap.
|
// Initialise stack extents and GC heap.
|
||||||
mp_stack_set_top(&_estack);
|
mp_stack_set_top(&_estack);
|
||||||
@ -178,9 +150,8 @@ soft_reset:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MICROPY_PY_SENSOR
|
#if MICROPY_PY_SENSOR
|
||||||
if (first_soft_reset
|
if (first_soft_reset) {
|
||||||
&& sensor_init() != 0) {
|
sensor_init();
|
||||||
printf("sensor init failed!\n");
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -211,7 +182,7 @@ soft_reset:
|
|||||||
} else {
|
} else {
|
||||||
// Create a fresh filesystem.
|
// Create a fresh filesystem.
|
||||||
fs_user_mount_t *vfs = MP_OBJ_TYPE_GET_SLOT(&mp_fat_vfs_type, make_new) (&mp_fat_vfs_type, 1, 0, &bdev);
|
fs_user_mount_t *vfs = MP_OBJ_TYPE_GET_SLOT(&mp_fat_vfs_type, make_new) (&mp_fat_vfs_type, 1, 0, &bdev);
|
||||||
if (factoryreset_create_filesystem(vfs) == 0) {
|
if (bootutils_init_filesystem(vfs) == 0) {
|
||||||
if (mp_vfs_mount_and_chdir_protected(bdev, mount_point) == 0) {
|
if (mp_vfs_mount_and_chdir_protected(bdev, mount_point) == 0) {
|
||||||
mimxrt_msc_medium = &mimxrt_flash_type;
|
mimxrt_msc_medium = &mimxrt_flash_type;
|
||||||
}
|
}
|
||||||
@ -219,19 +190,21 @@ soft_reset:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deferred tusb_init to allow the filesystem to be mounted/created before MSC.
|
// Mark the filesystem as an OpenMV storage.
|
||||||
|
file_ll_touch(".openmv_disk");
|
||||||
|
|
||||||
|
// Initialize TinyUSB after the filesystem is mounted.
|
||||||
if (!tusb_inited()) {
|
if (!tusb_inited()) {
|
||||||
tusb_init();
|
tusb_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark FS as OpenMV disk.
|
// Run boot.py script.
|
||||||
file_ll_touch(".openmv_disk");
|
bool interrupted = bootutils_exec_bootscript("boot.py", true, false);
|
||||||
|
|
||||||
// Execute user scripts.
|
// Run main.py script on first soft-reset.
|
||||||
exec_boot_script("boot.py", false);
|
if (first_soft_reset && !interrupted && mp_vfs_import_stat("main.py")) {
|
||||||
|
bootutils_exec_bootscript("main.py", true, false);
|
||||||
if (first_soft_reset) {
|
goto soft_reset_exit;
|
||||||
exec_boot_script("main.py", true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's no script ready, just re-exec REPL
|
// If there's no script ready, just re-exec REPL
|
||||||
@ -279,6 +252,7 @@ soft_reset:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
soft_reset_exit:
|
||||||
mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n");
|
mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n");
|
||||||
machine_pin_irq_deinit();
|
machine_pin_irq_deinit();
|
||||||
machine_rtc_irq_deinit();
|
machine_rtc_irq_deinit();
|
||||||
@ -300,7 +274,6 @@ soft_reset:
|
|||||||
mp_deinit();
|
mp_deinit();
|
||||||
first_soft_reset = false;
|
first_soft_reset = false;
|
||||||
goto soft_reset;
|
goto soft_reset;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gc_collect(void) {
|
void gc_collect(void) {
|
||||||
|
|||||||
@ -41,6 +41,7 @@ MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/lib/lwip/src/include/
|
|||||||
MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/ports/mimxrt/
|
MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/ports/mimxrt/
|
||||||
MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/ports/mimxrt/lwip_inc/
|
MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/ports/mimxrt/lwip_inc/
|
||||||
MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/shared/runtime/
|
MPY_CFLAGS += -I$(TOP_DIR)/$(MICROPY_DIR)/shared/runtime/
|
||||||
|
MPY_CFLAGS += -DMICROPY_VFS_FAT=1
|
||||||
|
|
||||||
ifeq ($(MICROPY_PY_LWIP), 0)
|
ifeq ($(MICROPY_PY_LWIP), 0)
|
||||||
MICROPY_ARGS += MICROPY_PY_LWIP=0 MICROPY_PY_USSL=0
|
MICROPY_ARGS += MICROPY_PY_LWIP=0 MICROPY_PY_USSL=0
|
||||||
@ -127,7 +128,6 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/alloc/, \
|
|||||||
|
|
||||||
FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/common/, \
|
FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/common/, \
|
||||||
array.o \
|
array.o \
|
||||||
file_utils.o \
|
|
||||||
ini.o \
|
ini.o \
|
||||||
ringbuf.o \
|
ringbuf.o \
|
||||||
trace.o \
|
trace.o \
|
||||||
@ -135,8 +135,9 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/common/, \
|
|||||||
vospi.o \
|
vospi.o \
|
||||||
usbdbg.o \
|
usbdbg.o \
|
||||||
tinyusb_debug.o \
|
tinyusb_debug.o \
|
||||||
|
file_utils.o \
|
||||||
|
boot_utils.o \
|
||||||
sensor_utils.o \
|
sensor_utils.o \
|
||||||
factoryreset.o \
|
|
||||||
)
|
)
|
||||||
|
|
||||||
FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/sensors/, \
|
FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/sensors/, \
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user