kopia lustrzana https://github.com/stlink-org/stlink
				
				
				
			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
							rodzic
							
								
									27cbdfaa6e
								
							
						
					
					
						commit
						105e266a05
					
				
							
								
								
									
										31
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										31
									
								
								Makefile
								
								
								
								
							|  | @ -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 | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
|  | @ -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 */ | ||||
|   { | ||||
|  |  | |||
|  | @ -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) | ||||
| 
 | ||||
|  |  | |||
|  | @ -91,11 +91,6 @@ 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....
 | ||||
|  | @ -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,6 +144,12 @@ int main(int argc, char** argv) { | |||
| 			} | ||||
| 			break; | ||||
| 		} | ||||
| #endif | ||||
| 
 | ||||
| 		default: { | ||||
| 			fprintf(stderr, HelpStr, NULL); | ||||
| 			return 1; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) { | ||||
|  |  | |||
|  | @ -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
 | ||||
|  |  | |||
|  | @ -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[]) { | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Ned Konz
						Ned Konz