From 7cdad05e54397969c4416737042659541dfc5d17 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 30 Jun 2022 14:27:13 +1000 Subject: [PATCH] rp2/rp2_flash: Add asserts for size of flash filesystem partition. Signed-off-by: Damien George --- ports/rp2/rp2_flash.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ports/rp2/rp2_flash.c b/ports/rp2/rp2_flash.c index 80bc1dc1df12..db6b9f3bfe75 100644 --- a/ports/rp2/rp2_flash.c +++ b/ports/rp2/rp2_flash.c @@ -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) @@ -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); }