Skip to content

Commit

Permalink
rp2/rp2_flash: Add asserts for size of flash filesystem partition.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Jun 30, 2022
1 parent c95f991 commit 7cdad05
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ports/rp2/rp2_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#ifndef MICROPY_HW_FLASH_STORAGE_BYTES
#define MICROPY_HW_FLASH_STORAGE_BYTES (1408 * 1024)
#endif
static_assert(MICROPY_HW_FLASH_STORAGE_BYTES % 4096 == 0, "Flash storage size must be a multiple of 4K");

#ifndef MICROPY_HW_FLASH_STORAGE_BASE
#define MICROPY_HW_FLASH_STORAGE_BASE (PICO_FLASH_SIZE_BYTES - MICROPY_HW_FLASH_STORAGE_BYTES)
Expand Down Expand Up @@ -72,6 +73,11 @@ STATIC mp_obj_t rp2_flash_make_new(const mp_obj_type_t *type, size_t n_args, siz
// Check args.
mp_arg_check_num(n_args, n_kw, 0, 0, false);

#ifndef NDEBUG
extern char __flash_binary_end;
assert((uintptr_t)&__flash_binary_end - XIP_BASE <= MICROPY_HW_FLASH_STORAGE_BASE);
#endif

// Return singleton object.
return MP_OBJ_FROM_PTR(&rp2_flash_obj);
}
Expand Down

0 comments on commit 7cdad05

Please sign in to comment.