diff --git a/Makefile b/Makefile index a3446b00..db9178f4 100644 --- a/Makefile +++ b/Makefile @@ -4,15 +4,18 @@ Q := @ endif PC_HOSTED = +NO_LIBOPENCM3 = ifeq ($(PROBE_HOST), libftdi) PC_HOSTED = true + NO_LIBOPENCM3 = true endif ifeq ($(PROBE_HOST), pc-stlinkv2) PC_HOSTED = true + NO_LIBOPENCM3 = true endif all: -ifndef PC_HOSTED +ifndef NO_LIBOPENCM3 $(Q)if [ ! -f libopencm3/Makefile ]; then \ echo "Initialising git submodules..." ;\ git submodule init ;\ @@ -23,7 +26,7 @@ endif $(Q)$(MAKE) $(MFLAGS) -C src clean: -ifndef PC_HOSTED +ifndef NO_LIBOPENCM3 $(Q)$(MAKE) $(MFLAGS) -C libopencm3 $@ endif $(Q)$(MAKE) $(MFLAGS) -C src $@ diff --git a/src/Makefile b/src/Makefile index 72132449..05f032e0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,12 +8,9 @@ MAKEFLAGS += --no-print-dir Q := @ endif -OPT_FLAGS ?= -O2 - CFLAGS += -Wall -Wextra -Werror -Wno-char-subscripts -Wno-cast-function-type \ - $(OPT_FLAGS) -std=gnu99 -g3 -MD \ + -std=gnu99 -g3 -MD \ -I. -Iinclude -Iplatforms/common -I$(PLATFORM_DIR) -LDFLAGS += $(OPT_FLAGS) ifeq ($(ENABLE_DEBUG), 1) CFLAGS += -DENABLE_DEBUG @@ -60,6 +57,10 @@ SRC = \ include $(PLATFORM_DIR)/Makefile.inc +OPT_FLAGS ?= -O2 +CFLAGS += $(OPT_FLAGS) +LDFLAGS += $(OPT_FLAGS) + ifndef TARGET TARGET=blackmagic endif @@ -72,7 +73,7 @@ ifndef OWN_HL SRC += jtag_scan.c jtagtap.c swdptap.c endif -OBJ = $(SRC:.c=.o) +OBJ = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(SRC))) $(TARGET): include/version.h $(OBJ) @echo " LD $@" @@ -82,6 +83,10 @@ $(TARGET): include/version.h $(OBJ) @echo " CC $<" $(Q)$(CC) $(CFLAGS) -c $< -o $@ +%.o: %.S + @echo " AS $<" + $(Q)$(CC) $(CFLAGS) -c $< -o $@ + %.bin: % @echo " OBJCOPY $@" $(Q)$(OBJCOPY) -O binary $^ $@ diff --git a/src/gdb_packet.c b/src/gdb_packet.c index f738996a..0396e0d3 100644 --- a/src/gdb_packet.c +++ b/src/gdb_packet.c @@ -120,7 +120,7 @@ void gdb_putpacket(const char *packet, int size) } } gdb_if_putchar('#', 0); - sprintf(xmit_csum, "%02X", csum); + snprintf(xmit_csum, sizeof(xmit_csum), "%02X", csum); gdb_if_putchar(xmit_csum[0], 0); gdb_if_putchar(xmit_csum[1], 1); #ifdef DEBUG_GDBPACKET diff --git a/src/include/gdb_if.h b/src/include/gdb_if.h index d2ad2439..1dc9e28d 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(PC_HOSTED) +#if !defined(NO_LIBOPENCM3) #include void gdb_usb_out_cb(usbd_device *dev, uint8_t ep); #endif diff --git a/src/platforms/libftdi/Makefile.inc b/src/platforms/libftdi/Makefile.inc index 06c07d76..0ddabe89 100644 --- a/src/platforms/libftdi/Makefile.inc +++ b/src/platforms/libftdi/Makefile.inc @@ -1,5 +1,5 @@ SYS = $(shell $(CC) -dumpmachine) -CFLAGS += -DPC_HOSTED -DENABLE_DEBUG +CFLAGS += -DPC_HOSTED -DNO_LIBOPENCM3 -DENABLE_DEBUG LDFLAGS += -lftdi1 ifneq (, $(findstring mingw, $(SYS))) LDFLAGS += -lusb-1.0 -lws2_32 diff --git a/src/platforms/pc-stlinkv2/Makefile.inc b/src/platforms/pc-stlinkv2/Makefile.inc index 53ec16a1..8762885d 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 -DSTLINKV2 -DJTAG_HL -DENABLE_DEBUG +CFLAGS += -DPC_HOSTED -DNO_LIBOPENCM3 -DSTLINKV2 -DJTAG_HL -DENABLE_DEBUG CFLAGS +=-I ./target LDFLAGS += -lusb-1.0 ifneq (, $(findstring mingw, $(SYS))) diff --git a/src/target/efm32.c b/src/target/efm32.c index fff186ba..4405d99a 100644 --- a/src/target/efm32.c +++ b/src/target/efm32.c @@ -611,7 +611,7 @@ bool efm32_probe(target *t) uint32_t ram_size = ram_kib * 0x400; uint32_t flash_page_size = device->flash_page_size; - sprintf(variant_string, "%c\b%c\b%s %d F%d %s", + snprintf(variant_string, sizeof(variant_string), "%c\b%c\b%s %d F%d %s", di_version + 48, (uint8_t)device_index + 32, device->name, part_number, flash_kib, device->description); diff --git a/src/target/samd.c b/src/target/samd.c index 588ca83c..3117f2ae 100644 --- a/src/target/samd.c +++ b/src/target/samd.c @@ -364,7 +364,7 @@ static void samd_add_flash(target *t, uint32_t addr, size_t length) target_add_flash(t, f); } -char variant_string[40]; +char variant_string[60]; bool samd_probe(target *t) { uint32_t cid = samd_read_cid(t); @@ -390,15 +390,15 @@ bool samd_probe(target *t) /* Part String */ if (protected) { - sprintf(variant_string, - "Atmel SAMD%d%c%dA%s (rev %c) (PROT=1)", - samd.series, samd.pin, samd.mem, - samd.package, samd.revision); + snprintf(variant_string, sizeof(variant_string), + "Atmel SAMD%d%c%dA%s (rev %c) (PROT=1)", + samd.series, samd.pin, samd.mem, + samd.package, samd.revision); } else { - sprintf(variant_string, - "Atmel SAMD%d%c%dA%s (rev %c)", - samd.series, samd.pin, samd.mem, - samd.package, samd.revision); + snprintf(variant_string, sizeof(variant_string), + "Atmel SAMD%d%c%dA%s (rev %c)", + samd.series, samd.pin, samd.mem, + samd.package, samd.revision); } /* Setup Target */