From 5b904ba60b7b666fdc113323eb3c8b7c7a88de85 Mon Sep 17 00:00:00 2001
From: jasper <jasper@openbsd.org>
Date: Thu, 2 Dec 2010 18:41:46 +0000
Subject: [PATCH] - update mspdebug to 0.13 - remove support for Olimex
 MSP430-JTAG-ISO which requires a linux-only ioctl.

---
 devel/mspdebug/Makefile               |  4 +--
 devel/mspdebug/distinfo               | 10 +++---
 devel/mspdebug/patches/patch-Makefile | 51 ++++++++++++++++-----------
 devel/mspdebug/patches/patch-bsl_c    | 10 +++---
 devel/mspdebug/patches/patch-olimex_c | 12 +++----
 devel/mspdebug/patches/patch-rf2500_c | 23 +++++++-----
 devel/mspdebug/patches/patch-uif_c    | 49 ++++++++++++++++++++++---
 7 files changed, 107 insertions(+), 52 deletions(-)

diff --git a/devel/mspdebug/Makefile b/devel/mspdebug/Makefile
index 0aaef0941f5..f732a156acd 100644
--- a/devel/mspdebug/Makefile
+++ b/devel/mspdebug/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.1.1.1 2010/12/02 10:35:04 jasper Exp $
+# $OpenBSD: Makefile,v 1.2 2010/12/02 18:41:46 jasper Exp $
 
 COMMENT=		debugger for use with MSP 430 MCUs
 
-DISTNAME=		mspdebug-0.10
+DISTNAME=		mspdebug-0.13
 CATEGORIES=		devel
 
 HOMEPAGE=		http://mspdebug.sourceforge.net/
diff --git a/devel/mspdebug/distinfo b/devel/mspdebug/distinfo
index 8d2b74be58c..5a9b90c210d 100644
--- a/devel/mspdebug/distinfo
+++ b/devel/mspdebug/distinfo
@@ -1,5 +1,5 @@
-MD5 (mspdebug-0.10.tar.gz) = ZTf2ZmRRqCQi1qWwG6SOnA==
-RMD160 (mspdebug-0.10.tar.gz) = 9mbp62s9UuHLEuwZ+lthOCG1jBg=
-SHA1 (mspdebug-0.10.tar.gz) = 93R9iGgXmWufARQNgpXqneHHDCs=
-SHA256 (mspdebug-0.10.tar.gz) = 93l1yZtA0zD4JYhxqw/SAz7ZdO8UmGS6ZkJZaKnddus=
-SIZE (mspdebug-0.10.tar.gz) = 75926
+MD5 (mspdebug-0.13.tar.gz) = 7z38BnGZHnRFY6FbK0fvkw==
+RMD160 (mspdebug-0.13.tar.gz) = ZarJfhMlP2k8PoKwyqoE+F/9HS8=
+SHA1 (mspdebug-0.13.tar.gz) = UzCjZShdygqYj7zHjY8xaCQ3Uho=
+SHA256 (mspdebug-0.13.tar.gz) = f3fL4rqyRc9QZHor0j6AP+IuLSGisJU+BVHr8+cvxI4=
+SIZE (mspdebug-0.13.tar.gz) = 91556
diff --git a/devel/mspdebug/patches/patch-Makefile b/devel/mspdebug/patches/patch-Makefile
index a515810aba4..a9388c39a9f 100644
--- a/devel/mspdebug/patches/patch-Makefile
+++ b/devel/mspdebug/patches/patch-Makefile
@@ -1,19 +1,10 @@
-$OpenBSD: patch-Makefile,v 1.1.1.1 2010/12/02 10:35:04 jasper Exp $
+$OpenBSD: patch-Makefile,v 1.2 2010/12/02 18:41:46 jasper Exp $
 
 - Add missing libraries and cflags.
 
---- Makefile.orig	Wed Aug  4 04:08:43 2010
-+++ Makefile	Thu Aug 12 12:58:14 2010
-@@ -15,7 +15,7 @@
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- 
--CC = gcc
-+CC ?= gcc
- INSTALL = /usr/bin/install
- PREFIX ?= /usr/local
- 
-@@ -24,7 +24,7 @@ ifdef WITHOUT_READLINE
+--- Makefile.orig	Mon Nov  8 22:40:57 2010
++++ Makefile	Thu Dec  2 13:06:08 2010
+@@ -26,17 +26,21 @@ ifdef WITHOUT_READLINE
  	READLINE_LIBS =
  else
  	READLINE_CFLAGS = -DUSE_READLINE
@@ -21,14 +12,34 @@ $OpenBSD: patch-Makefile,v 1.1.1.1 2010/12/02 10:35:04 jasper Exp $
 +	READLINE_LIBS = -lreadline -ltermcap
  endif
  
- # Mac OS X/MacPorts stuff
-@@ -57,7 +57,7 @@ mspdebug: main.o fet.o rf2500.o dis.o uif.o olimex.o i
-           util.o bsl.o sim.o symmap.o gdb.o btree.o rtools.o sym.o devcmd.o \
- 	  cproc.o vector.o cproc_util.o expr.o fet_error.o binfile.o fet_db.o \
- 	  usbutil.o titext.o srec.o device.o coff.o
+-# Mac OS X/MacPorts stuff
+ UNAME := $(shell sh -c 'uname -s')
+-ifeq ($(UNAME),Darwin)
+-	MACPORTS_CFLAGS = -I/opt/local/include
+-	MACPORTS_LDFLAGS = -L/opt/local/lib
++ifeq ($(UNAME),Darwin) # Mac OS X/MacPorts stuff
++	PORTS_CFLAGS = -I/opt/local/include
++	PORTS_LDFLAGS = -L/opt/local/lib
+ else
+-	MACPORTS_CFLAGS =
+-	MACPORTS_LDFLAGS =
++  ifeq ($(UNAME),OpenBSD) # OpenBSD Ports stuff
++	PORTS_CFLAGS = `pkg-config --cflags libelf libusb`
++	PORTS_LDFLAGS = `pkg-config --libs libelf libusb`
++  else
++	PORTS_CFLAGS =
++	PORTS_LDFLAGS =
++  endif
+ endif
+ 
+ MSPDEBUG_CFLAGS = -O1 -Wall -Wno-char-subscripts -ggdb
+@@ -60,7 +64,7 @@ mspdebug: main.o fet.o rf2500.o dis.o uif.o olimex.o i
+ 	  reader.o vector.o output_util.o expr.o fet_error.o binfile.o \
+ 	  fet_db.o usbutil.o titext.o srec.o device.o coff.o opdb.o output.o \
+ 	  cmddb.o stdcmd.o prog.o flash_bsl.o
 -	$(CC) $(LDFLAGS) $(MACPORTS_LDFLAGS) -o $@ $^ -lusb $(READLINE_LIBS)
-+	$(CC) $(LDFLAGS) $(MACPORTS_LDFLAGS) -o $@ $^ `pkg-config --libs libelf libusb` $(READLINE_LIBS)
++	$(CC) $(LDFLAGS) $(PORTS_LDFLAGS) -o $@ $^ -lusb $(READLINE_LIBS)
  
  .c.o:
 -	$(CC) $(CFLAGS) $(MACPORTS_CFLAGS) $(READLINE_CFLAGS) $(MSPDEBUG_CFLAGS) -o $@ -c $*.c
-+	$(CC) $(CFLAGS) `pkg-config --cflags libelf libusb` $(MACPORTS_CFLAGS) $(READLINE_CFLAGS) $(MSPDEBUG_CFLAGS) -o $@ -c $*.c
++	$(CC) $(CFLAGS) $(PORTS_CFLAGS) $(READLINE_CFLAGS) $(MSPDEBUG_CFLAGS) -o $@ -c $*.c
diff --git a/devel/mspdebug/patches/patch-bsl_c b/devel/mspdebug/patches/patch-bsl_c
index 976057b1e60..b5670db4a98 100644
--- a/devel/mspdebug/patches/patch-bsl_c
+++ b/devel/mspdebug/patches/patch-bsl_c
@@ -1,8 +1,8 @@
-$OpenBSD: patch-bsl_c,v 1.1.1.1 2010/12/02 10:35:04 jasper Exp $
---- bsl.c.orig	Thu Aug 12 12:21:18 2010
-+++ bsl.c	Thu Aug 12 12:22:36 2010
-@@ -30,7 +30,7 @@
- #include "util.h"
+$OpenBSD: patch-bsl_c,v 1.2 2010/12/02 18:41:46 jasper Exp $
+--- bsl.c.orig	Mon Nov  8 22:40:57 2010
++++ bsl.c	Thu Dec  2 13:05:14 2010
+@@ -31,7 +31,7 @@
+ #include "output.h"
  #include "fet_error.h"
  
 -#ifdef __APPLE__
diff --git a/devel/mspdebug/patches/patch-olimex_c b/devel/mspdebug/patches/patch-olimex_c
index 0079fbd8ac0..1fbfae7777d 100644
--- a/devel/mspdebug/patches/patch-olimex_c
+++ b/devel/mspdebug/patches/patch-olimex_c
@@ -1,7 +1,7 @@
-$OpenBSD: patch-olimex_c,v 1.2 2010/12/02 11:40:53 jasper Exp $
---- olimex.c.orig	Wed Aug  4 04:08:43 2010
-+++ olimex.c	Thu Aug 12 13:04:12 2010
-@@ -65,7 +65,7 @@ struct olimex_transport {
+$OpenBSD: patch-olimex_c,v 1.3 2010/12/02 18:41:46 jasper Exp $
+--- olimex.c.orig	Mon Nov  8 22:40:57 2010
++++ olimex.c	Thu Dec  2 13:05:14 2010
+@@ -66,7 +66,7 @@ struct olimex_transport {
  static int open_interface(struct olimex_transport *tr,
  			  struct usb_device *dev, int ino)
  {
@@ -10,7 +10,7 @@ $OpenBSD: patch-olimex_c,v 1.2 2010/12/02 11:40:53 jasper Exp $
  	int drv;
  	char drName[256];
  #endif
-@@ -81,7 +81,7 @@ static int open_interface(struct olimex_transport *tr,
+@@ -82,7 +82,7 @@ static int open_interface(struct olimex_transport *tr,
  		return -1;
  	}
  
@@ -18,4 +18,4 @@ $OpenBSD: patch-olimex_c,v 1.2 2010/12/02 11:40:53 jasper Exp $
 +#if defined(__linux__)
  	drv = usb_get_driver_np(tr->handle, tr->int_number, drName,
  				sizeof(drName));
- 	printf(__FILE__" : driver %d\n", drv);
+ 	printc(__FILE__" : driver %d\n", drv);
diff --git a/devel/mspdebug/patches/patch-rf2500_c b/devel/mspdebug/patches/patch-rf2500_c
index 278cdc4c470..9f3b3f56b51 100644
--- a/devel/mspdebug/patches/patch-rf2500_c
+++ b/devel/mspdebug/patches/patch-rf2500_c
@@ -1,24 +1,29 @@
-$OpenBSD: patch-rf2500_c,v 1.2 2010/12/02 11:40:53 jasper Exp $
+$OpenBSD: patch-rf2500_c,v 1.3 2010/12/02 18:41:46 jasper Exp $
 
 - usb_bulk_read() returns 0 on timeout, not -1
 
---- rf2500.c.orig	Sun Nov 28 12:04:17 2010
-+++ rf2500.c	Thu Dec  2 00:36:44 2010
-@@ -66,7 +66,7 @@ static int open_interface(struct rf2500_transport *tr,
+--- rf2500.c.orig	Mon Nov  8 22:40:57 2010
++++ rf2500.c	Thu Dec  2 13:31:01 2010
+@@ -67,7 +67,7 @@ static int open_interface(struct rf2500_transport *tr,
  		return -1;
  	}
  
 -#if !(defined(__APPLE__) || defined(WIN32))
-+#if defined(__linux__)
++#if defined (__linux__)
  	if (usb_detach_kernel_driver_np(tr->handle, tr->int_number) < 0)
- 		perror("rf2500: warning: can't "
+ 		pr_error("rf2500: warning: can't "
  			"detach kernel driver");
-@@ -215,7 +215,7 @@ transport_t rf2500_open(const char *devpath)
- 	/* Flush out lingering data */
+@@ -221,8 +221,12 @@ transport_t rf2500_open(const char *devpath)
+ #ifndef __APPLE__
  	while (usb_bulk_read(tr->handle, USB_FET_IN_EP,
  			     buf, sizeof(buf),
--			     100) >= 0);
++#if defined(__OpenBSD__)
 +			     100) > 0);
++#else
+ 			     100) >= 0);
+-#endif
++#endif /* __OpenBSD__ */
++#endif /* !__APPLE__ */
  
  	return (transport_t)tr;
  }
diff --git a/devel/mspdebug/patches/patch-uif_c b/devel/mspdebug/patches/patch-uif_c
index 0827df8ba06..c485f142cf8 100644
--- a/devel/mspdebug/patches/patch-uif_c
+++ b/devel/mspdebug/patches/patch-uif_c
@@ -1,12 +1,51 @@
-$OpenBSD: patch-uif_c,v 1.1.1.1 2010/12/02 10:35:04 jasper Exp $
---- uif.c.orig	Thu Aug 12 12:50:34 2010
-+++ uif.c	Thu Aug 12 12:50:48 2010
-@@ -28,7 +28,7 @@
- #include "uif.h"
+$OpenBSD: patch-uif_c,v 1.2 2010/12/02 18:41:46 jasper Exp $
+--- uif.c.orig	Mon Nov  8 22:40:57 2010
++++ uif.c	Thu Dec  2 13:05:36 2010
+@@ -25,7 +25,9 @@
+ #include <unistd.h>
+ #include <termios.h>
+ 
++#if defined(__linux__)
+ #include <linux/serial.h>
++#endif
+ #include <sys/ioctl.h>
+ #include <fcntl.h>
+ 
+@@ -33,7 +35,7 @@
  #include "util.h"
+ #include "output.h"
  
 -#ifdef __APPLE__
 +#if defined(__APPLE__) || defined(__OpenBSD__)
  #define B460800 460800
  #define B500000 500000
  #endif
+@@ -85,6 +87,7 @@ static void serial_destroy(transport_t tr_base)
+ 	free(tr);
+ }
+ 
++#if defined(__linux__)
+ static int open_olimex_iso(const char *device)
+ {
+         int fd = open(device, O_RDWR | O_NOCTTY);
+@@ -112,6 +115,7 @@ static int open_olimex_iso(const char *device)
+ 
+         return fd;
+ }
++#endif
+ 
+ transport_t uif_open(const char *device, uif_type_t type)
+ {
+@@ -138,8 +142,12 @@ transport_t uif_open(const char *device, uif_type_t ty
+ 		break;
+ 
+ 	case UIF_TYPE_OLIMEX_ISO:
++#if defined(__linux__)
+ 		printc("Trying to open Olimex (ISO) on %s...\n", device);
+ 		tr->serial_fd = open_olimex_iso(device);
++#else
++		printc_err("uif_open: ioctl TIOCSSERIAL not supported on this platform\n");
++#endif
+ 		break;
+ 	}
+