Skip to content

Commit 707a077

Browse files
authored
add ci support (#7)
* add Bootloader cmake * add GitHub build
1 parent 8935fde commit 707a077

File tree

2 files changed

+239
-0
lines changed

2 files changed

+239
-0
lines changed

.github/workflows/build.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Build and Release Graphical Bootloader
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build-and-release:
11+
strategy:
12+
matrix:
13+
board:
14+
- { name: "ESP32-S3-BOX-3", sdkconfig: "sdkconfig.defaults.esp-box-3" }
15+
- { name: "ESP32-S3-BOX", sdkconfig: "sdkconfig.defaults.esp-box" }
16+
#- { name: "ESP32-P4", sdkconfig: "sdkconfig.defaults.esp32_p4_function_ev_board" }
17+
- { name: "M5Stack-CoreS3", sdkconfig: "sdkconfig.defaults.m5stack_core_s3" }
18+
runs-on: ubuntu-22.04
19+
container: espressif/idf:release-v5.3
20+
21+
steps:
22+
- uses: actions/checkout@v3
23+
with:
24+
submodules: 'recursive'
25+
26+
- name: Set SDKCONFIG_DEFAULTS
27+
run: echo "SDKCONFIG_DEFAULTS=${{ matrix.board.sdkconfig }}" >> $GITHUB_ENV
28+
29+
- name: Build the main application and sub-applications
30+
run: |
31+
. /opt/esp/idf/export.sh
32+
cmake -Daction=select_board -P Bootloader.cmake
33+
cmake -Daction=build_all_apps -P Bootloader.cmake
34+
35+
- name: Merge binaries into a single image
36+
run: |
37+
. /opt/esp/idf/export.sh
38+
cmake -Daction=merge_binaries -P Bootloader.cmake
39+
40+
- name: Upload binary to release
41+
uses: actions/upload-artifact@v2
42+
with:
43+
name: graphical_bootloader_${{ matrix.board.name }}
44+
path: build/combined.bin
45+
46+
release:
47+
needs: build-and-release
48+
runs-on: ubuntu-22.04
49+
steps:
50+
- name: Create Release
51+
id: create_release
52+
uses: actions/create-release@v1
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
with:
56+
tag_name: ${{ github.ref }}
57+
release_name: Release ${{ github.ref }}
58+
draft: false
59+
prerelease: false
60+
61+
- name: Upload Release Asset
62+
uses: actions/upload-release-asset@v1
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
with:
66+
upload_url: ${{ steps.create_release.outputs.upload_url }}
67+
asset_path: build/combined.bin
68+
asset_name: graphical_bootloader_${{ matrix.board.name }}.bin
69+
asset_content_type: application/octet-stream

Bootloader.cmake

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
# Function to select the board
4+
function(select_board)
5+
if(NOT DEFINED ENV{SDKCONFIG_DEFAULTS})
6+
message(FATAL_ERROR "Environment variable SDKCONFIG_DEFAULTS is not set.")
7+
else()
8+
set(SDKCONFIG_DEFAULTS $ENV{SDKCONFIG_DEFAULTS})
9+
endif()
10+
11+
message(STATUS "Using SDKCONFIG_DEFAULTS: ${SDKCONFIG_DEFAULTS}")
12+
13+
# Map SDKCONFIG_DEFAULTS to the corresponding idf_component.yml template
14+
if(SDKCONFIG_DEFAULTS STREQUAL "sdkconfig.defaults.esp-box")
15+
set(IDF_COMPONENT_YML_TEMPLATE "${CMAKE_SOURCE_DIR}/idf_component_templates/esp-box.yml")
16+
elseif(SDKCONFIG_DEFAULTS STREQUAL "sdkconfig.defaults.esp-box-3")
17+
set(IDF_COMPONENT_YML_TEMPLATE "${CMAKE_SOURCE_DIR}/idf_component_templates/esp-box-3.yml")
18+
elseif(SDKCONFIG_DEFAULTS STREQUAL "sdkconfig.defaults.m5stack_core_s3")
19+
set(IDF_COMPONENT_YML_TEMPLATE "${CMAKE_SOURCE_DIR}/idf_component_templates/m5stack_core_s3.yml")
20+
elseif(SDKCONFIG_DEFAULTS STREQUAL "sdkconfig.defaults.esp32_p4_function_ev_board")
21+
set(IDF_COMPONENT_YML_TEMPLATE "${CMAKE_SOURCE_DIR}/idf_component_templates/esp32_p4_function_ev_board.yml")
22+
else()
23+
message(FATAL_ERROR "Unsupported SDKCONFIG_DEFAULTS: ${SDKCONFIG_DEFAULTS}")
24+
endif()
25+
26+
message(STATUS "IDF_COMPONENT_YML_TEMPLATE: ${IDF_COMPONENT_YML_TEMPLATE}")
27+
28+
# Copy the appropriate idf_component.yml template to main
29+
set(IDF_COMPONENT_YML_DEST "${CMAKE_SOURCE_DIR}/main/idf_component.yml")
30+
message(STATUS "Copying ${IDF_COMPONENT_YML_TEMPLATE} to ${IDF_COMPONENT_YML_DEST}")
31+
configure_file(${IDF_COMPONENT_YML_TEMPLATE} ${IDF_COMPONENT_YML_DEST} COPYONLY)
32+
33+
# Verify that the file was copied to main
34+
if(EXISTS ${IDF_COMPONENT_YML_DEST})
35+
message(STATUS "File copied successfully to ${IDF_COMPONENT_YML_DEST}")
36+
else()
37+
message(FATAL_ERROR "Failed to copy ${IDF_COMPONENT_YML_TEMPLATE} to ${IDF_COMPONENT_YML_DEST}")
38+
endif()
39+
40+
# List of sub-applications
41+
set(SUB_APPS tic_tac_toe wifi_list calculator synth_piano game_of_life)
42+
43+
# Copy the appropriate idf_component.yml template to each sub-application
44+
foreach(APP ${SUB_APPS})
45+
set(IDF_COMPONENT_YML_DEST "${CMAKE_SOURCE_DIR}/apps/${APP}/main/idf_component.yml")
46+
message(STATUS "Copying ${IDF_COMPONENT_YML_TEMPLATE} to ${IDF_COMPONENT_YML_DEST}")
47+
configure_file(${IDF_COMPONENT_YML_TEMPLATE} ${IDF_COMPONENT_YML_DEST} COPYONLY)
48+
49+
# Verify that the file was copied to the sub-application
50+
if(EXISTS ${IDF_COMPONENT_YML_DEST})
51+
message(STATUS "File copied successfully to ${IDF_COMPONENT_YML_DEST}")
52+
else()
53+
message(FATAL_ERROR "Failed to copy ${IDF_COMPONENT_YML_TEMPLATE} to ${IDF_COMPONENT_YML_DEST}")
54+
endif()
55+
endforeach()
56+
endfunction()
57+
58+
# Function to build all applications
59+
function(build_all_apps)
60+
# Build main app
61+
message(STATUS "Building main application")
62+
execute_process(
63+
COMMAND idf.py build
64+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
65+
RESULT_VARIABLE build_main_result
66+
)
67+
if(NOT build_main_result EQUAL 0)
68+
message(FATAL_ERROR "Failed to build main application")
69+
endif()
70+
71+
# List of sub-applications
72+
set(SUB_APPS tic_tac_toe wifi_list calculator synth_piano game_of_life)
73+
74+
# Function to build each sub-application
75+
function(build_app APP)
76+
message(STATUS "Building ${APP}")
77+
execute_process(
78+
COMMAND idf.py build
79+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/apps/${APP}
80+
RESULT_VARIABLE build_result
81+
)
82+
if(NOT build_result EQUAL 0)
83+
message(FATAL_ERROR "Failed to build ${APP}")
84+
endif()
85+
endfunction()
86+
87+
# Build each sub-application
88+
foreach(APP ${SUB_APPS})
89+
build_app(${APP})
90+
endforeach()
91+
endfunction()
92+
93+
# Function to merge all binaries
94+
function(merge_binaries)
95+
# Paths to binaries
96+
set(BOOTLOADER_BIN "${CMAKE_SOURCE_DIR}/build/bootloader/bootloader.bin")
97+
set(PARTITION_TABLE_BIN "${CMAKE_SOURCE_DIR}/build/partition_table/partition-table.bin")
98+
set(MAIN_APP_BIN "${CMAKE_SOURCE_DIR}/build/esp32-graphical-bootloader.bin")
99+
set(OTA_DATA_INITIAL_BIN "${CMAKE_SOURCE_DIR}/build/ota_data_initial.bin")
100+
101+
# List of sub-applications and corresponding flash addresses
102+
set(SUB_APP_NAMES
103+
tic_tac_toe
104+
wifi_list
105+
calculator
106+
synth_piano
107+
game_of_life
108+
)
109+
110+
set(SUB_APP_ADDRS
111+
0x220000
112+
0x4E0000
113+
0x7A0000
114+
0xA60000
115+
0xD20000
116+
)
117+
118+
# Build command for esptool.py merge_bin
119+
set(MERGE_CMD esptool.py --chip esp32s3 merge_bin -o ${CMAKE_SOURCE_DIR}/build/combined.bin
120+
--flash_mode dio --flash_size 16MB
121+
0x1000 ${BOOTLOADER_BIN}
122+
0x8000 ${PARTITION_TABLE_BIN}
123+
0xf000 ${OTA_DATA_INITIAL_BIN}
124+
0x20000 ${MAIN_APP_BIN}
125+
)
126+
127+
# Append sub-application binaries and addresses
128+
list(LENGTH SUB_APP_NAMES LENGTH_SUB_APP_NAMES)
129+
math(EXPR LAST_IDX "${LENGTH_SUB_APP_NAMES} - 1")
130+
foreach(APP_IDX RANGE 0 ${LAST_IDX})
131+
list(GET SUB_APP_NAMES ${APP_IDX} APP)
132+
list(GET SUB_APP_ADDRS ${APP_IDX} ADDR)
133+
list(APPEND MERGE_CMD ${ADDR} ${CMAKE_SOURCE_DIR}/apps/${APP}/build/${APP}.bin)
134+
endforeach()
135+
136+
# Execute merge command
137+
message(STATUS "Merging binaries into combined.bin...")
138+
execute_process(
139+
COMMAND ${MERGE_CMD}
140+
RESULT_VARIABLE merge_result
141+
)
142+
if(NOT merge_result EQUAL 0)
143+
message(FATAL_ERROR "Failed to merge binaries")
144+
endif()
145+
endfunction()
146+
147+
# Function to run all steps
148+
function(build_all)
149+
select_board()
150+
build_all_apps()
151+
merge_binaries()
152+
endfunction()
153+
154+
# Entry point
155+
if(DEFINED action)
156+
message(STATUS "Action specified: ${action}")
157+
if(action STREQUAL "select_board")
158+
select_board()
159+
elseif(action STREQUAL "build_all_apps")
160+
build_all_apps()
161+
elseif(action STREQUAL "merge_binaries")
162+
merge_binaries()
163+
elseif(action STREQUAL "build_all")
164+
build_all()
165+
else()
166+
message(FATAL_ERROR "Unknown action: ${action}")
167+
endif()
168+
else()
169+
message(FATAL_ERROR "No action specified")
170+
endif()

0 commit comments

Comments
 (0)