Parcourir la source

Added firmware update support to scsi2sd-util6

Michael McMaster il y a 9 ans
Parent
commit
4318e13647
100 fichiers modifiés avec 15193 ajouts et 754 suppressions
  1. BIN
      lib/SCSI2SD/doc/SCSI2SD_QuickStartGuide.odt
  2. BIN
      lib/SCSI2SD/rtl/fpga_bitmap.o
  3. 2 2
      lib/SCSI2SD/src/firmware/config.c
  4. 22 47
      lib/SCSI2SD/src/firmware/disk.c
  5. 8 5
      lib/SCSI2SD/src/firmware/main.c
  6. 0 10
      lib/SCSI2SD/src/firmware/scsi.c
  7. 67 32
      lib/SCSI2SD/src/firmware/scsiPhy.c
  8. 1 37
      lib/SCSI2SD/src/firmware/scsiPhy.h
  9. 20 570
      lib/SCSI2SD/src/firmware/sd.c
  10. 3 42
      lib/SCSI2SD/src/firmware/sd.h
  11. 65 0
      lib/SCSI2SD/src/scsi2sd-util6/Dfu.cc
  12. 48 0
      lib/SCSI2SD/src/scsi2sd-util6/Dfu.hh
  13. 41 7
      lib/SCSI2SD/src/scsi2sd-util6/Makefile
  14. 2 1
      lib/SCSI2SD/src/scsi2sd-util6/SCSI2SD_HID.cc
  15. 1 1
      lib/SCSI2SD/src/scsi2sd-util6/SCSI2SD_HID.hh
  16. 1630 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/Doxyfile
  17. 162 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/Makefile
  18. 21 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/README.txt
  19. 70 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/TerminalWx.cbp
  20. 32 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/TestApp.cpp
  21. 20 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/TestApp.h
  22. 116 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/TestMain.cpp
  23. 54 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/TestMain.h
  24. 481 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/lgpl-2.0.txt
  25. 53 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/licence3.txt
  26. 757 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/actions.cpp
  27. 161 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/gterm.cpp
  28. 355 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/gterm.hpp
  29. 382 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/keytrans.cpp
  30. 148 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/states.cpp
  31. 227 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/utils.cpp
  32. 53 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/vt52_states.cpp
  33. 1925 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/taTelnet/wxterm.cpp
  34. 206 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/taTelnet/wxterm.h
  35. 25 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/terminalinputevent.cpp
  36. 48 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/terminalinputevent.h
  37. 79 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/terminalwx.cpp
  38. 62 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/terminalwx.h
  39. 37 0
      lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/wxsmith/Testframe.wxs
  40. 24 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/.gitignore
  41. 34 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/AUTHORS
  42. 340 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/COPYING
  43. 103 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/ChangeLog
  44. 20 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/DEVICES.txt
  45. 19 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/INSTALL
  46. 3 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/Makefile.am
  47. 21 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/README
  48. 13 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/TODO
  49. 2 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/autogen.sh
  50. 40 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/configure.ac
  51. 77 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/README
  52. 60 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/dsonano.lsusb
  53. 58 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/lpclink.lsusb
  54. 203 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/lpclink2.lsusb
  55. 60 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/opc-20.lsusb
  56. 109 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/openmoko-freerunner-dfumode.lsusb
  57. 179 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/openmoko-freerunner.lsusb
  58. 182 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/openmoko-neo1973.lsusb
  59. 60 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/openpcd.lsusb
  60. 59 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/qi-hardware-atusb.lsusb
  61. 70 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/simtrace.lsusb
  62. 60 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/sparkcore.lsusb
  63. 48 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/stm32f107.bin-download
  64. 60 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/stm32f107.lsusb
  65. 36 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/stm32f4discovery.bin-download
  66. 80 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/stm32f4discovery.lsusb
  67. 269 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/tdk-bluetooth.lsusb
  68. 192 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/dfuse-pack.py
  69. 4 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/doc/40-dfuse.rules
  70. 2 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/doc/Makefile.am
  71. 21 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/doc/SPEC-differences.txt
  72. 248 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/doc/dfu-util.1
  73. 10 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/msvc/README_msvc.txt
  74. 100 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/msvc/dfu-suffix_2010.vcxproj
  75. 54 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/msvc/dfu-util_2010.sln
  76. 120 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/msvc/dfu-util_2010.vcxproj
  77. 28 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/Makefile.am
  78. 357 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu.c
  79. 133 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu.h
  80. 444 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_file.c
  81. 60 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_file.h
  82. 197 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_load.c
  83. 7 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_load.h
  84. 418 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_util.c
  85. 35 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_util.h
  86. 672 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfuse.c
  87. 35 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfuse.h
  88. 198 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfuse_mem.c
  89. 44 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfuse_mem.h
  90. 691 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/main.c
  91. 71 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/portable.h
  92. 176 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/prefix.c
  93. 56 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/quirks.c
  94. 27 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/quirks.h
  95. 176 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/suffix.c
  96. 103 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/usb_dfu.h
  97. 174 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/www/build.html
  98. 414 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/www/dfu-util.1.html
  99. 135 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/www/dfuse.html
  100. 118 0
      lib/SCSI2SD/src/scsi2sd-util6/dfu-util/www/index.html

BIN
lib/SCSI2SD/doc/SCSI2SD_QuickStartGuide.odt


BIN
lib/SCSI2SD/rtl/fpga_bitmap.o


+ 2 - 2
lib/SCSI2SD/src/firmware/config.c

@@ -37,7 +37,7 @@
 
 #include <string.h>
 
-static const uint16_t FIRMWARE_VERSION = 0x0603;
+static const uint16_t FIRMWARE_VERSION = 0x0604;
 
 // 1 flash row
 static const uint8_t DEFAULT_CONFIG[128] =
@@ -140,7 +140,7 @@ sdInfoCommand()
 static void
 scsiTestCommand()
 {
-	int resultCode = 0; // TODO scsiSelfTest();
+	int resultCode = scsiSelfTest();
 	uint8_t response[] =
 	{
 		resultCode == 0 ? S2S_CFG_STATUS_GOOD : S2S_CFG_STATUS_ERR,

+ 22 - 47
lib/SCSI2SD/src/firmware/disk.c

@@ -16,6 +16,8 @@
 //	You should have received a copy of the GNU General Public License
 //	along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
 
+#include "stm32f2xx.h"
+
 #include "scsi.h"
 #include "scsiPhy.h"
 #include "config.h"
@@ -546,7 +548,7 @@ void scsiDiskPoll()
 		int prep = 0;
 		int i = 0;
 		int scsiActive = 0;
-		// int sdActive = 0;
+		int sdActive = 0;
 		while ((i < totalSDSectors) &&
 			likely(scsiDev.phase == DATA_IN) &&
 			likely(!scsiDev.resetFlag))
@@ -554,64 +556,39 @@ void scsiDiskPoll()
 			// Wait for the next DMA interrupt. It's beneficial to halt the
 			// processor to give the DMA controller more memory bandwidth to
 			// work with.
-#if 0
-			int scsiBusy = 1;
-			int sdBusy = 1;
-			while (scsiBusy && sdBusy)
+			if (sdActive && scsiActive)
 			{
-				uint8_t intr = CyEnterCriticalSection();
-				scsiBusy = scsiDMABusy();
-				sdBusy = sdDMABusy();
-				if (scsiBusy && sdBusy)
-				{
-					__WFI();
-				}
-				CyExitCriticalSection(intr);
+				__WFI();
 			}
-#endif
 
-#if 0
-			if (sdActive && !sdBusy && sdReadSectorDMAPoll())
+			if (sdActive && sdReadDMAPoll())
 			{
+				prep += sdActive;
 				sdActive = 0;
-				prep++;
 			}
 
-			// Usually SD is slower than the SCSI interface.
-			// Prioritise starting the read of the next sector over starting a
-			// SCSI transfer for the last sector
-			// ie. NO "else" HERE.
 			if (!sdActive &&
 				(prep - i < buffers) &&
 				(prep < totalSDSectors))
 			{
 				// Start an SD transfer if we have space.
-				if (transfer.multiBlock)
+				uint32_t startBuffer = prep % buffers;
+				uint32_t sectors = totalSDSectors - prep;
+				if (!scsiActive && prep == i)
 				{
-					sdReadMultiSectorDMA(&scsiDev.data[SD_SECTOR_SIZE * (prep % buffers)]);
+					sectors = 1; // We need to get some data to send ASAP !
 				}
 				else
 				{
-					sdReadSingleSectorDMA(sdLBA + prep, &scsiDev.data[SD_SECTOR_SIZE * (prep % buffers)]);
+					uint32_t freeBuffers = buffers - (prep - i);
+					uint32_t contiguousBuffers = buffers - startBuffer;
+					freeBuffers = freeBuffers < contiguousBuffers
+						? freeBuffers : contiguousBuffers;
+					sectors = sectors < freeBuffers ? sectors : freeBuffers;
 				}
-				sdActive = 1;
-			}
-#endif
-#if 0
-			uint32_t maxSectors = sizeof(scsiDev.data) / SD_SECTOR_SIZE;
-			uint32_t rem = totalSDSectors - i;
-			uint32_t sectors =
-				rem < maxSectors ? rem : maxSectors;
-			sdTmpRead(&scsiDev.data[0], i + sdLBA, sectors);
-			scsiWrite(&scsiDev.data[0], sectors * SD_SECTOR_SIZE);
-			i += sectors;
-#endif
-			if ((prep - i < buffers) &&
-				(prep < totalSDSectors))
-			{
-				// TODO MM Blocking reads are bad mmkay
-				sdTmpRead(&scsiDev.data[SD_SECTOR_SIZE * (prep % buffers)], sdLBA + prep, 1);
-				prep++;
+				sdReadDMA(sdLBA + prep, sectors, &scsiDev.data[SD_SECTOR_SIZE * startBuffer]);
+
+				sdActive = sectors;
 			}
 
 			if (scsiActive && scsiPhyComplete() && scsiWriteDMAPoll())
@@ -639,9 +616,7 @@ void scsiDiskPoll()
 			likely(scsiDev.phase == DATA_IN) &&
 			likely(!scsiDev.resetFlag))
 		{
-#if 0
-		_WFI();
-#endif
+			__WFI();
 		}
 
 
@@ -852,14 +827,14 @@ void scsiDiskReset()
 	transfer.currentBlock = 0;
 
 	// Cancel long running commands!
+#if 0
 	if (
 		((scsiDev.boardCfg.flags & S2S_CFG_ENABLE_CACHE) == 0) ||
 			(transfer.multiBlock == 0)
 		)
+#endif
 	{
-#if 0
 		sdCompleteTransfer();
-#endif
 	}
 
 	transfer.multiBlock = 0;

+ 8 - 5
lib/SCSI2SD/src/firmware/main.c

@@ -106,19 +106,22 @@ void mainLoop()
 		}
 		else
 		{
-#if 0
 			// Wait for our 1ms timer to save some power.
 			// There's an interrupt on the SEL signal to ensure we respond
 			// quickly to any SCSI commands. The selection abort time is
 			// only 250us, and new SCSI-3 controllers time-out very
 			// not long after that, so we need to ensure we wake up quickly.
-			uint8_t interruptState = CyEnterCriticalSection();
-			if (!SCSI_ReadFilt(SCSI_Filt_SEL))
+			uint32_t interruptState = __get_PRIMASK();
+			__disable_irq();
+
+			if (!*SCSI_STS_SELECTED)
 			{
 				__WFI(); // Will wake on interrupt, regardless of mask
 			}
-			CyExitCriticalSection(interruptState);
-#endif
+			if (!interruptState)
+			{
+				__enable_irq();
+			}
 		}
 	}
 	else if (scsiDev.phase >= 0)

+ 0 - 10
lib/SCSI2SD/src/firmware/scsi.c

@@ -536,16 +536,6 @@ static void process_SelectionPhase()
 
 	uint8_t selStatus = *SCSI_STS_SELECTED;
 
-#if 0
-	int sel = SCSI_ReadFilt(SCSI_Filt_SEL);
-	int bsy = SCSI_ReadFilt(SCSI_Filt_BSY);
-	int io = SCSI_ReadPin(SCSI_In_IO);
-
-	// Only read these pins AFTER SEL and BSY - we don't want to catch them
-	// during a transition period.
-	uint8_t mask = scsiReadDBxPins();
-	int atnFlag = SCSI_ReadFilt(SCSI_Filt_ATN);
-#endif
 	int tgtIndex;
 	TargetState* target = NULL;
 	for (tgtIndex = 0; tgtIndex < S2S_MAX_TARGETS; ++tgtIndex)

+ 67 - 32
lib/SCSI2SD/src/firmware/scsiPhy.c

@@ -212,17 +212,12 @@ scsiRead(uint8_t* data, uint32_t count)
 			// Wait for the next DMA interrupt (or the 1ms systick)
 			// It's beneficial to halt the processor to
 			// give the DMA controller more memory bandwidth to work with.
-#if 0
 			__WFI();
-#endif
 			trace(trace_spinReadDMAPoll);
 
 			while (!scsiReadDMAPoll() && likely(!scsiDev.resetFlag))
 			{
-#if 0
-// TODO NEED SCSI DMA IRQs
-			__WFI();
-#endif
+				__WFI();
 			};
 		}
 
@@ -336,21 +331,19 @@ scsiWrite(const uint8_t* data, uint32_t count)
 			// Wait for the next DMA interrupt (or the 1ms systick)
 			// It's beneficial to halt the processor to
 			// give the DMA controller more memory bandwidth to work with.
-#if 0
 			__WFI();
-#endif
 			trace(trace_spinReadDMAPoll);
 
 			while (!scsiWriteDMAPoll() && likely(!scsiDev.resetFlag))
 			{
-#if 0
-// TODO NEED SCSI DMA IRQs
-			__WFI();
-#endif
+				__WFI();
 			};
 		}
 
-		while (!scsiPhyComplete() && likely(!scsiDev.resetFlag)) {}
+		while (!scsiPhyComplete() && likely(!scsiDev.resetFlag))
+		{
+			__WFI();
+		}
 
 #if FIFODEBUG
 		if (!scsiPhyFifoAltEmpty()) {
@@ -360,14 +353,12 @@ scsiWrite(const uint8_t* data, uint32_t count)
 #endif
 
 		scsiPhyFifoFlip();
-#if 0
-// TODO NEED SCSI IRQs
-			__WFI();
-#endif
-
 		i += chunk;
 	}
-	while (!scsiPhyComplete() && likely(!scsiDev.resetFlag)) {}
+	while (!scsiPhyComplete() && likely(!scsiDev.resetFlag))
+	{
+		__WFI();
+	}
 
 #if FIFODEBUG
 	if (!scsiPhyFifoAltEmpty()) {
@@ -462,6 +453,7 @@ void scsiPhyReset()
 
 	scsiPhyFifoSel = 0;
 	*SCSI_FIFO_SEL = 0;
+	*SCSI_CTRL_DBX = 0;
 
 	// DMA Benchmark code
 	// Currently 10MB/s. Assume 20MB/s is achievable with 16 bits.
@@ -493,7 +485,6 @@ void scsiPhyReset()
 
 	// FPGA comms test code
 	#ifdef FPGA_TEST
-
 	while(1)
 	{
 		for (int j = 0; j < SCSI_FIFO_DEPTH; ++j)
@@ -501,6 +492,11 @@ void scsiPhyReset()
 			scsiDev.data[j] = j;
 		}
 
+		if (!scsiPhyFifoEmpty())
+		{
+			assertFail();
+		}
+
 		*SCSI_CTRL_PHASE = DATA_IN;
 		HAL_DMA_Start(
 			&memToFSMC,
@@ -513,6 +509,11 @@ void scsiPhyReset()
 			HAL_DMA_FULL_TRANSFER,
 			0xffffffff);
 
+		if (!scsiPhyFifoFull())
+		{
+			assertFail();
+		}
+
 		memset(&scsiDev.data[0], 0, SCSI_FIFO_DEPTH);
 
 		*SCSI_CTRL_PHASE = DATA_OUT;
@@ -527,6 +528,12 @@ void scsiPhyReset()
 			HAL_DMA_FULL_TRANSFER,
 			0xffffffff);
 
+		if (!scsiPhyFifoEmpty())
+		{
+			assertFail();
+		}
+
+
 		for (int j = 0; j < SCSI_FIFO_DEPTH; ++j)
 		{
 			if (scsiDev.data[j] != (uint8_t) j)
@@ -609,6 +616,7 @@ void scsiPhyInit()
 	*SCSI_CTRL_BSY = 0x00;
 	scsiPhyFifoSel = 0;
 	*SCSI_FIFO_SEL = 0;
+	*SCSI_CTRL_DBX = 0;
 
 }
 
@@ -645,30 +653,55 @@ void scsiPhyConfig()
 // 32 = other error
 int scsiSelfTest()
 {
-	return 0;
-#if 0
+	if (scsiDev.phase != BUS_FREE)
+	{
+		return 32;
+	}
+
+	// Acquire the SCSI bus.
+	for (int i = 0; i < 100; ++i)
+	{
+		if (scsiStatusBSY())
+		{
+			s2s_delay_ms(1);
+		}
+	}
+	if (scsiStatusBSY())
+	{
+		// Error, couldn't acquire scsi bus
+		return 32;
+	}
+	*SCSI_CTRL_BSY = 1;
+	if (! scsiStatusBSY())
+	{
+		// Error, BSY doesn't work.
+		return 32;
+	}
+
+	// Should be safe to use the bus now.
+
 	int result = 0;
 
-	// TEST DBx and DBp
+	// TEST DBx
+	// TODO test DBp
 	int i;
-	SCSI_Out_Ctl_Write(1); // Write bits manually.
-	SCSI_CTL_PHASE_Write(__scsiphase_io); // Needed for parity generation
 	for (i = 0; i < 256; ++i)
 	{
-		SCSI_Out_Bits_Write(i);
-		scsiDeskewDelay();
-		if (scsiReadDBxPins() != (i & 0xff))
+		*SCSI_CTRL_DBX = i;
+		busSettleDelay();
+		if (*SCSI_STS_DBX != (i & 0xff))
 		{
 			result |= 1;
 		}
-		if (Lookup_OddParity[i & 0xff] != SCSI_ReadPin(SCSI_In_DBP))
+		/*if (Lookup_OddParity[i & 0xff] != SCSI_ReadPin(SCSI_In_DBP))
 		{
 			result |= 2;
-		}
+		}*/
 	}
-	SCSI_Out_Ctl_Write(0); // Write bits normally.
+	*SCSI_CTRL_DBX = 0;
 
 	// TEST MSG, CD, IO
+	/* TODO
 	for (i = 0; i < 8; ++i)
 	{
 		SCSI_CTL_PHASE_Write(i);
@@ -717,7 +750,9 @@ int scsiSelfTest()
 		}
 		SCSI_ClearPin(signalsOut[i]);
 	}
+	*/
+
+	*SCSI_CTRL_BSY = 0;
 	return result;
-#endif
 }
 

+ 1 - 37
lib/SCSI2SD/src/firmware/scsiPhy.h

@@ -24,6 +24,7 @@
 #define SCSI_DATA_CNT_HI ((volatile uint8_t*)0x60000004)
 #define SCSI_DATA_CNT_LO ((volatile uint8_t*)0x60000005)
 #define SCSI_DATA_CNT_SET ((volatile uint8_t*)0x60000006)
+#define SCSI_CTRL_DBX ((volatile uint8_t*)0x60000007)
 
 #define SCSI_STS_FIFO ((volatile uint8_t*)0x60000010)
 #define SCSI_STS_ALTFIFO ((volatile uint8_t*)0x60000011)
@@ -75,37 +76,6 @@ void sdTmpRead(uint8_t* data, uint32_t lba, int sectors);
 void sdTmpWrite(uint8_t* data, uint32_t lba, int sectors);
 #if 0
 
-
-
-
-
-#define SCSI_SetPin(pin) \
-	CyPins_SetPin((pin));
-
-#define SCSI_ClearPin(pin) \
-	CyPins_ClearPin((pin));
-
-// Active low: we interpret a 0 as "true", and non-zero as "false"
-#define SCSI_ReadPin(pin) \
-	(CyPins_ReadPin((pin)) == 0)
-
-// These signals go through a glitch filter - we do not access the pin
-// directly
-enum FilteredInputs
-{
-	SCSI_Filt_ATN = 0x01,
-	SCSI_Filt_BSY = 0x02,
-	SCSI_Filt_SEL = 0x04,
-	SCSI_Filt_RST = 0x08,
-	SCSI_Filt_ACK = 0x10		
-};
-#define SCSI_ReadFilt(filt) \
-	((SCSI_Filtered_Read() & (filt)) == 0)
-
-// SCSI delays, as referenced to the cpu clock
-#define CPU_CLK_PERIOD_NS (1000000000U / BCLK__BUS_CLK__HZ)
-#define scsiDeskewDelay() CyDelayCycles((55 / CPU_CLK_PERIOD_NS) + 1)
-
 // Contains the odd-parity flag for a given 8-bit value.
 extern const uint8_t Lookup_OddParity[256];
 
@@ -121,12 +91,6 @@ int scsiReadDMAPoll();
 void scsiWriteDMA(const uint8_t* data, uint32_t count);
 int scsiWriteDMAPoll();
 
-#if 0
-uint8_t scsiReadDBxPins(void);
-
-
 int scsiSelfTest(void);
 
 #endif
-
-#endif

+ 20 - 570
lib/SCSI2SD/src/firmware/sd.c

@@ -35,362 +35,18 @@
 // Global
 SdDevice sdDev;
 
-#if 0
-enum SD_CMD_STATE { CMD_STATE_IDLE, CMD_STATE_READ, CMD_STATE_WRITE };
-static int sdCmdState = CMD_STATE_IDLE;
-static uint32_t sdCmdNextLBA; // Only valid in CMD_STATE_READ or CMD_STATE_WRITE
-static uint32_t sdCmdTime;
-static uint32_t sdLastCmdState = CMD_STATE_IDLE;
-
-enum SD_IO_STATE { SD_DMA, SD_ACCEPTED, SD_IDLE };
-static int sdIOState = SD_IDLE;
-
-// Private DMA variables.
-static uint8 sdDMARxChan = CY_DMA_INVALID_CHANNEL;
-static uint8 sdDMATxChan = CY_DMA_INVALID_CHANNEL;
-
-// Dummy location for DMA to send unchecked CRC bytes to
-static uint8 discardBuffer __attribute__((aligned(4)));
-
-// 2 bytes CRC, response, 8bits to close the clock..
-// "NCR" time is up to 8 bytes.
-static uint8_t writeResponseBuffer[8]  __attribute__((aligned(4)));
-
-// Padded with a dummy byte just to allow the tx DMA channel to
-// use 2-byte bursts for performance.
-static uint8_t writeStartToken[2]  __attribute__((aligned(4))) = {0xFF, 0xFC};
-
-// Source of dummy SPI bytes for DMA
-static uint8_t dummyBuffer[2]  __attribute__((aligned(4))) = {0xFF, 0xFF};
-
-volatile uint8_t sdRxDMAComplete;
-volatile uint8_t sdTxDMAComplete;
-
-static void sdCompleteRead();
-static void sdCompleteWrite();
-
-CY_ISR_PROTO(sdRxISR);
-CY_ISR(sdRxISR)
-{
-	sdRxDMAComplete = 1;
-}
-CY_ISR_PROTO(sdTxISR);
-CY_ISR(sdTxISR)
-{
-	sdTxDMAComplete = 1;
-}
-
-static uint8 sdCrc7(uint8* chr, uint8 cnt, uint8 crc)
-{
-	uint8 a;
-	for(a = 0; a < cnt; a++)
-	{
-		uint8 Data = chr[a];
-		uint8 i;
-		for(i = 0; i < 8; i++)
-		{
-			crc <<= 1;
-			if( (Data & 0x80) ^ (crc & 0x80) ) {crc ^= 0x09;}
-			Data <<= 1;
-		}
-	}
-	return crc & 0x7F;
-}
-
-
-// Read and write 1 byte.
-static uint8_t sdSpiByte(uint8_t value)
-{
-	SDCard_WriteTxData(value);
-	trace(trace_spinSpiByte);
-	while (!(SDCard_ReadRxStatus() & SDCard_STS_RX_FIFO_NOT_EMPTY)) {}
-	trace(trace_sdSpiByte);
-	return SDCard_ReadRxData();
-}
-
-static void sdWaitWriteBusy()
-{
-	uint8 val;
-	do
-	{
-		val = sdSpiByte(0xFF);
-	} while (val != 0xFF);
-}
-
-static void sdPreCmdState(uint32_t newState)
-{
-	if (sdCmdState == CMD_STATE_READ)
-	{
-		sdCompleteRead();
-	}
-	else if (sdCmdState == CMD_STATE_WRITE)
-	{
-		sdCompleteWrite();
-	}
-	sdCmdState = CMD_STATE_IDLE;
-
-	if (sdLastCmdState != newState && newState != CMD_STATE_IDLE)
-	{
-		sdWaitWriteBusy();
-		sdLastCmdState = newState;
-	}
-}
-
-static uint16_t sdDoCommand(
-	uint8_t cmd,
-	uint32_t param,
-	int useCRC,
-	int use2byteResponse)
-{
-	int waitWhileBusy = (cmd != SD_GO_IDLE_STATE) && (cmd != SD_STOP_TRANSMISSION);
-
-	// "busy" probe. We'll examine the results later.
-	if (waitWhileBusy)
-	{
-		SDCard_WriteTxData(0xFF);
-	}
-
-	// send is static as the address must remain consistent for the static
-	// DMA descriptors to work.
-	// Size must be divisible by 2 to suit 2-byte-burst TX DMA channel.
-	static uint8_t send[6] __attribute__((aligned(4)));
-	send[0] = cmd | 0x40;
-	send[1] = param >> 24;
-	send[2] = param >> 16;
-	send[3] = param >> 8;
-	send[4] = param;
-	if (unlikely(useCRC))
-	{
-		send[5] = (sdCrc7(send, 5, 0) << 1) | 1;
-	}
-	else
-	{
-		send[5] = 1; // stop bit
-	}
-
-	static uint8_t dmaRxTd = CY_DMA_INVALID_TD;
-	static uint8_t dmaTxTd = CY_DMA_INVALID_TD;
-	if (unlikely(dmaRxTd == CY_DMA_INVALID_TD))
-	{
-		dmaRxTd = CyDmaTdAllocate();
-		dmaTxTd = CyDmaTdAllocate();
-		CyDmaTdSetConfiguration(dmaTxTd, sizeof(send), CY_DMA_DISABLE_TD, TD_INC_SRC_ADR|SD_TX_DMA__TD_TERMOUT_EN);
-		CyDmaTdSetAddress(dmaTxTd, LO16((uint32)&send), LO16((uint32)SDCard_TXDATA_PTR));
-		CyDmaTdSetConfiguration(dmaRxTd, sizeof(send), CY_DMA_DISABLE_TD, SD_RX_DMA__TD_TERMOUT_EN);
-		CyDmaTdSetAddress(dmaRxTd, LO16((uint32)SDCard_RXDATA_PTR), LO16((uint32)&discardBuffer));
-	}
-
-	sdTxDMAComplete = 0;
-	sdRxDMAComplete = 0;
-
-	CyDmaChSetInitialTd(sdDMARxChan, dmaRxTd);
-	CyDmaChSetInitialTd(sdDMATxChan, dmaTxTd);
-
-	// Some Samsung cards enter a busy-state after single-sector reads.
-	// But we also need to wait for R1B to complete from the multi-sector
-	// reads.
-	if (waitWhileBusy)
-	{
-		trace(trace_spinSDRxFIFO);
-		while (!(SDCard_ReadRxStatus() & SDCard_STS_RX_FIFO_NOT_EMPTY)) {}
-		int busy = SDCard_ReadRxData() != 0xFF;
-		if (unlikely(busy))
-		{
-			trace(trace_spinSDBusy);
-			while (sdSpiByte(0xFF) != 0xFF) {}
-		}
-	}
-
-	// The DMA controller is a bit trigger-happy. It will retain
-	// a drq request that was triggered while the channel was
-	// disabled.
-	CyDmaChSetRequest(sdDMATxChan, CY_DMA_CPU_REQ);
-	CyDmaClearPendingDrq(sdDMARxChan);
-
-	// There is no flow control, so we must ensure we can read the bytes
-	// before we start transmitting
-	CyDmaChEnable(sdDMARxChan, 1);
-	CyDmaChEnable(sdDMATxChan, 1);
-
-	trace(trace_spinSDDMA);
-	int allComplete = 0;
-	while (!allComplete)
-	{
-		uint8_t intr = CyEnterCriticalSection();
-		allComplete = sdTxDMAComplete && sdRxDMAComplete;
-		if (!allComplete)
-		{
-			__WFI();
-		}
-		CyExitCriticalSection(intr);
-	}
-
-	uint16_t response = sdSpiByte(0xFF); // Result code or stuff byte
-	if (unlikely(cmd == SD_STOP_TRANSMISSION))
-	{
-		// Stuff byte is required for this command only.
-		// Part 1 Simplified standard 3.01
-		// "The stop command has an execution delay due to the serial command
-		// transmission."
-		response = sdSpiByte(0xFF);
-	}
-
-	uint32_t start = getTime_ms();
-
-	trace(trace_spinSDBusy);
-	while ((response & 0x80) && likely(elapsedTime_ms(start) <= 200))
-	{
-		response = sdSpiByte(0xFF);
-	}
-	if (unlikely(use2byteResponse))
-	{
-		response = (response << 8) | sdSpiByte(0xFF);
-	}
-	return response;
-}
-
-
-static inline uint16_t sdCommandAndResponse(uint8_t cmd, uint32_t param)
-{
-	return sdDoCommand(cmd, param, 0, 0);
-}
-
-static inline uint16_t sdCRCCommandAndResponse(uint8_t cmd, uint32_t param)
-{
-	return sdDoCommand(cmd, param, 1, 0);
-}
-
-// Clear the sticky status bits on error.
-static void sdClearStatus()
-{
-	sdSpiByte(0xFF);
-	uint16_t r2 = sdDoCommand(SD_SEND_STATUS, 0, 1, 1);
-	(void) r2;
-}
-
-void
-sdReadMultiSectorPrep(uint32_t sdLBA, uint32_t sdSectors)
-{
-	uint32_t tmpNextLBA = sdLBA + sdSectors;
-
-	if (!sdDev.ccs)
-	{
-		sdLBA = sdLBA * SD_SECTOR_SIZE;
-		tmpNextLBA = tmpNextLBA * SD_SECTOR_SIZE;
-	}
-
-	if (sdCmdState == CMD_STATE_READ && sdCmdNextLBA == sdLBA)
-	{
-		// Well, that was lucky. We're already reading this data
-		sdCmdNextLBA = tmpNextLBA;
-		sdCmdTime = getTime_ms();
-	}
-	else
-	{
-		sdPreCmdState(CMD_STATE_READ);
-
-		uint8_t v = sdCommandAndResponse(SD_READ_MULTIPLE_BLOCK, sdLBA);
-		if (unlikely(v))
-		{
-			scsiDiskReset();
-			sdClearStatus();
-
-			scsiDev.status = CHECK_CONDITION;
-			scsiDev.target->sense.code = HARDWARE_ERROR;
-			scsiDev.target->sense.asc = LOGICAL_UNIT_COMMUNICATION_FAILURE;
-			scsiDev.phase = STATUS;
-		}
-		else
-		{
-			sdCmdNextLBA = tmpNextLBA;
-			sdCmdState = CMD_STATE_READ;
-			sdCmdTime = getTime_ms();
-		}
-	}
-}
-
-static void
-dmaReadSector(uint8_t* outputBuffer)
-{
-	// Wait for a start-block token.
-	// Don't wait more than 200ms.  The standard recommends 100ms.
-	uint32_t start = getTime_ms();
-	uint8_t token = sdSpiByte(0xFF);
-	trace(trace_spinSDBusy);
-	while (token != 0xFE && likely(elapsedTime_ms(start) <= 200))
-	{
-		if (unlikely(token && ((token & 0xE0) == 0)))
-		{
-			// Error token!
-			break;
-		}
-		token = sdSpiByte(0xFF);
-	}
-	if (unlikely(token != 0xFE))
-	{
-		if (transfer.multiBlock)
-		{
-			sdCompleteRead();
-		}
-		if (scsiDev.status != CHECK_CONDITION)
-		{
-			scsiDev.status = CHECK_CONDITION;
-			scsiDev.target->sense.code = HARDWARE_ERROR;
-			scsiDev.target->sense.asc = UNRECOVERED_READ_ERROR;
-			scsiDev.phase = STATUS;
-		}
-		sdClearStatus();
-		return;
-	}
-
-	static uint8_t dmaRxTd[2] = { CY_DMA_INVALID_TD, CY_DMA_INVALID_TD};
-	static uint8_t dmaTxTd = CY_DMA_INVALID_TD;
-	if (unlikely(dmaRxTd[0] == CY_DMA_INVALID_TD))
-	{
-		dmaRxTd[0] = CyDmaTdAllocate();
-		dmaRxTd[1] = CyDmaTdAllocate();
-		dmaTxTd = CyDmaTdAllocate();
-
-		// Receive 512 bytes of data and then 2 bytes CRC.
-		CyDmaTdSetConfiguration(dmaRxTd[0], SD_SECTOR_SIZE, dmaRxTd[1], TD_INC_DST_ADR);
-		CyDmaTdSetConfiguration(dmaRxTd[1], 2, CY_DMA_DISABLE_TD, SD_RX_DMA__TD_TERMOUT_EN);
-		CyDmaTdSetAddress(dmaRxTd[1], LO16((uint32)SDCard_RXDATA_PTR), LO16((uint32)&discardBuffer));
-
-		CyDmaTdSetConfiguration(dmaTxTd, SD_SECTOR_SIZE + 2, CY_DMA_DISABLE_TD, SD_TX_DMA__TD_TERMOUT_EN);
-		CyDmaTdSetAddress(dmaTxTd, LO16((uint32)&dummyBuffer), LO16((uint32)SDCard_TXDATA_PTR));
-
-	}
-	CyDmaTdSetAddress(dmaRxTd[0], LO16((uint32)SDCard_RXDATA_PTR), LO16((uint32)outputBuffer));
-
-	sdIOState = SD_DMA;
-	sdTxDMAComplete = 0;
-	sdRxDMAComplete = 0;
-
-	// Re-loading the initial TD's here is very important, or else
-	// we'll be re-using the last-used TD, which would be the last
-	// in the chain (ie. CRC TD)
-	CyDmaChSetInitialTd(sdDMARxChan, dmaRxTd[0]);
-	CyDmaChSetInitialTd(sdDMATxChan, dmaTxTd);
-
-	// The DMA controller is a bit trigger-happy. It will retain
-	// a drq request that was triggered while the channel was
-	// disabled.
-	CyDmaChSetRequest(sdDMATxChan, CY_DMA_CPU_REQ);
-	CyDmaClearPendingDrq(sdDMARxChan);
-
-	// There is no flow control, so we must ensure we can read the bytes
-	// before we start transmitting
-	CyDmaChEnable(sdDMARxChan, 1);
-	CyDmaChEnable(sdDMATxChan, 1);
-}
+static int sdCmdActive = 0;
 
 int
-sdReadSectorDMAPoll()
+sdReadDMAPoll()
 {
-	if (sdRxDMAComplete && sdTxDMAComplete)
+	if (hsd.DmaTransferCplt ||
+		hsd.SdTransferCplt ||
+		(HAL_SD_ErrorTypedef)hsd.SdTransferErr != SD_OK)
 	{
+		HAL_SD_CheckReadOperation(&hsd, (uint32_t)SD_DATATIMEOUT);
 		// DMA transfer is complete
-		sdIOState = SD_IDLE;
+		sdCmdActive = 0;
 		return 1;
 	}
 	else
@@ -399,20 +55,13 @@ sdReadSectorDMAPoll()
 	}
 }
 
-void sdReadSingleSectorDMA(uint32_t lba, uint8_t* outputBuffer)
+void sdReadDMA(uint32_t lba, uint32_t sectors, uint8_t* outputBuffer)
 {
-	sdPreCmdState(CMD_STATE_READ);
-
-	uint8 v;
-	if (!sdDev.ccs)
-	{
-		lba = lba * SD_SECTOR_SIZE;
-	}
-	v = sdCommandAndResponse(SD_READ_SINGLE_BLOCK, lba);
-	if (unlikely(v))
+	if (HAL_SD_ReadBlocks_DMA(
+			&hsd, (uint32_t*)outputBuffer, lba * 512ll, 512, sectors
+			) != SD_OK)
 	{
 		scsiDiskReset();
-		sdClearStatus();
 
 		scsiDev.status = CHECK_CONDITION;
 		scsiDev.target->sense.code = HARDWARE_ERROR;
@@ -421,49 +70,23 @@ void sdReadSingleSectorDMA(uint32_t lba, uint8_t* outputBuffer)
 	}
 	else
 	{
-		dmaReadSector(outputBuffer);
+		sdCmdActive = 1;
 	}
 }
 
-void
-sdReadMultiSectorDMA(uint8_t* outputBuffer)
-{
-	// Pre: sdReadMultiSectorPrep called.
-	dmaReadSector(outputBuffer);
-}
-
-static void sdCompleteRead()
+void sdCompleteTransfer()
 {
-	if (unlikely(sdIOState != SD_IDLE))
+	if (sdCmdActive)
 	{
-		// Not much choice but to wait until we've completed the transfer.
-		// Cancelling the transfer can't be done as we have no way to reset
-		// the SD card.
-		trace(trace_spinSDCompleteRead);
-		while (!sdReadSectorDMAPoll()) { /* spin */ }
+		HAL_SD_StopTransfer(&hsd);
+		HAL_DMA_Abort(hsd.hdmarx);
+		HAL_DMA_Abort(hsd.hdmatx);
+		sdCmdActive = 0;
 	}
-
-
-	if (sdCmdState == CMD_STATE_READ)
-	{
-		uint8 r1b = sdCommandAndResponse(SD_STOP_TRANSMISSION, 0);
-
-		if (unlikely(r1b) && (scsiDev.phase == DATA_IN))
-		{
-			scsiDev.status = CHECK_CONDITION;
-			scsiDev.target->sense.code = HARDWARE_ERROR;
-			scsiDev.target->sense.asc = UNRECOVERED_READ_ERROR;
-			scsiDev.phase = STATUS;
-		}
-	}
-
-	// R1b has an optional trailing "busy" signal, but we defer waiting on this.
-	// The next call so sdCommandAndResponse will wait for the busy state to
-	// clear.
-
-	sdCmdState = CMD_STATE_IDLE;
 }
 
+
+#if 0
 void
 sdWriteMultiSectorDMA(uint8_t* outputBuffer)
 {
@@ -495,7 +118,6 @@ sdWriteMultiSectorDMA(uint8_t* outputBuffer)
 	CyDmaTdSetAddress(dmaTxTd[1], LO16((uint32)outputBuffer), LO16((uint32)SDCard_TXDATA_PTR));
 
 
-	sdIOState = SD_DMA;
 	// The DMA controller is a bit trigger-happy. It will retain
 	// a drq request that was triggered while the channel was
 	// disabled.
@@ -612,172 +234,6 @@ static void sdCompleteWrite()
 	sdCmdState = CMD_STATE_IDLE;
 }
 
-void sdCompleteTransfer()
-{
-	sdPreCmdState(CMD_STATE_IDLE);
-}
-
-
-// SD Version 2 (SDHC) support
-static int sendIfCond()
-{
-	int retries = 50;
-
-	do
-	{
-		// 11:8 Host voltage. 1 = 2.7-3.6V
-		// 7:0 Echo bits. Ignore.
-		uint8 status = sdCRCCommandAndResponse(SD_SEND_IF_COND, 0x000001AA);
-
-		if (status == SD_R1_IDLE)
-		{
-			// Version 2 card.
-			sdDev.version = 2;
-			// Read 32bit response. Should contain the same bytes that
-			// we sent in the command parameter.
-			sdSpiByte(0xFF);
-			sdSpiByte(0xFF);
-			sdSpiByte(0xFF);
-			sdSpiByte(0xFF);
-			break;
-		}
-		else if (status & SD_R1_ILLEGAL)
-		{
-			// Version 1 card.
-			sdDev.version = 1;
-			sdClearStatus();
-			break;
-		}
-
-		sdClearStatus();
-	} while (--retries > 0);
-
-	return retries > 0;
-}
-
-static int sdOpCond()
-{
-	uint32_t start = getTime_ms();
-
-	uint8 status;
-	do
-	{
-		sdCRCCommandAndResponse(SD_APP_CMD, 0);
-		// Host Capacity Support = 1 (SDHC/SDXC supported)
-		status = sdCRCCommandAndResponse(SD_APP_SEND_OP_COND, 0x40000000);
-
-		sdClearStatus();
-
-	// Spec says to poll for 1 second.
-	} while ((status != 0) && (elapsedTime_ms(start) < 1000));
-
-	return status == 0;
-}
-
-static int sdReadOCR()
-{
-	uint32_t start = getTime_ms();
-	int complete;
-	uint8 status;
-
-	do
-	{
-		uint8 buf[4];
-		int i;
-
-		status = sdCRCCommandAndResponse(SD_READ_OCR, 0);
-		if(status) { break; }
-
-		for (i = 0; i < 4; ++i)
-		{
-			buf[i] = sdSpiByte(0xFF);
-		}
-
-		sdDev.ccs = (buf[0] & 0x40) ? 1 : 0;
-		complete = (buf[0] & 0x80);
-
-	} while (!status &&
-		!complete &&
-		(elapsedTime_ms(start) < 1000));
-
-	return (status == 0) && complete;
-}
-
-static void sdReadCID()
-{
-	uint8 startToken;
-	int maxWait, i;
-
-	uint8 status = sdCRCCommandAndResponse(SD_SEND_CID, 0);
-	if(status){return;}
-
-	maxWait = 1023;
-	do
-	{
-		startToken = sdSpiByte(0xFF);
-	} while(maxWait-- && (startToken != 0xFE));
-	if (startToken != 0xFE) { return; }
-
-	for (i = 0; i < 16; ++i)
-	{
-		sdDev.cid[i] = sdSpiByte(0xFF);
-	}
-	sdSpiByte(0xFF); // CRC
-	sdSpiByte(0xFF); // CRC
-}
-
-static int sdReadCSD()
-{
-	uint8 startToken;
-	int maxWait, i;
-
-	uint8 status = sdCRCCommandAndResponse(SD_SEND_CSD, 0);
-	if(status){goto bad;}
-
-	maxWait = 1023;
-	do
-	{
-		startToken = sdSpiByte(0xFF);
-	} while(maxWait-- && (startToken != 0xFE));
-	if (startToken != 0xFE) { goto bad; }
-
-	for (i = 0; i < 16; ++i)
-	{
-		sdDev.csd[i] = sdSpiByte(0xFF);
-	}
-	sdSpiByte(0xFF); // CRC
-	sdSpiByte(0xFF); // CRC
-
-	if ((sdDev.csd[0] >> 6) == 0x00)
-	{
-		// CSD version 1
-		// C_SIZE in bits [73:62]
-		uint32 c_size = (((((uint32)sdDev.csd[6]) & 0x3) << 16) | (((uint32)sdDev.csd[7]) << 8) | sdDev.csd[8]) >> 6;
-		uint32 c_mult = (((((uint32)sdDev.csd[9]) & 0x3) << 8) | ((uint32)sdDev.csd[0xa])) >> 7;
-		uint32 sectorSize = sdDev.csd[5] & 0x0F;
-		sdDev.capacity = ((c_size+1) * ((uint64)1 << (c_mult+2)) * ((uint64)1 << sectorSize)) / SD_SECTOR_SIZE;
-	}
-	else if ((sdDev.csd[0] >> 6) == 0x01)
-	{
-		// CSD version 2
-		// C_SIZE in bits [69:48]
-
-		uint32 c_size =
-			((((uint32)sdDev.csd[7]) & 0x3F) << 16) |
-			(((uint32)sdDev.csd[8]) << 8) |
-			((uint32)sdDev.csd[7]);
-		sdDev.capacity = (c_size + 1) * 1024;
-	}
-	else
-	{
-		goto bad;
-	}
-
-	return 1;
-bad:
-	return 0;
-}
-
 #endif
 static void sdInitDMA()
 {
@@ -819,7 +275,6 @@ static int sdDoInit()
 {
 	int result = 0;
 
-	// TODO sdCmdState = CMD_STATE_IDLE;
 	sdClear();
 
 
@@ -929,11 +384,6 @@ int sdInit()
 	// Check if there's an SD card present.
 	int result = 0;
 
-#if 0
-	if ((scsiDev.phase == BUS_FREE) &&
-		(sdIOState == SD_IDLE) &&
-		(sdCmdState == CMD_STATE_IDLE))
-#endif
 	static int firstInit = 1;
 
 	if (firstInit)

+ 3 - 42
lib/SCSI2SD/src/firmware/sd.h

@@ -21,39 +21,6 @@
 
 #define SD_SECTOR_SIZE 512
 
-/*
-typedef enum
-{
-	SD_GO_IDLE_STATE = 0,
-	SD_SEND_OP_COND = 1,
-	SD_SEND_IF_COND = 8, // SD V2
-	SD_SEND_CSD = 9,
-	SD_SEND_CID = 10,
-	SD_STOP_TRANSMISSION = 12,
-	SD_SEND_STATUS = 13,
-	SD_SET_BLOCKLEN = 16,
-	SD_READ_SINGLE_BLOCK = 17,
-	SD_READ_MULTIPLE_BLOCK = 18,
-	SD_APP_SET_WR_BLK_ERASE_COUNT = 23,
-	SD_WRITE_MULTIPLE_BLOCK = 25,
-	SD_APP_SEND_OP_COND = 41,
-	SD_APP_CMD = 55,
-	SD_READ_OCR = 58,
-	SD_CRC_ON_OFF = 59
-} SD_CMD;
-
-typedef enum
-{
-	SD_R1_IDLE = 1,
-	SD_R1_ERASE_RESET = 2,
-	SD_R1_ILLEGAL = 4,
-	SD_R1_CRC = 8,
-	SD_R1_ERASE_SEQ = 0x10,
-	SD_R1_ADDRESS = 0x20,
-	SD_R1_PARAMETER = 0x40
-} SD_R1;
-*/
-
 typedef struct
 {
 	int version; // SDHC = version 2.
@@ -65,23 +32,17 @@ typedef struct
 } SdDevice;
 
 extern SdDevice sdDev;
-extern volatile uint8_t sdRxDMAComplete;
-extern volatile uint8_t sdTxDMAComplete;
 
 int sdInit(void);
 
-#define sdDMABusy() (!(sdRxDMAComplete && sdTxDMAComplete))
-
 void sdWriteMultiSectorPrep(uint32_t sdLBA, uint32_t sdSectors);
 void sdWriteMultiSectorDMA(uint8_t* outputBuffer);
 int sdWriteSectorDMAPoll();
 
-void sdReadMultiSectorPrep(uint32_t sdLBA, uint32_t sdSectors);
-void sdReadMultiSectorDMA(uint8_t* outputBuffer);
-void sdReadSingleSectorDMA(uint32_t lba, uint8_t* outputBuffer);
-int sdReadSectorDMAPoll();
+void sdReadDMA(uint32_t lba, uint32_t sectors, uint8_t* outputBuffer);
+int sdReadDMAPoll();
+void sdCompleteTransfer();
 
-void sdCompleteTransfer(void);
 void sdPoll();
 
 #endif

+ 65 - 0
lib/SCSI2SD/src/scsi2sd-util6/Dfu.cc

@@ -0,0 +1,65 @@
+//	Copyright (C) 2016 Michael McMaster <michael@codesrc.com>
+//
+//	This file is part of SCSI2SD.
+//
+//	SCSI2SD is free software: you can redistribute it and/or modify
+//	it under the terms of the GNU General Public License as published by
+//	the Free Software Foundation, either version 3 of the License, or
+//	(at your option) any later version.
+//
+//	SCSI2SD is distributed in the hope that it will be useful,
+//	but WITHOUT ANY WARRANTY; without even the implied warranty of
+//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//	GNU General Public License for more details.
+//
+//	You should have received a copy of the GNU General Public License
+//	along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "Dfu.hh"
+
+#include <stdexcept>
+#include <string.h>
+
+using namespace SCSI2SD;
+
+
+
+Dfu::Dfu()
+{
+	libusb_init(&m_usbctx);
+}
+
+Dfu::~Dfu()
+{
+	if (m_usbctx)
+	{
+		libusb_exit(m_usbctx);
+		m_usbctx = NULL;
+	}
+}
+
+bool Dfu::hasDevice()
+{
+	bool found = false;
+
+	libusb_device **list;
+	ssize_t cnt = libusb_get_device_list(m_usbctx, &list);
+	ssize_t i = 0;
+	if (cnt < 0) return false;
+
+	for (i = 0; i < cnt; i++) {
+		libusb_device *device = list[i];
+		libusb_device_descriptor desc;
+		libusb_get_device_descriptor(device, &desc);
+		if (desc.idVendor == Vendor && desc.idProduct == Product )
+		{
+			found = true;
+			break;
+		}
+	}
+
+	libusb_free_device_list(list, 1);
+
+	return found;
+}
+

+ 48 - 0
lib/SCSI2SD/src/scsi2sd-util6/Dfu.hh

@@ -0,0 +1,48 @@
+//	Copyright (C) 2016 Michael McMaster <michael@codesrc.com>
+//
+//	This file is part of SCSI2SD.
+//
+//	SCSI2SD is free software: you can redistribute it and/or modify
+//	it under the terms of the GNU General Public License as published by
+//	the Free Software Foundation, either version 3 of the License, or
+//	(at your option) any later version.
+//
+//	SCSI2SD is distributed in the hope that it will be useful,
+//	but WITHOUT ANY WARRANTY; without even the implied warranty of
+//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//	GNU General Public License for more details.
+//
+//	You should have received a copy of the GNU General Public License
+//	along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.
+
+#include <libusb.h>
+
+#include <string>
+
+#ifndef SCSI2SD_DFU_H
+#define SCSI2SD_DFU_H
+
+namespace SCSI2SD
+{
+
+class Dfu
+{
+public:
+	Dfu();
+
+	~Dfu();
+
+	bool hasDevice();
+
+private:
+	enum { Vendor = 0x0483, Product = 0xdf11 };
+
+	libusb_context* m_usbctx;
+
+	std::string m_filename;
+};
+
+} // namespace
+
+#endif
+

+ 41 - 7
lib/SCSI2SD/src/scsi2sd-util6/Makefile

@@ -1,4 +1,4 @@
-VPATH=../firmware dfu-programmer/src
+VPATH=../firmware TerminalWx/src TerminalWx/src/taTelnet TerminalWx/src/GTerm
 
 VERSION=6.0
 NAME=scsi2sd-util6
@@ -14,7 +14,7 @@ ifeq ($(USE_SYSTEM_LIBUSB), Yes)
 CPPFLAGS_LIBUSB=$(shell pkg-config libusb-1.0 --cflags)
 LDFLAGS_LIBUSB=$(shell pkg-config libusb-1.0 --libs)
 else
-CPPFLAGS_LIBUSB=-I libusb-1.0.9/libusb
+CPPFLAGS_LIBUSB=-I $(PWD)/libusb-1.0.20/libusb
 LDFLAGS_LIBUSB=-L $(BUILD)/libusb/libusb/.libs -lusb-1.0
 endif
 
@@ -42,7 +42,7 @@ else
 LDFLAGS_WX=$(shell $(BUILD)/wx/wx-config --libs)
 endif
 
-CPPFLAGS = $(CPPFLAGS_HIDAPI) -I. -I ../../include -Idfu-programmer/src \
+CPPFLAGS = $(CPPFLAGS_HIDAPI) -I. -I ../../include -ITerminalWx/src \
 	-Ilibzipper-1.0.4 \
 	$(CPPFLAGS_ZLIB) \
 	$(CPPFLAGS_LIBUSB) \
@@ -75,6 +75,7 @@ ifeq ($(TARGET),Win32)
 	EXE=.exe
 	WX_CONFIG+=--host=i686-w64-mingw32
 	LIBUSB_CONFIG+=--host=i686-w64-mingw32 --disable-shared
+	DFU-UTIL_CONFIG+=--host=i686-w64-mingw32
 endif
 ifeq ($(TARGET),Win64)
 	VPATH += hidapi/windows
@@ -86,12 +87,14 @@ ifeq ($(TARGET),Win64)
 	EXE=.exe
 	WX_CONFIG+=--host=x86_64-w64-mingw32
 	LIBUSB_CONFIG+=--host=x86_64-w64-mingw32 --disable-shared
+	DFU-UTIL_CONFIG+=--host=x86_64-w64-mingw32
 endif
 ifeq ($(TARGET),Linux)
 	VPATH += hidapi/linux
 	LDFLAGS += -ludev -lexpat -lusb-1.0
 	BUILD := $(PWD)/build/linux
 	LIBUSB_CONFIG+=--disable-shared
+	LDFLAGS_LIBUSB+= -ludev -lpthread
 endif
 ifeq ($(TARGET),Darwin)
 	# Should match OSX
@@ -101,6 +104,8 @@ ifeq ($(TARGET),Darwin)
 	CXX=clang++ -stdlib=libc++ -mmacosx-version-min=10.7
 	WX_CONFIG += --with-macosx-version-min=10.7
 	LIBUSB_CONFIG += --with-macosx-version-min=10.7 --disable-shared
+	LDFLAGS_LIBUSB += -lobjc
+	DFU-UTIL_CONFIG += --with-macosx-version-min=10.7 --disable-shared
 	BUILD := $(PWD)/build/mac
 all: $(BUILD)/scsi2sd-util6.dmg
 
@@ -129,9 +134,16 @@ OBJ = \
 	$(BUILD)/TargetPanel.o \
 	$(BUILD)/SCSI2SD_HID.o \
 	$(BUILD)/hidpacket.o \
-
-#	$(BUILD)/Dfu.o \
-#	$(BUILD)/dfu.o \
+	$(BUILD)/Dfu.o \
+	$(BUILD)/terminalwx.o \
+	$(BUILD)/terminalinputevent.o \
+	$(BUILD)/wxterm.o \
+	$(BUILD)/gterm.o \
+	$(BUILD)/actions.o \
+	$(BUILD)/keytrans.o \
+	$(BUILD)/states.o \
+	$(BUILD)/utils.o \
+	$(BUILD)/vt52_states.o \
 
 
 EXEOBJ = \
@@ -159,10 +171,14 @@ $(BUILD)/libusb/buildstamp:
 	mkdir -p $(dir $@)
 	( \
 		cd $(dir $@) && \
-		$(CURDIR)/libusb-1.0.9/configure $(LIBUSB_CONFIG) && \
+		$(CURDIR)/libusb-1.0.20/configure $(LIBUSB_CONFIG) && \
 		$(MAKE) \
 	) && \
 	touch $@
+else
+$(BUILD)/libusb/buildstamp:
+	mkdir -p $(dir $@)
+	touch $@
 endif
 
 ifneq ($(USE_SYSTEM_WX),Yes)
@@ -213,10 +229,28 @@ else
 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
 endif
 
+$(BUILD)/%.o: %.cpp
+	mkdir -p $(dir $@)
+ifneq ($(USE_SYSTEM_WX),Yes)
+	$(CXX) $(CPPFLAGS) $(CXXFLAGS) `$(BUILD)/wx/wx-config --cxxflags` $< -c -o $@
+else
+	$(CXX) $(CPPFLAGS) $(CXXFLAGS) `wx-config-3.0 --cxxflags` $< -c -o $@
+endif
+
 $(BUILD)/scsi2sd-util6$(EXE): $(OBJ) $(BUILD)/scsi2sd-util.o
 	mkdir -p $(dir $@)
 	$(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
 
+all: $(BUILD)/dfu-util/buildstamp
+$(BUILD)/dfu-util/buildstamp: $(BUILD)/libusb/buildstamp
+	mkdir -p $(dir $@)
+	( \
+		cd $(dir $@) && \
+		$(CURDIR)/dfu-util/configure ${DFU-UTIL_CONFIG} CPPFLAGS="${CPPFLAGS_LIBUSB}" LDFLAGS="${LDFLAGS_LIBUSB} ${LDFLAGS}" && \
+		$(MAKE) \
+	) && \
+	touch $@
+
 clean:
 	rm $(BUILD)/scsi2sd-util6$(EXE) $(OBJ) $(BUILD)/libzipper/buildstamp
 

+ 2 - 1
lib/SCSI2SD/src/scsi2sd-util6/SCSI2SD_HID.cc

@@ -264,7 +264,7 @@ HID::getSD_CID()
 }
 
 bool
-HID::scsiSelfTest()
+HID::scsiSelfTest(int& code)
 {
 	std::vector<uint8_t> cmd { S2S_CMD_SCSITEST };
 	std::vector<uint8_t> out;
@@ -276,6 +276,7 @@ HID::scsiSelfTest()
 	{
 		return false;
 	}
+	code = out.size() >= 2 ? out[1] : -1;
 	return (out.size() >= 1) && (out[0] == S2S_CFG_STATUS_GOOD);
 }
 

+ 1 - 1
lib/SCSI2SD/src/scsi2sd-util6/SCSI2SD_HID.hh

@@ -58,7 +58,7 @@ public:
 	std::vector<uint8_t> getSD_CSD();
 	std::vector<uint8_t> getSD_CID();
 
-	bool scsiSelfTest();
+	bool scsiSelfTest(int& code);
 
 	void enterBootloader();
 

+ 1630 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/Doxyfile

@@ -0,0 +1,1630 @@
+# Doxyfile 1.7.1
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project
+#
+# All text after a hash (#) is considered a comment and will be ignored
+# The format is:
+#       TAG = value [value, ...]
+# For lists items can also be appended using:
+#       TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ")
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# http://www.gnu.org/software/libiconv for the list of possible encodings.
+
+DOXYFILE_ENCODING      = UTF-8
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
+# by quotes) that should identify the project.
+
+PROJECT_NAME           =  TerminalWx
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER         = 0.1
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY       = doc
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of
+# source files, where putting all generated files in the same directory would
+# otherwise cause performance problems for the file system.
+
+CREATE_SUBDIRS         = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German,
+# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English
+# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian,
+# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak,
+# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese.
+
+OUTPUT_LANGUAGE        = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC      = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF           = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator
+# that is used to form the text in various listings. Each string
+# in this list, if found as the leading text of the brief description, will be
+# stripped from the text and the result after processing the whole list, is
+# used as the annotated text. Otherwise, the brief description is used as-is.
+# If left blank, the following values are used ("$name" is automatically
+# replaced with the name of the entity): "The $name class" "The $name widget"
+# "The $name file" "is" "provides" "specifies" "contains"
+# "represents" "a" "an" "the"
+
+ABBREVIATE_BRIEF       =
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
+# description.
+
+ALWAYS_DETAILED_SEC    = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+
+INLINE_INHERITED_MEMB  = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES        = YES
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user-defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the
+# path to strip.
+
+STRIP_FROM_PATH        =
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
+# the path mentioned in the documentation of a class, which tells
+# the reader which header file to include in order to use a class.
+# If left blank only the name of the header file containing the class
+# definition is used. Otherwise one should specify the include paths that
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH    =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
+# (but less readable) file names. This can be useful is your file systems
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES            = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the JavaDoc
+# comments will behave just like regular Qt-style comments
+# (thus requiring an explicit @brief command for a brief description.)
+
+JAVADOC_AUTOBRIEF      = NO
+
+# If the QT_AUTOBRIEF tag is set to YES then Doxygen will
+# interpret the first line (until the first dot) of a Qt-style
+# comment as the brief description. If set to NO, the comments
+# will behave just like regular Qt-style comments (thus requiring
+# an explicit \brief command for a brief description.)
+
+QT_AUTOBRIEF           = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
+# treat a multi-line C++ special comment block (i.e. a block of //! or ///
+# comments) as a brief description. This used to be the default behaviour.
+# The new default is to treat a multi-line C++ comment block as a detailed
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
+# re-implements.
+
+INHERIT_DOCS           = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
+# a new page for each member. If set to NO, the documentation of a member will
+# be part of the file/class/namespace that contains it.
+
+SEPARATE_MEMBER_PAGES  = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE               = 8
+
+# This tag can be used to specify a number of aliases that acts
+# as commands in the documentation. An alias has the form "name=value".
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to
+# put the command \sideeffect (or @sideeffect) in the documentation, which
+# will result in a user-defined paragraph with heading "Side Effects:".
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES                =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
+# sources only. Doxygen will then generate output that is more tailored for C.
+# For instance, some of the names that are used will be different. The list
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C  = NO
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
+# sources only. Doxygen will then generate output that is more tailored for
+# Java. For instance, namespaces will be presented as packages, qualified
+# scopes will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA   = NO
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources only. Doxygen will then generate output that is more tailored for
+# Fortran.
+
+OPTIMIZE_FOR_FORTRAN   = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for
+# VHDL.
+
+OPTIMIZE_OUTPUT_VHDL   = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it
+# parses. With this tag you can assign which parser to use for a given extension.
+# Doxygen has a built-in mapping, but you can override or extend it using this
+# tag. The format is ext=language, where ext is a file extension, and language
+# is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C,
+# C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make
+# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C
+# (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions
+# you also need to set FILE_PATTERNS otherwise the files are not read by doxygen.
+
+EXTENSION_MAPPING      =
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should
+# set this tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
+# func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+
+BUILTIN_STL_SUPPORT    = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+
+CPP_CLI_SUPPORT        = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only.
+# Doxygen will parse them like normal C++ but will assume all classes use public
+# instead of private inheritance when no explicit protection keyword is present.
+
+SIP_SUPPORT            = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate getter
+# and setter methods for a property. Setting this option to YES (the default)
+# will make doxygen to replace the get and set methods by a property in the
+# documentation. This will only work if the methods are indeed getting or
+# setting a simple type. If this is not the case, or you want to show the
+# methods anyway, you should set this option to NO.
+
+IDL_PROPERTY_SUPPORT   = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC   = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
+# the same type (for instance a group of public functions) to be put as a
+# subgroup of that type (e.g. under the Public Functions section). Set it to
+# NO to prevent subgrouping. Alternatively, this can be done per class using
+# the \nosubgrouping command.
+
+SUBGROUPING            = YES
+
+# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum
+# is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically
+# be useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+
+TYPEDEF_HIDES_STRUCT   = NO
+
+# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
+# determine which symbols to keep in memory and which to flush to disk.
+# When the cache is full, less often used symbols will be written to disk.
+# For small to medium size projects (<1000 input files) the default value is
+# probably good enough. For larger projects a too small cache size can cause
+# doxygen to be busy swapping symbols to and from disk most of the time
+# causing a significant performance penality.
+# If the system has enough physical memory increasing the cache will improve the
+# performance by keeping more symbols in memory. Note that the value works on
+# a logarithmic scale so increasing the size by one will rougly double the
+# memory usage. The cache size is given by this formula:
+# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0,
+# corresponding to a cache size of 2^16 = 65536 symbols
+
+SYMBOL_CACHE_SIZE      = 0
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL            = NO
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
+# will be included in the documentation.
+
+EXTRACT_PRIVATE        = NO
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
+# will be included in the documentation.
+
+EXTRACT_STATIC         = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
+# defined locally in source files will be included in the documentation.
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES  = YES
+
+# This flag is only useful for Objective-C code. When set to YES local
+# methods, which are defined in the implementation section but not in
+# the interface are included in the documentation.
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS  = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base
+# name of the file that contains the anonymous namespace. By default
+# anonymous namespace are hidden.
+
+EXTRACT_ANON_NSPACES   = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS     = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these classes will be included in the various
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES     = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
+# friend (class|struct|union) declarations.
+# If set to NO (the default) these declarations will be included in the
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS  = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
+# documentation blocks found inside the body of a function.
+# If set to NO (the default) these blocks will be appended to the
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS      = NO
+
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS          = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
+# file names in lower-case letters. If set to YES upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+
+CASE_SENSE_NAMES       = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES       = NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put a list of the files that are included by a file in the documentation
+# of that file.
+
+SHOW_INCLUDE_FILES     = YES
+
+# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen
+# will list include files with double quotes in the documentation
+# rather than with sharp brackets.
+
+FORCE_LOCAL_INCLUDES   = NO
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
+# is inserted in the documentation for inline members.
+
+INLINE_INFO            = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
+# declaration order.
+
+SORT_MEMBER_DOCS       = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
+# brief documentation of file, namespace and class members alphabetically
+# by member name. If set to NO (the default) the members will appear in
+# declaration order.
+
+SORT_BRIEF_DOCS        = NO
+
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen
+# will sort the (brief and detailed) documentation of class members so that
+# constructors and destructors are listed first. If set to NO (the default)
+# the constructors will appear in the respective orders defined by
+# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS.
+# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO
+# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the
+# hierarchy of group names into alphabetical order. If set to NO (the default)
+# the group names will appear in their defined order.
+
+SORT_GROUP_NAMES       = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
+# sorted by fully-qualified names, including namespaces. If set to
+# NO (the default), the class list will be sorted only by class name,
+# not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the
+# alphabetical list.
+
+SORT_BY_SCOPE_NAME     = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or
+# disable (NO) the todo list. This list is created by putting \todo
+# commands in the documentation.
+
+GENERATE_TODOLIST      = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or
+# disable (NO) the test list. This list is created by putting \test
+# commands in the documentation.
+
+GENERATE_TESTLIST      = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or
+# disable (NO) the bug list. This list is created by putting \bug
+# commands in the documentation.
+
+GENERATE_BUGLIST       = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
+# disable (NO) the deprecated list. This list is created by putting
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS       =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
+# the initial value of a variable or define consists of for it to appear in
+# the documentation. If the initializer consists of more lines than specified
+# here it will be hidden. Use a value of 0 to hide initializers completely.
+# The appearance of the initializer of individual variables and defines in the
+# documentation can be controlled using \showinitializer or \hideinitializer
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES  = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
+# at the bottom of the documentation of classes and structs. If set to YES the
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES        = YES
+
+# If the sources in your project are distributed over multiple directories
+# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
+# in the documentation. The default is NO.
+
+SHOW_DIRECTORIES       = NO
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
+# This will remove the Files entry from the Quick Index and from the
+# Folder Tree View (if specified). The default is YES.
+
+SHOW_FILES             = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the
+# Namespaces page.
+# This will remove the Namespaces entry from the Quick Index
+# and from the Folder Tree View (if specified). The default is YES.
+
+SHOW_NAMESPACES        = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command <command> <input-file>, where <command> is the value of
+# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
+# provided by doxygen. Whatever the program writes to standard output
+# is used as the file version. See the manual for examples.
+
+FILE_VERSION_FILTER    =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
+# by doxygen. The layout file controls the global structure of the generated
+# output files in an output format independent way. The create the layout file
+# that represents doxygen's defaults, run doxygen with the -l option.
+# You can optionally specify a file name after the option, if omitted
+# DoxygenLayout.xml will be used as the name of the layout file.
+
+LAYOUT_FILE            =
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET                  = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
+# NO is used.
+
+WARNINGS               = YES
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED   = YES
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some
+# parameters in a documented function, or documenting parameters that
+# don't exist or using markup commands wrongly.
+
+WARN_IF_DOC_ERROR      = YES
+
+# This WARN_NO_PARAMDOC option can be abled to get warnings for
+# functions that are documented, but have no documentation for their parameters
+# or return value. If set to NO (the default) doxygen will only warn about
+# wrong or incomplete parameter documentation, but not about the absence of
+# documentation.
+
+WARN_NO_PARAMDOC       = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text. Optionally the format may contain
+# $version, which will be replaced by the version of the file (if it could
+# be obtained via FILE_VERSION_FILTER)
+
+WARN_FORMAT            = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+# and error messages should be written. If left blank the output is written
+# to stderr.
+
+WARN_LOGFILE           =
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT                  = src src/taTelnet src/GTerm
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
+# also the default input encoding. Doxygen uses libiconv (or the iconv built
+# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for
+# the list of possible encodings.
+
+INPUT_ENCODING         = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank the following patterns are tested:
+# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx
+# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90
+
+FILE_PATTERNS          =
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
+# If left blank NO is used.
+
+RECURSIVE              = NO
+
+# The EXCLUDE tag can be used to specify files and/or directories that should
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE                =
+
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
+# directories that are symbolic links (a Unix filesystem feature) are excluded
+# from the input.
+
+EXCLUDE_SYMLINKS       = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories. Note that the wildcards are matched
+# against the file with absolute path, so to exclude all test directories
+# for example use the pattern */test/*
+
+EXCLUDE_PATTERNS       =
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+
+EXCLUDE_SYMBOLS        =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+EXAMPLE_PATH           =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+EXAMPLE_PATTERNS       =
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude
+# commands irrespective of the value of the RECURSIVE tag.
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE      = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+IMAGE_PATH             =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output.
+# If FILTER_PATTERNS is specified, this tag will be
+# ignored.
+
+INPUT_FILTER           =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis.
+# Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match.
+# The filters are a list of the form:
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
+# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER
+# is applied to all files.
+
+FILTER_PATTERNS        =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will be used to filter the input files when producing source
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES    = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+# Note: To get rid of all source code in the generated output, make sure also
+# VERBATIM_HEADERS is set to NO.
+
+SOURCE_BROWSER         = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES         = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS    = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES
+# then for each documented function all documented
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = NO
+
+# If the REFERENCES_RELATION tag is set to YES
+# then for each documented function all documented entities
+# called/used by that function will be listed.
+
+REFERENCES_RELATION    = NO
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
+# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
+# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
+# link to the source code.
+# Otherwise they will link to the documentation.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
+# will need version 4.8.6 or higher.
+
+USE_HTAGS              = NO
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS       = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX     = YES
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX    = 5
+
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX          =
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# generate HTML output.
+
+GENERATE_HTML          = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT            = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION    = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard header.
+
+HTML_HEADER            =
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard footer.
+
+HTML_FOOTER            =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If the tag is left blank doxygen
+# will generate a default style sheet. Note that doxygen will try to copy
+# the style sheet file to the HTML output directory, so don't put your own
+# stylesheet in the HTML output directory as well, or it will be erased!
+
+HTML_STYLESHEET        =
+
+# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output.
+# Doxygen will adjust the colors in the stylesheet and background images
+# according to this color. Hue is specified as an angle on a colorwheel,
+# see http://en.wikipedia.org/wiki/Hue for more information.
+# For instance the value 0 represents red, 60 is yellow, 120 is green,
+# 180 is cyan, 240 is blue, 300 purple, and 360 is red again.
+# The allowed range is 0 to 359.
+
+HTML_COLORSTYLE_HUE    = 220
+
+# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of
+# the colors in the HTML output. For a value of 0 the output will use
+# grayscales only. A value of 255 will produce the most vivid colors.
+
+HTML_COLORSTYLE_SAT    = 100
+
+# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to
+# the luminance component of the colors in the HTML output. Values below
+# 100 gradually make the output lighter, whereas values above 100 make
+# the output darker. The value divided by 100 is the actual gamma applied,
+# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2,
+# and 100 does not change the gamma.
+
+HTML_COLORSTYLE_GAMMA  = 80
+
+# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
+# page will contain the date and time when the page was generated. Setting
+# this to NO can help when comparing the output of multiple runs.
+
+HTML_TIMESTAMP         = YES
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
+# files or namespaces will be aligned in HTML using tables. If set to
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS     = YES
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded. For this to work a browser that supports
+# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox
+# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari).
+
+HTML_DYNAMIC_SECTIONS  = NO
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files
+# will be generated that can be used as input for Apple's Xcode 3
+# integrated development environment, introduced with OSX 10.5 (Leopard).
+# To create a documentation set, doxygen will generate a Makefile in the
+# HTML output directory. Running make will produce the docset in that
+# directory and running "make install" will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find
+# it at startup.
+# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
+# for more information.
+
+GENERATE_DOCSET        = NO
+
+# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the
+# feed. A documentation feed provides an umbrella under which multiple
+# documentation sets from a single provider (such as a company or product suite)
+# can be grouped.
+
+DOCSET_FEEDNAME        = "Doxygen generated docs"
+
+# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that
+# should uniquely identify the documentation set bundle. This should be a
+# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen
+# will append .docset to the name.
+
+DOCSET_BUNDLE_ID       = org.doxygen.Project
+
+# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify
+# the documentation publisher. This should be a reverse domain-name style
+# string, e.g. com.mycompany.MyDocSet.documentation.
+
+DOCSET_PUBLISHER_ID    = org.doxygen.Publisher
+
+# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher.
+
+DOCSET_PUBLISHER_NAME  = Publisher
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compiled HTML help file (.chm)
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP      = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
+# be used to specify the file name of the resulting .chm file. You
+# can add a path in front of the file if the result should not be
+# written to the html output directory.
+
+CHM_FILE               =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
+# be used to specify the location (absolute path including file name) of
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
+# the HTML help compiler on the generated index.hhp.
+
+HHC_LOCATION           =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
+# controls if a separate .chi index file is generated (YES) or that
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI           = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING
+# is used to encode HtmlHelp index (hhk), content (hhc) and project file
+# content.
+
+CHM_INDEX_ENCODING     =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
+# controls whether a binary table of contents is generated (YES) or a
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC             = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members
+# to the contents of the HTML help documentation and to the tree view.
+
+TOC_EXPAND             = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
+# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated
+# that can be used as input for Qt's qhelpgenerator to generate a
+# Qt Compressed Help (.qch) of the generated HTML documentation.
+
+GENERATE_QHP           = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can
+# be used to specify the file name of the resulting .qch file.
+# The path specified is relative to the HTML output folder.
+
+QCH_FILE               =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#namespace
+
+QHP_NAMESPACE          = org.doxygen.Project
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#virtual-folders
+
+QHP_VIRTUAL_FOLDER     = doc
+
+# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to
+# add. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#custom-filters
+
+QHP_CUST_FILTER_NAME   =
+
+# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the
+# custom filter to add. For more information please see
+# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters">
+# Qt Help Project / Custom Filters</a>.
+
+QHP_CUST_FILTER_ATTRS  =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
+# project's
+# filter section matches.
+# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes">
+# Qt Help Project / Filter Attributes</a>.
+
+QHP_SECT_FILTER_ATTRS  =
+
+# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can
+# be used to specify the location of Qt's qhelpgenerator.
+# If non-empty doxygen will try to run qhelpgenerator on the generated
+# .qhp file.
+
+QHG_LOCATION           =
+
+# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files
+#  will be generated, which together with the HTML files, form an Eclipse help
+# plugin. To install this plugin and make it available under the help contents
+# menu in Eclipse, the contents of the directory containing the HTML and XML
+# files needs to be copied into the plugins directory of eclipse. The name of
+# the directory within the plugins directory should be the same as
+# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before
+# the help appears.
+
+GENERATE_ECLIPSEHELP   = NO
+
+# A unique identifier for the eclipse help plugin. When installing the plugin
+# the directory name containing the HTML and XML files should also have
+# this name.
+
+ECLIPSE_DOC_ID         = org.doxygen.Project
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
+# top of each HTML page. The value NO (the default) enables the index and
+# the value YES disables it.
+
+DISABLE_INDEX          = NO
+
+# This tag can be used to set the number of enum values (range [1..20])
+# that doxygen will group on one line in the generated HTML documentation.
+
+ENUM_VALUES_PER_LINE   = 4
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information.
+# If the tag value is set to YES, a side panel will be generated
+# containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser).
+# Windows users are probably better off using the HTML help feature.
+
+GENERATE_TREEVIEW      = NO
+
+# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories,
+# and Class Hierarchy pages using a tree view instead of an ordered list.
+
+USE_INLINE_TREES       = NO
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
+# is shown.
+
+TREEVIEW_WIDTH         = 250
+
+# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open
+# links to external symbols imported via tag files in a separate window.
+
+EXT_LINKS_IN_WINDOW    = NO
+
+# Use this tag to change the font size of Latex formulas included
+# as images in the HTML documentation. The default is 10. Note that
+# when you change the font size after a successful doxygen run you need
+# to manually remove any form_*.png images from the HTML output directory
+# to force them to be regenerated.
+
+FORMULA_FONTSIZE       = 10
+
+# Use the FORMULA_TRANPARENT tag to determine whether or not the images
+# generated for formulas are transparent PNGs. Transparent PNGs are
+# not supported properly for IE 6.0, but are supported on all modern browsers.
+# Note that when changing this option you need to delete any form_*.png files
+# in the HTML output before the changes have effect.
+
+FORMULA_TRANSPARENT    = YES
+
+# When the SEARCHENGINE tag is enabled doxygen will generate a search box
+# for the HTML output. The underlying search engine uses javascript
+# and DHTML and should work on any modern browser. Note that when using
+# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets
+# (GENERATE_DOCSET) there is already a search function so this one should
+# typically be disabled. For large projects the javascript based search engine
+# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution.
+
+SEARCHENGINE           = YES
+
+# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
+# implemented using a PHP enabled web server instead of at the web client
+# using Javascript. Doxygen will generate the search PHP script and index
+# file to put on the web server. The advantage of the server
+# based approach is that it scales better to large projects and allows
+# full text search. The disadvances is that it is more difficult to setup
+# and does not have live searching capabilities.
+
+SERVER_BASED_SEARCH    = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# generate Latex output.
+
+GENERATE_LATEX         = NO
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT           = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked. If left blank `latex' will be used as the default command name.
+# Note that when enabling USE_PDFLATEX this option is only used for
+# generating bitmaps for formulas in the HTML output, but not in the
+# Makefile that is written to the output directory.
+
+LATEX_CMD_NAME         = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
+# generate index for LaTeX. If left blank `makeindex' will be used as the
+# default command name.
+
+MAKEINDEX_CMD_NAME     = makeindex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_LATEX          = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, a4wide, letter, legal and
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE             = a4wide
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES         =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER           =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS         = YES
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
+# plain latex in the generated Makefile. Set this option to YES to get a
+# higher quality PDF documentation.
+
+USE_PDFLATEX           = YES
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE        = NO
+
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not
+# include the index chapters (such as File Index, Compound Index, etc.)
+# in the output.
+
+LATEX_HIDE_INDICES     = NO
+
+# If LATEX_SOURCE_CODE is set to YES then doxygen will include
+# source code with syntax highlighting in the LaTeX output.
+# Note that which sources are shown also depends on other settings
+# such as SOURCE_BROWSER.
+
+LATEX_SOURCE_CODE      = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# The RTF output is optimized for Word 97 and may not look very pretty with
+# other RTF readers or editors.
+
+GENERATE_RTF           = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT             = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_RTF            = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using WORD or other
+# programs which support those fields.
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS         = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# config file, i.e. a series of assignments. You only have to provide
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE    =
+
+# Set optional variables used in the generation of an rtf document.
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE    =
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# generate man pages
+
+GENERATE_MAN           = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT             = man
+
+# The MAN_EXTENSION tag determines the extension that is added to
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION          = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS              = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will
+# generate an XML file that captures the structure of
+# the code including all documentation.
+
+GENERATE_XML           = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `xml' will be used as the default path.
+
+XML_OUTPUT             = xml
+
+# The XML_SCHEMA tag can be used to specify an XML schema,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_SCHEMA             =
+
+# The XML_DTD tag can be used to specify an XML DTD,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_DTD                =
+
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
+# dump the program listings (including syntax highlighting
+# and cross-referencing information) to the XML output. Note that
+# enabling this will significantly increase the size of the XML output.
+
+XML_PROGRAMLISTING     = YES
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
+# generate an AutoGen Definitions (see autogen.sf.net) file
+# that captures the structure of the code including all
+# documentation. Note that this feature is still experimental
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF   = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will
+# generate a Perl module file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
+# moment.
+
+GENERATE_PERLMOD       = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX          = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
+# nicely formatted so it can be parsed by a human reader.
+# This is useful
+# if you want to understand what is going on.
+# On the other hand, if this
+# tag is set to NO the size of the Perl module output will be much smaller
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY         = YES
+
+# The names of the make variables in the generated doxyrules.make file
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
+# This is useful so different doxyrules.make files included by the same
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
+# files.
+
+ENABLE_PREPROCESSING   = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION        = NO
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
+# PREDEFINED and EXPAND_AS_DEFINED tags.
+
+EXPAND_ONLY_PREDEF     = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# in the INCLUDE_PATH (see below) will be search if a #include is found.
+
+SEARCH_INCLUDES        = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
+# the preprocessor.
+
+INCLUDE_PATH           =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
+# be used.
+
+INCLUDE_FILE_PATTERNS  =
+
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
+# instead of the = operator.
+
+PREDEFINED             =
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
+# Use the PREDEFINED tag if you want to use a different macro definition.
+
+EXPAND_AS_DEFINED      =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all function-like macros that are alone
+# on a line, have an all uppercase name, and do not end with a semicolon. Such
+# function macros are typically used for boiler-plate code, and will confuse
+# the parser if not removed.
+
+SKIP_FUNCTION_MACROS   = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles.
+# Optionally an initial location of the external documentation
+# can be added for each tagfile. The format of a tag file without
+# this location is as follows:
+#
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+#
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where "loc1" and "loc2" can be relative or absolute paths or
+# URLs. If a location is present for each tag, the installdox tool
+# does not have to be run to correct the links.
+# Note that each tag file must have a unique name
+# (where the name does NOT include the path)
+# If a tag file is not located in the directory in which doxygen
+# is run, you must also specify the path to the tagfile here.
+
+TAGFILES               =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE       =
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
+# will be listed.
+
+ALLEXTERNALS           = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
+# be listed.
+
+EXTERNAL_GROUPS        = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH              = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
+# or super classes. Setting the tag to NO turns the diagrams off. Note that
+# this option is superseded by the HAVE_DOT option below. This is only a
+# fallback. It is recommended to install and use dot, since it yields more
+# powerful graphs.
+
+CLASS_DIAGRAMS         = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see
+# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH            =
+
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS   = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT               = NO
+
+# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is
+# allowed to run in parallel. When set to 0 (the default) doxygen will
+# base this on the number of processors available in the system. You can set it
+# explicitly to a value larger than 0 to get control over the balance
+# between CPU load and processing speed.
+
+DOT_NUM_THREADS        = 0
+
+# By default doxygen will write a font called FreeSans.ttf to the output
+# directory and reference it in all dot files that doxygen generates. This
+# font does not include all possible unicode characters however, so when you need
+# these (or just want a differently looking font) you can specify the font name
+# using DOT_FONTNAME. You need need to make sure dot is able to find the font,
+# which can be done by putting it in a standard location or by setting the
+# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory
+# containing the font.
+
+DOT_FONTNAME           = FreeSans.ttf
+
+# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs.
+# The default size is 10pt.
+
+DOT_FONTSIZE           = 10
+
+# By default doxygen will tell dot to use the output directory to look for the
+# FreeSans.ttf font (which doxygen will put there itself). If you specify a
+# different font using DOT_FONTNAME you can set the path where dot
+# can find it using this tag.
+
+DOT_FONTPATH           =
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH            = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH    = YES
+
+# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for groups, showing the direct groups dependencies
+
+GROUP_GRAPHS           = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+
+UML_LOOK               = NO
+
+# If set to YES, the inheritance and collaboration graphs will show the
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS     = NO
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
+# other documented files.
+
+INCLUDE_GRAPH          = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH      = YES
+
+# If the CALL_GRAPH and HAVE_DOT options are set to YES then
+# doxygen will generate a call dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable call graphs
+# for selected functions only using the \callgraph command.
+
+CALL_GRAPH             = NO
+
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
+# doxygen will generate a caller dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable caller
+# graphs for selected functions only using the \callergraph command.
+
+CALLER_GRAPH           = NO
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# will graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY    = YES
+
+# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
+# then doxygen will show the dependencies a directory has on other directories
+# in a graphical way. The dependency relations are determined by the #include
+# relations between the files in the directories.
+
+DIRECTORY_GRAPH        = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. Possible values are png, jpg, or gif
+# If left blank png will be used.
+
+DOT_IMAGE_FORMAT       = png
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+
+DOT_PATH               =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
+# \dotfile command).
+
+DOTFILE_DIRS           =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
+# nodes that will be shown in the graph. If the number of nodes in a graph
+# becomes larger than this value, doxygen will truncate the graph, which is
+# visualized by representing a node as a red box. Note that doxygen if the
+# number of direct children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note
+# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+
+DOT_GRAPH_MAX_NODES    = 50
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
+# graphs generated by dot. A depth value of 3 means that only nodes reachable
+# from the root by following a path via at most 3 edges will be shown. Nodes
+# that lay further from the root node will be omitted. Note that setting this
+# option to 1 or 2 may greatly reduce the computation time needed for large
+# code bases. Also note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+
+MAX_DOT_GRAPH_DEPTH    = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not
+# seem to support this out of the box. Warning: Depending on the platform used,
+# enabling this option may lead to badly anti-aliased labels on the edges of
+# a graph (i.e. they become hard to read).
+
+DOT_TRANSPARENT        = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10)
+# support this, this feature is disabled by default.
+
+DOT_MULTI_TARGETS      = YES
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND        = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermediate dot files that are used to generate
+# the various graphs.
+
+DOT_CLEANUP            = YES

+ 162 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/Makefile

@@ -0,0 +1,162 @@
+#------------------------------------------------------------------------------#
+# This makefile was generated by 'cbp2make' tool rev.147                       #
+#------------------------------------------------------------------------------#
+
+
+WORKDIR = `pwd`
+
+CC = gcc
+CXX = g++
+AR = ar
+LD = g++
+WINDRES = windres
+
+INC = 
+CFLAGS = `wx-config --cflags` -Wall
+RESINC = 
+LIBDIR = 
+LIB = 
+LDFLAGS = `wx-config --libs`
+
+INC_DEBUG = $(INC)
+CFLAGS_DEBUG = $(CFLAGS) -g
+RESINC_DEBUG = $(RESINC)
+RCFLAGS_DEBUG = $(RCFLAGS)
+LIBDIR_DEBUG = $(LIBDIR)
+LIB_DEBUG = $(LIB)
+LDFLAGS_DEBUG = $(LDFLAGS)
+OBJDIR_DEBUG = obj/Debug
+DEP_DEBUG = 
+OUT_DEBUG = bin/Debug/TestApp
+
+INC_RELEASE = $(INC)
+CFLAGS_RELEASE = $(CFLAGS) -O2
+RESINC_RELEASE = $(RESINC)
+RCFLAGS_RELEASE = $(RCFLAGS)
+LIBDIR_RELEASE = $(LIBDIR)
+LIB_RELEASE = $(LIB)
+LDFLAGS_RELEASE =  -s $(LDFLAGS)
+OBJDIR_RELEASE = obj/Release
+DEP_RELEASE = 
+OUT_RELEASE = bin/Release/TestApp
+
+OBJ_DEBUG = $(OBJDIR_DEBUG)/src/GTerm/states.o $(OBJDIR_DEBUG)/src/terminalwx.o $(OBJDIR_DEBUG)/src/terminalinputevent.o $(OBJDIR_DEBUG)/src/taTelnet/wxterm.o $(OBJDIR_DEBUG)/src/GTerm/vt52_states.o $(OBJDIR_DEBUG)/src/GTerm/utils.o $(OBJDIR_DEBUG)/TestApp.o $(OBJDIR_DEBUG)/src/GTerm/keytrans.o $(OBJDIR_DEBUG)/src/GTerm/gterm.o $(OBJDIR_DEBUG)/src/GTerm/actions.o $(OBJDIR_DEBUG)/TestMain.o
+
+OBJ_RELEASE = $(OBJDIR_RELEASE)/src/GTerm/states.o $(OBJDIR_RELEASE)/src/terminalwx.o $(OBJDIR_RELEASE)/src/terminalinputevent.o $(OBJDIR_RELEASE)/src/taTelnet/wxterm.o $(OBJDIR_RELEASE)/src/GTerm/vt52_states.o $(OBJDIR_RELEASE)/src/GTerm/utils.o $(OBJDIR_RELEASE)/TestApp.o $(OBJDIR_RELEASE)/src/GTerm/keytrans.o $(OBJDIR_RELEASE)/src/GTerm/gterm.o $(OBJDIR_RELEASE)/src/GTerm/actions.o $(OBJDIR_RELEASE)/TestMain.o
+
+all: debug release
+
+clean: clean_debug clean_release
+
+before_debug: 
+	test -d bin/Debug || mkdir -p bin/Debug
+	test -d $(OBJDIR_DEBUG)/src/GTerm || mkdir -p $(OBJDIR_DEBUG)/src/GTerm
+	test -d $(OBJDIR_DEBUG)/src || mkdir -p $(OBJDIR_DEBUG)/src
+	test -d $(OBJDIR_DEBUG)/src/taTelnet || mkdir -p $(OBJDIR_DEBUG)/src/taTelnet
+	test -d $(OBJDIR_DEBUG) || mkdir -p $(OBJDIR_DEBUG)
+
+after_debug: 
+
+debug: before_debug out_debug after_debug
+
+out_debug: before_debug $(OBJ_DEBUG) $(DEP_DEBUG)
+	$(LD) $(LIBDIR_DEBUG) -o $(OUT_DEBUG) $(OBJ_DEBUG)  $(LDFLAGS_DEBUG) $(LIB_DEBUG)
+
+$(OBJDIR_DEBUG)/src/GTerm/states.o: src/GTerm/states.cpp
+	$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/GTerm/states.cpp -o $(OBJDIR_DEBUG)/src/GTerm/states.o
+
+$(OBJDIR_DEBUG)/src/terminalwx.o: src/terminalwx.cpp
+	$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/terminalwx.cpp -o $(OBJDIR_DEBUG)/src/terminalwx.o
+
+$(OBJDIR_DEBUG)/src/terminalinputevent.o: src/terminalinputevent.cpp
+	$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/terminalinputevent.cpp -o $(OBJDIR_DEBUG)/src/terminalinputevent.o
+
+$(OBJDIR_DEBUG)/src/taTelnet/wxterm.o: src/taTelnet/wxterm.cpp
+	$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/taTelnet/wxterm.cpp -o $(OBJDIR_DEBUG)/src/taTelnet/wxterm.o
+
+$(OBJDIR_DEBUG)/src/GTerm/vt52_states.o: src/GTerm/vt52_states.cpp
+	$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/GTerm/vt52_states.cpp -o $(OBJDIR_DEBUG)/src/GTerm/vt52_states.o
+
+$(OBJDIR_DEBUG)/src/GTerm/utils.o: src/GTerm/utils.cpp
+	$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/GTerm/utils.cpp -o $(OBJDIR_DEBUG)/src/GTerm/utils.o
+
+$(OBJDIR_DEBUG)/TestApp.o: TestApp.cpp
+	$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c TestApp.cpp -o $(OBJDIR_DEBUG)/TestApp.o
+
+$(OBJDIR_DEBUG)/src/GTerm/keytrans.o: src/GTerm/keytrans.cpp
+	$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/GTerm/keytrans.cpp -o $(OBJDIR_DEBUG)/src/GTerm/keytrans.o
+
+$(OBJDIR_DEBUG)/src/GTerm/gterm.o: src/GTerm/gterm.cpp
+	$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/GTerm/gterm.cpp -o $(OBJDIR_DEBUG)/src/GTerm/gterm.o
+
+$(OBJDIR_DEBUG)/src/GTerm/actions.o: src/GTerm/actions.cpp
+	$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c src/GTerm/actions.cpp -o $(OBJDIR_DEBUG)/src/GTerm/actions.o
+
+$(OBJDIR_DEBUG)/TestMain.o: TestMain.cpp
+	$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c TestMain.cpp -o $(OBJDIR_DEBUG)/TestMain.o
+
+clean_debug: 
+	rm -f $(OBJ_DEBUG) $(OUT_DEBUG)
+	rm -rf bin/Debug
+	rm -rf $(OBJDIR_DEBUG)/src/GTerm
+	rm -rf $(OBJDIR_DEBUG)/src
+	rm -rf $(OBJDIR_DEBUG)/src/taTelnet
+	rm -rf $(OBJDIR_DEBUG)
+
+before_release: 
+	test -d bin/Release || mkdir -p bin/Release
+	test -d $(OBJDIR_RELEASE)/src/GTerm || mkdir -p $(OBJDIR_RELEASE)/src/GTerm
+	test -d $(OBJDIR_RELEASE)/src || mkdir -p $(OBJDIR_RELEASE)/src
+	test -d $(OBJDIR_RELEASE)/src/taTelnet || mkdir -p $(OBJDIR_RELEASE)/src/taTelnet
+	test -d $(OBJDIR_RELEASE) || mkdir -p $(OBJDIR_RELEASE)
+
+after_release: 
+
+release: before_release out_release after_release
+
+out_release: before_release $(OBJ_RELEASE) $(DEP_RELEASE)
+	$(LD) $(LIBDIR_RELEASE) -o $(OUT_RELEASE) $(OBJ_RELEASE)  $(LDFLAGS_RELEASE) $(LIB_RELEASE)
+
+$(OBJDIR_RELEASE)/src/GTerm/states.o: src/GTerm/states.cpp
+	$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/GTerm/states.cpp -o $(OBJDIR_RELEASE)/src/GTerm/states.o
+
+$(OBJDIR_RELEASE)/src/terminalwx.o: src/terminalwx.cpp
+	$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/terminalwx.cpp -o $(OBJDIR_RELEASE)/src/terminalwx.o
+
+$(OBJDIR_RELEASE)/src/terminalinputevent.o: src/terminalinputevent.cpp
+	$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/terminalinputevent.cpp -o $(OBJDIR_RELEASE)/src/terminalinputevent.o
+
+$(OBJDIR_RELEASE)/src/taTelnet/wxterm.o: src/taTelnet/wxterm.cpp
+	$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/taTelnet/wxterm.cpp -o $(OBJDIR_RELEASE)/src/taTelnet/wxterm.o
+
+$(OBJDIR_RELEASE)/src/GTerm/vt52_states.o: src/GTerm/vt52_states.cpp
+	$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/GTerm/vt52_states.cpp -o $(OBJDIR_RELEASE)/src/GTerm/vt52_states.o
+
+$(OBJDIR_RELEASE)/src/GTerm/utils.o: src/GTerm/utils.cpp
+	$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/GTerm/utils.cpp -o $(OBJDIR_RELEASE)/src/GTerm/utils.o
+
+$(OBJDIR_RELEASE)/TestApp.o: TestApp.cpp
+	$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c TestApp.cpp -o $(OBJDIR_RELEASE)/TestApp.o
+
+$(OBJDIR_RELEASE)/src/GTerm/keytrans.o: src/GTerm/keytrans.cpp
+	$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/GTerm/keytrans.cpp -o $(OBJDIR_RELEASE)/src/GTerm/keytrans.o
+
+$(OBJDIR_RELEASE)/src/GTerm/gterm.o: src/GTerm/gterm.cpp
+	$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/GTerm/gterm.cpp -o $(OBJDIR_RELEASE)/src/GTerm/gterm.o
+
+$(OBJDIR_RELEASE)/src/GTerm/actions.o: src/GTerm/actions.cpp
+	$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c src/GTerm/actions.cpp -o $(OBJDIR_RELEASE)/src/GTerm/actions.o
+
+$(OBJDIR_RELEASE)/TestMain.o: TestMain.cpp
+	$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c TestMain.cpp -o $(OBJDIR_RELEASE)/TestMain.o
+
+clean_release: 
+	rm -f $(OBJ_RELEASE) $(OUT_RELEASE)
+	rm -rf bin/Release
+	rm -rf $(OBJDIR_RELEASE)/src/GTerm
+	rm -rf $(OBJDIR_RELEASE)/src
+	rm -rf $(OBJDIR_RELEASE)/src/taTelnet
+	rm -rf $(OBJDIR_RELEASE)
+
+.PHONY: before_debug after_debug clean_debug before_release after_release clean_release
+

+ 21 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/README.txt

@@ -0,0 +1,21 @@
+This is a wxWidgets Terminal widget conveniently packaged for you.
+
+For doxygen documentation, see: http://jeremysalwen.github.com/TerminalWx/
+
+TerminalWx is taken (with modifications) from the Chameleon IDE (Mark 
+Erikson), which itself took (with modifications) from taTelnet (Derry 
+Bryson), which itself took (with modifications) from GTerm (Timothy 
+Miller).  So this code has a bit of history ;).  All credit to those 
+before me, the amount I've contributed is relatively nothing.
+
+It is offered under the terms of the wxWindows License Version 3.1, 
+which is basically the LGPL version 2+ with an exception for the 
+requirement to distribute the source code with binaries.  (see 
+license3.txt for details of the license).
+
+Dependencies
+-----
+
+You will need wxgtk version 2.9 or later.
+You will also need libwxsmith to compile the test application.
+

+ 70 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/TerminalWx.cbp

@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+	<FileVersion major="1" minor="6" />
+	<Project>
+		<Option title="TerminalWx" />
+		<Option pch_mode="2" />
+		<Option compiler="gcc" />
+		<Build>
+			<Target title="Debug">
+				<Option output="bin/Debug/TestApp" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj/Debug/" />
+				<Option type="0" />
+				<Option compiler="gcc" />
+				<Option projectLinkerOptionsRelation="2" />
+				<Compiler>
+					<Add option="-g" />
+				</Compiler>
+			</Target>
+			<Target title="Release">
+				<Option output="bin/Release/TestApp" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj/Release/" />
+				<Option type="0" />
+				<Option compiler="gcc" />
+				<Option projectLinkerOptionsRelation="2" />
+				<Compiler>
+					<Add option="-O2" />
+				</Compiler>
+				<Linker>
+					<Add option="-s" />
+				</Linker>
+			</Target>
+		</Build>
+		<Compiler>
+			<Add option="`wx-config --cflags`" />
+			<Add option="-Wall" />
+		</Compiler>
+		<Linker>
+			<Add option="`wx-config --libs`" />
+		</Linker>
+		<Unit filename="TestApp.cpp" />
+		<Unit filename="TestApp.h" />
+		<Unit filename="TestMain.cpp" />
+		<Unit filename="TestMain.h" />
+		<Unit filename="src/GTerm/actions.cpp" />
+		<Unit filename="src/GTerm/gterm.cpp" />
+		<Unit filename="src/GTerm/gterm.hpp" />
+		<Unit filename="src/GTerm/keytrans.cpp" />
+		<Unit filename="src/GTerm/states.cpp" />
+		<Unit filename="src/GTerm/utils.cpp" />
+		<Unit filename="src/GTerm/vt52_states.cpp" />
+		<Unit filename="src/taTelnet/wxterm.cpp" />
+		<Unit filename="src/taTelnet/wxterm.h" />
+		<Unit filename="src/terminalinputevent.cpp" />
+		<Unit filename="src/terminalinputevent.h" />
+		<Unit filename="src/terminalwx.cpp" />
+		<Unit filename="src/terminalwx.h" />
+		<Extensions>
+			<code_completion />
+			<envvars />
+			<wxsmith version="1">
+				<gui name="wxWidgets" src="TerminalWxApp.cpp" main="TerminalWxFrame" init_handlers="necessary" language="CPP" />
+				<resources>
+					<wxFrame wxs="wxsmith/TerminalWxframe.wxs" src="TerminalWxMain.cpp" hdr="TerminalWxMain.h" name="TerminalWxFrame" language="CPP" />
+				</resources>
+			</wxsmith>
+			<lib_finder disable_auto="1" />
+			<debugger />
+		</Extensions>
+	</Project>
+</CodeBlocks_project_file>

+ 32 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/TestApp.cpp

@@ -0,0 +1,32 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+#include "TestApp.h"
+
+//(*AppHeaders
+#include "TestMain.h"
+#include <wx/image.h>
+//*)
+
+IMPLEMENT_APP(TestApp);
+
+bool TestApp::OnInit()
+{
+    //(*AppInitialize
+    bool wxsOK = true;
+    wxInitAllImageHandlers();
+    if ( wxsOK )
+    {
+    	TerminalWxFrame* Frame = new TerminalWxFrame(0);
+    	Frame->Show();
+    	SetTopWindow(Frame);
+    }
+    //*)
+    return wxsOK;
+
+}

+ 20 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/TestApp.h

@@ -0,0 +1,20 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+#ifndef TESTAPP_H
+#define TESTAPP_H
+
+#include <wx/app.h>
+
+class TestApp : public wxApp
+{
+    public:
+        virtual bool OnInit();
+};
+
+#endif // TESTAPP_H

+ 116 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/TestMain.cpp

@@ -0,0 +1,116 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+#include <wx/gdicmn.h>
+#include <wx/menuitem.h>
+#include <wx/utils.h>
+#include <wx/msgdlg.h>
+
+#include "TestMain.h"
+#include "src/terminalinputevent.h"
+
+//(*InternalHeaders(TerminalWxFrame)
+#include <wx/string.h>
+#include <wx/intl.h>
+//*)
+
+//helper functions
+enum wxbuildinfoformat {
+    short_f, long_f };
+
+wxString wxbuildinfo(wxbuildinfoformat format)
+{
+    wxString wxbuild(wxVERSION_STRING);
+
+    if (format == long_f )
+    {
+#if defined(__WXMSW__)
+        wxbuild << _T("-Windows");
+#elif defined(__UNIX__)
+        wxbuild << _T("-Linux");
+#endif
+
+#if wxUSE_UNICODE
+        wxbuild << _T("-Unicode build");
+#else
+        wxbuild << _T("-ANSI build");
+#endif // wxUSE_UNICODE
+    }
+
+    return wxbuild;
+}
+
+//(*IdInit(TerminalWxFrame)
+const long TerminalWxFrame::ID_TERM = wxNewId();
+const long TerminalWxFrame::idMenuQuit = wxNewId();
+const long TerminalWxFrame::idMenuAbout = wxNewId();
+const long TerminalWxFrame::ID_STATUSBAR1 = wxNewId();
+//*)
+
+BEGIN_EVENT_TABLE(TerminalWxFrame,wxFrame)
+    //(*EventTable(TerminalWxFrame)
+    //*)
+END_EVENT_TABLE()
+
+TerminalWxFrame::TerminalWxFrame(wxWindow* parent,wxWindowID id)
+{
+    //(*Initialize(TerminalWxFrame)
+    wxMenuItem* MenuItem2;
+    wxMenuItem* MenuItem1;
+    wxMenu* Menu1;
+    wxMenuBar* MenuBar1;
+    wxMenu* Menu2;
+
+    Create(parent, id, _("Test TerminalWx App"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
+    Term1 = new TerminalWx(this,ID_TERM,wxPoint(72,56),80,24,_T("ID_TERM"));
+    MenuBar1 = new wxMenuBar();
+    Menu1 = new wxMenu();
+    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
+    Menu1->Append(MenuItem1);
+    MenuBar1->Append(Menu1, _("&File"));
+    Menu2 = new wxMenu();
+    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
+    Menu2->Append(MenuItem2);
+    MenuBar1->Append(Menu2, _("Help"));
+    SetMenuBar(MenuBar1);
+    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
+    int __wxStatusBarWidths_1[1] = { -1 };
+    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
+    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
+    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
+    SetStatusBar(StatusBar1);
+
+    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&TerminalWxFrame::OnQuit);
+    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&TerminalWxFrame::OnAbout);
+    Connect(wxID_ANY,wxEVT_CLOSE_WINDOW,(wxObjectEventFunction)&TerminalWxFrame::OnClose);
+    //*)
+}
+
+TerminalWxFrame::~TerminalWxFrame()
+{
+    //(*Destroy(TerminalWxFrame)
+    //*)
+}
+
+void TerminalWxFrame::OnQuit(wxCommandEvent& event)
+{
+    Close();
+}
+
+void TerminalWxFrame::OnAbout(wxCommandEvent& event)
+{
+    wxString msg = wxbuildinfo(long_f);
+    wxMessageBox(msg, _("Welcome to..."));
+
+    Term1->DisplayCharsUnsafe(msg);
+}
+
+void TerminalWxFrame::OnClose(wxCloseEvent& event)
+{
+    Destroy();
+}

+ 54 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/TestMain.h

@@ -0,0 +1,54 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+#ifndef TESTMAIN_H
+#define TESTMAIN_H
+
+//(*Headers(TerminalWxFrame)
+#include <wx/menu.h>
+#include <wx/statusbr.h>
+#include <wx/frame.h>
+//*)
+
+#include <wx/event.h>
+#include <wx/window.h>
+
+#include "src/terminalwx.h"
+
+class TerminalWxFrame: public wxFrame
+{
+    public:
+
+        TerminalWxFrame(wxWindow* parent,wxWindowID id = -1);
+        virtual ~TerminalWxFrame();
+
+    private:
+
+        //(*Handlers(TerminalWxFrame)
+        void OnQuit(wxCommandEvent& event);
+        void OnAbout(wxCommandEvent& event);
+        void OnClose(wxCloseEvent& event);
+        void OnCustom1Paint(wxPaintEvent& event);
+        //*)
+
+        //(*Identifiers(TerminalWxFrame)
+        static const long ID_TERM;
+        static const long idMenuQuit;
+        static const long idMenuAbout;
+        static const long ID_STATUSBAR1;
+        //*)
+
+        //(*Declarations(TerminalWxFrame)
+        wxStatusBar* StatusBar1;
+        TerminalWx* Term1;
+        //*)
+
+        DECLARE_EVENT_TABLE()
+};
+
+#endif // TERMINALWXMAIN_H

+ 481 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/lgpl-2.0.txt

@@ -0,0 +1,481 @@
+                  GNU LIBRARY GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
+
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the library GPL.  It is
+ numbered 2 because it goes with version 2 of the ordinary GPL.]
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Library General Public License, applies to some
+specially designated Free Software Foundation software, and to any
+other libraries whose authors decide to use it.  You can use it for
+your libraries, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if
+you distribute copies of the library, or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link a program with the library, you must provide
+complete object files to the recipients so that they can relink them
+with the library, after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  Our method of protecting your rights has two steps: (1) copyright
+the library, and (2) offer you this license which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  Also, for each distributor's protection, we want to make certain
+that everyone understands that there is no warranty for this free
+library.  If the library is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original
+version, so that any problems introduced by others will not reflect on
+the original authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that companies distributing free
+software will individually obtain patent licenses, thus in effect
+transforming the program into proprietary software.  To prevent this,
+we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+  Most GNU software, including some libraries, is covered by the ordinary
+GNU General Public License, which was designed for utility programs.  This
+license, the GNU Library General Public License, applies to certain
+designated libraries.  This license is quite different from the ordinary
+one; be sure to read it in full, and don't assume that anything in it is
+the same as in the ordinary license.
+
+  The reason we have a separate public license for some libraries is that
+they blur the distinction we usually make between modifying or adding to a
+program and simply using it.  Linking a program with a library, without
+changing the library, is in some sense simply using the library, and is
+analogous to running a utility program or application program.  However, in
+a textual and legal sense, the linked executable is a combined work, a
+derivative of the original library, and the ordinary General Public License
+treats it as such.
+
+  Because of this blurred distinction, using the ordinary General
+Public License for libraries did not effectively promote software
+sharing, because most developers did not use the libraries.  We
+concluded that weaker conditions might promote sharing better.
+
+  However, unrestricted linking of non-free programs would deprive the
+users of those programs of all benefit from the free status of the
+libraries themselves.  This Library General Public License is intended to
+permit developers of non-free programs to use free libraries, while
+preserving your freedom as a user of such programs to change the free
+libraries that are incorporated in them.  (We have not seen how to achieve
+this as regards changes in header files, but we have achieved it as regards
+changes in the actual functions of the Library.)  The hope is that this
+will lead to faster development of free libraries.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, while the latter only
+works together with the library.
+
+  Note that it is possible for a library to be covered by the ordinary
+General Public License rather than by this special one.
+
+                  GNU LIBRARY GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library which
+contains a notice placed by the copyright holder or other authorized
+party saying it may be distributed under the terms of this Library
+General Public License (also called "this License").  Each licensee is
+addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+  
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also compile or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    c) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    d) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the source code distributed need not include anything that is normally
+distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded.  In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Library General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                            NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.  It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the library's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+  <signature of Ty Coon>, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!

+ 53 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/licence3.txt

@@ -0,0 +1,53 @@
+                wxWindows Library Licence, Version 3.1
+                ======================================
+
+  Copyright (C) 1998-2005 Julian Smart, Robert Roebling et al
+
+  Everyone is permitted to copy and distribute verbatim copies
+  of this licence document, but changing it is not allowed.
+
+                       WXWINDOWS LIBRARY LICENCE
+     TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+  
+  This library is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Library General Public Licence as published by
+  the Free Software Foundation; either version 2 of the Licence, or (at
+  your option) any later version.
+  
+  This library is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
+  General Public Licence for more details.
+
+  You should have received a copy of the GNU Library General Public Licence
+  along with this software, usually in a file named COPYING.LIB.  If not,
+  write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+  Boston, MA 02111-1307 USA.
+
+  EXCEPTION NOTICE
+
+  1. As a special exception, the copyright holders of this library give
+  permission for additional uses of the text contained in this release of
+  the library as licenced under the wxWindows Library Licence, applying
+  either version 3.1 of the Licence, or (at your option) any later version of
+  the Licence as published by the copyright holders of version
+  3.1 of the Licence document.
+
+  2. The exception is that you may use, copy, link, modify and distribute
+  under your own terms, binary object code versions of works based
+  on the Library.
+
+  3. If you copy code from files distributed under the terms of the GNU
+  General Public Licence or the GNU Library General Public Licence into a
+  copy of this library, as this licence permits, the exception does not
+  apply to the code that you add in this way.  To avoid misleading anyone as
+  to the status of such modified files, you must delete this exception
+  notice from such code and/or adjust the licensing conditions notice
+  accordingly.
+
+  4. If you write modifications of your own for this library, it is your
+  choice whether to permit this exception to apply to your modifications. 
+  If you do not wish that, you must delete the exception notice from such
+  code and/or adjust the licensing conditions notice accordingly.
+
+

+ 757 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/actions.cpp

@@ -0,0 +1,757 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 1999 Timothy Miller
+              2004  Mark Erikson
+              2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+#include "gterm.hpp"
+
+
+// For efficiency, this grabs all printing characters from buffer, up to
+// the end of the line or end of buffer
+void GTerm::normal_input()
+{
+	int n, n_taken, i, c, y;
+#if 0
+char str[100];
+#endif
+
+#define IS_CTRL_CHAR(c) ((c)<32 || (c) ==127)
+
+	if (IS_CTRL_CHAR(*input_data)) return;
+
+	if (cursor_x >= width) {
+		if (mode_flags & NOEOLWRAP) {
+			cursor_x = width-1;
+		} else {
+			next_line();
+		}
+	}
+
+	n = 0;
+	if (mode_flags & NOEOLWRAP) {
+		while (!IS_CTRL_CHAR(input_data[n]) && n<data_len) n++;
+		n_taken = n;
+		if (cursor_x+n>=width) n = width-cursor_x;
+	} else {
+		while (!IS_CTRL_CHAR(input_data[n]) && n<data_len && cursor_x+n<width) n++;
+		n_taken = n;
+	}
+
+#if 0
+memcpy(str, input_data, n);
+str[n] = 0;
+//printf("Processing %d characters (%d): %s\n", n, str[0], str);
+#endif
+
+	if (mode_flags & INSERT) {
+		changed_line(cursor_y, cursor_x, width-1);
+	} else {
+		changed_line(cursor_y, cursor_x, cursor_x+n-1);
+	}
+
+	y = linenumbers[cursor_y]*MAXWIDTH;
+	if (mode_flags & INSERT) for (i=width-1; i>=cursor_x+n; i--) {
+		text[y+i] = text[y+i-n];
+		color[y+i] = color[y+i-n];
+	}
+
+	c = calc_color(fg_color, bg_color, mode_flags);
+	for (i=0; i<n; i++) {
+		text[y+cursor_x] = input_data[i];
+		color[y+cursor_x] = c;
+		cursor_x++;
+	}
+
+	input_data += n_taken-1;
+	data_len -= n_taken-1;
+}
+
+void GTerm::cr()
+{
+	move_cursor(0, cursor_y);
+}
+
+void GTerm::lf()
+{
+	if (cursor_y < scroll_bot) {
+		move_cursor(cursor_x, cursor_y+1);
+	} else {
+		scroll_region(scroll_top, scroll_bot, 1);
+	}
+}
+
+void GTerm::ff()
+{
+	clear_area(0, scroll_top, width-1, scroll_bot);
+	move_cursor(0, scroll_top);
+}
+
+void GTerm::tab()
+{
+	int i, x = 0;
+
+	for (i=cursor_x+1; i<width && !x; i++) if (tab_stops[i]) x = i;
+	if (!x) x = (cursor_x+8) & -8;
+	if (x < width) {
+		move_cursor(x, cursor_y);
+	} else {
+		if (mode_flags & NOEOLWRAP) {
+			move_cursor(width-1, cursor_y);
+		} else {
+			next_line();
+		}
+	}
+}
+
+void GTerm::bs()
+{
+	if (cursor_x>0) move_cursor(cursor_x-1, cursor_y);
+	if (mode_flags & DESTRUCTBS) {
+	    clear_area(cursor_x, cursor_y, cursor_x, cursor_y);
+	}
+}
+
+void GTerm::bell()
+{
+	Bell();
+}
+
+void GTerm::clear_param()
+{
+	nparam = 0;
+	memset(param, 0, sizeof(param));
+	q_mode = 0;
+	got_param = 0;
+}
+
+void GTerm::keypad_numeric() { clear_mode_flag(KEYAPPMODE); }
+void GTerm::keypad_application() { set_mode_flag(KEYAPPMODE); }
+
+void GTerm::save_cursor()
+{
+	save_attrib = mode_flags;
+	save_x = cursor_x;
+	save_y = cursor_y;
+}
+
+void GTerm::restore_cursor()
+{
+	mode_flags = (mode_flags & ~15) | (save_attrib & 15);
+	move_cursor(save_x, save_y);
+}
+
+void GTerm::set_tab()
+{
+	tab_stops[cursor_x] = 1;
+}
+
+void GTerm::index_down()
+{
+	lf();
+}
+
+void GTerm::next_line()
+{
+	lf(); cr();
+}
+
+void GTerm::index_up()
+{
+	if (cursor_y > scroll_top) {
+		move_cursor(cursor_x, cursor_y-1);
+	} else {
+		scroll_region(scroll_top, scroll_bot, -1);
+	}
+}
+
+void GTerm::reset()
+{
+	int i;
+
+	pending_scroll = 0;
+	bg_color = 0;
+	fg_color = 7;
+	scroll_top = 0;
+	scroll_bot = height-1;
+	for (i=0; i<MAXHEIGHT; i++) linenumbers[i] = i;
+	memset(tab_stops, 0, sizeof(tab_stops));
+	current_state = GTerm::normal_state;
+
+	clear_mode_flag(NOEOLWRAP | CURSORAPPMODE | CURSORRELATIVE |
+		NEWLINE | INSERT | UNDERLINE | BLINK | KEYAPPMODE |
+                CURSORINVISIBLE);
+
+	clear_area(0, 0, width-1, height-1);
+	move_cursor(0, 0);
+}
+
+void GTerm::set_q_mode()
+{
+	q_mode = 1;
+}
+
+// The verification test used some strange sequence which was
+// ^[[61"p
+// in a function called set_level,
+// but it didn't explain the meaning.  Just in case I ever find out,
+// and just so that it doesn't leave garbage on the screen, I accept
+// the quote and mark a flag.
+void GTerm::set_quote_mode()
+{
+	quote_mode = 1;
+}
+
+// for performance, this grabs all digits
+void GTerm::param_digit()
+{
+	got_param = 1;
+	param[nparam] = param[nparam]*10 + (*input_data)-'0';
+}
+
+void GTerm::next_param()
+{
+	nparam++;
+}
+
+void GTerm::cursor_left()
+{
+	int n, x;
+	n = param[0]; if (n<1) n = 1;
+	x = cursor_x-n; if (x<0) x = 0;
+	move_cursor(x, cursor_y);
+}
+
+void GTerm::cursor_right()
+{
+	int n, x;
+	n = param[0]; if (n<1) n = 1;
+	x = cursor_x+n; if (x>=width) x = width-1;
+	move_cursor(x, cursor_y);
+}
+
+void GTerm::cursor_up()
+{
+	int n, y;
+	n = param[0]; if (n<1) n = 1;
+	y = cursor_y-n; if (y<0) y = 0;
+	move_cursor(cursor_x, y);
+}
+
+void GTerm::cursor_down()
+{
+	int n, y;
+	n = param[0]; if (n<1) n = 1;
+	y = cursor_y+n; if (y>=height) y = height-1;
+	move_cursor(cursor_x, y);
+}
+
+void GTerm::cursor_position()
+{
+	int x, y;
+	x = param[1];	if (x<1) x=1;
+	y = param[0];	if (y<1) y=1;
+	if (mode_flags & CURSORRELATIVE) {
+		move_cursor(x-1, y-1+scroll_top);
+	} else {
+		move_cursor(x-1, y-1);
+	}
+}
+
+void GTerm::device_attrib()
+{
+	char *str = "\033[?1;2c";
+        ProcessOutput(strlen(str), (unsigned char *)str);
+}
+
+void GTerm::delete_char()
+{
+	int n, mx;
+	n = param[0]; if (n<1) n = 1;
+	mx = width-cursor_x;
+	if (n>=mx) {
+		clear_area(cursor_x, cursor_y, width-1, cursor_y);
+	} else {
+		shift_text(cursor_y, cursor_x, width-1, -n);
+	}
+}
+
+void GTerm::set_mode()  // h
+{
+	switch (param[0] + 1000*q_mode) {
+		case 1007:	clear_mode_flag(NOEOLWRAP);	break;
+		case 1001:	set_mode_flag(CURSORAPPMODE);	break;
+		case 1006:	set_mode_flag(CURSORRELATIVE);	break;
+		case 4:		set_mode_flag(INSERT);		break;
+		case 1003:	RequestSizeChange(132, height);	break;
+		case 20:	set_mode_flag(NEWLINE);		break;
+		case 12:	clear_mode_flag(LOCALECHO);	break;
+		case 1025:
+			clear_mode_flag(CURSORINVISIBLE);
+			move_cursor(cursor_x, cursor_y);
+			break;
+	}
+}
+
+void GTerm::clear_mode()  // l
+{
+	switch (param[0] + 1000*q_mode) {
+		case 1007:	set_mode_flag(NOEOLWRAP);	break;
+		case 1001:	clear_mode_flag(CURSORAPPMODE);	break;
+		case 1006:	clear_mode_flag(CURSORRELATIVE); break;
+		case 4:		clear_mode_flag(INSERT);	break;
+		case 1003:	RequestSizeChange(80, height);	break;
+		case 20:	clear_mode_flag(NEWLINE);	break;
+		case 1002:	current_state = vt52_normal_state; break;
+		case 12:	set_mode_flag(LOCALECHO);	break;
+		case 1025:
+			set_mode_flag(CURSORINVISIBLE);	break;
+			move_cursor(cursor_x, cursor_y);
+			break;
+	}
+}
+
+void GTerm::request_param()
+{
+	char str[40];
+	sprintf(str, "\033[%d;1;1;120;120;1;0x", param[0]+2);
+	ProcessOutput(strlen(str), (unsigned char *)str);
+}
+
+void GTerm::set_margins()
+{
+	int t, b;
+
+	t = param[0];
+	if (t<1) t = 1;
+	b = param[1];
+	if (b<1) b = height;
+
+	if (pending_scroll) update_changes();
+
+	scroll_top = t-1;
+	scroll_bot = b-1;
+	if (cursor_y < scroll_top) move_cursor(cursor_x, scroll_top);
+	if (cursor_y > scroll_bot) move_cursor(cursor_x, scroll_bot);
+}
+
+void GTerm::delete_line()
+{
+	int n, mx;
+	n = param[0]; if (n<1) n = 1;
+	mx = scroll_bot-cursor_y+1;
+	if (n>=mx) {
+		clear_area(0, cursor_y, width-1, scroll_bot);
+	} else {
+		scroll_region(cursor_y, scroll_bot, n);
+	}
+}
+
+void GTerm::status_report()
+{
+	char str[20];
+	if (param[0] == 5) {
+		char *str = "\033[0n";
+                ProcessOutput(strlen(str), (unsigned char *)str);
+	} else if (param[0] == 6) {
+		sprintf(str, "\033[%d;%dR", cursor_y+1, cursor_x+1);
+		ProcessOutput(strlen(str), (unsigned char *)str);
+	}
+}
+
+void GTerm::erase_display()
+{
+	switch (param[0]) {
+	case 0:
+		clear_area(cursor_x, cursor_y, width-1, cursor_y);
+		if (cursor_y<height-1)
+			clear_area(0, cursor_y+1, width-1, height-1);
+		break;
+	case 1:
+		clear_area(0, cursor_y, cursor_x, cursor_y);
+		if (cursor_y>0)
+			clear_area(0, 0, width-1, cursor_y-1);
+		break;
+	case 2:
+		clear_area(0, 0, width-1, height-1);
+		break;
+	}
+}
+
+void GTerm::erase_line()
+{
+	switch (param[0]) {
+	case 0:
+		clear_area(cursor_x, cursor_y, width-1, cursor_y);
+		break;
+	case 1:
+		clear_area(0, cursor_y, cursor_x, cursor_y);
+		break;
+	case 2:
+		clear_area(0, cursor_y, width-1, cursor_y);
+		break;
+	}
+}
+
+void GTerm::insert_line()
+{
+	int n, mx;
+	n = param[0]; if (n<1) n = 1;
+	mx = scroll_bot-cursor_y+1;
+	if (n>=mx) {
+		clear_area(0, cursor_y, width-1, scroll_bot);
+	} else {
+		scroll_region(cursor_y, scroll_bot, -n);
+	}
+}
+
+void GTerm::set_colors()
+{
+	int n;
+
+	if (!nparam && param[0] == 0) {
+		clear_mode_flag(15);
+		fg_color = 7;
+		bg_color = 0;
+		return;
+	}
+
+	for (n=0; n<=nparam; n++) {
+		if (param[n]/10 == 4) {
+			bg_color = param[n]%10;
+		} else if (param[n]/10 == 3) {
+			fg_color = param[n]%10;
+		} else switch (param[n]) {
+		case 0:
+			clear_mode_flag(15);
+			fg_color = 7;
+			bg_color = 0;
+			break;
+		case 1:
+			set_mode_flag(BOLD);
+			break;
+		case 4:
+			set_mode_flag(UNDERLINE);
+			break;
+		case 5:
+			set_mode_flag(BLINK);
+			break;
+		case 7:
+			set_mode_flag(INVERSE);
+			break;
+		}
+	}
+}
+
+void GTerm::clear_tab()
+{
+	if (param[0] == 3) {
+		memset(tab_stops, 0, sizeof(tab_stops));
+	} else if (param[0] == 0) {
+		tab_stops[cursor_x] = 0;
+	}
+}
+
+void GTerm::insert_char()
+{
+	int n, mx;
+	n = param[0]; if (n<1) n = 1;
+	mx = width-cursor_x;
+	if (n>=mx) {
+		clear_area(cursor_x, cursor_y, width-1, cursor_y);
+	} else {
+		shift_text(cursor_y, cursor_x, width-1, n);
+	}
+}
+
+void GTerm::screen_align()
+{
+	int y, yp, x, c;
+
+	c = calc_color(7, 0, 0);
+	for (y=0; y<height; y++) {
+		yp = linenumbers[y]*MAXWIDTH;
+		changed_line(y, 0, width-1);
+		for (x=0; x<width; x++) {
+			text[yp+x] = 'E';
+			color[yp+x] = c;
+		}
+	}
+}
+
+void GTerm::erase_char()
+{
+	int n, mx;
+	n = param[0]; if (n<1) n = 1;
+	mx = width-cursor_x;
+	if (n>mx) n = mx;
+	clear_area(cursor_x, cursor_y, cursor_x+n-1, cursor_y);
+}
+
+void GTerm::vt52_cursory()
+{
+	// store y coordinate
+	param[0] = (*input_data) - 32;
+	if (param[0]<0) param[0] = 0;
+	if (param[0]>=height) param[0] = height-1;
+}
+
+void GTerm::vt52_cursorx()
+{
+	int x;
+	x = (*input_data)-32;
+	if (x<0) x = 0;
+	if (x>=width) x = width-1;
+	move_cursor(x, param[0]);
+}
+
+void GTerm::vt52_ident()
+{
+	char *str = "\033/Z";
+        ProcessOutput(strlen(str), (unsigned char *)str);
+}
+
+
+#ifdef GTERM_PC
+
+void GTerm::pc_begin(void)
+{
+//printf("pc_begin...\n");
+  set_mode_flag(PC);
+//printf("pc_begin: mode_flags = %x\n", mode_flags);
+  ProcessOutput((unsigned int)strlen(pc_machinename) + 1, (unsigned char *)pc_machinename);
+  pc_oldWidth = Width();
+  pc_oldHeight = Height();
+  ResizeTerminal(80, 25);
+  update_changes();
+}
+
+void GTerm::pc_end(void)
+{
+//  printf("pc_end...\n");
+  clear_mode_flag(PC);
+  ResizeTerminal(pc_oldWidth, pc_oldHeight);
+  update_changes();
+}
+
+void GTerm::pc_cmd(void)
+{
+  pc_curcmd = *input_data;
+//printf("pc_cmd: pc_curcmd = %d...\n", pc_curcmd);
+  pc_argcount = 0;
+  switch(pc_curcmd)
+  {
+    case GTERM_PC_CMD_CURONOFF :                 // <on/off>
+      pc_numargs = 1;
+    break;
+
+    case GTERM_PC_CMD_MOVECURSOR :               // <x> <y>
+      pc_numargs = 2;
+    break;
+
+    case GTERM_PC_CMD_PUTTEXT :                  // <x> <y> <wid> <len>
+      pc_numargs = 4;
+    break;
+
+    case GTERM_PC_CMD_WRITE :                   // <x> <y> <wid> <attr>
+      pc_numargs = 4;
+    break;
+
+    case GTERM_PC_CMD_MOVETEXT :                 // <sx> <sy> <wid> <len> <dx> <dy>
+      pc_numargs = 6;
+    break;
+
+    case GTERM_PC_CMD_BEEP :
+      Bell();
+    break;
+
+    case GTERM_PC_CMD_SELECTPRINTER :
+      pc_numargs = 1;
+    break;
+
+    case GTERM_PC_CMD_PRINTCHAR :
+      pc_numargs = 1;
+    break;
+
+    case GTERM_PC_CMD_PRINTCHARS :
+      pc_numargs = 2;
+    break;
+
+    default :
+      current_state = pc_cmd_state;
+    break;
+  }
+}
+
+void GTerm::pc_arg(void)
+{
+  int
+    i,
+    yp,
+    yp2;
+
+//printf("pc_arg: pc_curcmd = %d...\n", pc_curcmd);
+
+  pc_args[pc_argcount++] = *input_data;
+  if(pc_argcount == pc_numargs)
+  {
+    switch(pc_curcmd)
+    {
+      case GTERM_PC_CMD_CURONOFF :
+//printf("pc_arg: curonoff got %d\n", *input_data);
+        if(*input_data)
+          clear_mode_flag(CURSORINVISIBLE);
+        else
+          set_mode_flag(CURSORINVISIBLE);
+        current_state = pc_cmd_state;
+        changed_line(cursor_y, cursor_x, cursor_x);
+      break;
+
+      case GTERM_PC_CMD_MOVECURSOR :
+//printf("pc_arg: movecursor (%d, %d)\n", pc_args[0], pc_args[1]);
+        move_cursor(pc_args[0], pc_args[1]);
+        current_state = pc_cmd_state;
+      break;
+
+      case GTERM_PC_CMD_PUTTEXT :
+//printf("pc_arg: puttext got %d, %d, %d, %d\n", pc_args[0], pc_args[1], pc_args[2], pc_args[3]);
+        pc_numdata = pc_args[2] * pc_args[3] * 2;
+        pc_datacount = 0;
+        pc_curx = pc_args[0];
+        pc_cury = pc_args[1];
+        if(pc_numdata)
+          current_state = pc_data_state;
+        else
+          current_state = pc_cmd_state;
+      break;
+
+      case GTERM_PC_CMD_WRITE :
+//printf("pc_arg: write got %d, %d, %d, %d\n", pc_args[0], pc_args[1], pc_args[2], pc_args[3]);
+        pc_numdata = pc_args[2];
+        pc_datacount = 0;
+        pc_curx = pc_args[0];
+        pc_cury = pc_args[1];
+        if(pc_numdata)
+          current_state = pc_data_state;
+        else
+          current_state = pc_cmd_state;
+      break;
+
+      case GTERM_PC_CMD_MOVETEXT :  // <sx> <sy> <wid> <len> <dx> <dy>
+        if(pc_args[1] < pc_args[5])
+        {
+          for(i = 0; i < pc_args[3]; i++)
+          {
+            yp = linenumbers[pc_args[1] + i] * MAXWIDTH;
+            yp2 = linenumbers[pc_args[5] + i] * MAXWIDTH;
+            memmove(&text[yp2 + pc_args[4]], &text[yp + pc_args[0]], pc_args[2]);
+            memmove(&color[yp2 + pc_args[4]], &color[yp + pc_args[0]], pc_args[2]);
+            changed_line(pc_args[5] + i, pc_args[4], pc_args[4] + pc_args[2] - 1);
+          }
+        }
+        else
+        {
+          for(i = pc_args[3] - 1; i >= 0; i--)
+          {
+            yp = linenumbers[pc_args[1] + i] * MAXWIDTH;
+            yp2 = linenumbers[pc_args[5] + i] * MAXWIDTH;
+            memmove(&text[yp2 + pc_args[4]], &text[yp + pc_args[0]], pc_args[2]);
+            memmove(&color[yp2 + pc_args[4]], &color[yp + pc_args[0]], pc_args[2]);
+            changed_line(pc_args[5] + i, pc_args[4], pc_args[4] + pc_args[2] - 1);
+          }
+        }
+        current_state = pc_cmd_state;
+      break;
+
+      case GTERM_PC_CMD_SELECTPRINTER :
+        pc_numdata = pc_args[0];
+        pc_datacount = 0;
+        memset(pc_printername, 0, sizeof(pc_printername));
+        if(pc_numdata)
+          current_state = pc_data_state;
+        else
+        {
+          SelectPrinter("");
+          current_state = pc_cmd_state;
+        }
+      break;
+
+      case GTERM_PC_CMD_PRINTCHAR :
+        PrintChars(1, &pc_args[0]);
+        current_state = pc_cmd_state;
+      break;
+
+      case GTERM_PC_CMD_PRINTCHARS :
+        pc_numdata = (pc_args[0] << 8) + pc_args[1];
+        pc_datacount = 0;
+        if(pc_numdata)
+          current_state = pc_data_state;
+        else
+          current_state = pc_cmd_state;
+      break;
+    }
+  }
+}
+
+void GTerm::pc_data(void)
+{
+  int
+    yp;
+
+//printf("pc_data: pc_curcmd = %d, pc_datacount = %d, pc_numdata = %d, pc_curx = %d, pc_cur_y = %d...\n", pc_curcmd, pc_datacount, pc_numdata, pc_curx, pc_cury);
+  switch(pc_curcmd)
+  {
+    case GTERM_PC_CMD_PUTTEXT :
+      yp = linenumbers[pc_cury] * MAXWIDTH;
+      if(!(pc_datacount & 1))
+      {
+//printf("pc_data: got char %d\n", *input_data);
+        text[yp + pc_curx] = *input_data;
+      }
+      else
+      {
+//printf("pc_data: got attr %d\n", *input_data);
+        color[yp + pc_curx] = *input_data << 4;
+      }
+      if(pc_datacount & 1)
+      {
+        changed_line(pc_cury, pc_args[0], pc_curx);
+        pc_curx++;
+        if(pc_curx == pc_args[0] + pc_args[2])
+        {
+          pc_curx = pc_args[0];
+          pc_cury++;
+        }
+      }
+    break;
+
+    case GTERM_PC_CMD_WRITE :
+      yp = linenumbers[pc_cury] * MAXWIDTH;
+      text[yp + pc_curx] = *input_data;
+      color[yp + pc_curx] = (unsigned short)pc_args[3] << 4;
+      changed_line(pc_cury, pc_args[0], pc_curx);
+      pc_curx++;
+    break;
+
+    case GTERM_PC_CMD_SELECTPRINTER :
+      if(pc_datacount < GTERM_PC_MAXPRINTERNAME - 1)
+        pc_printername[pc_datacount] = *input_data;
+      if(pc_datacount == pc_numdata - 1)
+        SelectPrinter(pc_printername);
+    break;
+
+    case GTERM_PC_CMD_PRINTCHARS :
+      PrintChars(1, input_data);
+    break;
+  }
+
+  pc_datacount++;
+  if(pc_datacount == pc_numdata)
+    current_state = pc_cmd_state;
+}
+
+#endif // GTERM_PC

+ 161 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/gterm.cpp

@@ -0,0 +1,161 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 1999  Timothy Miller
+              2004  Mark Erikson
+              2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+#ifdef __GNUG__
+    #pragma implementation "gterm.hpp"
+#endif
+
+#include "gterm.hpp"
+#include <algorithm>
+
+using namespace std;
+
+void GTerm::Update()
+{
+	update_changes();
+}
+
+void GTerm::ProcessInput(int len, unsigned char *data)
+{
+//printf("ProcessInput called...\n");
+	int i;
+	StateOption *last_state;
+
+	data_len = len;
+	input_data = data;
+
+	while (data_len) {
+//printf("ProcessInput() processing %d...\n", *input_data);
+		i = 0;
+		while (current_state[i].byte != -1 &&
+		       current_state[i].byte != *input_data) i++;
+
+		// action must be allowed to redirect state change
+		last_state = current_state+i;
+		current_state = last_state->next_state;
+		if (last_state->action)
+			(this->*(last_state->action))();
+		input_data++;
+		data_len--;
+	}
+
+	if (!(mode_flags & DEFERUPDATE) ||
+	    (pending_scroll > scroll_bot-scroll_top)) update_changes();
+}
+
+void GTerm::Reset()
+{
+	reset();
+}
+
+void GTerm::ExposeArea(int x, int y, int w, int h)
+{
+	int i;
+	for (i=0; i<h; i++) changed_line(i+y, x, x+w-1);
+	if (!(mode_flags & DEFERUPDATE)) update_changes();
+}
+
+void GTerm::ResizeTerminal(int w, int h)
+{
+	int cx, cy;
+	clear_area(min(width,w), 0, MAXWIDTH-1, MAXHEIGHT-1);
+	clear_area(0, min(height,h), min(width,w)-1, MAXHEIGHT-1);
+	width = w;
+	height = h;
+	scroll_bot = height-1;
+	if (scroll_top >= height) scroll_top = 0;
+	cx = min(width-1, cursor_x);
+	cy = min(height-1, cursor_y);
+	move_cursor(cx, cy);
+}
+
+GTerm::GTerm(int w, int h) : width(w), height(h)
+{
+	int i;
+
+	doing_update = 0;
+
+	// could make this dynamic
+	text = new unsigned char[MAXWIDTH*MAXHEIGHT];
+	color = new unsigned short[MAXWIDTH*MAXHEIGHT];
+
+	for (i=0; i<MAXHEIGHT; i++) {
+		// make it draw whole terminal to start
+		dirty_startx[i] = 0;
+		dirty_endx[i] = MAXWIDTH-1;
+	}
+
+#ifdef GTERM_PC
+        pc_machinename = new char[7];
+        strcpy(pc_machinename, "pcterm");
+#endif
+	cursor_x = 0;
+	cursor_y = 0;
+	save_x = 0;
+	save_y = 0;
+        mode_flags = 0;
+	reset();
+}
+
+GTerm::~GTerm()
+{
+	delete text;
+	delete color;
+#ifdef GTERM_PC
+        if(pc_machinename)
+          delete pc_machinename;
+#endif // GTERM_PC
+}
+
+#ifdef GTERM_PC
+void
+GTerm::SetMachineName(char *machinename)
+{
+  if(pc_machinename)
+    delete pc_machinename;
+
+  pc_machinename = new char[strlen(machinename) + 1];
+  strcpy(pc_machinename, machinename);
+}
+#endif // GTERM_PC
+
+int
+GTerm::IsSelected(int x, int y)
+{
+  if(color && x >= 0 && x < Width() && y >= 0 && y < Height())
+    return color[(linenumbers[y] * MAXWIDTH) + x] & SELECTED;
+  return 0;
+}
+
+void
+GTerm::Select(int x, int y, int select)
+{
+  if(color && x >= 0 && x < Width() && y >= 0 && y < Height())
+  {
+    if(select)
+      color[(linenumbers[y] * MAXWIDTH) + x] |= SELECTED;
+    else
+      color[(linenumbers[y] * MAXWIDTH) + x] &= ~SELECTED;
+    changed_line(y, x, x);
+//    update_changes();
+  }
+}
+
+unsigned char
+GTerm::GetChar(int x, int y)
+{
+  if(text && x >= 0 && x < Width() && y >= 0 && y < Height())
+    return text[(linenumbers[y] * MAXWIDTH) + x];
+
+  return 0;
+}
+
+
+

+ 355 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/gterm.hpp

@@ -0,0 +1,355 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 1999  Timothy Miller
+              2004  Mark Erikson
+              2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+#ifndef INCLUDED_GTERM_H
+#define INCLUDED_GTERM_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define MAXWIDTH 200
+#define MAXHEIGHT 100
+
+
+#define GTERM_PC
+
+
+class GTerm;
+typedef void (GTerm::*StateFunc)();
+
+struct StateOption {
+	int byte;	// char value to look for; -1==end/default
+	StateFunc action;
+	StateOption *next_state;
+};
+
+class GTerm {
+public:
+	// mode flags
+	enum
+        {
+          BOLD=0x1,
+          BLINK=0x2,
+          UNDERLINE=0x4,
+          INVERSE=0x8,
+	  NOEOLWRAP=0x10,
+          CURSORAPPMODE=0x20,
+          CURSORRELATIVE=0x40,
+  	  NEWLINE=0x80,
+          INSERT=0x100,
+          KEYAPPMODE=0x200,
+	  DEFERUPDATE=0x400,
+          DESTRUCTBS=0x800,
+          TEXTONLY=0x1000,
+	  LOCALECHO=0x2000,
+          CURSORINVISIBLE=0x4000,
+#ifdef GTERM_PC
+//          ,PC=0x10000
+          PC=0x8000,
+#endif // GTERM_PC
+          SELECTED=0x8000	// flag to indicate a char is selected
+        } MODES;
+
+private:
+	// terminal info
+	int width, height, scroll_top, scroll_bot;
+	unsigned char *text;
+	unsigned short *color;
+	short linenumbers[MAXHEIGHT]; // text at text[linenumbers[y]*MAXWIDTH]
+	unsigned char dirty_startx[MAXHEIGHT], dirty_endx[MAXHEIGHT];
+	int pending_scroll; // >0 means scroll up
+	int doing_update;
+
+	// terminal state
+	int cursor_x, cursor_y;
+	int save_x, save_y, save_attrib;
+	int fg_color, bg_color;
+	int mode_flags;
+	char tab_stops[MAXWIDTH];
+	StateOption *current_state;
+	static StateOption normal_state[], esc_state[], bracket_state[];
+	static StateOption cset_shiftin_state[], cset_shiftout_state[];
+	static StateOption hash_state[];
+	static StateOption vt52_normal_state[], vt52_esc_state[];
+	static StateOption vt52_cursory_state[], vt52_cursorx_state[];
+
+public:
+        // keycode translation
+        enum
+        {
+          KEY_NULL = 0,
+          KEY_BACK = 1000,
+          KEY_TAB,
+          KEY_RETURN,
+          KEY_ESCAPE,
+          KEY_SPACE,
+          KEY_LEFT,
+          KEY_UP,
+          KEY_RIGHT,
+          KEY_DOWN,
+          KEY_NUMPAD_LEFT,
+          KEY_NUMPAD_UP,
+          KEY_NUMPAD_RIGHT,
+          KEY_NUMPAD_DOWN,
+          KEY_DIVIDE,
+          KEY_NUMPAD_DIVIDE,
+          KEY_MULTIPLY,
+          KEY_NUMPAD_MULTIPLY,
+          KEY_SUBTRACT,
+          KEY_NUMPAD_SUBTRACT,
+          KEY_ADD,
+          KEY_NUMPAD_ADD,
+          KEY_HOME,
+          KEY_NUMPAD_HOME,
+          KEY_END,
+          KEY_NUMPAD_END,
+          KEY_PAGEUP,
+          KEY_NUMPAD_PAGEUP,
+          KEY_PAGEDOWN,
+          KEY_NUMPAD_PAGEDOWN,
+          KEY_INSERT,
+          KEY_NUMPAD_INSERT,
+          KEY_DELETE,
+          KEY_NUMPAD_DELETE,
+          KEY_ENTER,
+          KEY_NUMPAD_ENTER,
+          KEY_NEXT,
+          KEY_PRIOR,
+          KEY_NUMPAD0,
+          KEY_NUMPAD1,
+          KEY_NUMPAD2,
+          KEY_NUMPAD3,
+          KEY_NUMPAD4,
+          KEY_NUMPAD5,
+          KEY_NUMPAD6,
+          KEY_NUMPAD7,
+          KEY_NUMPAD8,
+          KEY_NUMPAD9,
+          KEY_NUMPAD_BEGIN,
+          KEY_NUMPAD_DECIMAL,
+          KEY_F1,
+          KEY_F2,
+          KEY_F3,
+          KEY_F4,
+          KEY_F5,
+          KEY_F6,
+          KEY_F7,
+          KEY_F8,
+          KEY_F9,
+          KEY_F10,
+          KEY_F11,
+          KEY_F12
+        } KEYCODE;
+
+private:
+        typedef struct
+        {
+          int
+            keyCode;
+
+          char
+            *seq;
+        } VTKeySeq;
+
+        static VTKeySeq cursor_keys[];
+        static VTKeySeq cursor_app_keys[];
+        static VTKeySeq keypad_keys[];
+        static VTKeySeq keypad_app_keys[];
+        static VTKeySeq other_keys[];
+
+#ifdef GTERM_PC
+        typedef struct
+        {
+          int
+            keyCode;
+
+          unsigned short
+            normSeq,
+            shiftSeq,
+            ctrlSeq,
+            altSeq;
+        } PCKeySeq;
+
+        static PCKeySeq pc_keys[];
+#endif // GTERM_PC
+
+        VTKeySeq *translate_vt_keycode(int keyCode, VTKeySeq *table);
+#ifdef GTERM_PC
+        unsigned short translate_pc_keycode(int KeyCode, int shift, int ctrl, int alt);
+#endif // GTERM_PC
+
+#ifdef GTERM_PC
+
+#define GTERM_PC_MAXARGS             10
+
+#define GTERM_PC_CMD_EXIT            0     // end console mode
+#define GTERM_PC_CMD_CURONOFF        1     // cursor on/off
+#define GTERM_PC_CMD_MOVECURSOR      2     // move cursor to x,y
+#define GTERM_PC_CMD_PUTTEXT         3     // put text
+#define GTERM_PC_CMD_WRITE           4     // write text
+#define GTERM_PC_CMD_MOVETEXT        5     // move text
+#define GTERM_PC_CMD_BEEP            6     // beep
+#define GTERM_PC_CMD_SELECTPRINTER   7     // select printer
+#define GTERM_PC_CMD_PRINTCHAR       8     // print a single character
+#define GTERM_PC_CMD_PRINTCHARS      9     // prints multiple characters
+
+#define GTERM_PC_MAXPRINTERNAME      100
+
+        int pc_cury;
+        int pc_curx;
+        int pc_state;
+        int pc_curcmd;
+        int pc_numargs;
+        int pc_argcount;
+        int pc_numdata;
+        int pc_datacount;
+        int pc_oldWidth;
+        int pc_oldHeight;
+        unsigned char pc_args[GTERM_PC_MAXARGS];
+        char *pc_machinename;
+        char pc_printername[GTERM_PC_MAXPRINTERNAME];
+
+//
+//  Define state tables
+//
+        static StateOption pc_cmd_state[];
+        static StateOption pc_arg_state[];
+        static StateOption pc_data_state[];
+
+//
+//  Define actions
+//
+        void pc_begin(void);
+        void pc_end(void);
+        void pc_cmd(void);
+        void pc_arg(void);
+        void pc_data(void);
+
+#endif  // GTERM_PC
+
+	// utility functions
+	void update_changes();
+	void scroll_region(int start_y, int end_y, int num);	// does clear
+	void shift_text(int y, int start_x, int end_x, int num); // ditto
+	void clear_area(int start_x, int start_y, int end_x, int end_y);
+	void changed_line(int y, int start_x, int end_x);
+	void move_cursor(int x, int y);
+	int calc_color(int fg, int bg, int flags);
+
+	// action parameters
+	int nparam, param[30];
+	unsigned char *input_data;
+	int data_len, q_mode, got_param, quote_mode;
+
+	// terminal actions
+	void normal_input();
+	void set_q_mode();
+	void set_quote_mode();
+	void clear_param();
+	void param_digit();
+	void next_param();
+
+	// non-printing characters
+	void cr(), lf(), ff(), bell(), tab(), bs();
+
+	// escape sequence actions
+	void keypad_numeric();
+	void keypad_application();
+	void save_cursor();
+	void restore_cursor();
+	void set_tab();
+	void index_down();
+	void index_up();
+	void next_line();
+	void reset();
+
+	void cursor_left();
+	void cursor_down();
+	void cursor_right();
+	void cursor_up();
+	void cursor_position();
+	void device_attrib();
+	void delete_char();
+	void set_mode();
+	void clear_mode();
+	void request_param();
+	void set_margins();
+	void delete_line();
+	void status_report();
+	void erase_display();
+	void erase_line();
+	void insert_line();
+	void set_colors();
+	void clear_tab();
+	void insert_char();
+	void screen_align();
+	void erase_char();
+
+	// vt52 stuff
+	void vt52_cursory();
+	void vt52_cursorx();
+	void vt52_ident();
+
+public:
+	GTerm(int w, int h);
+	virtual ~GTerm();
+
+	// function to control terminal
+	virtual void ProcessInput(int len, unsigned char *data);
+   virtual void ProcessOutput(int len, unsigned char *data) { SendBack(len, (char *)data); }
+	virtual void ResizeTerminal(int width, int height);
+	int Width() { return width; }
+	int Height() { return height; }
+	virtual void Update();
+	virtual void ExposeArea(int x, int y, int w, int h);
+	virtual void Reset();
+
+	int GetMode() { return mode_flags; }
+	void SetMode(int mode) { mode_flags = mode; }
+	void set_mode_flag(int flag);
+	void clear_mode_flag(int flag);
+
+	// manditory child-supplied functions
+	virtual void DrawText(int fg_color, int bg_color, int flags,
+		int x, int y, int len, unsigned char *string) = 0;
+	virtual void DrawCursor(int fg_color, int bg_color, int flags,
+		int x, int y, unsigned char c) = 0;
+
+	// optional child-supplied functions
+	virtual void MoveChars(int sx, int sy, int dx, int dy, int w, int h) { }
+	virtual void ClearChars(int bg_color, int x, int y, int w, int h) { }
+   virtual void SendBack(int len, char *data) { }
+	virtual void SendBack(char *data) { SendBack(strlen(data), data); }
+	virtual void ModeChange(int state) { }
+	virtual void Bell() { }
+	virtual void RequestSizeChange(int w, int h) { }
+
+        virtual int TranslateKeyCode(int keycode, int *len, char *data,
+                                     int shift = 0, int ctrl = 0, int alt = 0);
+
+#ifdef GTERM_PC
+        virtual void SelectPrinter(char *PrinterName) {}
+        virtual void PrintChars(int len, unsigned char *data) {}
+
+        void SetMachineName(char *machinename);
+        char *GetMachineName(void) { return pc_machinename; }
+#endif // GTERM_PC
+
+        virtual int IsSelected(int x, int y);
+        virtual void Select(int x, int y, int select);
+        virtual unsigned char GetChar(int x, int y);
+};
+
+#endif

+ 382 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/keytrans.cpp

@@ -0,0 +1,382 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 1999  Derry Bryson
+              2004  Mark Erikson
+              2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+
+#include "gterm.hpp"
+#include <ctype.h>
+
+//
+//  Keycode translation tables
+//
+GTerm::VTKeySeq GTerm::cursor_keys[] =
+{
+  { KEY_LEFT, "\033[D" },
+  { KEY_UP, "\033[A" },
+  { KEY_RIGHT, "\033[C" },
+  { KEY_DOWN, "\033[B" },
+  { KEY_NUMPAD_LEFT, "\033[D" },
+  { KEY_NUMPAD_UP, "\033[A" },
+  { KEY_NUMPAD_RIGHT, "\033[C" },
+  { KEY_NUMPAD_DOWN, "\033[B" },
+  { KEY_NULL, 0 }
+};
+
+GTerm::VTKeySeq GTerm::cursor_app_keys[] =
+{
+  { KEY_LEFT, "\033OD" },
+  { KEY_UP, "\033OA" },
+  { KEY_RIGHT, "\033OC" },
+  { KEY_DOWN, "\033OB" },
+  { KEY_NUMPAD_LEFT, "\033OD" },
+  { KEY_NUMPAD_UP, "\033OA" },
+  { KEY_NUMPAD_RIGHT, "\033OC" },
+  { KEY_NUMPAD_DOWN, "\033OB" },
+  { KEY_NULL, 0 }
+};
+
+GTerm::VTKeySeq GTerm::keypad_keys[] =
+{
+  { KEY_NUMPAD_DIVIDE, "/" },
+  { KEY_NUMPAD_MULTIPLY, "*" },
+  { KEY_NUMPAD_SUBTRACT, "-" },
+  { KEY_NUMPAD_HOME, "\033[\000" },
+  { KEY_NUMPAD7, "7" },
+  { KEY_NUMPAD8, "8" },
+  { KEY_NUMPAD_PAGEUP, "\033[5~" },
+  { KEY_NUMPAD9, "9" },
+  { KEY_NUMPAD_ADD, "+" },
+  { KEY_NUMPAD4, "4" },
+  { KEY_NUMPAD_BEGIN, "\033[s" },
+  { KEY_NUMPAD5, "5" },
+  { KEY_NUMPAD6, "6" },
+  { KEY_NUMPAD_END, "\033[e" },
+  { KEY_NUMPAD1, "1" },
+  { KEY_NUMPAD2, "2" },
+  { KEY_NUMPAD_PAGEDOWN, "\033[6~" },
+  { KEY_NUMPAD3, "3" },
+  { KEY_NUMPAD_INSERT, "\033[2~" },
+  { KEY_NUMPAD0, "0" },
+  { KEY_NUMPAD_DELETE, "\033[3~" },
+  { KEY_NUMPAD_DECIMAL, "." },
+  { KEY_NUMPAD_ENTER, "\r" },
+  { KEY_NULL, 0 }
+};
+
+GTerm::VTKeySeq GTerm::keypad_app_keys[] =
+{
+  { KEY_NUMPAD_DIVIDE, "\033Oo" },
+  { KEY_NUMPAD_MULTIPLY, "\033Oj" },
+  { KEY_NUMPAD_SUBTRACT, "\033Om" },
+  { KEY_NUMPAD_HOME, "\033[\000" },
+  { KEY_NUMPAD7, "\033Ow" },
+  { KEY_NUMPAD8, "\033Ox" },
+  { KEY_NUMPAD_PAGEUP, "\033[5~" },
+  { KEY_NUMPAD9, "\033Oy" },
+  { KEY_NUMPAD_ADD, "\033Ok" },
+  { KEY_NUMPAD4, "\033Ot" },
+  { KEY_NUMPAD_BEGIN, "\033[s" },
+  { KEY_NUMPAD5, "\033Ou" },
+  { KEY_NUMPAD6, "\033Ov" },
+  { KEY_NUMPAD_END, "\033[e" },
+  { KEY_NUMPAD1, "\033Oq" },
+  { KEY_NUMPAD2, "\033Or" },
+  { KEY_NUMPAD_PAGEDOWN, "\033[6~" },
+  { KEY_NUMPAD3, "\033Os" },
+  { KEY_NUMPAD_INSERT, "\033[2~" },
+  { KEY_NUMPAD0, "\033Op" },
+  { KEY_NUMPAD_DELETE, "\033[3~" },
+  { KEY_NUMPAD_DECIMAL, "\033On" },
+  { KEY_NUMPAD_ENTER, "\033OM" },
+  { KEY_NULL, 0 }
+};
+
+GTerm::VTKeySeq GTerm::other_keys[] =
+{
+  { KEY_HOME, "\033[\000" },
+  { KEY_PAGEUP, "\033[5~" },
+  { KEY_PRIOR, "\033[5~" },
+  { KEY_PAGEDOWN, "\033[6~"},
+  { KEY_NEXT, "\033[6~" },
+  { KEY_END, "\033[e" },
+  { KEY_INSERT, "\033[2~" },
+  { KEY_F1, "\033[11~" },
+  { KEY_F2, "\033[12~" },
+  { KEY_F3, "\033[13~" },
+  { KEY_F4, "\033[14~" },
+  { KEY_F5, "\033[15~" },
+  { KEY_F6, "\033[17~" },
+  { KEY_F7, "\033[18~" },
+  { KEY_F8, "\033[19~" },
+  { KEY_F9, "\033[20~" },
+  { KEY_F10, "\033[21~" },
+  { KEY_F11, "\033[23~" },
+  { KEY_F12, "\033[24~" },
+  { KEY_RETURN, "\r" },
+  { KEY_SPACE, " " },
+  { KEY_BACK, "\x8" },
+  { KEY_ESCAPE, "\x1b" },
+  { KEY_TAB, "\x9" },
+  { KEY_DELETE, "\x7f" },
+  { KEY_NULL, 0 }
+};
+
+#ifdef GTERM_PC
+GTerm::PCKeySeq GTerm::pc_keys[] =
+{
+  { '0', 0x0030, 0x0029, 0x0000, 0x8100 },
+  { '1', 0x0031, 0x0021, 0x0000, 0x7800 },
+  { '2', 0x0032, 0x0040, 0x0000, 0x7900 },
+  { '3', 0x0033, 0x0023, 0x0000, 0x7a00 },
+  { '4', 0x0034, 0x0024, 0x0000, 0x7b00 },
+  { '5', 0x0035, 0x0025, 0x0000, 0x7c00 },
+  { '6', 0x0036, 0x005e, 0x0000, 0x7d00 },
+  { '7', 0x0037, 0x0026, 0x0000, 0x7e00 },
+  { '8', 0x0038, 0x002a, 0x0000, 0x7f00 },
+  { '9', 0x0039, 0x0028, 0x0000, 0x8000 },
+
+  { ')', 0x0030, 0x0029, 0x0000, 0x8100 },
+  { '!', 0x0031, 0x0021, 0x0000, 0x7800 },
+  { '@', 0x0032, 0x0040, 0x0000, 0x7900 },
+  { '#', 0x0033, 0x0023, 0x0000, 0x7a00 },
+  { '$', 0x0034, 0x0024, 0x0000, 0x7b00 },
+  { '%', 0x0035, 0x0025, 0x0000, 0x7c00 },
+  { '^', 0x0036, 0x005e, 0x0000, 0x7d00 },
+  { '&', 0x0037, 0x0026, 0x0000, 0x7e00 },
+  { '*', 0x0038, 0x002a, 0x0000, 0x7f00 },
+  { '(', 0x0039, 0x0028, 0x0000, 0x8000 },
+
+  { 'a', 0x0061, 0x0041, 0x0001, 0x1e00 },
+  { 'b', 0x0062, 0x0042, 0x0002, 0x3000 },
+  { 'c', 0x0063, 0x0043, 0x0003, 0x2e00 },
+  { 'd', 0x0064, 0x0044, 0x0004, 0x2000 },
+  { 'e', 0x0065, 0x0045, 0x0005, 0x1200 },
+  { 'f', 0x0066, 0x0046, 0x0006, 0x2100 },
+  { 'g', 0x0067, 0x0047, 0x0007, 0x2200 },
+  { 'h', 0x0068, 0x0048, 0x0008, 0x2300 },
+  { 'i', 0x0069, 0x0049, 0x0009, 0x1700 },
+  { 'j', 0x006a, 0x004a, 0x000a, 0x2400 },
+  { 'k', 0x006b, 0x004b, 0x000b, 0x2500 },
+  { 'l', 0x006c, 0x004c, 0x000c, 0x2600 },
+  { 'm', 0x006d, 0x004d, 0x000d, 0x3200 },
+  { 'n', 0x006e, 0x004e, 0x000e, 0x3100 },
+  { 'o', 0x006f, 0x004f, 0x000f, 0x1800 },
+  { 'p', 0x0070, 0x0050, 0x0010, 0x1900 },
+  { 'q', 0x0071, 0x0051, 0xff91, 0x1000 },
+  { 'r', 0x0072, 0x0052, 0x0012, 0x1300 },
+  { 's', 0x0073, 0x0053, 0xff93, 0x1f00 },
+  { 't', 0x0074, 0x0054, 0x0014, 0x1400 },
+  { 'u', 0x0075, 0x0055, 0x0015, 0x1600 },
+  { 'v', 0x0076, 0x0056, 0x0016, 0x2f00 },
+  { 'w', 0x0077, 0x0057, 0x0017, 0x1100 },
+  { 'x', 0x0078, 0x0058, 0x0018, 0x2d00 },
+  { 'y', 0x0079, 0x0059, 0x0019, 0x1500 },
+  { 'z', 0x007a, 0x005a, 0x001a, 0x2c00 },
+
+  { '`', 0x0060, 0x007e, 0x0000, 0x0000 },
+  { '~', 0x0060, 0x007e, 0x0000, 0x0000 },
+  { '-', 0x002d, 0x005f, 0x0000, 0x0000 },
+  { '_', 0x002d, 0x005f, 0x0000, 0x0000 },
+  { '=', 0x003d, 0x002b, 0x0000, 0x0000 },
+  { '+', 0x003d, 0x002b, 0x0000, 0x0000 },
+  { ',', 0x002c, 0x003c, 0x0000, 0x0000 },
+  { '<', 0x002c, 0x003c, 0x0000, 0x0000 },
+  { '.', 0x002e, 0x003e, 0x0000, 0x0000 },
+  { '>', 0x002e, 0x003e, 0x0000, 0x0000 },
+  { ';', 0x003b, 0x003a, 0x0000, 0x0000 },
+  { ':', 0x003b, 0x003a, 0x0000, 0x0000 },
+  { '\'', 0x002c, 0x0022, 0x0000, 0x0000 },
+  { '"', 0x002c, 0x0022, 0x0000, 0x0000 },
+  { '[', 0x005b, 0x007b, 0x0000, 0x0000 },
+  { '{', 0x005b, 0x007b, 0x0000, 0x0000 },
+  { ']', 0x005d, 0x007d, 0x0000, 0x0000 },
+  { '}', 0x005d, 0x007d, 0x0000, 0x0000 },
+  { '\\', 0x005c, 0x007c, 0x0000, 0x0000 },
+  { '|', 0x005c, 0x007c, 0x0000, 0x0000 },
+  { '/', 0x002f, 0x003f, 0x0000, 0x0000 },
+  { '?', 0x002f, 0x003f, 0x0000, 0x0000 },
+
+  { KEY_BACK, 0x0008, 0x0008, 0x007f, 0x0000 },
+  { KEY_TAB, 0x0009, 0x0f00, 0x0000, 0x0000 },
+  { KEY_RETURN, 0x000d, 0x000d, 0x000a, 0x0000 },
+  { KEY_ESCAPE, 0x001b, 0x001b, 0x001b, 0x0000 },
+  { KEY_SPACE, 0x0020, 0x0020, 0x0000, 0x0000 },
+  { KEY_LEFT, 0x4b00, 0x0034, 0x7300, 0xb200 },
+  { KEY_UP, 0x4800, 0x0038, 0xa000, 0xaf00 },
+  { KEY_RIGHT, 0x4d00, 0x0036, 0x7400, 0xb400 },
+  { KEY_DOWN, 0x5000, 0x0032, 0xa400, 0xb700 },
+  { KEY_NUMPAD_LEFT, 0x4b00, 0x0034, 0x7300, 0xb200 },
+  { KEY_NUMPAD_UP, 0x4800, 0x0038, 0xa000, 0xaf00 },
+  { KEY_NUMPAD_RIGHT, 0x4d00, 0x0036, 0x7400, 0xb400 },
+  { KEY_NUMPAD_DOWN, 0x5000, 0x0032, 0xa400, 0xb700 },
+  { KEY_DIVIDE, 0x002f, 0x002f, 0x0000, 0x0000 },
+  { KEY_MULTIPLY, 0x0038, 0x0038, 0x0000, 0x7f00 },
+  { KEY_SUBTRACT, 0x002d, 0x002d, 0x0000, 0x0000 },
+  { KEY_ADD, 0x003d, 0x003d, 0x0000, 0x0000 },
+  { KEY_HOME, 0x4700, 0x0037, 0x7700, 0xae00 },
+  { KEY_END, 0x4f00, 0x0031, 0x7500, 0xb600 },
+  { KEY_PAGEUP, 0x4900, 0x0039, 0x8400, 0xb000 },
+  { KEY_PAGEDOWN, 0x5100, 0x0033, 0x7600, 0xb800 },
+  { KEY_INSERT, 0x5200, 0x0030, 0xa500, 0xb900 },
+  { KEY_DELETE, 0x5300, 0x002e, 0xa600, 0xba00 },
+  { KEY_ENTER, 0x000d, 0x000d, 0x000a, 0x0000 },
+  { KEY_NEXT, 0x5100, 0x0033, 0x7600, 0xb800 },
+  { KEY_PRIOR, 0x4900, 0x0039, 0x8400, 0xb000 },
+
+  { KEY_NUMPAD0, 0x0030, 0x0029, 0x0000, 0x8100 },
+  { KEY_NUMPAD1, 0x0031, 0x0021, 0x0000, 0x7800 },
+  { KEY_NUMPAD2, 0x0032, 0x0040, 0x0000, 0x7900 },
+  { KEY_NUMPAD3, 0x0033, 0x0023, 0x0000, 0x7a00 },
+  { KEY_NUMPAD4, 0x0034, 0x0024, 0x0000, 0x7b00 },
+  { KEY_NUMPAD5, 0x0035, 0x0025, 0x0000, 0x7c00 },
+  { KEY_NUMPAD6, 0x0036, 0x005e, 0x0000, 0x7d00 },
+  { KEY_NUMPAD7, 0x0037, 0x0026, 0x0000, 0x7e00 },
+  { KEY_NUMPAD8, 0x0038, 0x002a, 0x0000, 0x7f00 },
+  { KEY_NUMPAD9, 0x0039, 0x0028, 0x0000, 0x8000 },
+
+  { KEY_F1, 0x3b00, 0x5400, 0x5e00, 0x6800 },
+  { KEY_F2, 0x3c00, 0x5500, 0x5f00, 0x6900 },
+  { KEY_F3, 0x3d00, 0x5600, 0x6000, 0x6a00 },
+  { KEY_F4, 0x3e00, 0x5700, 0x6100, 0x6b00 },
+  { KEY_F5, 0x3f00, 0x5800, 0x6200, 0x6c00 },
+  { KEY_F6, 0x4000, 0x5900, 0x6300, 0x6d00 },
+  { KEY_F7, 0x4100, 0x5a00, 0x6400, 0x6e00 },
+  { KEY_F8, 0x4200, 0x5b00, 0x6500, 0x6f00 },
+  { KEY_F9, 0x4300, 0x5c00, 0x6600, 0x7000 },
+  { KEY_F10, 0x4400, 0x5d00, 0x6700, 0x7100 },
+  { KEY_F11, 0x0000, 0x0000, 0x0000, 0x0000 },
+  { KEY_F12, 0x0000, 0x0000, 0x0000, 0x0000 },
+  { KEY_NULL, 0, 0, 0, 0 }
+};
+#endif // GTERM_PC
+
+GTerm::VTKeySeq *
+GTerm::translate_vt_keycode(int keyCode, VTKeySeq *table)
+{
+  while(table->keyCode != KEY_NULL)
+  {
+    if(table->keyCode == keyCode)
+      return table;
+    table++;
+  }
+  return 0;
+}
+
+#ifdef GTERM_PC
+unsigned short
+GTerm::translate_pc_keycode(int keyCode, int shift, int ctrl, int alt)
+{
+  int
+    i;
+
+  if(keyCode < 1000)
+  {
+    if(isupper(keyCode))
+    {
+      if(!alt)
+        shift = 1;
+      keyCode = tolower(keyCode);
+    }
+
+    if(iscntrl(keyCode))
+    {
+      ctrl = 1;
+      keyCode = keyCode + 'a' - 1;
+    }
+  }
+
+//printf("looking for %d...", keyCode);
+  for(i = 0; pc_keys[i].keyCode; i++)
+  {
+    if(keyCode == pc_keys[i].keyCode)
+    {
+//printf("found!\n");
+      if(shift)
+        return pc_keys[i].shiftSeq;
+      if(ctrl)
+        return pc_keys[i].ctrlSeq;
+      if(alt)
+        return pc_keys[i].altSeq;
+      return pc_keys[i].normSeq;
+    }
+  }
+//printf("not found!\n");
+  return 0;
+}
+#endif // GTERM_PC
+
+int
+GTerm::TranslateKeyCode(int keyCode, int *len, char *data, int shift,
+                        int ctrl, int alt)
+{
+  int
+    mode = GetMode();
+
+#ifdef GTERM_PC
+  unsigned short
+    pcKeySeq;
+#endif // GTERM_PC
+
+  VTKeySeq
+    *keySeq;
+
+//printf("keycode = %d, shift = %d, ctrl = %d, alt = %d\n", keyCode, shift, ctrl, alt);
+//printf("GTerm::TranslateKeyCode(): mode = %x\n", mode);
+#ifdef GTERM_PC
+  if(mode & PC)
+  {
+    pcKeySeq = translate_pc_keycode(keyCode, shift, ctrl, alt);
+    if(pcKeySeq)
+    {
+//printf("keySeq = %x\n", pcKeySeq);
+      *(unsigned char *)data++ = pcKeySeq >> 8;
+      *(unsigned char *)data = pcKeySeq & 0xff;
+      *len = 2;
+      return 1;
+    }
+    return 0;
+  }
+  else
+  {
+#endif // GTERM_PC
+//printf("mode = %x\n", mode);
+    if(mode & KEYAPPMODE)
+    {
+//printf("KEYAPPMODE\n");
+      keySeq = translate_vt_keycode(keyCode, keypad_app_keys);
+    }
+    else
+      keySeq = translate_vt_keycode(keyCode, keypad_keys);
+
+    if(!keySeq)
+    {
+      if(mode & CURSORAPPMODE)
+      {
+//printf("CURSORAPPMODE\n");
+        keySeq = translate_vt_keycode(keyCode, cursor_app_keys);
+//printf("keySeq = %08x\n", keySeq);
+      }
+      else
+        keySeq = translate_vt_keycode(keyCode, cursor_keys);
+    }
+
+    if(!keySeq)
+      keySeq = translate_vt_keycode(keyCode, other_keys);
+
+    if(keySeq)
+    {
+      *len = strlen(keySeq->seq);
+      strcpy(data, keySeq->seq);
+      return 1;
+    }
+    return 0;
+#ifdef GTERM_PC
+  }
+#endif // GTERM_PC
+}

+ 148 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/states.cpp

@@ -0,0 +1,148 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 1999  Timothy Miller
+              2004  Mark Erikson
+              2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+
+/* GRG: Added a lot of GTerm:: prefixes to correctly form pointers
+ *   to functions in all the tables. Example: &cr -> &GTerm::cr
+ */
+
+#include "gterm.hpp"
+
+// state machine transition tables
+StateOption GTerm::normal_state[] = {
+    { 13, &GTerm::cr,      normal_state },
+    { 10, &GTerm::lf,      normal_state },
+    { 12, &GTerm::ff,      normal_state },
+    { 9,  &GTerm::tab,     normal_state },
+    { 8,  &GTerm::bs,      normal_state },
+    { 7,  &GTerm::bell,        normal_state },
+	{ 27, 0,		esc_state },
+    { -1, &GTerm::normal_input,    normal_state} };
+
+StateOption GTerm::esc_state[] = {
+    { '[', &GTerm::clear_param,    bracket_state },
+    { '>', &GTerm::keypad_numeric, normal_state },
+    { '=', &GTerm::keypad_application, normal_state },
+    { '7', &GTerm::save_cursor,    normal_state },
+    { '8', &GTerm::restore_cursor, normal_state },
+    { 'H', &GTerm::set_tab,    normal_state },
+    { 'D', &GTerm::index_down, normal_state },
+    { 'M', &GTerm::index_up,   normal_state },
+    { 'E', &GTerm::next_line,  normal_state },
+    { 'c', &GTerm::reset,      normal_state },
+	{ '(', 0,		cset_shiftin_state },
+	{ ')', 0,		cset_shiftout_state },
+	{ '#', 0,		hash_state },
+#ifdef GTERM_PC
+        { '!', &GTerm::pc_begin,       pc_cmd_state },
+#endif
+
+    { 13, &GTerm::cr,      esc_state },    // standard VT100 wants
+    { 10, &GTerm::lf,      esc_state },    // cursor controls in
+    { 12, &GTerm::ff,      esc_state },    // the middle of ESC
+    { 9,  &GTerm::tab,     esc_state },    // sequences
+    { 8,  &GTerm::bs,      esc_state },
+    { 7,  &GTerm::bell,        esc_state },
+	{ -1, 0, normal_state} };
+
+// Should but cursor control characters in these groups as well.
+// Maybe later.
+
+StateOption GTerm::cset_shiftin_state[] = {
+	{ 'A', 0,		normal_state },	// should set UK characters
+	{ '0', 0,		normal_state },	// should set Business Gfx
+	{ -1, 0,		normal_state },	// default to ASCII
+	};
+
+StateOption GTerm::cset_shiftout_state[] = {
+	{ 'A', 0,		normal_state },	// should set UK characters
+	{ '0', 0,		normal_state },	// should set Business Gfx
+	{ -1, 0,		normal_state },	// default to ASCII
+	};
+
+StateOption GTerm::hash_state[] = {
+    { '8', &GTerm::screen_align,   normal_state },
+	{ -1, 0, normal_state} };
+
+StateOption GTerm::bracket_state[] = {
+    { '?', &GTerm::set_q_mode, bracket_state },
+    { '"', &GTerm::set_quote_mode, bracket_state },
+    { '0', &GTerm::param_digit,    bracket_state },
+    { '1', &GTerm::param_digit,    bracket_state },
+    { '2', &GTerm::param_digit,    bracket_state },
+    { '3', &GTerm::param_digit,    bracket_state },
+    { '4', &GTerm::param_digit,    bracket_state },
+    { '5', &GTerm::param_digit,    bracket_state },
+    { '6', &GTerm::param_digit,    bracket_state },
+    { '7', &GTerm::param_digit,    bracket_state },
+    { '8', &GTerm::param_digit,    bracket_state },
+    { '9', &GTerm::param_digit,    bracket_state },
+    { ';', &GTerm::next_param, bracket_state },
+    { 'D', &GTerm::cursor_left,    normal_state },
+    { 'B', &GTerm::cursor_down,    normal_state },
+    { 'C', &GTerm::cursor_right,   normal_state },
+    { 'A', &GTerm::cursor_up,  normal_state },
+    { 'H', &GTerm::cursor_position,    normal_state },
+    { 'f', &GTerm::cursor_position,    normal_state },
+    { 'c', &GTerm::device_attrib,  normal_state },
+    { 'P', &GTerm::delete_char,    normal_state },
+    { 'h', &GTerm::set_mode,   normal_state },
+    { 'l', &GTerm::clear_mode, normal_state },
+    { 's', &GTerm::save_cursor,    normal_state },
+    { 'u', &GTerm::restore_cursor, normal_state },
+    { 'x', &GTerm::request_param,  normal_state },
+    { 'r', &GTerm::set_margins,    normal_state },
+    { 'M', &GTerm::delete_line,    normal_state },
+    { 'n', &GTerm::status_report,  normal_state },
+    { 'J', &GTerm::erase_display,  normal_state },
+    { 'K', &GTerm::erase_line, normal_state },
+    { 'L', &GTerm::insert_line,    normal_state },
+    { 'm', &GTerm::set_colors, normal_state },
+    { 'g', &GTerm::clear_tab,  normal_state },
+    { '@', &GTerm::insert_char,    normal_state },
+    { 'X', &GTerm::erase_char, normal_state },
+	{ 'p', 0, 		normal_state },	// something to do with levels
+
+    { 13, &GTerm::cr,      bracket_state },// standard VT100 wants
+    { 10, &GTerm::lf,      bracket_state },// cursor controls in
+    { 12, &GTerm::ff,      bracket_state },// the middle of ESC
+    { 9,  &GTerm::tab,     bracket_state },// sequences
+    { 8,  &GTerm::bs,      bracket_state },
+    { 7,  &GTerm::bell,        bracket_state },
+	{ -1, 0, normal_state} };
+
+#ifdef GTERM_PC
+
+StateOption GTerm::pc_cmd_state[] =
+{
+        { GTERM_PC_CMD_CURONOFF,        &GTerm::pc_cmd,     pc_arg_state },
+        { GTERM_PC_CMD_MOVECURSOR,      &GTerm::pc_cmd,     pc_arg_state },
+        { GTERM_PC_CMD_PUTTEXT,         &GTerm::pc_cmd,     pc_arg_state },
+        { GTERM_PC_CMD_WRITE,           &GTerm::pc_cmd,     pc_arg_state },
+        { GTERM_PC_CMD_MOVETEXT,        &GTerm::pc_cmd,     pc_arg_state },
+        { GTERM_PC_CMD_EXIT,            &GTerm::pc_end,     normal_state },
+        { GTERM_PC_CMD_BEEP,            &GTerm::pc_cmd,     pc_cmd_state },
+        { GTERM_PC_CMD_SELECTPRINTER,   &GTerm::pc_cmd,     pc_arg_state },
+        { GTERM_PC_CMD_PRINTCHAR,       &GTerm::pc_cmd,     pc_arg_state },
+        { GTERM_PC_CMD_PRINTCHARS,      &GTerm::pc_cmd,     pc_arg_state },
+        { -1,                           &GTerm::pc_cmd,     pc_cmd_state }
+};
+
+StateOption GTerm::pc_arg_state[] =
+{
+        { -1,                           &GTerm::pc_arg,     pc_arg_state }
+};
+
+StateOption GTerm::pc_data_state[] =
+{
+        { -1,                           &GTerm::pc_data,    pc_data_state }
+};
+
+#endif // GTERM_PC

+ 227 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/utils.cpp

@@ -0,0 +1,227 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 1999  Timothy Miller
+              2004  Mark Erikson
+              2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+
+#include "gterm.hpp"
+//#include <stdlib.h>
+
+int GTerm::calc_color(int fg, int bg, int flags)
+{
+	return (flags & 15) | (fg << 4) | (bg << 8);
+}
+
+void GTerm::update_changes()
+{
+    int yp, start_x, mx;
+    int blank, c, x, y;
+
+    // prevent recursion for scrolls which cause exposures
+    if (doing_update) return;
+    doing_update = 1;
+
+    // first perform scroll-copy
+    mx = scroll_bot-scroll_top+1;
+    if (!(mode_flags & TEXTONLY) && pending_scroll &&
+	pending_scroll<mx && -pending_scroll<mx) {
+	if (pending_scroll<0) {
+	    MoveChars(0, scroll_top, 0, scroll_top-pending_scroll,
+		width, scroll_bot-scroll_top+pending_scroll+1);
+	} else {
+	    MoveChars(0, scroll_top+pending_scroll, 0, scroll_top,
+		width, scroll_bot-scroll_top-pending_scroll+1);
+	}
+    }
+    pending_scroll = 0;
+
+    // then update characters
+    for (y=0; y<height; y++) {
+	if (dirty_startx[y]>=MAXWIDTH) continue;
+	yp = linenumbers[y]*MAXWIDTH;
+
+	blank = !(mode_flags & TEXTONLY);
+	start_x = dirty_startx[y];
+	c = color[yp+start_x];
+	for (x=start_x; x<=dirty_endx[y]; x++) {
+	    if (text[yp+x]!=32 && text[yp+x]) blank = 0;
+	    if (c != color[yp+x]) {
+		if (!blank) {
+                  if(mode_flags & PC)
+		    DrawText((c>>4)&0xf, (c>>8)&0xf, c/*&15*/, start_x,
+			y, x-start_x, text+yp+start_x);
+                  else
+		    DrawText((c>>4)&7, (c>>8)&7, c/*&15*/, start_x,
+			y, x-start_x, text+yp+start_x);
+		} else {
+	    	    ClearChars((c>>8)&7, start_x, y, x-start_x, 1);
+		}
+		start_x = x;
+		c = color[yp+x];
+		blank = !(mode_flags & TEXTONLY);
+	    	if (text[yp+x]!=32 && text[yp+x]) blank = 0;
+	    }
+	}
+		if (!blank) {
+                  if(mode_flags & PC)
+		    DrawText((c>>4)&0xf, (c>>8)&0xf, c/*&15*/, start_x,
+			y, x-start_x, text+yp+start_x);
+                  else
+		    DrawText((c>>4)&7, (c>>8)&7, c/*&15*/, start_x,
+			y, x-start_x, text+yp+start_x);
+		} else {
+	    	    ClearChars((c>>8)&7, start_x, y, x-start_x, 1);
+		}
+
+	dirty_endx[y] = 0;
+	dirty_startx[y] = MAXWIDTH;
+    }
+
+    if (!(mode_flags & CURSORINVISIBLE)) {
+	x = cursor_x;
+	if (x>=width) x = width-1;
+        yp = linenumbers[cursor_y]*MAXWIDTH+x;
+        c = color[yp];
+        if(mode_flags & PC)
+          DrawCursor((c>>4)&0xf, (c>>8)&0xf, c&15, x, cursor_y, text[yp]);
+        else
+          DrawCursor((c>>4)&7, (c>>8)&7, c&15, x, cursor_y, text[yp]);
+    }
+
+    doing_update = 0;
+}
+
+void GTerm::scroll_region(int start_y, int end_y, int num)
+{
+	int y, takey, fast_scroll, mx, clr, x, yp, c;
+	short temp[MAXHEIGHT];
+	unsigned char temp_sx[MAXHEIGHT], temp_ex[MAXHEIGHT];
+
+	if (!num) return;
+	mx = end_y-start_y+1;
+	if (num > mx) num = mx;
+	if (-num > mx) num = -mx;
+
+	fast_scroll = (start_y == scroll_top && end_y == scroll_bot &&
+		!(mode_flags & TEXTONLY));
+
+	if (fast_scroll) pending_scroll += num;
+
+	memcpy(temp, linenumbers, sizeof(linenumbers));
+	if (fast_scroll) {
+		memcpy(temp_sx, dirty_startx, sizeof(dirty_startx));
+		memcpy(temp_ex, dirty_endx, sizeof(dirty_endx));
+	}
+
+        c = calc_color(fg_color, bg_color, mode_flags);
+
+	// move the lines by renumbering where they point to
+	if (num<mx && -num<mx) for (y=start_y; y<=end_y; y++) {
+		takey = y+num;
+		clr = (takey<start_y) || (takey>end_y);
+		if (takey<start_y) takey = end_y+1-(start_y-takey);
+		if (takey>end_y) takey = start_y-1+(takey-end_y);
+
+		linenumbers[y] = temp[takey];
+		if (!fast_scroll || clr) {
+			dirty_startx[y] = 0;
+			dirty_endx[y] = width-1;
+		} else {
+			dirty_startx[y] = temp_sx[takey];
+			dirty_endx[y] = temp_ex[takey];
+		}
+		if (clr) {
+			yp = linenumbers[y]*MAXWIDTH;
+			memset(text+yp, 32, width);
+			for (x=0; x<width; x++) {
+				color[yp++] = c;
+			}
+		}
+	}
+}
+
+void GTerm::shift_text(int y, int start_x, int end_x, int num)
+{
+     int x, yp, mx, c;
+
+     if (!num) return;
+
+     yp = linenumbers[y]*MAXWIDTH;
+
+     mx = end_x-start_x+1;
+     if (num>mx) num = mx;
+     if (-num>mx) num = -mx;
+
+     if (num<mx && -num<mx) {
+	if (num<0) {
+	    memmove(text+yp+start_x, text+yp+start_x-num, mx+num);
+	    memmove(color+yp+start_x, color+yp+start_x-num, (mx+num)<<1);
+	} else {
+	    memmove(text+yp+start_x+num, text+yp+start_x, mx-num);
+	    memmove(color+yp+start_x+num, color+yp+start_x, (mx-num)<<1);
+	}
+    }
+
+    if (num<0) {
+	x = yp+end_x+num+1;
+    } else {
+	x = yp+start_x;
+    }
+    num = abs(num);
+    memset(text+x, 32, num);
+    c = calc_color(fg_color, bg_color, mode_flags);
+    while (num--) color[x++] = c;
+
+    changed_line(y, start_x, end_x);
+}
+
+void GTerm::clear_area(int start_x, int start_y, int end_x, int end_y)
+{
+	int x, y, c, yp, w;
+
+    	c = calc_color(fg_color, bg_color, mode_flags);
+
+	w = end_x - start_x + 1;
+	if (w<1) return;
+
+	for (y=start_y; y<=end_y; y++) {
+		yp = linenumbers[y]*MAXWIDTH;
+		memset(text+yp+start_x, 32, w);
+		for (x=start_x; x<=end_x; x++) {
+			color[yp+x] = c;
+		}
+		changed_line(y, start_x, end_x);
+	}
+}
+
+void GTerm::changed_line(int y, int start_x, int end_x)
+{
+	if (dirty_startx[y] > start_x) dirty_startx[y] = start_x;
+	if (dirty_endx[y] < end_x) dirty_endx[y] = end_x;
+}
+
+void GTerm::move_cursor(int x, int y)
+{
+	if (cursor_x>=width) cursor_x = width-1;
+	changed_line(cursor_y, cursor_x, cursor_x);
+	cursor_x = x;
+	cursor_y = y;
+}
+
+void GTerm::set_mode_flag(int flag)
+{
+	mode_flags |= flag;
+	ModeChange(mode_flags);
+}
+
+void GTerm::clear_mode_flag(int flag)
+{
+	mode_flags &= ~flag;
+	ModeChange(mode_flags);
+}
+

+ 53 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/GTerm/vt52_states.cpp

@@ -0,0 +1,53 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 1999  Timothy Miller
+              2004  Mark Erikson
+              2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+/* GRG: Added a lot of GTerm:: prefixes to correctly form pointers
+ *   to functions in all the tables. Example: &cr -> &GTerm::cr
+ */
+
+#include "gterm.hpp"
+
+// I'm certain that this set is incomplete, but I got these from reverse-
+// engineering a VT100 verification test program.
+
+
+// state machine transition tables
+StateOption GTerm::vt52_normal_state[] = {
+    { 13, &GTerm::cr,      vt52_normal_state },
+    { 10, &GTerm::lf,      vt52_normal_state },
+    { 12, &GTerm::ff,      vt52_normal_state },
+    { 9,  &GTerm::tab,     vt52_normal_state },
+    { 8,  &GTerm::bs,      vt52_normal_state },
+    { 7,  &GTerm::bell,        vt52_normal_state },
+    { 27, &GTerm::clear_param, vt52_esc_state },
+    { -1, &GTerm::normal_input,    vt52_normal_state } };
+
+StateOption GTerm::vt52_esc_state[] = {
+    { 'D', &GTerm::cursor_left,    vt52_normal_state },
+    { 'B', &GTerm::cursor_down,    vt52_normal_state },
+    { 'C', &GTerm::cursor_right,   vt52_normal_state },
+    { 'A', &GTerm::cursor_up,  vt52_normal_state },
+	{ 'Y', 0,		vt52_cursory_state },
+    { 'J', &GTerm::erase_display,  vt52_normal_state },
+    { 'K', &GTerm::erase_line, vt52_normal_state },
+    { 'H', &GTerm::cursor_position,    vt52_normal_state },
+    { 'I', &GTerm::index_up,   vt52_normal_state },
+	{ 'F', 0,		vt52_normal_state }, // graphics mode
+	{ 'G', 0,		vt52_normal_state }, // ASCII mode
+    { 'Z', &GTerm::vt52_ident, vt52_normal_state }, // identify
+	{ '<', 0,		normal_state },
+	{ -1, 0, vt52_normal_state }};
+
+StateOption GTerm::vt52_cursory_state[] = {
+    { -1, &GTerm::vt52_cursory,    vt52_cursorx_state } };
+
+StateOption GTerm::vt52_cursorx_state[] = {
+    { -1, &GTerm::vt52_cursorx,    vt52_normal_state } };
+

+ 1925 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/taTelnet/wxterm.cpp

@@ -0,0 +1,1925 @@
+/*
+    taTelnet - A cross-platform telnet program.
+    Copyright (c) 2000 Derry Bryson
+                  2004 Mark Erikson
+                  2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+#ifdef __GNUG__
+    #pragma implementation "wxterm.h"
+#endif
+
+// For compilers that support precompilation, includes "wx/wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#include <wx/timer.h>
+#include <wx/event.h>
+#include <wx/bitmap.h>
+#include <wx/brush.h>
+#include <wx/cursor.h>
+#include <wx/dcclient.h>
+#include <wx/log.h>
+#include <wx/pen.h>
+#include <wx/settings.h>
+#include <wx/utils.h>
+
+#include <ctype.h>
+
+#include "../GTerm/gterm.hpp"
+#include "wxterm.h"
+
+
+
+#define CURSOR_BLINK_DEFAULT_TIMEOUT	300
+#define CURSOR_BLINK_MAX_TIMEOUT	2000
+
+/*
+**  Keycode translation tables
+*/
+wxTerm::TermKeyMap wxTerm::keyMapTable[] =
+{
+  { WXK_BACK, GTerm::KEY_BACK },
+  { WXK_TAB, GTerm::KEY_TAB },
+  { WXK_RETURN, GTerm::KEY_RETURN },
+  { WXK_ESCAPE, GTerm::KEY_ESCAPE },
+  { WXK_SPACE, GTerm::KEY_SPACE },
+  { WXK_LEFT, GTerm::KEY_LEFT },
+  { WXK_UP, GTerm::KEY_UP },
+  { WXK_RIGHT, GTerm::KEY_RIGHT },
+  { WXK_DOWN, GTerm::KEY_DOWN },
+//  { WXK_DIVIDE, GTerm::KEY_DIVIDE },
+//  { WXK_MULTIPLY, GTerm::KEY_MULTIPLY },
+//  { WXK_SUBTRACT, GTerm::KEY_SUBTRACT },
+//  { WXK_ADD, GTerm::KEY_ADD },
+  { WXK_HOME, GTerm::KEY_HOME },
+  { WXK_END, GTerm::KEY_END },
+  { WXK_PAGEUP, GTerm::KEY_PAGEUP },
+  { WXK_PAGEDOWN, GTerm::KEY_PAGEDOWN },
+  { WXK_INSERT, GTerm::KEY_INSERT },
+  { WXK_DELETE, GTerm::KEY_DELETE },
+//  { WXK_NEXT, GTerm::KEY_NEXT },
+//  { WXK_PRIOR, GTerm::KEY_PRIOR },
+//  { WXK_NUMPAD0, GTerm::KEY_NUMPAD0 },
+//  { WXK_NUMPAD1, GTerm::KEY_NUMPAD1 },
+//  { WXK_NUMPAD2, GTerm::KEY_NUMPAD2 },
+//  { WXK_NUMPAD3, GTerm::KEY_NUMPAD3 },
+//  { WXK_NUMPAD4, GTerm::KEY_NUMPAD4 },
+//  { WXK_NUMPAD5, GTerm::KEY_NUMPAD5 },
+//  { WXK_NUMPAD6, GTerm::KEY_NUMPAD6 },
+//  { WXK_NUMPAD7, GTerm::KEY_NUMPAD7 },
+//  { WXK_NUMPAD8, GTerm::KEY_NUMPAD8 },
+//  { WXK_NUMPAD9, GTerm::KEY_NUMPAD9 },
+//  { WXK_DECIMAL, GTerm::KEY_NUMPAD_DECIMAL },
+  { WXK_F1, GTerm::KEY_F1 },
+  { WXK_F2, GTerm::KEY_F2 },
+  { WXK_F3, GTerm::KEY_F3 },
+  { WXK_F4, GTerm::KEY_F4 },
+  { WXK_F5, GTerm::KEY_F5 },
+  { WXK_F6, GTerm::KEY_F6 },
+  { WXK_F7, GTerm::KEY_F7 },
+  { WXK_F8, GTerm::KEY_F8 },
+  { WXK_F9, GTerm::KEY_F9 },
+  { WXK_F10, GTerm::KEY_F10 },
+  { WXK_F11, GTerm::KEY_F11 },
+  { WXK_F12, GTerm::KEY_F12 },
+  { (wxKeyCode)0, GTerm::KEY_NULL }
+};
+
+static unsigned char
+  xCharMap[] =
+  {
+    0, // 0
+    1, // 1
+    2, // 2
+    3, // 3
+    1, // 4
+    5, // 5
+    6, // 6
+    7, // 7
+    8, // 8
+    9, // 9
+    10, // 10
+    11, // 11
+    12, // 12
+    13, // 13
+    14, // 14
+    15, // 15
+    62, // 16
+    60, // 17
+    18, // 18
+    19, // 19
+    20, // 20
+    21, // 21
+    22, // 22
+    23, // 23
+    24, // 24
+    25, // 25
+    26, // 26
+    27, // 27
+    28, // 28
+    29, // 29
+    94, // 30
+    31, // 31
+    32, // 32
+    33, // 33
+    34, // 34
+    35, // 35
+    36, // 36
+    37, // 37
+    38, // 38
+    39, // 39
+    40, // 40
+    41, // 41
+    42, // 42
+    43, // 43
+    44, // 44
+    45, // 45
+    46, // 46
+    47, // 47
+    48, // 48
+    49, // 49
+    50, // 50
+    51, // 51
+    52, // 52
+    53, // 53
+    54, // 54
+    55, // 55
+    56, // 56
+    57, // 57
+    58, // 58
+    59, // 59
+    60, // 60
+    61, // 61
+    62, // 62
+    63, // 63
+    64, // 64
+    65, // 65
+    66, // 66
+    67, // 67
+    68, // 68
+    69, // 69
+    70, // 70
+    71, // 71
+    72, // 72
+    73, // 73
+    74, // 74
+    75, // 75
+    76, // 76
+    77, // 77
+    78, // 78
+    79, // 79
+    80, // 80
+    81, // 81
+    82, // 82
+    83, // 83
+    84, // 84
+    85, // 85
+    86, // 86
+    87, // 87
+    88, // 88
+    89, // 89
+    90, // 90
+    91, // 91
+    92, // 92
+    93, // 93
+    94, // 94
+    95, // 95
+    96, // 96
+    97, // 97
+    98, // 98
+    99, // 99
+    100, // 100
+    101, // 101
+    102, // 102
+    103, // 103
+    104, // 104
+    105, // 105
+    106, // 106
+    107, // 107
+    108, // 108
+    109, // 109
+    110, // 110
+    111, // 111
+    112, // 112
+    113, // 113
+    114, // 114
+    115, // 115
+    116, // 116
+    117, // 117
+    118, // 118
+    119, // 119
+    120, // 120
+    121, // 121
+    122, // 122
+    123, // 123
+    124, // 124
+    125, // 125
+    126, // 126
+    127, // 127
+    128, // 128
+    129, // 129
+    130, // 130
+    131, // 131
+    132, // 132
+    133, // 133
+    134, // 134
+    135, // 135
+    136, // 136
+    137, // 137
+    138, // 138
+    139, // 139
+    140, // 140
+    141, // 141
+    142, // 142
+    143, // 143
+    144, // 144
+    145, // 145
+    146, // 146
+    147, // 147
+    148, // 148
+    149, // 149
+    150, // 150
+    151, // 151
+    152, // 152
+    153, // 153
+    154, // 154
+    155, // 155
+    156, // 156
+    157, // 157
+    158, // 158
+    159, // 159
+    160, // 160
+    161, // 161
+    162, // 162
+    163, // 163
+    164, // 164
+    165, // 165
+    166, // 166
+    167, // 167
+    168, // 168
+    169, // 169
+    170, // 170
+    171, // 171
+    172, // 172
+    173, // 173
+    174, // 174
+    175, // 175
+    2, // 176
+    2, // 177
+    2, // 178
+    25, // 179
+    22, // 180
+    22, // 181
+    22, // 182
+    12, // 183
+    12, // 184
+    22, // 185
+    25, // 186
+    12, // 187
+    11, // 188
+    11, // 189
+    11, // 190
+    12, // 191
+    14, // 192
+    23, // 193
+    24, // 194
+    21, // 195
+    18, // 196
+    15, // 197
+    21, // 198
+    21, // 199
+    14, // 200
+    13, // 201
+    23, // 202
+    24, // 203
+    21, // 204
+    18, // 205
+    15, // 206
+    23, // 207
+    23, // 208
+    24, // 209
+    24, // 210
+    14, // 211
+    14, // 212
+    13, // 213
+    13, // 214
+    15, // 215
+    15, // 216
+    11, // 217
+    13, // 218
+    0, // 219
+    220, // 220
+    221, // 221
+    222, // 222
+    223, // 223
+    224, // 224
+    225, // 225
+    226, // 226
+    227, // 227
+    228, // 228
+    229, // 229
+    230, // 230
+    231, // 231
+    232, // 232
+    233, // 233
+    234, // 234
+    235, // 235
+    236, // 236
+    237, // 237
+    238, // 238
+    239, // 239
+    240, // 240
+    241, // 241
+    242, // 242
+    243, // 243
+    244, // 244
+    245, // 245
+    246, // 246
+    247, // 247
+    248, // 248
+    249, // 249
+    250, // 250
+    251, // 251
+    252, // 252
+    253, // 253
+    254, // 254
+    255  // 255
+  };
+
+BEGIN_EVENT_TABLE(wxTerm, wxWindow)
+  EVT_PAINT						(wxTerm::OnPaint)
+  EVT_CHAR						(wxTerm::OnChar)
+  EVT_LEFT_DOWN					(wxTerm::OnLeftDown)
+  EVT_LEFT_UP					(wxTerm::OnLeftUp)
+  EVT_MOTION					(wxTerm::OnMouseMove)
+  EVT_TIMER						(-1, wxTerm::OnTimer)
+#if 0
+  EVT_KEY_DOWN(wxTerm::OnKeyDown)
+#endif
+
+  EVT_SIZE						(wxTerm::OnSize)
+  EVT_SET_FOCUS					(wxTerm::OnGainFocus)
+  EVT_KILL_FOCUS				(wxTerm::OnLoseFocus)
+END_EVENT_TABLE()
+
+wxTerm::wxTerm(wxWindow* parent, wxWindowID id,
+               const wxPoint& pos,
+               int width, int height,
+               const wxString& name) :
+  wxWindow(parent, id, pos, wxSize(-1, -1), wxWANTS_CHARS, name),
+  GTerm(width, height)
+{
+  int
+    i;
+
+  m_inUpdateSize = false;
+  m_init = 1;
+
+  m_curDC = 0;
+
+  m_charsInLine = width;
+  m_linesDisplayed = height;
+
+  m_selecting = FALSE;
+  m_selx1 = m_sely1 = m_selx2 = m_sely2 = 0;
+  m_marking = FALSE;
+  m_curX = -1;
+  m_curY = -1;
+  m_curBlinkRate = CURSOR_BLINK_DEFAULT_TIMEOUT;
+  m_timer.SetOwner(this);
+  if(m_curBlinkRate)
+    m_timer.Start(m_curBlinkRate);
+
+  m_boldStyle = COLOR;
+
+  GetDefVTColors(m_vt_colors);
+  GetDefPCColors(m_pc_colors);
+
+  m_colors = m_vt_colors;
+
+  SetBackgroundColour(m_colors[0]);
+
+  for(i = 0; i < 16; i++)
+    m_vt_colorPens[i] = wxPen(m_vt_colors[i], 1, wxSOLID);
+
+  for(i = 0; i < 16; i++)
+    m_pc_colorPens[i] = wxPen(m_pc_colors[i], 1, wxSOLID);
+
+  m_colorPens = m_vt_colorPens;
+
+  m_width = width;
+  m_height = height;
+
+  m_printerFN = 0;
+  m_printerName = 0;
+
+
+
+  m_normalFont = GetFont();
+  m_underlinedFont = GetFont();
+  m_underlinedFont.SetUnderlined(TRUE);
+  m_boldFont = GetFont();
+  m_boldFont.SetWeight(wxBOLD);
+  m_boldUnderlinedFont = m_boldFont;
+  m_boldUnderlinedFont.SetUnderlined(TRUE);
+
+  m_bitmap = 0;
+
+
+  //ResizeTerminal(width, height);
+
+
+  //SetVirtualSize(m_charWidth * 80, m_charHeight * 100);
+  //SetScrollRate(m_charWidth, m_charHeight);
+
+  m_init = 0;
+
+  SetCursor(wxCursor(wxCURSOR_IBEAM));
+
+  wxFont monospacedFont(10, wxMODERN, wxNORMAL, wxNORMAL, false, "Courier New");
+
+  SetFont(monospacedFont);
+
+  // 10pt Courier New is 8 pixels wide and 16 pixels high... set up
+  // a default client size to match
+  SetClientSize(m_charsInLine * 8, m_linesDisplayed * 16);
+  UpdateSize();
+}
+
+wxTerm::~wxTerm()
+{
+  if(m_bitmap)
+  {
+    m_memDC.SelectObject(wxNullBitmap);
+    delete m_bitmap;
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public SetBoldStyle
+///  Sets the bold style for the terminal
+///
+///  @param  boldStyle wxTerm::BOLDSTYLE & The style to be used
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::SetBoldStyle(wxTerm::BOLDSTYLE boldStyle)
+{
+//  wxColour colors[16];
+
+  if(boldStyle == DEFAULT)
+    boldStyle = COLOR;
+
+  m_boldStyle = boldStyle;
+//  GetDefVTColors(colors, m_boldStyle);
+//  SetVTColors(colors);
+  Refresh();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public SetFont
+///  Sets the font for the terminal
+///
+///  @param  font const wxFont & The font to be used
+///
+///  @return bool Unused (returns true)
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+bool
+wxTerm::SetFont(const wxFont& font)
+{
+  m_init = 1;
+
+  wxWindow::SetFont(font);
+  m_normalFont = font;
+  m_underlinedFont = font;
+  m_underlinedFont.SetUnderlined(TRUE);
+  m_boldFont = GetFont();
+  m_boldFont.SetWeight(wxBOLD);
+  m_boldUnderlinedFont = m_boldFont;
+  m_boldUnderlinedFont.SetUnderlined(TRUE);
+  m_init = 0;
+
+  ResizeTerminal(m_width, m_height);
+  Refresh();
+
+  return TRUE;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public GetDfVTColors
+///  Gets the colors for a VT100 terminal
+///
+///  @param  colors wxColour [] The colors that need to be assigned to
+///  @param  boldStyle wxTerm::BOLDSTYLE The bold style used in the terminal
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::GetDefVTColors(wxColour colors[16], wxTerm::BOLDSTYLE boldStyle)
+{
+  if(boldStyle == DEFAULT)
+    boldStyle = m_boldStyle;
+
+  if(boldStyle != COLOR)
+  {
+    colors[0] = wxColour(0, 0, 0);                             // black
+    colors[1] = wxColour(255, 0, 0);                           // red
+    colors[2] = wxColour(0, 255, 0);                           // green
+    colors[3] = wxColour(255, 0, 255);                         // yellow
+    colors[4] = wxColour(0, 0, 255);                           // blue
+    colors[5] = wxColour(255, 255, 0);                         // magenta
+    colors[6] = wxColour(0, 255, 255);                         // cyan
+    colors[7] = wxColour(255, 255, 255);                       // white
+    colors[8] = wxColour(0, 0, 0);                             // black
+    colors[9] = wxColour(255, 0, 0);                           // red
+    colors[10] = wxColour(0, 255, 0);                          // green
+    colors[11] = wxColour(255, 0, 255);                        // yellow
+    colors[12] = wxColour(0, 0, 255);                          // blue
+    colors[13] = wxColour(255, 255, 0);                        // magenta
+    colors[14] = wxColour(0, 255, 255);                        // cyan
+    colors[15] = wxColour(255, 255, 255);                      // white
+  }
+  else
+  {
+    colors[0] = wxColour(0, 0, 0);                             // black
+    colors[1] = wxColour(170, 0, 0);                           // red
+    colors[2] = wxColour(0, 170, 0);                           // green
+    colors[3] = wxColour(170, 0, 170);                         // yellow
+    colors[4] = wxColour(0, 0, 170);                           // blue
+    colors[5] = wxColour(170, 170, 0);                         // magenta
+    colors[6] = wxColour(0, 170, 170);                         // cyan
+    colors[7] = wxColour(192, 192, 192);                       // white
+//    colors[7] = wxColour(170, 170, 170);                       // white
+#if 0
+    colors[8] = wxColour(85, 85, 85);                          // bold black
+    colors[9] = wxColour(255, 85, 85);                         // bold red
+    colors[10] = wxColour(85, 255, 85);                        // bold green
+    colors[11] = wxColour(255, 85, 255);                       // bold yellow
+    colors[12] = wxColour(85, 85, 255);                        // bold blue
+    colors[13] = wxColour(255, 255, 85);                       // bold magenta
+    colors[14] = wxColour(85, 255, 255);                       // bold cyan
+    colors[15] = wxColour(255, 255, 255);                      // bold white
+#else
+    colors[8] = wxColour(85, 85, 85);                          // bold black
+    colors[9] = wxColour(255, 0, 0);                         // bold red
+    colors[10] = wxColour(0, 255, 0);                        // bold green
+    colors[11] = wxColour(255, 0, 255);                       // bold yellow
+    colors[12] = wxColour(0, 0, 255);                        // bold blue
+    colors[13] = wxColour(255, 255, 0);                       // bold magenta
+    colors[14] = wxColour(0, 255, 255);                       // bold cyan
+    colors[15] = wxColour(255, 255, 255);                      // bold white
+#endif
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public GetVTColors
+///  Retrieves a copy of the VT100 colors
+///
+///  @param  colors wxColour [] An array to be filled with the VT100 colors
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::GetVTColors(wxColour colors[16])
+{
+  int
+    i;
+
+  for(i = 0; i < 16; i++)
+    colors[i] = m_vt_colors[i];
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public SetVTColors
+///  Sets the VT100 colors
+///
+///  @param  colors wxColour [] The new colors to be used
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::SetVTColors(wxColour colors[16])
+{
+  int
+    i;
+
+  m_init = 1;
+  for(i = 0; i < 16; i++)
+    m_vt_colors[i] = colors[i];
+
+  if(!(GetMode() & PC))
+    SetBackgroundColour(m_vt_colors[0]);
+
+  for(i = 0; i < 16; i++)
+    m_vt_colorPens[i] = wxPen(m_vt_colors[i], 1, wxSOLID);
+  m_init = 0;
+
+  Refresh();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public GetDefPCColors
+///  Gets the default PC colors
+///
+///  @param  colors wxColour [] Filled with the colors to be used
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::GetDefPCColors(wxColour colors[16])
+{
+#if 0
+  /*
+  **  These colors need tweaking.  I'm sure they are not correct.
+  */
+  colors[0] = wxColour(0, 0, 0);                             // black
+  colors[1] = wxColour(0, 0, 128);                           // blue
+  colors[2] = wxColour(0, 128, 0);                           // green
+  colors[3] = wxColour(0, 128, 128);                         // cyan
+  colors[4] = wxColour(128, 0, 0);                           // red
+  colors[5] = wxColour(128, 0, 128);                         // magenta
+  colors[6] = wxColour(128, 128, 0);                         // brown
+  colors[7] = wxColour(128, 128, 128);                       // white
+  colors[8] = wxColour(64, 64, 64);                          // gray
+  colors[9] = wxColour(0, 0, 255);                           // lt blue
+  colors[10] = wxColour(0, 255, 0);                          // lt green
+  colors[11] = wxColour(0, 255, 255);                        // lt cyan
+  colors[12] = wxColour(255, 0, 0);                          // lt red
+  colors[13] = wxColour(255, 0, 255);                        // lt magenta
+  colors[14] = wxColour(255, 255, 0);                        // yellow
+  colors[15] = wxColour(255, 255, 255);                      // white
+#else
+  /*
+  **  These are much better
+  */
+  colors[0] = wxColour(0, 0, 0);                             // black
+  colors[1] = wxColour(0, 0, 170);                           // blue
+  colors[2] = wxColour(0, 170, 0);                           // green
+  colors[3] = wxColour(0, 170, 170);                         // cyan
+  colors[4] = wxColour(170, 0, 0);                           // red
+  colors[5] = wxColour(170, 0, 170);                         // magenta
+  colors[6] = wxColour(170, 170, 0);                         // brown
+  colors[7] = wxColour(170, 170, 170);                       // white
+#if 0
+  colors[8] = wxColour(85, 85, 85);                          // gray
+  colors[9] = wxColour(85, 85, 255);                         // lt blue
+  colors[10] = wxColour(85, 255, 85);                        // lt green
+  colors[11] = wxColour(85, 255, 255);                       // lt cyan
+  colors[12] = wxColour(255, 85, 85);                        // lt red
+  colors[13] = wxColour(255, 85, 255);                       // lt magenta
+  colors[14] = wxColour(255, 255, 85);                       // yellow
+  colors[15] = wxColour(255, 255, 255);                      // white
+#else
+  colors[8] = wxColour(50, 50, 50);                          // gray
+  colors[9] = wxColour(0, 0, 255);                         // lt blue
+  colors[10] = wxColour(0, 255, 0);                        // lt green
+  colors[11] = wxColour(0, 255, 255);                       // lt cyan
+  colors[12] = wxColour(255, 0, 0);                        // lt red
+  colors[13] = wxColour(255, 0, 255);                       // lt magenta
+  colors[14] = wxColour(255, 255, 0);                       // yellow
+  colors[15] = wxColour(255, 255, 255);                      // white
+#endif
+#endif
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public GetPCColors
+///  Retrieves the PC colors
+///
+///  @param  colors wxColour [] Filled with the PC colors
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::GetPCColors(wxColour colors[16])
+{
+  int
+    i;
+
+  for(i = 0; i < 16; i++)
+    colors[i] = m_pc_colors[i];
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public SetPCColors
+///  Sets the PC colors
+///
+///  @param  colors wxColour [] The new colors to be used
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::SetPCColors(wxColour colors[16])
+{
+  int
+    i;
+
+  m_init = 1;
+  for(i = 0; i < 16; i++)
+    m_pc_colors[i] = colors[i];
+
+  if(GetMode() & PC)
+    SetBackgroundColour(m_pc_colors[0]);
+
+  for(i = 0; i < 16; i++)
+    m_pc_colorPens[i] = wxPen(m_pc_colors[i], 1, wxSOLID);
+  m_init = 0;
+
+  Refresh();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public SetCursorBlinkRate
+///  Sets how often the cursor blinks
+///
+///  @param  rate int  How many milliseconds between blinks
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::SetCursorBlinkRate(int rate)
+{
+  if(rate < 0 || rate > CURSOR_BLINK_MAX_TIMEOUT)
+    return;
+
+  m_init = 1;
+  if(rate != m_curBlinkRate)
+  {
+    m_curBlinkRate = rate;
+    if(!m_curBlinkRate)
+      m_timer.Stop();
+    else
+      m_timer.Start(m_curBlinkRate);
+  }
+  m_init = 0;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private OnChar
+///  Handles user keyboard input and begins processing the server's response
+///
+///  @param  event wxKeyEvent & The generated key event
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::OnChar(wxKeyEvent& event)
+{
+  if(!(GetMode() & PC) && event.AltDown())
+    event.Skip();
+  else
+  {
+
+    int
+      rc,
+      keyCode = 0,
+      len;
+
+    unsigned char
+      buf[10];
+
+    /*
+    **  Map control characters
+    */
+    if(event.ControlDown())
+    {
+      if(event.GetKeyCode() >= 'a' && event.GetKeyCode() <= 'z')
+        keyCode = event.GetKeyCode() - 'a' + 1;
+      else if(event.GetKeyCode() >= '[' && event.GetKeyCode() <= '_')
+        keyCode = event.GetKeyCode() - '[' + 0x1b;
+      else if(event.GetKeyCode() == '6')
+        keyCode = 0x1e;
+      else if(event.GetKeyCode() == '-')
+        keyCode = 0x1f;
+    }
+
+    if(!keyCode && !(keyCode = MapKeyCode((int)event.GetKeyCode())))
+    {
+      /*
+      **  If the keycode wasn't mapped in the table and it is a special
+      **  key, then we just ignore it.
+      */
+      if(event.GetKeyCode() >= WXK_START)
+      {
+        event.Skip();
+        return;
+      }
+      /*
+      **  Otherwise, it must just be an ascii character
+      */
+      keyCode = (int)event.GetKeyCode();
+    }
+
+    if(GetMode() & PC)
+      rc = TranslateKeyCode(keyCode, &len, (char *)buf, event.ShiftDown(),
+                        event.ControlDown(), event.AltDown());
+    else
+      rc = TranslateKeyCode(keyCode, &len, (char *)buf);
+
+    if(rc)
+    {
+      if((GetMode() & NEWLINE) && !(GetMode() & PC) && (buf[len - 1] == 10))
+      {
+        buf[len - 1] = 13;
+        buf[len] = 10;
+        len++;
+      }
+      ProcessOutput(len, buf);
+      if((GetMode() & LOCALECHO) && !(GetMode() & PC))
+        ProcessInput(len, buf);
+    }
+    else if(!(GetMode() & PC))
+    {
+      if((GetMode() & NEWLINE) && !(GetMode() & PC) && (keyCode == 10))
+      {
+        len = 2;
+        buf[0] = 13;
+        buf[1] = keyCode;
+      }
+      else
+      {
+        len = 1;
+        buf[0] = keyCode;
+      }
+      ProcessOutput(len, buf);
+      if((GetMode() & LOCALECHO) && !(GetMode() & PC))
+        ProcessInput(len, buf);
+    }
+    else
+      event.Skip();
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private OnKeyDown
+///  Appears to be unused
+///
+///  @param  event wxKeyEvent & The generated key event
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::OnKeyDown(wxKeyEvent& event)
+{
+  if(!(GetMode() & PC) && event.AltDown())
+    event.Skip();
+  else if(event.AltDown())
+  {
+//    wxLogMessage("OnKeyDown() got KeyCode = %d", event.KeyCode());
+//    if(event.KeyCode() != 309)
+//      OnChar(event);
+  }
+  else
+    event.Skip();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private OnPaint
+///  Redraws the terminal widget
+///
+///  @param  event wxPaintEvent & The generated paint event
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::OnPaint(wxPaintEvent& WXUNUSED(event))
+{
+  wxPaintDC
+    dc(this);
+
+  m_curDC = &dc;
+  ExposeArea(0, 0, m_width, m_height);
+  m_curDC = 0;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private OnLeftDown
+///  Begins selection of terminal text
+///
+///  @param  event wxMouseEvent & The generated mouse event
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::OnLeftDown(wxMouseEvent& event)
+{
+	SetFocus();
+
+  ClearSelection();
+  m_selx1 = m_selx2 = event.GetX() / m_charWidth;
+  m_sely1 = m_sely2 = event.GetY() / m_charHeight;
+  m_selecting = TRUE;
+  CaptureMouse();
+
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private OnLeftUp
+///  Ends text selection
+///
+///  @param  event wxMouseEvent & The generated mouse event
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::OnLeftUp(wxMouseEvent& event)
+{
+
+  m_selecting = FALSE;
+  if(GetCapture() == this)
+  {
+	ReleaseMouse();
+  }
+
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private OnMouseMove
+///  Changes the selection if the mouse button is down
+///
+///  @param  event wxMouseEvent & The generated mouse event
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::OnMouseMove(wxMouseEvent& event)
+{
+
+  if(m_selecting)
+  {
+    m_selx2 = event.GetX() / m_charWidth;
+    if(m_selx2 >= Width())
+      m_selx2 = Width() - 1;
+    m_sely2 = event.GetY() / m_charHeight;
+    if(m_sely2 >= Height())
+      m_sely2 = Height() - 1;
+
+    MarkSelection();
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public ClearSelection
+///  De-selects all selected text
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::ClearSelection()
+{
+  int
+    x,
+    y;
+
+  wxClientDC
+    *dc = 0;
+
+  m_selx1 = m_sely1 = m_selx2 = m_sely2 = 0;
+
+  if(!m_curDC)
+  {
+    dc = new wxClientDC(this);
+    m_curDC = dc;
+  }
+
+  for(y = 0; y < Height(); y++)
+    for(x = 0; x < Width(); x++)
+      Select(x, y, 0);
+
+  if(dc)
+  {
+	  this->wxWindow::Update();
+
+    m_curDC = 0;
+    delete dc;
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private MarkSelection
+///  Does _something_ as far as selecting text, but not really sure... used for SelectAll, I think
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::MarkSelection()
+{
+  int
+    x,
+    y;
+
+  wxClientDC
+    *dc = 0;
+
+  m_marking = TRUE;
+
+  if(!m_curDC)
+  {
+    dc = new wxClientDC(this);
+    m_curDC = dc;
+  }
+
+  for(y = 0; y < Height(); y++)
+    for(x = 0; x < Width(); x++)
+      Select(x, y, 0);
+
+  if(m_sely1 == m_sely2)
+  {
+    if(m_selx1 >= m_selx2)
+      for(x = m_selx1; x <= m_selx2; x++)
+        Select(x, m_sely1, 1);
+    else
+      for(x = m_selx2; x >= m_selx1; x--)
+        Select(x, m_sely1, 1);
+  }
+  else if(m_sely1 < m_sely2)
+  {
+    for(x = m_selx1; x < Width(); x++)
+      Select(x, m_sely1, 1);
+
+    for(y = m_sely1 + 1; y < m_sely2; y++)
+      for(x = 0; x < Width(); x++)
+        Select(x, y, 1);
+
+    for(x = 0; x <= m_selx2; x++)
+      Select(x, m_sely2, 1);
+  }
+  else
+  {
+    for(x = 0; x <= m_selx1; x++)
+      Select(x, m_sely1, 1);
+
+    for(y = m_sely2 + 1; y < m_sely1; y++)
+      for(x = 0; x < Width(); x++)
+        Select(x, y, 1);
+
+    for(x = m_selx2; x < Width(); x++)
+      Select(x, m_sely2, 1);
+  }
+
+  this->wxWindow::Update();
+
+  if(dc)
+  {
+    m_curDC = 0;
+    delete dc;
+  }
+
+  m_marking = FALSE;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public HasSelection
+///  Checks if any text is selected
+///
+///  @return bool Whether or not there's any text selected
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+bool
+wxTerm::HasSelection()
+{
+  return(m_selx1 != m_selx2 || m_sely1 != m_sely2);
+}
+
+wxString
+//////////////////////////////////////////////////////////////////////////////
+///  public GetSelection
+///  Returns the selected text
+///
+///  @return wxString The selected text
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+wxTerm::GetSelection()
+{
+  int
+    x1,
+    y1,
+    x2,
+    y2;
+
+  wxString
+    sel;
+
+  if(m_sely1 <= m_sely2)
+  {
+    x1 = m_selx1;
+    y1 = m_sely1;
+    x2 = m_selx2;
+    y2 = m_sely2;
+  }
+  else
+  {
+    x1 = m_selx2;
+    y1 = m_sely2;
+    x2 = m_selx1;
+    y2 = m_sely1;
+  }
+
+  while(x1 != x2 || y1 != y2)
+  {
+    if(GetChar(x1, y1))
+      sel.Append(GetChar(x1, y1));
+
+    x1++;
+    if(x1 == Width())
+    {
+      sel.Append('\n');
+      x1 = 0;
+      y1++;
+    }
+  }
+  if(GetChar(x1, y1))
+    sel.Append(GetChar(x1, y1));
+
+  return sel;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public SelectAll
+///  Selects the whole terminal
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::SelectAll()
+{
+  m_selx1 = 0;
+  m_sely1 = 0;
+  m_selx2 = Width() - 1;
+  m_sely2 = Height() - 1;
+  MarkSelection();
+}
+
+/*
+**  GTerm stuff
+*/
+//////////////////////////////////////////////////////////////////////////////
+///  public virtual DrawText
+///  Responsible for actually drawing the terminal text on the widget.  This virtual
+///  function is called from GTerm::update_changes.
+///
+///  @param  fg_color int             The index of the foreground color
+///  @param  bg_color int             The index of the background color
+///  @param  flags    int             Modifiers for drawing the text
+///  @param  x        int             The x position in character cells
+///  @param  y        int             The y position in character cells
+///  @param  len      int             The number of characters to draw
+///  @param  string   unsigned char * The characters to draw
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::DrawText(int fg_color, int bg_color, int flags,
+                 int x, int y, int len, unsigned char *string)
+{
+  int
+    t;
+
+  if(flags & BOLD && m_boldStyle == COLOR)
+    fg_color = (fg_color % 8) + 8;
+
+  if(flags & SELECTED)
+  {
+    fg_color = 0;
+    bg_color = 15;
+  }
+
+  if(flags & INVERSE)
+  {
+    t = fg_color;
+    fg_color = bg_color;
+    bg_color = t;
+  }
+
+  if(!m_curDC)
+    return;
+
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+  int
+    i;
+
+  for(i = 0; string[i]; i++)
+    string[i] = xCharMap[string[i]];
+#endif
+
+  wxString
+    str(string, len);
+
+  if(m_boldStyle != FONT)
+  {
+    if(flags & UNDERLINE)
+      m_curDC->SetFont(m_underlinedFont);
+    else
+      m_curDC->SetFont(m_normalFont);
+  }
+  else
+  {
+    if(flags & BOLD)
+    {
+      if(flags & UNDERLINE)
+        m_curDC->SetFont(m_boldUnderlinedFont);
+      else
+        m_curDC->SetFont(m_boldFont);
+    }
+    else
+    {
+      if(flags & UNDERLINE)
+        m_curDC->SetFont(m_underlinedFont);
+      else
+        m_curDC->SetFont(m_normalFont);
+    }
+  }
+
+  x = x * m_charWidth;
+  y = y * m_charHeight;
+  m_curDC->SetBackgroundMode(wxSOLID);
+  m_curDC->SetTextBackground(m_colors[bg_color]);
+  m_curDC->SetTextForeground(m_colors[fg_color]);
+  m_curDC->DrawText(str, x, y);
+  if(flags & BOLD && m_boldStyle == OVERSTRIKE)
+  {
+    m_curDC->SetBackgroundMode(wxTRANSPARENT);
+    m_curDC->DrawText(str, x + 1, y);
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private DoDrawCursor
+///  Does the actual work of drawing the cursor
+///
+///  @param  fg_color int            The index of the foreground color
+///  @param  bg_color int            The index of the background color
+///  @param  flags    int            Modifier flags
+///  @param  x        int            The x position of the cursor, in characters
+///  @param  y        int            The y position of the cursor, in characters
+///  @param  c        unsigned char  The character the cursor is over
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::DoDrawCursor(int fg_color, int bg_color, int flags,
+                   int x, int y, unsigned char c)
+{
+
+  if(flags & BOLD && m_boldStyle == COLOR)
+    fg_color = (fg_color % 8) + 8;
+
+  if(flags & INVERSE)
+  {
+    int t = fg_color;
+    fg_color = bg_color;
+    bg_color = t;
+  }
+
+  if(!m_curDC)
+    return;
+
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+  c = xCharMap[c];
+#endif
+
+  wxString
+    str((char)c);
+
+  if(m_boldStyle != FONT)
+  {
+    if(flags & UNDERLINE)
+      m_curDC->SetFont(m_underlinedFont);
+    else
+      m_curDC->SetFont(m_normalFont);
+  }
+  else
+  {
+    if(flags & BOLD)
+    {
+      if(flags & UNDERLINE)
+        m_curDC->SetFont(m_boldUnderlinedFont);
+      else
+        m_curDC->SetFont(m_boldFont);
+    }
+    else
+    {
+      if(flags & UNDERLINE)
+        m_curDC->SetFont(m_underlinedFont);
+      else
+        m_curDC->SetFont(m_normalFont);
+    }
+  }
+
+  x = x * m_charWidth;
+  y = y * m_charHeight;
+  m_curDC->SetBackgroundMode(wxSOLID);
+  m_curDC->SetTextBackground(m_colors[fg_color]);
+  m_curDC->SetTextForeground(m_colors[bg_color]);
+  m_curDC->DrawText(str, x, y);
+  if(flags & BOLD && m_boldStyle == OVERSTRIKE)
+    m_curDC->DrawText(str, x + 1, y);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public virtual DrawCursor
+///  Draws the cursor on the terminal widget.  This virtual function is called
+///  from GTerm::update_changes.
+///
+///  @param  fg_color int            The index of the foreground color
+///  @param  bg_color int            The index of the background color
+///  @param  flags    int            Modifiers for drawing the cursor
+///  @param  x        int            The x position in character cells
+///  @param  y        int            The y position in character cells
+///  @param  c        unsigned char  The character that underlies the cursor
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::DrawCursor(int fg_color, int bg_color, int flags,
+                   int x, int y, unsigned char c)
+{
+  m_curX = x;
+  m_curY = y;
+  m_curFG = fg_color;
+  m_curBG = bg_color,
+  m_curFlags = flags;
+  m_curChar = c;
+
+
+
+  if(m_timer.IsRunning())
+    m_timer.Stop();
+  DoDrawCursor(fg_color, bg_color, flags, x, y, c);
+  if(m_curBlinkRate)
+  {
+    m_timer.Start(m_curBlinkRate);
+    m_curState = 1;
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private OnTimer
+///  Blinks the cursor each time it goes off
+///
+///  @param  event wxTimerEvent & The generated timer event
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::OnTimer(wxTimerEvent& WXUNUSED(event))
+{
+  wxClientDC
+    *dc = 0;
+
+  if(m_init)
+    return;
+
+  if(m_curX == -1 || m_curY == -1)
+    return;
+
+  if(GetMode() & CURSORINVISIBLE)
+  {
+	  //wxLogDebug("Skipping cursor");
+    return;
+  }
+  //wxLogDebug("Drawing cursor");
+  if(!m_curDC)
+  {
+    dc = new wxClientDC(this);
+    m_curDC = dc;
+  }
+
+  if(m_curBlinkRate)
+  {
+    m_curState++;
+    if(m_curState & 1 && m_curX != -1 && m_curY != -1)
+      DoDrawCursor(m_curFG, m_curBG, m_curFlags, m_curX, m_curY, m_curChar);
+    else
+      DoDrawCursor(m_curBG, m_curFG, m_curFlags, m_curX, m_curY, m_curChar);
+  }
+
+  if(dc)
+  {
+    delete dc;
+    m_curDC = 0;
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public virtual MoveChars
+///  Moves characters on the screen.  This virtual function is called from
+///  GTerm::update_changes.
+///
+///  @param  sx   int  The starting x position, in character cells
+///  @param  sy   int  The starting y position, in character cells
+///  @param  dx   int  The number of character cells to shift in the x direction
+///  @param  dy   int  The number of character cells to shift in the y direction
+///  @param  w    int  The width in characters of the area to be moved
+///  @param  h    int  The height in characters of the area to be moved
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::MoveChars(int sx, int sy, int dx, int dy, int w, int h)
+{
+  if(!m_marking)
+    ClearSelection();
+
+  sx = sx * m_charWidth;
+  sy = sy * m_charHeight;
+  dx = dx * m_charWidth;
+  dy = dy * m_charHeight;
+  w = w * m_charWidth;
+  h = h * m_charHeight;
+
+  m_memDC.Blit(0, 0, w, h, m_curDC, sx, sy);
+  m_curDC->Blit(dx, dy, w, h, &m_memDC, 0, 0);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public virtual ClearChars
+///  Clears a section of characters from the screen.  This virtual function
+///  is called from GTerm::update_changes.
+///
+///  @param  bg_color int  The background color to replace the characters with
+///  @param  x        int  The starting x position, in characters
+///  @param  y        int  The starting y position, in characters
+///  @param  w        int  The width of the area to be cleared, in characters
+///  @param  h        int  The height of the area to be cleared, in characters
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::ClearChars(int bg_color, int x, int y, int w, int h)
+{
+  if(!m_marking)
+    ClearSelection();
+
+  x = x * m_charWidth;
+  y = y * m_charHeight;
+  w = w * m_charWidth;
+  h = h * m_charHeight;
+
+  bool deleteDC = false;
+  if(!m_curDC)
+  {
+	  m_curDC = new wxClientDC(this);
+	  deleteDC = true;
+  }
+  m_curDC->SetPen(m_colorPens[bg_color]);
+  m_curDC->SetBrush(wxBrush(m_colors[bg_color], wxSOLID));
+  m_curDC->DrawRectangle(x, y, w /* + 1*/, h /*+ 1*/);
+
+  if(deleteDC)
+  {
+	  delete m_curDC;
+	  m_curDC = 0;
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public virtual ModeChange
+///  Changes the drawing mode between VT100 and PC
+///
+///  @param  state int  The new state
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::ModeChange(int state)
+{
+  ClearSelection();
+
+  if(state & GTerm::PC)
+  {
+    m_colors = m_pc_colors;
+    m_colorPens = m_pc_colorPens;
+  }
+  else
+  {
+    m_colors = m_vt_colors;
+    m_colorPens = m_vt_colorPens;
+  }
+  GTerm/*lnet*/::ModeChange(state);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public virtual Bell
+///  Rings the system bell
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::Bell()
+{
+  wxBell();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public UpdateSize
+///  Updates the terminal's size in characters after it has been resized on the screen.
+///
+///  @return void
+///
+///  @author Mark Erikson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void wxTerm::UpdateSize()
+{
+	// prevent any nasty recursion
+	if(m_inUpdateSize)
+	{
+		return;
+	}
+
+	m_inUpdateSize = true;
+	int charWidth, charHeight;
+
+	wxClientDC* dc = new wxClientDC(this);
+
+	if(!m_curDC)
+	{
+		m_curDC = dc;
+	}
+
+	dc->SetFont(m_normalFont);
+	dc->GetTextExtent("M", &charWidth, &charHeight);
+	wxSize currentClientSize = GetClientSize();
+	int numCharsInLine = currentClientSize.GetX() / charWidth;
+	int numLinesShown = currentClientSize.GetY() / charHeight;
+
+
+
+	if( (numCharsInLine != m_charsInLine) || (numLinesShown != m_linesDisplayed))
+	{
+		wxString message;
+
+		// FINALLY!  Finally killed the memory leak!  The problem is that somehow a size event
+		// was generating negative numbers for these values, which led to weird things happening.
+		if( (numCharsInLine > 0) && (numLinesShown > 0))
+		{
+			m_charsInLine = numCharsInLine;
+			m_linesDisplayed = numLinesShown;
+			// tell the GTerm core to resize itself
+			ResizeTerminal(numCharsInLine, numLinesShown);
+
+			UpdateRemoteSize(m_charsInLine, m_linesDisplayed);
+			/*
+			wxString remoteResizeCommand = wxString::Format("stty rows %d cols %d", m_linesDisplayed, m_charsInLine);
+			wxLogDebug("Resizing terminal: %s", remoteResizeCommand);
+			wxStringBuffer tempBuffer(remoteResizeCommand, 256);
+			SendBack(tempBuffer);
+			*/
+		}
+	}
+
+	m_inUpdateSize = false;
+
+	if(dc)
+	{
+		delete dc;
+		m_curDC = 0;
+	}
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public virtual ResizeTerminal
+///  <Resizes the terminal to a given number of characters high and wide
+///
+///  @param  width    int  The new number of characters wide
+///  @param  height    int  The new number of characters high
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::ResizeTerminal(int width, int height)
+{
+  int
+    w,
+    h;
+
+  ClearSelection();
+
+  /*
+  **  Determine window size from current font
+  */
+  wxClientDC
+    dc(this);
+
+  if(m_boldStyle != FONT)
+    dc.SetFont(m_normalFont);
+  else
+    dc.SetFont(m_boldFont);
+  dc.GetTextExtent("M", &m_charWidth, &m_charHeight);
+  w = width * m_charWidth;
+  h = height * m_charHeight;
+
+  /*
+  **  Create our bitmap for copying
+  */
+  if(m_bitmap)
+  {
+    m_memDC.SelectObject(wxNullBitmap);
+    delete m_bitmap;
+  }
+  m_bitmap = new wxBitmap(w, h);
+  m_memDC.SelectObject(*m_bitmap);
+
+  /*
+  **  Set window size
+  */
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+  SetSize(w, h + 4);
+#else
+  SetSize(w, h);
+#endif
+
+  /*
+  **  Set terminal size
+  */
+  GTerm::ResizeTerminal(width, height);
+  m_width = width;
+  m_height = height;
+
+  /*
+  **  Send event
+  */
+  if(!m_init)
+  {
+    wxCommandEvent e(wxEVT_COMMAND_TERM_RESIZE, GetId());
+    e.SetEventObject(this);
+    GetParent()->GetEventHandler()->ProcessEvent(e);
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public virtual RequestSizeChange
+///  A virtual function, used by GTerm to update the size
+///
+///  @param  w    int  The new width in characters
+///  @param  h    int  The new height in characters
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::RequestSizeChange(int w, int h)
+{
+  ResizeTerminal(w, h);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public virtual ProcessInput
+///  Processes text received from the server
+///
+///  @param  len  int             The number of characters received
+///  @param  data unsigned char * The received text
+///
+///  @return void
+///
+///  @remarks This function is *not* safe to call from anywhere but
+///  @remarks the main wxwidgets event loop, as it draws
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::ProcessInput(int len, unsigned char *data)
+{
+  wxClientDC
+    dc(this);
+
+  ClearSelection();
+  m_curDC = &dc;
+  GTerm::ProcessInput(len, data);
+  m_curDC = 0;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private MapKeyCode
+///  Converts from WXWidgets special keycodes to VT100
+///  special keycodes.
+///
+///
+///  @param  keyCode int  The keycode to check
+///
+///  @return int     The returned keycode
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+int
+wxTerm::MapKeyCode(int keyCode)
+{
+  int
+    i;
+
+  for(i = 0; keyMapTable[i].keyCode; i++)
+    if(keyMapTable[i].keyCode == keyCode)
+      return keyMapTable[i].VTKeyCode;
+  return 0;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public virtual SelectPrinter
+///  Selects the printer to be used
+///
+///  @param  PrinterName char * The text of the printer name
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::SelectPrinter(char *PrinterName)
+{
+  if(m_printerFN)
+  {
+    if(m_printerName[0] == '#')
+      fclose(m_printerFN);
+    else
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+      pclose(m_printerFN);
+#endif
+#if defined(__WXMSW__)
+      fclose(m_printerFN);
+#endif
+
+    m_printerFN = 0;
+  }
+
+  if(m_printerName)
+  {
+    free(m_printerName);
+    m_printerName = 0;
+  }
+
+  if(strlen(PrinterName))
+  {
+    m_printerName = strdup(PrinterName);
+  }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  public virtual PrintChars
+///  Prints stuff to the currently selected printer
+///
+///  @param  len  int             The number of characters
+///  @param  data unsigned char * The text
+///
+///  @return void
+///
+///  @author Derry Bryson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void
+wxTerm::PrintChars(int len, unsigned char *data)
+{
+  char
+    pname[100];
+
+  if(!m_printerFN)
+  {
+    if(!m_printerName)
+      return;
+
+    if(m_printerName[0] == '#')
+    {
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+      sprintf(pname, "/dev/lp%d", m_printerName[1] - '0');
+#endif
+#if defined(__WXMSW__)
+      sprintf(pname, "lpt%d", m_printerName[1] - '0' + 1);
+#endif
+      m_printerFN = fopen(pname, "wb");
+    }
+    else
+    {
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+      sprintf(pname, "lpr -P%s", m_printerName);
+      m_printerFN = popen(pname, "w");
+#endif
+#if defined(__WXMSW__)
+      m_printerFN = fopen(m_printerName, "wb");
+#endif
+    }
+  }
+
+  if(m_printerFN)
+  {
+    fwrite(data, len, 1, m_printerFN);
+  }
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+///  private OnGainFocus
+///  Enables the cursor
+///
+///  @param  event wxFocusEvent & The generated focus event
+///
+///  @return void
+///
+///  @author Mark Erikson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void wxTerm::OnGainFocus(wxFocusEvent &event)
+{
+	this->clear_mode_flag(CURSORINVISIBLE);
+	//wxLogDebug("TerminalWx Gained focus");
+	GTerm::Update();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private OnLoseFocus
+///  Disables the cursor
+///
+///  @param  event wxFocusEvent & The generated focus event
+///
+///  @return void
+///
+///  @author Mark Erikson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void wxTerm::OnLoseFocus(wxFocusEvent &event)
+{
+	this->set_mode_flag(CURSORINVISIBLE);
+	//wxLogDebug("TerminalWx Lost focus");
+	GTerm::Update();
+}
+
+//////////////////////////////////////////////////////////////////////////////
+///  private OnSize
+///  Lets the terminal resize the text whenever the window is resized
+///
+///  @param  event wxSizeEvent & The generated size event
+///
+///  @return void
+///
+///  @author Mark Erikson @date 04-22-2004
+//////////////////////////////////////////////////////////////////////////////
+void wxTerm::OnSize(wxSizeEvent &event)
+{
+	UpdateSize();
+}
+
+void wxTerm::UpdateRemoteSize(int width, int height)
+{
+
+}

+ 206 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/taTelnet/wxterm.h

@@ -0,0 +1,206 @@
+/*
+    taTelnet - A cross-platform telnet program.
+    Copyright (c) 2000 Derry Bryson
+                  2004 Mark Erikson
+                  2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+
+#ifndef INCLUDE_WXTERM
+#define INCLUDE_WXTERM
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "../GTerm/gterm.hpp"
+#include <wx/dcmemory.h>
+#include <wx/timer.h>
+#include <wx/colour.h>
+#include <wx/event.h>
+#include <wx/font.h>
+#include <wx/gdicmn.h>
+#include <wx/string.h>
+#include <wx/window.h>
+
+#define wxEVT_COMMAND_TERM_RESIZE        wxEVT_USER_FIRST + 1000
+#define wxEVT_COMMAND_TERM_NEXT          wxEVT_USER_FIRST + 1001
+
+#define EVT_TERM_RESIZE(id, fn) { wxEVT_COMMAND_TERM_RESIZE, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &fn, (wxObject *)NULL },
+
+class wxTerm : public wxWindow, public GTerm
+{
+  int
+    m_charWidth,
+    m_charHeight,
+    m_init,
+    m_width,
+    m_height,
+    m_selx1,
+    m_sely1,
+    m_selx2,
+    m_sely2,
+    m_curX,
+    m_curY,
+    m_curFG,
+    m_curBG,
+    m_curFlags,
+    m_curState,
+    m_curBlinkRate;
+
+      int m_charsInLine;
+  int m_linesDisplayed;
+
+  unsigned char
+    m_curChar;
+
+  bool
+    m_selecting,
+    m_marking;
+
+  bool m_inUpdateSize;
+
+  wxColour
+    m_vt_colors[16],
+    m_pc_colors[16],
+    *m_colors;
+
+  wxPen
+    m_vt_colorPens[16],
+    m_pc_colorPens[16],
+    *m_colorPens;
+
+  wxFont
+    m_normalFont,
+    m_underlinedFont,
+    m_boldFont,
+    m_boldUnderlinedFont;
+
+  wxDC
+    *m_curDC;
+
+  wxMemoryDC
+    m_memDC;
+
+  wxBitmap
+    *m_bitmap;
+
+  FILE
+    *m_printerFN;
+
+  char
+    *m_printerName;
+
+  wxTimer
+    m_timer;
+
+public:
+  enum BOLDSTYLE
+  {
+    DEFAULT = -1,
+    COLOR = 0,
+    OVERSTRIKE = 1,
+    FONT = 2
+  };
+
+private:
+  BOLDSTYLE
+    m_boldStyle;
+
+  typedef struct
+  {
+    wxKeyCode
+      keyCode;
+
+    int
+      VTKeyCode;
+  } TermKeyMap;
+
+  static TermKeyMap keyMapTable[];
+
+public:
+  wxTerm(wxWindow* parent, wxWindowID id,
+         const wxPoint& pos = wxDefaultPosition,
+         int width = 80, int height = 24,
+         const wxString& name = "wxTerm");
+
+  virtual ~wxTerm();
+
+  bool SetFont(const wxFont& font);
+
+  void GetDefVTColors(wxColor colors[16], wxTerm::BOLDSTYLE boldStyle = wxTerm::DEFAULT);
+  void GetVTColors(wxColour colors[16]);
+  void SetVTColors(wxColour colors[16]);
+  void GetDefPCColors(wxColour colors[16]);
+  void GetPCColors(wxColour colors[16]);
+  void SetPCColors(wxColour colors[16]);
+  int GetCursorBlinkRate() { return m_curBlinkRate; }
+  void SetCursorBlinkRate(int rate);
+
+  void SetBoldStyle(wxTerm::BOLDSTYLE boldStyle);
+  wxTerm::BOLDSTYLE GetBoldStyle(void) { return m_boldStyle; }
+
+  void ScrollTerminal(int numLines, bool scrollUp = true);
+
+  void ClearSelection();
+  bool HasSelection();
+  wxString GetSelection();
+  void SelectAll();
+
+  void UpdateSize();
+  //void UpdateSize(int &termheight, int &linesReceived);
+  //void UpdateSize(wxSizeEvent &event);
+
+  /*
+  **  GTerm stuff
+  */
+  virtual void DrawText(int fg_color, int bg_color, int flags,
+                        int x, int y, int len, unsigned char *string);
+  virtual void DrawCursor(int fg_color, int bg_color, int flags,
+                          int x, int y, unsigned char c);
+
+  virtual void MoveChars(int sx, int sy, int dx, int dy, int w, int h);
+  virtual void ClearChars(int bg_color, int x, int y, int w, int h);
+//  virtual void SendBack(int len, char *data);
+  virtual void ModeChange(int state);
+  virtual void Bell();
+  virtual void ResizeTerminal(int w, int h);
+  virtual void RequestSizeChange(int w, int h);
+
+  virtual void ProcessInput(int len, unsigned char *data);
+//  virtual void ProcessOutput(int len, unsigned char *data);
+
+  virtual void SelectPrinter(char *PrinterName);
+  virtual void PrintChars(int len, unsigned char *data);
+
+  virtual void UpdateRemoteSize(int width, int height);
+  int GetTermWidth(){return m_charsInLine;}
+  int GetTermHeight(){return m_linesDisplayed;}
+
+private:
+  int MapKeyCode(int keyCode);
+  void MarkSelection();
+  void DoDrawCursor(int fg_color, int bg_color, int flags,
+                    int x, int y, unsigned char c);
+
+  void OnChar(wxKeyEvent& event);
+  void OnKeyDown(wxKeyEvent& event);
+  void OnPaint(wxPaintEvent& event);
+  void OnLeftDown(wxMouseEvent& event);
+  void OnLeftUp(wxMouseEvent& event);
+  void OnMouseMove(wxMouseEvent& event);
+  void OnTimer(wxTimerEvent& event);
+  void OnSize(wxSizeEvent &event);
+
+  void OnGainFocus(wxFocusEvent &event);
+  void OnLoseFocus(wxFocusEvent &event);
+
+  //private wxScrollBar* m_scrollbar;
+
+  DECLARE_EVENT_TABLE()
+};
+
+#endif /* INCLUDE_WXTERM */

+ 25 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/terminalinputevent.cpp

@@ -0,0 +1,25 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 2004  Mark Erikson
+              2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+#include "terminalinputevent.h"
+
+
+DEFINE_EVENT_TYPE(chEVT_TERMINAL_INPUT)
+
+TerminalInputEvent::TerminalInputEvent(wxString str)
+	: wxEvent(0, chEVT_TERMINAL_INPUT),m_string(str)
+{
+	//
+}
+
+TerminalInputEvent::TerminalInputEvent(const TerminalInputEvent& otherEvent)
+: wxEvent(otherEvent)
+{
+	this->SetString(otherEvent.GetString());
+}

+ 48 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/terminalinputevent.h

@@ -0,0 +1,48 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 2004  Mark Erikson
+              2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+#ifndef __TERMINAL_INPUT_EVENT__H__
+#define __TERMINAL_INPUT_EVENT__H__
+
+#include <wx/process.h>
+#include <wx/event.h>
+
+// -------------------------------------------------------------------
+// ProcessEvent
+// -------------------------------------------------------------------
+DECLARE_EVENT_TYPE(chEVT_TERMINAL_INPUT, wxID_ANY)
+
+
+class TerminalInputEvent : public wxEvent
+{
+	public:
+		TerminalInputEvent(wxString str);
+		TerminalInputEvent(const TerminalInputEvent& event);
+
+		void SetString(wxString s) { m_string = s; }
+
+		wxString GetString() const { return m_string; }
+
+		virtual wxEvent *Clone() const { return new TerminalInputEvent(*this); }
+
+	private:
+		wxString m_string;
+
+};
+
+typedef void (wxEvtHandler::*TerminalInputEventFunction)(TerminalInputEvent&);
+
+
+#define EVT_TERMINAL_INPUT(fn) \
+	DECLARE_EVENT_TABLE_ENTRY( \
+			chEVT_TERMINAL_INPUT, wxID_ANY, wxID_ANY, \
+			(wxObjectEventFunction)(wxEventFunction)(TerminalInputEventFunction)&fn, \
+			(wxObject *) NULL),
+
+
+#endif // __TERMINAL_INPUT_EVENT__H__

+ 79 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/terminalwx.cpp

@@ -0,0 +1,79 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+#include "terminalwx.h"
+
+#include <wx/log.h>
+/**
+    Constructor for the terminal widget.
+
+    @param width The width of the terminal in characters
+    @param height The height of the terminal in character
+
+    @param name
+        The terminal name, which is not displayed but stored
+        internally, and might be changed by VT commands.
+
+*/
+TerminalWx::TerminalWx(wxWindow* parent, wxWindowID id,
+                               const wxPoint& pos,
+                               int width, int height,
+                               const wxString& name):  wxTerm(parent,id,pos,width,height,name)
+{
+    //ctor
+}
+/**
+    Called whenever the user has input additional text.
+        By default it does nothing.
+*/
+void TerminalWx::OnUserInput(wxString input) {
+    wxLogDebug("GotInput! %s",input);
+    //By default do nothing.
+}
+
+void TerminalWx::SendBack(int len,char* data) {
+    OnUserInput(wxString(data,len));
+}
+void TerminalWx::SendBack(char* data) {
+    OnUserInput(wxString(data));
+}
+/**
+ *  Processes characters sent from the backend.
+ *
+ *  This function is thread safe and can be called from any thread at any time.
+ *
+*/
+void TerminalWx::DisplayChars(const wxString& str) {
+     this->QueueEvent(new TerminalInputEvent(str));
+}
+
+/**
+ *  Processes characters sent from the backend
+ *
+ *  This function is not thread safe and can *only*
+ *  safely be called from the main event loop
+*/
+void TerminalWx::DisplayCharsUnsafe(const wxString& str) {
+     ProcessInput(str.length(),(unsigned char*)const_cast<char*>((const char*)str.mb_str()));
+}
+
+void TerminalWx::OnTerminalInput(TerminalInputEvent& evt) {
+    DisplayCharsUnsafe(evt.GetString());
+}
+
+TerminalWx::~TerminalWx()
+{
+    //dtor
+}
+
+
+wxBEGIN_EVENT_TABLE(TerminalWx, wxTerm)
+
+EVT_TERMINAL_INPUT(TerminalWx::OnTerminalInput)
+
+wxEND_EVENT_TABLE()

+ 62 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/src/terminalwx.h

@@ -0,0 +1,62 @@
+/*
+TerminalWx - A wxWidgets terminal widget
+Copyright (C) 2012-2013 Jeremy Salwen
+
+License: wxWindows License Version 3.1 (See the file license3.txt)
+
+*/
+
+#ifndef TERMINALWX_H
+#define TERMINALWX_H
+
+#include "taTelnet/wxterm.h"
+#include "terminalinputevent.h"
+
+/*! \mainpage TerminalWx
+ *
+ * \section intro_sec Introduction
+ *
+ * TerminalWx is a fully VT100 compatible virtual terminal widget for wxWindows
+ *
+ * The code is almost entirely from the Chameleon IDE by Mark Erikson,
+ *  taTelnet by Derry Bryson, and GTerm by Timothy Miller.
+ *
+ * \section install_sec Use
+ *
+ * The public API for TerminalWx is the class TerminalWx.
+ *  It is a wxWindow.  Simply add it to your gui as you would any other widget.
+ *
+ *
+ */
+
+
+/**
+ *  Terminal Widget
+ *
+ *  To handle user input to the terminal, inherit this
+ *  class and override the OnUserInput
+ *
+ *  To make the widget display new characters sent from your backend,
+ *  use DisplayChars (or you may use DisplayCharsUnsafe, if you are
+ *  calling from within the main event loop.
+ */
+class TerminalWx : public wxTerm
+{
+public:
+    TerminalWx(wxWindow* parent, wxWindowID id,
+                   const wxPoint& pos = wxDefaultPosition,
+                   int width = 80, int height = 24,
+                   const wxString& name = "TerminalWx");
+    virtual ~TerminalWx();
+    virtual void OnUserInput(wxString);
+    virtual void DisplayChars(const wxString& text);
+    virtual void DisplayCharsUnsafe(const wxString& text);
+protected:
+private:
+  void OnTerminalInput(TerminalInputEvent&);
+  virtual void SendBack(int len, char* data);
+  virtual void SendBack(char* data);
+  DECLARE_EVENT_TABLE()
+};
+
+#endif // TERMINALWX_H

+ 37 - 0
lib/SCSI2SD/src/scsi2sd-util6/TerminalWx/wxsmith/Testframe.wxs

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<wxsmith>
+	<object class="wxFrame" name="TerminalWxFrame">
+		<title>Test TerminalWx App</title>
+		<handler function="OnClose" entry="EVT_CLOSE" />
+		<object class="Custom" name="ID_TERM" subclass="TerminalWx" variable="Term1" member="yes">
+			<creating_code>$(THIS) = new $(CLASS)($(PARENT),$(ID),$(POS),80,24,$(NAME));</creating_code>
+			<style></style>
+			<pos>72,56</pos>
+		</object>
+		<object class="wxMenuBar" variable="MenuBar1" member="no">
+			<object class="wxMenu" variable="Menu1" member="no">
+				<label>&amp;File</label>
+				<object class="wxMenuItem" name="idMenuQuit" variable="MenuItem1" member="no">
+					<label>Quit</label>
+					<accel>Alt-F4</accel>
+					<help>Quit the application</help>
+					<handler function="OnQuit" entry="EVT_MENU" />
+				</object>
+			</object>
+			<object class="wxMenu" variable="Menu2" member="no">
+				<label>Help</label>
+				<object class="wxMenuItem" name="idMenuAbout" variable="MenuItem2" member="no">
+					<label>About</label>
+					<accel>F1</accel>
+					<help>Show info about this application</help>
+					<handler function="OnAbout" entry="EVT_MENU" />
+				</object>
+			</object>
+		</object>
+		<object class="wxStatusBar" name="ID_STATUSBAR1" variable="StatusBar1" member="yes">
+			<fields>1</fields>
+			<widths>-1</widths>
+			<styles>wxSB_NORMAL</styles>
+		</object>
+	</object>
+</wxsmith>

+ 24 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/.gitignore

@@ -0,0 +1,24 @@
+Makefile
+*/Makefile
+autom4te.cache/
+config.h
+configure
+m4/
+src/.deps/
+src/dfu-suffix
+src/dfu-prefix
+src/dfu-util
+src/dfu-version.h
+stamp-h1
+Win32/
+msvc/ipch/
+*.log
+*.status
+*.m4
+*.o
+*.in
+*.suo
+*.user
+*.opensdf
+*.sdf
+*~

+ 34 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/AUTHORS

@@ -0,0 +1,34 @@
+Authors ordered by first contribution.
+
+Harald Welte
+Werner Almesberger
+Michael Lauer
+Jim Huang
+Stefan Schmidt
+Daniel Willmann
+Mike Frysinger
+Uwe Hermann
+C. Scott Ananian
+Bernard Blackham
+Holger Freyther
+Marc Singer
+James Perkins
+Tommi Keisala
+Pascal Schweizer
+Bradley Scott
+Uwe Bonnes
+Andrey Smirnov
+Jussi Timperi
+Hans Petter Selasky
+Bo Shen
+Henrique de Almeida Mendonca
+Bernd Krumboeck
+Dennis Meier
+Veli-Pekka Peltola
+Dave Hylands
+Michael Grzeschik
+Paul Fertser
+Dirk Castelijns
+Gordon McNab
+Stefan Zehl
+Timo Poikola

+ 340 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/COPYING

@@ -0,0 +1,340 @@
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year  name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.

+ 103 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/ChangeLog

@@ -0,0 +1,103 @@
+0.9:
+	o Reimplemented USBPATH support (Stefan Zehl)
+	o Better parsing of numeric arguments (Timo Poikola)
+	o Avoid conflict with HID devices (Gordon McNab)
+	o Mass erase timeout workaround for STM32F405 (Tormod Volden)
+	o Workaround for LPC DFU bootloader (Dirk Castelijns)
+	o Include example udev rules file (Tormod Volden)
+
+2016-02-08: Tormod Volden <debian.tormod@gmail.com>
+
+0.8:
+	o New, separate dfu-prefix tool (Uwe Bonnes)
+	o Allow filtering on serial number (Uwe Bonnes)
+	o Improved VID/PID/serial filtering (Bradley Scott)
+	o Support reading firmware from stdin (Tormod Volden)
+	o Warn if missing DFU suffix (Tormod Volden)
+	o Improved progress bar (Hans Petter Selasky)
+	o Fix dfuse leave option (Uwe Bonnes)
+	o Major code rework (Hans Petter Selasky)
+	o MS Visual Studio build support (Henrique Mendonca)
+	o dfuse-pack.py tool for .dfu files (Antonio Galeo)
+	o Many other fixes from many people
+
+2014-09-13: Tormod Volden <debian.tormod@gmail.com>	
+
+0.7:
+	o Support for TI Stellaris devices (Tommi Keisala)
+	o Fix libusb detection on MacOSX (Marc Singer)
+	o Fix libusb detection on FreeBSD (Tormod Volden)
+	o Improved DfuSe support (Tormod Volden)
+	  o Support all special commands (leave, unprotect, mass-erase)
+	  o Arbitrary upload lengths
+	  o "force" option for various possible (dangerous) overrides
+
+2012-10-07: Tormod Volden <debian.tormod@gmail.com>	
+
+0.6:
+	o Add detach mode (Stefan Schmidt)
+	o Check return value on all libusb calls (Tormod Volden)
+	o Fix segmentation fault with -s option (Tormod Volden)
+	o Add DFU suffix manipulation tool (Stefan Schmidt)
+	o Port to Windows: (Tormod Volden, some parts based on work from Satz
+	  Klauer)
+	  o Port file handling to stdio streams
+	  o Sleep() macros
+	  o C99 types
+	  o Pack structs
+	o Detect DfuSe device correctly on big-endian architectures (Tormod
+	  Volden)
+	o Add dfuse progress indication on download (Tormod Volden)
+	o Cleanup: gcc pedantic, gcc extension, ... (Tormod Volden)
+	o Rely on page size from functional descriptor. Please report if you get
+	  an error about it.  (Tormod Volden)
+	o Add quirk for Maple since it reports wrong DFU version (Tormod Volden)
+
+2012-04-22: Stefan Schmidt <stefan@datenfreihafen.org>
+
+0.5:
+	o DfuSe extension support for ST devices (Tormod Volden)
+	o Add initial support for bitWillDetach flag from DFU 1.1 (Tormod
+	  Volden)
+	o Internal cleanup and some manual page fixes (Tormod Volden)
+
+2011-11-02: Stefan Schmidt <stefan@datenfreihafen.org>
+
+0.4:
+	o Rework to use libusb-1.0 (Stefan Schmidt)
+	o DFU suffix support (Tormod Volden, Stefan Schmidt)
+	o Sspeed up DFU downloads directly into memory (Bernard Blackham)
+	o More flexible -d vid:pid parsing (Tormod Volden)
+	o Many bug fixes and cleanups
+
+2011-07-20: Stefan Schmidt <stefan@datenfreihafen.org>
+
+0.3:
+	o quirks: Add OpenOCD to the poll timeout quirk table.
+
+2010-12-22: Stefan Schmidt <stefan@datenfreihafen.org>
+
+0.2:
+	o Fix some typos on the website and the README (Antonio Ospite, Uwe
+	  Hermann)
+	o Remove build rule for a static binary. We can use autotools for this.
+	  (Mike Frysinger)
+	o Fix infinite loop in download error path (C. Scott Ananian)
+	o Break out to show the 'finished' in upload (C. Scott Ananian)
+	o Add GPLv2+ headers (Harald Welte)
+	o Remove dead code (commands.[ch]) remnescent of dfu-programmer (Harald
+	  Welte)
+	o Simple quirk system with Openmoko quirk for missing bwPollTimeout (Tormod Volden)
+	o New default (1024) and clamping of transfer size (Tormod Volden)
+	o Verify sending of completion packet (Tormod Volden)
+	o Look for DFU functional descriptor among all descriptors (Tormod
+	  Volden)
+	o Print out in which direction we are transferring data
+	o Abort in upload if the file already exists
+
+2010-11-17 Stefan Schmidt <stefan@datenfreihafen.org>
+
+0.1:
+	Initial release
+
+2010-05-23 Stefan Schmidt <stefan@datenfreihafen.org>

+ 20 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/DEVICES.txt

@@ -0,0 +1,20 @@
+List of supported software and hardware products:
+
+Software user (bootloader, etc)
+-------------------------------
+- Sam7DFU: http://www.openpcd.org/Sam7dfu
+- U-boot: DFU patches
+- Barebox: http://www.barebox.org/
+- Leaflabs: http://code.google.com/p/leaflabs/
+- Blackmagic DFU
+
+Products using DFU
+------------------
+- OpenPCD (sam7dfu)
+- Openmoko Neo 1973 and Freerunner (u-boot with DFU patches)
+- Leaflabs Maple
+- ATUSB from Qi Hardware
+- STM32F105/7, STM32F2/F3/F4 in System Bootloader
+- Blackmagic debug probe
+- NXP LPC31xx/LPC43XX, e.g. LPC-Link and LPC-Link2, need binaries
+  with LPC prefix and encoding (LPC-Link)

+ 19 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/INSTALL

@@ -0,0 +1,19 @@
+
+1. If building from git (not needed for release tarballs):
+   Generate build system files (requires autoconf from autotools)
+
+	./autogen.sh
+
+2. Generate makefiles
+   (Run ./configure --help to see configuration options)
+
+	./configure
+
+3. Build executables
+
+	make
+
+4. Install executables and manual pages (optional)
+
+	make install
+

+ 3 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/Makefile.am

@@ -0,0 +1,3 @@
+SUBDIRS = src doc
+
+EXTRA_DIST = autogen.sh TODO DEVICES.txt dfuse-pack.py

+ 21 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/README

@@ -0,0 +1,21 @@
+Dfu-util - Device Firmware Upgrade Utilities
+
+Dfu-util is the host side implementation of the DFU 1.0 [1] and DFU 1.1 [2]
+specification of the USB forum.
+
+DFU is intended to download and upload firmware to devices connected over
+USB. It ranges from small devices like micro-controller boards up to mobile
+phones. With dfu-util you are able to download firmware to your device or
+upload firmware from it.
+
+dfu-util has been tested with Openmoko Neo1973 and Freerunner and many
+other devices.
+
+[1] DFU 1.0 spec: http://www.usb.org/developers/devclass_docs/usbdfu10.pdf
+[2] DFU 1.1 spec: http://www.usb.org/developers/devclass_docs/DFU_1.1.pdf
+
+The official website is:
+
+  http://dfu-util.sourceforge.net
+
+See the INSTALL file for build instructions.

+ 13 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/TODO

@@ -0,0 +1,13 @@
+DfuSe:
+- Skip "Set Address" command when downloading contiguous blocks
+- Implement "Get Commands" command
+
+Devices:
+- Research iPhone/iPod/iPad support
+  Heavily modified dfu-util fork here:
+  https://github.com/planetbeing/xpwn/tree/master/dfu-util
+- Test against Niftylights
+
+Non-Code:
+- Logo
+- Re-License as LGPL for usage as library?

+ 2 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/autogen.sh

@@ -0,0 +1,2 @@
+#! /bin/sh
+autoreconf -v -i

+ 40 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/configure.ac

@@ -0,0 +1,40 @@
+#                                               -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ(2.59)
+AC_INIT([dfu-util],[0.9],[http://sourceforge.net/p/dfu-util/tickets/],,[http://dfu-util.sourceforge.net])
+AC_CONFIG_AUX_DIR(m4)
+AM_INIT_AUTOMAKE([foreign])
+AC_CONFIG_HEADERS([config.h])
+
+# Test for new silent rules and enable only if they are available
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+
+# Checks for programs.
+AC_PROG_CC
+
+# Checks for libraries.
+# On FreeBSD the libusb-1.0 is called libusb and resides in system location
+AC_CHECK_LIB([usb], [libusb_init],, [native_libusb=no],)
+AS_IF([test x$native_libusb = xno], [
+    PKG_CHECK_MODULES([USB], [libusb-1.0 >= 1.0.0],,
+        AC_MSG_ERROR([*** Required libusb-1.0 >= 1.0.0 not installed ***]))
+])
+
+LIBS="$LIBS $USB_LIBS"
+CFLAGS="$CFLAGS $USB_CFLAGS"
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([windows.h sysexits.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_TYPE_SIZE_T
+
+# Checks for library functions.
+AC_FUNC_MEMCMP
+AC_CHECK_FUNCS([getpagesize nanosleep err])
+
+AC_CONFIG_FILES(Makefile src/Makefile doc/Makefile)
+AC_OUTPUT

+ 77 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/README

@@ -0,0 +1,77 @@
+Device:
+-------
+qi-hardware-atusb:
+- Qi Hardware ben-wpan
+- DFU implementation:
+  http://projects.qi-hardware.com/index.php/p/ben-wpan/source/tree/master/atusb/fw/usb
+- Tester: Stefan Schmidt
+
+openpcd:
+- OpenPCD RFID reader
+- DFU implementation: SAM7DFU
+  http://www.openpcd.org/Sam7dfu, git://git.gnumonks.org/openpcd.git
+- Tester: Stefan Schmidt
+
+simtrace:
+- Sysmocom SimTrace
+- DFU implementation: SAM7DFU
+  http://www.openpcd.org/Sam7dfu, git://git.gnumonks.org/openpcd.git
+- Tester: Stefan Schmidt
+
+openmoko-freerunner:
+- Openmoko Freerunner
+- DFU implementation: Old U-Boot
+  http://git.openmoko.org/?p=u-boot.git;a=shortlog;h=refs/heads/mokopatches
+- Tester: Stefan Schmidt
+
+openmoko-neo1973:
+- Openmoko Neo1073
+- DFU implementation: Old U-Boot
+  http://git.openmoko.org/?p=u-boot.git;a=shortlog;h=refs/heads/mokopatches
+- Tester: Stefan Schmidt
+
+tdk-bluetooth:
+- TDK Corp. Bluetooth Adapter
+- DFU implementation: closed soure
+- Only upload has been tested
+- Tester: Stefan Schmidt
+
+stm32f107:
+- STM32 microcontrollers with built-in (ROM) DFU loader
+- DFU implementation: Closed source but probably similar to the one
+  in their USB device libraries. Some relevant application notes:
+  http://www.st.com -> AN3156 and AN2606
+- Tested by Uwe Bonnes
+
+stm32f4discovery:
+- STM32 microcontroller board with built-in (ROM) DFU loader
+- DFU implementation: Closed source, probably similar to stm32f107.
+- Tested by Joe Rothweiler
+
+dso-nano:
+- DSO Nano pocket oscilloscope
+- DFU implementation: Based on ST Microelectronics USB FS Library 1.0
+  http://dsonano.googlecode.com/files/DS0201_OpenSource.rar
+- Tester: Tormod Volden
+
+opc-20:
+- Custom devices based on STM32F1xx
+- DFU implementation: ST Microelectronics USB FS Device Library 3.1.0
+  http://www.st.com -> um0424.zip
+- Tester: Tormod Volden
+
+lpc-link, lpclink2:
+- NXP LPCXpresso debug adapters
+- Proprietary DFU implementation, uses special download files with
+  LPC prefix and encoding of the target firmware code
+- Tested by Uwe Bonnes
+
+Adding the lsusb output and a download log of your device here helps
+us to avoid regressions for hardware we cannot test while working on
+the code. To extract the lsusb output use this command:
+sudo lsusb -v -d $USBID > $DEVICE.lsusb
+Prepare a description snippet as above, and send it to us. A log
+(copy-paste of the command window) of a firmware download is also
+nice, please use the double verbose option -v -v and include the
+command line in the log file.
+ 

+ 60 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/dsonano.lsusb

@@ -0,0 +1,60 @@
+
+Bus 002 Device 004: ID 0483:df11 SGS Thomson Microelectronics 
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  idVendor           0x0483 SGS Thomson Microelectronics
+  idProduct          0xdf11 
+  bcdDevice            1.1a
+  iManufacturer           1 STMicroelectronics
+  iProduct                2 STM32 DFU
+  iSerial                 3 001
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           36
+    bNumInterfaces          1
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower               64mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      0 
+      iInterface              4 @Internal Flash  /0x08000000/12*001Ka,116*001Kg
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       1
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      0 
+      iInterface              5 @SPI Flash : M25P64/0x00000000/64*064Kg,64*064Kg
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             9
+        bDescriptorType                    33
+        bmAttributes                       11
+          Will Detach
+          Manifestation Intolerant
+          Upload Supported
+          Download Supported
+        wDetachTimeout                    255 milliseconds
+        wTransferSize                    1024 bytes
+        bcdDFUVersion                   1.1a
+Device Status:     0x0000
+  (Bus Powered)

+ 58 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/lpclink.lsusb

@@ -0,0 +1,58 @@
+
+Bus 003 Device 008: ID 0471:df55 Philips (or NXP) LPCXpresso LPC-Link
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               2.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  idVendor           0x0471 Philips (or NXP)
+  idProduct          0xdf55 LPCXpresso LPC-Link
+  bcdDevice            0.01
+  iManufacturer           0 
+  iProduct                0 
+  iSerial                 0 
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           25
+    bNumInterfaces          1
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              100mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      0 
+      iInterface              0 
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             7
+        bDescriptorType                    33
+        bmAttributes                        1
+          Will Not Detach
+          Manifestation Intolerant
+          Upload Unsupported
+          Download Supported
+        wDetachTimeout                  65535 milliseconds
+        wTransferSize                    2048 bytes
+Device Qualifier (for other device speed):
+  bLength                10
+  bDescriptorType         6
+  bcdUSB               2.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  bNumConfigurations      1
+Device Status:     0x0000
+  (Bus Powered)

+ 203 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/lpclink2.lsusb

@@ -0,0 +1,203 @@
+
+Bus 003 Device 007: ID 0c72:000c PEAK System PCAN-USB
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        16
+  idVendor           0x0c72 PEAK System
+  idProduct          0x000c PCAN-USB
+  bcdDevice           1c.ff
+  iManufacturer           0 
+  iProduct                3 VER1:PEAK    
+VER2:02.8.01        
+DAT :06.05.2004
+TIME:09:35:37
+                             ...
+  iSerial                 0 
+  bNumConfigurations      3
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           46
+    bNumInterfaces          1
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              200mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           4
+      bInterfaceClass         0 (Defined at Interface level)
+      bInterfaceSubClass      0 
+      bInterfaceProtocol      0 
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval              20
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x01  EP 1 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval              20
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x82  EP 2 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0040  1x 64 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x02  EP 2 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0040  1x 64 bytes
+        bInterval               1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           46
+    bNumInterfaces          1
+    bConfigurationValue     2
+    iConfiguration          0 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              394mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           4
+      bInterfaceClass         0 (Defined at Interface level)
+      bInterfaceSubClass      0 
+      bInterfaceProtocol      0 
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval              20
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x01  EP 1 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval              20
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x82  EP 2 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0040  1x 64 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x02  EP 2 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0040  1x 64 bytes
+        bInterval               1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           46
+    bNumInterfaces          1
+    bConfigurationValue     3
+    iConfiguration          0 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              200mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           4
+      bInterfaceClass         0 (Defined at Interface level)
+      bInterfaceSubClass      0 
+      bInterfaceProtocol      0 
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            3
+          Transfer Type            Interrupt
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x01  EP 1 OUT
+        bmAttributes            3
+          Transfer Type            Interrupt
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x82  EP 2 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0040  1x 64 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x02  EP 2 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0040  1x 64 bytes
+        bInterval               1
+Device Status:     0x0001
+  Self Powered

+ 60 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/opc-20.lsusb

@@ -0,0 +1,60 @@
+
+Bus 001 Device 004: ID 0483:df11 SGS Thomson Microelectronics 
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  idVendor           0x0483 SGS Thomson Microelectronics
+  idProduct          0xdf11 
+  bcdDevice            2.00
+  iManufacturer           1 STMicroelectronics
+  iProduct                2 STM32 DFU
+  iSerial                 3 ÿÿÿÿÿÿÿÿÿÿÿÿ
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           36
+    bNumInterfaces          1
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0xc0
+      Self Powered
+    MaxPower              100mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              4 @Internal Flash  /0x08000000/12*001Ka,116*001Kg
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       1
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              5 @SPI Flash : M25P64/0x00000000/128*64Kg
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             9
+        bDescriptorType                    33
+        bmAttributes                       11
+          Will Detach
+          Manifestation Intolerant
+          Upload Supported
+          Download Supported
+        wDetachTimeout                    255 milliseconds
+        wTransferSize                    1024 bytes
+        bcdDFUVersion                   1a.01
+Device Status:     0x0001
+  Self Powered

+ 109 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/openmoko-freerunner-dfumode.lsusb

@@ -0,0 +1,109 @@
+Bus 003 Device 017: ID 1d50:5119 OpenMoko, Inc. GTA01/GTA02 U-Boot Bootloader
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        16
+  idVendor           0x1d50 OpenMoko, Inc.
+  idProduct          0x5119 GTA01/GTA02 U-Boot Bootloader
+  bcdDevice            0.00
+  iManufacturer           1 OpenMoko, Inc
+  iProduct                2 Neo1973 Bootloader U-Boot 1.3.2-moko12
+  iSerial                 3 0000000
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           81
+    bNumInterfaces          1
+    bConfigurationValue     1
+    iConfiguration          7 USB Device Firmware Upgrade
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              100mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              8 RAM 0x32000000
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       1
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              9 u-boot
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       2
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface             10 u-boot_env
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       3
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface             11 kernel
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       4
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface             12 splash
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       5
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface             13 factory
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       6
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface             14 rootfs
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             9
+        bDescriptorType                    33
+        bmAttributes                        7
+          Will Not Detach
+          Manifestation Tolerant
+          Upload Supported
+          Download Supported
+        wDetachTimeout                  65280 milliseconds
+        wTransferSize                    4096 bytes
+        bcdDFUVersion                   1.00
+Device Status:     0x0a00
+  (Bus Powered)

+ 179 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/openmoko-freerunner.lsusb

@@ -0,0 +1,179 @@
+Bus 005 Device 033: ID 1d50:5119 OpenMoko, Inc. GTA01/GTA02 U-Boot Bootloader
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.10
+  bDeviceClass            2 Communications
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        16
+  idVendor           0x1d50 OpenMoko, Inc.
+  idProduct          0x5119 GTA01/GTA02 U-Boot Bootloader
+  bcdDevice            0.00
+  iManufacturer           1 OpenMoko, Inc
+  iProduct                2 Neo1973 Bootloader U-Boot 1.3.2-moko12
+  iSerial                 3 0000000
+  bNumConfigurations      2
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           85
+    bNumInterfaces          3
+    bConfigurationValue     1
+    iConfiguration          4 TTY via USB
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              500mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           1
+      bInterfaceClass         2 Communications
+      bInterfaceSubClass      2 Abstract (modem)
+      bInterfaceProtocol      1 AT-commands (v.25ter)
+      iInterface              6 Control Interface
+      CDC Header:
+        bcdCDC               0.6e
+      CDC Call Management:
+        bmCapabilities       0x00
+        bDataInterface          1
+      CDC ACM:
+        bmCapabilities       0x00
+      CDC Union:
+        bMasterInterface        0
+        bSlaveInterface         1 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            3
+          Transfer Type            Interrupt
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       0
+      bNumEndpoints           2
+      bInterfaceClass        10 CDC Data
+      bInterfaceSubClass      0 Unused
+      bInterfaceProtocol      0 
+      iInterface              5 Bulk Data Interface
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x02  EP 2 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x83  EP 3 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        2
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      1 
+      iInterface              7 USB Device Firmware Upgrade
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             9
+        bDescriptorType                    33
+        bmAttributes                        7
+          Will Not Detach
+          Manifestation Tolerant
+          Upload Supported
+          Download Supported
+        wDetachTimeout                  65280 milliseconds
+        wTransferSize                    4096 bytes
+        bcdDFUVersion                   1.00
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           67
+    bNumInterfaces          2
+    bConfigurationValue     2
+    iConfiguration          4 TTY via USB
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              100mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           1
+      bInterfaceClass         2 Communications
+      bInterfaceSubClass      2 Abstract (modem)
+      bInterfaceProtocol      1 AT-commands (v.25ter)
+      iInterface              6 Control Interface
+      CDC Header:
+        bcdCDC               0.6e
+      CDC Call Management:
+        bmCapabilities       0x00
+        bDataInterface          1
+      CDC ACM:
+        bmCapabilities       0x00
+      CDC Union:
+        bMasterInterface        0
+        bSlaveInterface         1 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            3
+          Transfer Type            Interrupt
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       0
+      bNumEndpoints           2
+      bInterfaceClass        10 CDC Data
+      bInterfaceSubClass      0 Unused
+      bInterfaceProtocol      0 
+      iInterface              5 Bulk Data Interface
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x02  EP 2 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x83  EP 3 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+Device Status:     0x9a00
+  (Bus Powered)

+ 182 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/openmoko-neo1973.lsusb

@@ -0,0 +1,182 @@
+
+Bus 006 Device 020: ID 1457:5119 First International Computer, Inc. OpenMoko Neo1973 u-boot cdc_acm serial port
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.10
+  bDeviceClass            2 Communications
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        16
+  idVendor           0x1457 First International Computer, Inc.
+  idProduct          0x5119 OpenMoko Neo1973 u-boot cdc_acm serial port
+  bcdDevice            0.00
+  iManufacturer           1 
+  iProduct                2 
+  iSerial                 3 
+  bNumConfigurations      2
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           85
+    bNumInterfaces          3
+    bConfigurationValue     1
+    iConfiguration          4 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              500mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           1
+      bInterfaceClass         2 Communications
+      bInterfaceSubClass      2 Abstract (modem)
+      bInterfaceProtocol      1 AT-commands (v.25ter)
+      iInterface              6 
+      CDC Header:
+        bcdCDC               0.6e
+      CDC Call Management:
+        bmCapabilities       0x00
+        bDataInterface          1
+      CDC ACM:
+        bmCapabilities       0x00
+      CDC Union:
+        bMasterInterface        0
+        bSlaveInterface         1 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            3
+          Transfer Type            Interrupt
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       0
+      bNumEndpoints           2
+      bInterfaceClass        10 CDC Data
+      bInterfaceSubClass      0 Unused
+      bInterfaceProtocol      0 
+      iInterface              5 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x02  EP 2 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x83  EP 3 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        2
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      1 
+      iInterface              7 
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             9
+        bDescriptorType                    33
+        bmAttributes                        7
+          Will Not Detach
+          Manifestation Tolerant
+          Upload Supported
+          Download Supported
+        wDetachTimeout                  65280 milliseconds
+        wTransferSize                    4096 bytes
+        bcdDFUVersion                   1.00
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           67
+    bNumInterfaces          2
+    bConfigurationValue     2
+    iConfiguration          4 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              100mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           1
+      bInterfaceClass         2 Communications
+      bInterfaceSubClass      2 Abstract (modem)
+      bInterfaceProtocol      1 AT-commands (v.25ter)
+      iInterface              6 
+      CDC Header:
+        bcdCDC               0.6e
+      CDC Call Management:
+        bmCapabilities       0x00
+        bDataInterface          1
+      CDC ACM:
+        bmCapabilities       0x00
+      CDC Union:
+        bMasterInterface        0
+        bSlaveInterface         1 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            3
+          Transfer Type            Interrupt
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       0
+      bNumEndpoints           2
+      bInterfaceClass        10 CDC Data
+      bInterfaceSubClass      0 Unused
+      bInterfaceProtocol      0 
+      iInterface              5 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x02  EP 2 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x83  EP 3 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval             255
+Device Status:     0x0006
+  (Bus Powered)
+  Remote Wakeup Enabled
+  Test Mode

+ 60 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/openpcd.lsusb

@@ -0,0 +1,60 @@
+
+Bus 006 Device 016: ID 16c0:076b VOTI OpenPCD 13.56MHz RFID Reader
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0         8
+  idVendor           0x16c0 VOTI
+  idProduct          0x076b OpenPCD 13.56MHz RFID Reader
+  bcdDevice            0.00
+  iManufacturer           1 
+  iProduct                2 OpenPCD RFID Simulator - DFU Mode
+  iSerial                 0 
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           36
+    bNumInterfaces          1
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              200mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              0 
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       1
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              0 
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             9
+        bDescriptorType                    33
+        bmAttributes                        3
+          Will Not Detach
+          Manifestation Intolerant
+          Upload Supported
+          Download Supported
+        wDetachTimeout                  65280 milliseconds
+        wTransferSize                     256 bytes
+        bcdDFUVersion                   1.00
+Device Status:     0x0000
+  (Bus Powered)

+ 59 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/qi-hardware-atusb.lsusb

@@ -0,0 +1,59 @@
+
+Bus 006 Device 013: ID 20b7:1540 Qi Hardware ben-wpan, AT86RF230-based
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               2.00
+  bDeviceClass          255 Vendor Specific Class
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  idVendor           0x20b7 Qi Hardware
+  idProduct          0x1540 ben-wpan, AT86RF230-based
+  bcdDevice            0.01
+  iManufacturer           0 
+  iProduct                0 
+  iSerial                 1 4630333438371508231a
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           34
+    bNumInterfaces          2
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower               40mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           1
+      bInterfaceClass       255 Vendor Specific Class
+      bInterfaceSubClass      0 
+      bInterfaceProtocol      0 
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0040  1x 64 bytes
+        bInterval               0
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      1 
+      iInterface              0 
+Device Status:     0x0000
+  (Bus Powered)

+ 70 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/simtrace.lsusb

@@ -0,0 +1,70 @@
+
+Bus 006 Device 017: ID 16c0:0762 VOTI 
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0         8
+  idVendor           0x16c0 VOTI
+  idProduct          0x0762 
+  bcdDevice            0.00
+  iManufacturer           1 sysmocom - systems for mobile communications GmbH
+  iProduct                2 SimTrace SIM Sniffer - DFU Mode
+  iSerial                 0 
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           45
+    bNumInterfaces          1
+    bConfigurationValue     1
+    iConfiguration          3 SimTrace DFU Configuration
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              200mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              4 SimTrace DFU Interface - Application Partition
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       1
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              5 SimTrace DFU Interface - Bootloader Partition
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       2
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              6 SimTrace DFU Interface - RAM
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             9
+        bDescriptorType                    33
+        bmAttributes                        3
+          Will Not Detach
+          Manifestation Intolerant
+          Upload Supported
+          Download Supported
+        wDetachTimeout                  65280 milliseconds
+        wTransferSize                     256 bytes
+        bcdDFUVersion                   1.00
+Device Status:     0x0000
+  (Bus Powered)

+ 60 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/sparkcore.lsusb

@@ -0,0 +1,60 @@
+
+Bus 001 Device 008: ID 1d50:607f OpenMoko, Inc. 
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  idVendor           0x1d50 OpenMoko, Inc.
+  idProduct          0x607f 
+  bcdDevice            2.00
+  iManufacturer           1 Spark Devices     
+  iProduct                2 CORE DFU 
+  iSerial                 3 8D80527B5055
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           36
+    bNumInterfaces          1
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0xc0
+      Self Powered
+    MaxPower              100mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              4 @Internal Flash  /0x08000000/20*001Ka,108*001Kg
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       1
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              5 @SPI Flash : SST25x/0x00000000/512*04Kg
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             9
+        bDescriptorType                    33
+        bmAttributes                       11
+          Will Detach
+          Manifestation Intolerant
+          Upload Supported
+          Download Supported
+        wDetachTimeout                    255 milliseconds
+        wTransferSize                    1024 bytes
+        bcdDFUVersion                   1.1a
+Device Status:     0x0001
+  Self Powered

+ 48 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/stm32f107.bin-download

@@ -0,0 +1,48 @@
+> src/dfu-util --intf 0 --alt 0 -v -v -v -s 0x8000000 -D test3
+dfu-util 0.4
+
+(C) 2005-2008 by Weston Schmidt, Harald Welte and OpenMoko Inc.
+(C) 2010-2011 Tormod Volden (DfuSe support)
+This program is Free Software and has ABSOLUTELY NO WARRANTY
+
+dfu-util does currently only support DFU version 1.0
+
+Opening DFU USB device... ID 0483:df11
+Run-time device DFU version 011a
+Found DFU: [0483:df11] devnum=0, cfg=1, intf=0, alt=0, name="@Internal Flash  /0x08000000/128*002Kg"
+Claiming USB DFU Interface...
+Setting Alternate Setting #0 ...
+Determining device status: state = dfuIDLE, status = 0
+dfuIDLE, continuing
+DFU mode device DFU version 011a
+Device returned transfer size 2048
+No valid DFU suffix signature
+Warning: File has no DFU suffix
+DfuSe interface name: "Internal Flash  "
+Memory segment at 0x08000000 128 x 2048 = 262144 (rew)
+Uploading to address = 0x08000000, size = 16384
+Erasing page size 2048 at address 0x08000000, page starting at 0x08000000
+ Download from image offset 00000000 to memory 08000000-080007ff, size 2048
+  Setting address pointer to 0x08000000
+Erasing page size 2048 at address 0x08000800, page starting at 0x08000800
+ Download from image offset 00000800 to memory 08000800-08000fff, size 2048
+  Setting address pointer to 0x08000800
+Erasing page size 2048 at address 0x08001000, page starting at 0x08001000
+ Download from image offset 00001000 to memory 08001000-080017ff, size 2048
+  Setting address pointer to 0x08001000
+Erasing page size 2048 at address 0x08001800, page starting at 0x08001800
+ Download from image offset 00001800 to memory 08001800-08001fff, size 2048
+  Setting address pointer to 0x08001800
+Erasing page size 2048 at address 0x08002000, page starting at 0x08002000
+ Download from image offset 00002000 to memory 08002000-080027ff, size 2048
+  Setting address pointer to 0x08002000
+Erasing page size 2048 at address 0x08002800, page starting at 0x08002800
+ Download from image offset 00002800 to memory 08002800-08002fff, size 2048
+  Setting address pointer to 0x08002800
+Erasing page size 2048 at address 0x08003000, page starting at 0x08003000
+ Download from image offset 00003000 to memory 08003000-080037ff, size 2048
+  Setting address pointer to 0x08003000
+Erasing page size 2048 at address 0x08003800, page starting at 0x08003800
+ Download from image offset 00003800 to memory 08003800-08003fff, size 2048
+  Setting address pointer to 0x08003800
+

+ 60 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/stm32f107.lsusb

@@ -0,0 +1,60 @@
+
+Bus 001 Device 028: ID 0483:df11 SGS Thomson Microelectronics STM Device in DFU Mode
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  idVendor           0x0483 SGS Thomson Microelectronics
+  idProduct          0xdf11 STM Device in DFU Mode
+  bcdDevice           20.00
+  iManufacturer           1 STMicroelectronics
+  iProduct                2 STM32 0x418 DFU Bootloader
+  iSerial                 3 STM32
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           36
+    bNumInterfaces          1
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0xc0
+      Self Powered
+    MaxPower              100mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              4 @Internal Flash  /0x08000000/128*002Kg
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       1
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              5 @Option Bytes  /0x1FFFF800/01*016 g
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             9
+        bDescriptorType                    33
+        bmAttributes                       11
+          Will Detach
+          Manifestation Intolerant
+          Upload Supported
+          Download Supported
+        wDetachTimeout                    255 milliseconds
+        wTransferSize                    2048 bytes
+        bcdDFUVersion                   1.1a
+Device Status:     0x0000
+  (Bus Powered)

+ 36 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/stm32f4discovery.bin-download

@@ -0,0 +1,36 @@
+dfu-util  --device 0483:df11 --alt 0 \
+	--dfuse-address 0x08000000 \
+        -v -v -v \
+	--download arm/iotoggle.bin
+No valid DFU suffix signature
+Warning: File has no DFU suffix
+dfu-util 0.5
+
+(C) 2005-2008 by Weston Schmidt, Harald Welte and OpenMoko Inc.
+(C) 2010-2011 Tormod Volden (DfuSe support)
+This program is Free Software and has ABSOLUTELY NO WARRANTY
+
+dfu-util does currently only support DFU version 1.0
+
+Filter on vendor = 0x0483 product = 0xdf11
+Opening DFU capable USB device... ID 0483:df11
+Run-time device DFU version 011a
+Found DFU: [0483:df11] devnum=0, cfg=1, intf=0, alt=0, name="@Internal Flash  /0x08000000/04*016Kg,01*064Kg,07*128Kg"
+Claiming USB DFU Interface...
+Setting Alternate Setting #0 ...
+Determining device status: state = dfuERROR, status = 10
+dfuERROR, clearing status
+Determining device status: state = dfuIDLE, status = 0
+dfuIDLE, continuing
+DFU mode device DFU version 011a
+Device returned transfer size 2048
+DfuSe interface name: "Internal Flash  "
+Memory segment at 0x08000000   4 x 16384 = 65536 (rew)
+Memory segment at 0x08010000   1 x 65536 = 65536 (rew)
+Memory segment at 0x08020000   7 x 131072 = 917504 (rew)
+Uploading to address = 0x08000000, size = 2308
+Erasing page size 16384 at address 0x08000000, page starting at 0x08000000
+ Download from image offset 00000000 to memory 08000000-080007ff, size 2048
+  Setting address pointer to 0x08000000
+ Download from image offset 00000800 to memory 08000800-08000903, size 260
+  Setting address pointer to 0x08000800

+ 80 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/stm32f4discovery.lsusb

@@ -0,0 +1,80 @@
+
+Bus 001 Device 010: ID 0483:df11 SGS Thomson Microelectronics STM Device in DFU Mode
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               1.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  idVendor           0x0483 SGS Thomson Microelectronics
+  idProduct          0xdf11 STM Device in DFU Mode
+  bcdDevice           21.00
+  iManufacturer           1 STMicroelectronics
+  iProduct                2 STM32  BOOTLOADER
+  iSerial                 3 315A28A0B956
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           54
+    bNumInterfaces          1
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0xc0
+      Self Powered
+    MaxPower              100mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              4 @Internal Flash  /0x08000000/04*016Kg,01*064Kg,07*128Kg
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       1
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              5 @Option Bytes  /0x1FFFC000/01*016 g
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       2
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              6 @OTP Memory /0x1FFF7800/01*512 g,01*016 g
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       3
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      2 
+      iInterface              7 @Device Feature/0xFFFF0000/01*004 g
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             9
+        bDescriptorType                    33
+        bmAttributes                       11
+          Will Detach
+          Manifestation Intolerant
+          Upload Supported
+          Download Supported
+        wDetachTimeout                    255 milliseconds
+        wTransferSize                    2048 bytes
+        bcdDFUVersion                   1.1a
+Device Status:     0x0001
+  Self Powered

+ 269 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/device-logs/tdk-bluetooth.lsusb

@@ -0,0 +1,269 @@
+
+Bus 006 Device 014: ID 04bf:0320 TDK Corp. Bluetooth Adapter
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               2.00
+  bDeviceClass          224 Wireless
+  bDeviceSubClass         1 Radio Frequency
+  bDeviceProtocol         1 Bluetooth
+  bMaxPacketSize0        64
+  idVendor           0x04bf TDK Corp.
+  idProduct          0x0320 Bluetooth Adapter
+  bcdDevice           26.52
+  iManufacturer           1 Ezurio
+  iProduct                2 Turbo Bluetooth Adapter
+  iSerial                 3 008098D4FFBD
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength          193
+    bNumInterfaces          3
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower               64mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           3
+      bInterfaceClass       224 Wireless
+      bInterfaceSubClass      1 Radio Frequency
+      bInterfaceProtocol      1 Bluetooth
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            3
+          Transfer Type            Interrupt
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0010  1x 16 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x02  EP 2 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0040  1x 64 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x82  EP 2 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0040  1x 64 bytes
+        bInterval               1
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       0
+      bNumEndpoints           2
+      bInterfaceClass       224 Wireless
+      bInterfaceSubClass      1 Radio Frequency
+      bInterfaceProtocol      1 Bluetooth
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x03  EP 3 OUT
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0000  1x 0 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x83  EP 3 IN
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0000  1x 0 bytes
+        bInterval               1
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       1
+      bNumEndpoints           2
+      bInterfaceClass       224 Wireless
+      bInterfaceSubClass      1 Radio Frequency
+      bInterfaceProtocol      1 Bluetooth
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x03  EP 3 OUT
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0009  1x 9 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x83  EP 3 IN
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0009  1x 9 bytes
+        bInterval               1
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       2
+      bNumEndpoints           2
+      bInterfaceClass       224 Wireless
+      bInterfaceSubClass      1 Radio Frequency
+      bInterfaceProtocol      1 Bluetooth
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x03  EP 3 OUT
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0011  1x 17 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x83  EP 3 IN
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0011  1x 17 bytes
+        bInterval               1
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       3
+      bNumEndpoints           2
+      bInterfaceClass       224 Wireless
+      bInterfaceSubClass      1 Radio Frequency
+      bInterfaceProtocol      1 Bluetooth
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x03  EP 3 OUT
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0019  1x 25 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x83  EP 3 IN
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0019  1x 25 bytes
+        bInterval               1
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       4
+      bNumEndpoints           2
+      bInterfaceClass       224 Wireless
+      bInterfaceSubClass      1 Radio Frequency
+      bInterfaceProtocol      1 Bluetooth
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x03  EP 3 OUT
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0021  1x 33 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x83  EP 3 IN
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0021  1x 33 bytes
+        bInterval               1
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       5
+      bNumEndpoints           2
+      bInterfaceClass       224 Wireless
+      bInterfaceSubClass      1 Radio Frequency
+      bInterfaceProtocol      1 Bluetooth
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x03  EP 3 OUT
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0031  1x 49 bytes
+        bInterval               1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x83  EP 3 IN
+        bmAttributes            1
+          Transfer Type            Isochronous
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0031  1x 49 bytes
+        bInterval               1
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        2
+      bAlternateSetting       0
+      bNumEndpoints           0
+      bInterfaceClass       254 Application Specific Interface
+      bInterfaceSubClass      1 Device Firmware Update
+      bInterfaceProtocol      0 
+      iInterface              0 
+      Device Firmware Upgrade Interface Descriptor:
+        bLength                             7
+        bDescriptorType                    33
+        bmAttributes                        7
+          Will Not Detach
+          Manifestation Tolerant
+          Upload Supported
+          Download Supported
+        wDetachTimeout                   5000 milliseconds
+        wTransferSize                    1023 bytes
+Device Status:     0x0000
+  (Bus Powered)

+ 192 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/dfuse-pack.py

@@ -0,0 +1,192 @@
+#!/usr/bin/python
+
+# Written by Antonio Galea - 2010/11/18
+# Distributed under Gnu LGPL 3.0
+# see http://www.gnu.org/licenses/lgpl-3.0.txt
+
+import sys,struct,zlib,os
+import binascii
+from optparse import OptionParser
+
+DEFAULT_DEVICE="0x0483:0xdf11"
+DEFAULT_NAME=b'ST...'
+
+def named(tuple,names):
+  return dict(list(zip(names.split(),tuple)))
+def consume(fmt,data,names):
+  n = struct.calcsize(fmt)
+  return named(struct.unpack(fmt,data[:n]),names),data[n:]
+def cstring(bytestring):
+  return bytestring.partition(b'\0')[0]
+def compute_crc(data):
+  return 0xFFFFFFFF & -zlib.crc32(data) -1
+
+def parse(file,dump_images=False):
+  print('File: "%s"' % file)
+  data = open(file,'rb').read()
+  crc = compute_crc(data[:-4])
+  prefix, data = consume('<5sBIB',data,'signature version size targets')
+  print('%(signature)s v%(version)d, image size: %(size)d, targets: %(targets)d' % prefix)
+  for t in range(prefix['targets']):
+    tprefix, data  = consume('<6sBI255s2I',data,'signature altsetting named name size elements')
+    tprefix['num'] = t
+    if tprefix['named']:
+      tprefix['name'] = cstring(tprefix['name'])
+    else:
+      tprefix['name'] = ''
+    print('%(signature)s %(num)d, alt setting: %(altsetting)s, name: "%(name)s", size: %(size)d, elements: %(elements)d' % tprefix)
+    tsize = tprefix['size']
+    target, data = data[:tsize], data[tsize:]
+    for e in range(tprefix['elements']):
+      eprefix, target = consume('<2I',target,'address size')
+      eprefix['num'] = e
+      print('  %(num)d, address: 0x%(address)08x, size: %(size)d' % eprefix)
+      esize = eprefix['size']
+      image, target = target[:esize], target[esize:]
+      if dump_images:
+        out = '%s.target%d.image%d.bin' % (file,t,e)
+        open(out,'wb').write(image)
+        print('    DUMPED IMAGE TO "%s"' % out)
+    if len(target):
+      print("target %d: PARSE ERROR" % t)
+  suffix = named(struct.unpack('<4H3sBI',data[:16]),'device product vendor dfu ufd len crc')
+  print('usb: %(vendor)04x:%(product)04x, device: 0x%(device)04x, dfu: 0x%(dfu)04x, %(ufd)s, %(len)d, 0x%(crc)08x' % suffix)
+  if crc != suffix['crc']:
+    print("CRC ERROR: computed crc32 is 0x%08x" % crc)
+  data = data[16:]
+  if data:
+    print("PARSE ERROR")
+
+def checkbin(binfile):
+  data = open(binfile,'rb').read()
+  if (len(data) < 16):
+    return
+  crc = compute_crc(data[:-4])
+  suffix = named(struct.unpack('<4H3sBI',data[-16:]),'device product vendor dfu ufd len crc')
+  if crc == suffix['crc'] and suffix['ufd'] == b'UFD':
+    print('usb: %(vendor)04x:%(product)04x, device: 0x%(device)04x, dfu: 0x%(dfu)04x, %(ufd)s, %(len)d, 0x%(crc)08x' % suffix)
+    print("It looks like the file %s has a DFU suffix!" % binfile)
+    print("Please remove any DFU suffix and retry.")
+    sys.exit(1)
+
+def build(file,targets,name=DEFAULT_NAME,device=DEFAULT_DEVICE):
+  data = b''
+  for t,target in enumerate(targets):
+    tdata = b''
+    for image in target:
+      tdata += struct.pack('<2I',image['address'],len(image['data']))+image['data']
+    tdata = struct.pack('<6sBI255s2I',b'Target',0,1,name,len(tdata),len(target)) + tdata
+    data += tdata
+  data  = struct.pack('<5sBIB',b'DfuSe',1,len(data)+11,len(targets)) + data
+  v,d=[int(x,0) & 0xFFFF for x in device.split(':',1)]
+  data += struct.pack('<4H3sB',0,d,v,0x011a,b'UFD',16)
+  crc   = compute_crc(data)
+  data += struct.pack('<I',crc)
+  open(file,'wb').write(data)
+
+if __name__=="__main__":
+  usage = """
+%prog [-d|--dump] infile.dfu
+%prog {-b|--build} address:file.bin [-b address:file.bin ...] [{-D|--device}=vendor:device] outfile.dfu
+%prog {-s|--build-s19} file.s19 [{-D|--device}=vendor:device] outfile.dfu"""
+  parser = OptionParser(usage=usage)
+  parser.add_option("-b", "--build", action="append", dest="binfiles",
+    help="build a DFU file from given BINFILES. Note that the BINFILES must not have any DFU suffix!", metavar="BINFILES")
+  parser.add_option("-s", "--build-s19", type="string", dest="s19files",
+    help="build a DFU file from given S19 S-record file.", metavar="S19FILE")
+  parser.add_option("-D", "--device", action="store", dest="device",
+    help="build for DEVICE, defaults to %s" % DEFAULT_DEVICE, metavar="DEVICE")
+  parser.add_option("-d", "--dump", action="store_true", dest="dump_images",
+    default=False, help="dump contained images to current directory")
+  (options, args) = parser.parse_args()
+
+  if options.binfiles and len(args)==1:
+    target = []
+    for arg in options.binfiles:
+      try:
+        address,binfile = arg.split(':',1)
+      except ValueError:
+        print("Address:file couple '%s' invalid." % arg)
+        sys.exit(1)
+      try:
+        address = int(address,0) & 0xFFFFFFFF
+      except ValueError:
+        print("Address %s invalid." % address)
+        sys.exit(1)
+      if not os.path.isfile(binfile):
+        print("Unreadable file '%s'." % binfile)
+        sys.exit(1)
+      checkbin(binfile)
+      target.append({ 'address': address, 'data': open(binfile,'rb').read() })
+    outfile = args[0]
+    device = DEFAULT_DEVICE
+    if options.device:
+      device=options.device
+    try:
+      v,d=[int(x,0) & 0xFFFF for x in device.split(':',1)]
+    except:
+      print("Invalid device '%s'." % device)
+      sys.exit(1)
+    build(outfile,[target],DEFAULT_NAME,device)
+  elif options.s19files and len(args)==1:
+    address = 0
+    data = ""
+    target = []
+    name = DEFAULT_NAME
+    with open(options.s19files) as f:
+      lines = f.readlines()
+      for line in lines:
+          curaddress = 0
+          curdata = ""
+          line = line.rstrip()
+          if line.startswith ( "S0" ):
+            name = binascii.a2b_hex(line[8:len(line) - 2]).replace(".s19", "")
+          elif line.startswith ( "S3" ):
+            try:
+              curaddress = int(line[4:12], 16) & 0xFFFFFFFF
+            except ValueError:
+              print("Address %s invalid." % address)
+              sys.exit(1)
+            curdata = binascii.unhexlify(line[12:-2])
+          elif line.startswith ( "S2" ):
+            try:
+              curaddress = int(line[4:10], 16) & 0xFFFFFFFF
+            except ValueError:
+              print("Address %s invalid." % address)
+              sys.exit(1)
+            curdata = binascii.unhexlify(line[10:-2])
+          elif line.startswith ( "S1" ):
+            try:
+              curaddress = int(line[4:8], 16) & 0xFFFFFFFF
+            except ValueError:
+              print("Address %s invalid." % address)
+              sys.exit(1)
+            curdata = binascii.unhexlify(line[8:-2])
+          if address == 0:
+              address = curaddress
+              data = curdata
+          elif address + len(data) != curaddress:
+              target.append({ 'address': address, 'data': data })
+              address = curaddress
+              data = curdata
+          else:
+              data += curdata
+    outfile = args[0]
+    device = DEFAULT_DEVICE
+    if options.device:
+      device=options.device
+    try:
+      v,d=[int(x,0) & 0xFFFF for x in device.split(':',1)]
+    except:
+      print("Invalid device '%s'." % device)
+      sys.exit(1)
+    build(outfile,[target],name,device)
+  elif len(args)==1:
+    infile = args[0]
+    if not os.path.isfile(infile):
+      print("Unreadable file '%s'." % infile)
+      sys.exit(1)
+    parse(infile, dump_images=options.dump_images)
+  else:
+    parser.print_help()
+    sys.exit(1)

+ 4 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/doc/40-dfuse.rules

@@ -0,0 +1,4 @@
+# Example udev rules (usually placed in /etc/udev/rules.d)
+# Makes STM32 DfuSe device writeable for the "plugdev" group
+
+ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE="664", GROUP="plugdev"

+ 2 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/doc/Makefile.am

@@ -0,0 +1,2 @@
+man_MANS = dfu-util.1
+EXTRA_DIST = dfu-util.1 40-dfuse.rules

+ 21 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/doc/SPEC-differences.txt

@@ -0,0 +1,21 @@
+From 1.0 to 1.1:
+----------------
+(Page references in 1.1 spec)
+
+Page 10: Added protocol column to table 3.2
+Page 12: Changed value for bInterfaceProtocol from 00h to 01h (table 4.1)
+Page 13: Added bitWillDetach flag in bmAttributes at bit 3 (table 4.2)
+         Changed bLength from 07h to 09h (table 4.2)
+Page 14: Added bcdDFUVersion (table 4.2)
+         Changed bDeviceClass value from FEh to 00h (table 4.3)
+         Changed bDevicesubClass value from 01h to 00h (table 4.3)
+Page 15: Changed bInterfaceProtocol value from 00h to 02h (table 4.4)
+Page 17: Adjust wording for bitWillDetach addition (5.1)
+Page 26: Adjust wording for bitWillDetach addition (7)
+Page 29: Adjust wording for bitWillDetach addition (A.2.1)
+
+Summary:
+- Addition of the bitWillDetach flag which allows the device to detach instead
+  of waiting of the host to reset the device.
+- Version changes for bInterfaceProtocol, bDeviceClass and bDevicesubClass
+- Addition of bcdDFUVersion

+ 248 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/doc/dfu-util.1

@@ -0,0 +1,248 @@
+.TH DFU-UTIL 1 "September 23, 2012"
+.SH NAME
+dfu-util \- Device firmware update (DFU) USB programmer
+.SH SYNOPSIS
+.\" Listing devices
+.HP
+.B dfu-util
+.B \-l 
+.RB [\| \-v \|]
+.RB [\| \-d
+.IR vid:pid [\|, vid:pid \|]\|]
+.RB [\| \-p
+.IR path \|]
+.RB [\| \-c
+.IR configuration \|]
+.RB [\| \-i
+.IR interface \|]
+.RB [\| \-a
+.IR alt-intf \|]
+.RB [\| \-S
+.IR serial [\|, serial \|]\|]
+.\" Download to or upload from device
+.HP
+.B dfu-util
+.RB [\| \-v \|]
+.RB [\| \-d
+.IR vid:pid [\|, vid:pid \|]\|]
+.RB [\| \-p
+.IR path \|]
+.RB [\| \-c
+.IR configuration \|]
+.RB [\| \-i
+.IR interface \|]
+.RB [\| \-a
+.IR alt-intf \|]
+.RB [\| \-S
+.IR serial [\|, serial \|]\|]
+.RB [\| \-t
+.IR size \|]
+.RB [\| \-Z
+.IR size \|]
+.RB [\| \-s
+.IR address \|]
+.RB [\| \-R \|]
+.RB [\| \-D \||\| \-U
+.IR file \|]
+.\" --help and --version
+.HP
+.B dfu-util
+.RB [\| \-hV \|]
+.SH DESCRIPTION
+.B dfu-util
+is a program that implements the host (computer) side of the USB DFU
+(Universal Serial Bus Device Firmware Upgrade) protocol.
+.sp
+dfu-util communicates with devices that implement the device side of the
+USB DFU protocol, and is often used to upgrade the firmware of such
+devices.
+.SH OPTIONS
+.TP
+.B "\-l, \-\-list"
+List the currently attached DFU capable USB devices.
+.TP
+.BR "\-d, \-\-device" " [\fIRun-Time VENDOR\fP]:[\fIRun-Time PRODUCT\fP][,[\fIDFU Mode VENDOR\fP]:[\fIDFU Mode PRODUCT\fP]]"
+.RS
+Specify run-time and/or DFU mode vendor and/or product IDs of the DFU device
+to work with. \fBVENDOR\fP and \fBPRODUCT\fP are hexadecimal numbers (no prefix
+needed), "*" (match any), or "-" (match nothing). By default, any DFU capable
+device in either run-time or DFU mode will be considered.
+.sp
+If you only have one standards-compliant DFU device attached to your computer,
+this parameter is optional. However, as soon as you have multiple DFU devices
+connected, dfu-util will detect this and abort, asking you to specify which
+device to use.
+.sp
+If only run-time IDs are specified (e.g. "\fB--device 1457:51ab\fP"), then in
+addition to the specified run-time IDs, any DFU mode devices will also be
+considered. This is beneficial to allow a DFU capable device to be found
+again after a switch to DFU mode, since the vendor and/or product ID of a
+device usually changes in DFU mode.
+.sp
+If only DFU mode IDs are specified (e.g. "\fB--device ,951:26\fP"), then all
+run-time devices will be ignored, making it easy to target a specific device in
+DFU mode.
+.sp
+If both run-time and DFU mode IDs are specified (e.g. "\fB--device
+1457:51ab,:2bc\fP"), then unspecified DFU mode components will use the run-time
+value specified.
+.sp
+Examples:
+.TP
+.B "--device 1457:51ab,951:26"
+.br
+Work with a device in run-time mode with
+vendor ID 0x1457 and product ID 0x51ab, or in DFU mode with vendor ID 0x0951
+and product ID 0x0026
+.sp
+.TP
+.B "--device 1457:51ab,:2bc"
+.br
+Work with a device in run-time mode with vendor ID 0x1457 and product ID
+0x51ab, or in DFU mode with vendor ID 0x1457 and product ID 0x02bc
+.sp
+.TP
+.B "--device 1457:51ab"
+.br
+Work with a device in run-time mode with vendor ID 0x1457 and product ID
+0x51ab, or in DFU mode with any vendor and product ID
+.sp
+.TP
+.B "--device ,951:26"
+.br
+Work with a device in DFU mode with vendor ID 0x0951 and product ID 0x0026
+.sp
+.TP
+.B "--device *,-"
+.br
+Work with any device in run-time mode, and ignore any device in DFU mode
+.sp
+.TP
+.B "--device ,"
+.br
+Ignore any device in run-time mode, and Work with any device in DFU mode
+.RE
+.TP
+.BR "\-p, \-\-path" " BUS-PORT. ... .PORT"
+Specify the path to the DFU device.
+.TP
+.BR "\-c, \-\-cfg" " CONFIG-NR"
+Specify the configuration of the DFU device. Note that this is only used for matching, the configuration is not set by dfu-util.
+.TP
+.BR "\-i, \-\-intf" " INTF-NR"
+Specify the DFU interface number.
+.TP
+.BR "\-a, \-\-alt" " ALT"
+Specify the altsetting of the DFU interface by name or by number.
+.TP
+.BR "\-S, \-\-serial" " [\fIRun-Time SERIAL\fP][,[\fIDFU Mode SERIAL\fP]]"
+Specify the run-time and DFU mode serial numbers used to further restrict
+device matches.  If multiple, identical DFU devices are simultaneously
+connected to a system then vendor and product ID will be insufficient for
+targeting a single device.  In this situation, it may be possible to use this
+parameter to specify a serial number which also must match.
+.sp
+If only a single serial number is specified, then the same serial number is
+used in both run-time and DFU mode. An empty serial number will match any
+serial number in the corresponding mode.
+.TP
+.B "\-t, \-\-transfer-size" " SIZE"
+Specify the number of bytes per USB transfer. The optimal value is
+usually determined automatically so this option is rarely useful. If
+you need to use this option for a device, please report it as a bug.
+.TP
+.B "\-Z, \-\-upload-size" " SIZE"
+Specify the expected upload size, in bytes.
+.TP
+.BR "\-U, \-\-upload" " FILE"
+Read firmware from device into
+.BR FILE .
+.TP
+.BR "\-D, \-\-download" " FILE"
+Write firmware from
+.B FILE
+into device. When FILE is \-, the firmware is read from stdin.
+.TP
+.B "\-R, \-\-reset"
+Issue USB reset signalling after upload or download has finished.
+.TP
+.BR "\-s, \-\-dfuse-address" " address"
+Specify target address for raw binary download/upload on DfuSe devices. Do
+.B not
+use this for downloading DfuSe (.dfu) files. Modifiers can be added
+to the address, separated by a colon, to perform special DfuSE commands such
+as "leave" DFU mode, "unprotect" and "mass-erase" flash memory.
+.TP
+.B "\-v, \-\-verbose"
+Print more information about dfu-util's operation. A second
+.B -v
+will turn on verbose logging of USB requests. Repeat this option to further
+increase verbosity.
+.TP
+.B "\-h, \-\-help"
+Show a help text and exit.
+.TP
+.B "\-V, \-\-version"
+Show version information and exit.
+.SH EXAMPLES
+.SS Using dfu-util in the OpenMoko project
+(with the Neo1973 hardware)
+.PP
+Flashing the rootfs:
+.br
+.B "  $ dfu-util -a rootfs -R -D /path/to/openmoko-devel-image.jffs2"
+.PP
+Flashing the kernel:
+.br
+.B "  $ dfu-util -a kernel -R -D /path/to/uImage"
+.PP
+Flashing the bootloader:
+.br
+.B "  $ dfu-util -a u-boot -R -D /path/to/u-boot.bin"
+.PP
+Copying a kernel into RAM:
+.br
+.B "  $ dfu-util -a 0 -R -D /path/to/uImage"
+.sp
+Once this has finished, the kernel will be available at the default load
+address of 0x32000000 in Neo1973 RAM.
+.B Note:
+You cannot transfer more than 2MB of data into RAM using this method.
+.sp
+.SS Using dfu-util with a DfuSe device
+.PP
+Flashing a
+.B .dfu
+(special DfuSe format) file to the device:
+.br
+.B "  $ dfu-util -a 0 -D /path/to/dfuse-image.dfu"
+.PP
+Reading out 1 KB of flash starting at address 0x8000000:
+.br
+.B "  $ dfu-util -a 0 -s 0x08000000:1024 -U newfile.bin"
+.PP
+Flashing a binary file to address 0x8004000 of device memory and
+ask the device to leave DFU mode:
+.br
+.B "  $ dfu-util -a 0 -s 0x08004000:leave -D /path/to/image.bin"
+.\" There are no bugs of course
+.SH BUGS
+Please report any bugs to the dfu-util bug tracker at
+.BR http://sourceforge.net/p/dfu-util/tickets/ .
+Please use the
+.IR --verbose " option (repeated as necessary) to provide more"
+information in your bug report.
+.SH SEE ALSO
+The dfu-util home page is
+.B http://sourceforge.net/p/dfu-util/
+.SH HISTORY
+dfu-util was originally written for the OpenMoko project by
+Weston Schmidt <weston_schmidt@yahoo.com> and 
+Harald Welte <hwelte@hmw-consulting.de>. Over time, nearly complete
+support of DFU 1.0, DFU 1.1 and DfuSe ("1.1a") has been added.
+.SH LICENCE
+.B dfu-util
+is covered by the GNU General Public License (GPL), version 2 or later.
+.SH COPYRIGHT
+This manual page was originally written by Uwe Hermann <uwe@hermann-uwe.de>,
+and is now part of the dfu-util project.

+ 10 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/msvc/README_msvc.txt

@@ -0,0 +1,10 @@
+# (C) Roger Meier <r.meier@siemens.com>
+# (C) Pascal Schweizer <pascal.schweizer@siemens.com>
+# msvc folder is GPL-2.0+, LGPL-2.1+, BSD-3-Clause or MIT license(SPDX)
+
+Building dfu-util native on Windows with Visual Studio
+
+3rd party dependencies:
+- libusbx ( git clone https://github.com/libusbx/libusbx.git )
+  - getopt (part of libusbx: libusbx/examples/getopt)
+

+ 100 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/msvc/dfu-suffix_2010.vcxproj

@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{8F7600A2-3B37-4956-B39B-A1D43EF29EDA}</ProjectGuid>
+    <RootNamespace>dfusuffix</RootNamespace>
+    <ProjectName>dfu-suffix</ProjectName>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <IncludePath>$(SolutionDir)..\..\libusbx\examples\getopt;$(SolutionDir)..\..\libusbx\libusb;$(IncludePath)</IncludePath>
+    <OutDir>$(SolutionDir)..\$(Platform)\$(ProjectName)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)..\$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
+    <LibraryPath>$(SolutionDir)..\$(Platform)\$(ProjectName)\$(Configuration)\dll;$(LibraryPath)</LibraryPath>
+    <ReferencePath>$(VCInstallDir)atlmfc\lib;$(VCInstallDir)lib</ReferencePath>
+    <ExecutablePath>$(ExecutablePath)</ExecutablePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ExecutablePath>$(ExecutablePath)</ExecutablePath>
+    <IncludePath>$(SolutionDir)..\..\libusbx\examples\getopt;$(SolutionDir)..\..\libusbx\libusb;$(IncludePath)</IncludePath>
+    <LibraryPath>$(SolutionDir)..\$(Platform)\$(ProjectName)\$(Configuration)\dll;$(LibraryPath)</LibraryPath>
+    <OutDir>$(SolutionDir)..\$(Platform)\$(ProjectName)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)..\$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>HAVE_WINDOWS_H;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>HAVE_WINDOWS_H;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="..\src\dfu_file.c" />
+    <ClCompile Include="..\src\suffix.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\src\dfu_file.h" />
+    <ClInclude Include="..\src\portable.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\libusbx\msvc\getopt_2010.vcxproj">
+      <Project>{a2169bc8-cf99-40bf-83f3-b0e38f7067bd}</Project>
+    </ProjectReference>
+    <ProjectReference Include="..\..\libusbx\msvc\libusb_static_2010.vcxproj">
+      <Project>{349ee8f9-7d25-4909-aaf5-ff3fade72187}</Project>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>

+ 54 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/msvc/dfu-util_2010.sln

@@ -0,0 +1,54 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dfu-util", "dfu-util_2010.vcxproj", "{0E071A60-7EF2-4427-BAA8-9143CACB5BCB}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C4F8746D-B27E-4806-95E5-2052174E923B}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dfu-suffix", "dfu-suffix_2010.vcxproj", "{8F7600A2-3B37-4956-B39B-A1D43EF29EDA}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "getopt_2010", "..\..\libusbx\msvc\getopt_2010.vcxproj", "{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libusb-1.0 (static)", "..\..\libusbx\msvc\libusb_static_2010.vcxproj", "{349EE8F9-7D25-4909-AAF5-FF3FADE72187}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Debug|x64 = Debug|x64
+		Release|Win32 = Release|Win32
+		Release|x64 = Release|x64
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{0E071A60-7EF2-4427-BAA8-9143CACB5BCB}.Debug|Win32.ActiveCfg = Debug|Win32
+		{0E071A60-7EF2-4427-BAA8-9143CACB5BCB}.Debug|Win32.Build.0 = Debug|Win32
+		{0E071A60-7EF2-4427-BAA8-9143CACB5BCB}.Debug|x64.ActiveCfg = Debug|Win32
+		{0E071A60-7EF2-4427-BAA8-9143CACB5BCB}.Release|Win32.ActiveCfg = Release|Win32
+		{0E071A60-7EF2-4427-BAA8-9143CACB5BCB}.Release|Win32.Build.0 = Release|Win32
+		{0E071A60-7EF2-4427-BAA8-9143CACB5BCB}.Release|x64.ActiveCfg = Release|Win32
+		{8F7600A2-3B37-4956-B39B-A1D43EF29EDA}.Debug|Win32.ActiveCfg = Debug|Win32
+		{8F7600A2-3B37-4956-B39B-A1D43EF29EDA}.Debug|Win32.Build.0 = Debug|Win32
+		{8F7600A2-3B37-4956-B39B-A1D43EF29EDA}.Debug|x64.ActiveCfg = Debug|Win32
+		{8F7600A2-3B37-4956-B39B-A1D43EF29EDA}.Release|Win32.ActiveCfg = Release|Win32
+		{8F7600A2-3B37-4956-B39B-A1D43EF29EDA}.Release|Win32.Build.0 = Release|Win32
+		{8F7600A2-3B37-4956-B39B-A1D43EF29EDA}.Release|x64.ActiveCfg = Release|Win32
+		{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}.Debug|Win32.ActiveCfg = Debug|Win32
+		{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}.Debug|Win32.Build.0 = Debug|Win32
+		{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}.Debug|x64.ActiveCfg = Debug|x64
+		{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}.Debug|x64.Build.0 = Debug|x64
+		{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}.Release|Win32.ActiveCfg = Release|Win32
+		{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}.Release|Win32.Build.0 = Release|Win32
+		{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}.Release|x64.ActiveCfg = Release|x64
+		{AE83E1B4-CE06-47EE-B7A3-C3A1D7C2D71E}.Release|x64.Build.0 = Release|x64
+		{349EE8F9-7D25-4909-AAF5-FF3FADE72187}.Debug|Win32.ActiveCfg = Debug|Win32
+		{349EE8F9-7D25-4909-AAF5-FF3FADE72187}.Debug|Win32.Build.0 = Debug|Win32
+		{349EE8F9-7D25-4909-AAF5-FF3FADE72187}.Debug|x64.ActiveCfg = Debug|x64
+		{349EE8F9-7D25-4909-AAF5-FF3FADE72187}.Debug|x64.Build.0 = Debug|x64
+		{349EE8F9-7D25-4909-AAF5-FF3FADE72187}.Release|Win32.ActiveCfg = Release|Win32
+		{349EE8F9-7D25-4909-AAF5-FF3FADE72187}.Release|Win32.Build.0 = Release|Win32
+		{349EE8F9-7D25-4909-AAF5-FF3FADE72187}.Release|x64.ActiveCfg = Release|x64
+		{349EE8F9-7D25-4909-AAF5-FF3FADE72187}.Release|x64.Build.0 = Release|x64
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 120 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/msvc/dfu-util_2010.vcxproj

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{0E071A60-7EF2-4427-BAA8-9143CACB5BCB}</ProjectGuid>
+    <RootNamespace>dfuutil</RootNamespace>
+    <ProjectName>dfu-util</ProjectName>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <IncludePath>$(SolutionDir)..\..\libusbx\examples\getopt;$(SolutionDir)..\..\libusbx\libusb;$(IncludePath)</IncludePath>
+    <OutDir>$(SolutionDir)..\$(Platform)\$(ProjectName)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)..\$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
+    <LibraryPath>$(SolutionDir)..\$(Platform)\getopt\$(Configuration);$(LibraryPath)</LibraryPath>
+    <ReferencePath>$(VCInstallDir)atlmfc\lib;$(VCInstallDir)lib</ReferencePath>
+    <ExecutablePath>$(ExecutablePath)</ExecutablePath>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ExecutablePath>$(ExecutablePath)</ExecutablePath>
+    <IncludePath>$(SolutionDir)..\..\libusbx\examples\getopt;$(SolutionDir)..\..\libusbx\libusb;$(IncludePath)</IncludePath>
+    <LibraryPath>$(SolutionDir)..\$(Platform)\getopt\$(Configuration);$(LibraryPath)</LibraryPath>
+    <OutDir>$(SolutionDir)..\$(Platform)\$(ProjectName)\$(Configuration)\</OutDir>
+    <IntDir>$(SolutionDir)..\$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>HAVE_WINDOWS_H;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+    <PostBuildEvent>
+      <Command>
+      </Command>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <PreprocessorDefinitions>HAVE_WINDOWS_H;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+    <PostBuildEvent>
+      <Command>copy $(SolutionDir)..\$(Platform)\$(Configuration)\dll\libusb-1.0.dll  $(SolutionDir)..\$(Platform)\$(ProjectName)\$(Configuration)\</Command>
+    </PostBuildEvent>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="..\src\dfu.c" />
+    <ClCompile Include="..\src\dfuse.c" />
+    <ClCompile Include="..\src\dfuse_mem.c" />
+    <ClCompile Include="..\src\dfu_file.c" />
+    <ClCompile Include="..\src\dfu_load.c" />
+    <ClCompile Include="..\src\dfu_util.c" />
+    <ClCompile Include="..\src\main.c" />
+    <ClCompile Include="..\src\quirks.c" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="..\src\dfu.h" />
+    <ClInclude Include="..\src\dfuse.h" />
+    <ClInclude Include="..\src\dfuse_mem.h" />
+    <ClInclude Include="..\src\dfu_file.h" />
+    <ClInclude Include="..\src\dfu_load.h" />
+    <ClInclude Include="..\src\dfu_util.h" />
+    <ClInclude Include="..\src\portable.h" />
+    <ClInclude Include="..\src\quirks.h" />
+    <ClInclude Include="..\src\usb_dfu.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\libusbx\msvc\getopt_2010.vcxproj">
+      <Project>{a2169bc8-cf99-40bf-83f3-b0e38f7067bd}</Project>
+    </ProjectReference>
+    <ProjectReference Include="..\..\libusbx\msvc\libusb_static_2010.vcxproj">
+      <Project>{349ee8f9-7d25-4909-aaf5-ff3fade72187}</Project>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>

+ 28 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/Makefile.am

@@ -0,0 +1,28 @@
+AM_CFLAGS = -Wall -Wextra
+
+bin_PROGRAMS = dfu-util dfu-suffix dfu-prefix
+dfu_util_SOURCES = main.c \
+		portable.h \
+		dfu_load.c \
+		dfu_load.h \
+		dfu_util.c \
+		dfu_util.h \
+		dfuse.c \
+		dfuse.h \
+		dfuse_mem.c \
+		dfuse_mem.h \
+		dfu.c \
+		dfu.h \
+		usb_dfu.h \
+		dfu_file.c \
+		dfu_file.h \
+		quirks.c \
+		quirks.h
+
+dfu_suffix_SOURCES = suffix.c \
+		dfu_file.h \
+		dfu_file.c
+
+dfu_prefix_SOURCES = prefix.c \
+		dfu_file.h \
+		dfu_file.c

+ 357 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu.c

@@ -0,0 +1,357 @@
+/*
+ * Low-level DFU communication routines, originally taken from
+ * $Id: dfu.c,v 1.3 2006/06/20 06:28:04 schmidtw Exp $
+ * (part of dfu-programmer).
+ *
+ * Copyright 2005-2006 Weston Schmidt <weston_schmidt@alumni.purdue.edu>
+ * Copyright 2011-2014 Tormod Volden <debian.tormod@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <libusb.h>
+
+#include "portable.h"
+#include "dfu.h"
+#include "quirks.h"
+
+static int dfu_timeout = 5000;  /* 5 seconds - default */
+
+/*
+ *  DFU_DETACH Request (DFU Spec 1.0, Section 5.1)
+ *
+ *  device    - the usb_dev_handle to communicate with
+ *  interface - the interface to communicate with
+ *  timeout   - the timeout in ms the USB device should wait for a pending
+ *              USB reset before giving up and terminating the operation
+ *
+ *  returns 0 or < 0 on error
+ */
+int dfu_detach( libusb_device_handle *device,
+                const unsigned short interface,
+                const unsigned short timeout )
+{
+    return libusb_control_transfer( device,
+        /* bmRequestType */ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
+        /* bRequest      */ DFU_DETACH,
+        /* wValue        */ timeout,
+        /* wIndex        */ interface,
+        /* Data          */ NULL,
+        /* wLength       */ 0,
+                            dfu_timeout );
+}
+
+
+/*
+ *  DFU_DNLOAD Request (DFU Spec 1.0, Section 6.1.1)
+ *
+ *  device    - the usb_dev_handle to communicate with
+ *  interface - the interface to communicate with
+ *  length    - the total number of bytes to transfer to the USB
+ *              device - must be less than wTransferSize
+ *  data      - the data to transfer
+ *
+ *  returns the number of bytes written or < 0 on error
+ */
+int dfu_download( libusb_device_handle *device,
+                  const unsigned short interface,
+                  const unsigned short length,
+                  const unsigned short transaction,
+                  unsigned char* data )
+{
+    int status;
+
+    status = libusb_control_transfer( device,
+          /* bmRequestType */ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
+          /* bRequest      */ DFU_DNLOAD,
+          /* wValue        */ transaction,
+          /* wIndex        */ interface,
+          /* Data          */ data,
+          /* wLength       */ length,
+                              dfu_timeout );
+    return status;
+}
+
+
+/*
+ *  DFU_UPLOAD Request (DFU Spec 1.0, Section 6.2)
+ *
+ *  device    - the usb_dev_handle to communicate with
+ *  interface - the interface to communicate with
+ *  length    - the maximum number of bytes to receive from the USB
+ *              device - must be less than wTransferSize
+ *  data      - the buffer to put the received data in
+ *
+ *  returns the number of bytes received or < 0 on error
+ */
+int dfu_upload( libusb_device_handle *device,
+                const unsigned short interface,
+                const unsigned short length,
+                const unsigned short transaction,
+                unsigned char* data )
+{
+    int status;
+
+    status = libusb_control_transfer( device,
+          /* bmRequestType */ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
+          /* bRequest      */ DFU_UPLOAD,
+          /* wValue        */ transaction,
+          /* wIndex        */ interface,
+          /* Data          */ data,
+          /* wLength       */ length,
+                              dfu_timeout );
+    return status;
+}
+
+
+/*
+ *  DFU_GETSTATUS Request (DFU Spec 1.0, Section 6.1.2)
+ *
+ *  device    - the usb_dev_handle to communicate with
+ *  interface - the interface to communicate with
+ *  status    - the data structure to be populated with the results
+ *
+ *  return the number of bytes read in or < 0 on an error
+ */
+int dfu_get_status( struct dfu_if *dif, struct dfu_status *status )
+{
+    unsigned char buffer[6];
+    int result;
+
+    /* Initialize the status data structure */
+    status->bStatus       = DFU_STATUS_ERROR_UNKNOWN;
+    status->bwPollTimeout = 0;
+    status->bState        = STATE_DFU_ERROR;
+    status->iString       = 0;
+
+    result = libusb_control_transfer( dif->dev_handle,
+          /* bmRequestType */ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
+          /* bRequest      */ DFU_GETSTATUS,
+          /* wValue        */ 0,
+          /* wIndex        */ dif->interface,
+          /* Data          */ buffer,
+          /* wLength       */ 6,
+                              dfu_timeout );
+
+    if( 6 == result ) {
+        status->bStatus = buffer[0];
+        if (dif->quirks & QUIRK_POLLTIMEOUT)
+            status->bwPollTimeout = DEFAULT_POLLTIMEOUT;
+        else
+            status->bwPollTimeout = ((0xff & buffer[3]) << 16) |
+                                    ((0xff & buffer[2]) << 8)  |
+                                    (0xff & buffer[1]);
+        status->bState  = buffer[4];
+        status->iString = buffer[5];
+    }
+
+    return result;
+}
+
+
+/*
+ *  DFU_CLRSTATUS Request (DFU Spec 1.0, Section 6.1.3)
+ *
+ *  device    - the usb_dev_handle to communicate with
+ *  interface - the interface to communicate with
+ *
+ *  return 0 or < 0 on an error
+ */
+int dfu_clear_status( libusb_device_handle *device,
+                      const unsigned short interface )
+{
+    return libusb_control_transfer( device,
+        /* bmRequestType */ LIBUSB_ENDPOINT_OUT| LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
+        /* bRequest      */ DFU_CLRSTATUS,
+        /* wValue        */ 0,
+        /* wIndex        */ interface,
+        /* Data          */ NULL,
+        /* wLength       */ 0,
+                            dfu_timeout );
+}
+
+
+/*
+ *  DFU_GETSTATE Request (DFU Spec 1.0, Section 6.1.5)
+ *
+ *  device    - the usb_dev_handle to communicate with
+ *  interface - the interface to communicate with
+ *  length    - the maximum number of bytes to receive from the USB
+ *              device - must be less than wTransferSize
+ *  data      - the buffer to put the received data in
+ *
+ *  returns the state or < 0 on error
+ */
+int dfu_get_state( libusb_device_handle *device,
+                   const unsigned short interface )
+{
+    int result;
+    unsigned char buffer[1];
+
+    result = libusb_control_transfer( device,
+          /* bmRequestType */ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
+          /* bRequest      */ DFU_GETSTATE,
+          /* wValue        */ 0,
+          /* wIndex        */ interface,
+          /* Data          */ buffer,
+          /* wLength       */ 1,
+                              dfu_timeout );
+
+    /* Return the error if there is one. */
+    if (result < 1)
+	return -1;
+
+    /* Return the state. */
+    return buffer[0];
+}
+
+
+/*
+ *  DFU_ABORT Request (DFU Spec 1.0, Section 6.1.4)
+ *
+ *  device    - the usb_dev_handle to communicate with
+ *  interface - the interface to communicate with
+ *
+ *  returns 0 or < 0 on an error
+ */
+int dfu_abort( libusb_device_handle *device,
+               const unsigned short interface )
+{
+    return libusb_control_transfer( device,
+        /* bmRequestType */ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE,
+        /* bRequest      */ DFU_ABORT,
+        /* wValue        */ 0,
+        /* wIndex        */ interface,
+        /* Data          */ NULL,
+        /* wLength       */ 0,
+                            dfu_timeout );
+}
+
+
+const char* dfu_state_to_string( int state )
+{
+    const char *message;
+
+    switch (state) {
+        case STATE_APP_IDLE:
+            message = "appIDLE";
+            break;
+        case STATE_APP_DETACH:
+            message = "appDETACH";
+            break;
+        case STATE_DFU_IDLE:
+            message = "dfuIDLE";
+            break;
+        case STATE_DFU_DOWNLOAD_SYNC:
+            message = "dfuDNLOAD-SYNC";
+            break;
+        case STATE_DFU_DOWNLOAD_BUSY:
+            message = "dfuDNBUSY";
+            break;
+        case STATE_DFU_DOWNLOAD_IDLE:
+            message = "dfuDNLOAD-IDLE";
+            break;
+        case STATE_DFU_MANIFEST_SYNC:
+            message = "dfuMANIFEST-SYNC";
+            break;
+        case STATE_DFU_MANIFEST:
+            message = "dfuMANIFEST";
+            break;
+        case STATE_DFU_MANIFEST_WAIT_RESET:
+            message = "dfuMANIFEST-WAIT-RESET";
+            break;
+        case STATE_DFU_UPLOAD_IDLE:
+            message = "dfuUPLOAD-IDLE";
+            break;
+        case STATE_DFU_ERROR:
+            message = "dfuERROR";
+            break;
+        default:
+            message = NULL;
+            break;
+    }
+
+    return message;
+}
+
+/* Chapter 6.1.2 */
+static const char *dfu_status_names[] = {
+	/* DFU_STATUS_OK */
+		"No error condition is present",
+	/* DFU_STATUS_errTARGET */
+		"File is not targeted for use by this device",
+	/* DFU_STATUS_errFILE */
+		"File is for this device but fails some vendor-specific test",
+	/* DFU_STATUS_errWRITE */
+		"Device is unable to write memory",
+	/* DFU_STATUS_errERASE */
+		"Memory erase function failed",
+	/* DFU_STATUS_errCHECK_ERASED */
+		"Memory erase check failed",
+	/* DFU_STATUS_errPROG */
+		"Program memory function failed",
+	/* DFU_STATUS_errVERIFY */
+		"Programmed memory failed verification",
+	/* DFU_STATUS_errADDRESS */
+		"Cannot program memory due to received address that is out of range",
+	/* DFU_STATUS_errNOTDONE */
+		"Received DFU_DNLOAD with wLength = 0, but device does not think that it has all data yet",
+	/* DFU_STATUS_errFIRMWARE */
+		"Device's firmware is corrupt. It cannot return to run-time (non-DFU) operations",
+	/* DFU_STATUS_errVENDOR */
+		"iString indicates a vendor specific error",
+	/* DFU_STATUS_errUSBR */
+		"Device detected unexpected USB reset signalling",
+	/* DFU_STATUS_errPOR */
+		"Device detected unexpected power on reset",
+	/* DFU_STATUS_errUNKNOWN */
+		"Something went wrong, but the device does not know what it was",
+	/* DFU_STATUS_errSTALLEDPKT */
+		"Device stalled an unexpected request"
+};
+
+
+const char *dfu_status_to_string(int status)
+{
+	if (status > DFU_STATUS_errSTALLEDPKT)
+		return "INVALID";
+	return dfu_status_names[status];
+}
+
+int dfu_abort_to_idle(struct dfu_if *dif)
+{
+	int ret;
+	struct dfu_status dst;
+
+	ret = dfu_abort(dif->dev_handle, dif->interface);
+	if (ret < 0) {
+		errx(EX_IOERR, "Error sending dfu abort request");
+		exit(1);
+	}
+	ret = dfu_get_status(dif, &dst);
+	if (ret < 0) {
+		errx(EX_IOERR, "Error during abort get_status");
+		exit(1);
+	}
+	if (dst.bState != DFU_STATE_dfuIDLE) {
+		errx(EX_IOERR, "Failed to enter idle state on abort");
+		exit(1);
+	}
+	milli_sleep(dst.bwPollTimeout);
+	return ret;
+}

+ 133 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu.h

@@ -0,0 +1,133 @@
+/*
+ * dfu-programmer
+ *
+ * $Id: dfu.h,v 1.2 2005/09/25 01:27:42 schmidtw Exp $
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef DFU_H
+#define DFU_H
+
+#include <libusb.h>
+#include "usb_dfu.h"
+
+/* DFU states */
+#define STATE_APP_IDLE                  0x00
+#define STATE_APP_DETACH                0x01
+#define STATE_DFU_IDLE                  0x02
+#define STATE_DFU_DOWNLOAD_SYNC         0x03
+#define STATE_DFU_DOWNLOAD_BUSY         0x04
+#define STATE_DFU_DOWNLOAD_IDLE         0x05
+#define STATE_DFU_MANIFEST_SYNC         0x06
+#define STATE_DFU_MANIFEST              0x07
+#define STATE_DFU_MANIFEST_WAIT_RESET   0x08
+#define STATE_DFU_UPLOAD_IDLE           0x09
+#define STATE_DFU_ERROR                 0x0a
+
+
+/* DFU status */
+#define DFU_STATUS_OK                   0x00
+#define DFU_STATUS_ERROR_TARGET         0x01
+#define DFU_STATUS_ERROR_FILE           0x02
+#define DFU_STATUS_ERROR_WRITE          0x03
+#define DFU_STATUS_ERROR_ERASE          0x04
+#define DFU_STATUS_ERROR_CHECK_ERASED   0x05
+#define DFU_STATUS_ERROR_PROG           0x06
+#define DFU_STATUS_ERROR_VERIFY         0x07
+#define DFU_STATUS_ERROR_ADDRESS        0x08
+#define DFU_STATUS_ERROR_NOTDONE        0x09
+#define DFU_STATUS_ERROR_FIRMWARE       0x0a
+#define DFU_STATUS_ERROR_VENDOR         0x0b
+#define DFU_STATUS_ERROR_USBR           0x0c
+#define DFU_STATUS_ERROR_POR            0x0d
+#define DFU_STATUS_ERROR_UNKNOWN        0x0e
+#define DFU_STATUS_ERROR_STALLEDPKT     0x0f
+
+/* DFU commands */
+#define DFU_DETACH      0
+#define DFU_DNLOAD      1
+#define DFU_UPLOAD      2
+#define DFU_GETSTATUS   3
+#define DFU_CLRSTATUS   4
+#define DFU_GETSTATE    5
+#define DFU_ABORT       6
+
+/* DFU interface */
+#define DFU_IFF_DFU             0x0001  /* DFU Mode, (not Runtime) */
+
+/* This is based off of DFU_GETSTATUS
+ *
+ *  1 unsigned byte bStatus
+ *  3 unsigned byte bwPollTimeout
+ *  1 unsigned byte bState
+ *  1 unsigned byte iString
+*/
+
+struct dfu_status {
+    unsigned char bStatus;
+    unsigned int  bwPollTimeout;
+    unsigned char bState;
+    unsigned char iString;
+};
+
+struct dfu_if {
+    struct usb_dfu_func_descriptor func_dfu;
+    uint16_t quirks;
+    uint16_t busnum;
+    uint16_t devnum;
+    uint16_t vendor;
+    uint16_t product;
+    uint16_t bcdDevice;
+    uint8_t configuration;
+    uint8_t interface;
+    uint8_t altsetting;
+    uint8_t flags;
+    uint8_t bMaxPacketSize0;
+    char *alt_name;
+    char *serial_name;
+    libusb_device *dev;
+    libusb_device_handle *dev_handle;
+    struct dfu_if *next;
+};
+
+int dfu_detach( libusb_device_handle *device,
+                const unsigned short interface,
+                const unsigned short timeout );
+int dfu_download( libusb_device_handle *device,
+                  const unsigned short interface,
+                  const unsigned short length,
+                  const unsigned short transaction,
+                  unsigned char* data );
+int dfu_upload( libusb_device_handle *device,
+                const unsigned short interface,
+                const unsigned short length,
+                const unsigned short transaction,
+                unsigned char* data );
+int dfu_get_status( struct dfu_if *dif,
+                    struct dfu_status *status );
+int dfu_clear_status( libusb_device_handle *device,
+                      const unsigned short interface );
+int dfu_get_state( libusb_device_handle *device,
+                   const unsigned short interface );
+int dfu_abort( libusb_device_handle *device,
+               const unsigned short interface );
+int dfu_abort_to_idle( struct dfu_if *dif);
+
+const char *dfu_state_to_string( int state );
+
+const char *dfu_status_to_string( int status );
+
+#endif /* DFU_H */

+ 444 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_file.c

@@ -0,0 +1,444 @@
+/*
+ * Load or store DFU files including suffix and prefix
+ *
+ * Copyright 2014 Tormod Volden <debian.tormod@gmail.com>
+ * Copyright 2012 Stefan Schmidt <stefan@datenfreihafen.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <time.h>
+#include <fcntl.h>
+
+#include "portable.h"
+#include "dfu_file.h"
+
+#define DFU_SUFFIX_LENGTH 16
+#define LMDFU_PREFIX_LENGTH 8
+#define LPCDFU_PREFIX_LENGTH 16
+#define PROGRESS_BAR_WIDTH 25
+#define STDIN_CHUNK_SIZE 65536
+
+static const unsigned long crc32_table[] = {
+    0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+    0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+    0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+    0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+    0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+    0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+    0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
+    0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+    0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
+    0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+    0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
+    0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+    0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
+    0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+    0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+    0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+    0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
+    0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+    0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
+    0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+    0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
+    0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+    0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
+    0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+    0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+    0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+    0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
+    0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+    0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
+    0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+    0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
+    0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+    0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
+    0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+    0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+    0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+    0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
+    0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+    0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
+    0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+    0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
+    0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+    0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
+
+static uint32_t crc32_byte(uint32_t accum, uint8_t delta)
+{
+        return crc32_table[(accum ^ delta) & 0xff] ^ (accum >> 8);
+}
+
+static int probe_prefix(struct dfu_file *file)
+{
+	uint8_t *prefix = file->firmware;
+
+	if (file->size.total <  LMDFU_PREFIX_LENGTH)
+		return 1;
+	if ((prefix[0] == 0x01) && (prefix[1] == 0x00)) {
+		file->prefix_type = LMDFU_PREFIX;
+		file->size.prefix = LMDFU_PREFIX_LENGTH;
+		file->lmdfu_address = 1024 * ((prefix[3] << 8) | prefix[2]);
+	}
+	else if (((prefix[0] & 0x3f) == 0x1a) && ((prefix[1] & 0x3f)== 0x3f)) {
+		file->prefix_type = LPCDFU_UNENCRYPTED_PREFIX;
+		file->size.prefix = LPCDFU_PREFIX_LENGTH;
+	}
+
+	if (file->size.prefix + file->size.suffix > file->size.total)
+		return 1;
+	return 0;
+}
+
+void dfu_progress_bar(const char *desc, unsigned long long curr,
+		unsigned long long max)
+{
+	static char buf[PROGRESS_BAR_WIDTH + 1];
+	static unsigned long long last_progress = -1;
+	static time_t last_time;
+	time_t curr_time = time(NULL);
+	unsigned long long progress;
+	unsigned long long x;
+
+	/* check for not known maximum */
+	if (max < curr)
+		max = curr + 1;
+	/* make none out of none give zero */
+	if (max == 0 && curr == 0)
+		max = 1;
+
+	/* compute completion */
+	progress = (PROGRESS_BAR_WIDTH * curr) / max;
+	if (progress > PROGRESS_BAR_WIDTH)
+		progress = PROGRESS_BAR_WIDTH;
+	if (progress == last_progress &&
+	    curr_time == last_time)
+		return;
+	last_progress = progress;
+	last_time = curr_time;
+
+	for (x = 0; x != PROGRESS_BAR_WIDTH; x++) {
+		if (x < progress)
+			buf[x] = '=';
+		else
+			buf[x] = ' ';
+	}
+	buf[x] = 0;
+
+	printf("\r%s\t[%s] %3lld%% %12lld bytes", desc, buf,
+	    (100ULL * curr) / max, curr);
+
+	if (progress == PROGRESS_BAR_WIDTH)
+		printf("\n%s done.\n", desc);
+}
+
+void *dfu_malloc(size_t size)
+{
+	void *ptr = malloc(size);
+	if (ptr == NULL)
+		errx(EX_SOFTWARE, "Cannot allocate memory of size %d bytes", (int)size);
+	return (ptr);
+}
+
+uint32_t dfu_file_write_crc(int f, uint32_t crc, const void *buf, int size)
+{
+	int x;
+
+	/* compute CRC */
+	for (x = 0; x != size; x++)
+		crc = crc32_byte(crc, ((uint8_t *)buf)[x]);
+
+	/* write data */
+	if (write(f, buf, size) != size)
+		err(EX_IOERR, "Could not write %d bytes to file %d", size, f);
+
+	return (crc);
+}
+
+void dfu_load_file(struct dfu_file *file, enum suffix_req check_suffix, enum prefix_req check_prefix)
+{
+	off_t offset;
+	int f;
+	int i;
+	int res;
+
+	file->size.prefix = 0;
+	file->size.suffix = 0;
+
+	/* default values, if no valid suffix is found */
+	file->bcdDFU = 0;
+	file->idVendor = 0xffff; /* wildcard value */
+	file->idProduct = 0xffff; /* wildcard value */
+	file->bcdDevice = 0xffff; /* wildcard value */
+
+	/* default values, if no valid prefix is found */
+	file->lmdfu_address = 0;
+
+	free(file->firmware);
+
+	if (!strcmp(file->name, "-")) {
+		int read_bytes;
+
+#ifdef WIN32
+		_setmode( _fileno( stdin ), _O_BINARY );
+#endif
+		file->firmware = (uint8_t*) dfu_malloc(STDIN_CHUNK_SIZE);
+		read_bytes = fread(file->firmware, 1, STDIN_CHUNK_SIZE, stdin);
+		file->size.total = read_bytes;
+		while (read_bytes == STDIN_CHUNK_SIZE) {
+			file->firmware = (uint8_t*) realloc(file->firmware, file->size.total + STDIN_CHUNK_SIZE);
+			if (!file->firmware)
+				err(EX_IOERR, "Could not allocate firmware buffer");
+			read_bytes = fread(file->firmware + file->size.total, 1, STDIN_CHUNK_SIZE, stdin);
+			file->size.total += read_bytes;
+		}
+		if (verbose)
+			printf("Read %i bytes from stdin\n", file->size.total);
+		/* Never require suffix when reading from stdin */
+		check_suffix = MAYBE_SUFFIX;
+	} else {
+		f = open(file->name, O_RDONLY | O_BINARY);
+		if (f < 0)
+			err(EX_IOERR, "Could not open file %s for reading", file->name);
+
+		offset = lseek(f, 0, SEEK_END);
+
+		if ((int)offset < 0 || (int)offset != offset)
+			err(EX_IOERR, "File size is too big");
+
+		if (lseek(f, 0, SEEK_SET) != 0)
+			err(EX_IOERR, "Could not seek to beginning");
+
+		file->size.total = offset;
+		file->firmware = dfu_malloc(file->size.total);
+
+		if (read(f, file->firmware, file->size.total) != file->size.total) {
+			err(EX_IOERR, "Could not read %d bytes from %s",
+			    file->size.total, file->name);
+		}
+		close(f);
+	}
+
+	/* Check for possible DFU file suffix by trying to parse one */
+	{
+		uint32_t crc = 0xffffffff;
+		const uint8_t *dfusuffix;
+		int missing_suffix = 0;
+		const char *reason;
+
+		if (file->size.total < DFU_SUFFIX_LENGTH) {
+			reason = "File too short for DFU suffix";
+			missing_suffix = 1;
+			goto checked;
+		}
+
+		dfusuffix = file->firmware + file->size.total -
+		    DFU_SUFFIX_LENGTH;
+
+		for (i = 0; i < file->size.total - 4; i++)
+			crc = crc32_byte(crc, file->firmware[i]);
+
+		if (dfusuffix[10] != 'D' ||
+		    dfusuffix[9]  != 'F' ||
+		    dfusuffix[8]  != 'U') {
+			reason = "Invalid DFU suffix signature";
+			missing_suffix = 1;
+			goto checked;
+		}
+
+		file->dwCRC = (dfusuffix[15] << 24) +
+		    (dfusuffix[14] << 16) +
+		    (dfusuffix[13] << 8) +
+		    dfusuffix[12];
+
+		if (file->dwCRC != crc) {
+			reason = "DFU suffix CRC does not match";
+			missing_suffix = 1;
+			goto checked;
+		}
+
+		/* At this point we believe we have a DFU suffix
+		   so we require further checks to succeed */
+
+		file->bcdDFU = (dfusuffix[7] << 8) + dfusuffix[6];
+
+		if (verbose)
+			printf("DFU suffix version %x\n", file->bcdDFU);
+
+		file->size.suffix = dfusuffix[11];
+
+		if (file->size.suffix < DFU_SUFFIX_LENGTH) {
+			errx(EX_IOERR, "Unsupported DFU suffix length %d",
+			    file->size.suffix);
+		}
+
+		if (file->size.suffix > file->size.total) {
+			errx(EX_IOERR, "Invalid DFU suffix length %d",
+			    file->size.suffix);
+		}
+
+		file->idVendor	= (dfusuffix[5] << 8) + dfusuffix[4];
+		file->idProduct = (dfusuffix[3] << 8) + dfusuffix[2];
+		file->bcdDevice = (dfusuffix[1] << 8) + dfusuffix[0];
+
+checked:
+		if (missing_suffix) {
+			if (check_suffix == NEEDS_SUFFIX) {
+				warnx("%s", reason);
+				errx(EX_IOERR, "Valid DFU suffix needed");
+			} else if (check_suffix == MAYBE_SUFFIX) {
+				warnx("%s", reason);
+				warnx("A valid DFU suffix will be required in "
+				      "a future dfu-util release!!!");
+			}
+		} else {
+			if (check_suffix == NO_SUFFIX) {
+				errx(EX_SOFTWARE, "Please remove existing DFU suffix before adding a new one.\n");
+			}
+		}
+	}
+	res = probe_prefix(file);
+	if ((res || file->size.prefix == 0) && check_prefix == NEEDS_PREFIX)
+		errx(EX_IOERR, "Valid DFU prefix needed");
+	if (file->size.prefix && check_prefix == NO_PREFIX)
+		errx(EX_IOERR, "A prefix already exists, please delete it first");
+	if (file->size.prefix && verbose) {
+		uint8_t *data = file->firmware;
+		if (file->prefix_type == LMDFU_PREFIX)
+			printf("Possible TI Stellaris DFU prefix with "
+				   "the following properties\n"
+				   "Address:        0x%08x\n"
+				   "Payload length: %d\n",
+				   file->lmdfu_address,
+				   data[4] | (data[5] << 8) |
+				   (data[6] << 16) | (data[7] << 14));
+		else if (file->prefix_type == LPCDFU_UNENCRYPTED_PREFIX)
+			printf("Possible unencrypted NXP LPC DFU prefix with "
+				   "the following properties\n"
+				   "Payload length: %d kiByte\n",
+				   data[2] >>1 | (data[3] << 7) );
+		else
+			errx(EX_IOERR, "Unknown DFU prefix type");
+	}
+}
+
+void dfu_store_file(struct dfu_file *file, int write_suffix, int write_prefix)
+{
+	uint32_t crc = 0xffffffff;
+	int f;
+
+	f = open(file->name, O_WRONLY | O_BINARY | O_TRUNC | O_CREAT, 0666);
+	if (f < 0)
+		err(EX_IOERR, "Could not open file %s for writing", file->name);
+
+	/* write prefix, if any */
+	if (write_prefix) {
+		if (file->prefix_type == LMDFU_PREFIX) {
+			uint8_t lmdfu_prefix[LMDFU_PREFIX_LENGTH];
+			uint32_t addr = file->lmdfu_address / 1024;
+
+			/* lmdfu_dfu_prefix payload length excludes prefix and suffix */
+			uint32_t len = file->size.total -
+				file->size.prefix - file->size.suffix;
+
+			lmdfu_prefix[0] = 0x01; /* STELLARIS_DFU_PROG */
+			lmdfu_prefix[1] = 0x00; /* Reserved */
+			lmdfu_prefix[2] = (uint8_t)(addr & 0xff);
+			lmdfu_prefix[3] = (uint8_t)(addr >> 8);
+			lmdfu_prefix[4] = (uint8_t)(len & 0xff);
+			lmdfu_prefix[5] = (uint8_t)(len >> 8) & 0xff;
+			lmdfu_prefix[6] = (uint8_t)(len >> 16) & 0xff;
+			lmdfu_prefix[7] = (uint8_t)(len >> 24);
+
+			crc = dfu_file_write_crc(f, crc, lmdfu_prefix, LMDFU_PREFIX_LENGTH);
+		}
+		if (file->prefix_type == LPCDFU_UNENCRYPTED_PREFIX) {
+			uint8_t lpcdfu_prefix[LPCDFU_PREFIX_LENGTH] = {0};
+			int i;
+
+			/* Payload is firmware and prefix rounded to 512 bytes */
+			uint32_t len = (file->size.total - file->size.suffix + 511) /512;
+
+			lpcdfu_prefix[0] = 0x1a; /* Unencypted*/
+			lpcdfu_prefix[1] = 0x3f; /* Reserved */
+			lpcdfu_prefix[2] = (uint8_t)(len & 0xff);
+			lpcdfu_prefix[3] = (uint8_t)((len >> 8) & 0xff);
+			for (i = 12; i < LPCDFU_PREFIX_LENGTH; i++)
+				lpcdfu_prefix[i] = 0xff;
+
+			crc = dfu_file_write_crc(f, crc, lpcdfu_prefix, LPCDFU_PREFIX_LENGTH);
+		}
+	}
+	/* write firmware binary */
+	crc = dfu_file_write_crc(f, crc, file->firmware + file->size.prefix,
+	    file->size.total - file->size.prefix - file->size.suffix);
+
+	/* write suffix, if any */
+	if (write_suffix) {
+		uint8_t dfusuffix[DFU_SUFFIX_LENGTH];
+
+		dfusuffix[0] = file->bcdDevice & 0xff;
+		dfusuffix[1] = file->bcdDevice >> 8;
+		dfusuffix[2] = file->idProduct & 0xff;
+		dfusuffix[3] = file->idProduct >> 8;
+		dfusuffix[4] = file->idVendor & 0xff;
+		dfusuffix[5] = file->idVendor >> 8;
+		dfusuffix[6] = file->bcdDFU & 0xff;
+		dfusuffix[7] = file->bcdDFU >> 8;
+		dfusuffix[8] = 'U';
+		dfusuffix[9] = 'F';
+		dfusuffix[10] = 'D';
+		dfusuffix[11] = DFU_SUFFIX_LENGTH;
+
+		crc = dfu_file_write_crc(f, crc, dfusuffix,
+		    DFU_SUFFIX_LENGTH - 4);
+
+		dfusuffix[12] = crc;
+		dfusuffix[13] = crc >> 8;
+		dfusuffix[14] = crc >> 16;
+		dfusuffix[15] = crc >> 24;
+
+		crc = dfu_file_write_crc(f, crc, dfusuffix + 12, 4);
+	}
+	close(f);
+}
+
+void show_suffix_and_prefix(struct dfu_file *file)
+{
+	if (file->size.prefix == LMDFU_PREFIX_LENGTH) {
+		printf("The file %s contains a TI Stellaris DFU prefix with the following properties:\n", file->name);
+		printf("Address:\t0x%08x\n", file->lmdfu_address);
+	} else if (file->size.prefix == LPCDFU_PREFIX_LENGTH) {
+		uint8_t * prefix = file->firmware;
+		printf("The file %s contains a NXP unencrypted LPC DFU prefix with the following properties:\n", file->name);
+		printf("Size:\t%5d kiB\n", prefix[2]>>1|prefix[3]<<7);
+	} else if (file->size.prefix != 0) {
+		printf("The file %s contains an unknown prefix\n", file->name);
+	}
+	if (file->size.suffix > 0) {
+		printf("The file %s contains a DFU suffix with the following properties:\n", file->name);
+		printf("BCD device:\t0x%04X\n", file->bcdDevice);
+		printf("Product ID:\t0x%04X\n",file->idProduct);
+		printf("Vendor ID:\t0x%04X\n", file->idVendor);
+		printf("BCD DFU:\t0x%04X\n", file->bcdDFU);
+		printf("Length:\t\t%i\n", file->size.suffix);
+		printf("CRC:\t\t0x%08X\n", file->dwCRC);
+	}
+}

+ 60 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_file.h

@@ -0,0 +1,60 @@
+
+#ifndef DFU_FILE_H
+#define DFU_FILE_H
+
+#include <stdint.h>
+
+struct dfu_file {
+    /* File name */
+    const char *name;
+    /* Pointer to file loaded into memory */
+    uint8_t *firmware;
+    /* Different sizes */
+    struct {
+	int total;
+	int prefix;
+	int suffix;
+    } size;
+    /* From prefix fields */
+    uint32_t lmdfu_address;
+    /* From prefix fields */
+    uint32_t prefix_type;
+
+    /* From DFU suffix fields */
+    uint32_t dwCRC;
+    uint16_t bcdDFU;
+    uint16_t idVendor;
+    uint16_t idProduct;
+    uint16_t bcdDevice;
+};
+
+enum suffix_req {
+	NO_SUFFIX,
+	NEEDS_SUFFIX,
+	MAYBE_SUFFIX
+};
+
+enum prefix_req {
+	NO_PREFIX,
+	NEEDS_PREFIX,
+	MAYBE_PREFIX
+};
+
+enum prefix_type {
+	ZERO_PREFIX,
+	LMDFU_PREFIX,
+	LPCDFU_UNENCRYPTED_PREFIX
+};
+
+extern int verbose;
+
+void dfu_load_file(struct dfu_file *file, enum suffix_req check_suffix, enum prefix_req check_prefix);
+void dfu_store_file(struct dfu_file *file, int write_suffix, int write_prefix);
+
+void dfu_progress_bar(const char *desc, unsigned long long curr,
+		unsigned long long max);
+void *dfu_malloc(size_t size);
+uint32_t dfu_file_write_crc(int f, uint32_t crc, const void *buf, int size);
+void show_suffix_and_prefix(struct dfu_file *file);
+
+#endif /* DFU_FILE_H */

+ 197 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_load.c

@@ -0,0 +1,197 @@
+/*
+ * DFU transfer routines
+ *
+ * This is supposed to be a general DFU implementation, as specified in the
+ * USB DFU 1.0 and 1.1 specification.
+ *
+ * The code was originally intended to interface with a USB device running the
+ * "sam7dfu" firmware (see http://www.openpcd.org/) on an AT91SAM7 processor.
+ *
+ * Copyright 2007-2008 Harald Welte <laforge@gnumonks.org>
+ * Copyright 2013 Hans Petter Selasky <hps@bitfrost.no>
+ * Copyright 2014 Tormod Volden <debian.tormod@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#include <libusb.h>
+
+#include "portable.h"
+#include "dfu.h"
+#include "usb_dfu.h"
+#include "dfu_file.h"
+#include "dfu_load.h"
+#include "quirks.h"
+
+int dfuload_do_upload(struct dfu_if *dif, int xfer_size,
+    int expected_size, int fd)
+{
+	int total_bytes = 0;
+	unsigned short transaction = 0;
+	unsigned char *buf;
+	int ret;
+
+	buf = dfu_malloc(xfer_size);
+
+	printf("Copying data from DFU device to PC\n");
+
+	while (1) {
+		int rc;
+		dfu_progress_bar("Upload", total_bytes, expected_size);
+		rc = dfu_upload(dif->dev_handle, dif->interface,
+		    xfer_size, transaction++, buf);
+		if (rc < 0) {
+			warnx("\nError during upload");
+			ret = rc;
+			break;
+		}
+
+		dfu_file_write_crc(fd, 0, buf, rc);
+		total_bytes += rc;
+
+		if (total_bytes < 0)
+			errx(EX_SOFTWARE, "\nReceived too many bytes (wraparound)");
+
+		if (rc < xfer_size) {
+			/* last block, return */
+			ret = 0;
+			break;
+		}
+	}
+	free(buf);
+	if (ret == 0) {
+		dfu_progress_bar("Upload", total_bytes, total_bytes);
+	} else {
+		dfu_progress_bar("Upload", total_bytes, expected_size);
+		printf("\n");
+	}
+	if (total_bytes == 0)
+		printf("\nFailed.\n");
+	if (verbose)
+		printf("Received a total of %i bytes\n", total_bytes);
+	if (expected_size != 0 && total_bytes != expected_size)
+		errx(EX_SOFTWARE, "Unexpected number of bytes uploaded from device");
+	return ret;
+}
+
+int dfuload_do_dnload(struct dfu_if *dif, int xfer_size, struct dfu_file *file)
+{
+	int bytes_sent;
+	int expected_size;
+	unsigned char *buf;
+	unsigned short transaction = 0;
+	struct dfu_status dst;
+	int ret;
+
+	printf("Copying data from PC to DFU device\n");
+
+	buf = file->firmware;
+	expected_size = file->size.total - file->size.suffix;
+	bytes_sent = 0;
+
+	dfu_progress_bar("Download", 0, 1);
+	while (bytes_sent < expected_size) {
+		int bytes_left;
+		int chunk_size;
+
+		bytes_left = expected_size - bytes_sent;
+		if (bytes_left < xfer_size)
+			chunk_size = bytes_left;
+		else
+			chunk_size = xfer_size;
+
+		ret = dfu_download(dif->dev_handle, dif->interface,
+		    chunk_size, transaction++, chunk_size ? buf : NULL);
+		if (ret < 0) {
+			warnx("Error during download");
+			goto out;
+		}
+		bytes_sent += chunk_size;
+		buf += chunk_size;
+
+		do {
+			ret = dfu_get_status(dif, &dst);
+			if (ret < 0) {
+				errx(EX_IOERR, "Error during download get_status");
+				goto out;
+			}
+
+			if (dst.bState == DFU_STATE_dfuDNLOAD_IDLE ||
+					dst.bState == DFU_STATE_dfuERROR)
+				break;
+
+			/* Wait while device executes flashing */
+			milli_sleep(dst.bwPollTimeout);
+
+		} while (1);
+		if (dst.bStatus != DFU_STATUS_OK) {
+			printf(" failed!\n");
+			printf("state(%u) = %s, status(%u) = %s\n", dst.bState,
+				dfu_state_to_string(dst.bState), dst.bStatus,
+				dfu_status_to_string(dst.bStatus));
+			ret = -1;
+			goto out;
+		}
+		dfu_progress_bar("Download", bytes_sent, bytes_sent + bytes_left);
+	}
+
+	/* send one zero sized download request to signalize end */
+	ret = dfu_download(dif->dev_handle, dif->interface,
+	    0, transaction, NULL);
+	if (ret < 0) {
+		errx(EX_IOERR, "Error sending completion packet");
+		goto out;
+	}
+
+	dfu_progress_bar("Download", bytes_sent, bytes_sent);
+
+	if (verbose)
+		printf("Sent a total of %i bytes\n", bytes_sent);
+
+get_status:
+	/* Transition to MANIFEST_SYNC state */
+	ret = dfu_get_status(dif, &dst);
+	if (ret < 0) {
+		warnx("unable to read DFU status after completion");
+		goto out;
+	}
+	printf("state(%u) = %s, status(%u) = %s\n", dst.bState,
+		dfu_state_to_string(dst.bState), dst.bStatus,
+		dfu_status_to_string(dst.bStatus));
+
+	milli_sleep(dst.bwPollTimeout);
+
+	/* FIXME: deal correctly with ManifestationTolerant=0 / WillDetach bits */
+	switch (dst.bState) {
+	case DFU_STATE_dfuMANIFEST_SYNC:
+	case DFU_STATE_dfuMANIFEST:
+		/* some devices (e.g. TAS1020b) need some time before we
+		 * can obtain the status */
+		milli_sleep(1000);
+		goto get_status;
+		break;
+	case DFU_STATE_dfuIDLE:
+		break;
+	}
+	printf("Done!\n");
+
+out:
+	return bytes_sent;
+}

+ 7 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_load.h

@@ -0,0 +1,7 @@
+#ifndef DFU_LOAD_H
+#define DFU_LOAD_H
+
+int dfuload_do_upload(struct dfu_if *dif, int xfer_size, int expected_size, int fd);
+int dfuload_do_dnload(struct dfu_if *dif, int xfer_size, struct dfu_file *file);
+
+#endif /* DFU_LOAD_H */

+ 418 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_util.c

@@ -0,0 +1,418 @@
+/*
+ * Functions for detecting DFU USB entities
+ *
+ * Written by Harald Welte <laforge@openmoko.org>
+ * Copyright 2007-2008 by OpenMoko, Inc.
+ * Copyright 2013 Hans Petter Selasky <hps@bitfrost.no>
+ * Copyright 2016 Tormod Volden <debian.tormod@gmail.com>
+ *
+ * Based on existing code of dfu-programmer-0.4
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <libusb.h>
+
+#include "portable.h"
+#include "dfu.h"
+#include "usb_dfu.h"
+#include "dfu_file.h"
+#include "dfu_load.h"
+#include "dfu_util.h"
+#include "dfuse.h"
+#include "quirks.h"
+
+/*
+ * Look for a descriptor in a concatenated descriptor list. Will
+ * return upon the first match of the given descriptor type. Returns length of
+ * found descriptor, limited to res_size
+ */
+static int find_descriptor(const uint8_t *desc_list, int list_len,
+    uint8_t desc_type, void *res_buf, int res_size)
+{
+	int p = 0;
+
+	if (list_len < 2)
+		return (-1);
+
+	while (p + 1 < list_len) {
+		int desclen;
+
+		desclen = (int) desc_list[p];
+		if (desclen == 0) {
+			warnx("Invalid descriptor list");
+			return -1;
+		}
+		if (desc_list[p + 1] == desc_type) {
+			if (desclen > res_size)
+				desclen = res_size;
+			if (p + desclen > list_len)
+				desclen = list_len - p;
+			memcpy(res_buf, &desc_list[p], desclen);
+			return desclen;
+		}
+		p += (int) desc_list[p];
+	}
+	return -1;
+}
+
+/*
+ * Similar to libusb_get_string_descriptor_ascii but will allow
+ * truncated descriptors (descriptor length mismatch) seen on
+ * e.g. the STM32F427 ROM bootloader.
+ */
+static int get_string_descriptor_ascii(libusb_device_handle *devh,
+    uint8_t desc_index, unsigned char *data, int length)
+{
+	unsigned char tbuf[255];
+	uint16_t langid;
+	int r, di, si;
+
+	/* get the language IDs and pick the first one */
+	r = libusb_get_string_descriptor(devh, 0, 0, tbuf, sizeof(tbuf));
+	if (r < 0) {
+		warnx("Failed to retrieve language identifiers");
+		return r;
+	}
+	if (r < 4 || tbuf[0] < 4 || tbuf[1] != LIBUSB_DT_STRING) {		/* must have at least one ID */
+		warnx("Broken LANGID string descriptor");
+		return -1;
+	}
+	langid = tbuf[2] | (tbuf[3] << 8);
+
+	r = libusb_get_string_descriptor(devh, desc_index, langid, tbuf,
+					 sizeof(tbuf));
+	if (r < 0) {
+		warnx("Failed to retrieve string descriptor %d", desc_index);
+		return r;
+	}
+	if (tbuf[1] != LIBUSB_DT_STRING) {	/* sanity check */
+		warnx("Malformed string descriptor %d, type = 0x%02x", desc_index, tbuf[1]);
+		return -1;
+	}
+	if (tbuf[0] > r) {	/* if short read,           */
+		warnx("Patching string descriptor %d length (was %d, received %d)", desc_index, tbuf[0], r);
+		tbuf[0] = r;	/* fix up descriptor length */
+	}
+
+	/* convert from 16-bit unicode to ascii string */
+	for (di = 0, si = 2; si + 1 < tbuf[0] && di < length; si += 2) {
+		if (tbuf[si + 1])	/* high byte of unicode char */
+			data[di++] = '?';
+		else
+			data[di++] = tbuf[si];
+	}
+	data[di] = 0;
+	return di;
+}
+
+static void probe_configuration(libusb_device *dev, struct libusb_device_descriptor *desc)
+{
+	struct usb_dfu_func_descriptor func_dfu;
+	libusb_device_handle *devh;
+	struct dfu_if *pdfu;
+	struct libusb_config_descriptor *cfg;
+	const struct libusb_interface_descriptor *intf;
+	const struct libusb_interface *uif;
+	char alt_name[MAX_DESC_STR_LEN + 1];
+	char serial_name[MAX_DESC_STR_LEN + 1];
+	int cfg_idx;
+	int intf_idx;
+	int alt_idx;
+	int ret;
+	int has_dfu;
+
+	for (cfg_idx = 0; cfg_idx != desc->bNumConfigurations; cfg_idx++) {
+		memset(&func_dfu, 0, sizeof(func_dfu));
+		has_dfu = 0;
+
+		ret = libusb_get_config_descriptor(dev, cfg_idx, &cfg);
+		if (ret != 0)
+			return;
+		if (match_config_index > -1 && match_config_index != cfg->bConfigurationValue) {
+			libusb_free_config_descriptor(cfg);
+			continue;
+		}
+
+		/*
+		 * In some cases, noticably FreeBSD if uid != 0,
+		 * the configuration descriptors are empty
+		 */
+		if (!cfg)
+			return;
+
+		ret = find_descriptor(cfg->extra, cfg->extra_length,
+		    USB_DT_DFU, &func_dfu, sizeof(func_dfu));
+		if (ret > -1)
+			goto found_dfu;
+
+		for (intf_idx = 0; intf_idx < cfg->bNumInterfaces;
+		     intf_idx++) {
+			uif = &cfg->interface[intf_idx];
+			if (!uif)
+				break;
+
+			for (alt_idx = 0; alt_idx < cfg->interface[intf_idx].num_altsetting;
+			     alt_idx++) {
+				intf = &uif->altsetting[alt_idx];
+
+				if (intf->bInterfaceClass != 0xfe ||
+				    intf->bInterfaceSubClass != 1)
+					continue;
+
+				ret = find_descriptor(intf->extra, intf->extra_length, USB_DT_DFU,
+				      &func_dfu, sizeof(func_dfu));
+				if (ret > -1)
+					goto found_dfu;
+
+				has_dfu = 1;
+			}
+		}
+		if (has_dfu) {
+			/*
+			 * Finally try to retrieve it requesting the
+			 * device directly This is not supported on
+			 * all devices for non-standard types
+			 */
+			if (libusb_open(dev, &devh) == 0) {
+				ret = libusb_get_descriptor(devh, USB_DT_DFU, 0,
+				    (void *)&func_dfu, sizeof(func_dfu));
+				libusb_close(devh);
+				if (ret > -1)
+					goto found_dfu;
+			}
+			warnx("Device has DFU interface, "
+			    "but has no DFU functional descriptor");
+
+			/* fake version 1.0 */
+			func_dfu.bLength = 7;
+			func_dfu.bcdDFUVersion = libusb_cpu_to_le16(0x0100);
+			goto found_dfu;
+		}
+		libusb_free_config_descriptor(cfg);
+		continue;
+
+found_dfu:
+		if (func_dfu.bLength == 7) {
+			printf("Deducing device DFU version from functional descriptor "
+			    "length\n");
+			func_dfu.bcdDFUVersion = libusb_cpu_to_le16(0x0100);
+		} else if (func_dfu.bLength < 9) {
+			printf("Error obtaining DFU functional descriptor\n");
+			printf("Please report this as a bug!\n");
+			printf("Warning: Assuming DFU version 1.0\n");
+			func_dfu.bcdDFUVersion = libusb_cpu_to_le16(0x0100);
+			printf("Warning: Transfer size can not be detected\n");
+			func_dfu.wTransferSize = 0;
+		}
+
+		for (intf_idx = 0; intf_idx < cfg->bNumInterfaces;
+		     intf_idx++) {
+			if (match_iface_index > -1 && match_iface_index != intf_idx)
+				continue;
+
+			uif = &cfg->interface[intf_idx];
+			if (!uif)
+				break;
+
+			for (alt_idx = 0;
+			     alt_idx < uif->num_altsetting; alt_idx++) {
+				int dfu_mode;
+
+				intf = &uif->altsetting[alt_idx];
+
+				if (intf->bInterfaceClass != 0xfe ||
+				    intf->bInterfaceSubClass != 1)
+					continue;
+
+				dfu_mode = (intf->bInterfaceProtocol == 2);
+				/* e.g. DSO Nano has bInterfaceProtocol 0 instead of 2 */
+				if (func_dfu.bcdDFUVersion == 0x011a && intf->bInterfaceProtocol == 0)
+					dfu_mode = 1;
+
+				/* LPC DFU bootloader has bInterfaceProtocol 1 (Runtime) instead of 2 */
+				if (desc->idVendor == 0x1fc9 && desc->idProduct == 0x000c && intf->bInterfaceProtocol == 1)
+					dfu_mode = 1;
+
+				if (dfu_mode &&
+				    match_iface_alt_index > -1 && match_iface_alt_index != alt_idx)
+					continue;
+
+				if (dfu_mode) {
+					if ((match_vendor_dfu >= 0 && match_vendor_dfu != desc->idVendor) ||
+					    (match_product_dfu >= 0 && match_product_dfu != desc->idProduct)) {
+						continue;
+					}
+				} else {
+					if ((match_vendor >= 0 && match_vendor != desc->idVendor) ||
+					    (match_product >= 0 && match_product != desc->idProduct)) {
+						continue;
+					}
+				}
+
+				if (libusb_open(dev, &devh)) {
+					warnx("Cannot open DFU device %04x:%04x", desc->idVendor, desc->idProduct);
+					break;
+				}
+				if (intf->iInterface != 0)
+					ret = get_string_descriptor_ascii(devh,
+					    intf->iInterface, (void *)alt_name, MAX_DESC_STR_LEN);
+				else
+					ret = -1;
+				if (ret < 1)
+					strcpy(alt_name, "UNKNOWN");
+				if (desc->iSerialNumber != 0)
+					ret = get_string_descriptor_ascii(devh,
+					    desc->iSerialNumber, (void *)serial_name, MAX_DESC_STR_LEN);
+				else
+					ret = -1;
+				if (ret < 1)
+					strcpy(serial_name, "UNKNOWN");
+				libusb_close(devh);
+
+				if (dfu_mode &&
+				    match_iface_alt_name != NULL && strcmp(alt_name, match_iface_alt_name))
+					continue;
+
+				if (dfu_mode) {
+					if (match_serial_dfu != NULL && strcmp(match_serial_dfu, serial_name))
+						continue;
+				} else {
+					if (match_serial != NULL && strcmp(match_serial, serial_name))
+						continue;
+				}
+
+				pdfu = dfu_malloc(sizeof(*pdfu));
+
+				memset(pdfu, 0, sizeof(*pdfu));
+
+				pdfu->func_dfu = func_dfu;
+				pdfu->dev = libusb_ref_device(dev);
+				pdfu->quirks = get_quirks(desc->idVendor,
+				    desc->idProduct, desc->bcdDevice);
+				pdfu->vendor = desc->idVendor;
+				pdfu->product = desc->idProduct;
+				pdfu->bcdDevice = desc->bcdDevice;
+				pdfu->configuration = cfg->bConfigurationValue;
+				pdfu->interface = intf->bInterfaceNumber;
+				pdfu->altsetting = intf->bAlternateSetting;
+				pdfu->devnum = libusb_get_device_address(dev);
+				pdfu->busnum = libusb_get_bus_number(dev);
+				pdfu->alt_name = strdup(alt_name);
+				if (pdfu->alt_name == NULL)
+					errx(EX_SOFTWARE, "Out of memory");
+				pdfu->serial_name = strdup(serial_name);
+				if (pdfu->serial_name == NULL)
+					errx(EX_SOFTWARE, "Out of memory");
+				if (dfu_mode)
+					pdfu->flags |= DFU_IFF_DFU;
+				if (pdfu->quirks & QUIRK_FORCE_DFU11) {
+					pdfu->func_dfu.bcdDFUVersion =
+					  libusb_cpu_to_le16(0x0110);
+				}
+				pdfu->bMaxPacketSize0 = desc->bMaxPacketSize0;
+
+				/* queue into list */
+				pdfu->next = dfu_root;
+				dfu_root = pdfu;
+			}
+		}
+		libusb_free_config_descriptor(cfg);
+	}
+}
+
+#define MAX_PATH_LEN 20
+char path_buf[MAX_PATH_LEN];
+
+char *get_path(libusb_device *dev)
+{
+#if (defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102) || (defined(LIBUSBX_API_VERSION) && LIBUSBX_API_VERSION >= 0x01000102)
+	uint8_t path[8];
+	int r,j;
+	r = libusb_get_port_numbers(dev, path, sizeof(path));
+	if (r > 0) {
+		sprintf(path_buf,"%d-%d",libusb_get_bus_number(dev),path[0]);
+		for (j = 1; j < r; j++){
+			sprintf(path_buf+strlen(path_buf),".%d",path[j]);
+		};
+	}
+	return path_buf;
+#else
+# warning "libusb too old - building without USB path support!"
+	return NULL;
+#endif
+}
+
+void probe_devices(libusb_context *ctx)
+{
+	libusb_device **list;
+	ssize_t num_devs;
+	ssize_t i;
+
+	num_devs = libusb_get_device_list(ctx, &list);
+	for (i = 0; i < num_devs; ++i) {
+		struct libusb_device_descriptor desc;
+		struct libusb_device *dev = list[i];
+
+		if (match_path != NULL && strcmp(get_path(dev),match_path) != 0)
+			continue;
+		if (libusb_get_device_descriptor(dev, &desc))
+			continue;
+		probe_configuration(dev, &desc);
+	}
+	libusb_free_device_list(list, 0);
+}
+
+void disconnect_devices(void)
+{
+	struct dfu_if *pdfu;
+	struct dfu_if *prev = NULL;
+
+	for (pdfu = dfu_root; pdfu != NULL; pdfu = pdfu->next) {
+		free(prev);
+		libusb_unref_device(pdfu->dev);
+		free(pdfu->alt_name);
+		free(pdfu->serial_name);
+		prev = pdfu;
+	}
+	free(prev);
+	dfu_root = NULL;
+}
+
+void print_dfu_if(struct dfu_if *dfu_if)
+{
+	printf("Found %s: [%04x:%04x] ver=%04x, devnum=%u, cfg=%u, intf=%u, "
+	       "path=\"%s\", alt=%u, name=\"%s\", serial=\"%s\"\n",
+	       dfu_if->flags & DFU_IFF_DFU ? "DFU" : "Runtime",
+	       dfu_if->vendor, dfu_if->product,
+	       dfu_if->bcdDevice, dfu_if->devnum,
+	       dfu_if->configuration, dfu_if->interface,
+	       get_path(dfu_if->dev),
+	       dfu_if->altsetting, dfu_if->alt_name,
+	       dfu_if->serial_name);
+}
+
+/* Walk the device tree and print out DFU devices */
+void list_dfu_interfaces(void)
+{
+	struct dfu_if *pdfu;
+
+	for (pdfu = dfu_root; pdfu != NULL; pdfu = pdfu->next)
+		print_dfu_if(pdfu);
+}

+ 35 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfu_util.h

@@ -0,0 +1,35 @@
+#ifndef DFU_UTIL_H
+#define DFU_UTIL_H
+
+/* USB string descriptor should contain max 126 UTF-16 characters
+ * but 253 would even accomodate any UTF-8 encoding */
+#define MAX_DESC_STR_LEN 253
+
+enum mode {
+	MODE_NONE,
+	MODE_VERSION,
+	MODE_LIST,
+	MODE_DETACH,
+	MODE_UPLOAD,
+	MODE_DOWNLOAD
+};
+
+extern struct dfu_if *dfu_root;
+extern char *match_path;
+extern int match_vendor;
+extern int match_product;
+extern int match_vendor_dfu;
+extern int match_product_dfu;
+extern int match_config_index;
+extern int match_iface_index;
+extern int match_iface_alt_index;
+extern const char *match_iface_alt_name;
+extern const char *match_serial;
+extern const char *match_serial_dfu;
+
+void probe_devices(libusb_context *);
+void disconnect_devices(void);
+void print_dfu_if(struct dfu_if *);
+void list_dfu_interfaces(void);
+
+#endif /* DFU_UTIL_H */

+ 672 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfuse.c

@@ -0,0 +1,672 @@
+/*
+ * DfuSe specific functions
+ * 
+ * This implements the ST Microsystems DFU extensions (DfuSe)
+ * as per the DfuSe 1.1a specification (ST documents AN3156, AN2606)
+ * The DfuSe file format is described in ST document UM0391.
+ *
+ * Copyright 2010-2016 Tormod Volden <debian.tormod@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#include "portable.h"
+#include "dfu.h"
+#include "usb_dfu.h"
+#include "dfu_file.h"
+#include "dfuse.h"
+#include "dfuse_mem.h"
+
+#define DFU_TIMEOUT 5000
+
+extern int verbose;
+static unsigned int last_erased_page = 1; /* non-aligned value, won't match */
+static struct memsegment *mem_layout;
+static unsigned int dfuse_address = 0;
+static unsigned int dfuse_length = 0;
+static int dfuse_force = 0;
+static int dfuse_leave = 0;
+static int dfuse_unprotect = 0;
+static int dfuse_mass_erase = 0;
+
+unsigned int quad2uint(unsigned char *p)
+{
+	return (*p + (*(p + 1) << 8) + (*(p + 2) << 16) + (*(p + 3) << 24));
+}
+
+void dfuse_parse_options(const char *options)
+{
+	char *end;
+	const char *endword;
+	unsigned int number;
+
+	/* address, possibly empty, must be first */
+	if (*options != ':') {
+		endword = strchr(options, ':');
+		if (!endword)
+			endword = options + strlen(options); /* GNU strchrnul */
+
+		number = strtoul(options, &end, 0);
+		if (end == endword) {
+			dfuse_address = number;
+		} else {
+			errx(EX_IOERR, "Invalid dfuse address: %s", options);
+		}
+		options = endword;
+	}
+
+	while (*options) {
+		if (*options == ':') {
+			options++;
+			continue;
+		}
+		endword = strchr(options, ':');
+		if (!endword)
+			endword = options + strlen(options);
+
+		if (!strncmp(options, "force", endword - options)) {
+			dfuse_force++;
+			options += 5;
+			continue;
+		}
+		if (!strncmp(options, "leave", endword - options)) {
+			dfuse_leave = 1;
+			options += 5;
+			continue;
+		}
+		if (!strncmp(options, "unprotect", endword - options)) {
+			dfuse_unprotect = 1;
+			options += 9;
+			continue;
+		}
+		if (!strncmp(options, "mass-erase", endword - options)) {
+			dfuse_mass_erase = 1;
+			options += 10;
+			continue;
+		}
+
+		/* any valid number is interpreted as upload length */
+		number = strtoul(options, &end, 0);
+		if (end == endword) {
+			dfuse_length = number;
+		} else {
+			errx(EX_IOERR, "Invalid dfuse modifier: %s", options);
+		}
+		options = endword;
+	}
+}
+
+/* DFU_UPLOAD request for DfuSe 1.1a */
+int dfuse_upload(struct dfu_if *dif, const unsigned short length,
+		 unsigned char *data, unsigned short transaction)
+{
+	int status;
+
+	status = libusb_control_transfer(dif->dev_handle,
+		 /* bmRequestType */	 LIBUSB_ENDPOINT_IN |
+					 LIBUSB_REQUEST_TYPE_CLASS |
+					 LIBUSB_RECIPIENT_INTERFACE,
+		 /* bRequest      */	 DFU_UPLOAD,
+		 /* wValue        */	 transaction,
+		 /* wIndex        */	 dif->interface,
+		 /* Data          */	 data,
+		 /* wLength       */	 length,
+					 DFU_TIMEOUT);
+	if (status < 0) {
+		errx(EX_IOERR, "%s: libusb_control_msg returned %d",
+			__FUNCTION__, status);
+	}
+	return status;
+}
+
+/* DFU_DNLOAD request for DfuSe 1.1a */
+int dfuse_download(struct dfu_if *dif, const unsigned short length,
+		   unsigned char *data, unsigned short transaction)
+{
+	int status;
+
+	status = libusb_control_transfer(dif->dev_handle,
+		 /* bmRequestType */	 LIBUSB_ENDPOINT_OUT |
+					 LIBUSB_REQUEST_TYPE_CLASS |
+					 LIBUSB_RECIPIENT_INTERFACE,
+		 /* bRequest      */	 DFU_DNLOAD,
+		 /* wValue        */	 transaction,
+		 /* wIndex        */	 dif->interface,
+		 /* Data          */	 data,
+		 /* wLength       */	 length,
+					 DFU_TIMEOUT);
+	if (status < 0) {
+		errx(EX_IOERR, "%s: libusb_control_transfer returned %d",
+			__FUNCTION__, status);
+	}
+	return status;
+}
+
+/* DfuSe only commands */
+/* Leaves the device in dfuDNLOAD-IDLE state */
+int dfuse_special_command(struct dfu_if *dif, unsigned int address,
+			  enum dfuse_command command)
+{
+	const char* dfuse_command_name[] = { "SET_ADDRESS" , "ERASE_PAGE",
+					     "MASS_ERASE", "READ_UNPROTECT"};
+	unsigned char buf[5];
+	int length;
+	int ret;
+	struct dfu_status dst;
+	int firstpoll = 1;
+
+	if (command == ERASE_PAGE) {
+		struct memsegment *segment;
+		int page_size;
+
+		segment = find_segment(mem_layout, address);
+		if (!segment || !(segment->memtype & DFUSE_ERASABLE)) {
+			errx(EX_IOERR, "Page at 0x%08x can not be erased",
+				address);
+		}
+		page_size = segment->pagesize;
+		if (verbose > 1)
+			printf("Erasing page size %i at address 0x%08x, page "
+			       "starting at 0x%08x\n", page_size, address,
+			       address & ~(page_size - 1));
+		buf[0] = 0x41;	/* Erase command */
+		length = 5;
+		last_erased_page = address & ~(page_size - 1);
+	} else if (command == SET_ADDRESS) {
+		if (verbose > 2)
+			printf("  Setting address pointer to 0x%08x\n",
+			       address);
+		buf[0] = 0x21;	/* Set Address Pointer command */
+		length = 5;
+	} else if (command == MASS_ERASE) {
+		buf[0] = 0x41;	/* Mass erase command when length = 1 */
+		length = 1;
+	} else if (command == READ_UNPROTECT) {
+		buf[0] = 0x92;
+		length = 1;
+	} else {
+		errx(EX_IOERR, "Non-supported special command %d", command);
+	}
+	buf[1] = address & 0xff;
+	buf[2] = (address >> 8) & 0xff;
+	buf[3] = (address >> 16) & 0xff;
+	buf[4] = (address >> 24) & 0xff;
+
+	ret = dfuse_download(dif, length, buf, 0);
+	if (ret < 0) {
+		errx(EX_IOERR, "Error during special command \"%s\" download",
+			dfuse_command_name[command]);
+	}
+	do {
+		ret = dfu_get_status(dif, &dst);
+		if (ret < 0) {
+			errx(EX_IOERR, "Error during special command \"%s\" get_status",
+			     dfuse_command_name[command]);
+		}
+		if (firstpoll) {
+			firstpoll = 0;
+			if (dst.bState != DFU_STATE_dfuDNBUSY) {
+				printf("state(%u) = %s, status(%u) = %s\n", dst.bState,
+				       dfu_state_to_string(dst.bState), dst.bStatus,
+				       dfu_status_to_string(dst.bStatus));
+				errx(EX_IOERR, "Wrong state after command \"%s\" download",
+				     dfuse_command_name[command]);
+			}
+			/* STM32F405 lies about mass erase timeout */
+			if (command == MASS_ERASE && dst.bwPollTimeout == 100) {
+				dst.bwPollTimeout = 35000;
+				printf("Setting timeout to 35 seconds\n");
+			}
+		}
+		/* wait while command is executed */
+		if (verbose)
+			printf("   Poll timeout %i ms\n", dst.bwPollTimeout);
+		milli_sleep(dst.bwPollTimeout);
+		if (command == READ_UNPROTECT)
+			return ret;
+	} while (dst.bState == DFU_STATE_dfuDNBUSY);
+
+	if (dst.bStatus != DFU_STATUS_OK) {
+		errx(EX_IOERR, "%s not correctly executed",
+			dfuse_command_name[command]);
+	}
+	return ret;
+}
+
+int dfuse_dnload_chunk(struct dfu_if *dif, unsigned char *data, int size,
+		       int transaction)
+{
+	int bytes_sent;
+	struct dfu_status dst;
+	int ret;
+
+	ret = dfuse_download(dif, size, size ? data : NULL, transaction);
+	if (ret < 0) {
+		errx(EX_IOERR, "Error during download");
+		return ret;
+	}
+	bytes_sent = ret;
+
+	do {
+		ret = dfu_get_status(dif, &dst);
+		if (ret < 0) {
+			errx(EX_IOERR, "Error during download get_status");
+			return ret;
+		}
+		milli_sleep(dst.bwPollTimeout);
+	} while (dst.bState != DFU_STATE_dfuDNLOAD_IDLE &&
+		 dst.bState != DFU_STATE_dfuERROR &&
+		 dst.bState != DFU_STATE_dfuMANIFEST);
+
+	if (dst.bState == DFU_STATE_dfuMANIFEST)
+			printf("Transitioning to dfuMANIFEST state\n");
+
+	if (dst.bStatus != DFU_STATUS_OK) {
+		printf(" failed!\n");
+		printf("state(%u) = %s, status(%u) = %s\n", dst.bState,
+		       dfu_state_to_string(dst.bState), dst.bStatus,
+		       dfu_status_to_string(dst.bStatus));
+		return -1;
+	}
+	return bytes_sent;
+}
+
+int dfuse_do_upload(struct dfu_if *dif, int xfer_size, int fd,
+		    const char *dfuse_options)
+{
+	int total_bytes = 0;
+	int upload_limit = 0;
+	unsigned char *buf;
+	int transaction;
+	int ret;
+
+	buf = dfu_malloc(xfer_size);
+
+	if (dfuse_options)
+		dfuse_parse_options(dfuse_options);
+	if (dfuse_length)
+		upload_limit = dfuse_length;
+	if (dfuse_address) {
+		struct memsegment *segment;
+
+		mem_layout = parse_memory_layout((char *)dif->alt_name);
+		if (!mem_layout)
+			errx(EX_IOERR, "Failed to parse memory layout");
+
+		segment = find_segment(mem_layout, dfuse_address);
+		if (!dfuse_force &&
+		    (!segment || !(segment->memtype & DFUSE_READABLE)))
+			errx(EX_IOERR, "Page at 0x%08x is not readable",
+				dfuse_address);
+
+		if (!upload_limit) {
+			upload_limit = segment->end - dfuse_address + 1;
+			printf("Limiting upload to end of memory segment, "
+			       "%i bytes\n", upload_limit);
+		}
+		dfuse_special_command(dif, dfuse_address, SET_ADDRESS);
+		dfu_abort_to_idle(dif);
+	} else {
+		/* Boot loader decides the start address, unknown to us */
+		/* Use a short length to lower risk of running out of bounds */
+		if (!upload_limit)
+			upload_limit = 0x4000;
+		printf("Limiting default upload to %i bytes\n", upload_limit);
+	}
+
+	dfu_progress_bar("Upload", 0, 1);
+
+	transaction = 2;
+	while (1) {
+		int rc;
+
+		/* last chunk can be smaller than original xfer_size */
+		if (upload_limit - total_bytes < xfer_size)
+			xfer_size = upload_limit - total_bytes;
+		rc = dfuse_upload(dif, xfer_size, buf, transaction++);
+		if (rc < 0) {
+			ret = rc;
+			goto out_free;
+		}
+
+		dfu_file_write_crc(fd, 0, buf, rc);
+		total_bytes += rc;
+
+		if (total_bytes < 0)
+			errx(EX_SOFTWARE, "Received too many bytes");
+
+		if (rc < xfer_size || total_bytes >= upload_limit) {
+			/* last block, return successfully */
+			ret = total_bytes;
+			break;
+		}
+		dfu_progress_bar("Upload", total_bytes, upload_limit);
+	}
+
+	dfu_progress_bar("Upload", total_bytes, total_bytes);
+
+	dfu_abort_to_idle(dif);
+	if (dfuse_leave) {
+		dfuse_special_command(dif, dfuse_address, SET_ADDRESS);
+		dfuse_dnload_chunk(dif, NULL, 0, 2); /* Zero-size */
+	}
+
+ out_free:
+	free(buf);
+
+	return ret;
+}
+
+/* Writes an element of any size to the device, taking care of page erases */
+/* returns 0 on success, otherwise -EINVAL */
+int dfuse_dnload_element(struct dfu_if *dif, unsigned int dwElementAddress,
+			 unsigned int dwElementSize, unsigned char *data,
+			 int xfer_size)
+{
+	int p;
+	int ret;
+	struct memsegment *segment;
+
+	/* Check at least that we can write to the last address */
+	segment =
+	    find_segment(mem_layout, dwElementAddress + dwElementSize - 1);
+	if (!segment || !(segment->memtype & DFUSE_WRITEABLE)) {
+		errx(EX_IOERR, "Last page at 0x%08x is not writeable",
+			dwElementAddress + dwElementSize - 1);
+	}
+
+	dfu_progress_bar("Download", 0, 1);
+
+	/* First pass: Erase involved pages if needed */
+	for (p = 0; p < (int)dwElementSize; p += xfer_size) {
+		int page_size;
+		unsigned int erase_address;
+		unsigned int address = dwElementAddress + p;
+		int chunk_size = xfer_size;
+
+		segment = find_segment(mem_layout, address);
+		if (!segment || !(segment->memtype & DFUSE_WRITEABLE)) {
+			errx(EX_IOERR, "Page at 0x%08x is not writeable",
+				address);
+		}
+		page_size = segment->pagesize;
+
+		/* check if this is the last chunk */
+		if (p + chunk_size > (int)dwElementSize)
+			chunk_size = dwElementSize - p;
+
+		/* Erase only for flash memory downloads */
+		if ((segment->memtype & DFUSE_ERASABLE) && !dfuse_mass_erase) {
+			/* erase all involved pages */
+			for (erase_address = address;
+			     erase_address < address + chunk_size;
+			     erase_address += page_size)
+				if ((erase_address & ~(page_size - 1)) !=
+				    last_erased_page)
+					dfuse_special_command(dif,
+							      erase_address,
+							      ERASE_PAGE);
+
+			if (((address + chunk_size - 1) & ~(page_size - 1)) !=
+			    last_erased_page) {
+				if (verbose > 2)
+					printf(" Chunk extends into next page,"
+					       " erase it as well\n");
+				dfuse_special_command(dif,
+						      address + chunk_size - 1,
+						      ERASE_PAGE);
+			}
+		}
+	}
+
+	/* Second pass: Write data to (erased) pages */
+	for (p = 0; p < (int)dwElementSize; p += xfer_size) {
+		unsigned int address = dwElementAddress + p;
+		int chunk_size = xfer_size;
+
+		/* check if this is the last chunk */
+		if (p + chunk_size > (int)dwElementSize)
+			chunk_size = dwElementSize - p;
+
+		if (verbose) {
+			printf(" Download from image offset "
+			       "%08x to memory %08x-%08x, size %i\n",
+			       p, address, address + chunk_size - 1,
+			       chunk_size);
+		} else {
+			dfu_progress_bar("Download", p, dwElementSize);
+		}
+		
+		dfuse_special_command(dif, address, SET_ADDRESS);
+
+		/* transaction = 2 for no address offset */
+		ret = dfuse_dnload_chunk(dif, data + p, chunk_size, 2);
+		if (ret != chunk_size) {
+			errx(EX_IOERR, "Failed to write whole chunk: "
+				"%i of %i bytes", ret, chunk_size);
+			return -EINVAL;
+		}
+	}
+	if (!verbose)
+		dfu_progress_bar("Download", dwElementSize, dwElementSize);
+	return 0;
+}
+
+static void
+dfuse_memcpy(unsigned char *dst, unsigned char **src, int *rem, int size)
+{
+	if (size > *rem) {
+		errx(EX_IOERR, "Corrupt DfuSe file: "
+		    "Cannot read %d bytes from %d bytes", size, *rem);
+	}
+	if (dst != NULL)
+		memcpy(dst, *src, size);
+	(*src) += size;
+	(*rem) -= size;
+}
+
+/* Download raw binary file to DfuSe device */
+int dfuse_do_bin_dnload(struct dfu_if *dif, int xfer_size,
+			struct dfu_file *file, unsigned int start_address)
+{
+	unsigned int dwElementAddress;
+	unsigned int dwElementSize;
+	unsigned char *data;
+	int ret;
+
+	dwElementAddress = start_address;
+	dwElementSize = file->size.total -
+	    file->size.suffix - file->size.prefix;
+
+	printf("Downloading to address = 0x%08x, size = %i\n",
+	       dwElementAddress, dwElementSize);
+
+	data = file->firmware + file->size.prefix;
+
+	ret = dfuse_dnload_element(dif, dwElementAddress, dwElementSize, data,
+				   xfer_size);
+	if (ret != 0)
+		goto out_free;
+
+	printf("File downloaded successfully\n");
+	ret = dwElementSize;
+
+ out_free:
+	return ret;
+}
+
+/* Parse a DfuSe file and download contents to device */
+int dfuse_do_dfuse_dnload(struct dfu_if *dif, int xfer_size,
+			  struct dfu_file *file)
+{
+	uint8_t dfuprefix[11];
+	uint8_t targetprefix[274];
+	uint8_t elementheader[8];
+	int image;
+	int element;
+	int bTargets;
+	int bAlternateSetting;
+	int dwNbElements;
+	unsigned int dwElementAddress;
+	unsigned int dwElementSize;
+	uint8_t *data;
+	int ret;
+	int rem;
+	int bFirstAddressSaved = 0;
+
+	rem = file->size.total - file->size.prefix - file->size.suffix;
+	data = file->firmware + file->size.prefix;
+
+        /* Must be larger than a minimal DfuSe header and suffix */
+	if (rem < (int)(sizeof(dfuprefix) +
+	    sizeof(targetprefix) + sizeof(elementheader))) {
+		errx(EX_SOFTWARE, "File too small for a DfuSe file");
+        }
+
+	dfuse_memcpy(dfuprefix, &data, &rem, sizeof(dfuprefix));
+
+	if (strncmp((char *)dfuprefix, "DfuSe", 5)) {
+		errx(EX_IOERR, "No valid DfuSe signature");
+		return -EINVAL;
+	}
+	if (dfuprefix[5] != 0x01) {
+		errx(EX_IOERR, "DFU format revision %i not supported",
+			dfuprefix[5]);
+		return -EINVAL;
+	}
+	bTargets = dfuprefix[10];
+	printf("file contains %i DFU images\n", bTargets);
+
+	for (image = 1; image <= bTargets; image++) {
+		printf("parsing DFU image %i\n", image);
+		dfuse_memcpy(targetprefix, &data, &rem, sizeof(targetprefix));
+		if (strncmp((char *)targetprefix, "Target", 6)) {
+			errx(EX_IOERR, "No valid target signature");
+			return -EINVAL;
+		}
+		bAlternateSetting = targetprefix[6];
+		if (targetprefix[7])
+			printf("Target name: %s\n", &targetprefix[11]);
+		else
+			printf("No target name\n");
+		dwNbElements = quad2uint((unsigned char *)targetprefix + 270);
+		printf("image for alternate setting %i, ", bAlternateSetting);
+		printf("(%i elements, ", dwNbElements);
+		printf("total size = %i)\n",
+		       quad2uint((unsigned char *)targetprefix + 266));
+		if (bAlternateSetting != dif->altsetting)
+			printf("Warning: Image does not match current alternate"
+			       " setting.\n"
+			       "Please rerun with the correct -a option setting"
+			       " to download this image!\n");
+		for (element = 1; element <= dwNbElements; element++) {
+			printf("parsing element %i, ", element);
+			dfuse_memcpy(elementheader, &data, &rem, sizeof(elementheader));
+			dwElementAddress =
+			    quad2uint((unsigned char *)elementheader);
+			dwElementSize =
+			    quad2uint((unsigned char *)elementheader + 4);
+			printf("address = 0x%08x, ", dwElementAddress);
+			printf("size = %i\n", dwElementSize);
+
+			if (!bFirstAddressSaved) {
+				bFirstAddressSaved = 1;
+				dfuse_address = dwElementAddress;
+			}
+			/* sanity check */
+			if ((int)dwElementSize > rem)
+				errx(EX_SOFTWARE, "File too small for element size");
+
+			if (bAlternateSetting == dif->altsetting) {
+				ret = dfuse_dnload_element(dif, dwElementAddress,
+				    dwElementSize, data, xfer_size);
+			} else {
+				ret = 0;
+			}
+
+			/* advance read pointer */
+			dfuse_memcpy(NULL, &data, &rem, dwElementSize);
+
+			if (ret != 0)
+				return ret;
+		}
+	}
+
+	if (rem != 0)
+		warnx("%d bytes leftover", rem);
+
+	printf("done parsing DfuSe file\n");
+
+	return 0;
+}
+
+int dfuse_do_dnload(struct dfu_if *dif, int xfer_size, struct dfu_file *file,
+		    const char *dfuse_options)
+{
+	int ret;
+
+	if (dfuse_options)
+		dfuse_parse_options(dfuse_options);
+	mem_layout = parse_memory_layout((char *)dif->alt_name);
+	if (!mem_layout) {
+		errx(EX_IOERR, "Failed to parse memory layout");
+	}
+	if (dfuse_unprotect) {
+		if (!dfuse_force) {
+			errx(EX_IOERR, "The read unprotect command "
+				"will erase the flash memory"
+				"and can only be used with force\n");
+		}
+		dfuse_special_command(dif, 0, READ_UNPROTECT);
+		printf("Device disconnects, erases flash and resets now\n");
+		exit(0);
+	}
+	if (dfuse_mass_erase) {
+		if (!dfuse_force) {
+			errx(EX_IOERR, "The mass erase command "
+				"can only be used with force");
+		}
+		printf("Performing mass erase, this can take a moment\n");
+		dfuse_special_command(dif, 0, MASS_ERASE);
+	}
+	if (dfuse_address) {
+		if (file->bcdDFU == 0x11a) {
+			errx(EX_IOERR, "This is a DfuSe file, not "
+				"meant for raw download");
+		}
+		ret = dfuse_do_bin_dnload(dif, xfer_size, file, dfuse_address);
+	} else {
+		if (file->bcdDFU != 0x11a) {
+			warnx("Only DfuSe file version 1.1a is supported");
+			errx(EX_IOERR, "(for raw binary download, use the "
+			     "--dfuse-address option)");
+		}
+		ret = dfuse_do_dfuse_dnload(dif, xfer_size, file);
+	}
+	free_segment_list(mem_layout);
+
+	dfu_abort_to_idle(dif);
+
+	if (dfuse_leave) {
+		dfuse_special_command(dif, dfuse_address, SET_ADDRESS);
+		dfuse_dnload_chunk(dif, NULL, 0, 2); /* Zero-size */
+	}
+	return ret;
+}

+ 35 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfuse.h

@@ -0,0 +1,35 @@
+/* This implements the ST Microsystems DFU extensions (DfuSe)
+ * as per the DfuSe 1.1a specification (Document UM0391)
+ *
+ * (C) 2010-2012 Tormod Volden <debian.tormod@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef DFUSE_H
+#define DFUSE_H
+
+#include "dfu.h"
+
+enum dfuse_command { SET_ADDRESS, ERASE_PAGE, MASS_ERASE, READ_UNPROTECT };
+
+int dfuse_special_command(struct dfu_if *dif, unsigned int address,
+			  enum dfuse_command command);
+int dfuse_do_upload(struct dfu_if *dif, int xfer_size, int fd,
+		    const char *dfuse_options);
+int dfuse_do_dnload(struct dfu_if *dif, int xfer_size, struct dfu_file *file,
+		    const char *dfuse_options);
+
+#endif /* DFUSE_H */

+ 198 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfuse_mem.c

@@ -0,0 +1,198 @@
+/*
+ * Helper functions for reading the memory map of a device
+ * following the ST DfuSe 1.1a specification.
+ *
+ * Copyright 2011-2014 Tormod Volden <debian.tormod@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "portable.h"
+#include "dfu_file.h"
+#include "dfuse_mem.h"
+
+int add_segment(struct memsegment **segment_list, struct memsegment segment)
+{
+	struct memsegment *new_element;
+
+	new_element = dfu_malloc(sizeof(struct memsegment));
+	*new_element = segment;
+	new_element->next = NULL;
+
+	if (*segment_list == NULL)
+		/* list can be empty on first call */
+		*segment_list = new_element;
+	else {
+		struct memsegment *next_element;
+
+		/* find last element in list */
+		next_element = *segment_list;
+		while (next_element->next != NULL)
+			next_element = next_element->next;
+		next_element->next = new_element;
+	}
+	return 0;
+}
+
+struct memsegment *find_segment(struct memsegment *segment_list,
+				unsigned int address)
+{
+	while (segment_list != NULL) {
+		if (segment_list->start <= address &&
+		    segment_list->end >= address)
+			return segment_list;
+		segment_list = segment_list->next;
+	}
+	return NULL;
+}
+
+void free_segment_list(struct memsegment *segment_list)
+{
+	struct memsegment *next_element;
+
+	while (segment_list->next != NULL) {
+		next_element = segment_list->next;
+		free(segment_list);
+		segment_list = next_element;
+	}
+	free(segment_list);
+}
+
+/* Parse memory map from interface descriptor string
+ * encoded as per ST document UM0424 section 4.3.2.
+ */
+struct memsegment *parse_memory_layout(char *intf_desc)
+{
+
+	char multiplier, memtype;
+	unsigned int address;
+	int sectors, size;
+	char *name, *typestring;
+	int ret;
+	int count = 0;
+	char separator;
+	int scanned;
+	struct memsegment *segment_list = NULL;
+	struct memsegment segment;
+
+	name = dfu_malloc(strlen(intf_desc));
+
+	ret = sscanf(intf_desc, "@%[^/]%n", name, &scanned);
+	if (ret < 1) {
+		free(name);
+		warnx("Could not read name, sscanf returned %d", ret);
+		return NULL;
+	}
+	printf("DfuSe interface name: \"%s\"\n", name);
+
+	intf_desc += scanned;
+	typestring = dfu_malloc(strlen(intf_desc));
+
+	while (ret = sscanf(intf_desc, "/0x%x/%n", &address, &scanned),
+	       ret > 0) {
+
+		intf_desc += scanned;
+		while (ret = sscanf(intf_desc, "%d*%d%c%[^,/]%n",
+				    &sectors, &size, &multiplier, typestring,
+				    &scanned), ret > 2) {
+			intf_desc += scanned;
+
+			count++;
+			memtype = 0;
+			if (ret == 4) {
+				if (strlen(typestring) == 1
+				    && typestring[0] != '/')
+					memtype = typestring[0];
+				else {
+					warnx("Parsing type identifier '%s' "
+						"failed for segment %i",
+						typestring, count);
+					continue;
+				}
+			}
+
+			/* Quirk for STM32F4 devices */
+			if (strcmp(name, "Device Feature") == 0)
+				memtype = 'e';
+
+			switch (multiplier) {
+			case 'B':
+				break;
+			case 'K':
+				size *= 1024;
+				break;
+			case 'M':
+				size *= 1024 * 1024;
+				break;
+			case 'a':
+			case 'b':
+			case 'c':
+			case 'd':
+			case 'e':
+			case 'f':
+			case 'g':
+				if (!memtype) {
+					warnx("Non-valid multiplier '%c', "
+						"interpreted as type "
+						"identifier instead",
+						multiplier);
+					memtype = multiplier;
+					break;
+				}
+				/* fallthrough if memtype was already set */
+			default:
+				warnx("Non-valid multiplier '%c', "
+					"assuming bytes", multiplier);
+			}
+
+			if (!memtype) {
+				warnx("No valid type for segment %d\n", count);
+				continue;
+			}
+
+			segment.start = address;
+			segment.end = address + sectors * size - 1;
+			segment.pagesize = size;
+			segment.memtype = memtype & 7;
+			add_segment(&segment_list, segment);
+
+			if (verbose)
+				printf("Memory segment at 0x%08x %3d x %4d = "
+				       "%5d (%s%s%s)\n",
+				       address, sectors, size, sectors * size,
+				       memtype & DFUSE_READABLE  ? "r" : "",
+				       memtype & DFUSE_ERASABLE  ? "e" : "",
+				       memtype & DFUSE_WRITEABLE ? "w" : "");
+
+			address += sectors * size;
+
+			separator = *intf_desc;
+			if (separator == ',')
+				intf_desc += 1;
+			else
+				break;
+		}	/* while per segment */
+
+	}		/* while per address */
+	free(name);
+	free(typestring);
+
+	return segment_list;
+}

+ 44 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/dfuse_mem.h

@@ -0,0 +1,44 @@
+/* Helper functions for reading the memory map in a device
+ * following the ST DfuSe 1.1a specification.
+ *
+ * (C) 2011 Tormod Volden <debian.tormod@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef DFUSE_MEM_H
+#define DFUSE_MEM_H
+
+#define DFUSE_READABLE  1
+#define DFUSE_ERASABLE  2
+#define DFUSE_WRITEABLE 4
+
+struct memsegment {
+	unsigned int start;
+	unsigned int end;
+	int pagesize;
+	int memtype;
+	struct memsegment *next;
+};
+
+int add_segment(struct memsegment **list, struct memsegment new_element);
+
+struct memsegment *find_segment(struct memsegment *list, unsigned int address);
+
+void free_segment_list(struct memsegment *list);
+
+struct memsegment *parse_memory_layout(char *intf_desc_str);
+
+#endif /* DFUSE_MEM_H */

+ 691 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/main.c

@@ -0,0 +1,691 @@
+/*
+ * dfu-util
+ *
+ * Copyright 2007-2008 by OpenMoko, Inc.
+ * Copyright 2010-2016 Tormod Volden and Stefan Schmidt
+ * Copyright 2013-2014 Hans Petter Selasky <hps@bitfrost.no>
+ *
+ * Written by Harald Welte <laforge@openmoko.org>
+ *
+ * Based on existing code of dfu-programmer-0.4
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <getopt.h>
+#include <libusb.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+
+#include "portable.h"
+#include "dfu.h"
+#include "usb_dfu.h"
+#include "dfu_file.h"
+#include "dfu_load.h"
+#include "dfu_util.h"
+#include "dfuse.h"
+#include "quirks.h"
+
+int verbose = 0;
+
+struct dfu_if *dfu_root = NULL;
+
+char *match_path = NULL;
+int match_vendor = -1;
+int match_product = -1;
+int match_vendor_dfu = -1;
+int match_product_dfu = -1;
+int match_config_index = -1;
+int match_iface_index = -1;
+int match_iface_alt_index = -1;
+const char *match_iface_alt_name = NULL;
+const char *match_serial = NULL;
+const char *match_serial_dfu = NULL;
+
+static int parse_match_value(const char *str, int default_value)
+{
+	char *remainder;
+	int value;
+
+	if (str == NULL) {
+		value = default_value;
+	} else if (*str == '*') {
+		value = -1; /* Match anything */
+	} else if (*str == '-') {
+		value = 0x10000; /* Impossible vendor/product ID */
+	} else {
+		value = strtoul(str, &remainder, 16);
+		if (remainder == str) {
+			value = default_value;
+		}
+	}
+	return value;
+}
+
+static void parse_vendprod(const char *str)
+{
+	const char *comma;
+	const char *colon;
+
+	/* Default to match any DFU device in runtime or DFU mode */
+	match_vendor = -1;
+	match_product = -1;
+	match_vendor_dfu = -1;
+	match_product_dfu = -1;
+
+	comma = strchr(str, ',');
+	if (comma == str) {
+		/* DFU mode vendor/product being specified without any runtime
+		 * vendor/product specification, so don't match any runtime device */
+		match_vendor = match_product = 0x10000;
+	} else {
+		colon = strchr(str, ':');
+		if (colon != NULL) {
+			++colon;
+			if ((comma != NULL) && (colon > comma)) {
+				colon = NULL;
+			}
+		}
+		match_vendor = parse_match_value(str, match_vendor);
+		match_product = parse_match_value(colon, match_product);
+		if (comma != NULL) {
+			/* Both runtime and DFU mode vendor/product specifications are
+			 * available, so default DFU mode match components to the given
+			 * runtime match components */
+			match_vendor_dfu = match_vendor;
+			match_product_dfu = match_product;
+		}
+	}
+	if (comma != NULL) {
+		++comma;
+		colon = strchr(comma, ':');
+		if (colon != NULL) {
+			++colon;
+		}
+		match_vendor_dfu = parse_match_value(comma, match_vendor_dfu);
+		match_product_dfu = parse_match_value(colon, match_product_dfu);
+	}
+}
+
+static void parse_serial(char *str)
+{
+	char *comma;
+
+	match_serial = str;
+	comma = strchr(str, ',');
+	if (comma == NULL) {
+		match_serial_dfu = match_serial;
+	} else {
+		*comma++ = 0;
+		match_serial_dfu = comma;
+	}
+	if (*match_serial == 0) match_serial = NULL;
+	if (*match_serial_dfu == 0) match_serial_dfu = NULL;
+}
+
+static int parse_number(char *str, char *nmb)
+{
+	char *endptr;
+	long val;
+
+	errno = 0;
+	val = strtol(nmb, &endptr, 0);
+
+	if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
+		|| (errno != 0 && val == 0) || (*endptr != '\0')) {
+		errx(EX_SOFTWARE, "Something went wrong with the argument of --%s\n", str);
+	}
+
+	if (endptr == str) {
+		errx(EX_SOFTWARE, "No digits were found from the argument of --%s\n", str);
+	}
+
+	return (int)val;
+}
+
+static void help(void)
+{
+	fprintf(stderr, "Usage: dfu-util [options] ...\n"
+		"  -h --help\t\t\tPrint this help message\n"
+		"  -V --version\t\t\tPrint the version number\n"
+		"  -v --verbose\t\t\tPrint verbose debug statements\n"
+		"  -l --list\t\t\tList currently attached DFU capable devices\n");
+	fprintf(stderr, "  -e --detach\t\t\tDetach currently attached DFU capable devices\n"
+		"  -E --detach-delay seconds\tTime to wait before reopening a device after detach\n"
+		"  -d --device <vendor>:<product>[,<vendor_dfu>:<product_dfu>]\n"
+		"\t\t\t\tSpecify Vendor/Product ID(s) of DFU device\n"
+		"  -p --path <bus-port. ... .port>\tSpecify path to DFU device\n"
+		"  -c --cfg <config_nr>\t\tSpecify the Configuration of DFU device\n"
+		"  -i --intf <intf_nr>\t\tSpecify the DFU Interface number\n"
+		"  -S --serial <serial_string>[,<serial_string_dfu>]\n"
+		"\t\t\t\tSpecify Serial String of DFU device\n"
+		"  -a --alt <alt>\t\tSpecify the Altsetting of the DFU Interface\n"
+		"\t\t\t\tby name or by number\n");
+	fprintf(stderr, "  -t --transfer-size <size>\tSpecify the number of bytes per USB Transfer\n"
+		"  -U --upload <file>\t\tRead firmware from device into <file>\n"
+		"  -Z --upload-size <bytes>\tSpecify the expected upload size in bytes\n"
+		"  -D --download <file>\t\tWrite firmware from <file> into device\n"
+		"  -R --reset\t\t\tIssue USB Reset signalling once we're finished\n"
+		"  -s --dfuse-address <address>\tST DfuSe mode, specify target address for\n"
+		"\t\t\t\traw file download or upload. Not applicable for\n"
+		"\t\t\t\tDfuSe file (.dfu) downloads\n"
+		);
+	exit(EX_USAGE);
+}
+
+static void print_version(void)
+{
+	printf(PACKAGE_STRING "\n\n");
+	printf("Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.\n"
+	       "Copyright 2010-2016 Tormod Volden and Stefan Schmidt\n"
+	       "This program is Free Software and has ABSOLUTELY NO WARRANTY\n"
+	       "Please report bugs to " PACKAGE_BUGREPORT "\n\n");
+}
+
+static struct option opts[] = {
+	{ "help", 0, 0, 'h' },
+	{ "version", 0, 0, 'V' },
+	{ "verbose", 0, 0, 'v' },
+	{ "list", 0, 0, 'l' },
+	{ "detach", 0, 0, 'e' },
+	{ "detach-delay", 1, 0, 'E' },
+	{ "device", 1, 0, 'd' },
+	{ "path", 1, 0, 'p' },
+	{ "configuration", 1, 0, 'c' },
+	{ "cfg", 1, 0, 'c' },
+	{ "interface", 1, 0, 'i' },
+	{ "intf", 1, 0, 'i' },
+	{ "altsetting", 1, 0, 'a' },
+	{ "alt", 1, 0, 'a' },
+	{ "serial", 1, 0, 'S' },
+	{ "transfer-size", 1, 0, 't' },
+	{ "upload", 1, 0, 'U' },
+	{ "upload-size", 1, 0, 'Z' },
+	{ "download", 1, 0, 'D' },
+	{ "reset", 0, 0, 'R' },
+	{ "dfuse-address", 1, 0, 's' },
+	{ 0, 0, 0, 0 }
+};
+
+int main(int argc, char **argv)
+{
+	int expected_size = 0;
+	unsigned int transfer_size = 0;
+	enum mode mode = MODE_NONE;
+	struct dfu_status status;
+	libusb_context *ctx;
+	struct dfu_file file;
+	char *end;
+	int final_reset = 0;
+	int ret;
+	int dfuse_device = 0;
+	int fd;
+	const char *dfuse_options = NULL;
+	int detach_delay = 5;
+	uint16_t runtime_vendor;
+	uint16_t runtime_product;
+
+	memset(&file, 0, sizeof(file));
+
+	/* make sure all prints are flushed */
+	setvbuf(stdout, NULL, _IONBF, 0);
+
+	while (1) {
+		int c, option_index = 0;
+		c = getopt_long(argc, argv, "hVvleE:d:p:c:i:a:S:t:U:D:Rs:Z:", opts,
+				&option_index);
+		if (c == -1)
+			break;
+
+		switch (c) {
+		case 'h':
+			help();
+			break;
+		case 'V':
+			mode = MODE_VERSION;
+			break;
+		case 'v':
+			verbose++;
+			break;
+		case 'l':
+			mode = MODE_LIST;
+			break;
+		case 'e':
+			mode = MODE_DETACH;
+			break;
+		case 'E':
+			detach_delay = parse_number("detach-delay", optarg);
+			break;
+		case 'd':
+			parse_vendprod(optarg);
+			break;
+		case 'p':
+#if (defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102) || (defined(LIBUSBX_API_VERSION) && LIBUSBX_API_VERSION >= 0x01000102)
+			match_path = optarg;
+#else
+			errx(EX_SOFTWARE, "This dfu-util was built without USB path support");
+#endif
+			break;
+		case 'c':
+			/* Configuration */
+			match_config_index = parse_number("cfg", optarg);
+			break;
+		case 'i':
+			/* Interface */
+			match_iface_index = parse_number("intf", optarg);
+			break;
+		case 'a':
+			/* Interface Alternate Setting */
+			match_iface_alt_index = strtoul(optarg, &end, 0);
+			if (*end) {
+				match_iface_alt_name = optarg;
+				match_iface_alt_index = -1;
+			}
+			break;
+		case 'S':
+			parse_serial(optarg);
+			break;
+		case 't':
+			transfer_size = parse_number("transfer-size", optarg);
+			break;
+		case 'U':
+			mode = MODE_UPLOAD;
+			file.name = optarg;
+			break;
+		case 'Z':
+			expected_size = parse_number("upload-size", optarg);
+			break;
+		case 'D':
+			mode = MODE_DOWNLOAD;
+			file.name = optarg;
+			break;
+		case 'R':
+			final_reset = 1;
+			break;
+		case 's':
+			dfuse_options = optarg;
+			break;
+		default:
+			help();
+			break;
+		}
+	}
+
+	print_version();
+	if (mode == MODE_VERSION) {
+		exit(0);
+	}
+
+	if (mode == MODE_NONE) {
+		fprintf(stderr, "You need to specify one of -D or -U\n");
+		help();
+	}
+
+	if (match_config_index == 0) {
+		/* Handle "-c 0" (unconfigured device) as don't care */
+		match_config_index = -1;
+	}
+
+	if (mode == MODE_DOWNLOAD) {
+		dfu_load_file(&file, MAYBE_SUFFIX, MAYBE_PREFIX);
+		/* If the user didn't specify product and/or vendor IDs to match,
+		 * use any IDs from the file suffix for device matching */
+		if (match_vendor < 0 && file.idVendor != 0xffff) {
+			match_vendor = file.idVendor;
+			printf("Match vendor ID from file: %04x\n", match_vendor);
+		}
+		if (match_product < 0 && file.idProduct != 0xffff) {
+			match_product = file.idProduct;
+			printf("Match product ID from file: %04x\n", match_product);
+		}
+	}
+
+	ret = libusb_init(&ctx);
+	if (ret)
+		errx(EX_IOERR, "unable to initialize libusb: %s", libusb_error_name(ret));
+
+	if (verbose > 2) {
+		libusb_set_debug(ctx, 255);
+	}
+
+	probe_devices(ctx);
+
+	if (mode == MODE_LIST) {
+		list_dfu_interfaces();
+		exit(0);
+	}
+
+	if (dfu_root == NULL) {
+		errx(EX_IOERR, "No DFU capable USB device available");
+	} else if (dfu_root->next != NULL) {
+		/* We cannot safely support more than one DFU capable device
+		 * with same vendor/product ID, since during DFU we need to do
+		 * a USB bus reset, after which the target device will get a
+		 * new address */
+		errx(EX_IOERR, "More than one DFU capable USB device found! "
+		       "Try `--list' and specify the serial number "
+		       "or disconnect all but one device\n");
+	}
+
+	/* We have exactly one device. Its libusb_device is now in dfu_root->dev */
+
+	printf("Opening DFU capable USB device...\n");
+	ret = libusb_open(dfu_root->dev, &dfu_root->dev_handle);
+	if (ret || !dfu_root->dev_handle)
+		errx(EX_IOERR, "Cannot open device: %s", libusb_error_name(ret));
+
+	printf("ID %04x:%04x\n", dfu_root->vendor, dfu_root->product);
+
+	printf("Run-time device DFU version %04x\n",
+	       libusb_le16_to_cpu(dfu_root->func_dfu.bcdDFUVersion));
+
+	/* Transition from run-Time mode to DFU mode */
+	if (!(dfu_root->flags & DFU_IFF_DFU)) {
+		int err;
+		/* In the 'first round' during runtime mode, there can only be one
+		* DFU Interface descriptor according to the DFU Spec. */
+
+		/* FIXME: check if the selected device really has only one */
+
+		runtime_vendor = dfu_root->vendor;
+		runtime_product = dfu_root->product;
+
+		printf("Claiming USB DFU Runtime Interface...\n");
+		ret = libusb_claim_interface(dfu_root->dev_handle, dfu_root->interface);
+		if (ret < 0) {
+			errx(EX_IOERR, "Cannot claim interface %d: %s",
+				dfu_root->interface, libusb_error_name(ret));
+		}
+
+		ret = libusb_set_interface_alt_setting(dfu_root->dev_handle, dfu_root->interface, 0);
+		if (ret < 0) {
+			errx(EX_IOERR, "Cannot set alt interface zero: %s", libusb_error_name(ret));
+		}
+
+		printf("Determining device status: ");
+
+		err = dfu_get_status(dfu_root, &status);
+		if (err == LIBUSB_ERROR_PIPE) {
+			printf("Device does not implement get_status, assuming appIDLE\n");
+			status.bStatus = DFU_STATUS_OK;
+			status.bwPollTimeout = 0;
+			status.bState  = DFU_STATE_appIDLE;
+			status.iString = 0;
+		} else if (err < 0) {
+			errx(EX_IOERR, "error get_status");
+		} else {
+			printf("state = %s, status = %d\n",
+			       dfu_state_to_string(status.bState), status.bStatus);
+		}
+		milli_sleep(status.bwPollTimeout);
+
+		switch (status.bState) {
+		case DFU_STATE_appIDLE:
+		case DFU_STATE_appDETACH:
+			printf("Device really in Runtime Mode, send DFU "
+			       "detach request...\n");
+			if (dfu_detach(dfu_root->dev_handle,
+				       dfu_root->interface, 1000) < 0) {
+				warnx("error detaching");
+			}
+			if (dfu_root->func_dfu.bmAttributes & USB_DFU_WILL_DETACH) {
+				printf("Device will detach and reattach...\n");
+			} else {
+				printf("Resetting USB...\n");
+				ret = libusb_reset_device(dfu_root->dev_handle);
+				if (ret < 0 && ret != LIBUSB_ERROR_NOT_FOUND)
+					errx(EX_IOERR, "error resetting "
+						"after detach: %s", libusb_error_name(ret));
+			}
+			break;
+		case DFU_STATE_dfuERROR:
+			printf("dfuERROR, clearing status\n");
+			if (dfu_clear_status(dfu_root->dev_handle,
+					     dfu_root->interface) < 0) {
+				errx(EX_IOERR, "error clear_status");
+			}
+			/* fall through */
+		default:
+			warnx("WARNING: Runtime device already in DFU state ?!?");
+			libusb_release_interface(dfu_root->dev_handle,
+			    dfu_root->interface);
+			goto dfustate;
+		}
+		libusb_release_interface(dfu_root->dev_handle,
+					 dfu_root->interface);
+		libusb_close(dfu_root->dev_handle);
+		dfu_root->dev_handle = NULL;
+
+		if (mode == MODE_DETACH) {
+			libusb_exit(ctx);
+			exit(0);
+		}
+
+		/* keeping handles open might prevent re-enumeration */
+		disconnect_devices();
+
+		milli_sleep(detach_delay * 1000);
+
+		/* Change match vendor and product to impossible values to force
+		 * only DFU mode matches in the following probe */
+		match_vendor = match_product = 0x10000;
+
+		probe_devices(ctx);
+
+		if (dfu_root == NULL) {
+			errx(EX_IOERR, "Lost device after RESET?");
+		} else if (dfu_root->next != NULL) {
+			errx(EX_IOERR, "More than one DFU capable USB device found! "
+				"Try `--list' and specify the serial number "
+				"or disconnect all but one device");
+		}
+
+		/* Check for DFU mode device */
+		if (!(dfu_root->flags | DFU_IFF_DFU))
+			errx(EX_SOFTWARE, "Device is not in DFU mode");
+
+		printf("Opening DFU USB Device...\n");
+		ret = libusb_open(dfu_root->dev, &dfu_root->dev_handle);
+		if (ret || !dfu_root->dev_handle) {
+			errx(EX_IOERR, "Cannot open device");
+		}
+	} else {
+		/* we're already in DFU mode, so we can skip the detach/reset
+		 * procedure */
+		/* If a match vendor/product was specified, use that as the runtime
+		 * vendor/product, otherwise use the DFU mode vendor/product */
+		runtime_vendor = match_vendor < 0 ? dfu_root->vendor : match_vendor;
+		runtime_product = match_product < 0 ? dfu_root->product : match_product;
+	}
+
+dfustate:
+#if 0
+	printf("Setting Configuration %u...\n", dfu_root->configuration);
+	ret = libusb_set_configuration(dfu_root->dev_handle, dfu_root->configuration);
+	if (ret < 0) {
+		errx(EX_IOERR, "Cannot set configuration: %s", libusb_error_name(ret));
+	}
+#endif
+	printf("Claiming USB DFU Interface...\n");
+	ret = libusb_claim_interface(dfu_root->dev_handle, dfu_root->interface);
+	if (ret < 0) {
+		errx(EX_IOERR, "Cannot claim interface - %s", libusb_error_name(ret));
+	}
+
+	printf("Setting Alternate Setting #%d ...\n", dfu_root->altsetting);
+	ret = libusb_set_interface_alt_setting(dfu_root->dev_handle, dfu_root->interface, dfu_root->altsetting);
+	if (ret < 0) {
+		errx(EX_IOERR, "Cannot set alternate interface: %s", libusb_error_name(ret));
+	}
+
+status_again:
+	printf("Determining device status: ");
+	ret = dfu_get_status(dfu_root, &status );
+	if (ret < 0) {
+		errx(EX_IOERR, "error get_status: %s", libusb_error_name(ret));
+	}
+	printf("state = %s, status = %d\n",
+	       dfu_state_to_string(status.bState), status.bStatus);
+
+	milli_sleep(status.bwPollTimeout);
+
+	switch (status.bState) {
+	case DFU_STATE_appIDLE:
+	case DFU_STATE_appDETACH:
+		errx(EX_IOERR, "Device still in Runtime Mode!");
+		break;
+	case DFU_STATE_dfuERROR:
+		printf("dfuERROR, clearing status\n");
+		if (dfu_clear_status(dfu_root->dev_handle, dfu_root->interface) < 0) {
+			errx(EX_IOERR, "error clear_status");
+		}
+		goto status_again;
+		break;
+	case DFU_STATE_dfuDNLOAD_IDLE:
+	case DFU_STATE_dfuUPLOAD_IDLE:
+		printf("aborting previous incomplete transfer\n");
+		if (dfu_abort(dfu_root->dev_handle, dfu_root->interface) < 0) {
+			errx(EX_IOERR, "can't send DFU_ABORT");
+		}
+		goto status_again;
+		break;
+	case DFU_STATE_dfuIDLE:
+		printf("dfuIDLE, continuing\n");
+		break;
+	default:
+		break;
+	}
+
+	if (DFU_STATUS_OK != status.bStatus ) {
+		printf("WARNING: DFU Status: '%s'\n",
+			dfu_status_to_string(status.bStatus));
+		/* Clear our status & try again. */
+		if (dfu_clear_status(dfu_root->dev_handle, dfu_root->interface) < 0)
+			errx(EX_IOERR, "USB communication error");
+		if (dfu_get_status(dfu_root, &status) < 0)
+			errx(EX_IOERR, "USB communication error");
+		if (DFU_STATUS_OK != status.bStatus)
+			errx(EX_SOFTWARE, "Status is not OK: %d", status.bStatus);
+
+		milli_sleep(status.bwPollTimeout);
+	}
+
+	printf("DFU mode device DFU version %04x\n",
+	       libusb_le16_to_cpu(dfu_root->func_dfu.bcdDFUVersion));
+
+	if (dfu_root->func_dfu.bcdDFUVersion == libusb_cpu_to_le16(0x11a))
+		dfuse_device = 1;
+
+	/* If not overridden by the user */
+	if (!transfer_size) {
+		transfer_size = libusb_le16_to_cpu(
+		    dfu_root->func_dfu.wTransferSize);
+		if (transfer_size) {
+			printf("Device returned transfer size %i\n",
+			       transfer_size);
+		} else {
+			errx(EX_IOERR, "Transfer size must be specified");
+		}
+	}
+
+#ifdef HAVE_GETPAGESIZE
+/* autotools lie when cross-compiling for Windows using mingw32/64 */
+#ifndef __MINGW32__
+	/* limitation of Linux usbdevio */
+	if ((int)transfer_size > getpagesize()) {
+		transfer_size = getpagesize();
+		printf("Limited transfer size to %i\n", transfer_size);
+	}
+#endif /* __MINGW32__ */
+#endif /* HAVE_GETPAGESIZE */
+
+	if (transfer_size < dfu_root->bMaxPacketSize0) {
+		transfer_size = dfu_root->bMaxPacketSize0;
+		printf("Adjusted transfer size to %i\n", transfer_size);
+	}
+
+	switch (mode) {
+	case MODE_UPLOAD:
+		/* open for "exclusive" writing */
+		fd = open(file.name, O_WRONLY | O_BINARY | O_CREAT | O_EXCL | O_TRUNC, 0666);
+		if (fd < 0)
+			err(EX_IOERR, "Cannot open file %s for writing", file.name);
+
+		if (dfuse_device || dfuse_options) {
+		    if (dfuse_do_upload(dfu_root, transfer_size, fd,
+					dfuse_options) < 0)
+			exit(1);
+		} else {
+		    if (dfuload_do_upload(dfu_root, transfer_size,
+			expected_size, fd) < 0) {
+			exit(1);
+		    }
+		}
+		close(fd);
+		break;
+
+	case MODE_DOWNLOAD:
+		if (((file.idVendor  != 0xffff && file.idVendor  != runtime_vendor) ||
+		     (file.idProduct != 0xffff && file.idProduct != runtime_product)) &&
+		    ((file.idVendor  != 0xffff && file.idVendor  != dfu_root->vendor) ||
+		     (file.idProduct != 0xffff && file.idProduct != dfu_root->product))) {
+			errx(EX_IOERR, "Error: File ID %04x:%04x does "
+				"not match device (%04x:%04x or %04x:%04x)",
+				file.idVendor, file.idProduct,
+				runtime_vendor, runtime_product,
+				dfu_root->vendor, dfu_root->product);
+		}
+		if (dfuse_device || dfuse_options || file.bcdDFU == 0x11a) {
+		        if (dfuse_do_dnload(dfu_root, transfer_size, &file,
+							dfuse_options) < 0)
+				exit(1);
+		} else {
+			if (dfuload_do_dnload(dfu_root, transfer_size, &file) < 0)
+				exit(1);
+	 	}
+		break;
+	case MODE_DETACH:
+		if (dfu_detach(dfu_root->dev_handle, dfu_root->interface, 1000) < 0) {
+			warnx("can't detach");
+		}
+		break;
+	default:
+		errx(EX_IOERR, "Unsupported mode: %u", mode);
+		break;
+	}
+
+	if (final_reset) {
+		if (dfu_detach(dfu_root->dev_handle, dfu_root->interface, 1000) < 0) {
+			/* Even if detach failed, just carry on to leave the
+                           device in a known state */
+			warnx("can't detach");
+		}
+		printf("Resetting USB to switch back to runtime mode\n");
+		ret = libusb_reset_device(dfu_root->dev_handle);
+		if (ret < 0 && ret != LIBUSB_ERROR_NOT_FOUND) {
+			errx(EX_IOERR, "error resetting after download: %s", libusb_error_name(ret));
+		}
+	}
+
+	libusb_close(dfu_root->dev_handle);
+	dfu_root->dev_handle = NULL;
+	libusb_exit(ctx);
+
+	return (0);
+}

+ 71 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/portable.h

@@ -0,0 +1,71 @@
+
+#ifndef PORTABLE_H
+#define PORTABLE_H
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#else
+# define PACKAGE "dfu-util"
+# define PACKAGE_VERSION "0.9-msvc"
+# define PACKAGE_STRING "dfu-util 0.9-msvc"
+# define PACKAGE_BUGREPORT "http://sourceforge.net/p/dfu-util/tickets/"
+# include <io.h>
+#endif /* HAVE_CONFIG_H */
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+
+#ifdef HAVE_NANOSLEEP
+# include <time.h>
+# define milli_sleep(msec) do {\
+  if (msec) {\
+    struct timespec nanosleepDelay = { (msec) / 1000, ((msec) % 1000) * 1000000 };\
+    nanosleep(&nanosleepDelay, NULL);\
+  } } while (0)
+#elif defined HAVE_WINDOWS_H
+# define milli_sleep(msec) do {\
+  if (msec) {\
+    Sleep(msec);\
+  } } while (0)
+#else
+# error "Can't get no sleep! Please report"
+#endif /* HAVE_NANOSLEEP */
+
+#ifdef HAVE_ERR
+# include <err.h>
+#else
+# include <errno.h>
+# include <string.h>
+# define warnx(...) do {\
+    fprintf(stderr, __VA_ARGS__);\
+    fprintf(stderr, "\n"); } while (0)
+# define errx(eval, ...) do {\
+    warnx(__VA_ARGS__);\
+    exit(eval); } while (0)
+# define warn(...) do {\
+    fprintf(stderr, "%s: ", strerror(errno));\
+    warnx(__VA_ARGS__); } while (0)
+# define err(eval, ...) do {\
+    warn(__VA_ARGS__);\
+    exit(eval); } while (0)
+#endif /* HAVE_ERR */
+
+#ifdef HAVE_SYSEXITS_H
+# include <sysexits.h>
+#else
+# define EX_OK		0	/* successful termination */
+# define EX_USAGE	64	/* command line usage error */
+# define EX_SOFTWARE	70	/* internal software error */
+# define EX_IOERR	74	/* input/output error */
+#endif /* HAVE_SYSEXITS_H */
+
+#ifndef O_BINARY
+# define O_BINARY   0
+#endif
+
+#ifndef off_t
+# define off_t long int
+#endif
+
+#endif /* PORTABLE_H */

+ 176 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/prefix.c

@@ -0,0 +1,176 @@
+/*
+ * dfu-prefix
+ *
+ * Copyright 2011-2012 Stefan Schmidt <stefan@datenfreihafen.org>
+ * Copyright 2013 Hans Petter Selasky <hps@bitfrost.no>
+ * Copyright 2014 Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <getopt.h>
+#include <string.h>
+
+#include "portable.h"
+#include "dfu_file.h"
+
+enum mode {
+	MODE_NONE,
+	MODE_ADD,
+	MODE_DEL,
+	MODE_CHECK
+};
+
+int verbose;
+
+static void help(void)
+{
+	fprintf(stderr, "Usage: dfu-prefix [options] ...\n"
+		"  -h --help\t\t\tPrint this help message\n"
+		"  -V --version\t\t\tPrint the version number\n"
+		"  -c --check <file>\t\tCheck DFU prefix of <file>\n"
+		"  -D --delete <file>\t\tDelete DFU prefix from <file>\n"
+		"  -a --add <file>\t\tAdd DFU prefix to <file>\n"
+		"In combination with -a:\n"
+		);
+	fprintf(stderr, "  -s --stellaris-address <address>  Add TI Stellaris address prefix to <file>\n"
+		"In combination with -D or -c:\n"
+		"  -T --stellaris\t\tAct on TI Stellaris address prefix of <file>\n"
+		"In combination with -a or -D or -c:\n"
+		"  -L --lpc-prefix\t\tUse NXP LPC DFU prefix format\n"
+		);
+	exit(EX_USAGE);
+}
+
+static void print_version(void)
+{
+	printf("dfu-prefix (%s) %s\n\n", PACKAGE, PACKAGE_VERSION);
+	printf("Copyright 2011-2012 Stefan Schmidt, 2014 Uwe Bonnes\n"
+	       "This program is Free Software and has ABSOLUTELY NO WARRANTY\n"
+	       "Please report bugs to %s\n\n", PACKAGE_BUGREPORT);
+
+}
+
+static struct option opts[] = {
+	{ "help", 0, 0, 'h' },
+	{ "version", 0, 0, 'V' },
+	{ "check", 1, 0, 'c' },
+	{ "add", 1, 0, 'a' },
+	{ "delete", 1, 0, 'D' },
+	{ "stellaris-address", 1, 0, 's' },
+	{ "stellaris", 0, 0, 'T' },
+	{ "LPC", 0, 0, 'L' },
+};
+int main(int argc, char **argv)
+{
+	struct dfu_file file;
+	enum mode mode = MODE_NONE;
+	enum prefix_type type = ZERO_PREFIX;
+	uint32_t lmdfu_flash_address = 0;
+	char *end;
+
+	/* make sure all prints are flushed */
+	setvbuf(stdout, NULL, _IONBF, 0);
+
+	print_version();
+
+	memset(&file, 0, sizeof(file));
+
+	while (1) {
+		int c, option_index = 0;
+		c = getopt_long(argc, argv, "hVc:a:D:p:v:d:s:TL", opts,
+				&option_index);
+		if (c == -1)
+			break;
+
+		switch (c) {
+		case 'h':
+			help();
+			break;
+		case 'V':
+			exit(0);
+			break;
+		case 'D':
+			file.name = optarg;
+			mode = MODE_DEL;
+			break;
+		case 'c':
+			file.name = optarg;
+			mode = MODE_CHECK;
+			break;
+		case 'a':
+			file.name = optarg;
+			mode = MODE_ADD;
+			break;
+		case 's':
+			lmdfu_flash_address = strtoul(optarg, &end, 0);
+			if (*end) {
+				errx(EX_IOERR, "Invalid lmdfu "
+					"address: %s", optarg);
+			}
+			/* fall-through */
+		case 'T':
+			type = LMDFU_PREFIX;
+			break;
+		case 'L':
+			type = LPCDFU_UNENCRYPTED_PREFIX;
+			break;
+		default:
+			help();
+			break;
+		}
+	}
+
+	if (!file.name) {
+		fprintf(stderr, "You need to specify a filename\n");
+		help();
+	}
+
+	switch(mode) {
+	case MODE_ADD:
+		if (type == ZERO_PREFIX)
+			errx(EX_IOERR, "Prefix type must be specified");
+		dfu_load_file(&file, MAYBE_SUFFIX, NO_PREFIX);
+		file.lmdfu_address = lmdfu_flash_address;
+		file.prefix_type = type;
+		printf("Adding prefix to file\n");
+		dfu_store_file(&file, file.size.suffix != 0, 1);
+		break;
+
+	case MODE_CHECK:
+		dfu_load_file(&file, MAYBE_SUFFIX, MAYBE_PREFIX);
+		show_suffix_and_prefix(&file);
+		if (type > ZERO_PREFIX && file.prefix_type != type)
+			errx(EX_IOERR, "No prefix of requested type");
+		break;
+
+	case MODE_DEL:
+		dfu_load_file(&file, MAYBE_SUFFIX, NEEDS_PREFIX);
+		if (type > ZERO_PREFIX && file.prefix_type != type)
+			errx(EX_IOERR, "No prefix of requested type");
+		printf("Removing prefix from file\n");
+		/* if there was a suffix, rewrite it */
+		dfu_store_file(&file, file.size.suffix != 0, 0);
+		break;
+
+	default:
+		help();
+		break;
+	}
+	return (0);
+}

+ 56 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/quirks.c

@@ -0,0 +1,56 @@
+/*
+ *  Simple quirk system for dfu-util
+ *
+ *  Copyright 2010-2014 Tormod Volden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdint.h>
+#include "quirks.h"
+
+uint16_t get_quirks(uint16_t vendor, uint16_t product, uint16_t bcdDevice)
+{
+	uint16_t quirks = 0;
+
+	/* Device returns bogus bwPollTimeout values */
+	if ((vendor == VENDOR_OPENMOKO || vendor == VENDOR_FIC) &&
+	    product >= PRODUCT_FREERUNNER_FIRST &&
+	    product <= PRODUCT_FREERUNNER_LAST)
+		quirks |= QUIRK_POLLTIMEOUT;
+
+	if (vendor == VENDOR_VOTI &&
+	    product == PRODUCT_OPENPCD)
+		quirks |= QUIRK_POLLTIMEOUT;
+
+	/* Reports wrong DFU version in DFU descriptor */
+	if (vendor == VENDOR_LEAFLABS &&
+	    product == PRODUCT_MAPLE3 &&
+	    bcdDevice == 0x0200)
+		quirks |= QUIRK_FORCE_DFU11;
+
+	/* old devices(bcdDevice == 0) return bogus bwPollTimeout values */
+	if (vendor == VENDOR_SIEMENS &&
+	    (product == PRODUCT_PXM40 || product == PRODUCT_PXM50) &&
+	    bcdDevice == 0)
+		quirks |= QUIRK_POLLTIMEOUT;
+
+	/* M-Audio Transit returns bogus bwPollTimeout values */
+	if (vendor == VENDOR_MIDIMAN &&
+	    product == PRODUCT_TRANSIT)
+		quirks |= QUIRK_POLLTIMEOUT;
+
+	return (quirks);
+}

+ 27 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/quirks.h

@@ -0,0 +1,27 @@
+#ifndef DFU_QUIRKS_H
+#define DFU_QUIRKS_H
+
+#define VENDOR_OPENMOKO 0x1d50 /* Openmoko Freerunner / GTA02 */
+#define VENDOR_FIC      0x1457 /* Openmoko Freerunner / GTA02 */
+#define VENDOR_VOTI	0x16c0 /* OpenPCD Reader */
+#define VENDOR_LEAFLABS 0x1eaf /* Maple */
+#define VENDOR_SIEMENS 0x0908 /* Siemens AG */
+#define VENDOR_MIDIMAN  0x0763 /* Midiman */
+
+#define PRODUCT_FREERUNNER_FIRST 0x5117
+#define PRODUCT_FREERUNNER_LAST  0x5126
+#define PRODUCT_OPENPCD	0x076b
+#define PRODUCT_MAPLE3	0x0003 /* rev 3 and 5 */
+#define PRODUCT_PXM40	0x02c4 /* Siemens AG, PXM 40 */
+#define PRODUCT_PXM50	0x02c5 /* Siemens AG, PXM 50 */
+#define PRODUCT_TRANSIT	0x2806 /* M-Audio Transit (Midiman) */
+
+#define QUIRK_POLLTIMEOUT  (1<<0)
+#define QUIRK_FORCE_DFU11  (1<<1)
+
+/* Fallback value, works for OpenMoko */
+#define DEFAULT_POLLTIMEOUT  5
+
+uint16_t get_quirks(uint16_t vendor, uint16_t product, uint16_t bcdDevice);
+
+#endif /* DFU_QUIRKS_H */

+ 176 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/suffix.c

@@ -0,0 +1,176 @@
+/*
+ * dfu-suffix
+ *
+ * Copyright 2011-2012 Stefan Schmidt <stefan@datenfreihafen.org>
+ * Copyright 2013 Hans Petter Selasky <hps@bitfrost.no>
+ * Copyright 2014 Tormod Volden <debian.tormod@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <getopt.h>
+#include <string.h>
+
+#include "portable.h"
+#include "dfu_file.h"
+
+enum mode {
+	MODE_NONE,
+	MODE_ADD,
+	MODE_DEL,
+	MODE_CHECK
+};
+
+int verbose;
+
+static void help(void)
+{
+	fprintf(stderr, "Usage: dfu-suffix [options] ...\n"
+		"  -h --help\t\t\tPrint this help message\n"
+		"  -V --version\t\t\tPrint the version number\n"
+		"  -c --check <file>\t\tCheck DFU suffix of <file>\n"
+		"  -a --add <file>\t\tAdd DFU suffix to <file>\n"
+		"  -D --delete <file>\t\tDelete DFU suffix from <file>\n"
+		"  -p --pid <productID>\t\tAdd product ID into DFU suffix in <file>\n"
+		"  -v --vid <vendorID>\t\tAdd vendor ID into DFU suffix in <file>\n"
+		"  -d --did <deviceID>\t\tAdd device ID into DFU suffix in <file>\n"
+		"  -S --spec <specID>\t\tAdd DFU specification ID into DFU suffix in <file>\n"
+		);
+	exit(EX_USAGE);
+}
+
+static void print_version(void)
+{
+	printf("dfu-suffix (%s) %s\n\n", PACKAGE, PACKAGE_VERSION);
+	printf("Copyright 2011-2012 Stefan Schmidt, 2013-2014 Tormod Volden\n"
+	       "This program is Free Software and has ABSOLUTELY NO WARRANTY\n"
+	       "Please report bugs to %s\n\n", PACKAGE_BUGREPORT);
+
+}
+
+static struct option opts[] = {
+	{ "help", 0, 0, 'h' },
+	{ "version", 0, 0, 'V' },
+	{ "check", 1, 0, 'c' },
+	{ "add", 1, 0, 'a' },
+	{ "delete", 1, 0, 'D' },
+	{ "pid", 1, 0, 'p' },
+	{ "vid", 1, 0, 'v' },
+	{ "did", 1, 0, 'd' },
+	{ "spec", 1, 0, 'S' },
+};
+
+int main(int argc, char **argv)
+{
+	struct dfu_file file;
+	int pid, vid, did, spec;
+	enum mode mode = MODE_NONE;
+
+	/* make sure all prints are flushed */
+	setvbuf(stdout, NULL, _IONBF, 0);
+
+	print_version();
+
+	pid = vid = did = 0xffff;
+	spec = 0x0100;			/* Default to bcdDFU version 1.0 */
+        memset(&file, 0, sizeof(file));
+
+	while (1) {
+		int c, option_index = 0;
+		c = getopt_long(argc, argv, "hVc:a:D:p:v:d:S:s:T", opts,
+				&option_index);
+		if (c == -1)
+			break;
+
+		switch (c) {
+		case 'h':
+			help();
+			break;
+		case 'V':
+			exit(0);
+			break;
+		case 'D':
+			file.name = optarg;
+			mode = MODE_DEL;
+			break;
+		case 'p':
+			pid = strtol(optarg, NULL, 16);
+			break;
+		case 'v':
+			vid = strtol(optarg, NULL, 16);
+			break;
+		case 'd':
+			did = strtol(optarg, NULL, 16);
+			break;
+		case 'S':
+			spec = strtol(optarg, NULL, 16);
+			break;
+		case 'c':
+			file.name = optarg;
+			mode = MODE_CHECK;
+			break;
+		case 'a':
+			file.name = optarg;
+			mode = MODE_ADD;
+			break;
+		default:
+			help();
+			break;
+		}
+	}
+
+	if (!file.name) {
+		fprintf(stderr, "You need to specify a filename\n");
+		help();
+	}
+
+	if (spec != 0x0100 && spec != 0x011a) {
+		fprintf(stderr, "Only DFU specification 0x0100 and 0x011a supported\n");
+		help();
+	}
+
+	switch(mode) {
+	case MODE_ADD:
+		dfu_load_file(&file, NO_SUFFIX, MAYBE_PREFIX);
+		file.idVendor = vid;
+		file.idProduct = pid;
+		file.bcdDevice = did;
+		file.bcdDFU = spec;
+		/* always write suffix, rewrite prefix if there was one */
+		dfu_store_file(&file, 1, file.size.prefix != 0);
+		printf("Suffix successfully added to file\n");
+		break;
+
+	case MODE_CHECK:
+		dfu_load_file(&file, NEEDS_SUFFIX, MAYBE_PREFIX);
+		show_suffix_and_prefix(&file);
+		break;
+
+	case MODE_DEL:
+		dfu_load_file(&file, NEEDS_SUFFIX, MAYBE_PREFIX);
+		dfu_store_file(&file, 0, file.size.prefix != 0);
+		if (file.size.suffix) /* had a suffix */
+			printf("Suffix successfully removed from file\n");
+		break;
+
+	default:
+		help();
+		break;
+	}
+	return (0);
+}

+ 103 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/src/usb_dfu.h

@@ -0,0 +1,103 @@
+#ifndef USB_DFU_H
+#define USB_DFU_H
+/* USB Device Firmware Update Implementation for OpenPCD
+ * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
+ *
+ * Protocol definitions for USB DFU
+ *
+ * This ought to be compliant to the USB DFU Spec 1.0 as available from
+ * http://www.usb.org/developers/devclass_docs/usbdfu10.pdf
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdint.h>
+
+#define USB_DT_DFU			0x21
+
+#ifdef _MSC_VER
+# pragma pack(push)
+# pragma pack(1)
+#endif /* _MSC_VER */
+struct usb_dfu_func_descriptor {
+	uint8_t		bLength;
+	uint8_t		bDescriptorType;
+	uint8_t		bmAttributes;
+#define USB_DFU_CAN_DOWNLOAD	(1 << 0)
+#define USB_DFU_CAN_UPLOAD	(1 << 1)
+#define USB_DFU_MANIFEST_TOL	(1 << 2)
+#define USB_DFU_WILL_DETACH	(1 << 3)
+	uint16_t		wDetachTimeOut;
+	uint16_t		wTransferSize;
+	uint16_t		bcdDFUVersion;
+#ifdef _MSC_VER
+};
+# pragma pack(pop)
+#elif defined __GNUC__
+# if defined __MINGW32__
+} __attribute__ ((__packed__, __gcc_struct__));
+# else
+} __attribute__ ((__packed__));
+# endif
+#else
+ #warning "No way to pack struct on this compiler? This will break!"
+#endif /* _MSC_VER */
+
+#define USB_DT_DFU_SIZE			9
+
+#define USB_TYPE_DFU		(LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE)
+
+/* DFU class-specific requests (Section 3, DFU Rev 1.1) */
+#define USB_REQ_DFU_DETACH	0x00
+#define USB_REQ_DFU_DNLOAD	0x01
+#define USB_REQ_DFU_UPLOAD	0x02
+#define USB_REQ_DFU_GETSTATUS	0x03
+#define USB_REQ_DFU_CLRSTATUS	0x04
+#define USB_REQ_DFU_GETSTATE	0x05
+#define USB_REQ_DFU_ABORT	0x06
+
+/* DFU_GETSTATUS bStatus values (Section 6.1.2, DFU Rev 1.1) */
+#define DFU_STATUS_OK			0x00
+#define DFU_STATUS_errTARGET		0x01
+#define DFU_STATUS_errFILE		0x02
+#define DFU_STATUS_errWRITE		0x03
+#define DFU_STATUS_errERASE		0x04
+#define DFU_STATUS_errCHECK_ERASED	0x05
+#define DFU_STATUS_errPROG		0x06
+#define DFU_STATUS_errVERIFY		0x07
+#define DFU_STATUS_errADDRESS		0x08
+#define DFU_STATUS_errNOTDONE		0x09
+#define DFU_STATUS_errFIRMWARE		0x0a
+#define DFU_STATUS_errVENDOR		0x0b
+#define DFU_STATUS_errUSBR		0x0c
+#define DFU_STATUS_errPOR		0x0d
+#define DFU_STATUS_errUNKNOWN		0x0e
+#define DFU_STATUS_errSTALLEDPKT	0x0f
+
+enum dfu_state {
+	DFU_STATE_appIDLE		= 0,
+	DFU_STATE_appDETACH		= 1,
+	DFU_STATE_dfuIDLE		= 2,
+	DFU_STATE_dfuDNLOAD_SYNC	= 3,
+	DFU_STATE_dfuDNBUSY		= 4,
+	DFU_STATE_dfuDNLOAD_IDLE	= 5,
+	DFU_STATE_dfuMANIFEST_SYNC	= 6,
+	DFU_STATE_dfuMANIFEST		= 7,
+	DFU_STATE_dfuMANIFEST_WAIT_RST	= 8,
+	DFU_STATE_dfuUPLOAD_IDLE	= 9,
+	DFU_STATE_dfuERROR		= 10
+};
+
+#endif /* USB_DFU_H */

+ 174 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/www/build.html

@@ -0,0 +1,174 @@
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-US">
+
+<head>
+	<title>Building dfu-util from source</title>
+	<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
+	<meta name="author" content="Tormod Volden" />
+	<meta name="keywords" content="dfu-util, build, compile" />
+	<meta name="description" content="How to build dfu-util from source" />
+	<link rel="icon" type="image/png" href="favicon.ico" />
+	<link rel="stylesheet" type="text/css" href="simple.css" media="screen, print" />
+</head>
+
+<body>
+<div id="middlebox">
+    <h1>How to build dfu-util from source</h1>
+
+<h2>Prerequisites for building from git</h2>
+<h3>Mac OS X</h3>
+<p>
+First install MacPorts (and if you are on 10.6 or older, the Java Developer Package) and then run:
+</p>
+<pre>
+	sudo port install libusb-devel git-core
+</pre>
+
+<h3>FreeBSD</h3>
+<pre>
+	sudo pkg_add -r git pkgconf
+</pre>
+
+<h3>Ubuntu and Debian and derivatives</h3>
+<pre>
+	sudo apt-get build-dep dfu-util
+	sudo apt-get install libusb-1.0-0-dev
+</pre>
+
+<h2>Get the source code and build it</h2>
+<p>
+The first time you will have to clone the git repository:
+</p>
+<pre>
+	git clone git://git.code.sf.net/p/dfu-util/dfu-util
+	cd dfu-util
+</pre>
+<p>
+If you later want to update to latest git version, just run this:
+</p>
+<pre>
+	make maintainer-clean
+	git pull
+</pre>
+<p>
+To build the source:
+</p>
+<pre>
+	./autogen.sh
+	./configure  # on most systems
+	make
+</pre>
+
+<p>
+If you are building on Mac OS X, replace the ./configure command with:
+</p>
+<pre>
+	./configure --libdir=/opt/local/lib --includedir=/opt/local/include  # on MacOSX only
+</pre>
+
+<p>
+Your dfu-util binary will be inside the src folder. Use it from there, or install it to /usr/local/bin by running "sudo make install". 
+</p>
+
+<h2>Cross-building for Windows</h2>
+
+<p>
+Windows binaries can be built in a <a href="http://mingw.org/">MinGW</a>
+environment, on a Windows computer or cross-hosted in another OS.
+To build it on a Debian or Ubuntu host, first install build dependencies:
+</p>
+<pre>
+	sudo apt-get build-dep libusb-1.0-0 dfu-util
+	sudo apt-get install mingw32
+</pre>
+
+<p>
+The below example builds dfu-util 0.8 and libusb 1.0.20 from unpacked release
+tarballs. If you instead build from git, you will have to run "./autogen.sh"
+before running the "./configure" steps.
+</p>
+
+<pre>
+mkdir -p build
+cd libusb-1.0.20
+PKG_CONFIG_PATH=$PWD/../build/lib/pkgconfig ./configure \
+    --host=i586-mingw32msvc --prefix=$PWD/../build
+make
+make install
+cd ..
+
+cd dfu-util-0.8
+PKG_CONFIG_PATH=$PWD/../build/lib/pkgconfig ./configure \
+    --host=i586-mingw32msvc --prefix=$PWD/../build
+make
+make install
+cd ..
+</pre>
+The build files will now be in build/bin.
+<p>
+
+<h2>Building on Windows using MinGW-w64 from MSYS2</h2>
+
+<p>
+This assumes using release tarballs or having run ./autogen.sh on 
+the git sources.
+</p>
+
+<p>
+First install MSYS2 from the <a href="http://msys2.github.io/">MSYS2 installer</a> home page.
+</p>
+
+<p>
+To avoid interference from other software on your computer, set a clean path in the MSYS window before running the upgrade commands:
+</p>
+<pre>
+PATH=/usr/local/bin:/usr/bin:/bin:/opt/bin
+
+update-core
+pacman -Su
+pacman -Sy
+</pre>
+
+Close all MSYS windows and open a new one to install the toolchain:
+<pre>
+PATH=/usr/local/bin:/usr/bin:/bin:/opt/bin
+
+pacman -S mingw-w64-x86_64-gcc
+pacman -S make
+</pre>
+
+Now open a MINGW64 shell to build libusb and dfu-util:
+<pre>
+PATH=/mingw64/bin:/usr/local/bin:/usr/bin:/bin
+
+cd libusb-1.0.20
+./configure --prefix=$PWD/../build
+make
+make install
+cd ..
+
+cd dfu-util-0.9
+./configure USB_CFLAGS="-I$PWD/../build/include/libusb-1.0" \
+            USB_LIBS="-L $PWD/../build/lib -lusb-1.0" --prefix=$PWD/../build
+make
+make install
+cd ..
+</pre>
+To link libusb statically into dfu-util.exe use instead of only "make":
+<pre>
+make LDFLAGS=-static
+</pre>
+The built executables (and DLL) will now be in the build/bin folder.
+
+<p>
+[<a href="index.html">Back to dfu-util main page</a>]
+</p>
+      <p id="footer">
+        &copy;2014&ndash;2016 Tormod Volden &mdash; Valid <a href="http://validator.w3.org/check?uri=referer" title="validate XHTML">XHTML</a> &amp; <a href="http://jigsaw.w3.org/css-validator" title="validate CSS">CSS</a>
+      </p>
+</div>
+</body>
+</html>

+ 414 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/www/dfu-util.1.html

@@ -0,0 +1,414 @@
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<HTML><HEAD><TITLE>Man page of DFU-UTIL</TITLE>
+<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
+</HEAD><BODY>
+<H1>DFU-UTIL(1)</H1>
+
+<A NAME="lbAB">&nbsp;</A>
+<H2>NAME</H2>
+
+dfu-util - Device firmware update (DFU) USB programmer
+<A NAME="lbAC">&nbsp;</A>
+<H2>SYNOPSIS</H2>
+
+
+<DL COMPACT>
+<DT>
+<B>dfu-util</B>
+
+<B>-l </B>
+
+[<B>-v</B>]
+
+[<B>-d</B>
+
+<I>vid:pid</I>[,<I>vid:pid</I>]]
+
+[<B>-p</B>
+
+<I>path</I>]
+
+[<B>-c</B>
+
+<I>configuration</I>]
+
+[<B>-i</B>
+
+<I>interface</I>]
+
+[<B>-a</B>
+
+<I>alt-intf</I>]
+
+[<B>-S</B>
+
+<I>serial</I>[,<I>serial</I>]]
+
+
+<DT>
+<B>dfu-util</B>
+
+[<B>-v</B>]
+
+[<B>-d</B>
+
+<I>vid:pid</I>[,<I>vid:pid</I>]]
+
+[<B>-p</B>
+
+<I>path</I>]
+
+[<B>-c</B>
+
+<I>configuration</I>]
+
+[<B>-i</B>
+
+<I>interface</I>]
+
+[<B>-a</B>
+
+<I>alt-intf</I>]
+
+[<B>-S</B>
+
+<I>serial</I>[,<I>serial</I>]]
+
+[<B>-t</B>
+
+<I>size</I>]
+
+[<B>-Z</B>
+
+<I>size</I>]
+
+[<B>-s</B>
+
+<I>address</I>]
+
+[<B>-R</B>]
+
+[<B>-D</B>|<B>-U</B>
+
+<I>file</I>]
+
+
+<DT>
+<B>dfu-util</B>
+
+[<B>-hV</B>]
+
+</DL>
+<A NAME="lbAD">&nbsp;</A>
+<H2>DESCRIPTION</H2>
+
+<B>dfu-util</B>
+
+is a program that implements the host (computer) side of the USB DFU
+(Universal Serial Bus Device Firmware Upgrade) protocol.
+<P>
+dfu-util communicates with devices that implement the device side of the
+USB DFU protocol, and is often used to upgrade the firmware of such
+devices.
+<A NAME="lbAE">&nbsp;</A>
+<H2>OPTIONS</H2>
+
+<DL COMPACT>
+<DT><B>-l, --list</B>
+
+<DD>
+List the currently attached DFU capable USB devices.
+<DT><B>-d, --device</B> [<I>Run-Time VENDOR</I>]:[<I>Run-Time PRODUCT</I>][,[<I>DFU Mode VENDOR</I>]:[<I>DFU Mode PRODUCT</I>]]
+
+<DD>
+<DL COMPACT><DT><DD>
+Specify run-time and/or DFU mode vendor and/or product IDs of the DFU device
+to work with. <B>VENDOR</B> and <B>PRODUCT</B> are hexadecimal numbers (no prefix
+needed), &quot;*&quot; (match any), or &quot;-&quot; (match nothing). By default, any DFU capable
+device in either run-time or DFU mode will be considered.
+<P>
+If you only have one standards-compliant DFU device attached to your computer,
+this parameter is optional. However, as soon as you have multiple DFU devices
+connected, dfu-util will detect this and abort, asking you to specify which
+device to use.
+<P>
+If only run-time IDs are specified (e.g. &quot;<B>--device 1457:51ab</B>&quot;), then in
+addition to the specified run-time IDs, any DFU mode devices will also be
+considered. This is beneficial to allow a DFU capable device to be found
+again after a switch to DFU mode, since the vendor and/or product ID of a
+device usually changes in DFU mode.
+<P>
+If only DFU mode IDs are specified (e.g. &quot;<B>--device ,951:26</B>&quot;), then all
+run-time devices will be ignored, making it easy to target a specific device in
+DFU mode.
+<P>
+If both run-time and DFU mode IDs are specified (e.g. &quot;<B>--device
+1457:51ab,:2bc</B>&quot;), then unspecified DFU mode components will use the run-time
+value specified.
+<P>
+Examples:
+<DL COMPACT>
+<DT><B>--device 1457:51ab,951:26</B>
+
+<DD>
+<BR>
+
+Work with a device in run-time mode with
+vendor ID 0x1457 and product ID 0x51ab, or in DFU mode with vendor ID 0x0951
+and product ID 0x0026
+<P>
+<DT><B>--device 1457:51ab,:2bc</B>
+
+<DD>
+<BR>
+
+Work with a device in run-time mode with vendor ID 0x1457 and product ID
+0x51ab, or in DFU mode with vendor ID 0x1457 and product ID 0x02bc
+<P>
+<DT><B>--device 1457:51ab</B>
+
+<DD>
+<BR>
+
+Work with a device in run-time mode with vendor ID 0x1457 and product ID
+0x51ab, or in DFU mode with any vendor and product ID
+<P>
+<DT><B>--device ,951:26</B>
+
+<DD>
+<BR>
+
+Work with a device in DFU mode with vendor ID 0x0951 and product ID 0x0026
+<P>
+<DT><B>--device *,-</B>
+
+<DD>
+<BR>
+
+Work with any device in run-time mode, and ignore any device in DFU mode
+<P>
+<DT><B>--device ,</B>
+
+<DD>
+<BR>
+
+Ignore any device in run-time mode, and Work with any device in DFU mode
+</DL>
+</DL>
+
+<DT><B>-p, --path</B> BUS-PORT. ... .PORT
+
+<DD>
+Specify the path to the DFU device.
+<DT><B>-c, --cfg</B> CONFIG-NR
+
+<DD>
+Specify the configuration of the DFU device. Note that this is only used for matching, the configuration is not set by dfu-util.
+<DT><B>-i, --intf</B> INTF-NR
+
+<DD>
+Specify the DFU interface number.
+<DT><B>-a, --alt</B> ALT
+
+<DD>
+Specify the altsetting of the DFU interface by name or by number.
+<DT><B>-S, --serial</B> [<I>Run-Time SERIAL</I>][,[<I>DFU Mode SERIAL</I>]]
+
+<DD>
+Specify the run-time and DFU mode serial numbers used to further restrict
+device matches.  If multiple, identical DFU devices are simultaneously
+connected to a system then vendor and product ID will be insufficient for
+targeting a single device.  In this situation, it may be possible to use this
+parameter to specify a serial number which also must match.
+<P>
+If only a single serial number is specified, then the same serial number is
+used in both run-time and DFU mode. An empty serial number will match any
+serial number in the corresponding mode.
+<DT><B>-t, --transfer-size  SIZE</B>
+
+<DD>
+Specify the number of bytes per USB transfer. The optimal value is
+usually determined automatically so this option is rarely useful. If
+you need to use this option for a device, please report it as a bug.
+<DT><B>-Z, --upload-size  SIZE</B>
+
+<DD>
+Specify the expected upload size, in bytes.
+<DT><B>-U, --upload</B> FILE
+
+<DD>
+Read firmware from device into
+<B>FILE</B>.
+
+<DT><B>-D, --download</B> FILE
+
+<DD>
+Write firmware from
+<B>FILE</B>
+
+into device. When
+<B>FILE</B>
+
+is -, the firmware is read from stdin.
+<DT><B>-R, --reset</B>
+
+<DD>
+Issue USB reset signalling after upload or download has finished.
+<DT><B>-s, --dfuse-address</B> address
+
+<DD>
+Specify target address for raw binary download/upload on DfuSe devices. Do
+<B>not</B>
+
+use this for downloading DfuSe (.dfu) files. Modifiers can be added
+to the address, separated by a colon, to perform special DfuSE commands such
+as &quot;leave&quot; DFU mode, &quot;unprotect&quot; and &quot;mass-erase&quot; flash memory.
+<DT><B>-v, --verbose</B>
+
+<DD>
+Print more information about dfu-util's operation. A second
+<B>-v</B>
+
+will turn on verbose logging of USB requests. Repeat this option to further
+increase verbosity.
+<DT><B>-h, --help</B>
+
+<DD>
+Show a help text and exit.
+<DT><B>-V, --version</B>
+
+<DD>
+Show version information and exit.
+</DL>
+<A NAME="lbAF">&nbsp;</A>
+<H2>EXAMPLES</H2>
+
+<A NAME="lbAG">&nbsp;</A>
+<H3>Using dfu-util in the OpenMoko project</H3>
+
+(with the Neo1973 hardware)
+<P>
+
+Flashing the rootfs:
+<BR>
+
+<B>  $ dfu-util -a rootfs -R -D /path/to/openmoko-devel-image.jffs2</B>
+
+<P>
+
+Flashing the kernel:
+<BR>
+
+<B>  $ dfu-util -a kernel -R -D /path/to/uImage</B>
+
+<P>
+
+Flashing the bootloader:
+<BR>
+
+<B>  $ dfu-util -a u-boot -R -D /path/to/u-boot.bin</B>
+
+<P>
+
+Copying a kernel into RAM:
+<BR>
+
+<B>  $ dfu-util -a 0 -R -D /path/to/uImage</B>
+
+<P>
+Once this has finished, the kernel will be available at the default load
+address of 0x32000000 in Neo1973 RAM.
+<B>Note:</B>
+
+You cannot transfer more than 2MB of data into RAM using this method.
+<P>
+<A NAME="lbAH">&nbsp;</A>
+<H3>Using dfu-util with a DfuSe device</H3>
+
+<P>
+
+Flashing a
+<B>.dfu</B>
+
+(special DfuSe format) file to the device:
+<BR>
+
+<B>  $ dfu-util -a 0 -D /path/to/dfuse-image.dfu</B>
+
+<P>
+
+Reading out 1 KB of flash starting at address 0x8000000:
+<BR>
+
+<B>  $ dfu-util -a 0 -s 0x08000000:1024 -U newfile.bin</B>
+
+<P>
+
+Flashing a binary file to address 0x8004000 of device memory and
+ask the device to leave DFU mode:
+<BR>
+
+<B>  $ dfu-util -a 0 -s 0x08004000:leave -D /path/to/image.bin</B>
+
+
+<A NAME="lbAI">&nbsp;</A>
+<H2>BUGS</H2>
+
+Please report any bugs to the dfu-util bug tracker at
+<B><A HREF="http://sourceforge.net/p/dfu-util/tickets/">http://sourceforge.net/p/dfu-util/tickets/</A></B>.
+
+Please use the
+<I>--verbose</I> option (repeated as necessary) to provide more
+
+information in your bug report.
+<A NAME="lbAJ">&nbsp;</A>
+<H2>SEE ALSO</H2>
+
+The dfu-util home page is
+<B><A HREF="http://dfu-util.sourceforge.net">http://dfu-util.sourceforge.net</A></B>
+
+<A NAME="lbAK">&nbsp;</A>
+<H2>HISTORY</H2>
+
+dfu-util was originally written for the OpenMoko project by
+Weston Schmidt &lt;<A HREF="mailto:weston_schmidt@yahoo.com">weston_schmidt@yahoo.com</A>&gt; and 
+Harald Welte &lt;<A HREF="mailto:hwelte@hmw-consulting.de">hwelte@hmw-consulting.de</A>&gt;. Over time, nearly complete
+support of DFU 1.0, DFU 1.1 and DfuSe (&quot;1.1a&quot;) has been added.
+<A NAME="lbAL">&nbsp;</A>
+<H2>LICENCE</H2>
+
+<B>dfu-util</B>
+
+is covered by the GNU General Public License (GPL), version 2 or later.
+<A NAME="lbAM">&nbsp;</A>
+<H2>COPYRIGHT</H2>
+
+This manual page was originally written by Uwe Hermann &lt;<A HREF="mailto:uwe@hermann-uwe.de">uwe@hermann-uwe.de</A>&gt;,
+and is now part of the dfu-util project.
+<P>
+
+<HR>
+<A NAME="index">&nbsp;</A><H2>Index</H2>
+<DL>
+<DT><A HREF="#lbAB">NAME</A><DD>
+<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
+<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
+<DT><A HREF="#lbAE">OPTIONS</A><DD>
+<DT><A HREF="#lbAF">EXAMPLES</A><DD>
+<DL>
+<DT><A HREF="#lbAG">Using dfu-util in the OpenMoko project</A><DD>
+<DT><A HREF="#lbAH">Using dfu-util with a DfuSe device</A><DD>
+</DL>
+<DT><A HREF="#lbAI">BUGS</A><DD>
+<DT><A HREF="#lbAJ">SEE ALSO</A><DD>
+<DT><A HREF="#lbAK">HISTORY</A><DD>
+<DT><A HREF="#lbAL">LICENCE</A><DD>
+<DT><A HREF="#lbAM">COPYRIGHT</A><DD>
+</DL>
+<HR>
+This document was created by man2html,
+using the doc/dfu-util.1 manual page from dfu-util 0.8.<BR>
+Time: 14:40:57 GMT, September 13, 2014
+</BODY>
+</HTML>

+ 135 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/www/dfuse.html

@@ -0,0 +1,135 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-US">
+
+<head>
+	<title>DfuSe and dfu-util</title>
+	<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
+	<meta name="author" content="Tormod Volden" />
+	<meta name="keywords" content="dfu-util, DfuSe, ST DFU extensions" />
+	<meta name="description" content="How to use dfu-util with DfuSe devices" />
+	<link rel="icon" type="image/png" href="favicon.ico" />
+	<link rel="stylesheet" type="text/css" href="simple.css" media="screen, print" />
+</head>
+
+<body>
+<div id="middlebox">
+    <h1>Using dfu-util with DfuSe devices</h1>
+      <h2>DfuSe</h2>
+      <p>
+	DfuSe (DFU with ST Microsystems extensions) is a protocol based on
+	DFU 1.1. However, in expanding the functionality of the DFU protocol,
+	ST Microsystems broke all compatibility with the DFU 1.1 standard.
+	DfuSe devices report the DFU version as "1.1a".
+      </p>
+      <p>
+	DfuSe can be used to download firmware and other data
+	from a host computer to a conforming device (or upload in the
+	opposite direction) over USB similar to standard DFU.
+      </p>
+      <p>
+	The main difference from standard DFU is that the target address in
+	the device (flash) memory is specified by the host, so that a
+	download can be performed to parts of the device memory. The host
+	program is also responsible for erasing flash pages before they
+	are written to.
+      </p>
+      <h2>.dfu files</h2>
+      <p>
+	A special file format is defined by ST Microsystems to carry firmware
+	for DfuSe devices. The file contains target information such as address
+	and alternate interface information in addition to the binary data.
+	Several blocks of binary data can be combined in one .dfu file.
+      </p>
+      <h2>Alternate interfaces</h2>
+      <p>
+	Different memory locations of the device may have different
+	characteristics that the host program (dfu-util) has to take
+	into considerations, such as flash memory page size, read-only
+	versus read-write segments, the need to erase, and so on.
+	These parameters are reported by the device in the string
+	descriptors meant for describing the USB interfaces.
+	The host program decodes these strings to build a memory map of
+	the device. Different memory units or address spaces are listed
+	in separate alternate interface settings that must be selected
+	according to the memory unit to access.
+      </p>
+      <p>
+	Note that dfu-util leaves it to the user to select alternate
+	interface. When parsing a .dfu file it will skip file segments
+	not matching the selected alternate interface. Also, some
+	DfuSe device firmware implementations ignore the setting of
+	alternate interface and deduct the memory unit from the
+	address, since they have no address space overlap.
+      </p>
+      <h2>DfuSe special commands</h2>
+      <p>
+	DfuSe special commands are used by the host program during normal
+	downloads or uploads, such as SET_ADDRESS and ERASE_PAGE. Also
+	the normal DFU_DNLOAD and DFU_UPLOAD commands have special
+	implementations in DfuSe.
+	Many DfuSe devices also support commands to leave DFU mode,
+	read unprotect the flash memory or mass erase the flash memory.
+	dfu-util (from version 0.7)
+	supports adding "leave", "unprotect", or "mass-erase"
+	to the -s option argument to send such requests in combination
+	with a download request. These modifiers are separated with a colon.
+      </p>
+      <p>
+	Some DfuSe devices have their DfuSe bootloader running from flash
+	memory. Erasing the whole flash memory would therefore destroy
+	the DfuSe bootloader itself and practically brick the device
+	for most users. Any use of modifiers such as "unprotect"
+	and "mass-erase" therefore needs to be combined with the "force"
+	modifer. This is not included in the examples, to not encourage
+	ignorant users to copy and paste such instructions and shoot
+	themselves in the foot.
+      </p>
+      <p>
+	Devices based on for instance STM32F103 all run the bootloader
+	from flash, since there is no USB bootloader in ROM.
+      </p>
+      <p>
+	For instance STM32F107, STM32F2xx and STM32F4xx devices have a
+	DfuSe bootloader in ROM, so the flash can be erased while
+	keeping the device available for USB DFU transfers as long
+	as the device designers use this built-in bootloader and have
+	not implemented another DfuSe bootloader in flash that the user is
+	dependent upon.
+      </p>
+      <p>
+	Well-written bootloaders running from flash will report their
+	own memory region as read-only and not eraseable, but this does
+	not prevent dfu-util from sending a "unprotect" or "mass-erase"
+	request which overrides this, if the user insists.
+      </p>
+      <h2>Example usage</h2>
+      <p>
+       Flashing a .dfu (special DfuSe format) file to the device:
+      </p>
+	<pre>
+         $ dfu-util -a 0 -D /path/to/dfuse-image.dfu
+	</pre>
+      <p>
+       Reading out 1 KB of flash starting at address 0x8000000:
+      </p>
+	<pre>
+         $ dfu-util -a 0 -s 0x08000000:1024 -U newfile.bin
+	</pre>
+      <p>
+       Flashing  a  binary  file to address 0x8004000 of device memory and ask
+       the device to leave DFU mode:
+      </p>
+	<pre>
+         $ dfu-util -a 0 -s 0x08004000:leave -D /path/to/image.bin
+	</pre>
+      <p>
+	[<a href="index.html">Back to dfu-util main page</a>]
+      </p>
+      <p id="footer">
+        &copy;2012 Tormod Volden &mdash; Valid <a href="http://validator.w3.org/check?uri=referer" title="validate XHTML">XHTML</a> &amp; <a href="http://jigsaw.w3.org/css-validator" title="validate CSS">CSS</a>
+      </p>
+</div>
+</body>
+</html>

+ 118 - 0
lib/SCSI2SD/src/scsi2sd-util6/dfu-util/www/index.html

@@ -0,0 +1,118 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-US">
+
+<head>
+	<title>dfu-util Homepage</title>
+	<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
+	<meta name="author" content="Stefan Schmidt" />
+	<meta name="keywords" content="dfu-util, DFU, Device Firmware Upgrade, linux" />
+	<meta name="description" content="dfu-util Project Homepage" />
+	<link rel="icon" type="image/png" href="favicon.ico" />
+	<link rel="stylesheet" type="text/css" href="simple.css" media="screen, print" />
+</head>
+
+<body>
+<div id="middlebox">
+    <h1>dfu-util - Device Firmware Upgrade Utilities</h1>
+      <h2>Description</h2>
+      <p>
+	dfu-util is a host side implementation of the <a
+	href="http://www.usb.org/developers/devclass_docs/usbdfu10.pdf"
+	title="DFU revision 1.0"> DFU 1.0</a> and <a
+	href="http://www.usb.org/developers/devclass_docs/DFU_1.1.pdf"
+	title="DFU revision 1.1">DFU 1.1</a> specifications of the USB forum.
+
+	DFU is intended to download and upload firmware to/from devices connected
+	over USB. It ranges from small devices like micro-controller boards
+	to mobile phones. Using dfu-util you can download firmware to your
+	DFU-enabled device or upload firmware from it. dfu-util has been
+	tested with the Openmoko Neo1973 and Freerunner and many other devices.
+	</p>
+	<p>
+	See the <a href="dfu-util.1.html">manual page</a> for examples of use.
+	</p>
+	<h2>Supported Devices</h2>
+	<ul>
+	<li><a href="http://wiki.openmoko.org/wiki/Neo_1973">Openmoko Neo1973</a></li>
+	<li><a href="http://wiki.openmoko.org/wiki/Neo_FreeRunner">Openmoko Freerunner</a></li>
+	<li><a href="http://leaflabs.com/Maple">Leaflabs Maple</a></li>
+	<li><a href="http://www.openpcd.org/">OpenPCD and OpenPICC</a></li>
+	<li><a href="http://downloads.qi-hardware.com/people/werner/wpan/web/">Qi Hardware ATUSB</a> (use dfu-util 0.7)</li>
+	<li><a href="http://bb.osmocom.org/trac/wiki/SIMtrace">Osmocom SIMtrace</a></li>
+	<li>Many devices using the <a href="dfuse.html">DfuSe DFU extension</a> from ST, for instance:
+		<ul>
+		<li><a
+href="http://www.seeedstudio.com/depot/micro-digital-storage-oscilloscopedso-nano-p-512.html">DSO nano</a></li>
+		<li><a href="https://www.particle.io/">Spark Core / Particle Photon</a></li>
+		<li>STM32F2/F3/F4 built-in bootloader</li>
+		<li>Some STR750-based devices, e.g. USB2CAN</li>
+		</ul></li>
+	</ul>
+	<h2>Releases</h2>
+	<p>
+	Releases of the dfu-util software can be found in the <a
+	href="http://dfu-util.sourceforge.net/releases/" title="Releases">
+	releases</a> folder.
+	The current release is 0.9.
+	</p>
+	<p>
+	We offer binaries for Microsoft Windows and some other platforms.
+	dfu-util uses libusb 1.0 to access your device, so
+	on Windows you have to register the device with the WinUSB driver
+	(alternatively libusb-win32 or libusbK), please see the <a
+	href="https://github.com/libusb/libusb/wiki/Windows#How_to_use_libusb_on_Windows">libusb wiki</a>
+	for more details.
+	</p>
+	<p>
+	Mac OS X users can also get dfu-util from <a href="http://brew.sh/">Homebrew</a> with "brew install dfu-util" or from <a href="http://www.macports.org/">MacPorts</a>.
+	</p>
+	<p>
+	Most Linux distributions ship dfu-util in binary packages for those
+	who do not want to compile dfu-util from source.
+	On Debian, Ubuntu, Fedora and Gentoo you can install it through the
+	normal software package tools. For other distributions
+(namely OpenSuSe, Mandriva, and CentOS) Holger Freyther was kind enough to
+provide binary packages through the <a
+	href="https://build.opensuse.org/package/show?package=dfu-util&amp;project=home%3Azecke23">Open Build Service</a>.
+	</p>
+	<h2>Development</h2>
+	<p>
+	Development happens in a GIT repository. Browse it via the <a
+href="http://sourceforge.net/p/dfu-util/dfu-util/" title="Git repository">web
+interface</a> or clone it with:
+	</p>
+	<pre>
+	git clone git://git.code.sf.net/p/dfu-util/dfu-util
+	</pre>
+	<p>
+	See our <a href="build.html">build instructions</a> for how to
+	build the source on different platforms.
+	</p>
+	<h2>License</h2>
+	<p>
+	This software is licensed under the <a
+	href="http://www.gnu.org/licenses/gpl-2.0.html"> GPL version 2</a>.
+	</p>
+	<h2>Contact</h2>
+	<p>
+	If you have questions about the development or use of dfu-util please
+	use the <a href="http://sourceforge.net/p/dfu-util/tickets">bug tracker</a>
+	until we have reestablished our mailing list.
+	</p>
+	<h2>People</h2>
+	<p>
+	dfu-util was originally written by 
+	Harald Welte partially based on code from <a
+	href="http://dfu-programmer.sourceforge.net/">
+	dfu-programmer 0.4</a> and is currently maintained by <a
+	href="http://www.datenfreihafen.org/">Stefan Schmidt</a> and
+	Tormod Volden.
+	</p>
+	<p id="footer">
+        &copy;2010-2016 Stefan Schmidt & Tormod Volden &mdash; Valid <a href="http://validator.w3.org/check?uri=referer" title="validate XHTML">XHTML</a> &amp; <a href="http://jigsaw.w3.org/css-validator" title="validate CSS">CSS</a>
+      </p>
+</div>
+</body>
+</html>

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff