Skip to content

Commit

Permalink
CMake: align Himbaechel targets with non-Himbaechel ones.
Browse files Browse the repository at this point in the history
Primarily, this commit makes both of them use the `BBAsm` functions
to build and compile `.bba` files.

In addition, Himbaechel targets are now aligned with the rest in
how they are configured: instead of having all uarches enabled with
all of the devices disabled (the opposite of the rest of nextpnr),
uarches must be enabled explicitly but they come with all devices
enabled (except for Xilinx, which does not have a list of devices).
  • Loading branch information
whitequark committed Jan 16, 2025
1 parent c9ebbe1 commit 0fc4fb2
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .github/ci/build_himbaechel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function get_dependencies {
function build_nextpnr {
mkdir build
pushd build
cmake .. -DARCH=himbaechel -DHIMBAECHEL_EXAMPLE_DEVICES=example
cmake .. -DARCH=himbaechel -DHIMBAECHEL_UARCH=example -DHIMBAECHEL_EXAMPLE_DEVICES=example
make nextpnr-himbaechel chipdb-himbaechel-example -j`nproc`
popd
}
Expand Down
10 changes: 8 additions & 2 deletions cmake/BBAsm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ function(add_bba_produce_command)
DEPENDS
${arg_EXECUTABLE}
${arg_INPUTS}
$ENV{SERIALIZE_BBA_PRODUCE_COMMAND}
$ENV{SERIALIZE_BBA_TARGET}
VERBATIM
)

if (BBASM_SERIALIZE)
set(ENV{SERIALIZE_BBA_PRODUCE_COMMAND} ${arg_OUTPUT})
# Have to insert a custom target in between two custom commands, else CMake will try to
# depend on the previous (in serialization order) command directly, which will fail if
# they're in different directories. Unfortunately this makes the terminal output uglier.
math(EXPR next_count "$ENV{SERIALIZE_BBA_COUNT} + 1")
add_custom_target(--bbasm-serialize-${next_count} DEPENDS ${arg_OUTPUT})
set(ENV{SERIALIZE_BBA_COUNT} ${next_count})
set(ENV{SERIALIZE_BBA_TARGET} --bbasm-serialize-${next_count})
endif()

endfunction()
Expand Down
17 changes: 17 additions & 0 deletions cmake/FindApycula.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# nextpnr-gowin only

find_program (GOWIN_BBA_EXECUTABLE gowin_bba)
message(STATUS "gowin_bba executable: ${GOWIN_BBA_EXECUTABLE}")

# nextpnr-himbaechel-gowin only

if (DEFINED ENV{APYCULA_INSTALL_PREFIX})
set(apycula_default_install_prefix $ENV{APYCULA_INSTALL_PREFIX})
endif()
set(APYCULA_INSTALL_PREFIX ${apycula_default_install_prefix} CACHE STRING
"Apycula install prefix (virtualenv directory)")
if (NOT APYCULA_INSTALL_PREFIX STREQUAL "")
message(STATUS "Apycula install prefix: ${APYCULA_INSTALL_PREFIX}")
set(apycula_Python3_EXECUTABLE ${APYCULA_INSTALL_PREFIX}/bin/python)
else()
message(STATUS "Apycula install prefix: (not set, using Python: ${Python3_EXECUTABLE})")
set(apycula_Python3_EXECUTABLE ${Python3_EXECUTABLE})
endif()
28 changes: 20 additions & 8 deletions himbaechel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
set(HIMBAECHEL_UARCHES "example;gowin;xilinx;ng-ultra")
set(HIMBAECHEL_UARCHES example gowin xilinx ng-ultra)

set(HIMBAECHEL_UARCH "${HIMBAECHEL_UARCHES}" CACHE STRING "Microarchitectures for nextpnr-himbaechel build")
set(HIMBAECHEL_UARCH "" CACHE STRING "Microarchitectures for nextpnr-himbaechel build")
set_property(CACHE HIMBAECHEL_UARCH PROPERTY STRINGS ${HIMBAECHEL_UARCHES})

foreach (item ${HIMBAECHEL_UARCH})
if (NOT item IN_LIST HIMBAECHEL_UARCHES)
message(FATAL_ERROR "Microarchitecture '${item}' not in list of supported architectures")
endif()
endforeach()
if (NOT HIMBAECHEL_UARCH)
message(STATUS "Microarchitecture needs to be set, set desired one with -DHIMBAECHEL_UARCH=xxx")
message(STATUS "Supported Himbaechel microarchitectures are :")
message(STATUS " all")
foreach (item ${HIMBAECHEL_UARCHES})
message(STATUS " ${item}")
endforeach()
message(FATAL_ERROR "Microarchitecture setting is mandatory")
endif()

if (HIMBAECHEL_UARCH STREQUAL "all")
set(HIMBAECHEL_UARCH ${HIMBAECHEL_UARCHES})
endif()

foreach (uarch ${HIMBAECHEL_UARCH})
add_subdirectory(uarch/${uarch})
if (NOT uarch IN_LIST HIMBAECHEL_UARCHES)
message(FATAL_ERROR "Microarchitecture ${uarch} is not a supported Himbaechel microarchitectures")
endif()

add_subdirectory(uarch/${uarch})
aux_source_directory(uarch/${uarch} HM_UARCH_FILES)
foreach (target ${family_targets})
target_sources(${target} PRIVATE ${HM_UARCH_FILES})
Expand Down
55 changes: 31 additions & 24 deletions himbaechel/uarch/example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
message(STATUS "Configuring Himbaechel-Example uarch")
cmake_minimum_required(VERSION 3.5)
project(himbaechel-example-chipdb NONE)
add_custom_target(chipdb-himbaechel-example)
foreach (target ${family_targets})
add_dependencies(${target} chipdb-himbaechel-example)
endforeach()

set(ALL_HIMBAECHEL_EXAMPLE_DEVICES example)
set(HIMBAECHEL_EXAMPLE_DEVICES "" CACHE STRING
set(HIMBAECHEL_EXAMPLE_DEVICES ${ALL_HIMBAECHEL_EXAMPLE_DEVICES} CACHE STRING
"Include support for these Example devices (available: ${ALL_HIMBAECHEL_EXAMPLE_DEVICES})")
message(STATUS "Enabled Himbaechel-Example devices: ${HIMBAECHEL_EXAMPLE_DEVICES}")

set(chipdb_binaries)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/example)
foreach (device ${HIMBAECHEL_EXAMPLE_DEVICES})
set(device_bba ${CMAKE_BINARY_DIR}/share/himbaechel/example/chipdb-${device}.bba)
set(device_bin ${CMAKE_BINARY_DIR}/share/himbaechel/example/chipdb-${device}.bin)
add_custom_command(
OUTPUT ${device_bin}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/example_arch_gen.py ${device_bba}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} ${device_bba} ${device_bin}.new
# atomically update
COMMAND ${CMAKE_COMMAND} -E rename ${device_bin}.new ${device_bin}
DEPENDS
bbasm
${CMAKE_CURRENT_SOURCE_DIR}/example_arch_gen.py
${CMAKE_CURRENT_SOURCE_DIR}/constids.inc
${CMAKE_CURRENT_SOURCE_DIR}/gfxids.inc
VERBATIM)
list(APPEND chipdb_binaries ${device_bin})
if (NOT device IN_LIST ALL_HIMBAECHEL_EXAMPLE_DEVICES)
message(FATAL_ERROR "Device ${device} is not a supported Example device")
endif()

add_bba_produce_command(
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/example_arch_gen.py
${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba.new
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba
INPUTS
${CMAKE_CURRENT_SOURCE_DIR}/example_arch_gen.py
${CMAKE_CURRENT_SOURCE_DIR}/constids.inc
${CMAKE_CURRENT_SOURCE_DIR}/gfxids.inc
)

add_bba_compile_command(
TARGET chipdb-himbaechel-example
OUTPUT ${CMAKE_BINARY_DIR}/share/himbaechel/example/chipdb-${device}.bin
INPUT ${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba
MODE binary
)
endforeach()

add_custom_target(chipdb-himbaechel-example ALL DEPENDS ${chipdb_binaries})
install(DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/example/ DESTINATION share/nextpnr/himbaechel/example
PATTERN "*.bba" EXCLUDE)
install(
DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/example
DESTINATION share/nextpnr/himbaechel/example
)
67 changes: 30 additions & 37 deletions himbaechel/uarch/gowin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,44 @@
message(STATUS "Configuring Himbaechel-Gowin uarch")
cmake_minimum_required(VERSION 3.5)
project(himbaechel-gowin-chipdb NONE)
include(FindApycula)

add_custom_target(chipdb-himbaechel-gowin ALL)
foreach (target ${family_targets})
add_dependencies(${target} chipdb-himbaechel-gowin)
endforeach()

set(ALL_HIMBAECHEL_GOWIN_DEVICES GW1N-1 GW1NZ-1 GW1N-4 GW1N-9 GW1N-9C GW1NS-4 GW2A-18 GW2A-18C)
set(HIMBAECHEL_GOWIN_DEVICES "" CACHE STRING
set(HIMBAECHEL_GOWIN_DEVICES ${ALL_HIMBAECHEL_GOWIN_DEVICES} CACHE STRING
"Include support for these Gowin devices (available: ${ALL_HIMBAECHEL_GOWIN_DEVICES})")
if (HIMBAECHEL_GOWIN_DEVICES STREQUAL "all")
set(HIMBAECHEL_GOWIN_DEVICES ${ALL_HIMBAECHEL_GOWIN_DEVICES})
endif()
message(STATUS "Enabled Himbaechel-Gowin devices: ${HIMBAECHEL_GOWIN_DEVICES}")

if (DEFINED ENV{APYCULA_INSTALL_PREFIX})
set(apycula_default_install_prefix $ENV{APYCULA_INSTALL_PREFIX})
endif()
set(APYCULA_INSTALL_PREFIX ${apycula_default_install_prefix} CACHE STRING
"Apycula install prefix (virtualenv directory)")
if (NOT APYCULA_INSTALL_PREFIX STREQUAL "")
message(STATUS "Apycula install prefix: ${APYCULA_INSTALL_PREFIX}")
set(apycula_Python3_EXECUTABLE ${APYCULA_INSTALL_PREFIX}/bin/python)
else()
message(STATUS "Apycula install prefix: (using system Python)")
set(apycula_Python3_EXECUTABLE ${Python3_EXECUTABLE})
endif()

set(chipdb_binaries)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/gowin)
foreach (device ${HIMBAECHEL_GOWIN_DEVICES})
if (NOT device IN_LIST ALL_HIMBAECHEL_GOWIN_DEVICES)
message(FATAL_ERROR "Device ${device} is not a supported Gowin device")
message(FATAL_ERROR "Device ${device} is not a supported Gowin device")
endif()

set(device_bba ${CMAKE_BINARY_DIR}/share/himbaechel/gowin/chipdb-${device}.bba)
set(device_bin ${CMAKE_BINARY_DIR}/share/himbaechel/gowin/chipdb-${device}.bin)
add_custom_command(
OUTPUT ${device_bin}
COMMAND ${apycula_Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gowin_arch_gen.py -d ${device} -o ${device_bba}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} ${device_bba} ${device_bin}.new
# atomically update
COMMAND ${CMAKE_COMMAND} -E rename ${device_bin}.new ${device_bin}
DEPENDS
bbasm
${CMAKE_CURRENT_SOURCE_DIR}/gowin_arch_gen.py
${CMAKE_CURRENT_SOURCE_DIR}/constids.inc
VERBATIM)
list(APPEND chipdb_binaries ${device_bin})
add_bba_produce_command(
COMMAND ${apycula_Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/gowin_arch_gen.py
-d ${device}
-o ${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba.new
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba
INPUTS
${CMAKE_CURRENT_SOURCE_DIR}/gowin_arch_gen.py
${CMAKE_CURRENT_SOURCE_DIR}/constids.inc
)

add_bba_compile_command(
TARGET chipdb-himbaechel-gowin
OUTPUT ${CMAKE_BINARY_DIR}/share/himbaechel/gowin/chipdb-${device}.bin
INPUT ${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba
MODE binary
)
endforeach()

add_custom_target(chipdb-himbaechel-gowin ALL DEPENDS ${chipdb_binaries})
install(DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/gowin/ DESTINATION share/nextpnr/himbaechel/gowin
PATTERN "*.bba" EXCLUDE)
install(
DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/gowin
DESTINATION share/nextpnr/himbaechel/gowin
)
68 changes: 39 additions & 29 deletions himbaechel/uarch/ng-ultra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
message(STATUS "Configuring Himbaechel-NG-ULTRA uarch")
cmake_minimum_required(VERSION 3.5)
project(himbaechel-ng-ultra-chipdb NONE)
set(HIMBAECHEL_PRJBEYOND_DB "" CACHE STRING
"Path to a Project Beyond database")
if (NOT HIMBAECHEL_PRJBEYOND_DB)
message(FATAL_ERROR "HIMBAECHEL_PRJBEYOND_DB must be set to a prjbeyond database checkout")
endif()

add_custom_target(chipdb-himbaechel-ng-ultra)
foreach (target ${family_targets})
add_dependencies(${target} chipdb-himbaechel-ng-ultra)
endforeach()

set(ALL_HIMBAECHEL_NGULTRA_DEVICES ng-ultra)
set(HIMBAECHEL_NGULTRA_DEVICES "" CACHE STRING
set(HIMBAECHEL_NGULTRA_DEVICES ${ALL_HIMBAECHEL_NGULTRA_DEVICES} CACHE STRING
"Include support for these NG-Ultra devices (available: ${ALL_HIMBAECHEL_NGULTRA_DEVICES})")
message(STATUS "Enabled Himbaechel-NG-Ultra devices: ${HIMBAECHEL_NGULTRA_DEVICES}")
set(HIMBAECHEL_PRJBEYOND_DB "" CACHE STRING
"Path to a Project Beyond database")

set(chipdb_binaries)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/ng-ultra)
foreach (device ${HIMBAECHEL_NGULTRA_DEVICES})
if ("${HIMBAECHEL_PRJBEYOND_DB}" STREQUAL "")
message(SEND_ERROR "HIMBAECHEL_PRJBEYOND_DB must be set to a prjbeyond database checkout")
endif()
if (NOT device IN_LIST ALL_HIMBAECHEL_NGULTRA_DEVICES)
message(FATAL_ERROR "Device ${device} is not a supported NG-Ultra device")
endif()

string(TOUPPER ${device} upcase_device)

add_bba_produce_command(
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/gen/arch_gen.py
--db ${HIMBAECHEL_PRJBEYOND_DB}
--device ${upcase_device}
--bba ${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba.new
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba
INPUTS
${CMAKE_CURRENT_SOURCE_DIR}/gen/arch_gen.py
${CMAKE_CURRENT_SOURCE_DIR}/constids.inc
)

set(device_bba ${CMAKE_BINARY_DIR}/share/himbaechel/ng-ultra/chipdb-${device}.bba)
set(device_bin ${CMAKE_BINARY_DIR}/share/himbaechel/ng-ultra/chipdb-${device}.bin)
string(TOUPPER ${device} upcase_device)
add_custom_command(
OUTPUT ${device_bin}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gen/arch_gen.py --db ${HIMBAECHEL_PRJBEYOND_DB} --device ${upcase_device} --bba ${device_bba}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} ${device_bba} ${device_bin}.new
# atomically update
COMMAND ${CMAKE_COMMAND} -E rename ${device_bin}.new ${device_bin}
DEPENDS
bbasm
${CMAKE_CURRENT_SOURCE_DIR}/gen/arch_gen.py
${CMAKE_CURRENT_SOURCE_DIR}/constids.inc
VERBATIM)
list(APPEND chipdb_binaries ${device_bin})
add_bba_compile_command(
TARGET chipdb-himbaechel-ng-ultra
OUTPUT ${CMAKE_BINARY_DIR}/share/himbaechel/ng-ultra/chipdb-${device}.bin
INPUT ${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba
MODE binary
)
endforeach()

add_custom_target(chipdb-himbaechel-ng-ultra ALL DEPENDS ${chipdb_binaries})
install(DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/ng-ultra/ DESTINATION share/nextpnr/himbaechel/ng-ultra
PATTERN "*.bba" EXCLUDE)
install(
DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/ng-ultra
DESTINATION share/nextpnr/himbaechel/ng-ultra
)
61 changes: 32 additions & 29 deletions himbaechel/uarch/xilinx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
message(STATUS "Configuring Xilinx uarch")
cmake_minimum_required(VERSION 3.5)
project(himbaechel-xilinx-chipdb NONE)

set(HIMBAECHEL_XILINX_DEVICES "" CACHE STRING
"Include support for these Xilinx devices via himbaechel")
set(HIMBAECHEL_PRJXRAY_DB "" CACHE STRING
"Path to a project x-ray database")
message(STATUS "Enabled Himbaechel-Xilinx devices: ${HIMBAECHEL_XILINX_DEVICES}")
if (NOT HIMBAECHEL_PRJXRAY_DB)
message(FATAL_ERROR "HIMBAECHEL_PRJXRAY_DB must be set to a prjxray database checkout")
endif()

add_custom_target(chipdb-himbaechel-xilinx)
foreach (target ${family_targets})
add_dependencies(${target} chipdb-himbaechel-xilinx)
endforeach()

set(HIMBAECHEL_XILINX_DEVICES "" CACHE STRING
"Include support for these Xilinx devices")
message(STATUS "Enabled Himbaechel-Xilinx devices: ${HIMBAECHEL_XILINX_DEVICES}")

set(chipdb_binaries)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/xilinx)
foreach (device ${HIMBAECHEL_XILINX_DEVICES})
if ("${HIMBAECHEL_PRJXRAY_DB}" STREQUAL "")
message(SEND_ERROR "HIMBAECHEL_PRJXRAY_DB must be set to a prjxray database checkout")
endif()
add_bba_produce_command(
COMMAND /usr/bin/pypy3 ${CMAKE_CURRENT_SOURCE_DIR}/gen/xilinx_gen.py
--xray ${HIMBAECHEL_PRJXRAY_DB}/artix7
--device ${device}
--bba ${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba.new
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba
INPUTS
${CMAKE_CURRENT_SOURCE_DIR}/gen/xilinx_gen.py
${CMAKE_CURRENT_SOURCE_DIR}/constids.inc
)

set(device_bba ${CMAKE_BINARY_DIR}/share/himbaechel/xilinx/chipdb-${device}.bba)
set(device_bin ${CMAKE_BINARY_DIR}/share/himbaechel/xilinx/chipdb-${device}.bin)
add_custom_command(
OUTPUT ${device_bin}
COMMAND pypy3 ${CMAKE_CURRENT_SOURCE_DIR}/gen/xilinx_gen.py --xray ${HIMBAECHEL_PRJXRAY_DB}/artix7 --device ${device} --bba ${device_bba}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} ${device_bba} ${device_bin}.new
# atomically update
COMMAND ${CMAKE_COMMAND} -E rename ${device_bin}.new ${device_bin}
DEPENDS
bbasm
${CMAKE_CURRENT_SOURCE_DIR}/gen/xilinx_gen.py
${CMAKE_CURRENT_SOURCE_DIR}/constids.inc
VERBATIM)
list(APPEND chipdb_binaries ${device_bin})
add_bba_compile_command(
TARGET chipdb-himbaechel-xilinx
OUTPUT ${CMAKE_BINARY_DIR}/share/himbaechel/xilinx/chipdb-${device}.bin
INPUT ${CMAKE_CURRENT_BINARY_DIR}/chipdb-${device}.bba
MODE binary
)
endforeach()

add_custom_target(chipdb-himbaechel-xilinx ALL DEPENDS ${chipdb_binaries})
install(DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/xilinx/ DESTINATION share/nextpnr/himbaechel/xilinx
PATTERN "*.bba" EXCLUDE)
install(
DIRECTORY ${CMAKE_BINARY_DIR}/share/himbaechel/xilinx
DESTINATION share/nextpnr/himbaechel/xilinx
)

0 comments on commit 0fc4fb2

Please sign in to comment.