Skip to content

Commit a28b794

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

File tree

7 files changed

+58
-31
lines changed

7 files changed

+58
-31
lines changed

locale/circuitpython.pot

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,6 @@ msgstr ""
152152
msgid "%q must be >= %d"
153153
msgstr ""
154154

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-
163155
#: shared-bindings/analogbufio/BufferedIn.c
164156
#: shared-bindings/audiocore/RawSample.c
165157
msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'"
@@ -910,8 +902,7 @@ msgstr ""
910902
msgid "Error: Failure to bind"
911903
msgstr ""
912904

913-
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c py/enum.c
914-
#: shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
905+
#: py/enum.c shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
915906
#: shared-bindings/alarm/__init__.c shared-bindings/busio/SPI.c
916907
#: shared-bindings/microcontroller/Pin.c
917908
#: shared-bindings/neopixel_write/__init__.c
@@ -1569,10 +1560,12 @@ msgid "Only 8 or 16 bit mono with "
15691560
msgstr ""
15701561

15711562
#: ports/espressif/common-hal/wifi/__init__.c
1563+
#: ports/raspberrypi/common-hal/wifi/__init__.c
15721564
msgid "Only IPv4 addresses supported"
15731565
msgstr ""
15741566

15751567
#: ports/espressif/common-hal/socketpool/Socket.c
1568+
#: ports/raspberrypi/common-hal/socketpool/Socket.c
15761569
msgid "Only IPv4 sockets supported"
15771570
msgstr ""
15781571

@@ -1642,6 +1635,7 @@ msgid "Out of memory"
16421635
msgstr ""
16431636

16441637
#: ports/espressif/common-hal/socketpool/Socket.c
1638+
#: ports/raspberrypi/common-hal/socketpool/Socket.c
16451639
msgid "Out of sockets"
16461640
msgstr ""
16471641

@@ -1696,7 +1690,6 @@ msgid "Pin interrupt already in use"
16961690
msgstr ""
16971691

16981692
#: shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c
1699-
#: shared-bindings/digitalio/DigitalInOut.c
17001693
msgid "Pin is input only"
17011694
msgstr ""
17021695

@@ -1916,6 +1909,7 @@ msgid "Slices not supported"
19161909
msgstr ""
19171910

19181911
#: ports/espressif/common-hal/socketpool/SocketPool.c
1912+
#: ports/raspberrypi/common-hal/socketpool/SocketPool.c
19191913
msgid "SocketPool can only be used with wifi.radio"
19201914
msgstr ""
19211915

@@ -2341,10 +2335,6 @@ msgstr ""
23412335
msgid "a bytes-like object is required"
23422336
msgstr ""
23432337

2344-
#: shared-bindings/i2ctarget/I2CTarget.c
2345-
msgid "address out of bounds"
2346-
msgstr ""
2347-
23482338
#: shared-bindings/i2ctarget/I2CTarget.c
23492339
msgid "addresses is empty"
23502340
msgstr ""
@@ -2814,10 +2804,6 @@ msgstr ""
28142804
msgid "destination buffer must be an array of type 'H' for bit_depth = 16"
28152805
msgstr ""
28162806

2817-
#: shared-bindings/audiobusio/PDMIn.c
2818-
msgid "destination_length must be an int >= 0"
2819-
msgstr ""
2820-
28212807
#: py/objdict.c
28222808
msgid "dict update sequence has wrong length"
28232809
msgstr ""
@@ -3986,6 +3972,10 @@ msgstr ""
39863972
msgid "stop not reachable from start"
39873973
msgstr ""
39883974

3975+
#: ports/espressif/common-hal/dualbank/__init__.c
3976+
msgid "storage is extended"
3977+
msgstr ""
3978+
39893979
#: py/stream.c shared-bindings/getpass/__init__.c
39903980
msgid "stream operation not supported"
39913981
msgstr ""

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

Lines changed: 10 additions & 1 deletion
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

@@ -119,11 +121,18 @@ void common_hal_dualbank_flash(const void *buf, const size_t len, const size_t o
119121
}
120122
}
121123

122-
void common_hal_dualbank_switch(void) {
124+
void common_hal_dualbank_switch(bool both_bootable) {
123125
if (esp_ota_end(update_handle) == ESP_OK) {
124126
update_handle = 0;
125127
update_partition = NULL;
126128
}
129+
130+
#if CIRCUITPY_STORAGE_EXTEND
131+
if (both_bootable && supervisor_flash_get_extended()) {
132+
mp_raise_RuntimeError(translate("storage is extended"));
133+
}
134+
#endif
135+
127136
esp_err_t err = esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL));
128137
if (err != ESP_OK) {
129138
if (err == ESP_ERR_OTA_VALIDATE_FAILED) {

shared-bindings/dualbank/__init__.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,31 @@ STATIC mp_obj_t dualbank_flash(size_t n_args, const mp_obj_t *pos_args, mp_map_t
8585
}
8686
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dualbank_flash_obj, 0, dualbank_flash);
8787

88-
//| def switch() -> None:
88+
//| def switch(both_bootable: Optional[bool] = False) -> None:
8989
//| """Switches the boot partition.
9090
//|
9191
//| On next reset, firmware will be loaded from the partition
9292
//| just switched over to.
93+
//|
94+
//| :param bool both_bootable: If `False`, the other partition
95+
//| will be used to extend the ``CIRCUITPY`` storage.
9396
//| """
9497
//| ...
9598
//|
96-
STATIC mp_obj_t dualbank_switch(void) {
97-
common_hal_dualbank_switch();
99+
STATIC mp_obj_t dualbank_switch(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
100+
enum { ARG_both_bootable };
101+
static const mp_arg_t allowed_args[] = {
102+
{ MP_QSTR_both_bootable, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
103+
};
104+
105+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
106+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
107+
108+
common_hal_dualbank_switch(args[ARG_both_bootable].u_bool);
109+
98110
return mp_const_none;
99111
}
100-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(dualbank_switch_obj, dualbank_switch);
112+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dualbank_switch_obj, 0, dualbank_switch);
101113

102114
STATIC const mp_rom_map_elem_t dualbank_module_globals_table[] = {
103115
// module name

shared-bindings/dualbank/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#include "py/runtime.h"
3131

32-
extern void common_hal_dualbank_switch(void);
32+
extern void common_hal_dualbank_switch(bool both_bootable);
3333
extern void common_hal_dualbank_flash(const void *buf, const size_t len, const size_t offset);
3434

3535
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DUALBANK___INIT___H

shared-bindings/storage/__init__.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ STATIC mp_obj_t storage_getmount(const mp_obj_t mnt_in) {
150150
}
151151
MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount);
152152

153-
//| def erase_filesystem() -> None:
153+
//| def erase_filesystem(extended: Optional[bool] = True) -> None:
154154
//| """Erase and re-create the ``CIRCUITPY`` filesystem.
155155
//|
156156
//| On boards that present USB-visible ``CIRCUITPY`` drive (e.g., SAMD21 and SAMD51),
@@ -160,16 +160,29 @@ MP_DEFINE_CONST_FUN_OBJ_1(storage_getmount_obj, storage_getmount);
160160
//| This function can be called from the REPL when ``CIRCUITPY``
161161
//| has become corrupted.
162162
//|
163+
//| :param bool extended: On boards that support ``CIRCUITPY_DUALBANK``
164+
//| and ``CIRCUITPY_STORAGE_EXTEND``, the ``CIRCUITPY`` storage can be
165+
//| extended by setting this to `True`.
166+
//|
163167
//| .. warning:: All the data on ``CIRCUITPY`` will be lost, and
164168
//| CircuitPython will restart on certain boards."""
165169
//| ...
166170
//|
167171

168-
STATIC mp_obj_t storage_erase_filesystem(void) {
169-
common_hal_storage_erase_filesystem();
172+
STATIC mp_obj_t storage_erase_filesystem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
173+
enum { ARG_extended };
174+
static const mp_arg_t allowed_args[] = {
175+
{ MP_QSTR_extended, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
176+
};
177+
178+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
179+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
180+
181+
common_hal_storage_erase_filesystem(args[ARG_extended].u_bool);
182+
170183
return mp_const_none;
171184
}
172-
MP_DEFINE_CONST_FUN_OBJ_0(storage_erase_filesystem_obj, storage_erase_filesystem);
185+
MP_DEFINE_CONST_FUN_OBJ_KW(storage_erase_filesystem_obj, 0, storage_erase_filesystem);
173186

174187
//| def disable_usb_drive() -> None:
175188
//| """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)