Allowed CONFIG_USE_LIBSG=0 to suppress STLink/V1 compilation

This will let people with Macintosh OS/X computers compile and use stlink with STLink/V2 devices, as libsg3 is not available for that platform.
pull/16/head
Ned Konz 2011-10-20 19:21:43 -07:00
rodzic 27cbdfaa6e
commit 105e266a05
7 zmienionych plików z 78 dodań i 28 usunięć

Wyświetl plik

@ -1,21 +1,36 @@
# make ... for both libusb and libsg
#
# make CONFIG_USE_LIBSG=0 ...
# for just libusb
#
VPATH=src
SOURCES_LIB=stlink-common.c stlink-usb.c stlink-sg.c
SOURCES_LIB=stlink-common.c stlink-usb.c
OBJS_LIB=$(SOURCES_LIB:.c=.o)
TEST_PROGRAMS=test_usb
LDFLAGS=-lusb-1.0 -L. -lstlink
ifeq ($(CONFIG_USE_LIBSG),)
CONFIG_USE_LIBSG=1
endif
ifneq ($(CONFIG_USE_LIBSG),0)
SOURCES_LIB+=stlink-sg.c
CFLAGS+=-DCONFIG_USE_LIBSG=1
LDFLAGS+=-lsgutils2
TEST_PROGRAMS+=test_sg
endif
CFLAGS+=-g
CFLAGS+=-DCONFIG_USE_LIBUSB
CFLAGS+=-DCONFIG_USE_LIBSG
CFLAGS+=-DDEBUG
CFLAGS+=-DCONFIG_USE_LIBUSB=1
CFLAGS+=-DDEBUG=1
CFLAGS+=-std=gnu99
CFLAGS+=-Wall -Wextra
LDFLAGS=-lstlink -lusb-1.0 -lsgutils2 -L.
LIBRARY=libstlink.a
all: $(LIBRARY) flash gdbserver test_usb test_sg
all: $(LIBRARY) flash gdbserver $(TEST_PROGRAMS)
$(LIBRARY): $(OBJS_LIB)
@echo "objs are $(OBJS_LIB)"
@ -48,7 +63,7 @@ distclean: clean
$(MAKE) -C gdbserver clean
flash:
$(MAKE) -C flash
$(MAKE) -C flash CONFIG_USE_LIBSG="$(CONFIG_USE_LIBSG)"
gdbserver:
$(MAKE) -C gdbserver

Wyświetl plik

@ -1,14 +1,27 @@
# make ... for both libusb and libsg
#
# make CONFIG_USE_LIBSG=0 ...
# for just libusb
#
CC=gcc
CFLAGS+=-g
CFLAGS+=-DCONFIG_USE_LIBUSB
CFLAGS+=-DCONFIG_USE_LIBSG
CFLAGS+=-DCONFIG_USE_LIBUSB=1
CFLAGS+=-DDEBUG
CFLAGS+=-std=gnu99
CFLAGS+=-Wall -Wextra
CFLAGS+=-I../src
LDFLAGS=-L.. -lstlink -lusb-1.0 -lsgutils2
LDFLAGS=-lusb-1.0 -L.. -lstlink
ifeq ($(CONFIG_USE_LIBSG),)
CONFIG_USE_LIBSG=1
endif
ifneq ($(CONFIG_USE_LIBSG),0)
CFLAGS+=-DCONFIG_USE_LIBSG=1
LDFLAGS+=-lsgutils2
endif
SRCS=main.c
OBJS=$(SRCS:.c=.o)

Wyświetl plik

@ -86,9 +86,14 @@ int main(int ac, char** av)
if (o.devname != NULL) /* stlinkv1 */
{
#if CONFIG_USE_LIBSG
static const int scsi_verbose = 2;
sl = stlink_quirk_open(o.devname, scsi_verbose);
if (sl == NULL) goto on_error;
#else
printf("not compiled for use with STLink/V1");
goto on_error;
#endif
}
else /* stlinkv2 */
{

Wyświetl plik

@ -1,13 +1,24 @@
# make ... for both libusb and libsg
#
# make CONFIG_USE_LIBSG=0 ...
# for just libusb
#
PRG := st-util
OBJS = gdb-remote.o gdb-server.o
CFLAGS+=-g -Wall -Werror -std=gnu99 -I../src
CFLAGS+=-DCONFIG_USE_LIBUSB
CFLAGS+=-DCONFIG_USE_LIBSG
LIBS := -lstlink -lusb-1.0 -lsgutils2
LDFLAGS+=$(LIBS) -L..
CFLAGS+=-DCONFIG_USE_LIBUSB=1
LDFLAGS=-lusb-1.0 -L.. -lstlink
ifeq ($(CONFIG_USE_LIBSG),)
CONFIG_USE_LIBSG=1
endif
ifneq ($(CONFIG_USE_LIBSG),0)
CFLAGS+=-DCONFIG_USE_LIBSG=1
LDFLAGS+=-lsgutils2
endif
all: $(PRG)

Wyświetl plik

@ -91,15 +91,10 @@ int main(int argc, char** argv) {
switch(argc) {
default: {
fprintf(stderr, HelpStr, NULL);
return 1;
}
case 3 : {
//sl = stlink_quirk_open(argv[2], 0);
// FIXME - hardcoded to usb....
sl = stlink_open_usb(10);
// FIXME - hardcoded to usb....
sl = stlink_open_usb(10);
if(sl == NULL) return 1;
break;
}
@ -111,6 +106,7 @@ int main(int argc, char** argv) {
}
}
#if CONFIG_USE_LIBSG
case 1 : { // Search ST-LINK (from /dev/sg0 to /dev/sg99)
const int DevNumMax = 99;
int ExistDevCount = 0;
@ -148,11 +144,17 @@ int main(int argc, char** argv) {
}
break;
}
#endif
default: {
fprintf(stderr, HelpStr, NULL);
return 1;
}
}
if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
stlink_exit_dfu_mode(sl);
}
if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
stlink_exit_dfu_mode(sl);
}
if(stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) {
stlink_enter_swd_mode(sl);

Wyświetl plik

@ -80,12 +80,14 @@
#include <sys/stat.h>
#include <sys/mman.h>
#include "stlink-common.h"
#if CONFIG_USE_LIBSG
// sgutils2 (apt-get install libsgutils2-dev)
#include <scsi/sg_lib.h>
#include <scsi/sg_pt.h>
#include "stlink-common.h"
#include "stlink-sg.h"
#endif
// Suspends execution of the calling process for

Wyświetl plik

@ -6,8 +6,10 @@
#include <stdio.h>
#include <stdlib.h>
#if CONFIG_USE_LIBSG
#include <scsi/sg_lib.h>
#include <scsi/sg_pt.h>
#endif
#include "stlink-common.h"
int main(int argc, char *argv[]) {
@ -210,4 +212,4 @@ int main(int argc, char *argv[]) {
//fflush(stderr); fflush(stdout);
return EXIT_SUCCESS;
}
}