From e0bf376068ac7f103b0d663460ca9371152e6e0f Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 30 Mar 2023 20:36:52 +0200 Subject: [PATCH] rp2040: unify all linker scripts using LDFLAGS The only thing that's different between all these chips is the flash size, which can easily be passed as a linker flag instead. This removes a bunch of duplicate code in an uncommon language (linker script). I've also fixed a few boards with incorrect flash sizes: * nano-rp2040 has 16MB instead of 2MB * macropad-rp2040 has 8MB instead of 2MB * gopher-badge has 8MB instead of 1MB --- targets/badger2040.json | 4 +++- targets/badger2040.ld | 10 ---------- targets/challenger-rp2040.json | 4 +++- targets/feather-rp2040.json | 4 +++- targets/feather-rp2040.ld | 10 ---------- targets/gopher-badge.json | 4 +++- targets/gopher-badge.ld | 10 ---------- targets/kb2040.json | 4 +++- targets/macropad-rp2040.json | 4 +++- targets/nano-rp2040.json | 4 +++- targets/pico.json | 4 +++- targets/pico.ld | 10 ---------- targets/qtpy-rp2040.json | 4 +++- targets/qtpy-rp2040.ld | 10 ---------- targets/rp2040.json | 1 + targets/rp2040.ld | 7 +++++++ targets/thingplus-rp2040.json | 4 +++- targets/thingplus-rp2040.ld | 10 ---------- targets/trinkey-qt2040.json | 4 +++- targets/trinkey-qt2040.ld | 10 ---------- targets/tufty2040.json | 4 +++- targets/tufty2040.ld | 10 ---------- targets/waveshare-rp2040-zero.json | 4 +++- targets/waveshare-rp2040-zero.ld | 10 ---------- targets/xiao-rp2040.json | 4 +++- targets/xiao-rp2040.ld | 10 ---------- 26 files changed, 50 insertions(+), 114 deletions(-) delete mode 100644 targets/badger2040.ld delete mode 100644 targets/feather-rp2040.ld delete mode 100644 targets/gopher-badge.ld delete mode 100644 targets/pico.ld delete mode 100644 targets/qtpy-rp2040.ld delete mode 100644 targets/thingplus-rp2040.ld delete mode 100644 targets/trinkey-qt2040.ld delete mode 100644 targets/tufty2040.ld delete mode 100644 targets/waveshare-rp2040-zero.ld delete mode 100644 targets/xiao-rp2040.ld diff --git a/targets/badger2040.json b/targets/badger2040.json index d325bd06..34eef117 100644 --- a/targets/badger2040.json +++ b/targets/badger2040.json @@ -4,7 +4,9 @@ ], "serial-port": ["2e8a:0003"], "build-tags": ["badger2040"], - "linkerscript": "targets/badger2040.ld", + "ldflags": [ + "--defsym=__flash_size=1020K" + ], "extra-files": [ "targets/pico-boot-stage2.S" ] diff --git a/targets/badger2040.ld b/targets/badger2040.ld deleted file mode 100644 index 7e06d7a0..00000000 --- a/targets/badger2040.ld +++ /dev/null @@ -1,10 +0,0 @@ - -MEMORY -{ - /* Reserve exactly 256 bytes at start of flash for second stage bootloader */ - BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256 - FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = 1020K - 256 - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} - -INCLUDE "targets/rp2040.ld" diff --git a/targets/challenger-rp2040.json b/targets/challenger-rp2040.json index 28591db2..6d187e77 100644 --- a/targets/challenger-rp2040.json +++ b/targets/challenger-rp2040.json @@ -4,7 +4,9 @@ ], "serial-port": ["2e8a:1023"], "build-tags": ["challenger_rp2040"], - "linkerscript": "targets/feather-rp2040.ld", + "ldflags": [ + "--defsym=__flash_size=8M" + ], "extra-files": [ "targets/feather-rp2040-boot-stage2.S" ] diff --git a/targets/feather-rp2040.json b/targets/feather-rp2040.json index 5409f89b..871cdb45 100644 --- a/targets/feather-rp2040.json +++ b/targets/feather-rp2040.json @@ -4,7 +4,9 @@ ], "serial-port": ["239a:80f1"], "build-tags": ["feather_rp2040"], - "linkerscript": "targets/feather-rp2040.ld", + "ldflags": [ + "--defsym=__flash_size=8192K" + ], "extra-files": [ "targets/feather-rp2040-boot-stage2.S" ] diff --git a/targets/feather-rp2040.ld b/targets/feather-rp2040.ld deleted file mode 100644 index d97942f5..00000000 --- a/targets/feather-rp2040.ld +++ /dev/null @@ -1,10 +0,0 @@ - -MEMORY -{ - /* Reserve exactly 256 bytes at start of flash for second stage bootloader */ - BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256 - FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = 8192K - 256 - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} - -INCLUDE "targets/rp2040.ld" \ No newline at end of file diff --git a/targets/gopher-badge.json b/targets/gopher-badge.json index 8bf4f0c9..ec50b303 100644 --- a/targets/gopher-badge.json +++ b/targets/gopher-badge.json @@ -4,7 +4,9 @@ ], "serial-port": ["2e8a:0003"], "build-tags": ["gopher_badge"], - "linkerscript": "targets/gopher-badge.ld", + "ldflags": [ + "--defsym=__flash_size=8M" + ], "extra-files": [ "targets/pico-boot-stage2.S" ] diff --git a/targets/gopher-badge.ld b/targets/gopher-badge.ld deleted file mode 100644 index 7e06d7a0..00000000 --- a/targets/gopher-badge.ld +++ /dev/null @@ -1,10 +0,0 @@ - -MEMORY -{ - /* Reserve exactly 256 bytes at start of flash for second stage bootloader */ - BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256 - FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = 1020K - 256 - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} - -INCLUDE "targets/rp2040.ld" diff --git a/targets/kb2040.json b/targets/kb2040.json index ce9360f5..1fc045b5 100644 --- a/targets/kb2040.json +++ b/targets/kb2040.json @@ -4,7 +4,9 @@ ], "serial-port": ["239a:8106"], "build-tags": ["kb2040"], - "linkerscript": "targets/qtpy-rp2040.ld", + "ldflags": [ + "--defsym=__flash_size=8192K" + ], "extra-files": [ "targets/qtpy-rp2040-boot-stage2.S" ] diff --git a/targets/macropad-rp2040.json b/targets/macropad-rp2040.json index 027657bd..59db5b2a 100644 --- a/targets/macropad-rp2040.json +++ b/targets/macropad-rp2040.json @@ -4,7 +4,9 @@ ], "build-tags": ["macropad_rp2040"], "serial-port": ["239a:8107"], - "linkerscript": "targets/pico.ld", + "ldflags": [ + "--defsym=__flash_size=8M" + ], "extra-files": [ "targets/macropad-rp2040-boot-stage2.S" ] diff --git a/targets/nano-rp2040.json b/targets/nano-rp2040.json index f1623dfe..313fead9 100644 --- a/targets/nano-rp2040.json +++ b/targets/nano-rp2040.json @@ -4,7 +4,9 @@ ], "serial-port": ["2341:005e"], "build-tags": ["nano_rp2040"], - "linkerscript": "targets/pico.ld", + "ldflags": [ + "--defsym=__flash_size=16M" + ], "extra-files": [ "targets/pico-boot-stage2.S" ] diff --git a/targets/pico.json b/targets/pico.json index 984b9287..88aec23d 100644 --- a/targets/pico.json +++ b/targets/pico.json @@ -4,7 +4,9 @@ ], "build-tags": ["pico"], "serial-port": ["2e8a:000A"], - "linkerscript": "targets/pico.ld", + "ldflags": [ + "--defsym=__flash_size=2048K" + ], "extra-files": [ "targets/pico-boot-stage2.S" ] diff --git a/targets/pico.ld b/targets/pico.ld deleted file mode 100644 index 6ef32a3c..00000000 --- a/targets/pico.ld +++ /dev/null @@ -1,10 +0,0 @@ - -MEMORY -{ - /* Reserve exactly 256 bytes at start of flash for second stage bootloader */ - BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256 - FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = 2048K - 256 - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} - -INCLUDE "targets/rp2040.ld" diff --git a/targets/qtpy-rp2040.json b/targets/qtpy-rp2040.json index 0a53accc..394d83aa 100644 --- a/targets/qtpy-rp2040.json +++ b/targets/qtpy-rp2040.json @@ -4,7 +4,9 @@ ], "serial-port": ["239a:80f7"], "build-tags": ["qtpy_rp2040"], - "linkerscript": "targets/qtpy-rp2040.ld", + "ldflags": [ + "--defsym=__flash_size=8192K" + ], "extra-files": [ "targets/qtpy-rp2040-boot-stage2.S" ] diff --git a/targets/qtpy-rp2040.ld b/targets/qtpy-rp2040.ld deleted file mode 100644 index d97942f5..00000000 --- a/targets/qtpy-rp2040.ld +++ /dev/null @@ -1,10 +0,0 @@ - -MEMORY -{ - /* Reserve exactly 256 bytes at start of flash for second stage bootloader */ - BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256 - FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = 8192K - 256 - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} - -INCLUDE "targets/rp2040.ld" \ No newline at end of file diff --git a/targets/rp2040.json b/targets/rp2040.json index f4dc8c04..99a568a7 100644 --- a/targets/rp2040.json +++ b/targets/rp2040.json @@ -12,6 +12,7 @@ "extra-files": [ "src/device/rp/rp2040.s" ], + "linkerscript": "targets/rp2040.ld", "openocd-interface": "picoprobe", "openocd-transport": "swd", "openocd-target": "rp2040" diff --git a/targets/rp2040.ld b/targets/rp2040.ld index 5aa57ce6..118735e3 100644 --- a/targets/rp2040.ld +++ b/targets/rp2040.ld @@ -1,3 +1,10 @@ +MEMORY +{ + /* Reserve exactly 256 bytes at start of flash for second stage bootloader */ + BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256 + FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = __flash_size - 256 + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k +} _stack_size = 2K; diff --git a/targets/thingplus-rp2040.json b/targets/thingplus-rp2040.json index dfd71ad3..6718b86d 100644 --- a/targets/thingplus-rp2040.json +++ b/targets/thingplus-rp2040.json @@ -4,7 +4,9 @@ ], "serial-port": ["1b4f:0026"], "build-tags": ["thingplus_rp2040"], - "linkerscript": "targets/thingplus-rp2040.ld", + "ldflags": [ + "--defsym=__flash_size=16M" + ], "extra-files": [ "targets/pico-boot-stage2.S" ] diff --git a/targets/thingplus-rp2040.ld b/targets/thingplus-rp2040.ld deleted file mode 100644 index 5e49f3b8..00000000 --- a/targets/thingplus-rp2040.ld +++ /dev/null @@ -1,10 +0,0 @@ - -MEMORY -{ - /* Reserve exactly 256 bytes at start of flash for second stage bootloader */ - BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256 - FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = 16384K - 256 - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} - -INCLUDE "targets/rp2040.ld" \ No newline at end of file diff --git a/targets/trinkey-qt2040.json b/targets/trinkey-qt2040.json index 3678085d..23ae3f6c 100644 --- a/targets/trinkey-qt2040.json +++ b/targets/trinkey-qt2040.json @@ -4,7 +4,9 @@ ], "serial-port": ["239a:8109"], "build-tags": ["trinkey_qt2040"], - "linkerscript": "targets/trinkey-qt2040.ld", + "ldflags": [ + "--defsym=__flash_size=8192K" + ], "extra-files": [ "targets/trinkey-qt2040-boot-stage2.S" ] diff --git a/targets/trinkey-qt2040.ld b/targets/trinkey-qt2040.ld deleted file mode 100644 index d97942f5..00000000 --- a/targets/trinkey-qt2040.ld +++ /dev/null @@ -1,10 +0,0 @@ - -MEMORY -{ - /* Reserve exactly 256 bytes at start of flash for second stage bootloader */ - BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256 - FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = 8192K - 256 - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} - -INCLUDE "targets/rp2040.ld" \ No newline at end of file diff --git a/targets/tufty2040.json b/targets/tufty2040.json index 5534e4be..11c4e334 100644 --- a/targets/tufty2040.json +++ b/targets/tufty2040.json @@ -4,7 +4,9 @@ ], "serial-port": ["2e8a:0003"], "build-tags": ["tufty2040"], - "linkerscript": "targets/tufty2040.ld", + "ldflags": [ + "--defsym=__flash_size=1020K" + ], "extra-files": [ "targets/pico-boot-stage2.S" ] diff --git a/targets/tufty2040.ld b/targets/tufty2040.ld deleted file mode 100644 index 7e06d7a0..00000000 --- a/targets/tufty2040.ld +++ /dev/null @@ -1,10 +0,0 @@ - -MEMORY -{ - /* Reserve exactly 256 bytes at start of flash for second stage bootloader */ - BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256 - FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = 1020K - 256 - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} - -INCLUDE "targets/rp2040.ld" diff --git a/targets/waveshare-rp2040-zero.json b/targets/waveshare-rp2040-zero.json index 878969af..a31c4e84 100644 --- a/targets/waveshare-rp2040-zero.json +++ b/targets/waveshare-rp2040-zero.json @@ -4,7 +4,9 @@ ], "serial-port": ["2e8a:0003"], "build-tags": ["waveshare_rp2040_zero"], - "linkerscript": "targets/waveshare-rp2040-zero.ld", + "ldflags": [ + "--defsym=__flash_size=1020K" + ], "extra-files": [ "targets/pico-boot-stage2.S" ] diff --git a/targets/waveshare-rp2040-zero.ld b/targets/waveshare-rp2040-zero.ld deleted file mode 100644 index 7e06d7a0..00000000 --- a/targets/waveshare-rp2040-zero.ld +++ /dev/null @@ -1,10 +0,0 @@ - -MEMORY -{ - /* Reserve exactly 256 bytes at start of flash for second stage bootloader */ - BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256 - FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = 1020K - 256 - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} - -INCLUDE "targets/rp2040.ld" diff --git a/targets/xiao-rp2040.json b/targets/xiao-rp2040.json index ce967ad0..02a36c06 100644 --- a/targets/xiao-rp2040.json +++ b/targets/xiao-rp2040.json @@ -4,7 +4,9 @@ ], "serial-port": ["2e8a:000a"], "build-tags": ["xiao_rp2040"], - "linkerscript": "targets/xiao-rp2040.ld", + "ldflags": [ + "--defsym=__flash_size=1020K" + ], "extra-files": [ "targets/pico-boot-stage2.S" ] diff --git a/targets/xiao-rp2040.ld b/targets/xiao-rp2040.ld deleted file mode 100644 index 7e06d7a0..00000000 --- a/targets/xiao-rp2040.ld +++ /dev/null @@ -1,10 +0,0 @@ - -MEMORY -{ - /* Reserve exactly 256 bytes at start of flash for second stage bootloader */ - BOOT2_TEXT (rx) : ORIGIN = 0x10000000, LENGTH = 256 - FLASH_TEXT (rx) : ORIGIN = 0x10000000 + 256, LENGTH = 1020K - 256 - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k -} - -INCLUDE "targets/rp2040.ld"