[lang]

Present Perfect

Personal
Projects
Packages
Patches
Presents
Linux

Picture Gallery
Present Perfect

Building erlang for the N900

Filed under: maemo — Thomas @ 10:21 pm

2009-12-6
10:21 pm

So, it’s been a long weekend and I’ll have to recap the essentials sometime later.

I got my new phone – the n900 – on Friday from Zaheer. I wrote down first impressions but they’ll have to wait for now.
I spent most of Thursday night setting up scratchbox a few times and preparing to understand how to Build Stuff.

I was hoping I would be able to build on the source for previous packages but the original site that hosts those packages has been down for two months now. And not down in the usual way – it just leaves the connection attempt hanging! I mailed the guy, but got no reply. So, no other choice than to try it myself.

Over the course of the weekend, I managed to repackage .debs from Debian for erlang, spidermonkey and couchdb to work in the x86 scratchbox. I won’t bore you with the details on how much I suffered trying to learn debian packaging enough to build a working xulrunner. In the end, I managed to figure out that there was a very lightweight ‘spidermonkey’ source tree that builds just the js I need for couchdb (after reading the CouchDB MacOSX build instructions) and I packaged that up from scratch, which was definitely easier.

At some point during the weekend, I managed to run couchdb completely in the x86 scratchbox, so from that point I thought I was home free. Just rebuild the packages in the ARMEL scratchbox and off I go.

Boy was I ever wrong.

No, really.

I basically spent all of today trying to figure out why the build of erlang would hang as soon as it invoked the just-built erlang erlc compiler. Five processes down it seems stuck in a select(0, NULL, NULL, NULL) call, which afaict would have no hope of waking up. It was preceeded by an error about qemu not handling syscall 242. (it took me a while to figure out that this is the syscall for setting scheduler affinity, so probably not that necessary ?)

I got heaps of suggestions from various people, and thought of some things on my own too:

  • implement syscall 242 for qemu. Not my idea of a good time just yet.
  • patch out use of 242. Doable.
  • Set up sbrsh and use cpu transparency. There were no uptodate instructions for fremantle, it took me a good hour to figure out that these instructions are very misleading since those pages do not preserve the formatting, which is essential for the .sbrsh configuration file, besides also having extranuous spacing. And even when that worked to the point I was able to transparently execute hello-world-gtk, it would still hang on running simply quilt when doing the package build.
  • Since Erlang compiles to bytecode, I thought I could just copy .beam and .hrl files from my x86 tree into my armel tree each time the compiler hung on a compile. I actually did this for a good 90 minutes, until I gave up, because it was too tedious. I might try it again, but automated.
  • It should be possible to create a devkit with just the x86 erlang compiler, then convince the armel scratchbox target to use that compiler to generate all the erlang bytecode, instead of the just-built in-source compiler. Need to investigate further.
  • Upload the package to extras-devel, and have it built there. Good idea, but I’m waiting to be approved for now. Also, I don’t know if extras-devel will use qemu – it might fail the same way. And I’m not a fan of a build that can only be reproduced in an external service…
  • Building it on the phone directly. Apparently this was a working approach with previous devices. I added the sdk repo to the phone, and it proposed to remove some essential umbrella package before installing some dev packages. I didn’t want to brick my phone just yet.
  • Someone suggested to install scratchbox on the phone. An intriguing thought, but sadly it took only 5 minutes of work to see E: Currently Scratcbox can only run in 32 bit i386 architecture.

I have now settled on a mutation of some of these ideas, and we’ll see how that goes. I basically created /opt/chroot, copied essentials off the phone’s root into that dir, and chrooted into it. In there, I added the sdk repo, and am now installing the tools to be able to build the packages as if I was doing it directly on the phone – but nicely protected inside a chroot.

I hope there are going to be some packages at the end of this tunnel. And to think some people actually enjoy this lowlevel device hacking!

9 Comments »

  1. I think you’ll find that patching qemu to support the affinity syscall won’t take much effort. Adding a new syscall to qemu doesn’t require much work at all, once you know your way around qemu.

    Comment by Anonymous — 2009-12-7 @ 4:15 am

  2. 1. select(0, NULL, NULL, NULL) could return because of a signal

    2. syscall 242 on arm-eabi is ‘sched_getaffinity(2)’ (http://lxr.linux.no/linux+v2.6.32/arch/arm/include/asm/unistd.h#L270)
    I suspect it’s not why erlc is hanging. If removing its use in erlc improves things, adding it to qemu’s so called “user mode” is indeed not too difficult. (see: qemu/linux-user/syscall.c)

    3. Are you doing all this on Fedora? Would really appreciate a write up on how you setup your environment and learned enough Debian packaging.
    I tried to use:
    http://dev.openbossa.org/trac/mamona/
    on Fedora a few months ago but didn’t have time to finish the effort.

    Comment by Scott Tsai — 2009-12-7 @ 9:11 am

  3. Hi Scott,

    yes, this is on Fedora. I just set up maemo scratchbox sdk 5.0, works fine for me except for this build issue. I didn’t know about mamona, that looks like an alternative I should try to see this build.

    As for .deb packaging, that has indeed been the more painful process – reading a bunch of debian guides to understand enough about debian packaging to be dangerous….

    Comment by Thomas — 2009-12-7 @ 10:44 am

  4. [...] done to see desktopcouch on other Linux distributions and on phones like the Nokia N900 (hooray for Thomas, among others!). I’d really like to see this happen on Windows and Mac too; are you [...]

    Pingback by Desktopcouch on Windows/Mac | as days pass by, by Stuart Langridge — 2009-12-15 @ 2:39 pm

  5. Hi,

    FYI, using easydebchroot http://maemo.org/packages/view/easy-deb-chroot/, I was able to apt-get install debian armel port of couchdb:
    http://packages.debian.org/sid/armel/couchdb/download

    Hope that helps ;)

    Comment by proppy — 2010-1-3 @ 1:52 pm

  6. I did so too, without easydebchroot.

    I want to repackage it properly though.

    Comment by Thomas — 2010-1-3 @ 5:11 pm

  7. [...] native database framework that can interoperate with the CouchDB replication protocol and previous work has already been done by the third-party developer community to bring CouchDB to Nokia’s [...]

    Pingback by Mobile Internet Solutions » NoSQL takes a seat on Android with new mobile version of CouchDB — 2010-9-9 @ 11:35 pm

  8. [...] native database framework that can interoperate with the CouchDB replication protocol and┬áprevious work has already been done by the third-party developer community to bring CouchDB to Nokia’s [...]

    Pingback by NoSQL takes a seat on Android with new mobile version of CouchDB « Codealis — 2010-9-10 @ 11:08 am

  9. [...] native database framework that can interoperate with the CouchDB replication protocol and previous work has already been done by the third-party developer community to bring CouchDB to Nokia’s [...]

    Pingback by NoSQL takes a seat on Android with new mobile version of CouchDB | ItPak.net — 2010-9-10 @ 6:12 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

picture