Thicket data repository for the EEG
1{
2 "id": "https://anil.recoil.org/notes/dreamplug-debian-and-ocaml",
3 "title": "Dreaming of an ARM OCaml",
4 "link": "https://anil.recoil.org/notes/dreamplug-debian-and-ocaml",
5 "updated": "2012-02-25T00:00:00",
6 "published": "2012-02-25T00:00:00",
7 "summary": "<p>I’ve been meaning to play with <a href=\"http://www.plugcomputer.org/\">Plug\nComputers</a> for some time now, as I need a\nlow-power embedded system around the house. I recently bought a <a href=\"http://soekris.com/products/net6501.html\">Soekris\nNet6501</a> (a pretty powerful\nIntel CPU, that even has VT support), but had annoying\n<a href=\"http://marc.info/?l=soekris-tech&m=132915532912206&w=2\">issues</a> getting\nit working reliably. I ordered an ARM-based\n<a href=\"http://www.newit.co.uk/shop/products.php?cat=21\">Dreamplug</a> as an\nalternative (and as a bonus, the Dreamplug is 6x cheaper than the\nSoekris!). Here are my notes on getting it to work.</p>\n<p><a href=\"http://www.flickr.com/photos/tlamer/5693063642/\" title=\"dreamplug by tlamer, on Flickr\"><img alt=\"dreamplug\" src=\"http://farm6.staticflickr.com/5230/5693063642_47aa7c4c99.jpg\"></a></p>\n<p>Requirements:</p>\n<ul>\n<li>Aside from the Dreamplug itself, make sure you order the optional\nJTAG module. This provides a serial console that is essential to\ngetting any development done with it.</li>\n<li>I also grabbed the extra 16GB Class 10 SLC SD Card, to act as my\nhome directory.</li>\n<li>You will also need another functional system running Debian (or a VM\non your Mac; whatever is easiest). The JTAG drivers for the USB\nserial are easiest to get running on Linux.</li>\n</ul>\n<p>The Dreamplug arrived with a working installation, but running the\nabsolutely ancient Debian Lenny. A dist-upgrade through to Wheezy led to\nbricking it almost immediately, and so I did a fresh installation from\nscratch.</p>\n<p>For a fresh installation, place a USB stick of suitable size (greater\nthan 2GB is best) into your functional Debian installation. Then:</p>\n<ul>\n<li>\n<p>The Marvell bootloader boots from a VFAT partition, so you will need\ntwo partitions. The first should be a small <code>fat16</code> (I picked 150MB)\nand the remainder an <code>ext3</code> partition for Linux itself. There are\ngood instructions available on the\n<a href=\"https://trac.torproject.org/projects/tor/wiki/doc/DebianDreamPlug\">Tor/Dreamplug</a>\nwiki which show you how to do this.</p>\n</li>\n<li>\n<p>I grabbed the latest kernel (at this time, 3.2.7) from\n<a href=\"http://sheeva.with-linux.com/sheeva/3/3.2/3.2.7/\">with-linux</a>, and\ninstalled it with the following commands (assuming your USB stick is\n<code>/dev/sdb</code>).</p>\n<pre><code>$ sudo mount /dev/sdb1 /mnt\n$ sudo cp uImage /mnt\n$ sudo umount /mnt\n</code></pre>\n</li>\n<li>\n<p>You now need to use <code>debootstrap</code> to install a fresh root image.\nBecause it is ARM and your main PC is probably an x86, you will need\nto setup the QEMU CPU emulator. An extremely cool feature of QEMU is\nthat it can do <a href=\"http://wiki.debian.org/QemuUserEmulation\">transparent\nemulation</a> of foreign\nbinaries, so you can chroot directly into the ARM filesystem and run\ncommands as if they were x86. The <code>qemu-deboostrap</code> command will\ntake care of this for you, if you perform the steps below (again,\nassuming your USB stick is <code>/dev/sdb</code>).</p>\n<pre><code>$ sudo apt-get install qemu-user-static debootstrap\n$ sudo mount /dev/sdb2 /mnt\n$ sudo mkdir -p /mnt/usr/bin\n$ sudo cp /usr/bin/qemu-arm-static /mnt/usr/bin/\n$ sudo qemu-debootstrap --arch=armel wheezy http://ftp.uk.debian.org/debian/\n</code></pre>\n</li>\n<li>\n<p>Now grab the kernel modules from the same place as your uImage (for\n3.2.7, from\n<a href=\"http://sheeva.with-linux.com/sheeva/3/3.2/3.2.7/sheeva-3.2.7-Modules.tar.gz\">here</a>).\nThen, chroot into your fresh installation and untar them.</p>\n<pre><code>$ cd /mnt\n$ sudo tar -zxvf ~/sheeva-3.2.7-Modules.tar.gz\n$ sudo chroot /mnt\n$ depmod -a\n# edit /etc/network/interfaces\n# edit /etc/resolv.conf\n</code></pre>\n</li>\n<li>\n<p>The wireless setup involves some extremely crap firmware which\nrelentlessly kernel panicked for me, so I just disabled it by adding\nthe following to <code>/etc/modprobe.d/dpwifiap.conf</code>, as I only want\nwired access:</p>\n<pre><code>blacklist libertas\nblacklist libertas_sdio\n</code></pre>\n</li>\n<li>\n<p>From there on, put the USB stick into the Dreamplug, and follow the\nrest of the boot instructions from the <a href=\"https://trac.torproject.org/projects/tor/wiki/doc/DebianDreamPlug\">Tor\nwiki</a>\nto interact with the Marvell BIOS and boot from the USB stick. I\ncopied the contents of the USB stick onto the internal MicroSD, and\nit all boots standalone now.</p>\n</li>\n</ul>\n<h2><a href=\"https://anil.recoil.org/#ocaml-on-arm\"></a>OCaml on ARM</h2>\n<p>One of the reasons I wanted an ARM-based setup is to experiment with the\nOCaml native code generation. <a href=\"http://www.home.unix-ag.org/bmeurer/index.html\">Benedikt\nMeurer</a> has been doing\nsome excellent work on <a href=\"http://old.nabble.com/New-ARM-backend-merged-into-trunk-td33262083.html\">improving code\ngeneration</a>\nfor embedded systems, including support for 16-bit Thumb code, exception\nbacktraces, and dynamic linking and profiling.</p>\n<p>Once Linux was up and running, compiling up the latest ocaml-trunk was\nstraightforward.</p>\n<pre><code> $ sudo apt-get install build-essential git\n $ git clone http://github.com/OCamlPro/ocp-ocaml svn-trunk\n $ cd ocp-ocaml\n $ ./configure && make world opt opt.opt install\n</code></pre>\n<p>This compiles the bytecode and native code compilers, and then compiles\nthem again using the native code generator. This takes a while to do on\nthe poor little ARM CPU. Once that finished, I compiled up a few simple\nmodules and they worked great! Since the trunk of OCaml is a development\nbranch, you may run into a few packaging issues (use the very latest\nOASIS to regenerate any <code>setup.ml</code>, and you will need a small patch\nuntil <a href=\"http://caml.inria.fr/mantis/view.php?id=5503\">PR 5503</a> is\napplied).</p>\n<p>Incidentally, if anyone is interested in working on a\n<a href=\"http://openmirage.org\">Mirage</a> port to ARM as an internship in the\n<a href=\"http://www.cl.cam.ac.uk/research/srg/netos/\">Cambridge Computer Lab</a>,\ndo get in touch with me...</p>",
8 "content": "<p>I’ve been meaning to play with <a href=\"http://www.plugcomputer.org/\">Plug\nComputers</a> for some time now, as I need a\nlow-power embedded system around the house. I recently bought a <a href=\"http://soekris.com/products/net6501.html\">Soekris\nNet6501</a> (a pretty powerful\nIntel CPU, that even has VT support), but had annoying\n<a href=\"http://marc.info/?l=soekris-tech&m=132915532912206&w=2\">issues</a> getting\nit working reliably. I ordered an ARM-based\n<a href=\"http://www.newit.co.uk/shop/products.php?cat=21\">Dreamplug</a> as an\nalternative (and as a bonus, the Dreamplug is 6x cheaper than the\nSoekris!). Here are my notes on getting it to work.</p>\n<p><a href=\"http://www.flickr.com/photos/tlamer/5693063642/\" title=\"dreamplug by tlamer, on Flickr\"><img alt=\"dreamplug\" src=\"http://farm6.staticflickr.com/5230/5693063642_47aa7c4c99.jpg\"></a></p>\n<p>Requirements:</p>\n<ul>\n<li>Aside from the Dreamplug itself, make sure you order the optional\nJTAG module. This provides a serial console that is essential to\ngetting any development done with it.</li>\n<li>I also grabbed the extra 16GB Class 10 SLC SD Card, to act as my\nhome directory.</li>\n<li>You will also need another functional system running Debian (or a VM\non your Mac; whatever is easiest). The JTAG drivers for the USB\nserial are easiest to get running on Linux.</li>\n</ul>\n<p>The Dreamplug arrived with a working installation, but running the\nabsolutely ancient Debian Lenny. A dist-upgrade through to Wheezy led to\nbricking it almost immediately, and so I did a fresh installation from\nscratch.</p>\n<p>For a fresh installation, place a USB stick of suitable size (greater\nthan 2GB is best) into your functional Debian installation. Then:</p>\n<ul>\n<li>\n<p>The Marvell bootloader boots from a VFAT partition, so you will need\ntwo partitions. The first should be a small <code>fat16</code> (I picked 150MB)\nand the remainder an <code>ext3</code> partition for Linux itself. There are\ngood instructions available on the\n<a href=\"https://trac.torproject.org/projects/tor/wiki/doc/DebianDreamPlug\">Tor/Dreamplug</a>\nwiki which show you how to do this.</p>\n</li>\n<li>\n<p>I grabbed the latest kernel (at this time, 3.2.7) from\n<a href=\"http://sheeva.with-linux.com/sheeva/3/3.2/3.2.7/\">with-linux</a>, and\ninstalled it with the following commands (assuming your USB stick is\n<code>/dev/sdb</code>).</p>\n<pre><code>$ sudo mount /dev/sdb1 /mnt\n$ sudo cp uImage /mnt\n$ sudo umount /mnt\n</code></pre>\n</li>\n<li>\n<p>You now need to use <code>debootstrap</code> to install a fresh root image.\nBecause it is ARM and your main PC is probably an x86, you will need\nto setup the QEMU CPU emulator. An extremely cool feature of QEMU is\nthat it can do <a href=\"http://wiki.debian.org/QemuUserEmulation\">transparent\nemulation</a> of foreign\nbinaries, so you can chroot directly into the ARM filesystem and run\ncommands as if they were x86. The <code>qemu-deboostrap</code> command will\ntake care of this for you, if you perform the steps below (again,\nassuming your USB stick is <code>/dev/sdb</code>).</p>\n<pre><code>$ sudo apt-get install qemu-user-static debootstrap\n$ sudo mount /dev/sdb2 /mnt\n$ sudo mkdir -p /mnt/usr/bin\n$ sudo cp /usr/bin/qemu-arm-static /mnt/usr/bin/\n$ sudo qemu-debootstrap --arch=armel wheezy http://ftp.uk.debian.org/debian/\n</code></pre>\n</li>\n<li>\n<p>Now grab the kernel modules from the same place as your uImage (for\n3.2.7, from\n<a href=\"http://sheeva.with-linux.com/sheeva/3/3.2/3.2.7/sheeva-3.2.7-Modules.tar.gz\">here</a>).\nThen, chroot into your fresh installation and untar them.</p>\n<pre><code>$ cd /mnt\n$ sudo tar -zxvf ~/sheeva-3.2.7-Modules.tar.gz\n$ sudo chroot /mnt\n$ depmod -a\n# edit /etc/network/interfaces\n# edit /etc/resolv.conf\n</code></pre>\n</li>\n<li>\n<p>The wireless setup involves some extremely crap firmware which\nrelentlessly kernel panicked for me, so I just disabled it by adding\nthe following to <code>/etc/modprobe.d/dpwifiap.conf</code>, as I only want\nwired access:</p>\n<pre><code>blacklist libertas\nblacklist libertas_sdio\n</code></pre>\n</li>\n<li>\n<p>From there on, put the USB stick into the Dreamplug, and follow the\nrest of the boot instructions from the <a href=\"https://trac.torproject.org/projects/tor/wiki/doc/DebianDreamPlug\">Tor\nwiki</a>\nto interact with the Marvell BIOS and boot from the USB stick. I\ncopied the contents of the USB stick onto the internal MicroSD, and\nit all boots standalone now.</p>\n</li>\n</ul>\n<h2><a href=\"https://anil.recoil.org/#ocaml-on-arm\"></a>OCaml on ARM</h2>\n<p>One of the reasons I wanted an ARM-based setup is to experiment with the\nOCaml native code generation. <a href=\"http://www.home.unix-ag.org/bmeurer/index.html\">Benedikt\nMeurer</a> has been doing\nsome excellent work on <a href=\"http://old.nabble.com/New-ARM-backend-merged-into-trunk-td33262083.html\">improving code\ngeneration</a>\nfor embedded systems, including support for 16-bit Thumb code, exception\nbacktraces, and dynamic linking and profiling.</p>\n<p>Once Linux was up and running, compiling up the latest ocaml-trunk was\nstraightforward.</p>\n<pre><code> $ sudo apt-get install build-essential git\n $ git clone http://github.com/OCamlPro/ocp-ocaml svn-trunk\n $ cd ocp-ocaml\n $ ./configure && make world opt opt.opt install\n</code></pre>\n<p>This compiles the bytecode and native code compilers, and then compiles\nthem again using the native code generator. This takes a while to do on\nthe poor little ARM CPU. Once that finished, I compiled up a few simple\nmodules and they worked great! Since the trunk of OCaml is a development\nbranch, you may run into a few packaging issues (use the very latest\nOASIS to regenerate any <code>setup.ml</code>, and you will need a small patch\nuntil <a href=\"http://caml.inria.fr/mantis/view.php?id=5503\">PR 5503</a> is\napplied).</p>\n<p>Incidentally, if anyone is interested in working on a\n<a href=\"http://openmirage.org\">Mirage</a> port to ARM as an internship in the\n<a href=\"http://www.cl.cam.ac.uk/research/srg/netos/\">Cambridge Computer Lab</a>,\ndo get in touch with me...</p>",
9 "content_type": "html",
10 "author": {
11 "name": "Anil Madhavapeddy",
12 "email": "anil@recoil.org",
13 "uri": "https://anil.recoil.org"
14 },
15 "categories": [],
16 "rights": "(c) 1998-2025 Anil Madhavapeddy, all rights reserved",
17 "source": "https://anil.recoil.org/news.xml"
18}