Skip to content

Commit c046b23

Browse files
DavidEGraysondpgeorge
authored andcommitted
shared/runtime/pyexec: Don't allow Ctrl+C to interrupt frozen boot code.
Helps prevent the filesystem from getting formatted by mistake, among other things. For example, on a Pico board, entering Ctrl+D and Ctrl+C fast many times will eventually wipe the filesystem (without warning or notice). Further rationale: Ctrl+C is used a lot by automation scripts (eg mpremote) and UI's (eg Mu, Thonny) to get the board into a known state. If the board is not responding for a short time then it's not possible to know if it's just a slow start up (eg in _boot.py), or an infinite loop in the main application. The former should not be interrupted, but the latter should. The only way to distinguish these two cases would be to wait "long enough", and if there's nothing on the serial after "long enough" then assume it's running the application and Ctrl+C should break out of it. But defining "long enough" is impossible for all the different boards and their possible behaviour. The solution in this commit is to make it so that frozen start-up code cannot be interrupted by Ctrl+C. That code then effectively acts like normal C start-up code, which also cannot be interrupted. Note: on the stm32 port this was never seen as an issue because all start-up code is in C. But now other ports start to put more things in _boot.py and so this problem crops up. Signed-off-by: David Grayson <[email protected]>
1 parent db4b416 commit c046b23

File tree

13 files changed

+24
-19
lines changed

13 files changed

+24
-19
lines changed

ports/esp32/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void mp_task(void *pvParameter) {
161161
#endif
162162

163163
// run boot-up scripts
164-
pyexec_frozen_module("_boot.py");
164+
pyexec_frozen_module("_boot.py", false);
165165
pyexec_file_if_exists("boot.py");
166166
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
167167
int ret = pyexec_file_if_exists("main.py");

ports/esp8266/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ STATIC void mp_reset(void) {
7474
}
7575

7676
#if MICROPY_MODULE_FROZEN
77-
pyexec_frozen_module("_boot.py");
77+
pyexec_frozen_module("_boot.py", false);
7878
pyexec_file_if_exists("boot.py");
7979
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
8080
pyexec_file_if_exists("main.py");

ports/mimxrt/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main(void) {
8585
readline_init0();
8686

8787
// Execute _boot.py to set up the filesystem.
88-
pyexec_frozen_module("_boot.py");
88+
pyexec_frozen_module("_boot.py", false);
8989

9090
// Execute user scripts.
9191
int ret = pyexec_file_if_exists("boot.py");

ports/minimal/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int main(int argc, char **argv) {
5555
// do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT);
5656
// do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT);
5757
#else
58-
pyexec_frozen_module("frozentest.py");
58+
pyexec_frozen_module("frozentest.py", false);
5959
#endif
6060
mp_deinit();
6161
return 0;

ports/nrf/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ int main(int argc, char **argv) {
184184
int ret = mp_vfs_mount_and_chdir_protected((mp_obj_t)&nrf_flash_obj, mount_point);
185185

186186
if ((ret == -MP_ENODEV) || (ret == -MP_EIO)) {
187-
pyexec_frozen_module("_mkfs.py"); // Frozen script for formatting flash filesystem.
187+
pyexec_frozen_module("_mkfs.py", false); // Frozen script for formatting flash filesystem.
188188
ret = mp_vfs_mount_and_chdir_protected((mp_obj_t)&nrf_flash_obj, mount_point);
189189
}
190190

ports/powerpc/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int main(int argc, char **argv) {
9595
pyexec_friendly_repl();
9696
#endif
9797
#else
98-
pyexec_frozen_module("frozentest.py");
98+
pyexec_frozen_module("frozentest.py", false);
9999
#endif
100100
mp_deinit();
101101
return 0;

ports/renesas-ra/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void ra_main(uint32_t reset_mode) {
325325

326326
// Run optional frozen boot code.
327327
#ifdef MICROPY_BOARD_FROZEN_BOOT_FILE
328-
pyexec_frozen_module(MICROPY_BOARD_FROZEN_BOOT_FILE);
328+
pyexec_frozen_module(MICROPY_BOARD_FROZEN_BOOT_FILE, false);
329329
#endif
330330

331331
// Run boot.py (or whatever else a board configures at this stage).

ports/rp2/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ int main(int argc, char **argv) {
168168

169169
// Execute _boot.py to set up the filesystem.
170170
#if MICROPY_VFS_FAT && MICROPY_HW_USB_MSC
171-
pyexec_frozen_module("_boot_fat.py");
171+
pyexec_frozen_module("_boot_fat.py", false);
172172
#else
173-
pyexec_frozen_module("_boot.py");
173+
pyexec_frozen_module("_boot.py", false);
174174
#endif
175175

176176
// Execute user scripts.

ports/samd/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void samd_main(void) {
5252
readline_init0();
5353

5454
// Execute _boot.py to set up the filesystem.
55-
pyexec_frozen_module("_boot.py");
55+
pyexec_frozen_module("_boot.py", false);
5656

5757
// Execute user scripts.
5858
int ret = pyexec_file_if_exists("boot.py");

ports/stm32/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ void stm32_main(uint32_t reset_mode) {
559559

560560
// Run optional frozen boot code.
561561
#ifdef MICROPY_BOARD_FROZEN_BOOT_FILE
562-
pyexec_frozen_module(MICROPY_BOARD_FROZEN_BOOT_FILE);
562+
pyexec_frozen_module(MICROPY_BOARD_FROZEN_BOOT_FILE, false);
563563
#endif
564564

565565
// Run boot.py (or whatever else a board configures at this stage).

0 commit comments

Comments
 (0)