Archive for April, 2012

L4Linux Patch for MV643xx Ethernet

April 12, 2012 2 comments

A while ago I posted a tutorial on how to run Linux virtualized on top of L4 on the Sheevaplug. But one problem with the solution is that Sheevaplug’s hardware components (e.g. network, sd-card, etc.) aren’t working out of the box. In the menuconfig of L4Linux you can’t even select the driver (…for L4 architecture). So for all who want to run L4Linux on the Sheevaplug and want to use the physical network interface, this patch is for you mv643xx.patch. Copy the patch beside your ‘L4Linux’ folder and call

patch -p0 < mv643xx_eth.patch

to patch your Linux tree. Then enable

Device Drivers -->
    Network device support -->
        Ethernet (1000 Mbit) -->
            Marvell Discovery (643XX) and Orion ethernet support

in your ‘menuconfig’ and use the following configuration when you build your L4 image (at least the *.io file)


modaddr 0x01100000

entry L4Linux ARM
kernel fiasco -serial_esc
roottask moe rom/l4lx.cfg
module l4re
module ned
module l4lx.cfg
module io
module vmlinuz.arm
module ramdisk.rd

  NIC => new Device()
    .hid = "mv643xx"; 
    new-res Mmio(0xF1000000 .. 0xF100FFFF);
    new-res Mmio(0xF1020000 .. 0xF102FFFF);
    new-res Mmio(0xF1070000 .. 0xF107FFFF);
    new-res Irq(46);
    new-res Irq(11);

  DMA => new Device()
    .hid = "dmamem";
    new-res Mmio_ram(8388608,0);

l4lx_bus => new System_bus()
  DMA => wrap(hw-root.DMA);
  NIC => wrap(hw-root.NIC);


-- vim:set ft=lua:


local io_caps = {
    sigma0 = L4.cast(L4.Proto.Factory, L4.Env.sigma0):create(L4.Proto.Sigma0);
    l4lx_bus = L4.default_loader:new_channel():svr();
    icu =;

local linux_caps = {
    log  = L4.Env.log:m("rws"),
    vbus = io_caps.l4lx_bus    

    caps = io_caps,
    log = { "io", "blue" }
}, "rom/io -vvv rom/");

    caps = linux_caps,
    log = {"l4linux", "yellow"},
    l4re_dbg = L4.Dbg.Warn
}, "rom/vmlinuz.arm mem=64M console=ttyLv0 l4x_rd=rom/ramdisk.rd \
root=1:0 ramdisk_size=11000 rw");

Depending on the name/size of your ramdisk you have to adapt the parameters in the config files.

The patch is tested and working, I’m using the device every day. But sometimes L4Linux jumps into the debugger JDB with the message ‘IRET returned’, I’m not 100% sure if the problem arises from my patch but could be. When this happens, restarting the device is your only chance. When you are in the debugger hit ‘^^’ twice to restart.
Leave a comment when you have questions about the patch…

Have fun!

Categories: tech foo Tags: , , , ,

Dropbox Challenge – File Events

April 10, 2012 Leave a comment

The Story

In the near future I will finish my Master Thesis and then I’m looking for a Job. Because of this I stumbled over the Jobs page on Dropbox and the challenges they provide in order to test the skills of potential employees. The second challenge “File Events” instantly drew my attention and I started to think about it.


First I had a lot of crazy ideas in mind, like building a hash tree and always change the tree when a new event occurs. But this is very complex and I’m not sure if it even leads to a solution. Then I tried to create classes for files and folders and keep track of these, and whenever a new event for a specific class (file/foldr) occurs I wanted to plot the result. But first, this leads to lots of class instances when there are lots of folders, files and subfolders and second, what happens when a file/folder gets renamed (an essential event in this challenge). So I also discarded this solution. Finally I came up with just handling the events and nothing else, which basically leads to a simple statemachine.

I have to say that I’m not a huge fan of statemachines, not because I think they are useless, but more because of my previous experience with them (mostly in the lecture ‘programmable logic’ ). But for this problem I think a statemachine is a good idea. So I started to create one. Finally after some different ideas I came up with a very simple one with only two states:
In ‘stage0’ there are two transitions

  • stage0 -> del -> stage1, which stores the DEL event, to decide upon the next event what to do
  • stage0 -> add -> stage0, which triggers the add_object() function for the current object

In ‘stage1’ there are also two transitions

  • stage1 -> del -> stage1, which triggers the delete_object() function for the previous object
  • stage1 -> add -> stage0, which triggers move_object() (move_object() contains move and del+add)


A few month ago I started learning Ruby, and the challenge was a good opportunity to test my Ruby skills. So I decided to give Ruby a try. For the statemachine I used the Statemachine Gem which is after reading the four short tutorials very self explaining. Other than that I only used constructs provided by Ruby’s core library.

I first implemented a method ‘run’ that ‘gets()’ the first line of the input as the number of events that will follow. Then it ‘gets()’ one line after another from the input, parses the strings and converts them to Events::Event class instances:

#!/usr/bin/env ruby
#file: fileevent.rb

$: << File.expand_path(File.dirname(__FILE__) + "/../lib")

require 'rubygems'
require 'statemachine'

require 'fileevent/eventmachine'
require 'fileevent/events'

class FileEvent
    def initialize
        @events =
        @em =
        @context = @em.context
    def run
            events = Integer(gets())
        rescue => e
            puts "Error: #{e.message}"

        events.times do 
                new_event =' '))
            rescue => e
                puts 'Unknown event...'
            if new_event.time > @context.c_events.time
                @em.add if @context.c_events.type == 'ADD'
                @em.del if @context.c_events.type == 'DEL'
                @context.l_events = @context.c_events 
                @context.c_events =
            elsif @context.c_events.time == new_event.time 
                @context.c_events << new_event

        @em.add if @context.c_events.type == 'ADD'
        @em.del if @context.c_events.type == 'DEL'
        if @em.state == :stage1    
            @context.c_events.each do |event|
                obj = 'file'
                obj = 'folder' if event.hash == '-'
                puts "Deleted #{obj} #{event.path}"

fe =

Then I implemented the Events class, that contains logic to compare event content/hashes and stores all events for a given timestamp

#file: fileevent/events.rb

class Events
    attr_reader :type, :time, :root
    def initialize(event)
        @type = event.type
        @time = event.time
        @root = event.path
        self << event
    def <<(event)
        return if event.type != @type || event.time != @time
        @events = if @events == nil
        if event.path.count('/') < @root.count('/')
            @root = event.path[0]
        @events << event
    def ==(events)       
        if (content & events.content).size == content.size &&
              (hashes & events.hashes).size == hashes.size
            return true
        return false
    def each
        @events.each do |event|
            yield event
    def hashes
        h =
        self.each do |event|
            h << event.hash 
        return h
    def content
        c =  
        self.each do |event|
            file = (event.path.split('/') - @root.split('/'))[0]
            c << file if file != nil
        return c
    class Event
        attr_reader :type, :time, :path, :hash
        def initialize(event)
            if event.size == 4
                @type = event[0]
                @time = Integer(event[1])
                @path = event[2]
                @hash = event[3]

And finally I implemented the Statemachine (EventMachine) + Context:

# file: fileevents/eventmachine.rb

require 'fileevent/events'

class EventMachineContext
    attr_accessor :c_events, :l_events
    def initialize
        @c_events =['ADD',0,'/','-']))
    def add_object
        @c_events.each do |event|
            obj = 'file'
            obj = 'folder' if event.hash == '-'
            puts "Added #{obj} #{event.path}"
    def del_object
        @l_events.each do |event|
            obj = 'file'
            obj = 'folder' if event.hash == '-'
            puts "Deleted #{obj} #{event.path}"
    def move_object
        if @c_events == @l_events
            obj = 'folder'
            puts "Moved #{obj} #{@l_events.root} -> #{@c_events.root}"

class EventMachine
    attr_reader :eventmachine
    def initialize
        @eventmachine = do
            state :stage0 do
                event :del, :stage1
                event :add, :stage0, :add_object 
            state :stage1 do
                event :del, :stage1, :del_object
                event :add, :stage0, :move_object   

That’s basically it. I have to say that the Statemachine Gem was really helpful and easy to use. When you have a problem that can be solved with a statemachine use this Gem. To the rest of the implementation is not much to say I thing. “ugly” parts are just the ‘content’ and ‘hashes’ methods in the Events class…


I had to restrict/simplify my solution, because otherwise the solution would have been much more complex. First, for a given timestamp it is only allowed to occur one type of event, either ‘DEL’ or ‘ADD’. The first event of the input decides which one. If the following happens the ‘ADD 1 /home/test3 -‘ will be ignored.

DEL 1 /home/test/1.txt 123456
DEL 1 /home/test/2.txt 123457
DEL 1 /home/test -
ADD 1 /home/test3 -

Why did I made this simplification? If I had handled different events for one timestamp I had to decide which event to handle first, ‘ADD’ or ‘DEL’. Based on this decision the output might get messed up. Or I had to store one more previous event, to decide if the current+previous ADD/DEL is part of a move operation or not.

Second, In order to make the right decision if a ‘move’ or a ‘del+add’ event occured I compared the content of both folders by their hashes and by their names, e.g.

DEL 1 /home/test/1.txt 123456
DEL 1 /home/test -
ADD 2 /home/test2 -
ADD 2 /home/test2/1.txt 123456

would end up in a

Moved /home/test -> /home/test2'


DEL 1 /home/test/1.txt 123457
DEL 1 /home/test -
ADD 2 /home/test2 -
ADD 2 /home/test2/1.txt 123456

ends up in a

Deleted file /home/test/1.txt
Deleted folder /home/test
Added folder /home/test2
Added file /home/test2/1.txt

I know, the one event per timestamp is not very realistic, because when I move a folder with all its content, each DEL/ADD operation would have a different timestamp, because depending on filesize, etc. the move operation would take some time for each element (at least in my understanding). But the sample input from the Dropbox website, shows that a move operation is done only in two steps, one timestamp for deletion of all the objects and one timestamp for adding all the objects. So I think we can life with the simplification.


I have to say that solving the challenge took me longer than I thought. The idea of only handling the events rather than keeping track of all events came very late. I already tinkered on the other solutions for half a day, before realizing that these solutions don’t lead to success.
I hope I can spare you that by providing my solution.

P.S. Please be indulgent with my implementation, I’m not that into algorithms and I just started learning Ruby…

Addition: I forgot to tell that the whole sourcecode is available on GitHub.

Google Music

April 5, 2012 1 comment

The Story

Every time I have new music on my PC (bought from a prestigious online music store of course), I forget to put it on my Phone as well. Then the next day when I go to work, I want to listen to my music. Just when I leave the door I realize that (again) I forgot to copy the new tracks to my phone. So I was searching for a service/application that synchronizes the music from my computer with my phone and laptop over night.

The Problem

Most online services only provide “full” sync (e.g. Dropbox, Ubuntu One), but I was looking for a service that intelligently synchronizes my files. By ‘intelligent’ I mean I want to define which files to sync according to simple patterns, like

  • Newest/Oldest first
  • Only defined amounts of data (e.g. 4Gb)
  • First a defined set of files, then newest/oldest first

Why I want this? My phone only has 16Gb of storage and I only have about 8Gb free for music. But my music collection at home is about 35Gb. So I want to have a basic set of tracks on my Phone (Tracks I always want to have on the device) and Tracks I recently added to my music collection.
I have to say, that I haven’t found a service/application that provides such a flexibility. But I found something else that comes, lets say close to my needs.

Google Music

I think most people have already heard about Google Music, but only a few have really tested it, because its only available in the USA. But in this post I will explain how to use Google Music from Everywhere.

First of all you need a Google Mail Account. When you have one go to When you access this Website from the US you are good to go and you can just click the button to accept the License Agreement. But when you live outside the US, you are faced with a page saying that this service is only available to residents of the United States. But no problem, go to hidemyass and type in the URL of Google Music again. Now the whole communication with the Google Website goes over a Web Proxy located in the USA. When the page is loaded you should face the License Agreement page as well. Just hit ‘accept’, and your account is activated for Google Music. After accepting the License Agreement you can go to without the Proxy.

Google Music Manager
When you are logged in you are faced with the ‘Google Music Player’. First thing to do is uploading music to your player. This is done with the ‘Google Music Manager’. A desktop application available for all big Operating systems (Linux/Mac/Windows). To get the download link hit the ‘Upload Music’ button

Google Music

or follow my links:

I’m sorry I can’t provide the Windows links, because I don’t have a Windows Computer around. But as I explained when you visit the ‘Upload Music’ page with a Windows Computer you are provided with the according link.
Install the application and let it guide you through the steps of uploading your music to the Google servers. You are allowed to upload up to 20.000 songs. I think this is more then enough for most of us.
Tip: Most of us have an ADSL connection at home, means fast, download slow upload. But if you are a University student, go there and upload the tracks over the University network, because most Universities have a high capacity upload of about 10-100Mbit/s (against 1-3.3Mbit/s). Otherwise the upload of your tracks will take a looooong time.

Google Play Music
The next step is to install the Android app to access the music from your phone. Again when you are a resident of the United States just go to the store and install ‘Google Play Music’. But when you are outside of the US, you have to get the app from somewhere else. Here is the link to the latest version (4.1.513). Download the *.apk file and install it to your phone. When you open the App it takes a few seconds, but then it should show all your uploaded music. When you click a track it will get streamed from the Google Servers to your phone.
But you don’t want to stream the music when you only have a volume contract (e.g. 500Mb) or are in a rural area. You can hit the ‘Offline Available’ button, then select the tracks that should be available offline and the app will download these tracks to a local folder. You can playback these tracks without an Internet connection. The app also allows to filter only tracks that are available offline, to see whats stored on your phone.

Google Play Music + Atrix
Here is a small hint for the Google Play Music app on the Motorola Atrix. Since Google Music is still in beta phase, there aren’t many settings. E.g. you can not decide where ‘Google Play Music’ puts the offline available music. The app stores the music under


When you have a lot of apps, your internal sdcard might already be full, and it would be useful to store all the music on your external sdcard. But both the sdcard and sdcard-ext are fat formated so you can’t create a softlink from your external memory to the internal to trick the app into storing the cached music on the external sdcard. But luckily we have the mount command to mount a folder into another folder, and this exactly what we are going to do. Just follow the steps below.
!!!You will lose all the music already made available offline!!!

rm -rf /sdcard/Android/data/
mkdir /sdcard-ext/music
busybox mount --bind /sdcard-ext/music \

Now when the ‘Google Play Music’ stores music on your device for offline playback it will be stored on the external sdcard (sdcard-ext) and not the internal memory (sdcard). !!!But remember each time you restart your device you have to call the mount command again!!!

Nuvola Player

When you use Ubuntu (like me) you can use the Nuvola Music player to access the Google Music website in a more comfortable way. Just call the following commands to add the repository to your system and install the player

sudo apt-add-repistory ppa:nuvola-player-builders/stable
sudo apt-get update
sudo apt-get install nuvolaplayer

The player integrates into your system like a desktop application and is accessible via Ubuntu’s sound menu.

Screenshot at 2012-04-05 16:22:15

And for the Last.FM fanboys like me there is even a scrobbler script. Follow the tutorial from here to get it.

Have Fun!

Debian on Android/Atrix with Debootstrap

April 2, 2012 1 comment

The Story

I have bought a new Smartphone. No, not the new and shiny Samsung Galaxy Nexus. An already a little bit older model, but still one of the most powerful devices out there, and a lot cheaper then the Galaxy Nexus, the Motorola Atrix 4G. My Nokia N900 served me well for the past 1.5 years, but now it was time for me to jump on the train called Android. But with my new Smartphone I don’t wanted to lose the possibility to use all my favorite Unix tools (e.g. SSH, SCP, RSYNC, etc.). So I decided to search for a guide on how to install Debian on Android. I found a lot, but non of them directly addressed on how to install Debian on Android/Atrix. So I decided to write a short guide for all the Atrix owners out there.

Rooting the Atrix

Before you start with the guide on how to install Debian you have to root your phone, otherwise this tutorial is useless for you. There are plenty of tutorials on how to do that, just bug google with “root atrix”. In other words, here I will not explain how to root your phone.

Debian Image

First of all we have to build a Debian image file, which we store on the Atrix to chroot into later. Just follow these steps to create an image. The parameter seek=xxxx defines the size of your chroot, so if you have enough space on your phone you can also create a bigger image. The command below will create a 800MB Debian image.

sudo -s
apt-get install debootstrap
dd if=/dev/zero of=debian.img seek=838860800 bs=1 count=1
mke2fs -F debian.img
mkdir debian
mount -o loop debian.img debian/
debootstrap --verbose --arch armel --foreign lenny debian
umount debian/
rm -r debian/

The debootstrap command will take some time, because it basically downloads the whole OS from the Debian FTP server.


On the Web I found a script to boot Debian on your phone, but for my Atrix it didn’t work out of the box. So I changed it to fit the Atrix’s system structure.

if [ $EUID -ne 0 ]
	echo "Becoming ROOT!"
	su -c bootdebian
	exit 1
echo "Mounting system as R/W"
mount -o remount,rw -t ext3 /dev/block/mmcblk0p12 /system
echo "Setting some stuff up.."
export bin=/system/bin
export img=/mnt/sdcard-ext/debian.img
export mnt=/data/local/debian
export PATH=$bin:/usr/bin:/usr/sbin:/bin:$PATH
export TERM=linux
export HOME=/root
if [ ! -d $mnt ]; then
    mkdir $mnt
echo "Mounting the Linux Image"
losetup /dev/block/loop5 $img
mount -t ext2 -o noatime,nodiratime /dev/block/loop5 $mnt
mount -t devpts devpts $mnt/dev/pts
mount -t proc proc $mnt/proc
mount -t sysfs sysfs $mnt/sys
echo "Setting Up Networking"
sysctl -w net.ipv4.ip_forward=1
echo "nameserver" > $mnt/etc/resolv.conf
echo "nameserver" >> $mnt/etc/resolv.conf
echo " localhost" > $mnt/etc/hosts
echo "Mounting sdcard and emmc in /mnt"
if [ ! -d $mnt/mnt/sdcard ]; then
    mkdir $mnt/mnt/sdcard
/system/xbin/busybox mount --bind /mnt/sdcard $mnt/mnt/sdcard
if [ ! -d $mnt/mnt/sdcard-ext ]; then
    mkdir $mnt/mnt/sdcard-ext
/system/xbin/busybox mount --bind /mnt/sdcard-ext/ $mnt/mnt/sdcard-ext
echo "Entering CHROOT "
echo " "
chroot $mnt /bin/bash
echo " "
echo "Shutting down CHROOT"
umount $mnt/mnt/sdcard
umount $mnt/mnt/sdcard-ext
sysctl -w net.ipv4.ip_forward=0
umount $mnt/dev/pts
umount $mnt/proc
umount $mnt/sys
umount $mnt
losetup -d /dev/block/loop5
mount -o remount,ro -t ext3 /dev/block/mmcblk0p12 /system

Copy the quoted text and save it to the root folder of the internal memory of the Atrix (/sdcard) with the name


It’s important to keep the name, otherwise the first command where the script checks if you’re root will fail. Now start the terminal application of your choice on the Atrix. I use the Better Terminal Emulator (I think its worth the price for only 2.99). Start the second stage of the debootstrap process by typing the following text.

mount -o remount,rw -t ext3 /dev/block/mmcblk0p12 /system
cat /sdcard/bootdebian > /system/xbin/bootdebian
rm /sdcard/bootdebian
chmod 777 /system/xbin/bootdebian
/debootstrap/debootstrap --second-stage
echo 'deb lenny main' > /etc/apt/sources.list
apt-get autoclean
apt-get update

Now thats it, From now on you can call bootdebian when ever you need access to your Chroot. You can install everything with apt-get, the same as on you Desktop machine or Laptop.

Have Fun!