diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cda454f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +XLoad/xload +XLoad/*.o +XLoad/FTDI/*.dylib diff --git a/README-macOS.md b/README-macOS.md new file mode 100644 index 0000000..fd37aec --- /dev/null +++ b/README-macOS.md @@ -0,0 +1,50 @@ +# XLoad for macOS + +This repository includes a port of the XLoad tool to macOS. The codebase has been modified to compile using `clang++` while maintaining compatibility. + +## Changes Made + +- **File Encodings:** The original `XLoad.cpp` and `ftd2xx.h` files were converted from UTF-16LE/Latin-1 to standard UTF-8. +- **POSIX API Alternatives:** The Windows-specific terminal APIs (``, `Sleep`, `GetAsyncKeyState`, and `SetConsoleTextAttribute`) were replaced with POSIX-compliant equivalents using ``, ``, and ``. +- **FTDI macOS Compatibility:** A missing `WinTypes.h` shim file was added to the `FTDI/` directory to define the required Windows types (`DWORD`, `HANDLE`, `BOOL`, etc.) on UNIX-like platforms. Path separators in `#include` directives were converted to forward slashes. +- **Compiler Warnings:** Addressed compiler warnings arising from mismatched types on macOS (such as `ULONG` format specifiers for `printf` and `std::min` parameter types). +- **Makefile:** A `Makefile` was included to simplify compilation via the command line. + +## How to Compile and Run on macOS + +### Prerequisites + +You need the official FTDI D2XX drivers for macOS: + +1. Download the latest **D2XX Drivers for macOS** from the [FTDI official website](https://ftdichip.com/drivers/d2xx-drivers/). +2. Mount the downloaded `.dmg` image. +3. Extract the `libftd2xx.X.X.X.dylib` file from the image (e.g., `release/build/libftd2xx.1.4.30.dylib`) and place it in the `XLoad/FTDI/` directory, renaming it to `libftd2xx.dylib`. + +*(Alternatively, you can install the library system-wide in `/usr/local/lib/` and update the `LDFLAGS` in the `Makefile` accordingly.)* + +### Compilation + +Open a terminal, navigate to the `XLoad` source folder, and run `make`: + +```bash +cd XLoad +make +``` + +### Running the Tool + +After a successful build, you can run the executable directly from the source directory: + +```bash +./xload +``` + +To view the available commands: +```bash +./xload -h +``` + +### Troubleshooting + +- **Library not loaded:** If you receive a `dyld: Library not loaded` error when trying to run `./xload`, ensure that `libftd2xx.dylib` is properly placed in the `XLoad/FTDI/` directory. The binary is configured to look for the library relative to its execution path using an `rpath`. +- **Permissions:** If your device is claimed by Apple's built-in serial port driver (preventing `xload` from accessing it), you may need to install the `D2xxHelper` tool, also available on the FTDI driver download page. diff --git a/XLoad/FTDI/WinTypes.h b/XLoad/FTDI/WinTypes.h new file mode 100644 index 0000000..7742792 --- /dev/null +++ b/XLoad/FTDI/WinTypes.h @@ -0,0 +1,60 @@ +#ifndef _WINTYPES_H_ +#define _WINTYPES_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned char UCHAR; +typedef unsigned short USHORT; +typedef unsigned int UINT; +typedef unsigned long ULONG; +typedef void *PVOID; +typedef void *LPVOID; +typedef void *HANDLE; +typedef uint32_t DWORD; +typedef DWORD *LPDWORD; +typedef ULONG *PULONG; +typedef unsigned short WORD; +typedef WORD *LPWORD; +typedef unsigned char BYTE; +typedef uint8_t *PUCHAR; +typedef char *PCHAR; +typedef char *LPCTSTR; +typedef int *LPLONG; +typedef unsigned long ULONG_PTR; +typedef int BOOL; + +#define WINAPI +#define WINBASEAPI + +// Additional overrides for ftd2xx.h structures on non-windows +typedef struct _SECURITY_ATTRIBUTES { + DWORD nLength; + LPVOID lpSecurityDescriptor; + bool bInheritHandle; +} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; + +typedef struct _OVERLAPPED { + ULONG_PTR Internal; + ULONG_PTR InternalHigh; + union { + struct { + DWORD Offset; + DWORD OffsetHigh; + } DUMMYSTRUCTNAME; + PVOID Pointer; + } DUMMYUNIONNAME; + HANDLE hEvent; +} OVERLAPPED, *LPOVERLAPPED; + +#ifdef __cplusplus +} +#endif + +#endif // _WINTYPES_H_ diff --git a/XLoad/FTDI/ftd2xx.h b/XLoad/FTDI/ftd2xx.h index ec02ac6..58dd0c7 100644 --- a/XLoad/FTDI/ftd2xx.h +++ b/XLoad/FTDI/ftd2xx.h @@ -1,6 +1,6 @@ /*++ -Copyright © 2001-2011 Future Technology Devices International Limited +Copyright 2001-2011 Future Technology Devices International Limited THIS SOFTWARE IS PROVIDED BY FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/XLoad/Makefile b/XLoad/Makefile new file mode 100644 index 0000000..0e2f5b9 --- /dev/null +++ b/XLoad/Makefile @@ -0,0 +1,20 @@ +CXX = clang++ +CXXFLAGS = -std=c++11 -Wall -O2 -I. -I./FTDI +LDFLAGS = -L./FTDI -Wl,-rpath,./FTDI -lftd2xx + +TARGET = xload +SRCS = XLoad.cpp +OBJS = $(SRCS:.cpp=.o) + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CXX) $(OBJS) -o $(TARGET) $(LDFLAGS) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) $(TARGET) + +.PHONY: all clean diff --git a/XLoad/XLoad.cpp b/XLoad/XLoad.cpp index 7fae752..8c413e8 100644 Binary files a/XLoad/XLoad.cpp and b/XLoad/XLoad.cpp differ