Skip to content

Commit 61b051a

Browse files
committed
espressif: generate combined.bin and combined_ota.bin (for 4MB board) as post_build, copy artifacts as post_build.
1 parent d4722ff commit 61b051a

File tree

5 files changed

+53
-35
lines changed

5 files changed

+53
-35
lines changed

.github/workflows/build_util.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
5959
- name: Build using ESP-IDF docker
6060
if: inputs.toolchain == 'esp-idf'
61-
run: docker run --rm -v $PWD:/project -w /project espressif/idf:${{ inputs.toolchain_version }} /bin/bash -c "git config --global --add safe.directory /project && make -C ports/espressif/ BOARD=${{ matrix.board }} all copy-artifact"
61+
run: docker run --rm -v $PWD:/project -w /project espressif/idf:${{ inputs.toolchain_version }} /bin/bash -c "git config --global --add safe.directory /project && idf.py -C ports/espressif -DBOARD=${{ matrix.board }} build"
6262

6363
- uses: actions/upload-artifact@v4
6464
with:

.github/workflows/ci_set_matrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def set_matrix_json():
1818
if b.is_dir():
1919
matrix[p.name]['board'].append(b.name)
2020
# For quick testing by only build 1 espressif board
21-
#if p.name == 'espressif':
22-
# break
21+
if p.name == 'espressif':
22+
break
2323
print(json.dumps(matrix))
2424

2525

ports/espressif/CMakeLists.txt

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,67 @@ add_compile_definitions(
2828
UF2_VERSION_BASE="${GIT_VERSION}"
2929
UF2_VERSION="${GIT_VERSION} - ${GIT_SUBMODULE_VERSIONS}"
3030
)
31-
3231
cmake_print_variables(GIT_VERSION GIT_SUBMODULE_VERSIONS)
3332

3433
project(tinyuf2)
3534

3635
# Post build: generate bootloader_bin.c for self-update and combined.bin
37-
add_custom_command(TARGET app POST_BUILD
36+
add_custom_command(TARGET tinyuf2.elf POST_BUILD
3837
COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} --carray -o ${CMAKE_CURRENT_LIST_DIR}/apps/self_update/main/bootloader_bin.c ${CMAKE_BINARY_DIR}/tinyuf2.bin
3938
)
4039

40+
add_custom_command(TARGET tinyuf2.elf POST_BUILD
41+
BYPRODUCTS ${CMAKE_BINARY_DIR}/combined.bin
42+
COMMAND ${CMAKE_COMMAND} -E echo "Creating combined.bin"
43+
COMMAND bash -c "esptool.py --chip ${IDF_TARGET} merge_bin --output combined.bin $(tr '\\n' ' ' < ${CMAKE_BINARY_DIR}/flash_args)"
44+
VERBATIM
45+
)
46+
47+
## Post build: copy binaries for artifact
48+
set(ARTIFACT_PATH ${CMAKE_CURRENT_LIST_DIR}/_bin/${BOARD})
49+
add_custom_command(TARGET tinyuf2.elf POST_BUILD
50+
COMMAND ${CMAKE_COMMAND} -E echo "Copy binaries for artifact"
51+
COMMAND mkdir -p ${ARTIFACT_PATH}
52+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bootloader/bootloader.bin ${ARTIFACT_PATH}/bootloader.bin
53+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/ota_data_initial.bin ${ARTIFACT_PATH}/ota_data_initial.bin
54+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/partition_table/partition-table.bin ${ARTIFACT_PATH}/partition-table.bin
55+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/tinyuf2.bin ${ARTIFACT_PATH}/tinyuf2.bin
56+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/combined.bin ${ARTIFACT_PATH}/combined.bin
57+
VERBATIM
58+
)
59+
60+
# check if board is 4MB flash and create combined-ota.bin
61+
file(READ ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/sdkconfig BOARD_SDKCONFIG_CONTENTS)
62+
string(FIND ${BOARD_SDKCONFIG_CONTENTS} "partitions-4MB-noota.csv" MATCH_INDEX)
63+
if(NOT MATCH_INDEX EQUAL -1)
64+
add_custom_command(TARGET tinyuf2.elf POST_BUILD
65+
BYPRODUCTS ${CMAKE_BINARY_DIR}/combined_ota.bin
66+
COMMAND ${CMAKE_COMMAND} -E echo "Creating combined_ota.bin"
67+
COMMAND gen_esp32part.py ${CMAKE_CURRENT_LIST_DIR}/partitions-4MB.csv ${CMAKE_BINARY_DIR}/partition_table/partitions-table-4MB-ota.bin
68+
COMMAND bash -c "esptool.py --chip ${IDF_TARGET} merge_bin --output combined_ota.bin $(tr '\\n' ' ' < ${CMAKE_BINARY_DIR}/flash_args | sed 's/partition-table.bin/partitions-table-4MB-ota.bin/g')"
69+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/combined_ota.bin ${ARTIFACT_PATH}/combined_ota.bin
70+
VERBATIM
71+
)
72+
endif()
73+
4174
# External project for self-update
4275
externalproject_add(self_update
4376
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/apps/self_update
4477
BINARY_DIR ${CMAKE_BINARY_DIR}/self_update
45-
# Modiying the list separator for the arguments, as such, we won't need to manually
78+
# Modifying the list separator for the arguments, as such, we won't need to manually
4679
# replace the new separator by the default ';' in the subproject
4780
CMAKE_ARGS -DBOARD=${BOARD}
4881
INSTALL_COMMAND ""
4982
BUILD_ALWAYS 1
50-
DEPENDS app
83+
DEPENDS tinyuf2.elf
84+
)
85+
86+
# flash combined.bin
87+
add_custom_target(combined-flash
88+
DEPENDS tinyuf2.elf
89+
COMMAND ${CMAKE_COMMAND} -E echo "Flashing combined.bin"
90+
COMMAND esptool.py --chip ${IDF_TARGET} write_flash 0x0 combined.bin
91+
VERBATIM
5192
)
5293

5394
# -------------------------------------------------------------
@@ -61,7 +102,7 @@ if (0)
61102
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bootloader/bootloader.bin ${ARDUINO_VARIANT_DIR}/bootloader-tinyuf2.bin
62103
)
63104

64-
add_custom_command(TARGET app POST_BUILD
105+
add_custom_command(TARGET tinyuf2.elf POST_BUILD
65106
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/tinyuf2.bin ${ARDUINO_VARIANT_DIR}/tinyuf2.bin
66107
)
67108
endif ()

ports/espressif/Makefile

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
.PHONY: all build clean flash monitor erase
44
.DEFAULT_GOAL := all
55

6-
# Set default python interpreters
7-
PYTHON3 ?= python3
8-
96
# Build directory
107
BUILD = _build/$(BOARD)
118
BIN = _bin/$(BOARD)
@@ -15,9 +12,6 @@ ifdef SERIAL
1512
SERIAL_OPT = --port $(SERIAL)
1613
endif
1714

18-
UF2_FAMILY_ID_esp32s2 = 0xbfdd4eee
19-
UF2_FAMILY_ID_esp32s3 = 0xc47e5767
20-
2115
BOARD_CMAKE := $(file < boards/$(BOARD)/board.cmake)
2216
ifneq ($(findstring esp32s2,$(BOARD_CMAKE)),)
2317
IDF_TARGET = esp32s2
@@ -40,31 +34,12 @@ fullclean:
4034
app bootloader clean flash bootloader-flash app-flash erase-flash monitor dfu-flash dfu size size-components size-files:
4135
idf.py -B$(BUILD) -DBOARD=$(BOARD) $(SERIAL_OPT) $@
4236

43-
combined.bin: $(BUILD)/combined.bin
44-
37+
# combined.bin is POST build step, generated by cmake app target
4538
$(BUILD)/combined.bin: app
46-
cd $(BUILD); \
47-
esptool.py --chip $(IDF_TARGET) merge_bin --output combined.bin $(strip $(file < $(BUILD)/flash_args))
48-
4939
combined-flash: $(BUILD)/combined.bin
5040
esptool.py --chip $(IDF_TARGET) write_flash 0x0 $<
5141

52-
#-------------- Self Update --------------
5342
# Self_update is a sub/external project, will be built by cmake's all target
5443
SELF_BUILD = ${BUILD}/self_update
5544

56-
#-------------- Artifacts --------------
57-
$(BIN):
58-
@mkdir -p $@
59-
60-
# get the partition csv from sdkconfig
61-
PARTITION_CSV := $(strip $(foreach csv,$(wildcard partitions-*.csv),$(findstring $(csv),$(file < boards/$(BOARD)/sdkconfig))))
62-
63-
copy-artifact: $(BIN) all $(BUILD)/combined.bin
64-
@cp $(BUILD)/bootloader/bootloader.bin $<
65-
@cp $(BUILD)/partition_table/partition-table.bin $<
66-
@cp $(BUILD)/ota_data_initial.bin $<
67-
@cp $(BUILD)/tinyuf2.bin $<
68-
@cp $(BUILD)/combined.bin $<
69-
@cp $(SELF_BUILD)/update-tinyuf2.uf2 $<
70-
@cp $(PARTITION_CSV) $<
45+
# Artifacts is generated as Cmake post build

ports/espressif/apps/self_update/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ add_compile_definitions(TINYUF2_SELF_UPDATE)
1616

1717
project(update-tinyuf2)
1818

19+
set(ARTIFACT_PATH ${CMAKE_CURRENT_LIST_DIR}/../../_bin/${BOARD})
1920
add_custom_command(TARGET app POST_BUILD
2021
COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${UF2_FAMILY_ID_${IDF_TARGET}} -b 0x0 -c -o ${CMAKE_BINARY_DIR}/update-tinyuf2.uf2 ${CMAKE_BINARY_DIR}/update-tinyuf2.bin
22+
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/update-tinyuf2.uf2 ${ARTIFACT_PATH}/update-tinyuf2.uf2
2123
VERBATIM
2224
)
2325

0 commit comments

Comments
 (0)