Merge pull request #990 from miek/fix_m0_rebuild

Fix automatic rebuilding of M0 code
This commit is contained in:
Michael Ossmann
2021-11-11 17:03:12 -07:00
committed by GitHub
3 changed files with 31 additions and 14 deletions

View File

@ -0,0 +1,4 @@
configure_file(
${SRC}
${DEST}
)

View File

@ -20,4 +20,4 @@
.data
.section .m0_bin, "ax"
.incbin "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_m0.bin"
.incbin "${BIN}"

View File

@ -117,9 +117,33 @@ include_directories("${LIBOPENCM3}/include/")
include_directories("${PATH_HACKRF_FIRMWARE_COMMON}")
macro(DeclareTarget project_name variant_suffix cflags ldflags)
add_library(${project_name}${variant_suffix}_objects OBJECT ${SRC_M4} m0_bin.s)
# Generate M0 bin from elf
add_custom_command(
OUTPUT ${project_name}${variant_suffix}_m0.bin
DEPENDS ${PROJECT_NAME}_m0.elf
COMMAND ${CMAKE_OBJCOPY} -Obinary ${PROJECT_NAME}_m0.elf ${project_name}${variant_suffix}_m0.bin
)
# Generate asm source that includes the M0 bin
add_custom_command(
OUTPUT ${project_name}${variant_suffix}_m0_bin.s
DEPENDS
${project_name}${variant_suffix}_m0.bin
${PATH_HACKRF_FIRMWARE_COMMON}/m0_bin.s.cmake
${PATH_HACKRF_FIRMWARE_COMMON}/configure_file.cmake
COMMAND
${CMAKE_COMMAND}
-DSRC=${PATH_HACKRF_FIRMWARE_COMMON}/m0_bin.s.cmake
-DDEST=${project_name}${variant_suffix}_m0_bin.s
-DBIN=${CMAKE_CURRENT_BINARY_DIR}/${project_name}${variant_suffix}_m0.bin
-P ${PATH_HACKRF_FIRMWARE_COMMON}/configure_file.cmake
# `configure_file` only updates the output if the input changed, but it can't recognise when the bin changes.
# So, force an update with `touch`
COMMAND ${CMAKE_COMMAND} -E touch ${project_name}${variant_suffix}_m0_bin.s
)
add_library(${project_name}${variant_suffix}_objects OBJECT ${SRC_M4} ${project_name}${variant_suffix}_m0_bin.s)
set_target_properties(${project_name}${variant_suffix}_objects PROPERTIES COMPILE_FLAGS "${cflags}")
add_dependencies(${project_name}${variant_suffix}_objects ${project_name}_m0.bin)
add_executable(${project_name}${variant_suffix}.elf $<TARGET_OBJECTS:${project_name}${variant_suffix}_objects>)
add_dependencies(${project_name}${variant_suffix}.elf libopencm3_${project_name})
@ -176,11 +200,6 @@ macro(DeclareTargets)
)
endif()
configure_file(
${PATH_HACKRF_FIRMWARE_COMMON}/m0_bin.s.cmake
m0_bin.s
)
link_directories(
"${PATH_HACKRF_FIRMWARE_COMMON}"
"${LIBOPENCM3}/lib"
@ -201,12 +220,6 @@ macro(DeclareTargets)
set_target_properties(${PROJECT_NAME}_m0.elf PROPERTIES COMPILE_FLAGS "${CFLAGS_M0}")
set_target_properties(${PROJECT_NAME}_m0.elf PROPERTIES LINK_FLAGS "${LDFLAGS_M0}")
add_custom_target(
${PROJECT_NAME}_m0.bin
DEPENDS ${PROJECT_NAME}_m0.elf
COMMAND ${CMAKE_OBJCOPY} -Obinary ${PROJECT_NAME}_m0.elf ${PROJECT_NAME}_m0.bin
)
DeclareTarget("${PROJECT_NAME}" "" "${CFLAGS_M4}" "${LDFLAGS_M4}")
DeclareTarget("${PROJECT_NAME}" "_ram" "${CFLAGS_M4_RAM}" "${LDFLAGS_M4_RAM}")
DeclareTarget("${PROJECT_NAME}" "_dfu" "${CFLAGS_M4_RAM} -DDFU_MODE" "${LDFLAGS_M4_RAM}")