Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

# ======================================================================
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down
22 changes: 22 additions & 0 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 21 additions & 12 deletions scripts/romfs.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
)
Expand All @@ -52,20 +54,27 @@ 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)
set(CONFIG_FS_IMAGE "${CONFIG_FS_IMAGE}" PARENT_SCOPE)

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()
Loading