Skip to content
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

Pico loader #877

Draft
wants to merge 70 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
8129568
pico: don't attempt picovision render before a mode is set
Daft-Freak Jul 17, 2023
bb9d7f6
Header function ptrs for pico builds too
Daft-Freak Mar 7, 2023
03b38f2
pico: output a sort-of .blit file as well as a standalone .uf2
Daft-Freak Mar 3, 2023
7d9673d
pico: pass board defs to blit builds
Daft-Freak Mar 7, 2023
3bd92b6
pico: add list_installed_games
Daft-Freak Mar 3, 2023
402e320
pico: Add some launch support
Daft-Freak Mar 3, 2023
3cf8ccd
Build launcher for pico
Daft-Freak Mar 3, 2023
6585be6
pico: some kind of basic loader
Daft-Freak Mar 6, 2023
f8cea51
HACK: disable picosystem-hardware-test
Daft-Freak Mar 7, 2023
e92536d
pico: WIP user split
Daft-Freak Mar 7, 2023
6b61002
pico: rework standalone/blit builds
Daft-Freak Mar 10, 2023
713222e
Revert "HACK: disable picosystem-hardware-test"
Daft-Freak Jul 13, 2023
2098ba3
Add an API to get screen.data to fix pico page-flipping
Daft-Freak Mar 7, 2023
d7a4adc
pico: move framebuffer allocation to the other side of teh API
Daft-Freak Mar 7, 2023
4007c26
pico: change tick in launch API
Daft-Freak Mar 7, 2023
27f5232
pico: delay launches
Daft-Freak Mar 8, 2023
a033e0f
pico: remove reset-based launch
Daft-Freak Mar 10, 2023
0d61c84
pico: refactor multiplayer code into generic CDC command handling
Daft-Freak Mar 10, 2023
090ef71
pico: CDC flash command
Daft-Freak Mar 10, 2023
dca997c
pico: move disable_user_code after render decl
Daft-Freak Mar 10, 2023
0e32044
pico: pass max hires bounds through set_framebuffer
Daft-Freak Mar 13, 2023
f7375e3
pico: clamp display width to max game was built for
Daft-Freak Mar 13, 2023
8e43e30
pico: only include PROG command if building a loader with USB in devi…
Daft-Freak Mar 14, 2023
16b891d
pico: handle metadata for blits
Daft-Freak Jul 18, 2023
b14f9e7
pico: fix save path for blits
Daft-Freak Jul 18, 2023
799f912
pico: move code related to blit files and launching to its own file
Daft-Freak Jul 27, 2023
f1bf270
pico: refactor the flash writing part of the prog command into a class
Daft-Freak Jul 29, 2023
22380c4
pico: handle launching files from storage (SD card)
Daft-Freak Jul 30, 2023
95cae8b
pico: auto install launcher from storage
Daft-Freak Jul 31, 2023
2cedc32
ci: test building pico-blits for picosystem
Daft-Freak Jul 13, 2023
169bc98
pico: don't init null command
Daft-Freak Jun 24, 2024
8fb441e
pico: allow overriding flash offset for blits
Daft-Freak Jun 24, 2024
af92890
launcher: build at a lower offset for pico
Daft-Freak Jun 24, 2024
34e2d43
pico: list games with missing metadata
Daft-Freak Jun 25, 2024
9e671a8
pico: move game block size to header
Daft-Freak Jun 25, 2024
6dfd0b6
pico: handle __LS command
Daft-Freak Jun 25, 2024
7c5fdb3
pico: move filename/size parsing buffer out of PROG command
Daft-Freak Jun 26, 2024
240935c
pico: handle LNCH command
Daft-Freak Jun 26, 2024
6a9825f
pico: refactor some helpers out of list_installed_games
Daft-Freak Jun 27, 2024
87d9880
pico: implement erase_game API
Daft-Freak Jun 27, 2024
5613f2b
pico: handle ERSE command
Daft-Freak Jun 28, 2024
10fa85e
pico: refactor cdc buffer
Daft-Freak Jun 29, 2024
a0f532f
pico: update loader linker script
Daft-Freak Sep 4, 2024
362e266
pico: fixup blit build and update linker script
Daft-Freak Sep 4, 2024
e86cdbe
pico: link blits against pico_clib_interface
Daft-Freak Sep 4, 2024
e34f89e
pico: early out from dbi update if framebuffer not set yet
Daft-Freak Sep 4, 2024
e4bd771
pico: add linker scripts for rp2530 loader/blits
Daft-Freak Sep 4, 2024
e064e4c
pico: add define for device id
Daft-Freak Sep 5, 2024
663945f
pico: add 2350 device id
Daft-Freak Sep 5, 2024
743992d
pico: use untranslated flash addr for scanning and metadata
Daft-Freak Sep 5, 2024
33669a5
Move default value for blit offset to 32blit-pico
Daft-Freak Sep 5, 2024
e511917
pico: fix indentation in BlitWriter::prepare_write
Daft-Freak Sep 5, 2024
4b78d88
pico: move helpers above api impl in blit-launch
Daft-Freak Sep 5, 2024
281fa19
pico: support .blits flashed at any offset using address translation
Daft-Freak Sep 5, 2024
565348a
pico: set default flash offset for RP2350 to 4MB
Daft-Freak Sep 5, 2024
e07d2c5
pico: invalidate cache after setting up translation
Daft-Freak Sep 6, 2024
3e8d780
pico: move fb size calcs to config.h and dedup
Daft-Freak Sep 6, 2024
0946117
pico: implement the HOME button exit/reset
Daft-Freak Sep 6, 2024
fb0eda9
pico: fix non-loader fb size
Daft-Freak Oct 22, 2024
b5aa475
pico: always use half fb size as page size
Daft-Freak Oct 30, 2024
f1d48a3
pico: rename blit-launch to blit_launch for consistency
Daft-Freak Oct 31, 2024
e12dde0
pico: avoid running pre-init code for blits
Daft-Freak Oct 31, 2024
c6353f9
pico: set our board directory as an extra search path for the SDK
Daft-Freak Nov 7, 2024
5ad2f21
pico: helper for reading file metadata
Daft-Freak Nov 11, 2024
3d42048
pico: check for existing copy of game before flashing
Daft-Freak Nov 11, 2024
55053fe
pico: cleanup duplicates after flashing new game
Daft-Freak Nov 12, 2024
aed25f7
pico: restore pre-init on RP2040
Daft-Freak Nov 26, 2024
2d1e63d
pico: use cache API to invalidate after setting up translation
Daft-Freak Dec 30, 2024
d37f1fa
pico: set flash size to 4M for 2350 blits
Daft-Freak Jan 13, 2025
243e6c7
pico: put fb in uninitialzed data
Daft-Freak Jan 13, 2025
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
8 changes: 8 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ jobs:
apt-packages: ccache gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib pipx python3-requests

- os: ubuntu-22.04
pico-sdk: true
name: PicoSystem (.blit)
cache-key: picosystem-bl
release-suffix: PicoSystem-blit
cmake-args: -D32BLIT_DIR=$GITHUB_WORKSPACE -DPICO_SDK_PATH=$GITHUB_WORKSPACE/pico-sdk -DPICO_BOARD=pimoroni_picosystem -DBLIT_EXECUTABLE_PICO_BLIT=1 -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
apt-packages: ccache gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib python3-setuptools

- os: ubuntu-20.04
pico-sdk: true
name: PicoVision
cache-key: picovision
Expand Down
38 changes: 38 additions & 0 deletions 32blit-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,60 @@ if (NOT DEFINED BLIT_ONCE)
function(blit_executable_args)
set(SOURCES)

# enable one of the pico builds if neither set
if(NOT BLIT_EXECUTABLE_PICO_STANDALONE_UF2 AND NOT BLIT_EXECUTABLE_PICO_BLIT)
set(BLIT_EXECUTABLE_PICO_STANDALONE_UF2 TRUE)
endif()

# global overrides
if(DEFINED BLIT_EXECUTABLE_INTERNAL_FLASH)
set(INTERNAL_FLASH ${BLIT_EXECUTABLE_INTERNAL_FLASH})
else()
set(INTERNAL_FLASH FALSE)
endif()

if(DEFINED BLIT_EXECUTABLE_PICO_STANDALONE_UF2)
set(PICO_STANDALONE_UF2 ${BLIT_EXECUTABLE_PICO_STANDALONE_UF2})
else()
set(PICO_STANDALONE_UF2 FALSE)
endif()

if(DEFINED BLIT_EXECUTABLE_PICO_BLIT)
set(PICO_BLIT ${BLIT_EXECUTABLE_PICO_BLIT})
else()
set(PICO_BLIT FALSE)
endif()

if(DEFINED BLIT_EXECUTABLE_PICO_BLIT_OFFSET_KB)
set(PICO_BLIT_OFFSET_KB ${BLIT_EXECUTABLE_PICO_BLIT_OFFSET_KB})
endif()

foreach(arg IN LISTS ARGN)
if(arg STREQUAL "INTERNAL_FLASH")
set(${arg} TRUE)
elseif(arg STREQUAL "PICO_STANDALONE_UF2")
set(${arg} TRUE)
set(PICO_BLIT FALSE) # can't build both
elseif(arg STREQUAL "PICO_BLIT")
set(${arg} TRUE)
set(PICO_STANDALONE_UF2 FALSE)
# args with value
elseif(arg STREQUAL "PICO_BLIT_OFFSET_KB")
set(prev_arg ${arg})
# value for args with one
elseif(prev_arg STREQUAL "PICO_BLIT_OFFSET_KB")
set(${prev_arg} ${arg})
unset(prev_arg)
else()
list(APPEND SOURCES ${arg})
endif()
endforeach()

set(SOURCES ${SOURCES} PARENT_SCOPE)
set(INTERNAL_FLASH ${INTERNAL_FLASH} PARENT_SCOPE)
set(PICO_STANDALONE_UF2 ${PICO_STANDALONE_UF2} PARENT_SCOPE)
set(PICO_BLIT ${PICO_BLIT} PARENT_SCOPE)
set(PICO_BLIT_OFFSET_KB ${PICO_BLIT_OFFSET_KB} PARENT_SCOPE)
endfunction()

if (32BLIT_HW)
Expand Down
155 changes: 136 additions & 19 deletions 32blit-pico/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ include (pico_sdk_import.cmake)

set(32BLIT_PICO 1 PARENT_SCOPE)

if(PICO_PLATFORM MATCHES "^rp2350")
set(32BLIT_PICO_2350 1)
set(32BLIT_PICO_2350 ${32BLIT_PICO_2350} PARENT_SCOPE)
endif()

# prevent find_package errors in pico_add_uf2_output later
set(PICO_SDK_VERSION_MAJOR ${PICO_SDK_VERSION_MAJOR} PARENT_SCOPE)
set(PICO_SDK_VERSION_MINOR ${PICO_SDK_VERSION_MINOR} PARENT_SCOPE)
Expand All @@ -34,11 +39,13 @@ endfunction()

add_library(BlitHalPico INTERFACE)
target_sources(BlitHalPico INTERFACE
${CMAKE_CURRENT_LIST_DIR}/blit_launch.cpp
${CMAKE_CURRENT_LIST_DIR}/display.cpp
${CMAKE_CURRENT_LIST_DIR}/file.cpp
${CMAKE_CURRENT_LIST_DIR}/led.cpp
${CMAKE_CURRENT_LIST_DIR}/main.cpp
${CMAKE_CURRENT_LIST_DIR}/multiplayer.cpp
${CMAKE_CURRENT_LIST_DIR}/usb.cpp
${CMAKE_CURRENT_LIST_DIR}/usb_descriptors.c
)

Expand All @@ -47,6 +54,7 @@ target_link_libraries(BlitHalPico INTERFACE
pico_multicore pico_stdlib pico_unique_id pico_rand
tinyusb_device
FatFsBlitAPI
LauncherShared
)

target_include_directories(BlitHalPico INTERFACE
Expand Down Expand Up @@ -170,23 +178,110 @@ endif()
target_compile_definitions(BlitHalPico INTERFACE ${BLIT_BOARD_DEFINITIONS})
target_link_libraries(BlitHalPico INTERFACE ${BLIT_BOARD_LIBRARIES})

set(BLIT_BOARD_DEFINITIONS ${BLIT_BOARD_DEFINITIONS} PARENT_SCOPE)

# some file paths we need later
if(32BLIT_PICO_2350)
set(LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/memmap_blit_2350.ld.in PARENT_SCOPE)
else()
set(LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/memmap_blit.ld.in PARENT_SCOPE)
endif()
set(STARTUP_SRC ${CMAKE_CURRENT_LIST_DIR}/startup.S ${CMAKE_CURRENT_LIST_DIR}/startup.cpp PARENT_SCOPE)
set(LAUNCHERSHARED_DIR ${CMAKE_CURRENT_LIST_DIR}/../launcher-shared PARENT_SCOPE)

# functions
function(blit_executable NAME)
message(STATUS "Processing ${NAME}")
blit_executable_args(${ARGN})

add_executable(${NAME} ${SOURCES})
target_compile_definitions(${NAME} PRIVATE PICO_EMBED_XIP_SETUP=1)
target_link_libraries(${NAME} BlitHalPico BlitEngine)
target_link_libraries(${NAME} BlitEngine pico_platform_headers)

pico_enable_stdio_uart(${NAME} 1)
pico_enable_stdio_usb(${NAME} 0)

pico_add_extra_outputs(${NAME})

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.uf2
DESTINATION bin
)
if(PICO_STANDALONE_UF2)
# standalone .uf2
# TODO: import pico hal if standalone build
if(NOT TARGET LauncherShared)
add_subdirectory(${LAUNCHERSHARED_DIR} launcher-shared)
endif()

target_compile_definitions(${NAME} PRIVATE BLIT_PICO_STANDALONE=1 PICO_EMBED_XIP_SETUP=1)
target_link_libraries(${NAME} BlitHalPico)

pico_add_extra_outputs(${NAME})

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.uf2
DESTINATION bin
)
elseif(PICO_BLIT)
# loadable .blit
set_property(TARGET ${NAME} PROPERTY BLIT_PICO_BLIT TRUE)

# calculate and verify flash offset
if(NOT PICO_BLIT_OFFSET_KB)
if(32BLIT_PICO_2350)
# if we build the file for a 4MB offset, we can use address translation
set(PICO_BLIT_OFFSET_KB 4096)
else()
set(PICO_BLIT_OFFSET_KB 512)
endif()
endif()

math(EXPR offset_mod "${PICO_BLIT_OFFSET_KB} % 64")
if(${PICO_BLIT_OFFSET_KB} LESS 256 OR offset_mod)
message(FATAL_ERROR "Blit offset should be >= 256k and a multiple of 64k")
endif()

math(EXPR FLASH_OFFSET_BYTES "${PICO_BLIT_OFFSET_KB} * 1024")

# customise linker script
configure_file(${LINKER_SCRIPT} memmap_blit.ld)
set(LINKER_SCRIPT_OUT ${CMAKE_CURRENT_BINARY_DIR}/memmap_blit.ld)

target_compile_definitions(${NAME} PRIVATE ${BLIT_BOARD_DEFINITIONS}) # need these for framebuffer config
target_compile_options(${NAME} PRIVATE -ffunction-sections -fdata-sections)

# set device id in header, these should match the BlitDevice enum
if(32BLIT_PICO_2350)
set_source_files_properties(${STARTUP_SRC} PROPERTIES COMPILE_DEFINITIONS DEVICE_ID=3)
else()
set_source_files_properties(${STARTUP_SRC} PROPERTIES COMPILE_DEFINITIONS DEVICE_ID=2)
endif()

# minimal pico-sdk libs
target_link_libraries(${NAME} boot_picobin_headers pico_bit_ops pico_clib_interface pico_cxx_options pico_divider pico_double pico_int64_ops pico_float pico_malloc pico_mem_ops pico_runtime_headers)
target_compile_definitions(${NAME} PRIVATE PICO_TIME_DEFAULT_ALARM_POOL_DISABLED) # avoid pulling timer and irq code

target_link_options(${NAME} PRIVATE --specs=nosys.specs LINKER:--script=${LINKER_SCRIPT_OUT} LINKER:--gc-sections)
set_property(TARGET ${NAME} APPEND PROPERTY LINK_DEPENDS ${LINKER_SCRIPT_OUT})

target_sources(${NAME} PRIVATE ${STARTUP_SRC})

pico_add_bin_output(${NAME})
pico_add_dis_output(${NAME})

# Ideally we want the .blit filename to match the .elf, but TARGET_FILE_BASE_NAME isn't always available
# (This only affects the firmware updater as it's the only thing setting a custom OUTPUT_NAME)
if(${CMAKE_VERSION} VERSION_LESS "3.15.0")
set(BLIT_FILENAME ${NAME}.blit)
else()
set(BLIT_FILENAME $<TARGET_FILE_BASE_NAME:${NAME}>.blit)
endif()

# no relocs, just copy it
set(BIN_NAME "$<IF:$<BOOL:$<TARGET_PROPERTY:${NAME},OUTPUT_NAME>>,$<TARGET_PROPERTY:${NAME},OUTPUT_NAME>,$<TARGET_PROPERTY:${NAME},NAME>>.bin")
add_custom_command(TARGET ${NAME} POST_BUILD
VERBATIM
COMMENT "Building ${NAME}.blit"
COMMAND cp ${BIN_NAME} ${BLIT_FILENAME}
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${BLIT_FILENAME}
DESTINATION bin
)
endif()
endfunction()

function(blit_metadata TARGET FILE)
Expand All @@ -208,20 +303,42 @@ function(blit_metadata TARGET FILE)

include(${CMAKE_CURRENT_BINARY_DIR}/metadata.cmake)

# create metadata/binary info source at build time
set(METADATA_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_binary_info.cpp")
get_property(PICO_BLIT TARGET ${TARGET} PROPERTY BLIT_PICO_BLIT)

add_custom_command(
OUTPUT ${METADATA_SOURCE}
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${32BLIT_TOOLS_EXECUTABLE} metadata --force --config ${FILE} --pico-bi ${METADATA_SOURCE}
DEPENDS ${FILE}
VERBATIM
)
if(NOT PICO_BLIT)
# create metadata/binary info source at build time
set(METADATA_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_binary_info.cpp")

# add the generated source
target_sources(${TARGET} PRIVATE ${METADATA_SOURCE})
add_custom_command(
OUTPUT ${METADATA_SOURCE}
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${32BLIT_TOOLS_EXECUTABLE} metadata --force --config ${FILE} --pico-bi ${METADATA_SOURCE}
DEPENDS ${FILE}
VERBATIM
)

# avoid the fallback to target name
target_compile_definitions(${TARGET} PRIVATE PICO_NO_BI_PROGRAM_NAME=1)
# add the generated source
target_sources(${TARGET} PRIVATE ${METADATA_SOURCE})

# avoid the fallback to target name
target_compile_definitions(${TARGET} PRIVATE PICO_NO_BI_PROGRAM_NAME=1)
else()
# real .blit metadata
if(${CMAKE_VERSION} VERSION_LESS "3.15.0")
set(BLIT_FILENAME ${TARGET}.blit)
else()
set(BLIT_FILENAME $<TARGET_FILE_BASE_NAME:${TARGET}>.blit)
endif()

add_custom_command(
TARGET ${TARGET} POST_BUILD
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${32BLIT_TOOLS_EXECUTABLE} metadata --config ${FILE} --file ${CMAKE_CURRENT_BINARY_DIR}/${BLIT_FILENAME}
VERBATIM
)

# force relink on change so that the post-build commands are rerun
set_property(TARGET ${TARGET} APPEND PROPERTY LINK_DEPENDS ${FILE} ${METADATA_DEPENDS})
endif()

endfunction()

add_subdirectory(loader)
Loading
Loading