From 3f54fba98692b3eb4fc2d20986bc7ea4bf412c90 Mon Sep 17 00:00:00 2001 From: fabalthazar Date: Sat, 9 Oct 2021 21:14:52 +0200 Subject: [PATCH 1/4] HOSTED_BMP_ONLY=0 by default on Linux. The user is warned about missing dependencies. --- src/platforms/hosted/Makefile.inc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/platforms/hosted/Makefile.inc b/src/platforms/hosted/Makefile.inc index 1aebd811..ad888638 100644 --- a/src/platforms/hosted/Makefile.inc +++ b/src/platforms/hosted/Makefile.inc @@ -5,10 +5,15 @@ CFLAGS +=-I ./target -I./platforms/pc # Define HOSTED_BMP_ONLY to '0' in order to build the hosted blackmagic # executable with support for other probes beside BMP. Default HOSTED_BMP_ONLY -# == 1 makes linking against the libftdi and libusb libraries unnecessary. +# == 1 on Windows makes linking against the libftdi and libusb libraries +# unnecessary. # This can be useful to minimize external dependencies, and make building on # windows systems easier and is default now. +ifneq (, $(findstring linux, $(SYS))) +HOSTED_BMP_ONLY ?= 0 +else HOSTED_BMP_ONLY ?= 1 +endif CFLAGS += -DHOSTED_BMP_ONLY=$(HOSTED_BMP_ONLY) ifneq (, $(findstring linux, $(SYS))) @@ -42,10 +47,14 @@ HIDAPILIB = 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 + $(shell pkg-config --exists libftdi1) + ifneq ($(.SHELLSTATUS), 0) + $(error Please install libftdi1 dependency or set HOSTED_BMP_ONLY to 1) + endif + LDFLAGS += -lusb-1.0 + CFLAGS += $(shell pkg-config --cflags libftdi1) + LDFLAGS += $(shell pkg-config --libs libftdi1) + CFLAGS += -Wno-missing-field-initializers endif ifneq ($(HOSTED_BMP_ONLY), 1) @@ -54,6 +63,10 @@ ifneq ($(HOSTED_BMP_ONLY), 1) ifneq (, $(findstring mingw, $(SYS))) SRC += hid.c else + $(shell pkg-config --exists $(HIDAPILIB)) + ifneq ($(.SHELLSTATUS), 0) + $(error Please install $(HIDAPILIB) dependency or set HOSTED_BMP_ONLY to 1) + endif CFLAGS += $(shell pkg-config --cflags $(HIDAPILIB)) LDFLAGS += $(shell pkg-config --libs $(HIDAPILIB)) endif From 7274f55ff4d62a3c620f6c362bdf2a127b70663c Mon Sep 17 00:00:00 2001 From: fabalthazar Date: Sat, 9 Oct 2021 21:17:58 +0200 Subject: [PATCH 2/4] Fixed return value of hosted blackmagic in erase mode --- src/platforms/pc/cl_utils.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 74b24bd6..6e8db4a6 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -351,7 +351,7 @@ static void display_target(int i, target *t, void *context) int cl_execute(BMP_CL_OPTIONS_t *opt) { - int res = -1; + int res = 0; int num_targets; if (opt->opt_tpwr) { platform_target_set_power(true); @@ -361,7 +361,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) platform_srst_set_val(true); platform_delay(1); platform_srst_set_val(false); - return 0; + return res; } if (opt->opt_connect_under_reset) DEBUG_INFO("Connecting under reset\n"); @@ -381,19 +381,20 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) } if (!num_targets) { DEBUG_WARN("No target found\n"); - return res; + return -1; } else { num_targets = target_foreach(display_target, &num_targets); } if (opt->opt_target_dev > num_targets) { DEBUG_WARN("Given target nummer %d not available max %d\n", opt->opt_target_dev, num_targets); - return res; + return -1; } target *t = target_attach_n(opt->opt_target_dev, &cl_controller); if (!t) { DEBUG_WARN("Can not attach to target %d\n", opt->opt_target_dev); + res = -1; goto target_detach; } /* List each defined RAM */ @@ -462,6 +463,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) int mmap_res = bmp_mmap(opt->opt_flash_file, &map); if (mmap_res) { DEBUG_WARN("Can not map file: %s. Aborting!\n", strerror(errno)); + res = -1; goto target_detach; } } else if (opt->opt_mode == BMP_MODE_FLASH_READ) { @@ -471,7 +473,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) if (read_file == -1) { DEBUG_WARN("Error opening flashfile %s for read: %s\n", opt->opt_flash_file, strerror(errno)); - return res; + res = -1; + goto target_detach; } } if (opt->opt_flash_size < map.size) @@ -485,7 +488,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) unsigned int erased = target_flash_erase(t, opt->opt_flash_start, opt->opt_flash_size); if (erased) { - DEBUG_WARN("Erased failed!\n"); + DEBUG_WARN("Erasure failed!\n"); + res = -1; goto free_map; } target_reset(t); @@ -497,7 +501,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) unsigned int erased = target_flash_erase(t, opt->opt_flash_start, map.size); if (erased) { - DEBUG_WARN("Erased failed!\n"); + DEBUG_WARN("Erasure failed!\n"); + res = -1; goto free_map; } else { DEBUG_INFO("Flashing %zu bytes at 0x%08" PRIx32 "\n", @@ -507,9 +512,10 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) /* Buffered write cares for padding*/ if (flashed) { DEBUG_WARN("Flashing failed!\n"); + res = -1; + goto free_map; } else { DEBUG_INFO("Success!\n"); - res = 0; } } target_flash_done(t); @@ -529,7 +535,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) if (!data) { DEBUG_WARN("Can not malloc memory for flash read/verify " "operation\n"); - return res; + res = -1; + goto free_map; } if (opt->opt_mode == BMP_MODE_FLASH_READ) DEBUG_INFO("Reading flash from 0x%08" PRIx32 " for %zu" @@ -563,7 +570,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) if (difference){ DEBUG_WARN("Verify failed at flash region 0x%08" PRIx32 "\n", flash_src); - return -1; + res = -1; + goto free_map; } flash += worksize; } else if (read_file != -1) { @@ -571,13 +579,12 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) if (written < worksize) { DEBUG_WARN("Read failed at flash region 0x%08" PRIx32 "\n", flash_src); - return -1; + res = -1; + goto free_map; } } flash_src += worksize; size -= worksize; - if (size <= 0) - res = 0; } uint32_t end_time = platform_time_ms(); if (read_file != -1) From 59282b6f66757eb109045e8d55fbf25dc9481283 Mon Sep 17 00:00:00 2001 From: fabalthazar Date: Sat, 9 Oct 2021 21:18:52 +0200 Subject: [PATCH 3/4] Fixed typography --- src/platforms/hosted/bmp_libusb.c | 2 +- src/platforms/pc/cl_utils.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platforms/hosted/bmp_libusb.c b/src/platforms/hosted/bmp_libusb.c index 9a5e6369..b866ee4a 100644 --- a/src/platforms/hosted/bmp_libusb.c +++ b/src/platforms/hosted/bmp_libusb.c @@ -220,7 +220,7 @@ int find_debuggers(BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info) type = BMP_TYPE_BMP; } else { if (desc.idProduct == PRODUCT_ID_BMP_BL) - DEBUG_WARN("BMP in botloader mode found. Restart or reflash!\n"); + DEBUG_WARN("BMP in bootloader mode found. Restart or reflash!\n"); continue; } } else if ((type == BMP_TYPE_NONE) && diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 6e8db4a6..88e16a0c 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -386,7 +386,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) num_targets = target_foreach(display_target, &num_targets); } if (opt->opt_target_dev > num_targets) { - DEBUG_WARN("Given target nummer %d not available max %d\n", + DEBUG_WARN("Given target number %d not available max %d\n", opt->opt_target_dev, num_targets); return -1; } @@ -438,7 +438,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) if (opt->opt_mode == BMP_MODE_SWJ_TEST) { switch (t->core[0]) { case 'M': - DEBUG_WARN("Continious read/write-back DEMCR. Abort with ^C\n"); + DEBUG_WARN("Continuous read/write-back DEMCR. Abort with ^C\n"); while(1) { uint32_t demcr; target_mem_read(t, &demcr, CORTEXM_DEMCR, 4); From e2d3161442443e7613b952bc5215aa2f2ca7d1dc Mon Sep 17 00:00:00 2001 From: fabalthazar Date: Sat, 9 Oct 2021 21:38:48 +0200 Subject: [PATCH 4/4] Removed -S message as debugger selection option since it is used for reading bytes --- src/platforms/hosted/bmp_libusb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/platforms/hosted/bmp_libusb.c b/src/platforms/hosted/bmp_libusb.c index b866ee4a..fdcb2efc 100644 --- a/src/platforms/hosted/bmp_libusb.c +++ b/src/platforms/hosted/bmp_libusb.c @@ -307,9 +307,8 @@ int find_debuggers(BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info) ((found_debuggers == 1) && (cl_opts->opt_list_only))) { if (!report) { if (found_debuggers > 1) - DEBUG_WARN("%d debuggers found!\nSelect with -P , " - "-s <(partial)serial no.> " - "and/or -S <(partial)description>\n", + DEBUG_WARN("%d debuggers found!\nSelect with -P " + "or -s <(partial)serial no.>\n", found_debuggers); report = true; goto rescan;