Skip to content

Commit

Permalink
ci: add option to build UF2 image
Browse files Browse the repository at this point in the history
  • Loading branch information
georgik committed Jul 18, 2024
1 parent 8943a9a commit 4b9974b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
58 changes: 57 additions & 1 deletion Bootloader.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function(build_all_apps)
endforeach()
endfunction()

# Function to merge all binaries
# Function to merge all binaries into a single .bin file
function(merge_binaries)
# Paths to binaries
set(BOOTLOADER_BIN "${CMAKE_SOURCE_DIR}/build/bootloader/bootloader.bin")
Expand Down Expand Up @@ -144,6 +144,60 @@ function(merge_binaries)
endif()
endfunction()

# Function to merge all binaries into a single UF2 file
function(merge_binaries_uf2)
# Paths to binaries
set(BOOTLOADER_BIN "${CMAKE_SOURCE_DIR}/build/bootloader/bootloader.bin")
set(PARTITION_TABLE_BIN "${CMAKE_SOURCE_DIR}/build/partition_table/partition-table.bin")
set(MAIN_APP_BIN "${CMAKE_SOURCE_DIR}/build/esp32-graphical-bootloader.bin")
set(OTA_DATA_INITIAL_BIN "${CMAKE_SOURCE_DIR}/build/ota_data_initial.bin")

# List of sub-applications and corresponding flash addresses
set(SUB_APP_NAMES
tic_tac_toe
wifi_list
calculator
synth_piano
game_of_life
)

set(SUB_APP_ADDRS
0x220000
0x4E0000
0x7A0000
0xA60000
0xD20000
)

# Build command for esptool.py merge_bin with UF2 format
set(MERGE_CMD esptool.py --chip esp32s3 merge_bin --format uf2 -o ${CMAKE_SOURCE_DIR}/build/uf2.bin
--flash_mode dio --flash_size 16MB
0x0 ${BOOTLOADER_BIN}
0x8000 ${PARTITION_TABLE_BIN}
0xf000 ${OTA_DATA_INITIAL_BIN}
0x20000 ${MAIN_APP_BIN}
)

# Append sub-application binaries and addresses
list(LENGTH SUB_APP_NAMES LENGTH_SUB_APP_NAMES)
math(EXPR LAST_IDX "${LENGTH_SUB_APP_NAMES} - 1")
foreach(APP_IDX RANGE 0 ${LAST_IDX})
list(GET SUB_APP_NAMES ${APP_IDX} APP)
list(GET SUB_APP_ADDRS ${APP_IDX} ADDR)
list(APPEND MERGE_CMD ${ADDR} ${CMAKE_SOURCE_DIR}/apps/${APP}/build/${APP}.bin)
endforeach()

# Execute merge command
message(STATUS "Merging binaries into uf2.bin...")
execute_process(
COMMAND ${MERGE_CMD}
RESULT_VARIABLE merge_result
)
if(NOT merge_result EQUAL 0)
message(FATAL_ERROR "Failed to merge binaries into UF2")
endif()
endfunction()

# Function to run all steps
function(build_all)
select_board()
Expand All @@ -160,6 +214,8 @@ if(DEFINED action)
build_all_apps()
elseif(action STREQUAL "merge_binaries")
merge_binaries()
elseif(action STREQUAL "merge_binaries_uf2")
merge_binaries_uf2()
elseif(action STREQUAL "build_all")
build_all()
else()
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ The following command merges all applications into UF2 format:

```shell
esptool.py --chip esp32s3 merge_bin --format uf2 -o build/uf2.bin --flash_mode dio --flash_size 16MB \
0x10000 build/esp32-graphical-bootloader.bin \
0x0 build/bootloader/bootloader.bin \
0x8000 build/partition_table/partition-table.bin \
0xf000 build/ota_data_initial.bin \
0x20000 build/esp32-graphical-bootloader.bin \
0x220000 apps/tic_tac_toe/build/tic_tac_toe.bin \
0x4E0000 apps/wifi_list/build/wifi_list.bin \
0x7A0000 apps/calculator/build/calculator.bin \
Expand All @@ -93,7 +96,7 @@ esptool.py --chip esp32s3 merge_bin --format uf2 -o build/uf2.bin --flash_mode d

The following command merges all applications into binary image format:
```shell
esptool.py --chip esp32s3 merge_bin -o build/all.bin --flash_mode dio --flash_size 16MB \
esptool.py --chip esp32s3 merge_bin -o build/combined.bin --flash_mode dio --flash_size 16MB \
0x0 build/bootloader/bootloader.bin \
0x8000 build/partition_table/partition-table.bin \
0xf000 build/ota_data_initial.bin \
Expand All @@ -108,7 +111,7 @@ esptool.py --chip esp32s3 merge_bin -o build/all.bin --flash_mode dio --flash_s
The single binary can be flashed by command:

```shell
esptool.py --chip esp32s3 --baud 921600 write_flash 0x0000 build/all.bin
esptool.py --chip esp32s3 --baud 921600 write_flash 0x0000 build/combined.bin
```

## Build
Expand Down

0 comments on commit 4b9974b

Please sign in to comment.