42
42
#include "supervisor/flash.h"
43
43
#include "supervisor/usb.h"
44
44
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 ];
46
52
47
53
// TODO: Split the caching out of supervisor/shared/external_flash so we can use it.
48
54
#define SECTOR_SIZE 4096
@@ -53,17 +59,23 @@ void supervisor_flash_init(void) {
53
59
_partition [0 ] = esp_partition_find_first (ESP_PARTITION_TYPE_DATA ,
54
60
ESP_PARTITION_SUBTYPE_DATA_FAT ,
55
61
NULL );
62
+ #if CIRCUITPY_STORAGE_EXTEND
56
63
_partition [1 ] = esp_partition_find_first (ESP_PARTITION_TYPE_APP ,
57
64
ESP_PARTITION_SUBTYPE_APP_OTA_1 ,
58
65
NULL );
66
+ #endif
59
67
}
60
68
61
69
uint32_t supervisor_flash_get_block_size (void ) {
62
70
return FILESYSTEM_BLOCK_SIZE ;
63
71
}
64
72
65
73
uint32_t supervisor_flash_get_block_count (void ) {
74
+ #if CIRCUITPY_STORAGE_EXTEND
66
75
return (_partition [0 ]-> size + _partition [1 ]-> size ) / FILESYSTEM_BLOCK_SIZE ;
76
+ #else
77
+ return _partition [0 ]-> size / FILESYSTEM_BLOCK_SIZE ;
78
+ #endif
67
79
}
68
80
69
81
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
74
86
uint32_t offset = block * FILESYSTEM_BLOCK_SIZE ;
75
87
uint32_t read_total = num_blocks * FILESYSTEM_BLOCK_SIZE ;
76
88
89
+ #if CIRCUITPY_STORAGE_EXTEND
77
90
if (offset > _partition [0 ]-> size ) {
78
91
// only read from partition 1
79
92
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
83
96
uint32_t read_1 = read_total - read_0 ;
84
97
esp_partition_read (_partition [0 ], offset , dest , read_0 );
85
98
esp_partition_read (_partition [1 ], 0 , (dest + read_0 ), read_1 );
86
- } else {
99
+ } else
100
+ #endif
101
+ {
87
102
// only read from partition 0
88
103
esp_partition_read (_partition [0 ], offset , dest , read_total );
89
104
}
@@ -115,6 +130,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32
115
130
block ++ ;
116
131
}
117
132
133
+ #if CIRCUITPY_STORAGE_EXTEND
118
134
if (sector_offset > _partition [0 ]-> size ) {
119
135
// only write to partition 1
120
136
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
127
143
esp_partition_write (_partition [0 ], sector_offset , _cache , write_0 );
128
144
esp_partition_erase_range (_partition [1 ], 0 , write_1 );
129
145
esp_partition_write (_partition [1 ], 0 , _cache + write_0 , write_1 );
130
- } else {
146
+ } else
147
+ #endif
148
+ {
131
149
// only write to partition 0
132
150
esp_partition_erase_range (_partition [0 ], sector_offset , SECTOR_SIZE );
133
151
esp_partition_write (_partition [0 ], sector_offset , _cache , SECTOR_SIZE );
0 commit comments