From c3a3f7737f94a138e0abcdfab2518049b629f496 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Tue, 10 Dec 2019 21:26:35 +0100 Subject: [PATCH] Hosted: Allow command line interaction. --- src/platforms/pc-hosted/Makefile.inc | 5 +++-- src/platforms/pc-hosted/platform.c | 30 ++++++++++++++-------------- src/platforms/pc/cl_utils.c | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/platforms/pc-hosted/Makefile.inc b/src/platforms/pc-hosted/Makefile.inc index 7af7743..8a35408 100644 --- a/src/platforms/pc-hosted/Makefile.inc +++ b/src/platforms/pc-hosted/Makefile.inc @@ -1,7 +1,8 @@ TARGET=blackmagic_hosted SYS = $(shell $(CC) -dumpmachine) -CFLAGS += -DPC_HOSTED -DNO_LIBOPENCM3 -DENABLE_DEBUG +CFLAGS += -DPC_HOSTED -DNO_LIBOPENCM3 -DENABLE_DEBUG -I CFLAGS += $(shell pkg-config --cflags libftdi1) +CFLAGS +=-I ./target -I./platforms/pc LDFLAGS += $(shell pkg-config --libs libftdi1) ifneq (, $(findstring mingw, $(SYS))) LDFLAGS += -lusb-1.0 -lws2_32 @@ -10,4 +11,4 @@ else ifneq (, $(findstring cygwin, $(SYS))) LDFLAGS += -lusb-1.0 -lws2_32 endif VPATH += platforms/pc -SRC += timing.c \ +SRC += cl_utils.c timing.c diff --git a/src/platforms/pc-hosted/platform.c b/src/platforms/pc-hosted/platform.c index ca88d31..d972b4e 100644 --- a/src/platforms/pc-hosted/platform.c +++ b/src/platforms/pc-hosted/platform.c @@ -37,6 +37,8 @@ #include #include +#include "cl_utils.h" + /* Allow 100mS for responses to reach us */ #define RESP_TIMEOUT (100) @@ -93,29 +95,20 @@ int set_interface_attribs (int fd, int speed, int parity) void platform_init(int argc, char **argv) { - int c; + BMP_CL_OPTIONS_t cl_opts = {0}; + cl_opts.opt_idstring = "Blackmagic Debug Probe Remote"; + cl_init(&cl_opts, argc, argv); char construct[PLATFORM_MAX_MSG_SIZE]; - char *serial = NULL; - while((c = getopt(argc, argv, "s:")) != -1) { - switch(c) - { - case 's': - serial = optarg; - break; - } - } printf("\nBlack Magic Probe (" FIRMWARE_VERSION ")\n"); printf("Copyright (C) 2019 Black Sphere Technologies Ltd.\n"); printf("License GPLv3+: GNU GPL version 3 or later " "\n\n"); - assert(gdb_if_init() == 0); - - f=open(serial,O_RDWR|O_SYNC|O_NOCTTY); + f=open(cl_opts.opt_serial,O_RDWR|O_SYNC|O_NOCTTY); if (f<0) { - fprintf(stderr,"Couldn't open serial port %s\n",serial); + fprintf(stderr,"Couldn't open serial port %s\n", cl_opts.opt_serial); exit(-1); } @@ -124,7 +117,7 @@ void platform_init(int argc, char **argv) exit(-1); } - c=snprintf(construct,PLATFORM_MAX_MSG_SIZE,"%s",REMOTE_START_STR); + int c=snprintf(construct,PLATFORM_MAX_MSG_SIZE,"%s",REMOTE_START_STR); platform_buffer_write((uint8_t *)construct,c); c=platform_buffer_read((uint8_t *)construct, PLATFORM_MAX_MSG_SIZE); @@ -135,6 +128,13 @@ void platform_init(int argc, char **argv) } printf("Remote is %s\n",&construct[1]); + if (cl_opts.opt_mode != BMP_MODE_DEBUG) { + int ret = cl_execute(&cl_opts); + close(f); + exit(ret); + } else { + assert(gdb_if_init() == 0); + } } bool platform_target_get_power(void) diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 2bdac9f..45d5ea6 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -/* This file allows pc-hosted BMP platforms to erase and flash a +/* This file allows pc-hosted BMP platforms to erase or read/verify/flash a * binary file from the command line. */