Skip to content

Commit 728fea4

Browse files
committed
add storage extension python api
1 parent b0ef35d commit 728fea4

File tree

6 files changed

+63
-26
lines changed

6 files changed

+63
-26
lines changed

locale/circuitpython.pot

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ msgstr ""
112112
msgid "%q init failed"
113113
msgstr ""
114114

115+
#: shared-bindings/dualbank/__init__.c
116+
msgid "%q is %q"
117+
msgstr ""
118+
115119
#: py/argcheck.c
116120
msgid "%q length must be %d"
117121
msgstr ""
@@ -152,14 +156,6 @@ msgstr ""
152156
msgid "%q must be >= %d"
153157
msgstr ""
154158

155-
#: py/argcheck.c
156-
msgid "%q must be >= 0"
157-
msgstr ""
158-
159-
#: shared-bindings/vectorio/Circle.c shared-bindings/vectorio/Rectangle.c
160-
msgid "%q must be >= 1"
161-
msgstr ""
162-
163159
#: shared-bindings/analogbufio/BufferedIn.c
164160
#: shared-bindings/audiocore/RawSample.c
165161
msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'"
@@ -214,7 +210,7 @@ msgstr ""
214210
msgid "%q, %q, and %q must all be the same length"
215211
msgstr ""
216212

217-
#: py/objint.c
213+
#: py/objint.c shared-bindings/storage/__init__.c
218214
msgid "%q=%q"
219215
msgstr ""
220216

@@ -910,8 +906,7 @@ msgstr ""
910906
msgid "Error: Failure to bind"
911907
msgstr ""
912908

913-
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c py/enum.c
914-
#: shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
909+
#: py/enum.c shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
915910
#: shared-bindings/alarm/__init__.c shared-bindings/busio/SPI.c
916911
#: shared-bindings/microcontroller/Pin.c
917912
#: shared-bindings/neopixel_write/__init__.c
@@ -1569,10 +1564,12 @@ msgid "Only 8 or 16 bit mono with "
15691564
msgstr ""
15701565

15711566
#: ports/espressif/common-hal/wifi/__init__.c
1567+
#: ports/raspberrypi/common-hal/wifi/__init__.c
15721568
msgid "Only IPv4 addresses supported"
15731569
msgstr ""
15741570

15751571
#: ports/espressif/common-hal/socketpool/Socket.c
1572+
#: ports/raspberrypi/common-hal/socketpool/Socket.c
15761573
msgid "Only IPv4 sockets supported"
15771574
msgstr ""
15781575

@@ -1642,6 +1639,7 @@ msgid "Out of memory"
16421639
msgstr ""
16431640

16441641
#: ports/espressif/common-hal/socketpool/Socket.c
1642+
#: ports/raspberrypi/common-hal/socketpool/Socket.c
16451643
msgid "Out of sockets"
16461644
msgstr ""
16471645

@@ -1696,7 +1694,6 @@ msgid "Pin interrupt already in use"
16961694
msgstr ""
16971695

16981696
#: shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c
1699-
#: shared-bindings/digitalio/DigitalInOut.c
17001697
msgid "Pin is input only"
17011698
msgstr ""
17021699

@@ -1916,6 +1913,7 @@ msgid "Slices not supported"
19161913
msgstr ""
19171914

19181915
#: ports/espressif/common-hal/socketpool/SocketPool.c
1916+
#: ports/raspberrypi/common-hal/socketpool/SocketPool.c
19191917
msgid "SocketPool can only be used with wifi.radio"
19201918
msgstr ""
19211919

@@ -2341,10 +2339,6 @@ msgstr ""
23412339
msgid "a bytes-like object is required"
23422340
msgstr ""
23432341

2344-
#: shared-bindings/i2ctarget/I2CTarget.c
2345-
msgid "address out of bounds"
2346-
msgstr ""
2347-
23482342
#: shared-bindings/i2ctarget/I2CTarget.c
23492343
msgid "addresses is empty"
23502344
msgstr ""
@@ -2814,10 +2808,6 @@ msgstr ""
28142808
msgid "destination buffer must be an array of type 'H' for bit_depth = 16"
28152809
msgstr ""
28162810

2817-
#: shared-bindings/audiobusio/PDMIn.c
2818-
msgid "destination_length must be an int >= 0"
2819-
msgstr ""
2820-
28212811
#: py/objdict.c
28222812
msgid "dict update sequence has wrong length"
28232813
msgstr ""

ports/espressif/common-hal/dualbank/__init__.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "esp_log.h"
3333
#include "esp_ota_ops.h"
3434

35+
#include "supervisor/flash.h"
36+
3537
static const esp_partition_t *update_partition = NULL;
3638
static esp_ota_handle_t update_handle = 0;
3739

shared-bindings/dualbank/__init__.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
#include "shared-bindings/dualbank/__init__.h"
2828

29+
#if CIRCUITPY_STORAGE_EXTEND
30+
#include "supervisor/flash.h"
31+
#endif
32+
2933
//| """DUALBANK Module
3034
//|
3135
//| The `dualbank` module adds ability to update and switch
@@ -55,6 +59,14 @@
5559
//| """
5660
//| ...
5761

62+
#if CIRCUITPY_STORAGE_EXTEND
63+
STATIC void raise_error_if_storage_extended(void) {
64+
if (supervisor_flash_get_extended()) {
65+
mp_raise_msg_varg(&mp_type_RuntimeError, translate("%q is %q"), MP_QSTR_storage, MP_QSTR_extended);
66+
}
67+
}
68+
#endif
69+
5870
//| def flash(buffer: ReadableBuffer, offset: int = 0) -> None:
5971
//| """Writes one of two app partitions at the given offset.
6072
//|
@@ -70,6 +82,10 @@ STATIC mp_obj_t dualbank_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t
7082
{ MP_QSTR_offset, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
7183
};
7284

85+
#if CIRCUITPY_STORAGE_EXTEND
86+
raise_error_if_storage_extended();
87+
#endif
88+
7389
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
7490
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
7591

@@ -94,6 +110,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dualbank_flash_obj, 0, dualbank_flash);
94110
//| ...
95111
//|
96112
STATIC mp_obj_t dualbank_switch(void) {
113+
#if CIRCUITPY_STORAGE_EXTEND
114+
raise_error_if_storage_extended();
115+
#endif
97116
common_hal_dualbank_switch();
98117
return mp_const_none;
99118
}

shared-bindings/storage/__init__.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "py/runtime.h"
3535
#include "shared-bindings/storage/__init__.h"
3636
#include "supervisor/shared/translate/translate.h"
37+
#include "supervisor/flash.h"
3738

3839
//| """Storage management
3940
//|
@@ -150,7 +151,7 @@ STATIC mp_obj_t storage_getmount(const mp_obj_t mnt_in) {
150151
}
151152
MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount);
152153

153-
//| def erase_filesystem() -> None:
154+
//| def erase_filesystem(extended: Optional[bool] = None) -> None:
154155
//| """Erase and re-create the ``CIRCUITPY`` filesystem.
155156
//|
156157
//| 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);
160161
//| This function can be called from the REPL when ``CIRCUITPY``
161162
//| has become corrupted.
162163
//|
164+
//| :param bool extended: On boards that support ``dualbank`` module
165+
//| and the ``extended`` parameter, the ``CIRCUITPY`` storage can be
166+
//| extended by setting this to `True`. If this isn't provided or
167+
//| set to `None` (default), the existing configuration will be used.
168+
//|
163169
//| .. warning:: All the data on ``CIRCUITPY`` will be lost, and
164170
//| CircuitPython will restart on certain boards."""
165171
//| ...
166172
//|
167173

168-
STATIC mp_obj_t storage_erase_filesystem(void) {
169-
common_hal_storage_erase_filesystem();
174+
STATIC mp_obj_t storage_erase_filesystem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
175+
enum { ARG_extended };
176+
static const mp_arg_t allowed_args[] = {
177+
{ MP_QSTR_extended, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
178+
};
179+
180+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
181+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
182+
183+
#if CIRCUITPY_STORAGE_EXTEND
184+
bool extended = (args[ARG_extended].u_obj == mp_const_none) ? supervisor_flash_get_extended() : mp_obj_is_true(args[ARG_extended].u_obj);
185+
common_hal_storage_erase_filesystem(extended);
186+
#else
187+
if (mp_obj_is_true(args[ARG_extended].u_obj)) {
188+
mp_raise_NotImplementedError_varg(translate("%q=%q"), MP_QSTR_extended, MP_QSTR_True);
189+
}
190+
common_hal_storage_erase_filesystem(false);
191+
#endif
192+
170193
return mp_const_none;
171194
}
172-
MP_DEFINE_CONST_FUN_OBJ_0(storage_erase_filesystem_obj, storage_erase_filesystem);
195+
MP_DEFINE_CONST_FUN_OBJ_KW(storage_erase_filesystem_obj, 0, storage_erase_filesystem);
173196

174197
//| def disable_usb_drive() -> None:
175198
//| """Disable presenting ``CIRCUITPY`` as a USB mass storage device.

shared-bindings/storage/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void common_hal_storage_umount_path(const char *path);
3737
void common_hal_storage_umount_object(mp_obj_t vfs_obj);
3838
void common_hal_storage_remount(const char *path, bool readonly, bool disable_concurrent_write_protection);
3939
mp_obj_t common_hal_storage_getmount(const char *path);
40-
void common_hal_storage_erase_filesystem(void);
40+
void common_hal_storage_erase_filesystem(bool extended);
4141

4242
bool common_hal_storage_disable_usb_drive(void);
4343
bool common_hal_storage_enable_usb_drive(void);

shared-module/storage/__init__.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,14 @@ void common_hal_storage_remount(const char *mount_path, bool readonly, bool disa
267267
filesystem_set_internal_concurrent_write_protection(!disable_concurrent_write_protection);
268268
}
269269

270-
void common_hal_storage_erase_filesystem(void) {
270+
void common_hal_storage_erase_filesystem(bool extended) {
271271
#if CIRCUITPY_USB
272272
usb_disconnect();
273273
#endif
274274
mp_hal_delay_ms(1000);
275+
#if CIRCUITPY_STORAGE_EXTEND
276+
supervisor_flash_set_extended(extended);
277+
#endif
275278
(void)filesystem_init(false, true); // Force a re-format. Ignore failure.
276279
common_hal_mcu_reset();
277280
// We won't actually get here, since we're resetting.

0 commit comments

Comments
 (0)