diff --git a/CMakeLists.txt b/CMakeLists.txt index ba6740a..49abc0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ cmake_minimum_required(VERSION 3.10) set(TARGET "STM32F746xG" CACHE STRING "Target microcontroller") set(STARTUP_DMP_FILE "" CACHE FILEPATH "Optional startup.dmp file to embed in ROM") set(USER_DATA_FILE "" CACHE FILEPATH "Optional user_data file to embed in ROM") -set(DMBOOT_CONFIG_DIR "" CACHE PATH "Optional config directory to mount as /configs/ using dmffs") +set(DMBOOT_CONFIG_DIR "${CMAKE_BINARY_DIR}/configs" CACHE PATH "Config directory to mount as /configs/ using dmffs (defaults to build/configs)") option(DMBOOT_EMULATION "Enable Renode emulation mode" OFF) # ====================================================================== @@ -79,11 +79,6 @@ endif() include(scripts/romfs.cmake) if(CONFIG_FS_OBJECT) list(APPEND EMBEDDED_OBJECTS "${CONFIG_FS_OBJECT}") - # Add dependency on the filesystem generation - add_custom_command( - OUTPUT "${CONFIG_FS_OBJECT}" - DEPENDS generate_config_fs - ) endif() # Embed modules.dmp if it exists after build diff --git a/README.md b/README.md index 7eb5ed6..9d9f1b4 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ cmake --build build **Build Parameters:** - `STARTUP_DMP_FILE` (optional) - Path to a startup package file (`.dmp`) that will be automatically loaded using `Dmod_AddPackageBuffer` at boot - `USER_DATA_FILE` (optional) - Path to a user data file that will be embedded in ROM, with its address and size available via environment variables `USER_DATA_ADDR` and `USER_DATA_SIZE` -- `DMBOOT_CONFIG_DIR` (optional) - Path to a directory that will be converted to a dmffs filesystem image and mounted at `/configs/` at boot time +- `DMBOOT_CONFIG_DIR` (optional, defaults to `build/configs`) - Path to a directory that will be converted to a dmffs filesystem image and mounted at `/configs/` at boot time. By default, configuration files from `modules.dmd` are downloaded to this directory. - `DMBOOT_EMULATION` (optional) - Enable Renode simulation mode instead of hardware mode **Automatic Build-Time Embedding:** diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 214b5ae..30ef569 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -26,6 +26,28 @@ if(EXISTS "${DMBOOT_MODULES_DMD}") else() message(WARNING "Modules DMD file not found at ${DMBOOT_MODULES_DMD}. Skipping module download.") endif() + +# ====================================================================== +# Downloading configuration files from DMD +# ====================================================================== +set(DMBOOT_CONFIGS_MARKER_FILE "${DMBOOT_CONFIG_DIR}/.download_complete") +if(EXISTS "${DMBOOT_MODULES_DMD}") + add_custom_command( + OUTPUT "${DMBOOT_CONFIGS_MARKER_FILE}" + COMMAND ${CMAKE_COMMAND} -E make_directory "${DMBOOT_CONFIG_DIR}" + COMMAND ${CMAKE_COMMAND} -E echo "Downloading configuration files to ${DMBOOT_CONFIG_DIR}..." + COMMAND ${DMF_GET} -d "${DMBOOT_MODULES_DMD}" -o "${DMBOOT_CONFIG_DIR}" -t "${DMOD_TOOLS_NAME}" --cpu-family "${DMBOOT_MCU_SERIES}" -y --type dmfc + COMMAND ${CMAKE_COMMAND} -E touch "${DMBOOT_CONFIGS_MARKER_FILE}" + DEPENDS "${DMBOOT_MODULES_DMD}" + COMMENT "Downloading configuration files specified in ${DMBOOT_MODULES_DMD} from DMD..." + VERBATIM + ) + add_custom_target(download_configs ALL + DEPENDS "${DMBOOT_CONFIGS_MARKER_FILE}" + ) +else() + message(WARNING "Modules DMD file not found at ${DMBOOT_MODULES_DMD}. Skipping config download.") +endif() # ====================================================================== # Preparing dmp file from modules diff --git a/scripts/romfs.cmake b/scripts/romfs.cmake index 9011b85..4b2d09a 100644 --- a/scripts/romfs.cmake +++ b/scripts/romfs.cmake @@ -1,8 +1,10 @@ # This script sets up a ROM filesystem using dmffs and integrates it into the build # It checks for the required tools, creates the ROMFS image, and embeds it into the firmware -# Check if DMBOOT_CONFIG_DIR is set and exists -if(DMBOOT_CONFIG_DIR AND EXISTS "${DMBOOT_CONFIG_DIR}") +# Check if DMBOOT_CONFIG_DIR is set +if(DMBOOT_CONFIG_DIR) + # Create the directory if it doesn't exist + file(MAKE_DIRECTORY "${DMBOOT_CONFIG_DIR}") message(STATUS "Config directory specified: ${DMBOOT_CONFIG_DIR}") # Set output path for the config filesystem image @@ -41,8 +43,8 @@ if(DMBOOT_CONFIG_DIR AND EXISTS "${DMBOOT_CONFIG_DIR}") # Create custom command to generate the config filesystem image add_custom_command( OUTPUT "${CONFIG_FS_IMAGE}" - COMMAND ${MAKE_DMFFS_COMMAND} -d "${DMBOOT_CONFIG_DIR}" -o "${CONFIG_FS_IMAGE}" - DEPENDS "${DMBOOT_CONFIG_DIR}" + COMMAND ${MAKE_DMFFS_COMMAND} "${DMBOOT_CONFIG_DIR}" "${CONFIG_FS_IMAGE}" + DEPENDS "${DMBOOT_CONFIG_DIR}" download_configs COMMENT "Creating config filesystem image from ${DMBOOT_CONFIG_DIR}" VERBATIM ) @@ -52,14 +54,21 @@ if(DMBOOT_CONFIG_DIR AND EXISTS "${DMBOOT_CONFIG_DIR}") DEPENDS "${CONFIG_FS_IMAGE}" ) - # Embed the config filesystem image - embed_binary_file( - INPUT_FILE "${CONFIG_FS_IMAGE}" - SECTION_NAME ".embedded.config_fs" - SYMBOL_PREFIX "__config_fs" - ) - + # Create custom command to embed the config filesystem image (similar to modules.dmp approach) set(CONFIG_FS_OBJECT "${CMAKE_BINARY_DIR}/__config_fs.o") + add_custom_command( + OUTPUT "${CONFIG_FS_OBJECT}" + COMMAND ${CMAKE_OBJCOPY} + --input-target=binary + --output-target=elf32-littlearm + --binary-architecture=arm + --rename-section .data=.embedded.config_fs,alloc,load,readonly,data,contents + "${CONFIG_FS_IMAGE}" + "${CONFIG_FS_OBJECT}" + DEPENDS "${CONFIG_FS_IMAGE}" + COMMENT "Embedding config filesystem into section .embedded.config_fs" + VERBATIM + ) # Export variables to parent scope set(CONFIG_FS_OBJECT "${CONFIG_FS_OBJECT}" PARENT_SCOPE) @@ -67,5 +76,5 @@ if(DMBOOT_CONFIG_DIR AND EXISTS "${DMBOOT_CONFIG_DIR}") message(STATUS "Config filesystem will be embedded from: ${DMBOOT_CONFIG_DIR}") else() - message(STATUS "No config directory specified (DMBOOT_CONFIG_DIR not set or doesn't exist)") + message(STATUS "No config directory specified (DMBOOT_CONFIG_DIR not set)") endif() \ No newline at end of file