@@ -21,9 +21,10 @@ include(ExternalProject)
2121# The build will output a TARGET.bin file which can be written using picotool, and a
2222# TARGET.uf2 file which can be dragged and dropped onto the device in BOOTSEL mode
2323function (add_universal_target TARGET SOURCE )
24+ set (zeroValueArgs SEPARATE_RP2040)
2425 set (oneValueArgs SOURCE_TARGET PADDING PACKADDR BOARD_RP2040 BOARD_RP2350)
2526 set (multiValueArgs PLATFORMS)
26- cmake_parse_arguments (PARSE_ARGV 2 PARSED "" "${oneValueArgs} " "${multiValueArgs} " )
27+ cmake_parse_arguments (PARSE_ARGV 2 PARSED "${zeroValueArgs} " "${oneValueArgs} " "${multiValueArgs} " )
2728
2829 set (SOURCE_TARGET ${TARGET} )
2930 if (PARSED_SOURCE_TARGET)
@@ -107,13 +108,35 @@ function (add_universal_target TARGET SOURCE)
107108 message (FATAL_ERROR "Cannot link universal binary without picotool" )
108109 endif ()
109110
110- # Link the binaries for different platforms into a single block loop, with
111- # appropriate rolling window deltas. This creates a universal binary file,
112- # which will run on any of the platforms when loaded using picotool.
113- add_custom_target (${TARGET} _combined
114- COMMAND picotool link ${COMBINED} ${BINS} --pad ${PADDING}
115- DEPENDS ${DEPS}
116- )
111+ list (FIND PLATFORMS "rp2040" idx)
112+ if (idx EQUAL 0 AND PARSED_SEPARATE_RP2040)
113+ # Don't include RP2040 bin in the combined BIN, just include it in the RP2040 UF2
114+ # POP_FRONT only added in CMake 3.15, so use GET and REMOVE_AT instead
115+ list (GET BINS 0 RP2040_BIN)
116+ list (REMOVE_AT BINS 0)
117+ set (RP2040_COMBINED ${RP2040_BIN} )
118+ else ()
119+ set (RP2040_COMBINED ${COMBINED} )
120+ endif ()
121+
122+ list (LENGTH BINS BINS_COUNT)
123+ if (BINS_COUNT GREATER 1)
124+ # Link the binaries for different platforms into a single block loop, with
125+ # appropriate rolling window deltas. This creates a universal binary file,
126+ # which will run on any of the platforms when loaded using picotool.
127+ add_custom_target (${TARGET} _combined
128+ COMMAND picotool link ${COMBINED} ${BINS} --pad ${PADDING}
129+ DEPENDS ${DEPS}
130+ )
131+ else ()
132+ # Only one binary left, so no picotool link is needed - just copy instead
133+ # This could be the case if only building for rp2040 and rp2350-arm-s,
134+ # with SEPARATE_RP2040 set
135+ add_custom_target (${TARGET} _combined
136+ COMMAND ${CMAKE_COMMAND} -E copy ${BINS} ${COMBINED}
137+ DEPENDS ${DEPS}
138+ )
139+ endif ()
117140
118141 # Create UF2s targeting the absolute and rp2040 family IDs, then combine these
119142 # into a single universal UF2. This is required as there isn't a single family
@@ -124,7 +147,7 @@ function (add_universal_target TARGET SOURCE)
124147 DEPENDS ${TARGET} _combined
125148 )
126149 add_custom_target (${TARGET} _rp2040_uf2
127- COMMAND picotool uf2 convert ${COMBINED } ${BINDIR} /rp2040.uf2 --family rp2040 --offset ${PACKADDR}
150+ COMMAND picotool uf2 convert ${RP2040_COMBINED } ${BINDIR} /rp2040.uf2 --family rp2040 --offset ${PACKADDR}
128151 DEPENDS ${TARGET} _combined
129152 )
130153 add_custom_target (${TARGET} _uf2
@@ -146,7 +169,7 @@ add_universal_target(blink_universal
146169 SOURCE_TARGET blink_universal
147170 BOARD_RP2040 universal
148171 BOARD_RP2350 universal
149- PLATFORMS "rp2040;rp2350-arm-s" # Skip RISC-V, as wifi firmware takes up lots of space
172+ SEPARATE_RP2040 PLATFORMS "rp2040;rp2350-arm-s" # Skip RISC-V and keep RP2040 separate , as wifi firmware takes up lots of space
150173 )
151174
152175# nuke binary - is no_flash, so needs to be sent to SRAM on RP2040
0 commit comments