Skip to content

Commit 855bdb4

Browse files
Add program target for romfs image in CMake
1 parent fd9e6e5 commit 855bdb4

3 files changed

Lines changed: 54 additions & 15 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (C) 2024 by Skyward
2+
#
3+
# This program is free software; you can redistribute it and/or
4+
# it under the terms of the GNU General Public License as published
5+
# the Free Software Foundation; either version 2 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# As a special exception, if other files instantiate templates or use
14+
# macros or inline functions from this file, or you compile this file
15+
# and link it with other works to produce a work based on this file,
16+
# this file does not by itself cause the resulting work to be covered
17+
# by the GNU General Public License. However the source code for this
18+
# file must still be made available in accordance with the GNU
19+
# Public License. This exception does not invalidate any other
20+
# why a work based on this file might be covered by the GNU General
21+
# Public License.
22+
#
23+
# You should have received a copy of the GNU General Public License
24+
# along with this program; if not, see <http://www.gnu.org/licenses/>
25+
26+
# Creates a custom target to program the board
27+
#
28+
# miosix_add_program_target(<target> [DEPENDS <target1> <target2> ...])
29+
#
30+
function(miosix_add_program_target TARGET)
31+
cmake_parse_arguments(PROGRAM "" "" "DEPENDS" ${ARGN})
32+
33+
if(NOT PROGRAM_DEPENDS)
34+
set(PROGRAM_DEPENDS ${TARGET}_bin ${TARGET}_hex)
35+
endif()
36+
37+
get_target_property(PROGRAM_CMDLINE miosix PROGRAM_CMDLINE)
38+
if(PROGRAM_CMDLINE STREQUAL "PROGRAM_CMDLINE-NOTFOUND")
39+
set(PROGRAM_CMDLINE st-flash --connect-under-reset --reset write <binary> 0x8000000)
40+
endif()
41+
42+
list(TRANSFORM PROGRAM_CMDLINE REPLACE <binary> ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.bin)
43+
list(TRANSFORM PROGRAM_CMDLINE REPLACE <hex> ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.hex)
44+
45+
add_custom_target(${TARGET}_program ${PROGRAM_CMDLINE}
46+
DEPENDS ${PROGRAM_DEPENDS}
47+
VERBATIM
48+
)
49+
endfunction()

miosix/cmake/AddRomfsImage.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# along with this program; if not, see <http://www.gnu.org/licenses/>
2525

2626
include(ExternalProject)
27+
include(AddProgramTarget)
2728
include(CreateProcessesDir)
2829

2930
# Create a target that builds the buildromfs tool
@@ -79,4 +80,7 @@ function(miosix_add_romfs_image)
7980

8081
# Create the custom romfs target
8182
add_custom_target(${ROMFS_IMAGE_NAME} ALL DEPENDS ${PROJECT_BINARY_DIR}/${ROMFS_IMAGE_NAME}.bin)
83+
84+
# And a target to flash the image
85+
miosix_add_program_target(${ROMFS_IMAGE_NAME} TARGETS ${ROMFS_IMAGE_NAME})
8286
endfunction()

miosix/cmake/LinkTarget.cmake

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,7 @@
2323
# You should have received a copy of the GNU General Public License
2424
# along with this program; if not, see <http://www.gnu.org/licenses/>
2525

26-
# Creates a custom target to program the board
27-
function(miosix_add_program_target TARGET)
28-
get_target_property(PROGRAM_CMDLINE miosix PROGRAM_CMDLINE)
29-
if(PROGRAM_CMDLINE STREQUAL "PROGRAM_CMDLINE-NOTFOUND")
30-
set(PROGRAM_CMDLINE st-flash --connect-under-reset --reset write <binary> 0x8000000)
31-
endif()
32-
33-
list(TRANSFORM PROGRAM_CMDLINE REPLACE <binary> ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.bin)
34-
list(TRANSFORM PROGRAM_CMDLINE REPLACE <hex> ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.hex)
35-
36-
add_custom_target(${TARGET}_program ${PROGRAM_CMDLINE}
37-
DEPENDS ${TARGET}_bin ${TARGET}_hex
38-
VERBATIM
39-
)
40-
endfunction()
26+
include(AddProgramTarget)
4127

4228
# Function to link the Miosix libraries to a target and register the build command
4329
#

0 commit comments

Comments
 (0)