2019-04-22 20:39:48 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2021-12-16 13:55:09 +01:00
|
|
|
#
|
|
|
|
# Copyright (c) 2021, Nordic Semiconductor ASA
|
2019-04-22 20:39:48 +02:00
|
|
|
|
2021-12-16 13:55:09 +01:00
|
|
|
# Validate board and setup boards target.
|
|
|
|
#
|
|
|
|
# This CMake module will validate the BOARD argument as well as splitting the
|
|
|
|
# BOARD argument into <BOARD> and <BOARD_REVISION>.
|
|
|
|
#
|
|
|
|
# If a board implementation is not found for the specified board an error will
|
|
|
|
# be raised and list of valid boards will be printed.
|
|
|
|
#
|
|
|
|
# If user provided board is a board alias, the board will be adjusted to real
|
|
|
|
# board name.
|
|
|
|
#
|
|
|
|
# If board name is deprecated, then board will be adjusted to new board name and
|
|
|
|
# a deprecation warning will be printed to the user.
|
|
|
|
#
|
|
|
|
# Outcome:
|
|
|
|
# The following variables will be defined when this CMake module completes:
|
|
|
|
#
|
|
|
|
# - BOARD: Board, without revision field.
|
|
|
|
# - BOARD_REVISION: Board revision
|
|
|
|
# - BOARD_DIR: Board directory with the implementation for selected board
|
|
|
|
# - ARCH_DIR: Arch dir for extracted from selected board
|
|
|
|
# - BOARD_ROOT: BOARD_ROOT with ZEPHYR_BASE appended
|
|
|
|
#
|
|
|
|
# The following targets will be defined when this CMake module completes:
|
|
|
|
# - board : when invoked a list of valid boards will be printed
|
|
|
|
#
|
|
|
|
# Required variables:
|
|
|
|
# - BOARD: Board name, including any optional revision field, for example: `foo` or `foo@1.0.0`
|
|
|
|
#
|
|
|
|
# Optional variables:
|
|
|
|
# - BOARD_ROOT: CMake list of board roots containing board implementations
|
|
|
|
# - ARCH_ROOT: CMake list of arch roots containing arch implementations
|
|
|
|
#
|
|
|
|
# Optional environment variables:
|
|
|
|
# - ZEPHYR_BOARD_ALIASES: Environment setting pointing to a CMake file
|
|
|
|
# containing board aliases.
|
|
|
|
#
|
|
|
|
# Variables set by this module and not mentioned above are considered internal
|
|
|
|
# use only and may be removed, renamed, or re-purposed without prior notice.
|
|
|
|
|
2021-12-16 17:13:54 +01:00
|
|
|
include_guard(GLOBAL)
|
|
|
|
|
|
|
|
include(python)
|
|
|
|
include(extensions)
|
|
|
|
|
2021-12-16 13:55:09 +01:00
|
|
|
# Check that BOARD has been provided, and that it has not changed.
|
|
|
|
# If user tries to change the BOARD, the BOARD value is reset to the BOARD_CACHED value.
|
|
|
|
zephyr_check_cache(BOARD REQUIRED)
|
|
|
|
|
|
|
|
# 'BOARD_ROOT' is a prioritized list of directories where boards may
|
|
|
|
# be found. It always includes ${ZEPHYR_BASE} at the lowest priority.
|
|
|
|
list(APPEND BOARD_ROOT ${ZEPHYR_BASE})
|
|
|
|
|
|
|
|
string(FIND "${BOARD}" "@" REVISION_SEPARATOR_INDEX)
|
|
|
|
if(NOT (REVISION_SEPARATOR_INDEX EQUAL -1))
|
|
|
|
math(EXPR BOARD_REVISION_INDEX "${REVISION_SEPARATOR_INDEX} + 1")
|
|
|
|
string(SUBSTRING ${BOARD} ${BOARD_REVISION_INDEX} -1 BOARD_REVISION)
|
|
|
|
string(SUBSTRING ${BOARD} 0 ${REVISION_SEPARATOR_INDEX} BOARD)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(DEFINED ENV{ZEPHYR_BOARD_ALIASES})
|
|
|
|
include($ENV{ZEPHYR_BOARD_ALIASES})
|
|
|
|
if(${BOARD}_BOARD_ALIAS)
|
|
|
|
set(BOARD_ALIAS ${BOARD} CACHE STRING "Board alias, provided by user")
|
|
|
|
set(BOARD ${${BOARD}_BOARD_ALIAS})
|
|
|
|
message(STATUS "Aliased BOARD=${BOARD_ALIAS} changed to ${BOARD}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
include(${ZEPHYR_BASE}/boards/deprecated.cmake)
|
|
|
|
if(${BOARD}_DEPRECATED)
|
|
|
|
set(BOARD_DEPRECATED ${BOARD} CACHE STRING "Deprecated board name, provided by user")
|
|
|
|
set(BOARD ${${BOARD}_DEPRECATED})
|
|
|
|
message(WARNING "Deprecated BOARD=${BOARD_DEPRECATED} name specified, board automatically changed to: ${BOARD}.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
zephyr_boilerplate_watch(BOARD)
|
2019-04-22 20:39:48 +02:00
|
|
|
|
boards/shields: re-work handling in cmake and west
Remove the boards and shields lists from the 'usage' target output.
That might have been readable at some point long ago in Zephyr's
history, when only a few boards were available, but right now it's
obscuring the high level targets we really want 'usage' to print.
Instead, add 'boards' and 'shields' targets which the user can run to
get those lists, and reference them from the 'usage' output. This
makes 'usage' squintable again. We use the new list_boards.py script
from the 'boards' target.
Reference the 'help' target from 'usage' as well, and drop the
recommendation that people run '--target help' from the 'west build
--help' output for the 'west build --target' option. The canonical
place to look is 'usage' now.
Use the new list_boards.py code from 'west boards' as well, which
allows us to add the board's directory as a format string key, in
addition to its name and architecture.
Keep west-completion.bash up to date. While doing that, I noticed that
a bunch of references to this file refer to a stale location, so fix
those too.
Finally, the 'usage' output is what we print for a failed board or
shield lookup, so that needs to be updated also. Handle that by
invoking boards.cmake and a new shields.cmake in CMake script mode to
print the relevant output.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-12-09 15:53:00 -08:00
|
|
|
foreach(root ${BOARD_ROOT})
|
2021-12-16 13:55:09 +01:00
|
|
|
# Check that the board root looks reasonable.
|
|
|
|
if(NOT IS_DIRECTORY "${root}/boards")
|
|
|
|
message(WARNING "BOARD_ROOT element without a 'boards' subdirectory:
|
|
|
|
${root}
|
|
|
|
Hints:
|
|
|
|
- if your board directory is '/foo/bar/boards/<ARCH>/my_board' then add '/foo/bar' to BOARD_ROOT, not the entire board directory
|
|
|
|
- if in doubt, use absolute paths")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# NB: find_path will return immediately if the output variable is
|
|
|
|
# already set
|
|
|
|
if (BOARD_ALIAS)
|
|
|
|
find_path(BOARD_HIDDEN_DIR
|
|
|
|
NAMES ${BOARD_ALIAS}_defconfig
|
|
|
|
PATHS ${root}/boards/*/*
|
|
|
|
NO_DEFAULT_PATH
|
|
|
|
)
|
|
|
|
if(BOARD_HIDDEN_DIR)
|
|
|
|
message("Board alias ${BOARD_ALIAS} is hiding the real board of same name")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
find_path(BOARD_DIR
|
|
|
|
NAMES ${BOARD}_defconfig
|
|
|
|
PATHS ${root}/boards/*/*
|
|
|
|
NO_DEFAULT_PATH
|
|
|
|
)
|
|
|
|
if(BOARD_DIR AND NOT (${root} STREQUAL ${ZEPHYR_BASE}))
|
|
|
|
set(USING_OUT_OF_TREE_BOARD 1)
|
|
|
|
endif()
|
boards/shields: re-work handling in cmake and west
Remove the boards and shields lists from the 'usage' target output.
That might have been readable at some point long ago in Zephyr's
history, when only a few boards were available, but right now it's
obscuring the high level targets we really want 'usage' to print.
Instead, add 'boards' and 'shields' targets which the user can run to
get those lists, and reference them from the 'usage' output. This
makes 'usage' squintable again. We use the new list_boards.py script
from the 'boards' target.
Reference the 'help' target from 'usage' as well, and drop the
recommendation that people run '--target help' from the 'west build
--help' output for the 'west build --target' option. The canonical
place to look is 'usage' now.
Use the new list_boards.py code from 'west boards' as well, which
allows us to add the board's directory as a format string key, in
addition to its name and architecture.
Keep west-completion.bash up to date. While doing that, I noticed that
a bunch of references to this file refer to a stale location, so fix
those too.
Finally, the 'usage' output is what we print for a failed board or
shield lookup, so that needs to be updated also. Handle that by
invoking boards.cmake and a new shields.cmake in CMake script mode to
print the relevant output.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-12-09 15:53:00 -08:00
|
|
|
endforeach()
|
2019-04-22 20:39:48 +02:00
|
|
|
|
2021-12-16 13:55:09 +01:00
|
|
|
if(EXISTS ${BOARD_DIR}/revision.cmake)
|
|
|
|
# Board provides revision handling.
|
|
|
|
include(${BOARD_DIR}/revision.cmake)
|
|
|
|
elseif(BOARD_REVISION)
|
|
|
|
message(WARNING "Board revision ${BOARD_REVISION} specified for ${BOARD}, \
|
|
|
|
but board has no revision so revision will be ignored.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(board_message "Board: ${BOARD}")
|
|
|
|
|
|
|
|
if(DEFINED BOARD_REVISION)
|
|
|
|
set(board_message "${board_message}, Revision: ${BOARD_REVISION}")
|
|
|
|
if(DEFINED ACTIVE_BOARD_REVISION)
|
|
|
|
set(board_message "${board_message} (Active: ${ACTIVE_BOARD_REVISION})")
|
|
|
|
set(BOARD_REVISION ${ACTIVE_BOARD_REVISION})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
string(REPLACE "." "_" BOARD_REVISION_STRING ${BOARD_REVISION})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
message(STATUS "${board_message}")
|
|
|
|
|
|
|
|
# Prepare boards usage command printing.
|
|
|
|
# This command prints all boards in the system in the following cases:
|
|
|
|
# - User specifies an invalid BOARD
|
|
|
|
# - User invokes '<build-command> boards' target
|
|
|
|
list(TRANSFORM ARCH_ROOT PREPEND "--arch-root=" OUTPUT_VARIABLE arch_root_args)
|
|
|
|
list(TRANSFORM BOARD_ROOT PREPEND "--board-root=" OUTPUT_VARIABLE board_root_args)
|
|
|
|
|
boards/shields: re-work handling in cmake and west
Remove the boards and shields lists from the 'usage' target output.
That might have been readable at some point long ago in Zephyr's
history, when only a few boards were available, but right now it's
obscuring the high level targets we really want 'usage' to print.
Instead, add 'boards' and 'shields' targets which the user can run to
get those lists, and reference them from the 'usage' output. This
makes 'usage' squintable again. We use the new list_boards.py script
from the 'boards' target.
Reference the 'help' target from 'usage' as well, and drop the
recommendation that people run '--target help' from the 'west build
--help' output for the 'west build --target' option. The canonical
place to look is 'usage' now.
Use the new list_boards.py code from 'west boards' as well, which
allows us to add the board's directory as a format string key, in
addition to its name and architecture.
Keep west-completion.bash up to date. While doing that, I noticed that
a bunch of references to this file refer to a stale location, so fix
those too.
Finally, the 'usage' output is what we print for a failed board or
shield lookup, so that needs to be updated also. Handle that by
invoking boards.cmake and a new shields.cmake in CMake script mode to
print the relevant output.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-12-09 15:53:00 -08:00
|
|
|
set(list_boards_commands
|
2021-12-16 13:55:09 +01:00
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/list_boards.py
|
|
|
|
${arch_root_args} ${board_root_args}
|
boards/shields: re-work handling in cmake and west
Remove the boards and shields lists from the 'usage' target output.
That might have been readable at some point long ago in Zephyr's
history, when only a few boards were available, but right now it's
obscuring the high level targets we really want 'usage' to print.
Instead, add 'boards' and 'shields' targets which the user can run to
get those lists, and reference them from the 'usage' output. This
makes 'usage' squintable again. We use the new list_boards.py script
from the 'boards' target.
Reference the 'help' target from 'usage' as well, and drop the
recommendation that people run '--target help' from the 'west build
--help' output for the 'west build --target' option. The canonical
place to look is 'usage' now.
Use the new list_boards.py code from 'west boards' as well, which
allows us to add the board's directory as a format string key, in
addition to its name and architecture.
Keep west-completion.bash up to date. While doing that, I noticed that
a bunch of references to this file refer to a stale location, so fix
those too.
Finally, the 'usage' output is what we print for a failed board or
shield lookup, so that needs to be updated also. Handle that by
invoking boards.cmake and a new shields.cmake in CMake script mode to
print the relevant output.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-12-09 15:53:00 -08:00
|
|
|
)
|
2019-04-22 20:39:48 +02:00
|
|
|
|
2021-12-16 13:55:09 +01:00
|
|
|
if(NOT BOARD_DIR)
|
|
|
|
message("No board named '${BOARD}' found.\n\n"
|
|
|
|
"Please choose one of the following boards:\n"
|
|
|
|
)
|
|
|
|
execute_process(${list_boards_commands})
|
|
|
|
unset(CACHED_BOARD CACHE)
|
|
|
|
message(FATAL_ERROR "Invalid BOARD; see above.")
|
2019-04-22 20:39:48 +02:00
|
|
|
endif()
|
|
|
|
|
2021-12-16 13:55:09 +01:00
|
|
|
add_custom_target(boards ${list_boards_commands} USES_TERMINAL)
|