From 2d730af04c56719bfe8a6683162b032240679dc9 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Wed, 20 Dec 2023 18:38:59 +0000 Subject: [PATCH] hosted/meson: Created a Meson build system for BMDA --- meson.build | 8 ++ src/meson.build | 7 +- src/platforms/hosted/Makefile.inc | 1 - src/platforms/hosted/meson.build | 123 +++++++++++++++++++++++ src/platforms/hosted/remote/meson.build | 41 ++++++++ src/platforms/hosted/windows/meson.build | 46 +++++++++ 6 files changed, 221 insertions(+), 5 deletions(-) create mode 100644 src/platforms/hosted/meson.build create mode 100644 src/platforms/hosted/remote/meson.build create mode 100644 src/platforms/hosted/windows/meson.build diff --git a/meson.build b/meson.build index 391d7f43b78..a31f184b388 100644 --- a/meson.build +++ b/meson.build @@ -271,6 +271,14 @@ if meson.is_subproject() include_directories: bmd_core_includes, link_with: libbmd, ) +else + # BMDA executable + bmda = executable( + 'blackmagic', + dependencies: [libbmd_core, bmda_platform], + native: is_cross_build, + ) + alias_target('bmda', bmda) endif # We report this at the end of the configuration, so it's easier to spot diff --git a/src/meson.build b/src/meson.build index 6598310446b..bb364902146 100644 --- a/src/meson.build +++ b/src/meson.build @@ -38,22 +38,20 @@ libbmd_core_sources = files( 'command.c', 'crc32.c', 'exception.c', + 'gdb_hostio.c', 'gdb_main.c', 'gdb_packet.c', 'hex_utils.c', 'main.c', 'maths_utils.c', 'morse.c', + 'remote.c', 'timing.c', ) # Define sources used only by the firmware bmd_core_sources = [ libbmd_core_sources, - files( - 'gdb_hostio.c', - 'remote.c', - ), ] bmd_core_args = [] @@ -114,6 +112,7 @@ if is_firmware_build # Get probe host and platform dependencies subdir('platforms') endif +subdir('platforms/hosted') summary( { diff --git a/src/platforms/hosted/Makefile.inc b/src/platforms/hosted/Makefile.inc index 9a3c4b632f8..27cd27fbe13 100644 --- a/src/platforms/hosted/Makefile.inc +++ b/src/platforms/hosted/Makefile.inc @@ -109,7 +109,6 @@ ifneq ($(HOSTED_BMP_ONLY), 1) endif ifneq ($(HOSTED_BMP_ONLY), 1) - CFLAGS += -DCMSIS_DAP SRC += cmsis_dap.c dap.c dap_command.c dap_swd.c dap_jtag.c ifneq ($(shell pkg-config --exists $(HIDAPILIB); echo $$?), 0) $(error Please install $(HIDAPILIB) dependency or set HOSTED_BMP_ONLY to 1) diff --git a/src/platforms/hosted/meson.build b/src/platforms/hosted/meson.build new file mode 100644 index 00000000000..239da4f01c0 --- /dev/null +++ b/src/platforms/hosted/meson.build @@ -0,0 +1,123 @@ +# This file is part of the Black Magic Debug project. +# +# Copyright (C) 2023 1BitSquared +# Written by Rachel Mant +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +bmda_includes = include_directories('.') + +bmda_sources = files( + 'platform.c', + 'gdb_if.c', + 'rtt_if.c', + 'cli.c', + 'utils.c', + 'probe_info.c', + 'debug.c', + 'bmp_remote.c', + 'bmp_libusb.c', + 'cmsis_dap.c', + 'dap.c', + 'dap_command.c', + 'dap_swd.c', + 'dap_jtag.c', + 'stlinkv2.c', + 'stlinkv2_jtag.c', + 'stlinkv2_swd.c', + 'ftdi_bmp.c', + 'ftdi_jtag.c', + 'ftdi_swd.c', + 'jlink.c', + 'jlink_jtag.c', + 'jlink_swd.c', +) +subdir('remote') + +bmda_args = [ + '-DPC_HOSTED=1', + '-DHOSTED_BMP_ONLY=0', +] +bmda_link_args = [] +bmda_deps = [] + +cc = is_cross_build ? cc_native : cc_host + +# Determine if we're on a MSYS2 environment of some kind +# If the compiler is MSYS2 GCC or Clang (but not Clang-cl) +if build_machine.system() == 'windows' and cc.has_define('__MINGW32__') + # Check if we're in a UCRT based environment or not + if cc.has_define('_UCRT', prefix: '#include ') + # Force linking against the correct C runtime DLL + if cc.get_id() != 'clang' + bmda_args += ['-mcrtdll=ucrt'] + bmda_link_args += ['-mcrtdll=ucrt'] + endif + elif + bmda_args += ['-mcrtdll=msvcrt'] + bmda_link_args += ['-mcrtdll=msvcrt'] + endif +endif + +if build_machine.system() in ['windows', 'cygwin'] + subdir('windows') + + # Make sure we build for Windows Vista and above, where the + # 'SetupDiGetDevicePropertyW()' function is available + bmda_args += ['-D_WIN32_WINNT=0x600'] + bmda_link_args += [ + cxx.find_library('ws2_32'), + cxx.find_library('setupapi'), + ] + bmda_sources += files('serial_win.c') +else + bmda_deps += [dependency('libftdi1', method: 'pkg-config', native: is_cross_build)] + bmda_sources += files('serial_unix.c') +endif + +# Pick the appropriate HIDAPI depending on platform +if build_machine.system() == 'linux' + bmda_deps += [dependency('hidapi-hidraw', method: 'pkg-config', native: is_cross_build)] +else + bmda_deps += [dependency('hidapi', method: 'pkg-config', native: is_cross_build)] +endif +bmda_deps += [ + dependency( + 'libusb-1.0', + version: '>=1.0.13', + method: 'pkg-config', + fallback: 'libusb', + native: is_cross_build, + ) +] + +bmda_platform = declare_dependency( + include_directories: bmda_includes, + sources: bmda_sources, + compile_args: bmda_args, + link_args: bmda_link_args, + dependencies: [libbmd_core, bmda_deps], +) diff --git a/src/platforms/hosted/remote/meson.build b/src/platforms/hosted/remote/meson.build new file mode 100644 index 00000000000..cf3ac571333 --- /dev/null +++ b/src/platforms/hosted/remote/meson.build @@ -0,0 +1,41 @@ +# This file is part of the Black Magic Debug project. +# +# Copyright (C) 2023 1BitSquared +# Written by Rachel Mant +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +bmda_sources += files( + 'protocol_v0.c', + 'protocol_v0_swd.c', + 'protocol_v0_jtag.c', + 'protocol_v0_adiv5.c', + 'protocol_v1.c', + 'protocol_v1_adiv5.c', + 'protocol_v2.c', + 'protocol_v3.c', + 'protocol_v3_adiv5.c', +) diff --git a/src/platforms/hosted/windows/meson.build b/src/platforms/hosted/windows/meson.build new file mode 100644 index 00000000000..a30f274a067 --- /dev/null +++ b/src/platforms/hosted/windows/meson.build @@ -0,0 +1,46 @@ +# This file is part of the Black Magic Debug project. +# +# Copyright (C) 2023 1BitSquared +# Written by Rachel Mant +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +bmda_sources += files('ftdi.c') + +bmda_includes += include_directories('@0@/3rdparty/ftdi'.format(meson.project_source_root())) + +bmda_link_args += [ + cc.find_library( + 'ftd2xx', + dirs: '@0@/3rdparty/ftdi/@1@'.format(meson.project_source_root(), build_machine.cpu()) + ) +] + +configure_file( + input: '@0@/3rdparty/ftdi/@1@/ftd2xx.dll'.format(meson.project_source_root(), build_machine.cpu()), + output: '@0@/src/ftd2xx.dll'.format(meson.project_build_root()), + copy: true, +)