I have been using a RasPi5 to compile Kilograham's "new" DOOM for the original (RP2040) Pico using the "new" SDK 2.0.0. I am using GNU 13.2 as suggested in his readme. The resulting "doom_tiny_usb.uf2" file is generating fine except it is a little too big. The binary end is 0x10042114; whereas the original DOOM using SDK 1.5.1 creates a "doom_tiny_usb.uf2" that ends at 0x10041c2c (and runs great). After loading in the game (doom1.whx) at 0x10042000, the new DOOM will "kinda" run; the graphics are fine, but the sound is very distorted. Here is the picotool output for the new program:
compared to the legacy program (also compiled with GNU 13.2):
I did a little digging into the map files and it appears that SDK 2.0.0 is adding an embedded block into the files for the RP2040. Here is portion of "doom_tiny_usb.elf.map" for the new DOOM:
compared to the legacy DOOM (with SDK 1.5.1):As you can see, the stacks end at the same spot in memory, but the extra embedded block adds an additional 628 (decimal) bytes to the "new" DOOM binary. Referring to the SDK 2.0.0 release, changes to pico_crt0; the embedded block is needed for the rp2350, but evidently not for the rp2040.
My goal is to be able to use SDK 2.0.0 regardless of platform. It probably isn't an issue for many smaller programs, but DOOM is SOOOO tight, that the problem shows up here. I don't know if it is a bug; or I'm just doing it wrong. I would appreciate any clues on how to address this issue. Thanks!
Code:
david@raspberrypi:~/pico/rp2040-doom-rp2/build_rp2040 $ cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DPICO_BOARD=vgaboard -DPICO_SDK_PATH=/home/david/pico/pico-sdk -DPICO_EXTRAS_PATH=/home/david/pico/pico-extras .....-- Build files have been written to: /home/david/pico/rp2040-doom-rp2/build_rp2040david@raspberrypi:~/pico/rp2040-doom-rp2/build_rp2040 $ make...[100%] Built target doom_tiny_nost_usbdavid@raspberrypi:~/pico/rp2040-doom-rp2/build_rp2040 $ picotool infoProgram Information name: doom_tiny_usb features: WHX at 0x10042000 USB keyboard support I2C multi-player UART stdin / stdout binary start: 0x10000000 binary end: 0x10042114david@raspberrypi:~/pico/rp2040-doom-rp2/build_rp2040 $ cd ..david@raspberrypi:~/pico/rp2040-doom-rp2 $ picotool load -v -t bin doom1.whx -o 0x10042000Loading into Flash: [==============================] 100%Verifying Flash: [==============================] 100% OK
Code:
david@raspberrypi:~/pico/rp2040-doom-rp2040/build_legacy $ cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DPICO_BOARD=vgaboard -DPICO_SDK_PATH=/home/david/pico/rp2040-doom-rp2040/pico-sdk-legacy -DPICO_EXTRAS_PATH=/home/david/pico/rp2040-doom-rp2040/pico-extras-legacy .....-- Build files have been written to: /home/david/pico/rp2040-doom-rp2040/build_legacydavid@raspberrypi:~/pico/rp2040-doom-rp2040/build_legacy $ make...[100%] Built target doom_tiny_nost_usbdavid@raspberrypi:~/pico/rp2040-doom-rp2040/build_legacy $ picotool infoProgram Information name: doom_tiny_usb features: WHX at 0x10042000 USB keyboard support I2C multi-player UART stdin / stdout binary start: 0x10000000 binary end: 0x10041c2cdavid@raspberrypi:~/pico/rp2040-doom-rp2040/build_legacy $ cd ..david@raspberrypi:~/pico/rp2040-doom-rp2040 $ picotool load -v -t bin doom1.whx -o 0x10042000Loading into Flash: [==============================] 100%Verifying Flash: [==============================] 100% OK
Code:
.stack_dummy 0x200416a0 0x800 *(.stack*) .stack 0x200416a0 0x800 CMakeFiles/doom_tiny_usb.dir/home/david/pico/pico-sdk/src/rp2_common/pico_crt0/crt0.S.obj.flash_end 0x10042114 0x0 *(.embedded_end_block*) 0x10042114 PROVIDE (__flash_binary_end = .) 0x20040000 __StackLimit = (ORIGIN (RAM) + LENGTH (RAM)) 0x20041000 __StackOneTop = (ORIGIN (SCRATCH_X) + LENGTH (SCRATCH_X)) 0x20042000 __StackTop = (ORIGIN (SCRATCH_Y) + LENGTH (SCRATCH_Y)) 0x20040b08 __StackOneBottom = (__StackOneTop - SIZEOF (.stack1_dummy)) 0x20041800 __StackBottom = (__StackTop - SIZEOF (.stack_dummy)) 0x20042000 PROVIDE (__stack = __StackTop) [!provide] PROVIDE (__heap_start = __end__) [!provide] PROVIDE (__heap_end = __HeapLimit) [!provide] PROVIDE (__tls_align = MAX (ALIGNOF (.tdata), ALIGNOF (.tbss))) [!provide] PROVIDE (__tls_size_align = (((__tls_size + __tls_align) - 0x1) & ~ ((__tls_align - 0x1)))) [!provide] PROVIDE (__arm32_tls_tcb_offset = MAX (0x8, __tls_align)) [!provide] PROVIDE (_end = __end__) [!provide] PROVIDE (__llvm_libc_heap_limit = __HeapLimit) 0x00000001 ASSERT ((__StackLimit >= __HeapLimit), region RAM overflowed) 0x00000001 ASSERT (((__binary_info_header_end - __logical_binary_start) <= 0x100), Binary info must be in first 256 bytes of the binary)
Code:
.stack_dummy 0x200416a0 0x800 *(.stack*) .stack 0x200416a0 0x800 CMakeFiles/doom_tiny_usb.dir/__/pico-sdk-legacy/src/rp2_common/pico_standard_link/crt0.S.obj.flash_end 0x10041c2c 0x0 0x10041c2c PROVIDE (__flash_binary_end = .) 0x20040000 __StackLimit = (ORIGIN (RAM) + LENGTH (RAM)) 0x20041000 __StackOneTop = (ORIGIN (SCRATCH_X) + LENGTH (SCRATCH_X)) 0x20042000 __StackTop = (ORIGIN (SCRATCH_Y) + LENGTH (SCRATCH_Y)) 0x20040b08 __StackOneBottom = (__StackOneTop - SIZEOF (.stack1_dummy)) 0x20041800 __StackBottom = (__StackTop - SIZEOF (.stack_dummy)) 0x20042000 PROVIDE (__stack = __StackTop) 0x00000001 ASSERT ((__StackLimit >= __HeapLimit), region RAM overflowed) 0x00000001 ASSERT (((__binary_info_header_end - __logical_binary_start) <= 0x100), Binary info must
I did some more digging and it looks like the linker script files for the RP2040 include the embedded block; I tried deleting them; but no joy. I also tried using the legacy crt0.S in the SDK 2.0.0, but again, no joy.Note: The linker scripts have changed since the previous release of the SDK. If you have custom linker scripts, it is recommended that you update them to match.
In particular the new linker scripts include an "embedded block" which is required for a binary to boot on RP2350.
__HeapLimit is now defined to be the end of RAM rather than the end of a PICO_HEAP_SIZE chunk, to better match the standard behaviour. PICO_HEAP_SIZE is the minimum heap size required, and space is required for it at link time. sbrk in the previous SDK ignored it anyway and used the end of RAM so there is no functional change there.
My goal is to be able to use SDK 2.0.0 regardless of platform. It probably isn't an issue for many smaller programs, but DOOM is SOOOO tight, that the problem shows up here. I don't know if it is a bug; or I'm just doing it wrong. I would appreciate any clues on how to address this issue. Thanks!
Statistics: Posted by dminderman — Sat Nov 23, 2024 2:50 pm — Replies 0 — Views 15