(Almost) no-brainer linux virtual machine for firmware building

(Note: this is just an experiment. I’m not sure I’m going to do anything more with this, but it is geeky cool.)

Background: I’d much rather do firmware development on linux, but I don’t have a spare, energy-sucking linux box. I do, however, have a windows box with some disk space, and I also happen to like virtual machines.

So, just for grins, I wondered how hard it would be to create an automagically-downloaded and configured virtual linux system for building the firmware. It turns out to be quite simple.

If you install these programs on windows:

Then downloading, installing, and configuring a firmware build box is easy, as long as you don’t mind working from the command-line (like cmd.exe):

# cd to some convenient directory
git clone https://github.com/darrylo/sparkyvm.git
cd sparkyvm
vagrant up

Bang, done. At this point, you have a fully configured (and running) linux virtual machine, fully capable of building the spark firmware. (However, the vagrant up command can take 15-30+ minutes to run, and you also need maybe 90GB of free disk space.)

In fact, if you want to build the spark firmware:

# login to the system (no password required)
vagrant ssh

# Get sources and build everything:
cd /vagrant
/vagrant/firmware-init
/vagrant/firmware-build

# logout
exit

Done. At this point, the new firmware can be found as /vagrant/spark/core-firmware/build/core-firmware.bin. However, because /vagrant is shared between the virtual linux system and the windows host, you can use windows to transfer spark/core-firmware/build/core-firmware.bin to a core.

For more information, see here: https://github.com/darrylo/sparkyvm

7 Likes

This is a great idea. I haven’t played with Vagrant yet (though I’ve been meaning to). Any plans for something smaller than an 80GB disk image? Even with dynamic growth, space is still at a premium on my SSD.

It’s possible, but not by me.

The issue is that I’m using a preconfigured basic virtual machine from the vagrant folks, and they configured that virtual machine to have an 80GB disk. However, while it is some work, you can create your own smaller disk. (I can’t do it, because I don’t have any place that can host huge files.) The basic procedure is here: http://www.my-guides.net/en/guides/general-software/how-to-resize-a-virtualbox-disk-partition

The other things you need to know are:

  • The preconfigured .box image is actually an uncompressed tarball. You just extract the virtual disk (box-disk1.vmdk), and use that to create a smaller disk, which you then put back into the .box image.

  • The Vagrantfile (in my github project, not the one in the .box image) needs to be modified to point to your modified .box image. I’m not positive, but I think you can just edit that file and change this line to point to the pathname of your new .box image:

      config.vm.box_url = "http://files.vagrantup.com/precise64.box"
    

I think you can use a file:/// type URL that points to your .box.

Spark devops wizard @jgoggins is a vagrant master. Any thoughts here Joe?

1 Like

@Raldus Nice work! This is sweet.
I love the idea of making it simple for people to get set up to compile spark firmware.

80Gb is huge, I! Most of the VMs I’m using these days are between 400-600Mb (provided by OpsCode/Chef here). If you change the config.vm.box_url = "http://files.vagrantup.com/precise64.box in your Vagrantfile to point at one of these OpsCode .box files, the disk space required might get much much smaller.

If it seemed like lots of people would want this functionality, I’d be down with cooking up a “Spark Firmware Compile” .box file or something (for CentOS, maybe Ubuntu later)

Yeah, 80GB is large. While I can shrink it, I don’t have anywhere to host the result. I’ll take a look at the other boxes, but 400-600MB is on the small side. I’d want to have space for some additional tools, and 600MB might not be enough. We’ll see.

If it seemed like lots of people would want this functionality, I’d be down with cooking up a “Spark Firmware Compile” .box file or something (for CentOS, maybe Ubuntu later)

I’m not sure what you mean by this. The VM is already running Ubuntu 12.10 LTS.

Hey @Raldus, by “cooking up a spark firmware compile” box, I meant using one the OpsCode base boxes and publishing the a .box file so others could point their Vagrantfile file at it. I was thinking the VM would include the core firmware toolchain, required repos, and a [yet to be released] command line tool for compiling, flashing firmware, etc. But you’re right though, you already have something working, so i won’t bother at this point.

Have you looked at Docker.io? I wonder that would be an easier way to deliver a Spark Core Firmware build environment?

Thanks @jgoggins. I took a look at both the 32- and 64-bit Ubuntu 12.10 OpsCode bases, and they’re both 40GB images. The download size might be small (450+MB), but the disk images really are 40GB ones. The initial size is around 1.4GB, but it can grow to 40GB.

Still, 40GB < 80GB, and so I’ll take a look at using these images, instead.

Note that my vagrant config auto-downloads the compiler toolchain and everything else needed. By the time the VM is up, it’s all ready to build firmware. The only thing missing are the firmware sources, and there are two scripts provided for obtaining and building the firmware.

No, I hadn’t heard of docker.io, before. While it looks cool, I’m not sure it’s a good fit for spark canned firmware development. The biggest issue is that it appears linux-only. Having a canned firmware build box is probably of most use to windows and mac users, neither of which appear to be supported by docker.io; I’m guessing that actual linux users will just install the toolchain and not bother with a VM.

Sounds good @Raldus. Maybe Docker.io isn’t the right fit for this problem-space. One last thing, if you have an ideal target VM size (and are feeling adventurous :)), Packer.io or VeeWee are the tools that OpsCode uses to transform a .iso OS install image into a .box file, with those tools you can set exactly how much memory, disk-space, + virtual CPUs to allocate to the VM by default.

Thanks @jgoggins, but the real issue is hosting the base box. I don’t have any place to host it. I can take an existing box and change the disk size, number of CPUs, network interfaces, or whatever, but I don’t have any place to host the result, and so I have to currently reference existing boxes (e.g., from vagrant or the packer baseboxes). (For what we want to do, it’s a lot easier to take an existing, prepackaged box and hand-tweak it; while packer/etc. are great, they’re overkill.)

Now, if spark.io would like to host it, that would be nice. :smile:

How big is the file? I’m sure we can find a way to help out

Well, since the existing box images are around 350-450MB, it should be in that range, too. Almost certainly under 500MB.

OK, I now have a 438MB vagrant box image (64-bit Ubuntu 12.04LTS), with the firmware tools pre-installed. The disk size is 4GB, currently with 1.7GB free. I could shrink this down to 3GB, but I’m not sure if I should do that.

Downloading the spark firmware sources and building everything is still a trivial matter of running two canned scripts.

However, I still don’t have any place to host this.

I did end up using packer.io, as it turned out that the existing boxes used lvm (I didn’t want to deal with resizing/copying lvm volumes).

1 Like

I probably shouldn’t. I left the VM running overnight, and the nightly cron jobs sucked down updates that ate maybe another 400+MB of disk space. The free disk space is now down to ~1.3GB.

@Raldus Thanks for getting this started and describing everything here on the community, much appreciated.

I played around with this idea weekend and made a lot of progress. I think there are some great opportunities for Spark to support a Vagrant firmware build environment to make it easier for people to build firmware locally. Will post here when I know more.

@jgoggins A few days ago, I forked bento, and made a 4GB spark firmware buildbox config for virtualbox/vagrant (sorry, I don’t have vmware, and so I stripped out the vmware support from the packer config). See here for the forked github repo. You want to use the config file, “bento/packer/spark-ubuntu-12.04-4GB-amd64.json”, which uses the config script, “bento/packer/scripts/common/spark.sh”, to install the firmware build environment (yeah, this really should be under the “ubuntu” directory).

You can then use the two firmware scripts from the other project to obtain and build the latest firmware.

I should have totally checked the forum first, but I just now created this:

Gist: 9787007

Almost exactly the same thing :slight_smile:

There’s also a 4GB vagrant image available: https://s3.amazonaws.com/spark_public/spark_ubuntu-12.04-4GB-20140213.box (download size is around 560MB, but the filesystem size is 4GB).

This is from mid-February, and contains a basic firmware build environment. However, it does NOT have the command-line tools for app building.

Edit: Once you have vagrant installed, you can just run the following from the command-line to download, install, and run the virtual machine (you can change testdir to whatever you want)

mkdir testdir
cd testdir

# The following is all on one line:
vagrant init sparkbuild https://s3.amazonaws.com/spark_public/spark_ubuntu-12.04-4GB-20140213.box

# Download, install, and start the virtual machine:
vagrant up

Note that downloading and installing could take 15-30 minutes or more, mostly depending on the speed of your internet connection.

Can I monitor via usb my core with this vagrant machine?