-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpost_build.cmake
More file actions
78 lines (70 loc) · 2.39 KB
/
post_build.cmake
File metadata and controls
78 lines (70 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
if(NOT DEFINED DEST)
message(FATAL_ERROR "post_build.cmake: DEST is not set")
endif()
if(NOT DEFINED BLD)
message(FATAL_ERROR "post_build.cmake: BLD is not set")
endif()
if(NOT DEFINED APP)
message(FATAL_ERROR "post_build.cmake: APP is not set")
endif()
if(NOT DEFINED BOARD)
set(BOARD "unknown")
endif()
file(MAKE_DIRECTORY "${DEST}")
file(GLOB OLD_BINS "${DEST}/*.bin")
if(OLD_BINS)
file(REMOVE ${OLD_BINS})
endif()
set(SRCS
"${BLD}/${APP}"
"${BLD}/bootloader/bootloader.bin"
"${BLD}/partition_table/partition-table.bin"
)
foreach(F ${SRCS})
if(EXISTS "${F}")
file(COPY "${F}" DESTINATION "${DEST}")
else()
message(WARNING "post_build.cmake: Missing file: ${F}")
endif()
endforeach()
if(DEFINED BOARD)
# Copy board-specific aliases into the output folder
if(EXISTS "${DEST}/bootloader.bin")
file(COPY_FILE "${DEST}/bootloader.bin" "${DEST}/bootloader-${BOARD}.bin")
endif()
if(EXISTS "${DEST}/partition-table.bin")
file(COPY_FILE "${DEST}/partition-table.bin" "${DEST}/partition-table-${BOARD}.bin")
endif()
if(EXISTS "${DEST}/${APP}")
file(COPY_FILE "${DEST}/${APP}" "${DEST}/M5MonsterC5-CardputerADV-${BOARD}.bin")
endif()
endif()
if(DEFINED SRC AND EXISTS "${SRC}/binaries-esp32s3/flash_board.py")
file(COPY "${SRC}/binaries-esp32s3/flash_board.py" DESTINATION "${DEST}")
endif()
set(BOOTLOADER "${BLD}/bootloader/bootloader.bin")
set(PART_TABLE "${BLD}/partition_table/partition-table.bin")
set(APP_BIN "${BLD}/${APP}")
set(FULL_OUT "${DEST}/M5MonsterC5-CardputerADV-${BOARD}-full.bin")
if(EXISTS "${BOOTLOADER}" AND EXISTS "${PART_TABLE}" AND EXISTS "${APP_BIN}")
find_program(PYTHON_EXE NAMES python3 python)
if(PYTHON_EXE)
execute_process(
COMMAND "${PYTHON_EXE}" -m esptool --chip esp32s3 merge_bin -o "${FULL_OUT}"
--flash_mode dio --flash_freq 80m --flash_size 4MB
0x0 "${BOOTLOADER}"
0x8000 "${PART_TABLE}"
0x10000 "${APP_BIN}"
RESULT_VARIABLE MERGE_RESULT
OUTPUT_VARIABLE MERGE_STDOUT
ERROR_VARIABLE MERGE_STDERR
)
if(NOT MERGE_RESULT EQUAL 0)
message(WARNING "post_build.cmake: esptool merge_bin failed (${MERGE_RESULT}). ${MERGE_STDERR}")
endif()
else()
message(WARNING "post_build.cmake: python not found; skipping full image merge.")
endif()
else()
message(WARNING "post_build.cmake: Missing input(s) for full image merge; skipping.")
endif()