From 0870b778c00b196d535e32bfd612bbdd92374b3b Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 5 Dec 2020 16:52:35 +0100 Subject: [PATCH] hosted: Allow to build without libusb, libftdi and hidapi with HOSTED_BMP_ONLY=1 --- src/platforms/hosted/Makefile.inc | 27 +++++++++++++++------ src/platforms/hosted/bmp_libusb.c | 12 ++++++++++ src/platforms/hosted/bmp_serial.c | 40 +++++++++++++++++++++++++++++++ src/platforms/hosted/platform.c | 6 +---- 4 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 src/platforms/hosted/bmp_serial.c diff --git a/src/platforms/hosted/Makefile.inc b/src/platforms/hosted/Makefile.inc index 7aa0f187..c43c5d31 100644 --- a/src/platforms/hosted/Makefile.inc +++ b/src/platforms/hosted/Makefile.inc @@ -2,6 +2,14 @@ SYS = $(shell $(CC) -dumpmachine) CFLAGS += -DENABLE_DEBUG -DPLATFORM_HAS_DEBUG CFLAGS +=-I ./target -I./platforms/pc +# Define HOSTED_BMP_ONLY to '1' in order to build the hosted blackmagic +# executable with support for native BMP probes only. This makes +# linking against the libftdi and libusb libraries unnecessary. This can +# be useful to minimize external dependencies, and make building on +# windows systems easier. +HOSTED_BMP_ONLY ?= 0 +CFLAGS += -DHOSTED_BMP_ONLY=$(HOSTED_BMP_ONLY) + ifneq (, $(findstring linux, $(SYS))) SRC += serial_unix.c ifeq ($(ASAN), 1) @@ -24,27 +32,32 @@ LDFLAGS += -framework CoreFoundation CFLAGS += -Ihidapi/hidapi endif +ifneq ($(HOSTED_BMP_ONLY), 1) LDFLAGS += -lusb-1.0 CFLAGS += $(shell pkg-config --cflags libftdi1) LDFLAGS += $(shell pkg-config --libs libftdi1) CFLAGS += -Wno-missing-field-initializers +endif -ifneq (, $(findstring mingw, $(SYS))) - SRC += cmsis_dap.c dap.c hid.c +ifneq ($(HOSTED_BMP_ONLY), 1) CFLAGS += -DCMSIS_DAP -else - ifeq ($(shell pkg-config --exists hidapi-libusb && echo 0), 0) + SRC += cmsis_dap.c dap.c + ifneq (, $(findstring mingw, $(SYS))) + SRC += hid.c + else CFLAGS += $(shell pkg-config --cflags hidapi-libusb) LDFLAGS += $(shell pkg-config --libs hidapi-libusb) - CFLAGS += -DCMSIS_DAP - SRC += cmsis_dap.c dap.c endif endif VPATH += platforms/pc SRC += timing.c cl_utils.c utils.c -SRC += stlinkv2.c bmp_libusb.c SRC += bmp_remote.c remote_swdptap.c remote_jtagtap.c +ifneq ($(HOSTED_BMP_ONLY), 1) +SRC += bmp_libusb.c stlinkv2.c SRC += ftdi_bmp.c libftdi_swdptap.c libftdi_jtagtap.c SRC += jlink.c jlink_adiv5_swdp.c jlink_jtagtap.c +else +SRC += bmp_serial.c +endif PC_HOSTED = 1 diff --git a/src/platforms/hosted/bmp_libusb.c b/src/platforms/hosted/bmp_libusb.c index 44603bcb..30abda8d 100644 --- a/src/platforms/hosted/bmp_libusb.c +++ b/src/platforms/hosted/bmp_libusb.c @@ -22,6 +22,7 @@ #include "libusb-1.0/libusb.h" #include "cl_utils.h" #include "ftdi_bmp.h" +#include "version.h" #define VENDOR_ID_STLINK 0x0483 #define PRODUCT_ID_STLINK_MASK 0xffe0 @@ -35,6 +36,17 @@ #define VENDOR_ID_SEGGER 0x1366 +void bmp_ident(bmp_info_t *info) +{ + DEBUG_INFO("BMP hosted %s\n for ST-Link V2/3, CMSIS_DAP, JLINK and " + "LIBFTDI/MPSSE\n", FIRMWARE_VERSION); + if (info && info->vid && info->pid) + DEBUG_INFO("Using %04x:%04x %s %s\n %s\n", info->vid, info->pid, + info->serial, + info->manufacturer, + info->product); +} + void libusb_exit_function(bmp_info_t *info) { if (!info->usb_link) diff --git a/src/platforms/hosted/bmp_serial.c b/src/platforms/hosted/bmp_serial.c new file mode 100644 index 00000000..53325bec --- /dev/null +++ b/src/platforms/hosted/bmp_serial.c @@ -0,0 +1,40 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2020 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* Find all known serial connected debuggers */ + +#include "general.h" +#include +#include "platform.h" +#include "bmp_hosted.h" +#include "version.h" + +void bmp_ident(bmp_info_t *info) +{ + (void) info; + DEBUG_INFO("BMP hosted %s\n", FIRMWARE_VERSION); +} + +void libusb_exit_function(bmp_info_t *info) {(void)info;}; +int find_debuggers(BMP_CL_OPTIONS_t *cl_opts, bmp_info_t *info) +{ + (void)cl_opts; + (void)info; + return -1; +}; diff --git a/src/platforms/hosted/platform.c b/src/platforms/hosted/platform.c index 2f5046bc..09f883e3 100644 --- a/src/platforms/hosted/platform.c +++ b/src/platforms/hosted/platform.c @@ -85,11 +85,7 @@ void platform_init(int argc, char **argv) } else if (find_debuggers(&cl_opts, &info)) { exit(-1); } - DEBUG_INFO("BMP hosted %s\n for ST-Link V2/3, CMSIS_DAP, JLINK and " - "LIBFTDI/MPSSE\n", FIRMWARE_VERSION); - DEBUG_INFO("Using %04x:%04x %s %s\n %s\n", info.vid, info.pid, info.serial, - info.manufacturer, - info.product); + bmp_ident(&info); switch (info.bmp_type) { case BMP_TYPE_BMP: if (serial_open(&cl_opts, info.serial))