From 05adcd9bf5b36d099627aff6b73e463030ee417f Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 15 Apr 2020 17:36:26 +0200 Subject: [PATCH] remote.c: Compile only relevant functions. Do no compile firmware functions when compiling pc-hosted. --- src/Makefile | 8 +++++++- src/command.c | 12 ++++++------ src/gdb_packet.c | 2 +- src/include/gdb_if.h | 2 +- src/include/platform_support.h | 2 +- src/main.c | 2 +- src/morse.c | 2 +- src/platforms/libftdi/Makefile.inc | 3 ++- src/platforms/pc-hosted/Makefile.inc | 3 ++- src/platforms/pc-stlinkv2/Makefile.inc | 3 ++- src/platforms/stm32/usbuart.c | 2 +- src/remote.c | 2 ++ src/target/cortexm.c | 6 +++--- src/target/target.c | 2 +- 14 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/Makefile b/src/Makefile index 0072715..f95721c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -45,6 +45,7 @@ SRC = \ nrf51.c \ nxpke04.c \ platform.c \ + remote.c \ sam3x.c \ sam4l.c \ samd.c \ @@ -72,11 +73,16 @@ endif ifndef OWN_HL SRC += jtag_scan.c jtagtap.c swdptap.c -SRC += remote.c else CFLAGS += -DOWN_HL endif +ifdef PC_HOSTED +CFLAGS += -DPC_HOSTED=1 +else +CFLAGS += -DPC_HOSTED=0 +endif + OBJ = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(SRC))) $(TARGET): include/version.h $(OBJ) diff --git a/src/command.c b/src/command.c index 1059e33..372b8e9 100644 --- a/src/command.c +++ b/src/command.c @@ -60,7 +60,7 @@ static bool cmd_target_power(target *t, int argc, const char **argv); static bool cmd_traceswo(target *t, int argc, const char **argv); #endif static bool cmd_heapinfo(target *t, int argc, const char **argv); -#if defined(PLATFORM_HAS_DEBUG) && !defined(PC_HOSTED) +#if defined(PLATFORM_HAS_DEBUG) && (PC_HOSTED == 0) static bool cmd_debug_bmp(target *t, int argc, const char **argv); #endif @@ -85,14 +85,14 @@ const struct command_s cmd_list[] = { #endif #endif {"heapinfo", (cmd_handler)cmd_heapinfo, "Set semihosting heapinfo" }, -#if defined(PLATFORM_HAS_DEBUG) && !defined(PC_HOSTED) +#if defined(PLATFORM_HAS_DEBUG) && (PC_HOSTED == 0) {"debug_bmp", (cmd_handler)cmd_debug_bmp, "Output BMP \"debug\" strings to the second vcom: (enable|disable)"}, #endif {NULL, NULL, NULL} }; bool connect_assert_srst; -#if defined(PLATFORM_HAS_DEBUG) && !defined(PC_HOSTED) +#if defined(PLATFORM_HAS_DEBUG) && (PC_HOSTED == 0) bool debug_bmp; #endif long cortexm_wait_timeout = 2000; /* Timeout to wait for Cortex to react on halt command. */ @@ -135,7 +135,7 @@ bool cmd_version(target *t, int argc, char **argv) (void)t; (void)argc; (void)argv; -#if defined PC_HOSTED +#if PC_HOSTED == 1 gdb_outf("Black Magic Probe, PC-Hosted for " PLATFORM_IDENT ", Version " FIRMWARE_VERSION "\n"); #else @@ -389,7 +389,7 @@ static bool cmd_traceswo(target *t, int argc, const char **argv) } } } -#if defined(PLATFORM_HAS_DEBUG) && !defined(PC_HOSTED) && defined(ENABLE_DEBUG) +#if defined(PLATFORM_HAS_DEBUG) && (PC_HOSTED == 0) && defined(ENABLE_DEBUG) if (debug_bmp) { #if TRACESWO_PROTOCOL == 2 gdb_outf("baudrate: %lu ", baudrate); @@ -412,7 +412,7 @@ static bool cmd_traceswo(target *t, int argc, const char **argv) } #endif -#if defined(PLATFORM_HAS_DEBUG) && !defined(PC_HOSTED) +#if defined(PLATFORM_HAS_DEBUG) && (PC_HOSTED == 0) static bool cmd_debug_bmp(target *t, int argc, const char **argv) { (void)t; diff --git a/src/gdb_packet.c b/src/gdb_packet.c index f0f1f1d..6a01c89 100644 --- a/src/gdb_packet.c +++ b/src/gdb_packet.c @@ -47,7 +47,7 @@ int gdb_getpacket(char *packet, int size) packet[0] = gdb_if_getchar(); if (packet[0]==0x04) return 1; } while ((packet[0] != '$') && (packet[0] != REMOTE_SOM)); -#ifndef OWN_HL +#if PC_HOSTED == 0 if (packet[0]==REMOTE_SOM) { /* This is probably a remote control packet * - get and handle it */ diff --git a/src/include/gdb_if.h b/src/include/gdb_if.h index 1dc9e28..eed1b9a 100644 --- a/src/include/gdb_if.h +++ b/src/include/gdb_if.h @@ -21,7 +21,7 @@ #ifndef __GDB_IF_H #define __GDB_IF_H -#if !defined(NO_LIBOPENCM3) +#if PC_HOSTED == 0 #include void gdb_usb_out_cb(usbd_device *dev, uint8_t ep); #endif diff --git a/src/include/platform_support.h b/src/include/platform_support.h index 36bd7ae..a111354 100644 --- a/src/include/platform_support.h +++ b/src/include/platform_support.h @@ -24,7 +24,7 @@ # error "Include 'general.h' instead" #endif -#if defined(PC_HOSTED) +#if PC_HOSTED == 1 void platform_init(int argc, char **argv); #else void platform_init(void); diff --git a/src/main.c b/src/main.c index 26e8ffd..8895954 100644 --- a/src/main.c +++ b/src/main.c @@ -33,7 +33,7 @@ int main(int argc, char **argv) { -#if defined(PC_HOSTED) +#if PC_HOSTED == 1 platform_init(argc, argv); #else (void) argc; diff --git a/src/morse.c b/src/morse.c index 55db0ba..9ba4814 100644 --- a/src/morse.c +++ b/src/morse.c @@ -59,7 +59,7 @@ static char morse_repeat; void morse(const char *msg, char repeat) { -#if defined(PC_HOSTED) +#if PC_HOSTED == 1 if (msg) DEBUG("%s\n", msg); (void) repeat; diff --git a/src/platforms/libftdi/Makefile.inc b/src/platforms/libftdi/Makefile.inc index 12c4696..fab3b06 100644 --- a/src/platforms/libftdi/Makefile.inc +++ b/src/platforms/libftdi/Makefile.inc @@ -1,5 +1,5 @@ SYS = $(shell $(CC) -dumpmachine) -CFLAGS += -DPC_HOSTED -DNO_LIBOPENCM3 -DENABLE_DEBUG +CFLAGS += -DENABLE_DEBUG CFLAGS += $(shell pkg-config --cflags libftdi1) LDFLAGS += $(shell pkg-config --libs libftdi1) ifneq (, $(findstring mingw, $(SYS))) @@ -10,3 +10,4 @@ endif VPATH += platforms/pc SRC += timing.c cl_utils.c utils.c CFLAGS +=-I ./target -I./platforms/pc +PC_HOSTED = 1 \ No newline at end of file diff --git a/src/platforms/pc-hosted/Makefile.inc b/src/platforms/pc-hosted/Makefile.inc index 9493b0c..3d10dc1 100644 --- a/src/platforms/pc-hosted/Makefile.inc +++ b/src/platforms/pc-hosted/Makefile.inc @@ -1,6 +1,6 @@ TARGET=blackmagic_hosted SYS = $(shell $(CC) -dumpmachine) -CFLAGS += -DPC_HOSTED -DNO_LIBOPENCM3 -DENABLE_DEBUG +CFLAGS += -DENABLE_DEBUG CFLAGS +=-I ./target -I./platforms/pc ifneq (, $(findstring mingw, $(SYS))) SRC += serial_win.c @@ -13,3 +13,4 @@ SRC += serial_unix.c endif VPATH += platforms/pc SRC += cl_utils.c timing.c utils.c +PC_HOSTED = 1 diff --git a/src/platforms/pc-stlinkv2/Makefile.inc b/src/platforms/pc-stlinkv2/Makefile.inc index 299a815..70f6f8e 100644 --- a/src/platforms/pc-stlinkv2/Makefile.inc +++ b/src/platforms/pc-stlinkv2/Makefile.inc @@ -1,6 +1,6 @@ TARGET=blackmagic_stlinkv2 SYS = $(shell $(CC) -dumpmachine) -CFLAGS += -DPC_HOSTED -DNO_LIBOPENCM3 -DSTLINKV2 -DJTAG_HL -DENABLE_DEBUG +CFLAGS += -DSTLINKV2 -DJTAG_HL -DENABLE_DEBUG CFLAGS +=-I ./target -I./platforms/pc LDFLAGS += -lusb-1.0 ifneq (, $(findstring mingw, $(SYS))) @@ -11,3 +11,4 @@ endif VPATH += platforms/pc SRC += timing.c stlinkv2.c cl_utils.c utils.c OWN_HL = 1 +PC_HOSTED = 1 diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index f13ff10..d2dc215 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -263,7 +263,7 @@ enum { int rdi_write(int fn, const char *buf, size_t len) { (void)fn; -#if defined(PLATFORM_HAS_DEBUG) && !defined(PC_HOSTED) +#if defined(PLATFORM_HAS_DEBUG) if (debug_bmp) return len - usbuart_debug_write(buf, len); #else diff --git a/src/remote.c b/src/remote.c index dc44ff7..354e1b6 100644 --- a/src/remote.c +++ b/src/remote.c @@ -56,6 +56,7 @@ uint64_t remotehston(uint32_t limit, char *s) return ret; } +#if PC_HOSTED == 0 static void _respond(char respCode, uint64_t param) /* Send response to far end */ @@ -274,3 +275,4 @@ void remotePacketProcess(uint8_t i, char *packet) break; } } +#endif diff --git a/src/target/cortexm.c b/src/target/cortexm.c index 6f27379..051befd 100644 --- a/src/target/cortexm.c +++ b/src/target/cortexm.c @@ -38,7 +38,7 @@ #include -#ifdef PC_HOSTED +#if PC_HOSTED == 1 /* * pc-hosted semihosting does keyboard, file and screen i/o on the system @@ -1067,7 +1067,7 @@ static bool cortexm_vector_catch(target *t, int argc, char *argv[]) #define SYS_WRITEC 0x03 #define SYS_WRITE0 0x04 -#if !defined(PC_HOSTED) +#if PC_HOSTED == 0 /* probe memory access functions */ static void probe_mem_read(target *t __attribute__((unused)), void *probe_dest, target_addr target_src, size_t len) { @@ -1104,7 +1104,7 @@ static int cortexm_hostio_request(target *t) DEBUG("syscall 0"PRIx32"%"PRIx32" (%"PRIx32" %"PRIx32" %"PRIx32" %"PRIx32")\n", syscall, params[0], params[1], params[2], params[3]); switch (syscall) { -#if defined(PC_HOSTED) +#if PC_HOSTED == 1 /* code that runs in pc-hosted process. use linux system calls. */ diff --git a/src/target/target.c b/src/target/target.c index 7171da8..520c629 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -337,7 +337,7 @@ void target_detach(target *t) { t->detach(t); t->attached = false; -#if defined(PC_HOSTED) +#if PC_HOSTED == 1 # include "platform.h" platform_buffer_flush(); #endif