Skip to content

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Oct 7, 2025

#10648 mistakenly prevented USB writes all the time. Fixing it was more complicated than one might think

  • The old way of doing self->blockdev.writeblocks[0] = MP_OBJ_NULL; turns off write for everyone, and is not a good way of setting read-only for host but not CircuitPython or vice-versa. So use the blockdev MP_BLOCKDEV_FLAGs exclusively. via filesystem_is_writable_by_python() and filesystem_is_writable_by_usb().
  • The above change caused boot_out.txt not to be written in most cases, because now the read-write check on the flags is done at a lower level. So add a new flag MP_BLOCKDEV_FLAG_IGNORE_WRITE_PROTECTION to turn off write protection during boot.py execution. We can't just temporarily toggle MP_BLOCKDEV_FLAG_USB_WRITABLE, because boot.py might do a storage.remount(), which changes that flag, and we can't tell if it was changed in main.c or in the boot.py Python code.

Tested with all four combinations of {CIRCUITPY, /sd} x {read-write, readonly} on a Feather RP2040 with an Adalogger Featherwing. Also tested the three drives presented by Fruit Jam in their regular states to check proper read-only/read-write.

@dhalbert dhalbert requested a review from tannewt October 7, 2025 22:49
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you!

@dhalbert dhalbert merged commit 97c6617 into adafruit:main Oct 7, 2025
1255 of 1256 checks passed
@dhalbert dhalbert deleted the fix-usb-writability branch October 7, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SD card mounted in code.py is not writable from USB even when storage.mount(..., readonly=True)

2 participants