Merge pull request #939 from fabalthazar/hosted-return-val

Consistent return value and output of hosted blackmagic + HOSTED_BMP_ONLY=0 on Linux
This commit is contained in:
UweBonnes 2021-10-10 12:54:48 +02:00 committed by GitHub
commit 28623e6b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 24 deletions

View File

@ -5,10 +5,15 @@ CFLAGS +=-I ./target -I./platforms/pc
# Define HOSTED_BMP_ONLY to '0' in order to build the hosted blackmagic # 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 # 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 # This can be useful to minimize external dependencies, and make building on
# windows systems easier and is default now. # windows systems easier and is default now.
ifneq (, $(findstring linux, $(SYS)))
HOSTED_BMP_ONLY ?= 0
else
HOSTED_BMP_ONLY ?= 1 HOSTED_BMP_ONLY ?= 1
endif
CFLAGS += -DHOSTED_BMP_ONLY=$(HOSTED_BMP_ONLY) CFLAGS += -DHOSTED_BMP_ONLY=$(HOSTED_BMP_ONLY)
ifneq (, $(findstring linux, $(SYS))) ifneq (, $(findstring linux, $(SYS)))
@ -42,10 +47,14 @@ HIDAPILIB = hidapi
endif endif
ifneq ($(HOSTED_BMP_ONLY), 1) ifneq ($(HOSTED_BMP_ONLY), 1)
LDFLAGS += -lusb-1.0 $(shell pkg-config --exists libftdi1)
CFLAGS += $(shell pkg-config --cflags libftdi1) ifneq ($(.SHELLSTATUS), 0)
LDFLAGS += $(shell pkg-config --libs libftdi1) $(error Please install libftdi1 dependency or set HOSTED_BMP_ONLY to 1)
CFLAGS += -Wno-missing-field-initializers endif
LDFLAGS += -lusb-1.0
CFLAGS += $(shell pkg-config --cflags libftdi1)
LDFLAGS += $(shell pkg-config --libs libftdi1)
CFLAGS += -Wno-missing-field-initializers
endif endif
ifneq ($(HOSTED_BMP_ONLY), 1) ifneq ($(HOSTED_BMP_ONLY), 1)
@ -54,6 +63,10 @@ ifneq ($(HOSTED_BMP_ONLY), 1)
ifneq (, $(findstring mingw, $(SYS))) ifneq (, $(findstring mingw, $(SYS)))
SRC += hid.c SRC += hid.c
else 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)) CFLAGS += $(shell pkg-config --cflags $(HIDAPILIB))
LDFLAGS += $(shell pkg-config --libs $(HIDAPILIB)) LDFLAGS += $(shell pkg-config --libs $(HIDAPILIB))
endif endif

View File

@ -220,7 +220,7 @@ int find_debuggers(BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info)
type = BMP_TYPE_BMP; type = BMP_TYPE_BMP;
} else { } else {
if (desc.idProduct == PRODUCT_ID_BMP_BL) 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; continue;
} }
} else if ((type == BMP_TYPE_NONE) && } else if ((type == BMP_TYPE_NONE) &&
@ -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))) { ((found_debuggers == 1) && (cl_opts->opt_list_only))) {
if (!report) { if (!report) {
if (found_debuggers > 1) if (found_debuggers > 1)
DEBUG_WARN("%d debuggers found!\nSelect with -P <pos>, " DEBUG_WARN("%d debuggers found!\nSelect with -P <pos> "
"-s <(partial)serial no.> " "or -s <(partial)serial no.>\n",
"and/or -S <(partial)description>\n",
found_debuggers); found_debuggers);
report = true; report = true;
goto rescan; goto rescan;

View File

@ -351,7 +351,7 @@ static void display_target(int i, target *t, void *context)
int cl_execute(BMP_CL_OPTIONS_t *opt) int cl_execute(BMP_CL_OPTIONS_t *opt)
{ {
int res = -1; int res = 0;
int num_targets; int num_targets;
if (opt->opt_tpwr) { if (opt->opt_tpwr) {
platform_target_set_power(true); platform_target_set_power(true);
@ -361,7 +361,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
platform_srst_set_val(true); platform_srst_set_val(true);
platform_delay(1); platform_delay(1);
platform_srst_set_val(false); platform_srst_set_val(false);
return 0; return res;
} }
if (opt->opt_connect_under_reset) if (opt->opt_connect_under_reset)
DEBUG_INFO("Connecting under reset\n"); DEBUG_INFO("Connecting under reset\n");
@ -381,19 +381,20 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
} }
if (!num_targets) { if (!num_targets) {
DEBUG_WARN("No target found\n"); DEBUG_WARN("No target found\n");
return res; return -1;
} else { } else {
num_targets = target_foreach(display_target, &num_targets); num_targets = target_foreach(display_target, &num_targets);
} }
if (opt->opt_target_dev > 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); opt->opt_target_dev, num_targets);
return res; return -1;
} }
target *t = target_attach_n(opt->opt_target_dev, &cl_controller); target *t = target_attach_n(opt->opt_target_dev, &cl_controller);
if (!t) { if (!t) {
DEBUG_WARN("Can not attach to target %d\n", opt->opt_target_dev); DEBUG_WARN("Can not attach to target %d\n", opt->opt_target_dev);
res = -1;
goto target_detach; goto target_detach;
} }
/* List each defined RAM */ /* List each defined RAM */
@ -437,7 +438,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
if (opt->opt_mode == BMP_MODE_SWJ_TEST) { if (opt->opt_mode == BMP_MODE_SWJ_TEST) {
switch (t->core[0]) { switch (t->core[0]) {
case 'M': 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) { while(1) {
uint32_t demcr; uint32_t demcr;
target_mem_read(t, &demcr, CORTEXM_DEMCR, 4); target_mem_read(t, &demcr, CORTEXM_DEMCR, 4);
@ -462,6 +463,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
int mmap_res = bmp_mmap(opt->opt_flash_file, &map); int mmap_res = bmp_mmap(opt->opt_flash_file, &map);
if (mmap_res) { if (mmap_res) {
DEBUG_WARN("Can not map file: %s. Aborting!\n", strerror(errno)); DEBUG_WARN("Can not map file: %s. Aborting!\n", strerror(errno));
res = -1;
goto target_detach; goto target_detach;
} }
} else if (opt->opt_mode == BMP_MODE_FLASH_READ) { } 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) { if (read_file == -1) {
DEBUG_WARN("Error opening flashfile %s for read: %s\n", DEBUG_WARN("Error opening flashfile %s for read: %s\n",
opt->opt_flash_file, strerror(errno)); opt->opt_flash_file, strerror(errno));
return res; res = -1;
goto target_detach;
} }
} }
if (opt->opt_flash_size < map.size) 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, unsigned int erased = target_flash_erase(t, opt->opt_flash_start,
opt->opt_flash_size); opt->opt_flash_size);
if (erased) { if (erased) {
DEBUG_WARN("Erased failed!\n"); DEBUG_WARN("Erasure failed!\n");
res = -1;
goto free_map; goto free_map;
} }
target_reset(t); 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, unsigned int erased = target_flash_erase(t, opt->opt_flash_start,
map.size); map.size);
if (erased) { if (erased) {
DEBUG_WARN("Erased failed!\n"); DEBUG_WARN("Erasure failed!\n");
res = -1;
goto free_map; goto free_map;
} else { } else {
DEBUG_INFO("Flashing %zu bytes at 0x%08" PRIx32 "\n", 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*/ /* Buffered write cares for padding*/
if (flashed) { if (flashed) {
DEBUG_WARN("Flashing failed!\n"); DEBUG_WARN("Flashing failed!\n");
res = -1;
goto free_map;
} else { } else {
DEBUG_INFO("Success!\n"); DEBUG_INFO("Success!\n");
res = 0;
} }
} }
target_flash_done(t); target_flash_done(t);
@ -529,7 +535,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
if (!data) { if (!data) {
DEBUG_WARN("Can not malloc memory for flash read/verify " DEBUG_WARN("Can not malloc memory for flash read/verify "
"operation\n"); "operation\n");
return res; res = -1;
goto free_map;
} }
if (opt->opt_mode == BMP_MODE_FLASH_READ) if (opt->opt_mode == BMP_MODE_FLASH_READ)
DEBUG_INFO("Reading flash from 0x%08" PRIx32 " for %zu" DEBUG_INFO("Reading flash from 0x%08" PRIx32 " for %zu"
@ -563,7 +570,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
if (difference){ if (difference){
DEBUG_WARN("Verify failed at flash region 0x%08" DEBUG_WARN("Verify failed at flash region 0x%08"
PRIx32 "\n", flash_src); PRIx32 "\n", flash_src);
return -1; res = -1;
goto free_map;
} }
flash += worksize; flash += worksize;
} else if (read_file != -1) { } else if (read_file != -1) {
@ -571,13 +579,12 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
if (written < worksize) { if (written < worksize) {
DEBUG_WARN("Read failed at flash region 0x%08" PRIx32 "\n", DEBUG_WARN("Read failed at flash region 0x%08" PRIx32 "\n",
flash_src); flash_src);
return -1; res = -1;
goto free_map;
} }
} }
flash_src += worksize; flash_src += worksize;
size -= worksize; size -= worksize;
if (size <= 0)
res = 0;
} }
uint32_t end_time = platform_time_ms(); uint32_t end_time = platform_time_ms();
if (read_file != -1) if (read_file != -1)