Skip to content

Commit 81ff612

Browse files
committed
Partiton table self updating
1 parent 39eb99f commit 81ff612

12 files changed

Lines changed: 12782 additions & 63 deletions

ports/espressif/CMakeLists.txt

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,8 @@ cmake_print_variables(GIT_VERSION GIT_SUBMODULE_VERSIONS)
3131

3232
project(tinyuf2)
3333

34-
# Create post-build script for combined.bin / combined-ota.bin
35-
file(WRITE ${CMAKE_BINARY_DIR}/tinyuf2.postbuild.sh
36-
"#!/bin/bash\n"
37-
"echo \"Creating combined.bin\"\n"
38-
"esptool.py --chip ${IDF_TARGET} merge_bin --output combined.bin $(tr '\\n' ' ' < ${CMAKE_BINARY_DIR}/flash_args)\n"
39-
)
40-
41-
# check if board is 4MB flash and create combined-ota.bin
42-
file(READ ${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/sdkconfig BOARD_SDKCONFIG_CONTENTS)
43-
string(FIND ${BOARD_SDKCONFIG_CONTENTS} "partitions-4MB-noota.csv" MATCH_INDEX)
44-
if(NOT MATCH_INDEX EQUAL -1)
45-
file(APPEND ${CMAKE_BINARY_DIR}/tinyuf2.postbuild.sh
46-
"echo \"Creating combined-ota.bin\"\n"
47-
"gen_esp32part.py ${CMAKE_CURRENT_LIST_DIR}/partitions-4MB.csv ${CMAKE_BINARY_DIR}/partition_table/partitions-table-ota.bin\n"
48-
"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-ota.bin/g')\n"
49-
"cp ${CMAKE_BINARY_DIR}/partition_table/partitions-table-ota.bin ${ARTIFACT_PATH}/partitions-table-ota.bin\n"
50-
"cp combined-ota.bin ${ARTIFACT_PATH}/combined-ota.bin\n"
51-
)
52-
endif()
53-
54-
# Read flash_args file at build time and create combined.bin
5534
add_custom_command(TARGET app POST_BUILD
56-
COMMAND ${CMAKE_COMMAND} -E echo "Creating combined.bin"
57-
COMMAND ${Python_EXECUTABLE} -c "import subprocess, os; content = open('flash_args', 'r').read().replace('\\n', ' '); cmd = ['python', '-m', 'esptool', '--chip', '${IDF_TARGET}', 'merge_bin', '--output', 'combined.bin'] + content.split(); subprocess.run(cmd, env=os.environ)"
5835
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
59-
VERBATIM
6036
)
6137

6238
# Post build: copy binaries for artifact
@@ -67,15 +43,6 @@ add_custom_command(TARGET app POST_BUILD
6743
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/ota_data_initial.bin ${ARTIFACT_PATH}/ota_data_initial.bin
6844
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/partition_table/partition-table.bin ${ARTIFACT_PATH}/partition-table.bin
6945
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/tinyuf2.bin ${ARTIFACT_PATH}/tinyuf2.bin
70-
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/combined.bin ${ARTIFACT_PATH}/combined.bin
71-
VERBATIM
72-
)
73-
74-
# flash combined.bin
75-
add_custom_target(combined-flash
76-
DEPENDS tinyuf2.elf
77-
COMMAND ${CMAKE_COMMAND} -E echo "Flashing combined.bin"
78-
COMMAND esptool.py --chip ${IDF_TARGET} write_flash 0x0 combined.bin
7946
VERBATIM
8047
)
8148

@@ -86,19 +53,7 @@ add_custom_target(combined-flash
8653
# Generate bootloader_bin.c and partition_table_bin.c as custom targets before external projects
8754
add_custom_target(generate_bootloader_bin
8855
COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} --carray -o ${CMAKE_CURRENT_LIST_DIR}/apps/update_tinyuf2/main/bootloader_bin.c ${CMAKE_BINARY_DIR}/tinyuf2.bin
89-
COMMAND ${Python_EXECUTABLE} -c "
90-
import sys
91-
with open('${CMAKE_BINARY_DIR}/partition_table/partition-table.bin', 'rb') as f:
92-
data = f.read()
93-
with open('${CMAKE_CURRENT_LIST_DIR}/apps/update_tinyuf2/main/partition_table_bin.c', 'w') as f:
94-
f.write('const unsigned long partition_table_len = %d;\\n' % len(data))
95-
f.write('const unsigned char partition_table[] __attribute__((aligned(16))) = {')
96-
for i in range(len(data)):
97-
if i % 16 == 0:
98-
f.write('\\n')
99-
f.write('0x%02x, ' % data[i])
100-
f.write('\\n};\\n')
101-
"
56+
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/generate_partition_array.py ${CMAKE_BINARY_DIR}/partition_table/partition-table.bin ${CMAKE_CURRENT_LIST_DIR}/apps/update_tinyuf2/main/partition_table_bin.c
10257
DEPENDS tinyuf2.elf
10358
)
10459

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
dependencies:
2+
idf:
3+
source:
4+
type: idf
5+
version: 5.3.1
6+
direct_dependencies:
7+
- idf
8+
manifest_hash: f2643a0d45a12f85533cb52f8fc47a42c229fb4b9e95d0568fd637d4b3bb3ba3
9+
target: esp32s3
10+
version: 2.0.0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
dependencies:
2+
idf:
3+
source:
4+
type: idf
5+
version: 5.3.1
6+
direct_dependencies:
7+
- idf
8+
manifest_hash: f2643a0d45a12f85533cb52f8fc47a42c229fb4b9e95d0568fd637d4b3bb3ba3
9+
target: esp32s3
10+
version: 2.0.0
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Note: bootloader_bin.c is generated by tinyuf2 app target
2-
idf_component_register(SRCS ${TOP}/apps/self_update/self_update.c bootloader_bin.c
1+
# Note: bootloader_bin.c and partition_table_bin.c are generated by tinyuf2 app target
2+
idf_component_register(SRCS ${TOP}/apps/self_update/self_update.c bootloader_bin.c partition_table_bin.c
33
INCLUDE_DIRS ${TOP}/src
44
REQUIRES boards)

0 commit comments

Comments
 (0)