Pre-built environment for Raspberry Pi cross-compiling and NFS booting

Hey all:

I’ve just released this: https://github.com/twobitcircus/rpi-build-and-boot

It uses Vagrant and Ansible to spin up a Virtualbox virtual machine that runs on Mac, Linux, or Windows(?). In no time at all, you’ll have an environment that:

  • Cross-compiles for the Raspberry Pi armv6l architecture.
  • NFS boots one or more Raspberry Pis. The root partition is loop-mounted from a .img file, so you can later dd it to an SD card for standalone operation.
  • Is ready to cross-compile OpenFrameworks applications and run them on a cluster of Raspberry Pis.
    You won’t have to do any of the things on the Raspberry Pi Cross-Compiling Guide page. I have contributed to that guide to make the process more smooth, but it’s still a mess.
    Here, Vagrant automates the process of setting up a Virtualbox virtual machine and Ansible automates the process of setting up the cross-compiler, the NFS server, and OpenFrameworks.

I’m really proud of it. Let me know if the setup-instructions are unclear, or if you encounter any problems!

11 Likes

Sounds cool! I get that you can edit and compile on a desktop machine but I am unclear on how the RPi OF apps are ran. Are they ran over a network or copied back locally to the RPi?

No copying necessary. The virtual machine owns the entire rpi filesystem and exports it via nfs. Any changes to that filesystem, for example by compiling, are immediately visible on all the rpis that are nfs booted.
I tend to execute the raspberry pi binaries using ssh over the network, a process I don’t detail in that readme. But that’s a feature of the show control system I’ve implemented on top of this base.
One of my first applications of this design pattern BTW was a specialized ofxomxplayer media player that shared media files located on the virtual machine.

Ok - so I just read the “Standalone Raspberry Pi” section.

Awesome to hear about the ofxOMXPlayer project - was the network access fast enough for video files?

I like this process as distcc is pretty fast but the library linking still takes a while.

Oh yeah.  Totally fast enough. I think the SD card bandwidth and the ethernet bandwidth are about equal.

just followed the tutorial, and i have projects compiling. as an example; i’ve been working on an rPi app that uses ofxUI and ofxTimeline. Previously it took >1 hour to compile on the Pi. It now takes a few seconds. Thanks.

It’s working good on my side too, but I can not apt-get update neither upgrade.
Any clue?

Another question… what is the best way to directly access/edit files within /opt/openframeworks from OSX? I tried Samba on the rPi image using the samba config file from my CMU_rpi image, then SMB into 10.0.0.101. That didn’t work. Any other options here?

Here’s what I’m using to edit/make projects with this setup… it seems to be working so far:

  • Place oF project in /vagrant/ on the VM. This is the same as the
    rpi-build-and-boot/ directory on your mac.

  • Edit and save files from that directory on your host machine (i’m
    using sublime text)

  • from the vagrant shell, use rsync -a to sync the project in
    /vagrant with /opt/openframeworks/apps/myApps

  • staying in the vagrant shell, rmake from /opt/openframeworks/apps/myApps/<projectFolder>

    I then set up an alias that will rsync, cd into the rPi project
    folder and rmake

It’s a clunky/ugly workaround, but it works. Please let me know if there is a more elegant workflow.

I’m going to keep reporting on my findings here… as I’d love to see this workflow become useful for everyone.

working with the wiringPi library is tricky, as Raspbian Wheezy doesn’t come with wiringPi already installed. From what I’m reading and experiencing, building wiringPi on this system is problematic.

So Far:

  • I’ve built wiringPi from the Pi (not from within the vagrant shell)
  • when I try to run any of the gpio commands (in particular i2cdetect) i get this error: /usr/local/bin/gpio: 1: /usr/local/bin/gpio: Syntax error: word unexpected (expecting ")")

If anyone has advice on building/using wiringPi from within this setup, please let me know. I’ll post what i find.

to make apt-get work on the Pi you need to give apt a proxy to reach the internet:

  • ssh into the pi
  • cd /etc/apt
  • sudo nano apt.conf
  • add these lines:
  • Acquire::http::proxy "http://10.0.0.1:8888"
  • Acquire::https::proxy "https://10.0.0.1:8888";
  • reboot

to give the NFS-booted Pi general access to internet (for git, etc.):
add a proxy to your ~/.bashrc

export http_proxy="http://10.0.0.1:8888"
export https_proxy="https://10.0.0.1:8888"

then reload your .bashrc with . ~/.bashrc

show me what it says on the screen.

Yes, there is!

Download NFS Manager on your
Mac.
Open it, and manually mount 10.0.0.1:/opt/raspberrypi/root to (wherever)
You can now edit the files in the rpi root partition directly.

This about how weird this is for a sec, though. You’re editing files on
your Mac which are NFS exported from your VM. Which are in turn
loop-mounted from an SD card. Which is in a directory on your Mac and made
available to your VM through magical VirtualBox drivers. But it works!

1 Like

​To get wiringPi working, I downloaded and built wiringPi on the pi
directly, rather than through the cross compiler (as you did). WiringPi
works great in OpenFrameworks, with both GPIO and i2c. However, note that
i2cdetect is NOT a wiringPi program… its from the i2c-tools package. Do
make sure that the i2c kernel modules are loaded into the Pi kernel:
https://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi/configuring-your-pi-for-i2c

I’ve never used the wiringPi gpio utility. I jumped straight into
programming the GPIO with OpenFrameworks and it worked.

I’ll post an example when I get back in town Monday.​

Thanks for the help… it turns out all of my problems were pretty much related not having an internet connection to the NFS mounted Pi. Just about everythign was resolved once i got that sorted. As for wiringPi, i’m currently compiling with a static version of the lib within the ofxWiringPi addon (per @jvcleave’s wiringPi example

I’ve just deployed my first project developed with this workflow on a standalone rPi. The project used slimmed down versions of ofxTimeline and ofxUI, which had previously taken 1-1.5 hours to compile on the pi. Using this workflow, each compile cycle took about 3 minutes.

@eric_gradman I’d like to help add to your read_me for this process. what’s the best way forward for that?

1 Like

Oh man, that’s cool.
Fork my repository, and send me pull requests!

1 Like

Thanks a lot for sharing!

this looks awesome! will try it out and report back how it goes!

Thanks A LOT!
It saves so much time compiling oF!

But I’m a newbie and have quite some difficulties to understand:

  1. where to put your project in order to compile them and sync them to the PI
    but especially how to turn the NFS boot “off” on the rpi SD to get a standalone image.
    I don’t really get what do to when you say:
  2. On the Raspberry Pi root partition, alter /etc/fstab and restore the mount point for /
  3. On the Raspberry Pi boot partition, remove the stuff after “rootwait”

do you make a sudo nano on fstab?
where to remove the stuff rootwait ?

Thanks for the help