@@ -51,8 +51,10 @@ if(NOT MATCH_INDEX EQUAL -1)
5151 )
5252endif ()
5353
54+ # Read flash_args file at build time and create combined.bin
5455add_custom_command (TARGET app POST_BUILD
55- COMMAND bash ${CMAKE_BINARY_DIR} /tinyuf2.postbuild.sh
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)"
5658 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
5759 VERBATIM
5860 )
@@ -81,9 +83,23 @@ add_custom_target(combined-flash
8183# External project (update_tinyuf2, blinky etc ...)
8284#------------------------------
8385
84- # Post build: generate bootloader_bin .c for update-tinyuf2 and combined.bin
85- add_custom_command ( TARGET app POST_BUILD
86+ # Generate bootloader_bin.c and partition_table_bin .c as custom targets before external projects
87+ add_custom_target ( generate_bootloader_bin
8688 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+ "
102+ DEPENDS tinyuf2.elf
87103 )
88104
89105externalproject_add (update-tinyuf2
@@ -94,7 +110,7 @@ externalproject_add(update-tinyuf2
94110 CMAKE_ARGS -DBOARD=${BOARD}
95111 INSTALL_COMMAND ""
96112 BUILD_ALWAYS 1
97- DEPENDS tinyuf2.elf
113+ DEPENDS generate_bootloader_bin
98114 )
99115
100116externalproject_add (blinky
0 commit comments