Skip to content

Commit 287adf5

Browse files
authored
Merge branch 'adafruit:main' into main
2 parents c3b6fb3 + 0d88686 commit 287adf5

File tree

28 files changed

+375
-53
lines changed

28 files changed

+375
-53
lines changed

extmod/vfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#define MP_BLOCKDEV_FLAG_CONCURRENT_WRITE_PROTECTED (0x0020)
5353
// Bit set when something has claimed the right to mutate the blockdev.
5454
#define MP_BLOCKDEV_FLAG_LOCKED (0x0040)
55+
// Ignore write protections. Used to override other flags temporarily.
56+
#define MP_BLOCKDEV_FLAG_IGNORE_WRITE_PROTECTION (0x0080)
5557

5658
// constants for block protocol ioctl
5759
#define MP_BLOCKDEV_IOCTL_INIT (1)

extmod/vfs_fat.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,10 @@ static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_statvfs_obj, fat_vfs_statvfs);
427427
static mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) {
428428
fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in);
429429

430-
// Read-only device indicated by writeblocks[0] == MP_OBJ_NULL.
431-
// User can specify read-only device by:
432-
// 1. readonly=True keyword argument
433-
// 2. nonexistent writeblocks method (then writeblocks[0] == MP_OBJ_NULL already)
434-
if (mp_obj_is_true(readonly)) {
435-
self->blockdev.writeblocks[0] = MP_OBJ_NULL;
436-
}
430+
// CIRCUITPY-CHANGE: Use MP_BLOCKDEV_FLAG_USB_WRITABLE instead of writeblocks[0] =/!= MP_OBJ_NULL
431+
// to specify read-write.
432+
// If readonly to Python, it's writable by USB and vice versa.
433+
filesystem_set_writable_by_usb(self, mp_obj_is_true(readonly));
437434

438435
// check if we need to make the filesystem
439436
FRESULT res = (self->blockdev.flags & MP_BLOCKDEV_FLAG_NO_FILESYSTEM) ? FR_NO_FILESYSTEM : FR_OK;

extmod/vfs_fat_diskio.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
#include "lib/oofatfs/diskio.h"
4444
#include "extmod/vfs_fat.h"
4545

46+
// CIRCUITPY-CHANGE
47+
#include "supervisor/filesystem.h"
48+
4649
typedef void *bdev_t;
4750
static fs_user_mount_t *disk_get_device(void *bdev) {
4851
return (fs_user_mount_t *)bdev;
@@ -153,7 +156,8 @@ DRESULT disk_ioctl(
153156
if (ret != mp_const_none && MP_OBJ_SMALL_INT_VALUE(ret) != 0) {
154157
// error initialising
155158
stat = STA_NOINIT;
156-
} else if (vfs->blockdev.writeblocks[0] == MP_OBJ_NULL) {
159+
// CIRCUITPY-CHANGE: writability from Python check
160+
} else if (!filesystem_is_writable_by_python(vfs)) {
157161
stat = STA_PROTECT;
158162
} else {
159163
stat = 0;

main.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,22 @@ static void start_mp(safe_mode_t safe_mode) {
211211

212212
static void stop_mp(void) {
213213
#if MICROPY_VFS
214-
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
215214

216215
// Unmount all heap allocated vfs mounts.
217-
while (gc_ptr_on_heap(vfs)) {
216+
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
217+
do {
218+
if (gc_ptr_on_heap(vfs)) {
219+
// mp_vfs_umount will splice out an unmounted vfs from the vfs_mount_table linked list.
220+
mp_vfs_umount(vfs->obj);
221+
// Start over at the beginning of the list since the first entry may have been removed.
222+
vfs = MP_STATE_VM(vfs_mount_table);
223+
continue;
224+
}
218225
vfs = vfs->next;
219-
}
220-
MP_STATE_VM(vfs_mount_table) = vfs;
226+
} while (vfs != NULL);
227+
221228
// The last vfs is CIRCUITPY and the root directory.
229+
vfs = MP_STATE_VM(vfs_mount_table);
222230
while (vfs->next != NULL) {
223231
vfs = vfs->next;
224232
}
@@ -855,6 +863,14 @@ static void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
855863
boot_output = &boot_text;
856864
#endif
857865

866+
// Get the base filesystem.
867+
fs_user_mount_t *vfs = filesystem_circuitpy();
868+
FATFS *fs = &vfs->fatfs;
869+
870+
// Allow boot.py access to CIRCUITPY, and allow writes to boot_out.txt.
871+
// We can't use the regular flags for this, because they might get modified inside boot.py.
872+
filesystem_set_ignore_write_protection(vfs, true);
873+
858874
// Write version info
859875
mp_printf(&mp_plat_print, "%s\nBoard ID:%s\n", MICROPY_FULL_VERSION_INFO, CIRCUITPY_BOARD_ID);
860876
#if CIRCUITPY_MICROCONTROLLER && COMMON_HAL_MCU_PROCESSOR_UID_LENGTH > 0
@@ -873,10 +889,6 @@ static void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
873889

874890

875891
#ifdef CIRCUITPY_BOOT_OUTPUT_FILE
876-
// Get the base filesystem.
877-
fs_user_mount_t *vfs = filesystem_circuitpy();
878-
FATFS *fs = &vfs->fatfs;
879-
880892
boot_output = NULL;
881893
#if CIRCUITPY_STATUS_BAR
882894
supervisor_status_bar_resume();
@@ -898,16 +910,16 @@ static void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
898910
// in case power is momentary or will fail shortly due to, say a low, battery.
899911
mp_hal_delay_ms(1000);
900912

901-
// USB isn't up, so we can write the file.
902-
// operating at the oofatfs (f_open) layer means the usb concurrent write permission
903-
// is not even checked!
904913
f_open(fs, &boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_WRITE | FA_CREATE_ALWAYS);
905914
UINT chars_written;
906915
f_write(&boot_output_file, boot_text.buf, boot_text.len, &chars_written);
907916
f_close(&boot_output_file);
908917
filesystem_flush();
909918
}
910919
#endif
920+
921+
// Back to regular filesystem protections.
922+
filesystem_set_ignore_write_protection(vfs, false);
911923
}
912924

913925
cleanup_after_vm(_exec_result.exception);

ports/analog/common-hal/digitalio/DigitalInOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
107107

108108
if (self->pin->port < 4) {
109109
// Check that I/O mode is enabled and we don't have in AND out on at the same time
110-
MP_STATIC_ASSERT(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask)));
110+
MP_STATIC_ASSERT_NONCONSTEXPR(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask)));
111111

112112
if ((port->en0 & mask) && (port->outen & mask)) {
113113
return DIRECTION_OUTPUT;

ports/atmel-samd/boards/circuitbrains_basic_m0/mpconfigboard.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ"
1111
LONGINT_IMPL = MPZ
1212

1313
CIRCUITPY_CODEOP = 0
14-
CIRCUITPY_JPEGIO = 0
14+
CIRCUITPY_ERRNO = 0
15+
CIRCUITPY_RAINBOWIO = 0

ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C, W25Q16JVxQ"
1111
LONGINT_IMPL = MPZ
1212

1313
CIRCUITPY_CODEOP = 0
14+
CIRCUITPY_ERRNO = 0
1415
CIRCUITPY_RAINBOWIO = 0

ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ EXTERNAL_FLASH_DEVICES = "S25FL064L"
1111
LONGINT_IMPL = MPZ
1212

1313
CIRCUITPY_CODEOP = 0
14+
CIRCUITPY_ERRNO = 0
1415
CIRCUITPY_RAINBOWIO = 0

0 commit comments

Comments
 (0)