Skip to content

Commit 9fe7308

Browse files
committed
conditionally add storage extension
1 parent 7d8ff20 commit 9fe7308

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

ports/espressif/supervisor/internal_flash.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@
4242
#include "supervisor/flash.h"
4343
#include "supervisor/usb.h"
4444

45-
STATIC const esp_partition_t *_partition[2];
45+
#if CIRCUITPY_STORAGE_EXTEND
46+
#define PARTITION_NUM (2)
47+
#else
48+
#define PARTITION_NUM (1)
49+
#endif
50+
51+
STATIC const esp_partition_t *_partition[PARTITION_NUM];
4652

4753
// TODO: Split the caching out of supervisor/shared/external_flash so we can use it.
4854
#define SECTOR_SIZE 4096
@@ -53,17 +59,23 @@ void supervisor_flash_init(void) {
5359
_partition[0] = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,
5460
ESP_PARTITION_SUBTYPE_DATA_FAT,
5561
NULL);
62+
#if CIRCUITPY_STORAGE_EXTEND
5663
_partition[1] = esp_partition_find_first(ESP_PARTITION_TYPE_APP,
5764
ESP_PARTITION_SUBTYPE_APP_OTA_1,
5865
NULL);
66+
#endif
5967
}
6068

6169
uint32_t supervisor_flash_get_block_size(void) {
6270
return FILESYSTEM_BLOCK_SIZE;
6371
}
6472

6573
uint32_t supervisor_flash_get_block_count(void) {
74+
#if CIRCUITPY_STORAGE_EXTEND
6675
return (_partition[0]->size + _partition[1]->size) / FILESYSTEM_BLOCK_SIZE;
76+
#else
77+
return _partition[0]->size / FILESYSTEM_BLOCK_SIZE;
78+
#endif
6779
}
6880

6981
void port_internal_flash_flush(void) {
@@ -74,6 +86,7 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n
7486
uint32_t offset = block * FILESYSTEM_BLOCK_SIZE;
7587
uint32_t read_total = num_blocks * FILESYSTEM_BLOCK_SIZE;
7688

89+
#if CIRCUITPY_STORAGE_EXTEND
7790
if (offset > _partition[0]->size) {
7891
// only read from partition 1
7992
esp_partition_read(_partition[1], (offset - _partition[0]->size), dest, read_total);
@@ -83,7 +96,9 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n
8396
uint32_t read_1 = read_total - read_0;
8497
esp_partition_read(_partition[0], offset, dest, read_0);
8598
esp_partition_read(_partition[1], 0, (dest + read_0), read_1);
86-
} else {
99+
} else
100+
#endif
101+
{
87102
// only read from partition 0
88103
esp_partition_read(_partition[0], offset, dest, read_total);
89104
}
@@ -115,6 +130,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32
115130
block++;
116131
}
117132

133+
#if CIRCUITPY_STORAGE_EXTEND
118134
if (sector_offset > _partition[0]->size) {
119135
// only write to partition 1
120136
esp_partition_erase_range(_partition[1], sector_offset - _partition[0]->size, SECTOR_SIZE);
@@ -127,7 +143,9 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32
127143
esp_partition_write(_partition[0], sector_offset, _cache, write_0);
128144
esp_partition_erase_range(_partition[1], 0, write_1);
129145
esp_partition_write(_partition[1], 0, _cache + write_0, write_1);
130-
} else {
146+
} else
147+
#endif
148+
{
131149
// only write to partition 0
132150
esp_partition_erase_range(_partition[0], sector_offset, SECTOR_SIZE);
133151
esp_partition_write(_partition[0], sector_offset, _cache, SECTOR_SIZE);

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ CFLAGS += -DCIRCUITPY_STATUS_BAR=$(CIRCUITPY_STATUS_BAR)
384384
CIRCUITPY_STORAGE ?= 1
385385
CFLAGS += -DCIRCUITPY_STORAGE=$(CIRCUITPY_STORAGE)
386386

387+
CIRCUITPY_STORAGE_EXTEND ?= $(CIRCUITPY_DUALBANK)
388+
CFLAGS += -DCIRCUITPY_STORAGE_EXTEND=$(CIRCUITPY_STORAGE_EXTEND)
389+
387390
CIRCUITPY_STRUCT ?= 1
388391
CFLAGS += -DCIRCUITPY_STRUCT=$(CIRCUITPY_STRUCT)
389392

0 commit comments

Comments
 (0)