← index #10898PR #10833
Likely Duplicate · high · value 2.369
QUERY · ISSUE

Interrupting soft reset (Ctrl-D) with Ctrl-C erases filesystem on Raspberry Pi Pico

openby connorclopened 2023-03-01updated 2023-03-01
bug

Sending a Ctrl-D to the MicroPython REPL to initiate a soft reset and then immediately issuing a Ctrl-C causes the entire filesystem to be erased on the Raspberry Pi Pico board. This issue was observed on 2 separate Pico boards across the following nightly builds (the 4 latest as of 01 March 2023):

However, the bug was not observed in the latest stable version 1.19.1.

Steps to reproduce

These steps were tested on a Linux host (Ubuntu 22.04).

First, load one of the above nightly versions of MicroPython onto a Raspberry Pi Pico board.

Next, using mpremote, install a library on the Pico’s filesystem, for example hashlib:

mpremote mip install hashlib

Then check that the library exists on the Pico’s filesystem:

mpremote fs ls /lib

This should show the hashlib folder:

ls :/lib
           0 hashlib/

Then, to send the required keystrokes (Ctrl-D followed by Ctrl-C), execute the following lines of Python on the Linux host machine to which the Pico is connected, replacing /dev/ttyACM0 with the serial port of the MicroPython REPL. This script requires pyserial.

import serial
s = serial.Serial('/dev/ttyACM0')
s.write(b'\x04') # Ctrl-D
s.write(b'\x03') # Ctrl-C
s.close()

Less precisely, the issue can also be reproduced by entering a REPL with mpremote and pressing Ctrl-D and Ctrl-C in rapid succession.

Then check the Pico’s filesystem once again:

mpremote fs ls

This should show that the lib folder and all files it contains have been removed:

ls :

This issue became evident because the visual studio code extension Pico-W-Go exhibits this behaviour when running a MicroPython file, issuing a Ctrl-D and Ctrl-C in rapid succession before running the given code. This issue has been reported on that project’s GitHub page here, suggesting it affects other nightly versions older than the 4 listed above.

CANDIDATE · PULL REQUEST

rp2: Do not format the file system in response to Ctrl+C.

mergedby DavidEGraysonopened 2023-02-24updated 2023-04-05
py-core

I noticed that the @mu-editor sends Ctrl+A followed by Ctrl+D to reboot the board, and then it very quickly sends a Ctrl+C character, interrupting the code in _boot.py or _boot_fat.py while it is trying to mount the root file system. The except: clause in those files catches the KeyboardInterrupt and destroys the existing file system.

This pull request fixes the problem by only catching exceptions that inherit from the Exception class, which does not include KeyboardInterrupt. In the future, maybe the except clause should be restricted further, since formatting the file system is so destructive and it only makes sense to do it if we have confirmed that the file system is invalid.

Note that this pull request is not sufficient to actually get Mu to work with an RP2040: the errant Ctrl+C will interrupt the booting process and leave the interpreter in a state where it does not have a root file system.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied