From f54d4005001945760d87300a8b1e6b0cc6025b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Smoczy=C5=84ski?= Date: Fri, 6 Aug 2021 18:06:23 +0200 Subject: [PATCH] [BH-734] Add hardware board selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To support bell hardware one needs to distinguish between the rt1051 generic target and product's boards. Signed-off-by: Marcin SmoczyƄski --- .github/workflows/releases.yaml | 2 +- CMakeLists.txt | 16 +++++---- board/CMakeLists.txt | 3 +- cmake/modules/Board.cmake | 53 +++++++++++++++++++++++++++++ cmake/modules/FetchBootloader.cmake | 2 +- cmake/modules/ProjectConfig.cmake | 14 ++++---- cmake/modules/Utils.cmake | 7 ++++ 7 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 cmake/modules/Board.cmake diff --git a/.github/workflows/releases.yaml b/.github/workflows/releases.yaml index febe871b779a0a9d491cfc4cc649b5bc08842115..24460fae2aad41cf47d4cea9fd3e8b508af6799c 100644 --- a/.github/workflows/releases.yaml +++ b/.github/workflows/releases.yaml @@ -40,7 +40,7 @@ jobs: run: | export JOBS=${JOBS:-$(nproc)} && \ echo "JOBS=${JOBS}" && \ - ./configure.sh pure rt1051 RelWithDebInfo -DPURE_HW_TARGET=T6 -G Ninja && \ + ./configure.sh pure rt1051 RelWithDebInfo -DWITH_BOARD_REVISION=6 -G Ninja && \ pushd build-purephone-rt1051-RelWithDebInfo && \ ninja -j ${JOBS} Pure&& \ ninja -j ${JOBS} PurePhone-UpdatePackage && \ diff --git a/CMakeLists.txt b/CMakeLists.txt index ac9eaa5b9227b2ebf0d54fefbd95366892aaada9..aa462b1b0c023a3dc404a90e8d42e6f521a731e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,12 @@ project(PureOS) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") +include(Product) +include(Board) + +validate_product_selection() +select_board() + include(Colours) include(CCacheConfig) include(ProjectConfig) @@ -20,12 +26,11 @@ include(FetchBootloader) include(AddPureUpdater) include(DiskImage) include(AddPackage) -include(Product) - -validate_product_selection() message("Selected product: ${PRODUCT}") -message("PROJECT_TARGET: ${PROJECT_TARGET}") +message("Selected board: ${BOARD}") +message("Board revision: ${BOARD_REVISION}") +message("PROJECT_TARGET: ${PROJECT_TARGET}") message("TARGET_COMPILE_DEFINITIONS: ${TARGET_COMPILE_OPTIONS}") message("TARGET_LIBRARIES: ${TARGET_LIBRARIES}") message("TARGET_LINKER_FLAGS: ${TARGET_LINKER_FLAGS}") @@ -156,9 +161,8 @@ add_custom_target( "Generating version info" ) - copy_updater_bin() copy_updater_ver() fetch_ecoboot() -add_subdirectory(products) +add_subdirectory(products) diff --git a/board/CMakeLists.txt b/board/CMakeLists.txt index 032d480419b22ffd017150339aa71a2866ca0e5a..f3fc5db120b17e94e89c888603b2abaaa1adc6fc 100644 --- a/board/CMakeLists.txt +++ b/board/CMakeLists.txt @@ -1,2 +1,3 @@ add_library(board STATIC) -add_subdirectory(${PROJECT_TARGET_NAME}) + +add_board_subdirectory() diff --git a/cmake/modules/Board.cmake b/cmake/modules/Board.cmake new file mode 100644 index 0000000000000000000000000000000000000000..ef75b61d71574c1d49ac6107f4e555d154547da0 --- /dev/null +++ b/cmake/modules/Board.cmake @@ -0,0 +1,53 @@ +include(Utils) + +set(WITH_BOARD_REVISION CACHE STRING "Board revision" ) + +function(add_board_subdirectory) + if(NOT ${ARGV0} STREQUAL "") + set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/${ARGV0}) + else() + set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}) + endif() + + if(NOT DEFINED BOARD) + message(FATAL_ERROR "Board is not defined") + endif() + + if (${BOARD} STREQUAL "bellpx" OR ${BOARD} STREQUAL "puretx") + add_subdirectory_if_exists(${ROOT_DIR}/rt1051) + endif () + + add_subdirectory_if_exists(${ROOT_DIR}/${BOARD}) +endfunction() + +macro(select_board) + if(NOT DEFINED PRODUCT) + message(FATAL_ERROR "Cannot determine board without knowing the product") + endif() + + set(BOARD_REVISION 1) + + if(${PROJECT_TARGET} STREQUAL "TARGET_Linux") + set(BOARD linux) + elseif(${PROJECT_TARGET} STREQUAL "TARGET_RT1051") + if(${PRODUCT} STREQUAL "PurePhone") + set(BOARD puretx) + set(BOARD_REVISION 7) + elseif(${PRODUCT} STREQUAL "BellHybrid") + set(BOARD bellpx) + else() + message(FATAL_ERROR "Unknown product: ${PRODUCT}") + endif() + else() + message(FATAL_ERROR "Unsupported target: ${PROJECT_TARGET}") + endif() + + # overwrite board revision with user selection + if(NOT "${WITH_BOARD_REVISION}" STREQUAL "") + set(BOARD_REVISION ${WITH_BOARD_REVISION}) + endif() + + if("${BOARD}" STREQUAL "") + message(FATAL_ERROR "Cannot determine board selection.") + endif() +endmacro() diff --git a/cmake/modules/FetchBootloader.cmake b/cmake/modules/FetchBootloader.cmake index d8cc8e86e6a53dad5401ea201eb5908f93f44067..1f8902bb00e239a9d65073c730203f3c09a18e72 100644 --- a/cmake/modules/FetchBootloader.cmake +++ b/cmake/modules/FetchBootloader.cmake @@ -1,6 +1,6 @@ function(fetch_ecoboot) set(ECOBOOT_ASSET_NAME ecoboot.bin) - if(${PURE_HW_TARGET} STREQUAL "T6") + if(${BOARD} STREQUAL "puretx" AND ${BOARD_REVISION} LESS_EQUAL 6) set(ECOBOOT_ASSET_NAME ecoboot_T6.bin) endif() diff --git a/cmake/modules/ProjectConfig.cmake b/cmake/modules/ProjectConfig.cmake index 4f37d503388acb4ad520bad75e648bad1454da0c..f3f6e458f1bf6008f9a3649ef36d1192e7773993 100644 --- a/cmake/modules/ProjectConfig.cmake +++ b/cmake/modules/ProjectConfig.cmake @@ -49,17 +49,15 @@ else() set (USB_DEVICE_PRODUCT_ID 0x0622 CACHE INTERNAL "Sets USB_DEVICE_PRODUCT_ID to Windows MTP Simulator Product ID") endif() -option(PURE_HW_TARGET "PURE_HW_TARGET" T7) -if (${PURE_HW_TARGET} STREQUAL "T6") - message("Building for T6") - set (MEMORY_LINKER_FILE "memory_T6.ld") - set (PROJECT_CONFIG_USER_DYNMEM_SIZE 9*1024*1024 CACHE INTERNAL "") - set (PURE_SDRAM_64_MB 0 CACHE INTERNAL "") -else() - message("Building for T7 - 64MB SDRAM !") +if(${BOARD} STREQUAL "puretx" AND ${BOARD_REVISION} EQUAL 7) + message("Building for T7 - 64MB SDRAM") set (MEMORY_LINKER_FILE "memory_T7.ld") set (PROJECT_CONFIG_USER_DYNMEM_SIZE 28*1024*1024 CACHE INTERNAL "") set (PURE_SDRAM_64_MB 1 CACHE INTERNAL "") +else() + set (MEMORY_LINKER_FILE "memory_T6.ld") + set (PROJECT_CONFIG_USER_DYNMEM_SIZE 9*1024*1024 CACHE INTERNAL "") + set (PURE_SDRAM_64_MB 0 CACHE INTERNAL "") endif() #Config options described in README.md diff --git a/cmake/modules/Utils.cmake b/cmake/modules/Utils.cmake index 4848b8e0889ac7eb5e0ce57ace65a39ece44885d..b75f28e1de748d8f84727852d1c91cd1b7d1d3f9 100644 --- a/cmake/modules/Utils.cmake +++ b/cmake/modules/Utils.cmake @@ -40,3 +40,10 @@ function(strip_executable TARGET) ) endif() endfunction() + +function(add_subdirectory_if_exists) + set(_DIR ${ARGV0}) + if(IS_DIRECTORY ${_DIR}) + add_subdirectory(${_DIR}) + endif() +endfunction()