From 6e2c24083a95acfca4624053736f94eff8e66807 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 6 Oct 2022 10:12:22 -0500 Subject: [PATCH 1/3] switch flash split to leave 512kB for CIRCUITPY --- ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld | 2 +- ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld b/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld index 7d0a44ce51..e87f0805eb 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld @@ -23,7 +23,7 @@ MEMORY { - FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1788k + FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1532k RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk index 15c4261f83..50c7f5a0a9 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk @@ -21,4 +21,4 @@ CIRCUITPY_WIFI = 1 CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0 # Must be accompanied by a linker script change -CFLAGS += -DRESERVED_FLASH='(1792 * 1024)' +CFLAGS += -DRESERVED_FLASH='(1532 * 1024)' From 07cd2ff0650a66eccebcab25a626fec5553d9133 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 6 Oct 2022 11:20:48 -0500 Subject: [PATCH 2/3] restore 4kB gap pending resolution of #7011 --- ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld b/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld index e87f0805eb..e46f5ad5d4 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld @@ -23,7 +23,7 @@ MEMORY { - FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1532k + FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1528k RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k From 644d2936415f803e61f0b60fc4a90a7d46b19e4f Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 6 Oct 2022 11:52:25 -0500 Subject: [PATCH 3/3] Fix CIRCUITPY drive offset in flash correctly, accounting for NVM .. and fix nvm to read/right the correct area. .. putting a comment in link.ld to explain it all Closes #7012 --- .../boards/raspberry_pi_pico_w/link.ld | 3 ++- .../raspberry_pi_pico_w/mpconfigboard.mk | 2 +- ports/raspberrypi/link.ld | 1 + ports/raspberrypi/mpconfigport.h | 12 ++++++++-- ports/raspberrypi/supervisor/internal_flash.c | 22 ++++++++----------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld b/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld index e46f5ad5d4..2777b41720 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld @@ -23,7 +23,8 @@ MEMORY { - FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1528k + FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1532k + /* Followed by: 4kB of NVRAM and at least 512kB of CIRCUITPY */ RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk index 50c7f5a0a9..f075b03693 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk @@ -21,4 +21,4 @@ CIRCUITPY_WIFI = 1 CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0 # Must be accompanied by a linker script change -CFLAGS += -DRESERVED_FLASH='(1532 * 1024)' +CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(1536 * 1024)' diff --git a/ports/raspberrypi/link.ld b/ports/raspberrypi/link.ld index c9480f84db..982c5e3a0c 100644 --- a/ports/raspberrypi/link.ld +++ b/ports/raspberrypi/link.ld @@ -24,6 +24,7 @@ MEMORY { FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1020k + /* Followed by: 4kB of NVRAM and at least 1024kB of CIRCUITPY */ RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k diff --git a/ports/raspberrypi/mpconfigport.h b/ports/raspberrypi/mpconfigport.h index 7f2b75a81b..a2eb9a15ef 100644 --- a/ports/raspberrypi/mpconfigport.h +++ b/ports/raspberrypi/mpconfigport.h @@ -31,9 +31,17 @@ #define MICROPY_PY_SYS_PLATFORM "RP2040" -#define CIRCUITPY_INTERNAL_NVM_SIZE (4 * 1024) -#define CIRCUITPY_INTERNAL_NVM_START_ADDR (0x100FF000) +// Setting a non-default value also requires a non-default link.ld +#ifndef CIRCUITPY_FIRMWARE_SIZE +#define CIRCUITPY_FIRMWARE_SIZE (1020 * 1024) +#endif +#define CIRCUITPY_INTERNAL_NVM_SIZE (4 * 1024) +// This is the XIP address +#define CIRCUITPY_INTERNAL_NVM_START_ADDR (0x10000000 + CIRCUITPY_FIRMWARE_SIZE) + +// This is the flash linear address +#define CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR (CIRCUITPY_FIRMWARE_SIZE + CIRCUITPY_INTERNAL_NVM_SIZE) #define CIRCUITPY_DEFAULT_STACK_SIZE (24 * 1024) #define MICROPY_USE_INTERNAL_PRINTF (1) diff --git a/ports/raspberrypi/supervisor/internal_flash.c b/ports/raspberrypi/supervisor/internal_flash.c index d2d80b40ad..010528559d 100644 --- a/ports/raspberrypi/supervisor/internal_flash.c +++ b/ports/raspberrypi/supervisor/internal_flash.c @@ -46,10 +46,6 @@ #include "src/rp2_common/hardware_flash/include/hardware/flash.h" #include "src/common/pico_binary_info/include/pico/binary_info.h" -#if !defined(RESERVED_FLASH) -#define RESERVED_FLASH (1 * 1024 * 1024) -#endif - #if !defined(TOTAL_FLASH_MINIMUM) #define TOTAL_FLASH_MINIMUM (2 * 1024 * 1024) #endif @@ -65,8 +61,8 @@ void supervisor_flash_init(void) { bi_decl_if_func_used(bi_block_device( BINARY_INFO_MAKE_TAG('C', 'P'), "CircuitPython", - RESERVED_FLASH, - TOTAL_FLASH_MINIMUM - RESERVED_FLASH, // This is a minimum. We can't set it dynamically. + CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR, + TOTAL_FLASH_MINIMUM - CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR, // This is a minimum. We can't set it dynamically. NULL, BINARY_INFO_BLOCK_DEV_FLAG_READ | BINARY_INFO_BLOCK_DEV_FLAG_WRITE | @@ -92,7 +88,7 @@ uint32_t supervisor_flash_get_block_size(void) { } uint32_t supervisor_flash_get_block_count(void) { - return (_flash_size - RESERVED_FLASH) / FILESYSTEM_BLOCK_SIZE; + return (_flash_size - CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR) / FILESYSTEM_BLOCK_SIZE; } void port_internal_flash_flush(void) { @@ -100,15 +96,15 @@ void port_internal_flash_flush(void) { return; } common_hal_mcu_disable_interrupts(); - flash_range_erase(RESERVED_FLASH + _cache_lba, SECTOR_SIZE); - flash_range_program(RESERVED_FLASH + _cache_lba, _cache, SECTOR_SIZE); + flash_range_erase(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + _cache_lba, SECTOR_SIZE); + flash_range_program(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + _cache_lba, _cache, SECTOR_SIZE); common_hal_mcu_enable_interrupts(); _cache_lba = NO_CACHE; } mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { memcpy(dest, - (void *)(XIP_BASE + RESERVED_FLASH + block * FILESYSTEM_BLOCK_SIZE), + (void *)(XIP_BASE + CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + block * FILESYSTEM_BLOCK_SIZE), num_blocks * FILESYSTEM_BLOCK_SIZE); return 0; } @@ -123,7 +119,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32 if (_cache_lba != block_address) { memcpy(_cache, - (void *)(XIP_BASE + RESERVED_FLASH + sector_offset), + (void *)(XIP_BASE + CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + sector_offset), SECTOR_SIZE); _cache_lba = sector_offset; } @@ -139,8 +135,8 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32 } // Make sure we don't have an interrupt while we do flash operations. common_hal_mcu_disable_interrupts(); - flash_range_erase(RESERVED_FLASH + sector_offset, SECTOR_SIZE); - flash_range_program(RESERVED_FLASH + sector_offset, _cache, SECTOR_SIZE); + flash_range_erase(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + sector_offset, SECTOR_SIZE); + flash_range_program(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + sector_offset, _cache, SECTOR_SIZE); common_hal_mcu_enable_interrupts(); }