add storage extension python api
This commit is contained in:
parent
b0ef35d50b
commit
728fea4ca4
|
@ -112,6 +112,10 @@ msgstr ""
|
|||
msgid "%q init failed"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/dualbank/__init__.c
|
||||
msgid "%q is %q"
|
||||
msgstr ""
|
||||
|
||||
#: py/argcheck.c
|
||||
msgid "%q length must be %d"
|
||||
msgstr ""
|
||||
|
@ -152,14 +156,6 @@ msgstr ""
|
|||
msgid "%q must be >= %d"
|
||||
msgstr ""
|
||||
|
||||
#: py/argcheck.c
|
||||
msgid "%q must be >= 0"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/vectorio/Circle.c shared-bindings/vectorio/Rectangle.c
|
||||
msgid "%q must be >= 1"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/analogbufio/BufferedIn.c
|
||||
#: shared-bindings/audiocore/RawSample.c
|
||||
msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'"
|
||||
|
@ -214,7 +210,7 @@ msgstr ""
|
|||
msgid "%q, %q, and %q must all be the same length"
|
||||
msgstr ""
|
||||
|
||||
#: py/objint.c
|
||||
#: py/objint.c shared-bindings/storage/__init__.c
|
||||
msgid "%q=%q"
|
||||
msgstr ""
|
||||
|
||||
|
@ -910,8 +906,7 @@ msgstr ""
|
|||
msgid "Error: Failure to bind"
|
||||
msgstr ""
|
||||
|
||||
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c py/enum.c
|
||||
#: shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
|
||||
#: py/enum.c shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
|
||||
#: shared-bindings/alarm/__init__.c shared-bindings/busio/SPI.c
|
||||
#: shared-bindings/microcontroller/Pin.c
|
||||
#: shared-bindings/neopixel_write/__init__.c
|
||||
|
@ -1569,10 +1564,12 @@ msgid "Only 8 or 16 bit mono with "
|
|||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/wifi/__init__.c
|
||||
#: ports/raspberrypi/common-hal/wifi/__init__.c
|
||||
msgid "Only IPv4 addresses supported"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/socketpool/Socket.c
|
||||
#: ports/raspberrypi/common-hal/socketpool/Socket.c
|
||||
msgid "Only IPv4 sockets supported"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1642,6 +1639,7 @@ msgid "Out of memory"
|
|||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/socketpool/Socket.c
|
||||
#: ports/raspberrypi/common-hal/socketpool/Socket.c
|
||||
msgid "Out of sockets"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1696,7 +1694,6 @@ msgid "Pin interrupt already in use"
|
|||
msgstr ""
|
||||
|
||||
#: shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c
|
||||
#: shared-bindings/digitalio/DigitalInOut.c
|
||||
msgid "Pin is input only"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1916,6 +1913,7 @@ msgid "Slices not supported"
|
|||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/socketpool/SocketPool.c
|
||||
#: ports/raspberrypi/common-hal/socketpool/SocketPool.c
|
||||
msgid "SocketPool can only be used with wifi.radio"
|
||||
msgstr ""
|
||||
|
||||
|
@ -2341,10 +2339,6 @@ msgstr ""
|
|||
msgid "a bytes-like object is required"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/i2ctarget/I2CTarget.c
|
||||
msgid "address out of bounds"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/i2ctarget/I2CTarget.c
|
||||
msgid "addresses is empty"
|
||||
msgstr ""
|
||||
|
@ -2814,10 +2808,6 @@ msgstr ""
|
|||
msgid "destination buffer must be an array of type 'H' for bit_depth = 16"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/audiobusio/PDMIn.c
|
||||
msgid "destination_length must be an int >= 0"
|
||||
msgstr ""
|
||||
|
||||
#: py/objdict.c
|
||||
msgid "dict update sequence has wrong length"
|
||||
msgstr ""
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include "esp_log.h"
|
||||
#include "esp_ota_ops.h"
|
||||
|
||||
#include "supervisor/flash.h"
|
||||
|
||||
static const esp_partition_t *update_partition = NULL;
|
||||
static esp_ota_handle_t update_handle = 0;
|
||||
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
|
||||
#include "shared-bindings/dualbank/__init__.h"
|
||||
|
||||
#if CIRCUITPY_STORAGE_EXTEND
|
||||
#include "supervisor/flash.h"
|
||||
#endif
|
||||
|
||||
//| """DUALBANK Module
|
||||
//|
|
||||
//| The `dualbank` module adds ability to update and switch
|
||||
|
@ -55,6 +59,14 @@
|
|||
//| """
|
||||
//| ...
|
||||
|
||||
#if CIRCUITPY_STORAGE_EXTEND
|
||||
STATIC void raise_error_if_storage_extended(void) {
|
||||
if (supervisor_flash_get_extended()) {
|
||||
mp_raise_msg_varg(&mp_type_RuntimeError, translate("%q is %q"), MP_QSTR_storage, MP_QSTR_extended);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//| def flash(buffer: ReadableBuffer, offset: int = 0) -> None:
|
||||
//| """Writes one of two app partitions at the given offset.
|
||||
//|
|
||||
|
@ -70,6 +82,10 @@ STATIC mp_obj_t dualbank_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t
|
|||
{ MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
|
||||
};
|
||||
|
||||
#if CIRCUITPY_STORAGE_EXTEND
|
||||
raise_error_if_storage_extended();
|
||||
#endif
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
|
@ -94,6 +110,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dualbank_flash_obj, 0, dualbank_flash);
|
|||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t dualbank_switch(void) {
|
||||
#if CIRCUITPY_STORAGE_EXTEND
|
||||
raise_error_if_storage_extended();
|
||||
#endif
|
||||
common_hal_dualbank_switch();
|
||||
return mp_const_none;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "py/runtime.h"
|
||||
#include "shared-bindings/storage/__init__.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
#include "supervisor/flash.h"
|
||||
|
||||
//| """Storage management
|
||||
//|
|
||||
|
@ -150,7 +151,7 @@ STATIC mp_obj_t storage_getmount(const mp_obj_t mnt_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount);
|
||||
|
||||
//| def erase_filesystem() -> None:
|
||||
//| def erase_filesystem(extended: Optional[bool] = None) -> None:
|
||||
//| """Erase and re-create the ``CIRCUITPY`` filesystem.
|
||||
//|
|
||||
//| On boards that present USB-visible ``CIRCUITPY`` drive (e.g., SAMD21 and SAMD51),
|
||||
|
@ -160,16 +161,38 @@ MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount);
|
|||
//| This function can be called from the REPL when ``CIRCUITPY``
|
||||
//| has become corrupted.
|
||||
//|
|
||||
//| :param bool extended: On boards that support ``dualbank`` module
|
||||
//| and the ``extended`` parameter, the ``CIRCUITPY`` storage can be
|
||||
//| extended by setting this to `True`. If this isn't provided or
|
||||
//| set to `None` (default), the existing configuration will be used.
|
||||
//|
|
||||
//| .. warning:: All the data on ``CIRCUITPY`` will be lost, and
|
||||
//| CircuitPython will restart on certain boards."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t storage_erase_filesystem(void) {
|
||||
common_hal_storage_erase_filesystem();
|
||||
STATIC mp_obj_t storage_erase_filesystem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_extended };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_extended, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
};
|
||||
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
#if CIRCUITPY_STORAGE_EXTEND
|
||||
bool extended = (args[ARG_extended].u_obj == mp_const_none) ? supervisor_flash_get_extended() : mp_obj_is_true(args[ARG_extended].u_obj);
|
||||
common_hal_storage_erase_filesystem(extended);
|
||||
#else
|
||||
if (mp_obj_is_true(args[ARG_extended].u_obj)) {
|
||||
mp_raise_NotImplementedError_varg(translate("%q=%q"), MP_QSTR_extended, MP_QSTR_True);
|
||||
}
|
||||
common_hal_storage_erase_filesystem(false);
|
||||
#endif
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(storage_erase_filesystem_obj, storage_erase_filesystem);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(storage_erase_filesystem_obj, 0, storage_erase_filesystem);
|
||||
|
||||
//| def disable_usb_drive() -> None:
|
||||
//| """Disable presenting ``CIRCUITPY`` as a USB mass storage device.
|
||||
|
|
|
@ -37,7 +37,7 @@ void common_hal_storage_umount_path(const char *path);
|
|||
void common_hal_storage_umount_object(mp_obj_t vfs_obj);
|
||||
void common_hal_storage_remount(const char *path, bool readonly, bool disable_concurrent_write_protection);
|
||||
mp_obj_t common_hal_storage_getmount(const char *path);
|
||||
void common_hal_storage_erase_filesystem(void);
|
||||
void common_hal_storage_erase_filesystem(bool extended);
|
||||
|
||||
bool common_hal_storage_disable_usb_drive(void);
|
||||
bool common_hal_storage_enable_usb_drive(void);
|
||||
|
|
|
@ -267,11 +267,14 @@ void common_hal_storage_remount(const char *mount_path, bool readonly, bool disa
|
|||
filesystem_set_internal_concurrent_write_protection(!disable_concurrent_write_protection);
|
||||
}
|
||||
|
||||
void common_hal_storage_erase_filesystem(void) {
|
||||
void common_hal_storage_erase_filesystem(bool extended) {
|
||||
#if CIRCUITPY_USB
|
||||
usb_disconnect();
|
||||
#endif
|
||||
mp_hal_delay_ms(1000);
|
||||
#if CIRCUITPY_STORAGE_EXTEND
|
||||
supervisor_flash_set_extended(extended);
|
||||
#endif
|
||||
(void)filesystem_init(false, true); // Force a re-format. Ignore failure.
|
||||
common_hal_mcu_reset();
|
||||
// We won't actually get here, since we're resetting.
|
||||
|
|
Loading…
Reference in New Issue