Skip to content

Commit 8f8ac1c

Browse files
committed
ports/rp2: Per-board linker flash config.
Add per-board flash config to avoid silently overwriting user code on vfs init. Make linker FLASH section reflect board size. Add linker APP section for user code. Add linker FILESYSTEM section for vfs. Add per-board config for FLASH + APP sizes: * MICROPY_HW_FLASH_SIZE_BYTES * MICROPY_HW_APP_SIZE_BYTES CMake "configure_file" memmap_mp.ld.in. Signed-off-by: Phil Howard <github@gadgetoid.com>
1 parent 4998ffe commit 8f8ac1c

13 files changed

+135
-67
lines changed

ports/rp2/CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ set_source_files_properties(
549549
COMPILE_OPTIONS "-Wno-error=array-bounds;-Wno-error=unused-but-set-variable"
550550
)
551551

552+
if(NOT MICROPY_HW_ROMFS_SIZE_BYTES)
553+
set(MICROPY_HW_ROMFS_SIZE_BYTES 0)
554+
endif()
555+
552556
target_compile_definitions(${MICROPY_TARGET} PRIVATE
553557
${MICROPY_DEF_BOARD}
554558
FFCONF_H=\"${MICROPY_OOFATFS_DIR}/ffconf.h\"
@@ -562,6 +566,9 @@ target_compile_definitions(${MICROPY_TARGET} PRIVATE
562566
PICO_NO_PROGRAM_VERSION_STRING=1 # do it ourselves in main.c
563567
MICROPY_BUILD_TYPE="${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} ${CMAKE_BUILD_TYPE}"
564568
PICO_NO_BI_STDIO_UART=1 # we call it UART REPL
569+
MICROPY_HW_FLASH_SIZE_BYTES=${MICROPY_HW_FLASH_SIZE_BYTES}
570+
MICROPY_HW_APP_SIZE_BYTES=${MICROPY_HW_APP_SIZE_BYTES}
571+
MICROPY_HW_ROMFS_SIZE_BYTES=${MICROPY_HW_ROMFS_SIZE_BYTES}
565572
)
566573

567574
if(PICO_RP2040)
@@ -588,14 +595,24 @@ endif()
588595
# todo this is a bit brittle, but we want to move a few source files into RAM (which requires
589596
# a linker script modification) until we explicitly add macro calls around the function
590597
# defs to move them into RAM.
591-
if (PICO_ON_DEVICE AND NOT PICO_NO_FLASH AND NOT PICO_COPY_TO_RAM)
598+
if (NOT MICROPY_BOARD_LINKER_SCRIPT)
592599
if(PICO_RP2040)
593-
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2040.ld)
600+
set(MICROPY_BOARD_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2040.ld.in)
594601
elseif(PICO_RP2350)
595-
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2350.ld)
602+
set(MICROPY_BOARD_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2350.ld.in)
596603
endif()
597604
endif()
598605

606+
# Parse the linker file if needed, replacing ${MICROPY_HW_FLASH_SIZE_BYTES}, etc with their values
607+
if(MICROPY_BOARD_LINKER_SCRIPT MATCHES "\.in$")
608+
configure_file(${MICROPY_BOARD_LINKER_SCRIPT} ${CMAKE_CURRENT_BINARY_DIR}/memmap_mp.ld)
609+
set(MICROPY_BOARD_LINKER_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/memmap_mp.ld)
610+
endif()
611+
612+
if (MICROPY_BOARD_LINKER_SCRIPT AND PICO_ON_DEVICE AND NOT PICO_NO_FLASH AND NOT PICO_COPY_TO_RAM)
613+
pico_set_linker_script(${MICROPY_TARGET} ${MICROPY_BOARD_LINKER_SCRIPT})
614+
endif()
615+
599616
pico_add_extra_outputs(${MICROPY_TARGET})
600617

601618
pico_find_compiler_with_triples(PICO_COMPILER_SIZE "${PICO_GCC_TRIPLE}" size)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# cmake file for Raspberry Pi Pico
22
set(PICO_BOARD "pico")
33
set(PICO_PLATFORM "rp2040")
4+
5+
set(MICROPY_HW_FLASH_SIZE_BYTES "2 * 1024 * 1024")
6+
set(MICROPY_HW_APP_SIZE_BYTES "640 * 1024")
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
// Board and hardware specific configuration
22
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico"
3-
#define MICROPY_HW_FLASH_STORAGE_BYTES (1408 * 1024)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# cmake file for Raspberry Pi Pico2
22
set(PICO_BOARD "pico2")
33

4+
set(MICROPY_HW_FLASH_SIZE_BYTES "4 * 1024 * 1024")
5+
set(MICROPY_HW_APP_SIZE_BYTES "2560 * 1024")
6+
47
# To change the gpio count for QFN-80
58
# set(PICO_NUM_GPIOS 48)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
// Board and hardware specific configuration
22
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico2"
3-
#define MICROPY_HW_FLASH_STORAGE_BYTES (PICO_FLASH_SIZE_BYTES - 1024 * 1024)

ports/rp2/boards/RPI_PICO2_W/mpconfigboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Board and hardware specific configuration
22
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico 2 W"
3-
#define MICROPY_HW_FLASH_STORAGE_BYTES (PICO_FLASH_SIZE_BYTES - 1536 * 1024)
43

54
// Enable networking.
65
#define MICROPY_PY_NETWORK 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
set(PICO_PLATFORM "rp2350")
2+
3+
set(MICROPY_HW_FLASH_SIZE_BYTES "4 * 1024 * 1024")
4+
set(MICROPY_HW_APP_SIZE_BYTES "2560 * 1024")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
set(PICO_PLATFORM "rp2350-riscv")
2+
3+
set(MICROPY_HW_FLASH_SIZE_BYTES "4 * 1024 * 1024")
4+
set(MICROPY_HW_APP_SIZE_BYTES "2560 * 1024")

ports/rp2/boards/RPI_PICO_W/mpconfigboard.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
set(PICO_BOARD "pico_w")
44

5+
set(MICROPY_HW_FLASH_SIZE_BYTES "2 * 1024 * 1024")
6+
set(MICROPY_HW_APP_SIZE_BYTES "1200 * 1024")
7+
58
set(MICROPY_PY_LWIP ON)
69
set(MICROPY_PY_NETWORK_CYW43 ON)
710

ports/rp2/boards/RPI_PICO_W/mpconfigboard.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Board and hardware specific configuration
22
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico W"
33

4-
// todo: We need something to check our binary size
5-
#define MICROPY_HW_FLASH_STORAGE_BYTES (848 * 1024)
6-
74
// Enable networking.
85
#define MICROPY_PY_NETWORK 1
96
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "PicoW"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy