From 9f1365c2dccb0c4cc1bafcd1ee99e7d79184f2f1 Mon Sep 17 00:00:00 2001 From: M-D-777 <105963455+M-D-777@users.noreply.github.com> Date: Wed, 25 May 2022 22:23:13 +0800 Subject: [PATCH 1/3] Add MSC support for ESP32 S3 --- .../boards/GENERIC_S3/mpconfigboard.cmake | 1 + ports/esp32/boards/sdkconfig.usb_msc | 6 + ports/esp32/main/CMakeLists.txt | 1 + ports/esp32/modules/inisetup.py | 6 +- ports/esp32/usb.c | 4 + ports/esp32/usb.h | 1 + ports/esp32/usb_msc.c | 154 ++++++++++++++++++ ports/esp32/usb_msc.h | 47 ++++++ 8 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 ports/esp32/boards/sdkconfig.usb_msc create mode 100644 ports/esp32/usb_msc.c create mode 100644 ports/esp32/usb_msc.h diff --git a/ports/esp32/boards/GENERIC_S3/mpconfigboard.cmake b/ports/esp32/boards/GENERIC_S3/mpconfigboard.cmake index 3d83f89044642..965bf349ea1b4 100644 --- a/ports/esp32/boards/GENERIC_S3/mpconfigboard.cmake +++ b/ports/esp32/boards/GENERIC_S3/mpconfigboard.cmake @@ -3,6 +3,7 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.usb + #boards/sdkconfig.usb_msc boards/sdkconfig.ble boards/GENERIC_S3/sdkconfig.board ) diff --git a/ports/esp32/boards/sdkconfig.usb_msc b/ports/esp32/boards/sdkconfig.usb_msc new file mode 100644 index 0000000000000..8639e19b27817 --- /dev/null +++ b/ports/esp32/boards/sdkconfig.usb_msc @@ -0,0 +1,6 @@ +# +# Massive Storage Class (MSC) +# +CONFIG_USB_MSC_ENABLED=y +CONFIG_USB_MSC_BUFSIZE=4096 +# end of Massive Storage Class (MSC) diff --git a/ports/esp32/main/CMakeLists.txt b/ports/esp32/main/CMakeLists.txt index ab333c329024c..6799364bdf437 100644 --- a/ports/esp32/main/CMakeLists.txt +++ b/ports/esp32/main/CMakeLists.txt @@ -48,6 +48,7 @@ set(MICROPY_SOURCE_PORT ${PROJECT_DIR}/uart.c ${PROJECT_DIR}/usb.c ${PROJECT_DIR}/usb_serial_jtag.c + ${PROJECT_DIR}/usb_msc.c ${PROJECT_DIR}/gccollect.c ${PROJECT_DIR}/mphalport.c ${PROJECT_DIR}/fatfs_port.c diff --git a/ports/esp32/modules/inisetup.py b/ports/esp32/modules/inisetup.py index 426a47a6b45e5..285c215acc342 100644 --- a/ports/esp32/modules/inisetup.py +++ b/ports/esp32/modules/inisetup.py @@ -33,8 +33,10 @@ def fs_corrupted(): def setup(): check_bootsec() print("Performing initial setup") - uos.VfsLfs2.mkfs(bdev) - vfs = uos.VfsLfs2(bdev) + # uos.VfsLfs2.mkfs(bdev) + # vfs = uos.VfsLfs2(bdev) + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) uos.mount(vfs, "/") with open("boot.py", "w") as f: f.write( diff --git a/ports/esp32/usb.c b/ports/esp32/usb.c index 5a613d24412c8..1f66c161c74b3 100644 --- a/ports/esp32/usb.c +++ b/ports/esp32/usb.c @@ -84,6 +84,10 @@ void usb_init(void) { usb_cdc_connected = 0; ESP_ERROR_CHECK(tusb_cdc_acm_init(&amc_cfg)); +#if CONFIG_USB_MSC_ENABLED + ESP_ERROR_CHECK(usb_msc_init()); +#endif // CONFIG_USB_MSC_ENABLED + } void usb_tx_strn(const char *str, size_t len) { diff --git a/ports/esp32/usb.h b/ports/esp32/usb.h index a1037803337f8..3254298b446dd 100644 --- a/ports/esp32/usb.h +++ b/ports/esp32/usb.h @@ -25,6 +25,7 @@ */ #ifndef MICROPY_INCLUDED_ESP32_USB_H #define MICROPY_INCLUDED_ESP32_USB_H +#include "usb_msc.h" void usb_init(void); void usb_tx_strn(const char *str, size_t len); diff --git a/ports/esp32/usb_msc.c b/ports/esp32/usb_msc.c new file mode 100644 index 0000000000000..7147e3ae108c3 --- /dev/null +++ b/ports/esp32/usb_msc.c @@ -0,0 +1,154 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2020-2021 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +#include "usb_msc.h" +#if CONFIG_USB_MSC_ENABLED +#include "esp_err.h" +#include "esp_log.h" +#include "esp_partition.h" + +#define BLOCK_SIZE (CFG_TUD_MSC_BUFSIZE) + +static bool ejected = false; + +const esp_partition_t *partition; +esp_err_t usb_msc_init() +{ + partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "vfs"); + assert(partition != NULL); + ESP_LOGD(__func__, ""); + return ESP_OK; +} + +// Invoked when received SCSI_CMD_INQUIRY +// Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively +void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]) +{ + const char vid[] = "Micropy"; + const char pid[] = "Mass Storage"; + const char rev[] = "1.0"; + + memcpy(vendor_id, vid, strlen(vid)); + memcpy(product_id, pid, strlen(pid)); + memcpy(product_rev, rev, strlen(rev)); +} + +// Invoked when received Test Unit Ready command. +// return true allowing host to read/write this LUN e.g SD card inserted +bool tud_msc_test_unit_ready_cb(uint8_t lun) +{ + if (ejected) { + // Set 0x3a for media not present. + tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x3A, 0x00); + return false; + } + return true; +} + +// Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size +// Application update block count and block size +void tud_msc_capacity_cb(uint8_t lun, uint32_t *block_count, uint16_t *block_size) +{ + *block_size = BLOCK_SIZE; + *block_count = partition->size / BLOCK_SIZE; +} + +// Invoked when received Start Stop Unit command +// - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage +// - Start = 1 : active mode, if load_eject = 1 : load disk storage +bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) +{ + if (load_eject) { + if (!start) { + ejected = true; + } else { + // We can only load if it hasn't been ejected. + ejected = false; + } + } else { + // Always start the unit, even if ejected. Whether media is present is a separate check. + } + + return true; +} + +// Callback invoked when received READ10 command. +// Copy disk's data to buffer (up to bufsize) and return number of copied bytes. +int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buffer, uint32_t bufsize) +{ + ESP_ERROR_CHECK(esp_partition_read(partition, lba * BLOCK_SIZE, buffer, bufsize)); + return bufsize; +} + +// Callback invoked when received WRITE10 command. +// Process data in buffer to disk's storage and return number of written bytes +int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t bufsize) +{ + ESP_ERROR_CHECK(esp_partition_erase_range(partition, lba * BLOCK_SIZE, bufsize)); + ESP_ERROR_CHECK(esp_partition_write(partition, lba * BLOCK_SIZE, buffer, bufsize)); + return bufsize; +} + +// Callback invoked when received an SCSI command not in built-in list below +// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE +// - READ10 and WRITE10 has their own callbacks +int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t bufsize) +{ + void const *response = NULL; + uint16_t resplen = 0; + + // most scsi handled is input + bool in_xfer = true; + + switch (scsi_cmd[0]) { + case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL: + // Host is about to read/write etc ... better not to disconnect disk + resplen = 0; + break; + + default: + // Set Sense = Invalid Command Operation + tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); + + // negative means error -> tinyusb could stall and/or response with failed status + resplen = -1; + break; + } + + // return resplen must not larger than bufsize + if (resplen > bufsize) { + resplen = bufsize; + } + + if (response && (resplen > 0)) { + if (in_xfer) { + memcpy(buffer, response, resplen); + } else { + // SCSI output + } + } + + return resplen; +} +#endif // CONFIG_USB_MSC_ENABLED \ No newline at end of file diff --git a/ports/esp32/usb_msc.h b/ports/esp32/usb_msc.h new file mode 100644 index 0000000000000..678fecdf53082 --- /dev/null +++ b/ports/esp32/usb_msc.h @@ -0,0 +1,47 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "tusb.h" +#include "tinyusb.h" + +/** + * @brief Initialize MSC Device. + * + * @param cfg - init configuration structure + * @return esp_err_t + */ +esp_err_t usb_msc_init(); + +#ifdef __cplusplus +} +#endif From d08ee2591951784e91e845f554a3a7ef198b77ab Mon Sep 17 00:00:00 2001 From: M-D-777 <105963455+M-D-777@users.noreply.github.com> Date: Wed, 1 Jun 2022 17:48:55 +0800 Subject: [PATCH 2/3] add custom manifest.py for msc boot fatfs --- ports/esp32/boards/GENERIC_S3/manifest.py | 2 + .../boards/GENERIC_S3/modules/_boot_fat.py | 13 +++++ .../boards/GENERIC_S3/modules/inisetup_fat.py | 49 +++++++++++++++++++ .../boards/GENERIC_S3/mpconfigboard.cmake | 2 + ports/esp32/main.c | 4 ++ 5 files changed, 70 insertions(+) create mode 100644 ports/esp32/boards/GENERIC_S3/manifest.py create mode 100644 ports/esp32/boards/GENERIC_S3/modules/_boot_fat.py create mode 100644 ports/esp32/boards/GENERIC_S3/modules/inisetup_fat.py diff --git a/ports/esp32/boards/GENERIC_S3/manifest.py b/ports/esp32/boards/GENERIC_S3/manifest.py new file mode 100644 index 0000000000000..7ae2ed15d9169 --- /dev/null +++ b/ports/esp32/boards/GENERIC_S3/manifest.py @@ -0,0 +1,2 @@ +include("$(PORT_DIR)/boards/manifest.py") +freeze("modules") diff --git a/ports/esp32/boards/GENERIC_S3/modules/_boot_fat.py b/ports/esp32/boards/GENERIC_S3/modules/_boot_fat.py new file mode 100644 index 0000000000000..6e7d9aa8bbb33 --- /dev/null +++ b/ports/esp32/boards/GENERIC_S3/modules/_boot_fat.py @@ -0,0 +1,13 @@ +import gc +import uos +from flashbdev import bdev + +try: + if bdev: + uos.mount(bdev, "/") +except OSError: + import inisetup_fat + + vfs = inisetup_fat.setup() + +gc.collect() diff --git a/ports/esp32/boards/GENERIC_S3/modules/inisetup_fat.py b/ports/esp32/boards/GENERIC_S3/modules/inisetup_fat.py new file mode 100644 index 0000000000000..55538a96a9136 --- /dev/null +++ b/ports/esp32/boards/GENERIC_S3/modules/inisetup_fat.py @@ -0,0 +1,49 @@ +import uos +from flashbdev import bdev + + +def check_bootsec(): + buf = bytearray(bdev.ioctl(5, 0)) # 5 is SEC_SIZE + bdev.readblocks(0, buf) + empty = True + for b in buf: + if b != 0xFF: + empty = False + break + if empty: + return True + fs_corrupted() + + +def fs_corrupted(): + import time + + while 1: + print( + """\ +The filesystem appears to be corrupted. If you had important data there, you +may want to make a flash snapshot to try to recover it. Otherwise, perform +factory reprogramming of MicroPython firmware (completely erase flash, followed +by firmware programming). +""" + ) + time.sleep(3) + + +def setup(): + check_bootsec() + print("Performing initial setup") + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) + uos.mount(vfs, "/") + with open("boot.py", "w") as f: + f.write( + """\ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +#import webrepl +#webrepl.start() +""" + ) + return vfs diff --git a/ports/esp32/boards/GENERIC_S3/mpconfigboard.cmake b/ports/esp32/boards/GENERIC_S3/mpconfigboard.cmake index 965bf349ea1b4..3e28370591377 100644 --- a/ports/esp32/boards/GENERIC_S3/mpconfigboard.cmake +++ b/ports/esp32/boards/GENERIC_S3/mpconfigboard.cmake @@ -7,3 +7,5 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.ble boards/GENERIC_S3/sdkconfig.board ) + +set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 14b7e14c62ff1..204a6d2a6a5ce 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -161,7 +161,11 @@ void mp_task(void *pvParameter) { #endif // run boot-up scripts + #if CONFIG_USB_MSC_ENABLED + pyexec_frozen_module("_boot_fat.py"); + #else pyexec_frozen_module("_boot.py"); + #endif pyexec_file_if_exists("boot.py"); if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) { int ret = pyexec_file_if_exists("main.py"); From 1ccf556813836a9d92409e9b637688bf35ed01b0 Mon Sep 17 00:00:00 2001 From: M-D-777 <105963455+M-D-777@users.noreply.github.com> Date: Fri, 3 Jun 2022 08:40:06 +0800 Subject: [PATCH 3/3] Add usb msc feature to all of the ESP32 S2 and S3 variants. By default, the usb feature is disabled by #boards/sdkconfig.usb_msc in mpconfigboard.cmake. --- ports/esp32/boards/GENERIC_S2/manifest.py | 2 + .../boards/GENERIC_S2/modules/_boot_fat.py | 13 +++++ .../boards/GENERIC_S2/modules/inisetup_fat.py | 49 +++++++++++++++++++ .../boards/GENERIC_S2/mpconfigboard.cmake | 3 ++ .../boards/GENERIC_S3_SPIRAM/manifest.py | 2 + .../GENERIC_S3_SPIRAM/modules/_boot_fat.py | 13 +++++ .../GENERIC_S3_SPIRAM/modules/inisetup_fat.py | 49 +++++++++++++++++++ .../GENERIC_S3_SPIRAM/mpconfigboard.cmake | 3 ++ .../boards/LOLIN_S2_MINI/modules/_boot_fat.py | 13 +++++ .../LOLIN_S2_MINI/modules/inisetup_fat.py | 49 +++++++++++++++++++ .../boards/LOLIN_S2_MINI/mpconfigboard.cmake | 1 + .../boards/LOLIN_S2_PICO/modules/_boot_fat.py | 13 +++++ .../LOLIN_S2_PICO/modules/inisetup_fat.py | 49 +++++++++++++++++++ .../boards/LOLIN_S2_PICO/mpconfigboard.cmake | 1 + .../boards/UM_FEATHERS2/modules/_boot_fat.py | 13 +++++ .../UM_FEATHERS2/modules/inisetup_fat.py | 49 +++++++++++++++++++ .../boards/UM_FEATHERS2/mpconfigboard.cmake | 1 + .../UM_FEATHERS2NEO/modules/_boot_fat.py | 13 +++++ .../UM_FEATHERS2NEO/modules/inisetup_fat.py | 49 +++++++++++++++++++ .../UM_FEATHERS2NEO/mpconfigboard.cmake | 1 + .../boards/UM_FEATHERS3/modules/_boot_fat.py | 13 +++++ .../UM_FEATHERS3/modules/inisetup_fat.py | 49 +++++++++++++++++++ .../boards/UM_FEATHERS3/mpconfigboard.cmake | 1 + .../boards/UM_PROS3/modules/_boot_fat.py | 13 +++++ .../boards/UM_PROS3/modules/inisetup_fat.py | 49 +++++++++++++++++++ .../esp32/boards/UM_PROS3/mpconfigboard.cmake | 1 + .../boards/UM_TINYS2/modules/_boot_fat.py | 13 +++++ .../boards/UM_TINYS2/modules/inisetup_fat.py | 49 +++++++++++++++++++ .../boards/UM_TINYS2/mpconfigboard.cmake | 3 ++ .../boards/UM_TINYS3/modules/_boot_fat.py | 13 +++++ .../boards/UM_TINYS3/modules/inisetup_fat.py | 49 +++++++++++++++++++ .../boards/UM_TINYS3/mpconfigboard.cmake | 1 + 32 files changed, 640 insertions(+) create mode 100644 ports/esp32/boards/GENERIC_S2/manifest.py create mode 100644 ports/esp32/boards/GENERIC_S2/modules/_boot_fat.py create mode 100644 ports/esp32/boards/GENERIC_S2/modules/inisetup_fat.py create mode 100644 ports/esp32/boards/GENERIC_S3_SPIRAM/manifest.py create mode 100644 ports/esp32/boards/GENERIC_S3_SPIRAM/modules/_boot_fat.py create mode 100644 ports/esp32/boards/GENERIC_S3_SPIRAM/modules/inisetup_fat.py create mode 100644 ports/esp32/boards/LOLIN_S2_MINI/modules/_boot_fat.py create mode 100644 ports/esp32/boards/LOLIN_S2_MINI/modules/inisetup_fat.py create mode 100644 ports/esp32/boards/LOLIN_S2_PICO/modules/_boot_fat.py create mode 100644 ports/esp32/boards/LOLIN_S2_PICO/modules/inisetup_fat.py create mode 100644 ports/esp32/boards/UM_FEATHERS2/modules/_boot_fat.py create mode 100644 ports/esp32/boards/UM_FEATHERS2/modules/inisetup_fat.py create mode 100644 ports/esp32/boards/UM_FEATHERS2NEO/modules/_boot_fat.py create mode 100644 ports/esp32/boards/UM_FEATHERS2NEO/modules/inisetup_fat.py create mode 100644 ports/esp32/boards/UM_FEATHERS3/modules/_boot_fat.py create mode 100644 ports/esp32/boards/UM_FEATHERS3/modules/inisetup_fat.py create mode 100644 ports/esp32/boards/UM_PROS3/modules/_boot_fat.py create mode 100644 ports/esp32/boards/UM_PROS3/modules/inisetup_fat.py create mode 100644 ports/esp32/boards/UM_TINYS2/modules/_boot_fat.py create mode 100644 ports/esp32/boards/UM_TINYS2/modules/inisetup_fat.py create mode 100644 ports/esp32/boards/UM_TINYS3/modules/_boot_fat.py create mode 100644 ports/esp32/boards/UM_TINYS3/modules/inisetup_fat.py diff --git a/ports/esp32/boards/GENERIC_S2/manifest.py b/ports/esp32/boards/GENERIC_S2/manifest.py new file mode 100644 index 0000000000000..7ae2ed15d9169 --- /dev/null +++ b/ports/esp32/boards/GENERIC_S2/manifest.py @@ -0,0 +1,2 @@ +include("$(PORT_DIR)/boards/manifest.py") +freeze("modules") diff --git a/ports/esp32/boards/GENERIC_S2/modules/_boot_fat.py b/ports/esp32/boards/GENERIC_S2/modules/_boot_fat.py new file mode 100644 index 0000000000000..6e7d9aa8bbb33 --- /dev/null +++ b/ports/esp32/boards/GENERIC_S2/modules/_boot_fat.py @@ -0,0 +1,13 @@ +import gc +import uos +from flashbdev import bdev + +try: + if bdev: + uos.mount(bdev, "/") +except OSError: + import inisetup_fat + + vfs = inisetup_fat.setup() + +gc.collect() diff --git a/ports/esp32/boards/GENERIC_S2/modules/inisetup_fat.py b/ports/esp32/boards/GENERIC_S2/modules/inisetup_fat.py new file mode 100644 index 0000000000000..55538a96a9136 --- /dev/null +++ b/ports/esp32/boards/GENERIC_S2/modules/inisetup_fat.py @@ -0,0 +1,49 @@ +import uos +from flashbdev import bdev + + +def check_bootsec(): + buf = bytearray(bdev.ioctl(5, 0)) # 5 is SEC_SIZE + bdev.readblocks(0, buf) + empty = True + for b in buf: + if b != 0xFF: + empty = False + break + if empty: + return True + fs_corrupted() + + +def fs_corrupted(): + import time + + while 1: + print( + """\ +The filesystem appears to be corrupted. If you had important data there, you +may want to make a flash snapshot to try to recover it. Otherwise, perform +factory reprogramming of MicroPython firmware (completely erase flash, followed +by firmware programming). +""" + ) + time.sleep(3) + + +def setup(): + check_bootsec() + print("Performing initial setup") + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) + uos.mount(vfs, "/") + with open("boot.py", "w") as f: + f.write( + """\ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +#import webrepl +#webrepl.start() +""" + ) + return vfs diff --git a/ports/esp32/boards/GENERIC_S2/mpconfigboard.cmake b/ports/esp32/boards/GENERIC_S2/mpconfigboard.cmake index 59ca906f4d47d..e458bbd70e048 100644 --- a/ports/esp32/boards/GENERIC_S2/mpconfigboard.cmake +++ b/ports/esp32/boards/GENERIC_S2/mpconfigboard.cmake @@ -3,4 +3,7 @@ set(IDF_TARGET esp32s2) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.usb + #boards/sdkconfig.usb_msc ) + +set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) diff --git a/ports/esp32/boards/GENERIC_S3_SPIRAM/manifest.py b/ports/esp32/boards/GENERIC_S3_SPIRAM/manifest.py new file mode 100644 index 0000000000000..7ae2ed15d9169 --- /dev/null +++ b/ports/esp32/boards/GENERIC_S3_SPIRAM/manifest.py @@ -0,0 +1,2 @@ +include("$(PORT_DIR)/boards/manifest.py") +freeze("modules") diff --git a/ports/esp32/boards/GENERIC_S3_SPIRAM/modules/_boot_fat.py b/ports/esp32/boards/GENERIC_S3_SPIRAM/modules/_boot_fat.py new file mode 100644 index 0000000000000..6e7d9aa8bbb33 --- /dev/null +++ b/ports/esp32/boards/GENERIC_S3_SPIRAM/modules/_boot_fat.py @@ -0,0 +1,13 @@ +import gc +import uos +from flashbdev import bdev + +try: + if bdev: + uos.mount(bdev, "/") +except OSError: + import inisetup_fat + + vfs = inisetup_fat.setup() + +gc.collect() diff --git a/ports/esp32/boards/GENERIC_S3_SPIRAM/modules/inisetup_fat.py b/ports/esp32/boards/GENERIC_S3_SPIRAM/modules/inisetup_fat.py new file mode 100644 index 0000000000000..55538a96a9136 --- /dev/null +++ b/ports/esp32/boards/GENERIC_S3_SPIRAM/modules/inisetup_fat.py @@ -0,0 +1,49 @@ +import uos +from flashbdev import bdev + + +def check_bootsec(): + buf = bytearray(bdev.ioctl(5, 0)) # 5 is SEC_SIZE + bdev.readblocks(0, buf) + empty = True + for b in buf: + if b != 0xFF: + empty = False + break + if empty: + return True + fs_corrupted() + + +def fs_corrupted(): + import time + + while 1: + print( + """\ +The filesystem appears to be corrupted. If you had important data there, you +may want to make a flash snapshot to try to recover it. Otherwise, perform +factory reprogramming of MicroPython firmware (completely erase flash, followed +by firmware programming). +""" + ) + time.sleep(3) + + +def setup(): + check_bootsec() + print("Performing initial setup") + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) + uos.mount(vfs, "/") + with open("boot.py", "w") as f: + f.write( + """\ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +#import webrepl +#webrepl.start() +""" + ) + return vfs diff --git a/ports/esp32/boards/GENERIC_S3_SPIRAM/mpconfigboard.cmake b/ports/esp32/boards/GENERIC_S3_SPIRAM/mpconfigboard.cmake index b7351b90fe8e4..fce556dd0786f 100644 --- a/ports/esp32/boards/GENERIC_S3_SPIRAM/mpconfigboard.cmake +++ b/ports/esp32/boards/GENERIC_S3_SPIRAM/mpconfigboard.cmake @@ -3,6 +3,9 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.usb + #boards/sdkconfig.usb_msc boards/sdkconfig.spiram_sx boards/GENERIC_S3_SPIRAM/sdkconfig.board ) + +set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) diff --git a/ports/esp32/boards/LOLIN_S2_MINI/modules/_boot_fat.py b/ports/esp32/boards/LOLIN_S2_MINI/modules/_boot_fat.py new file mode 100644 index 0000000000000..6e7d9aa8bbb33 --- /dev/null +++ b/ports/esp32/boards/LOLIN_S2_MINI/modules/_boot_fat.py @@ -0,0 +1,13 @@ +import gc +import uos +from flashbdev import bdev + +try: + if bdev: + uos.mount(bdev, "/") +except OSError: + import inisetup_fat + + vfs = inisetup_fat.setup() + +gc.collect() diff --git a/ports/esp32/boards/LOLIN_S2_MINI/modules/inisetup_fat.py b/ports/esp32/boards/LOLIN_S2_MINI/modules/inisetup_fat.py new file mode 100644 index 0000000000000..55538a96a9136 --- /dev/null +++ b/ports/esp32/boards/LOLIN_S2_MINI/modules/inisetup_fat.py @@ -0,0 +1,49 @@ +import uos +from flashbdev import bdev + + +def check_bootsec(): + buf = bytearray(bdev.ioctl(5, 0)) # 5 is SEC_SIZE + bdev.readblocks(0, buf) + empty = True + for b in buf: + if b != 0xFF: + empty = False + break + if empty: + return True + fs_corrupted() + + +def fs_corrupted(): + import time + + while 1: + print( + """\ +The filesystem appears to be corrupted. If you had important data there, you +may want to make a flash snapshot to try to recover it. Otherwise, perform +factory reprogramming of MicroPython firmware (completely erase flash, followed +by firmware programming). +""" + ) + time.sleep(3) + + +def setup(): + check_bootsec() + print("Performing initial setup") + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) + uos.mount(vfs, "/") + with open("boot.py", "w") as f: + f.write( + """\ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +#import webrepl +#webrepl.start() +""" + ) + return vfs diff --git a/ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.cmake b/ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.cmake index dc9abd7478bca..f8637305c1f49 100644 --- a/ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.cmake +++ b/ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.cmake @@ -4,6 +4,7 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.spiram_sx boards/sdkconfig.usb + #boards/sdkconfig.usb_msc ) set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) diff --git a/ports/esp32/boards/LOLIN_S2_PICO/modules/_boot_fat.py b/ports/esp32/boards/LOLIN_S2_PICO/modules/_boot_fat.py new file mode 100644 index 0000000000000..6e7d9aa8bbb33 --- /dev/null +++ b/ports/esp32/boards/LOLIN_S2_PICO/modules/_boot_fat.py @@ -0,0 +1,13 @@ +import gc +import uos +from flashbdev import bdev + +try: + if bdev: + uos.mount(bdev, "/") +except OSError: + import inisetup_fat + + vfs = inisetup_fat.setup() + +gc.collect() diff --git a/ports/esp32/boards/LOLIN_S2_PICO/modules/inisetup_fat.py b/ports/esp32/boards/LOLIN_S2_PICO/modules/inisetup_fat.py new file mode 100644 index 0000000000000..55538a96a9136 --- /dev/null +++ b/ports/esp32/boards/LOLIN_S2_PICO/modules/inisetup_fat.py @@ -0,0 +1,49 @@ +import uos +from flashbdev import bdev + + +def check_bootsec(): + buf = bytearray(bdev.ioctl(5, 0)) # 5 is SEC_SIZE + bdev.readblocks(0, buf) + empty = True + for b in buf: + if b != 0xFF: + empty = False + break + if empty: + return True + fs_corrupted() + + +def fs_corrupted(): + import time + + while 1: + print( + """\ +The filesystem appears to be corrupted. If you had important data there, you +may want to make a flash snapshot to try to recover it. Otherwise, perform +factory reprogramming of MicroPython firmware (completely erase flash, followed +by firmware programming). +""" + ) + time.sleep(3) + + +def setup(): + check_bootsec() + print("Performing initial setup") + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) + uos.mount(vfs, "/") + with open("boot.py", "w") as f: + f.write( + """\ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +#import webrepl +#webrepl.start() +""" + ) + return vfs diff --git a/ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.cmake b/ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.cmake index dc9abd7478bca..f8637305c1f49 100644 --- a/ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.cmake +++ b/ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.cmake @@ -4,6 +4,7 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.spiram_sx boards/sdkconfig.usb + #boards/sdkconfig.usb_msc ) set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) diff --git a/ports/esp32/boards/UM_FEATHERS2/modules/_boot_fat.py b/ports/esp32/boards/UM_FEATHERS2/modules/_boot_fat.py new file mode 100644 index 0000000000000..6e7d9aa8bbb33 --- /dev/null +++ b/ports/esp32/boards/UM_FEATHERS2/modules/_boot_fat.py @@ -0,0 +1,13 @@ +import gc +import uos +from flashbdev import bdev + +try: + if bdev: + uos.mount(bdev, "/") +except OSError: + import inisetup_fat + + vfs = inisetup_fat.setup() + +gc.collect() diff --git a/ports/esp32/boards/UM_FEATHERS2/modules/inisetup_fat.py b/ports/esp32/boards/UM_FEATHERS2/modules/inisetup_fat.py new file mode 100644 index 0000000000000..55538a96a9136 --- /dev/null +++ b/ports/esp32/boards/UM_FEATHERS2/modules/inisetup_fat.py @@ -0,0 +1,49 @@ +import uos +from flashbdev import bdev + + +def check_bootsec(): + buf = bytearray(bdev.ioctl(5, 0)) # 5 is SEC_SIZE + bdev.readblocks(0, buf) + empty = True + for b in buf: + if b != 0xFF: + empty = False + break + if empty: + return True + fs_corrupted() + + +def fs_corrupted(): + import time + + while 1: + print( + """\ +The filesystem appears to be corrupted. If you had important data there, you +may want to make a flash snapshot to try to recover it. Otherwise, perform +factory reprogramming of MicroPython firmware (completely erase flash, followed +by firmware programming). +""" + ) + time.sleep(3) + + +def setup(): + check_bootsec() + print("Performing initial setup") + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) + uos.mount(vfs, "/") + with open("boot.py", "w") as f: + f.write( + """\ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +#import webrepl +#webrepl.start() +""" + ) + return vfs diff --git a/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake b/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake index 5e570d513bb47..26f8bc14f8043 100644 --- a/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake @@ -3,6 +3,7 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.spiram_sx boards/sdkconfig.usb + #boards/sdkconfig.usb_msc boards/UM_FEATHERS2/sdkconfig.board ) diff --git a/ports/esp32/boards/UM_FEATHERS2NEO/modules/_boot_fat.py b/ports/esp32/boards/UM_FEATHERS2NEO/modules/_boot_fat.py new file mode 100644 index 0000000000000..6e7d9aa8bbb33 --- /dev/null +++ b/ports/esp32/boards/UM_FEATHERS2NEO/modules/_boot_fat.py @@ -0,0 +1,13 @@ +import gc +import uos +from flashbdev import bdev + +try: + if bdev: + uos.mount(bdev, "/") +except OSError: + import inisetup_fat + + vfs = inisetup_fat.setup() + +gc.collect() diff --git a/ports/esp32/boards/UM_FEATHERS2NEO/modules/inisetup_fat.py b/ports/esp32/boards/UM_FEATHERS2NEO/modules/inisetup_fat.py new file mode 100644 index 0000000000000..55538a96a9136 --- /dev/null +++ b/ports/esp32/boards/UM_FEATHERS2NEO/modules/inisetup_fat.py @@ -0,0 +1,49 @@ +import uos +from flashbdev import bdev + + +def check_bootsec(): + buf = bytearray(bdev.ioctl(5, 0)) # 5 is SEC_SIZE + bdev.readblocks(0, buf) + empty = True + for b in buf: + if b != 0xFF: + empty = False + break + if empty: + return True + fs_corrupted() + + +def fs_corrupted(): + import time + + while 1: + print( + """\ +The filesystem appears to be corrupted. If you had important data there, you +may want to make a flash snapshot to try to recover it. Otherwise, perform +factory reprogramming of MicroPython firmware (completely erase flash, followed +by firmware programming). +""" + ) + time.sleep(3) + + +def setup(): + check_bootsec() + print("Performing initial setup") + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) + uos.mount(vfs, "/") + with open("boot.py", "w") as f: + f.write( + """\ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +#import webrepl +#webrepl.start() +""" + ) + return vfs diff --git a/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake b/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake index b0b3e3aa992ae..50935c11e9309 100644 --- a/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake @@ -3,6 +3,7 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.spiram_sx boards/sdkconfig.usb + #boards/sdkconfig.usb_msc ) set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) \ No newline at end of file diff --git a/ports/esp32/boards/UM_FEATHERS3/modules/_boot_fat.py b/ports/esp32/boards/UM_FEATHERS3/modules/_boot_fat.py new file mode 100644 index 0000000000000..6e7d9aa8bbb33 --- /dev/null +++ b/ports/esp32/boards/UM_FEATHERS3/modules/_boot_fat.py @@ -0,0 +1,13 @@ +import gc +import uos +from flashbdev import bdev + +try: + if bdev: + uos.mount(bdev, "/") +except OSError: + import inisetup_fat + + vfs = inisetup_fat.setup() + +gc.collect() diff --git a/ports/esp32/boards/UM_FEATHERS3/modules/inisetup_fat.py b/ports/esp32/boards/UM_FEATHERS3/modules/inisetup_fat.py new file mode 100644 index 0000000000000..55538a96a9136 --- /dev/null +++ b/ports/esp32/boards/UM_FEATHERS3/modules/inisetup_fat.py @@ -0,0 +1,49 @@ +import uos +from flashbdev import bdev + + +def check_bootsec(): + buf = bytearray(bdev.ioctl(5, 0)) # 5 is SEC_SIZE + bdev.readblocks(0, buf) + empty = True + for b in buf: + if b != 0xFF: + empty = False + break + if empty: + return True + fs_corrupted() + + +def fs_corrupted(): + import time + + while 1: + print( + """\ +The filesystem appears to be corrupted. If you had important data there, you +may want to make a flash snapshot to try to recover it. Otherwise, perform +factory reprogramming of MicroPython firmware (completely erase flash, followed +by firmware programming). +""" + ) + time.sleep(3) + + +def setup(): + check_bootsec() + print("Performing initial setup") + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) + uos.mount(vfs, "/") + with open("boot.py", "w") as f: + f.write( + """\ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +#import webrepl +#webrepl.start() +""" + ) + return vfs diff --git a/ports/esp32/boards/UM_FEATHERS3/mpconfigboard.cmake b/ports/esp32/boards/UM_FEATHERS3/mpconfigboard.cmake index 63d1af1da76ca..388a52ba1c14c 100644 --- a/ports/esp32/boards/UM_FEATHERS3/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_FEATHERS3/mpconfigboard.cmake @@ -3,6 +3,7 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.usb + #boards/sdkconfig.usb_msc boards/sdkconfig.ble boards/sdkconfig.240mhz boards/sdkconfig.spiram_sx diff --git a/ports/esp32/boards/UM_PROS3/modules/_boot_fat.py b/ports/esp32/boards/UM_PROS3/modules/_boot_fat.py new file mode 100644 index 0000000000000..6e7d9aa8bbb33 --- /dev/null +++ b/ports/esp32/boards/UM_PROS3/modules/_boot_fat.py @@ -0,0 +1,13 @@ +import gc +import uos +from flashbdev import bdev + +try: + if bdev: + uos.mount(bdev, "/") +except OSError: + import inisetup_fat + + vfs = inisetup_fat.setup() + +gc.collect() diff --git a/ports/esp32/boards/UM_PROS3/modules/inisetup_fat.py b/ports/esp32/boards/UM_PROS3/modules/inisetup_fat.py new file mode 100644 index 0000000000000..55538a96a9136 --- /dev/null +++ b/ports/esp32/boards/UM_PROS3/modules/inisetup_fat.py @@ -0,0 +1,49 @@ +import uos +from flashbdev import bdev + + +def check_bootsec(): + buf = bytearray(bdev.ioctl(5, 0)) # 5 is SEC_SIZE + bdev.readblocks(0, buf) + empty = True + for b in buf: + if b != 0xFF: + empty = False + break + if empty: + return True + fs_corrupted() + + +def fs_corrupted(): + import time + + while 1: + print( + """\ +The filesystem appears to be corrupted. If you had important data there, you +may want to make a flash snapshot to try to recover it. Otherwise, perform +factory reprogramming of MicroPython firmware (completely erase flash, followed +by firmware programming). +""" + ) + time.sleep(3) + + +def setup(): + check_bootsec() + print("Performing initial setup") + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) + uos.mount(vfs, "/") + with open("boot.py", "w") as f: + f.write( + """\ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +#import webrepl +#webrepl.start() +""" + ) + return vfs diff --git a/ports/esp32/boards/UM_PROS3/mpconfigboard.cmake b/ports/esp32/boards/UM_PROS3/mpconfigboard.cmake index 41a96f26e34c4..728cba04204dc 100644 --- a/ports/esp32/boards/UM_PROS3/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_PROS3/mpconfigboard.cmake @@ -3,6 +3,7 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.usb + #boards/sdkconfig.usb_msc boards/sdkconfig.ble boards/sdkconfig.240mhz boards/sdkconfig.spiram_sx diff --git a/ports/esp32/boards/UM_TINYS2/modules/_boot_fat.py b/ports/esp32/boards/UM_TINYS2/modules/_boot_fat.py new file mode 100644 index 0000000000000..6e7d9aa8bbb33 --- /dev/null +++ b/ports/esp32/boards/UM_TINYS2/modules/_boot_fat.py @@ -0,0 +1,13 @@ +import gc +import uos +from flashbdev import bdev + +try: + if bdev: + uos.mount(bdev, "/") +except OSError: + import inisetup_fat + + vfs = inisetup_fat.setup() + +gc.collect() diff --git a/ports/esp32/boards/UM_TINYS2/modules/inisetup_fat.py b/ports/esp32/boards/UM_TINYS2/modules/inisetup_fat.py new file mode 100644 index 0000000000000..55538a96a9136 --- /dev/null +++ b/ports/esp32/boards/UM_TINYS2/modules/inisetup_fat.py @@ -0,0 +1,49 @@ +import uos +from flashbdev import bdev + + +def check_bootsec(): + buf = bytearray(bdev.ioctl(5, 0)) # 5 is SEC_SIZE + bdev.readblocks(0, buf) + empty = True + for b in buf: + if b != 0xFF: + empty = False + break + if empty: + return True + fs_corrupted() + + +def fs_corrupted(): + import time + + while 1: + print( + """\ +The filesystem appears to be corrupted. If you had important data there, you +may want to make a flash snapshot to try to recover it. Otherwise, perform +factory reprogramming of MicroPython firmware (completely erase flash, followed +by firmware programming). +""" + ) + time.sleep(3) + + +def setup(): + check_bootsec() + print("Performing initial setup") + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) + uos.mount(vfs, "/") + with open("boot.py", "w") as f: + f.write( + """\ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +#import webrepl +#webrepl.start() +""" + ) + return vfs diff --git a/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake b/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake index e4b7b4a915c94..5790172dae7e6 100644 --- a/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake @@ -3,4 +3,7 @@ set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.spiram_sx boards/sdkconfig.usb + #boards/sdkconfig.usb_msc ) + +set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) diff --git a/ports/esp32/boards/UM_TINYS3/modules/_boot_fat.py b/ports/esp32/boards/UM_TINYS3/modules/_boot_fat.py new file mode 100644 index 0000000000000..6e7d9aa8bbb33 --- /dev/null +++ b/ports/esp32/boards/UM_TINYS3/modules/_boot_fat.py @@ -0,0 +1,13 @@ +import gc +import uos +from flashbdev import bdev + +try: + if bdev: + uos.mount(bdev, "/") +except OSError: + import inisetup_fat + + vfs = inisetup_fat.setup() + +gc.collect() diff --git a/ports/esp32/boards/UM_TINYS3/modules/inisetup_fat.py b/ports/esp32/boards/UM_TINYS3/modules/inisetup_fat.py new file mode 100644 index 0000000000000..55538a96a9136 --- /dev/null +++ b/ports/esp32/boards/UM_TINYS3/modules/inisetup_fat.py @@ -0,0 +1,49 @@ +import uos +from flashbdev import bdev + + +def check_bootsec(): + buf = bytearray(bdev.ioctl(5, 0)) # 5 is SEC_SIZE + bdev.readblocks(0, buf) + empty = True + for b in buf: + if b != 0xFF: + empty = False + break + if empty: + return True + fs_corrupted() + + +def fs_corrupted(): + import time + + while 1: + print( + """\ +The filesystem appears to be corrupted. If you had important data there, you +may want to make a flash snapshot to try to recover it. Otherwise, perform +factory reprogramming of MicroPython firmware (completely erase flash, followed +by firmware programming). +""" + ) + time.sleep(3) + + +def setup(): + check_bootsec() + print("Performing initial setup") + uos.VfsFat.mkfs(bdev) + vfs = uos.VfsFat(bdev) + uos.mount(vfs, "/") + with open("boot.py", "w") as f: + f.write( + """\ +# This file is executed on every boot (including wake-boot from deepsleep) +#import esp +#esp.osdebug(None) +#import webrepl +#webrepl.start() +""" + ) + return vfs diff --git a/ports/esp32/boards/UM_TINYS3/mpconfigboard.cmake b/ports/esp32/boards/UM_TINYS3/mpconfigboard.cmake index 6c7f34009e432..66e9ef45aec8c 100644 --- a/ports/esp32/boards/UM_TINYS3/mpconfigboard.cmake +++ b/ports/esp32/boards/UM_TINYS3/mpconfigboard.cmake @@ -3,6 +3,7 @@ set(IDF_TARGET esp32s3) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base boards/sdkconfig.usb + #boards/sdkconfig.usb_msc boards/sdkconfig.ble boards/sdkconfig.240mhz boards/sdkconfig.spiram_sx