Skip to content

Commit c86ea88

Browse files
authored
Merge pull request #52 from choco-technologies/copilot/update-config-directory-path
Default config directory to build/configs and auto-download config files
2 parents ab4d823 + cfb769c commit c86ea88

4 files changed

Lines changed: 45 additions & 19 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cmake_minimum_required(VERSION 3.10)
99
set(TARGET "STM32F746xG" CACHE STRING "Target microcontroller")
1010
set(STARTUP_DMP_FILE "" CACHE FILEPATH "Optional startup.dmp file to embed in ROM")
1111
set(USER_DATA_FILE "" CACHE FILEPATH "Optional user_data file to embed in ROM")
12-
set(DMBOOT_CONFIG_DIR "" CACHE PATH "Optional config directory to mount as /configs/ using dmffs")
12+
set(DMBOOT_CONFIG_DIR "${CMAKE_BINARY_DIR}/configs" CACHE PATH "Config directory to mount as /configs/ using dmffs (defaults to build/configs)")
1313
option(DMBOOT_EMULATION "Enable Renode emulation mode" OFF)
1414

1515
# ======================================================================
@@ -79,11 +79,6 @@ endif()
7979
include(scripts/romfs.cmake)
8080
if(CONFIG_FS_OBJECT)
8181
list(APPEND EMBEDDED_OBJECTS "${CONFIG_FS_OBJECT}")
82-
# Add dependency on the filesystem generation
83-
add_custom_command(
84-
OUTPUT "${CONFIG_FS_OBJECT}"
85-
DEPENDS generate_config_fs
86-
)
8782
endif()
8883

8984
# Embed modules.dmp if it exists after build

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ cmake --build build
4545
**Build Parameters:**
4646
- `STARTUP_DMP_FILE` (optional) - Path to a startup package file (`.dmp`) that will be automatically loaded using `Dmod_AddPackageBuffer` at boot
4747
- `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`
48-
- `DMBOOT_CONFIG_DIR` (optional) - Path to a directory that will be converted to a dmffs filesystem image and mounted at `/configs/` at boot time
48+
- `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.
4949
- `DMBOOT_EMULATION` (optional) - Enable Renode simulation mode instead of hardware mode
5050

5151
**Automatic Build-Time Embedding:**

modules/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@ if(EXISTS "${DMBOOT_MODULES_DMD}")
2626
else()
2727
message(WARNING "Modules DMD file not found at ${DMBOOT_MODULES_DMD}. Skipping module download.")
2828
endif()
29+
30+
# ======================================================================
31+
# Downloading configuration files from DMD
32+
# ======================================================================
33+
set(DMBOOT_CONFIGS_MARKER_FILE "${DMBOOT_CONFIG_DIR}/.download_complete")
34+
if(EXISTS "${DMBOOT_MODULES_DMD}")
35+
add_custom_command(
36+
OUTPUT "${DMBOOT_CONFIGS_MARKER_FILE}"
37+
COMMAND ${CMAKE_COMMAND} -E make_directory "${DMBOOT_CONFIG_DIR}"
38+
COMMAND ${CMAKE_COMMAND} -E echo "Downloading configuration files to ${DMBOOT_CONFIG_DIR}..."
39+
COMMAND ${DMF_GET} -d "${DMBOOT_MODULES_DMD}" -o "${DMBOOT_CONFIG_DIR}" -t "${DMOD_TOOLS_NAME}" --cpu-family "${DMBOOT_MCU_SERIES}" -y --type dmfc
40+
COMMAND ${CMAKE_COMMAND} -E touch "${DMBOOT_CONFIGS_MARKER_FILE}"
41+
DEPENDS "${DMBOOT_MODULES_DMD}"
42+
COMMENT "Downloading configuration files specified in ${DMBOOT_MODULES_DMD} from DMD..."
43+
VERBATIM
44+
)
45+
add_custom_target(download_configs ALL
46+
DEPENDS "${DMBOOT_CONFIGS_MARKER_FILE}"
47+
)
48+
else()
49+
message(WARNING "Modules DMD file not found at ${DMBOOT_MODULES_DMD}. Skipping config download.")
50+
endif()
2951

3052
# ======================================================================
3153
# Preparing dmp file from modules

scripts/romfs.cmake

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# This script sets up a ROM filesystem using dmffs and integrates it into the build
22
# It checks for the required tools, creates the ROMFS image, and embeds it into the firmware
33

4-
# Check if DMBOOT_CONFIG_DIR is set and exists
5-
if(DMBOOT_CONFIG_DIR AND EXISTS "${DMBOOT_CONFIG_DIR}")
4+
# Check if DMBOOT_CONFIG_DIR is set
5+
if(DMBOOT_CONFIG_DIR)
6+
# Create the directory if it doesn't exist
7+
file(MAKE_DIRECTORY "${DMBOOT_CONFIG_DIR}")
68
message(STATUS "Config directory specified: ${DMBOOT_CONFIG_DIR}")
79

810
# Set output path for the config filesystem image
@@ -41,8 +43,8 @@ if(DMBOOT_CONFIG_DIR AND EXISTS "${DMBOOT_CONFIG_DIR}")
4143
# Create custom command to generate the config filesystem image
4244
add_custom_command(
4345
OUTPUT "${CONFIG_FS_IMAGE}"
44-
COMMAND ${MAKE_DMFFS_COMMAND} -d "${DMBOOT_CONFIG_DIR}" -o "${CONFIG_FS_IMAGE}"
45-
DEPENDS "${DMBOOT_CONFIG_DIR}"
46+
COMMAND ${MAKE_DMFFS_COMMAND} "${DMBOOT_CONFIG_DIR}" "${CONFIG_FS_IMAGE}"
47+
DEPENDS "${DMBOOT_CONFIG_DIR}" download_configs
4648
COMMENT "Creating config filesystem image from ${DMBOOT_CONFIG_DIR}"
4749
VERBATIM
4850
)
@@ -52,20 +54,27 @@ if(DMBOOT_CONFIG_DIR AND EXISTS "${DMBOOT_CONFIG_DIR}")
5254
DEPENDS "${CONFIG_FS_IMAGE}"
5355
)
5456

55-
# Embed the config filesystem image
56-
embed_binary_file(
57-
INPUT_FILE "${CONFIG_FS_IMAGE}"
58-
SECTION_NAME ".embedded.config_fs"
59-
SYMBOL_PREFIX "__config_fs"
60-
)
61-
57+
# Create custom command to embed the config filesystem image (similar to modules.dmp approach)
6258
set(CONFIG_FS_OBJECT "${CMAKE_BINARY_DIR}/__config_fs.o")
59+
add_custom_command(
60+
OUTPUT "${CONFIG_FS_OBJECT}"
61+
COMMAND ${CMAKE_OBJCOPY}
62+
--input-target=binary
63+
--output-target=elf32-littlearm
64+
--binary-architecture=arm
65+
--rename-section .data=.embedded.config_fs,alloc,load,readonly,data,contents
66+
"${CONFIG_FS_IMAGE}"
67+
"${CONFIG_FS_OBJECT}"
68+
DEPENDS "${CONFIG_FS_IMAGE}"
69+
COMMENT "Embedding config filesystem into section .embedded.config_fs"
70+
VERBATIM
71+
)
6372

6473
# Export variables to parent scope
6574
set(CONFIG_FS_OBJECT "${CONFIG_FS_OBJECT}" PARENT_SCOPE)
6675
set(CONFIG_FS_IMAGE "${CONFIG_FS_IMAGE}" PARENT_SCOPE)
6776

6877
message(STATUS "Config filesystem will be embedded from: ${DMBOOT_CONFIG_DIR}")
6978
else()
70-
message(STATUS "No config directory specified (DMBOOT_CONFIG_DIR not set or doesn't exist)")
79+
message(STATUS "No config directory specified (DMBOOT_CONFIG_DIR not set)")
7180
endif()

0 commit comments

Comments
 (0)