Skip to content

Instantly share code, notes, and snippets.

@vitorio
Last active January 4, 2023 19:10
Show Gist options
  • Save vitorio/c239128dea1a4af23031059d6ca32c35 to your computer and use it in GitHub Desktop.
Save vitorio/c239128dea1a4af23031059d6ca32c35 to your computer and use it in GitHub Desktop.
Compiling libusb and rpiboot natively on OS X within your home directory

NOTE: rpiboot doesn't actually work on recent OS X versions and/or Macs due to a bug in the RPi0/RPi1 chipset: https://www.raspberrypi.org/forums/viewtopic.php?f=98&t=90825

These instructions compile a native OS X version of rpiboot that lives in your home directory, and which cannot be moved around, but should always be discoverable by applications.

Assumes OS X with Xcode or Xcode command-line tools, not macports or homebrew

To install Xcode command-line tools in recent versions of OS X, open Terminal, type xcode-select --install and click "Install"

Older versions of OS X may need to manually download disk images of older versions of Xcode and/or the Xcode command-line tools, as various certificates may have expired (e.g. 10.7.4 requires a manual install from the Xcode 4.6.2 command-line tools image)

Download latest libusb (tested with 1.0.21) from https://sourceforge.net/projects/libusb/files/latest/download?source=files

Download latest rpiboot from https://github.com/raspberrypi/usbboot

Compile libusb, rpiboot

$ cd ~/Downloads/
$ cd libusb-1.0.21
$ ./configure --prefix=$HOME/
$ make
$ make install
$ cd ..
$ cd usbboot-master
$ cc -Wall -Wextra -g -o rpiboot main.c -lusb-1.0 -L$HOME/lib -I$HOME/include
$ cp -a rpiboot ~/bin

Now, your home directory has four new (probably) folders with libusb and rpiboot in them:

$ ls -al
drwxr-xr-x   25 username  1897370479    850 Aug 27 00:24 bin
drwxr-xr-x    5 username  1897370479    170 Aug 27 00:24 include
drwxr-xr-x   15 username  1897370479    510 Aug 27 00:23 lib
drwxr-xr-x    5 username  1897370479    170 Aug 27 00:20 share

The ~/lib folder is in the default search path for dynamic libraries, so any software that uses libusb should be able to automatically find it. These should always work without modification, even on OS X systems with System Integrity Protection (10.11 El Capitan and later), as long as they stay in ~/lib.

To compile libusb from HEAD (e.g. if you're using Sierra/High Sierra and it's not enumerating devices properly any more: libusb/libusb#303), you'll need autotools installed as well:

$ cd autoconf-2.69
$ ./configure --prefix=$HOME/
$ make
$ make install
$ export PATH="$HOME/bin:$PATH"
$ cd ../automake-1.15.1
$ ./configure --prefix=$HOME/
$ make
$ make install
$ cd ../libtool-2.4.6
$ ./configure --prefix=$HOME/
$ make
$ make install
$ cd ../libusb-master/
$ ./bootstrap.sh 
$ ./configure --prefix=$HOME/
$ make
$ make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment