Skip to content

Commit cdc6966

Browse files
committed
storage: map_file - require the port hook instead of a weak default
A port that sets CIRCUITPY_STORAGE_MAP_FILE now has to define port_internal_flash_xip_address(); there is no weak fallback returning NULL. Both ports that set it - raspberrypi and espressif - already define it, and espressif still returns NULL for a partition it could not map, so the caller's NULL path keeps its meaning. Setting the flag without the function is a link error rather than a module that builds and then refuses every call at runtime.
1 parent b4fda7c commit cdc6966

3 files changed

Lines changed: 5 additions & 9 deletions

File tree

‎py/circuitpy_mpconfig.mk‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,9 @@ CFLAGS += -DCIRCUITPY_STORAGE=$(CIRCUITPY_STORAGE)
636636
CIRCUITPY_STORAGE_EXTEND ?= $(CIRCUITPY_DUALBANK)
637637
CFLAGS += -DCIRCUITPY_STORAGE_EXTEND=$(CIRCUITPY_STORAGE_EXTEND)
638638

639-
# storage.map_file(): read a file straight out of memory-mapped flash. Ports whose CIRCUITPY drive
640-
# is memory-mapped implement port_internal_flash_xip_address() and turn it on.
639+
# storage.map_file(): read a file straight out of memory-mapped flash. A port whose CIRCUITPY drive
640+
# is memory-mapped implements port_internal_flash_xip_address() and turns this on; turning it on
641+
# without that function is a link error, not a silent no-op.
641642
CIRCUITPY_STORAGE_MAP_FILE ?= 0
642643
CFLAGS += -DCIRCUITPY_STORAGE_MAP_FILE=$(CIRCUITPY_STORAGE_MAP_FILE)
643644

‎supervisor/shared/flash.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,6 @@ static mp_uint_t flash_read_blocks(mp_obj_t self_in, uint8_t *dest, uint32_t blo
150150
}
151151

152152
#if CIRCUITPY_STORAGE_MAP_FILE
153-
MP_WEAK const uint8_t *port_internal_flash_xip_address(uint32_t block, uint32_t *contiguous) {
154-
(void)block;
155-
(void)contiguous;
156-
return NULL; // this port does not map its drive
157-
}
158-
159153
// The sector -> block translation of flash_read_blocks(); FatFs has already validated the
160154
// cluster chain, so every sector it hands over lies inside the volume.
161155
const uint8_t *supervisor_flash_xip_address(uint32_t fatfs_sector, uint32_t *contiguous) {

‎supervisor/shared/internal_flash.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ void port_internal_flash_flush(void);
1111

1212
#if CIRCUITPY_STORAGE_MAP_FILE
1313
// The memory-mapped address of a drive block, NULL if the port cannot map it; *contiguous
14-
// receives how many blocks from it are contiguous in the mapping. Weak NULL default.
14+
// receives how many blocks from it are contiguous in the mapping. A port that sets
15+
// CIRCUITPY_STORAGE_MAP_FILE implements this.
1516
const uint8_t *port_internal_flash_xip_address(uint32_t block, uint32_t *contiguous);
1617
#endif

0 commit comments

Comments
 (0)