Skip to content

ports/rp2: Per-board linker scripts to avoid producing self-corrupting builds. #8761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions ports/rp2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,10 @@ set_source_files_properties(
COMPILE_OPTIONS "-Wno-error=array-bounds;-Wno-error=unused-but-set-variable"
)

if(NOT MICROPY_HW_ROMFS_SIZE_BYTES)
set(MICROPY_HW_ROMFS_SIZE_BYTES 0)
endif()

target_compile_definitions(${MICROPY_TARGET} PRIVATE
${MICROPY_DEF_BOARD}
FFCONF_H=\"${MICROPY_OOFATFS_DIR}/ffconf.h\"
Expand All @@ -562,6 +566,9 @@ target_compile_definitions(${MICROPY_TARGET} PRIVATE
PICO_NO_PROGRAM_VERSION_STRING=1 # do it ourselves in main.c
MICROPY_BUILD_TYPE="${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} ${CMAKE_BUILD_TYPE}"
PICO_NO_BI_STDIO_UART=1 # we call it UART REPL
MICROPY_HW_FLASH_SIZE_BYTES=${MICROPY_HW_FLASH_SIZE_BYTES}
MICROPY_HW_APP_SIZE_BYTES=${MICROPY_HW_APP_SIZE_BYTES}
MICROPY_HW_ROMFS_SIZE_BYTES=${MICROPY_HW_ROMFS_SIZE_BYTES}
)

if(PICO_RP2040)
Expand All @@ -578,6 +585,10 @@ target_link_libraries(${MICROPY_TARGET}
${PICO_SDK_COMPONENTS}
)

target_link_options(${MICROPY_TARGET} PRIVATE
-Wl,--print-memory-usage
)

if (MICROPY_HW_ENABLE_DOUBLE_TAP)
# Enable double tap reset into bootrom.
target_link_libraries(${MICROPY_TARGET}
Expand All @@ -588,14 +599,24 @@ endif()
# todo this is a bit brittle, but we want to move a few source files into RAM (which requires
# a linker script modification) until we explicitly add macro calls around the function
# defs to move them into RAM.
if (PICO_ON_DEVICE AND NOT PICO_NO_FLASH AND NOT PICO_COPY_TO_RAM)
if (NOT MICROPY_BOARD_LINKER_SCRIPT)
if(PICO_RP2040)
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2040.ld)
set(MICROPY_BOARD_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2040.ld.in)
elseif(PICO_RP2350)
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2350.ld)
set(MICROPY_BOARD_LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/memmap_mp_rp2350.ld.in)
endif()
endif()

# Parse the linker file if needed, replacing ${MICROPY_HW_FLASH_SIZE_BYTES}, etc with their values
if(MICROPY_BOARD_LINKER_SCRIPT MATCHES "\.in$")
configure_file(${MICROPY_BOARD_LINKER_SCRIPT} ${CMAKE_CURRENT_BINARY_DIR}/memmap_mp.ld)
set(MICROPY_BOARD_LINKER_SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/memmap_mp.ld)
endif()

if (MICROPY_BOARD_LINKER_SCRIPT AND PICO_ON_DEVICE AND NOT PICO_NO_FLASH AND NOT PICO_COPY_TO_RAM)
pico_set_linker_script(${MICROPY_TARGET} ${MICROPY_BOARD_LINKER_SCRIPT})
endif()

pico_add_extra_outputs(${MICROPY_TARGET})

pico_find_compiler_with_triples(PICO_COMPILER_SIZE "${PICO_GCC_TRIPLE}" size)
Expand Down
3 changes: 3 additions & 0 deletions ports/rp2/boards/RPI_PICO/mpconfigboard.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# cmake file for Raspberry Pi Pico
set(PICO_BOARD "pico")
set(PICO_PLATFORM "rp2040")

set(MICROPY_HW_FLASH_SIZE_BYTES "2 * 1024 * 1024")
set(MICROPY_HW_APP_SIZE_BYTES "640 * 1024")
1 change: 0 additions & 1 deletion ports/rp2/boards/RPI_PICO/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// Board and hardware specific configuration
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico"
#define MICROPY_HW_FLASH_STORAGE_BYTES (1408 * 1024)
3 changes: 3 additions & 0 deletions ports/rp2/boards/RPI_PICO2/mpconfigboard.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# cmake file for Raspberry Pi Pico2
set(PICO_BOARD "pico2")

set(MICROPY_HW_FLASH_SIZE_BYTES "4 * 1024 * 1024")
set(MICROPY_HW_APP_SIZE_BYTES "2560 * 1024")

# To change the gpio count for QFN-80
# set(PICO_NUM_GPIOS 48)
1 change: 0 additions & 1 deletion ports/rp2/boards/RPI_PICO2/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// Board and hardware specific configuration
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico2"
#define MICROPY_HW_FLASH_STORAGE_BYTES (PICO_FLASH_SIZE_BYTES - 1024 * 1024)
1 change: 0 additions & 1 deletion ports/rp2/boards/RPI_PICO2_W/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Board and hardware specific configuration
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico 2 W"
#define MICROPY_HW_FLASH_STORAGE_BYTES (PICO_FLASH_SIZE_BYTES - 1536 * 1024)

// Enable networking.
#define MICROPY_PY_NETWORK 1
Expand Down
3 changes: 3 additions & 0 deletions ports/rp2/boards/RPI_PICO2_W/mpconfigvariant.cmake
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
set(PICO_PLATFORM "rp2350")

set(MICROPY_HW_FLASH_SIZE_BYTES "4 * 1024 * 1024")
set(MICROPY_HW_APP_SIZE_BYTES "2560 * 1024")
3 changes: 3 additions & 0 deletions ports/rp2/boards/RPI_PICO2_W/mpconfigvariant_RISCV.cmake
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
set(PICO_PLATFORM "rp2350-riscv")

set(MICROPY_HW_FLASH_SIZE_BYTES "4 * 1024 * 1024")
set(MICROPY_HW_APP_SIZE_BYTES "2560 * 1024")
3 changes: 3 additions & 0 deletions ports/rp2/boards/RPI_PICO_W/mpconfigboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set(PICO_BOARD "pico_w")

set(MICROPY_HW_FLASH_SIZE_BYTES "2 * 1024 * 1024")
set(MICROPY_HW_APP_SIZE_BYTES "1200 * 1024")

set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)

Expand Down
3 changes: 0 additions & 3 deletions ports/rp2/boards/RPI_PICO_W/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Board and hardware specific configuration
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico W"

// todo: We need something to check our binary size
#define MICROPY_HW_FLASH_STORAGE_BYTES (848 * 1024)

// Enable networking.
#define MICROPY_PY_NETWORK 1
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "PicoW"
Expand Down
52 changes: 36 additions & 16 deletions ports/rp2/memmap_mp_rp2040.ld → ports/rp2/memmap_mp_rp2040.ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,32 @@
__stack (== StackTop)
*/

/* Default RP2 flash size. Assumes no user filesystem. */
_micropy_hw_internal_flash_storage_start = 0x10000000;
_micropy_hw_internal_flash_storage_size_bytes = ${MICROPY_HW_FLASH_SIZE_BYTES};
_micropy_hw_internal_flash_storage_end = _micropy_hw_internal_flash_storage_start + _micropy_hw_internal_flash_storage_size_bytes;

_micropy_hw_application_start = _micropy_hw_internal_flash_storage_start;
_micropy_hw_application_size_bytes = ${MICROPY_HW_APP_SIZE_BYTES};
_micropy_hw_application_end = _micropy_hw_application_start + _micropy_hw_application_size_bytes;

_micropy_hw_romfs_start = _micropy_hw_internal_flash_storage_start + _micropy_hw_application_size_bytes;
_micropy_hw_romfs_size_bytes = ${MICROPY_HW_ROMFS_SIZE_BYTES};
_micropy_hw_romfs_end = _micropy_hw_romfs_start + _micropy_hw_romfs_size_bytes;

_micropy_hw_filesystem_start = _micropy_hw_internal_flash_storage_start + _micropy_hw_application_size_bytes + _micropy_hw_romfs_size_bytes;
_micropy_hw_filesystem_size_bytes = _micropy_hw_internal_flash_storage_size_bytes - _micropy_hw_application_size_bytes - _micropy_hw_romfs_size_bytes;
_micropy_hw_filesystem_end = _micropy_hw_filesystem_start + _micropy_hw_filesystem_size_bytes;

MEMORY
{
FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2048k
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
FLASH(rx) : ORIGIN = _micropy_hw_internal_flash_storage_start, LENGTH = _micropy_hw_internal_flash_storage_size_bytes
APP(rx) : ORIGIN = _micropy_hw_application_start, LENGTH = _micropy_hw_application_size_bytes
ROMFS(rx) : ORIGIN = _micropy_hw_romfs_start, LENGTH = _micropy_hw_romfs_size_bytes
FILESYSTEM(r) : ORIGIN = _micropy_hw_filesystem_start, LENGTH = _micropy_hw_filesystem_size_bytes
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
}

ENTRY(_entry_point)
Expand All @@ -40,13 +60,13 @@ SECTIONS

.flash_begin : {
__flash_binary_start = .;
} > FLASH
} > APP

.boot2 : {
__boot2_start__ = .;
KEEP (*(.boot2))
__boot2_end__ = .;
} > FLASH
} > APP

ASSERT(__boot2_end__ - __boot2_start__ == 256,
"ERROR: Pico second stage bootloader must be 256 bytes in size")
Expand All @@ -66,7 +86,7 @@ SECTIONS
KEEP (*(.reset))
/* TODO revisit this now memset/memcpy/float in ROM */
/* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from
* FLASH ... we will include any thing excluded here in .data below by default */
* flash ... we will include any thing excluded here in .data below by default */
*(.init)
/* Change for MicroPython... exclude gc.c, parse.c, vm.c from flash */
*(EXCLUDE_FILE(*libgcc.a: *libc.a: *lib_a-mem*.o *libm.a: *gc.c.obj *vm.c.obj *parse.c.obj) .text*)
Expand All @@ -86,25 +106,25 @@ SECTIONS

*(.eh_frame*)
. = ALIGN(4);
} > FLASH
} > APP

.rodata : {
*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*)
. = ALIGN(4);
*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*)))
. = ALIGN(4);
} > FLASH
} > APP

.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH
} > APP

__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
} > APP
__exidx_end = .;

/* Machine inspectable binary information */
Expand All @@ -114,7 +134,7 @@ SECTIONS
{
KEEP(*(.binary_info.keep.*))
*(.binary_info.*)
} > FLASH
} > APP
__binary_info_end = .;
. = ALIGN(4);

Expand Down Expand Up @@ -173,7 +193,7 @@ SECTIONS
. = ALIGN(4);
/* All data end */
__data_end__ = .;
} > RAM AT> FLASH
} > RAM AT> APP

.uninitialized_data (COPY): {
. = ALIGN(4);
Expand All @@ -192,15 +212,15 @@ SECTIONS
*(.scratch_x.*)
. = ALIGN(4);
__scratch_x_end__ = .;
} > SCRATCH_X AT > FLASH
} > SCRATCH_X AT > APP
__scratch_x_source__ = LOADADDR(.scratch_x);

.scratch_y : {
__scratch_y_start__ = .;
*(.scratch_y.*)
. = ALIGN(4);
__scratch_y_end__ = .;
} > SCRATCH_Y AT > FLASH
} > SCRATCH_Y AT > APP
__scratch_y_source__ = LOADADDR(.scratch_y);

.bss : {
Expand Down Expand Up @@ -240,7 +260,7 @@ SECTIONS

.flash_end : {
__flash_binary_end = .;
} > FLASH
} > APP

/* stack limit is poorly named, but historically is maximum heap ptr */
__StackLimit = __bss_end__ + __micropy_c_heap_size__;
Expand Down
Loading
Loading
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