mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Rework boot scripts and pyexec.
* Run frozen _boot.py if it exists (for early boot stuff). * Allow freezing main.py and boot.py boot scripts. * Give frozen boot scripts priority over filesystem boot scripts.
This commit is contained in:
parent
6a0bc6716e
commit
b0c7a32721
@ -1 +1 @@
|
||||
Subproject commit 138c043f945139f1618d58b0fb25f5953f59e2f3
|
||||
Subproject commit 4f78d8682c9350179b3f02f66b32e4366818e863
|
||||
@ -211,7 +211,7 @@ soft_reset:
|
||||
int ret = vfs_mount_and_chdir((mp_obj_t)&nrf_flash_obj, mount_point);
|
||||
|
||||
if ((ret == -MP_ENODEV) || (ret == -MP_EIO)) {
|
||||
pyexec_frozen_module("_mkfs.py"); // Frozen script for formatting flash filesystem.
|
||||
pyexec_frozen_module("_mkfs.py", false); // Frozen script for formatting flash filesystem.
|
||||
ret = vfs_mount_and_chdir((mp_obj_t)&nrf_flash_obj, mount_point);
|
||||
}
|
||||
|
||||
@ -284,8 +284,8 @@ soft_reset:
|
||||
|
||||
#if MICROPY_VFS || MICROPY_MBFS || MICROPY_MODULE_FROZEN
|
||||
// run boot.py and main.py if they exist.
|
||||
pyexec_file_if_exists("boot.py");
|
||||
pyexec_file_if_exists("main.py");
|
||||
pyexec_file_if_exists("boot.py", false);
|
||||
pyexec_file_if_exists("main.py", false);
|
||||
#endif
|
||||
|
||||
#if MICROPY_HW_USB_CDC
|
||||
@ -326,7 +326,7 @@ soft_reset:
|
||||
usbdbg_set_irq_enabled(true);
|
||||
|
||||
// Execute the script.
|
||||
pyexec_str(usbdbg_get_script());
|
||||
pyexec_str(usbdbg_get_script(), true);
|
||||
nlr_pop();
|
||||
} else {
|
||||
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
|
||||
|
||||
@ -113,7 +113,7 @@ void exec_boot_script(const char *path, bool interruptible)
|
||||
}
|
||||
|
||||
// Parse, compile and execute the script.
|
||||
pyexec_file_if_exists(path);
|
||||
pyexec_file_if_exists(path, true);
|
||||
nlr_pop();
|
||||
} else {
|
||||
interrupted = true;
|
||||
@ -206,9 +206,9 @@ soft_reset:
|
||||
|
||||
// Execute _boot.py to set up the filesystem.
|
||||
#if MICROPY_VFS_FAT && MICROPY_HW_USB_MSC
|
||||
pyexec_frozen_module("_boot_fat.py");
|
||||
pyexec_frozen_module("_boot_fat.py", false);
|
||||
#else
|
||||
pyexec_frozen_module("_boot.py");
|
||||
pyexec_frozen_module("_boot.py", false);
|
||||
#endif
|
||||
|
||||
// Execute user scripts.
|
||||
@ -247,7 +247,7 @@ soft_reset:
|
||||
// Enable IDE interrupt
|
||||
usbdbg_set_irq_enabled(true);
|
||||
// Execute the script.
|
||||
pyexec_str(usbdbg_get_script());
|
||||
pyexec_str(usbdbg_get_script(), true);
|
||||
nlr_pop();
|
||||
} else {
|
||||
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
|
||||
|
||||
@ -371,25 +371,30 @@ FRESULT exec_boot_script(const char *path, bool selftest, bool interruptible, bo
|
||||
{
|
||||
nlr_buf_t nlr;
|
||||
bool interrupted = false;
|
||||
FRESULT f_res = f_stat(&vfs_fat->fatfs, path, NULL);
|
||||
FRESULT f_res = FR_NO_FILE;
|
||||
|
||||
if (f_res == FR_OK) {
|
||||
if (nlr_push(&nlr) == 0) {
|
||||
// Enable IDE interrupts if allowed.
|
||||
if (interruptible) {
|
||||
usbdbg_set_irq_enabled(true);
|
||||
usbdbg_set_script_running(true);
|
||||
#if OMV_ENABLE_WIFIDBG && MICROPY_PY_WINC1500
|
||||
wifidbg_set_irq_enabled(wifidbg_enabled);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Parse, compile and execute the script.
|
||||
pyexec_file(path);
|
||||
nlr_pop();
|
||||
} else {
|
||||
interrupted = true;
|
||||
if (nlr_push(&nlr) == 0) {
|
||||
// Enable IDE interrupts if allowed.
|
||||
if (interruptible) {
|
||||
usbdbg_set_irq_enabled(true);
|
||||
usbdbg_set_script_running(true);
|
||||
#if OMV_ENABLE_WIFIDBG && MICROPY_PY_WINC1500
|
||||
wifidbg_set_irq_enabled(wifidbg_enabled);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Try to run the frozen module first.
|
||||
if (pyexec_frozen_module(path, true) == false) {
|
||||
// No frozen module, try the filesystem.
|
||||
f_res = f_stat(&vfs_fat->fatfs, path, NULL);
|
||||
if (f_res == FR_OK) {
|
||||
// Parse, compile and execute the script.
|
||||
pyexec_file(path, true);
|
||||
}
|
||||
}
|
||||
nlr_pop();
|
||||
} else {
|
||||
interrupted = true;
|
||||
}
|
||||
|
||||
// Disable IDE interrupts
|
||||
@ -673,15 +678,18 @@ soft_reset:
|
||||
openmv_config.wifidbg = false;
|
||||
#endif
|
||||
|
||||
// Execute frozen _boot.py (if any) for early system setup.
|
||||
pyexec_frozen_module("_boot.py", false);
|
||||
|
||||
// Run boot script(s)
|
||||
if (first_soft_reset) {
|
||||
// Execute the boot.py script before initializing the USB dev to
|
||||
// override the USB mode if required, otherwise VCP+MSC is used.
|
||||
exec_boot_script("/boot.py", false, false, false);
|
||||
exec_boot_script("boot.py", false, false, false);
|
||||
#if (OMV_ENABLE_SELFTEST == 1)
|
||||
// Execute the selftests.py script before the filesystem is mounted
|
||||
// to avoid corrupting the filesystem when selftests.py is removed.
|
||||
exec_boot_script("/selftest.py", true, false, false);
|
||||
exec_boot_script("selftest.py", true, false, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -707,7 +715,7 @@ soft_reset:
|
||||
|
||||
// Run main script if it exists.
|
||||
if (first_soft_reset) {
|
||||
exec_boot_script("/main.py", false, true, openmv_config.wifidbg);
|
||||
exec_boot_script("main.py", false, true, openmv_config.wifidbg);
|
||||
}
|
||||
|
||||
do {
|
||||
@ -755,7 +763,7 @@ soft_reset:
|
||||
#endif
|
||||
|
||||
// Execute the script.
|
||||
pyexec_str(usbdbg_get_script());
|
||||
pyexec_str(usbdbg_get_script(), true);
|
||||
nlr_pop();
|
||||
} else {
|
||||
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user