Skip to content

Commit 04e5a50

Browse files
authored
Merge pull request #69 from choco-technologies/copilot/add-main-module-retrieval
Download main module via dmf-get at end of installation
2 parents 7994953 + 61bced3 commit 04e5a50

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

modules/CMakeLists.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ endif()
7777
set(DMBOOT_MODULES_OUT_DIR "${CMAKE_BINARY_DIR}/dmf")
7878
set(DMBOOT_MODULES_MARKER_FILE "${DMBOOT_MODULES_OUT_DIR}/.download_complete")
7979

80+
# Helper macro to append main module download commands to a list
81+
macro(append_main_module_download_commands LIST_VAR)
82+
if(DMBOOT_MANIFEST_URL)
83+
list(APPEND ${LIST_VAR}
84+
COMMAND ${CMAKE_COMMAND} -E echo "Downloading main module ${DMBOOT_MAIN_MODULE} (manifest: ${DMBOOT_MANIFEST_URL})..."
85+
COMMAND ${DMF_GET} ${DMBOOT_MAIN_MODULE} -m "${DMBOOT_MANIFEST_URL}" -o "${DMBOOT_MODULES_OUT_DIR}" -t "${DMOD_TOOLS_NAME}" --cpu-family "${DMBOOT_MCU_SERIES}" -y --type dmf --config-dir "${DMBOOT_CONFIG_DIR}"
86+
)
87+
else()
88+
list(APPEND ${LIST_VAR}
89+
COMMAND ${CMAKE_COMMAND} -E echo "Downloading main module ${DMBOOT_MAIN_MODULE}..."
90+
COMMAND ${DMF_GET} ${DMBOOT_MAIN_MODULE} -o "${DMBOOT_MODULES_OUT_DIR}" -t "${DMOD_TOOLS_NAME}" --cpu-family "${DMBOOT_MCU_SERIES}" -y --type dmf --config-dir "${DMBOOT_CONFIG_DIR}"
91+
)
92+
endif()
93+
endmacro()
94+
8095
if(DMBOOT_FLASH_DMD_FILES)
8196
# Build a sequence of download commands, one per flash.dmd file
8297
set(_FLASH_DOWNLOAD_COMMANDS
@@ -96,6 +111,33 @@ if(DMBOOT_FLASH_DMD_FILES)
96111
)
97112
endif()
98113
endforeach()
114+
115+
# Download main module if specified (at the end of installation),
116+
# but only if it is not already listed in any flash.dmd file
117+
if(DMBOOT_MAIN_MODULE)
118+
set(_MAIN_MODULE_IN_FLASH_DMD FALSE)
119+
foreach(_DMD_FILE IN LISTS DMBOOT_FLASH_DMD_FILES)
120+
file(STRINGS "${_DMD_FILE}" _DMD_LINES)
121+
foreach(_LINE IN LISTS _DMD_LINES)
122+
string(STRIP "${_LINE}" _LINE_STRIPPED)
123+
if(NOT _LINE_STRIPPED MATCHES "^#" AND NOT _LINE_STRIPPED STREQUAL "")
124+
if(_LINE_STRIPPED STREQUAL "${DMBOOT_MAIN_MODULE}")
125+
set(_MAIN_MODULE_IN_FLASH_DMD TRUE)
126+
break()
127+
endif()
128+
endif()
129+
endforeach()
130+
if(_MAIN_MODULE_IN_FLASH_DMD)
131+
break()
132+
endif()
133+
endforeach()
134+
if(NOT _MAIN_MODULE_IN_FLASH_DMD)
135+
append_main_module_download_commands(_FLASH_DOWNLOAD_COMMANDS)
136+
else()
137+
message(STATUS "Main module '${DMBOOT_MAIN_MODULE}' is already listed in flash.dmd, skipping explicit download")
138+
endif()
139+
endif()
140+
99141
list(APPEND _FLASH_DOWNLOAD_COMMANDS
100142
COMMAND ${CMAKE_COMMAND} -E touch "${DMBOOT_MODULES_MARKER_FILE}"
101143
)
@@ -111,6 +153,25 @@ if(DMBOOT_FLASH_DMD_FILES)
111153
DEPENDS "${DMBOOT_MODULES_MARKER_FILE}"
112154
)
113155
message(STATUS "Flash DMD files: ${DMBOOT_FLASH_DMD_FILES}")
156+
elseif(DMBOOT_MAIN_MODULE)
157+
# No flash.dmd files configured. Downloading main module only.
158+
message(STATUS "No flash.dmd files configured. Downloading main module only: ${DMBOOT_MAIN_MODULE}")
159+
set(_MAIN_MODULE_COMMANDS
160+
COMMAND ${CMAKE_COMMAND} -E make_directory "${DMBOOT_MODULES_OUT_DIR}"
161+
)
162+
append_main_module_download_commands(_MAIN_MODULE_COMMANDS)
163+
list(APPEND _MAIN_MODULE_COMMANDS
164+
COMMAND ${CMAKE_COMMAND} -E touch "${DMBOOT_MODULES_MARKER_FILE}"
165+
)
166+
add_custom_command(
167+
OUTPUT "${DMBOOT_MODULES_MARKER_FILE}"
168+
${_MAIN_MODULE_COMMANDS}
169+
COMMENT "Downloading main module: ${DMBOOT_MAIN_MODULE}"
170+
VERBATIM
171+
)
172+
add_custom_target(download_modules ALL
173+
DEPENDS "${DMBOOT_MODULES_MARKER_FILE}"
174+
)
114175
else()
115176
message(WARNING "No flash.dmd files found. Skipping flash module download.")
116177
add_custom_target(download_modules ALL)

0 commit comments

Comments
 (0)