Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
XLoad/xload
XLoad/*.o
XLoad/FTDI/*.dylib
50 changes: 50 additions & 0 deletions README-macOS.md
Original file line number Diff line number Diff line change
@@ -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 (`<windows.h>`, `Sleep`, `GetAsyncKeyState`, and `SetConsoleTextAttribute`) were replaced with POSIX-compliant equivalents using `<unistd.h>`, `<termios.h>`, and `<fcntl.h>`.
- **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.
60 changes: 60 additions & 0 deletions XLoad/FTDI/WinTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef _WINTYPES_H_
#define _WINTYPES_H_

#include <stdbool.h>
#include <stdint.h>
#include <pthread.h>
#include <sys/time.h>

#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_
2 changes: 1 addition & 1 deletion XLoad/FTDI/ftd2xx.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 20 additions & 0 deletions XLoad/Makefile
Original file line number Diff line number Diff line change
@@ -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
Binary file modified XLoad/XLoad.cpp
Binary file not shown.