Changing RaspberryPi RAM CPU:GPU Ratio

The Raspberry Pi comes with 256MB of RAM, included in the Broadcom BCM2835 System on chip, which also contains the CPU, GPU and DSP in the same package.

 

That 256MB of RAM is split between the CPU and GPU at boot time of the Pi, and by default is a 50:50 split, 128MB each. This works well for video decoding and 3D graphics, but if you know you won’t be using such graphically intensive applications, you can change this split to give the CPU a bit more.

 

To do so, you just need to copy the pre-made .elf files to the start.elf file in /boot, and reboot:

 

For 192MB for the CPU and 64MB for the GPU:

sudo cp /boot/arm192_start.elf /boot/start.elf

For 224MB for the CPU and 32MB for the GPU:

sudo cp /boot/arm224_start.elf /boot/start.elf

For the default equal split of 128MB for both CPU & GPU:

sudo cp /boot/arm128_start.elf /boot/start.elf

Node.JS on Raspberry Pi

I have a few applications in mind for my Raspberry Pi, and one uses Node.JS. Compiling and installing node is not difficult, but requires a few tweaks to the standard system before it will compile.

 

I’m using the Debian Squeeze image, and though installing the prerequisites and the majority of the build goes smoothly, I ran into a problem building the V8 engine:

error: #error “For thumb inter-working we require an architecture which supports blx”

This is down to Debian using a default of ARMv4 architecture, to try and target the widest range of devices by default. Unfortunately Node.JS requires ARMv5 architecture, but luckily for us, the Raspberry Pi’s CPU is based on ARMv6, we just need to tell the compiler to use it!

 

To build and install Node.js:

$ sudo apt-get install git-core build-essential libssl-dev (to installed needed packages)

$ mkdir ~/nodeDL && cd ~/nodeDL (to make a temporary place to download and compile)

$ git clone https://github.com/joyent/node.git . (to get a copy of node)

$ git checkout v0.6.15 (to checkout the most recent stable version (at time of writing))

 

next we need to tell the compiler to use the armv6 architecture for the compilation:

$ export CCFLAGS='-march=armv6'

$ export CXXFLAGS='-march=armv6'

and then edit deps/v8/SConstruct around the line 82 mark, to add “-march=armv6”:

'all': {

   'CCFLAGS':      ['$DIALECTFLAGS', '$WARNINGFLAGS', '-march=armv6'],

   'CXXFLAGS':     ['-fno-rtti', '-fno-exceptions', '-march=armv6'],

 },

Then comment out lines starting around the 157 mark, to remove the vfp3 and simulator parts. Since this is a JSON-like object, remember to remove the comma on the CPPDEFINES line!

'armeabi:softfp' : {

   'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0']

  # 'vfp3:on': {

  #   'CPPDEFINES' : ['CAN_USE_VFP_INSTRUCTIONS']

  # },

  # 'simulator:none': {

  #   'CCFLAGS':     ['-mfloat-abi=softfp'],

  # }

 },

 

Then the usual configure, make, make install process, NB I had to manually specify the location of the OpenSSL libpath:

$ ./configure --openssl-libpath=/usr/lib/ssl (to configure the build)

$ make (to compile node (This took 103 minutes on my RPi!))

$ sudo make install (to install)

 

Thats it, you should now have a working Node.JS install!

$ node -v should show you the version number

$ npm -v should show you the version of the Node Package Manager

Adding <br> tags or text breaks into Tumblr HTML

Overall I’m very happy with my Tumblr blog, but the HTML support is something that is sadly not so great - quite a few tags are not supported, including the <br> tag.

Unfortunately this makes it hard to have short breaks in blocks of text between groups of paragraphs - empty <p></p> pairs are also stripped out :(

 

However! The <code> tag is not, and using this and a "&nbsp" (non-breaking space) we can create paragraphs that don’t look empty to Tumblr and so aren’t stripped out, but also don’t contain any visible characters, and thus look like an ordinary line break.

The exact HTML is “<p><code>&nbsp;</code></p>” :-)

Basic Raspberry Pi Setup

Earlier this week I took delivery of my Raspberry Pi, and I’ve been setting a few basic things up prior to properly playing around with it - I thought I’d document this to help others who were looking to do the same thing.

I’m using the Debian Squeeze image, using the instructions here (I’m using OSX). When I DD’ed it across to the SD card I got the error “dd: /dev/rdisk1: Invalid argument” but this didn’t stop it working.

The following is how I resized the Raspberry Pi Debian image to the full size of my SD card, enabling the ssh server, and changing the hostname.

Resizing the SD card partition and creation of a swapfile.

The Debian image is sized to fit on a 2GB disk, if your card is larger than this you will have to resize the partitions manually. Note if this works with no problems you won’t loose any data, but just incase it doesn’t go well I did it straight after booting my Pi for the first time, and didn’t have anything on it that I couldn’t afford to loose.

This involves, firing up fdisk, rewriting the partition table, resizing the filesystem to the new partitions, and the creation and mounting of a swapfile.

If you like videos, this one carries out the exact same thing :)

 

To start, run fdisk. “mmcblk0” is where my /boot was mounted (IE the SD card), yours might be different- check with “df -h

sudo fdisk -uc /dev/mmcblk0

(Whilst running fdisk):

“p” (to print the partition table)

“d” (to delete a partition)

“2” (to delete /dev/mmcblk0p2)

“d” (to delete another partition)

“3” (to delete the existing swap partition)

“n” (for creating a new partition)

“p” (for new primary partition)

“2” (for creation of partition number 2)

“157696” (in my case, to create a partition at the same location as the ones just deleted, enter in the old start number of /dev/mmcblk0p2 printed earlier).

Just hitting enter next will use the remaining space of the card, or you can manually specify a size yourself.

“w” (to write the changes)

Reboot the system, (sudo reboot) and the we can resize the filesystem into the new partitions with:

sudo resize2fs /dev/mmcblk0p2 (this will take a while if you have a large card)

Reboot afterwards, and “df -h” will show the new filesystem using all the space of your card!

 

To create the swapfile;

sudo dd if=/dev/zero of=/var/swapfile bs=1M count=128

This creates a 128MB file filled with zeros called /var/swapfile, and might take a little while depending on the speed of your card.

sudo mkswap /var/swapfile (to setup the file as swap space)

sudo swapon /var/swapfile (to enable the swap space, this also might take a little while.)

sudo reboot

 

All thats left now is to edit /etc/fstab and tell the system to mount the file as swap every time it starts up;

sudo nano /etc/fstab

Whilst in nano, delete the line starting with a hash (#), and paste or type in:

/dev/mmcblk0p2  /       ext4    defaults,noatime,nodiratime     0 0

/var/swapfile   none    swap    sw                              0 0

This tells the system to mount the 2nd partition at / in the filesystem, and to mount it with “noatime,nodiratime”, meaning the system will not write when files and directories were last accessed, speed things up a bit. The next line also tells the system to mount the swapfile we made. This file is read at boot time, and tells the system to mount the stated devices automatically each time the system is booted.

“CTRL+W” then “Y” to exit nano and save changes, and then a final reboot is all that’s needed.

Change Hostname:

I also changed the hostname of my Pi, to do this:

sudo nano /etc/hostname (and enter the desired name, “CTRL+W” then “Y” to quit) 

sudo nano /etc/hosts and replace raspberry with the hostname you chose above

sudo /etc/init.d/hostname.sh start (to enable the changes).

Enable SSH:

ssh-keygen (I hit enter for all three options to accept defaults and no passphrase)

sudo service ssh start (to start sshd)

sudo update-rc.d ssh defaults (to run the ssh server on startup by default)

Adding SVG Dashed Line Array Support into Protovis

Recently I wanted to draw dashed lines in Protovis, this particular case was to represent missing data in a time series line chart.

Protovis doesn’t support this natively, and is now no-longer maintained with the Standford Visualisation guys preferring D3.js these days.

However, adding in support for dashed lines wasn’t too hard, there were a few posts on google groups mentioning how to add it to V3.2, I was using the latest V3.3.1 (the last and most recent version) so I forked it on GitHub and made the changes, mainly adding in options and defaults for the SVG1.1 stroke-dasharray attribute.

You can then do something like the following to create various dashed lines, see the SVG docs for more info.

context.add(pv.Line) .data(myData) .left(function(d) x(d.x)) .bottom(function(d) y(d.y)) .strokeStyle(function(d) d.colour) .segmented(true) .strokeDasharray('2,2') .lineWidth(2);

NB: You’ll need to set the segmented attribute if you want to have parts of lines dashed and others not, etc, just like for colours and other styles.

The new fork is available here, and the commit log shows just what was added for this support- as you can see it’s not a lot, and might serve other people well if they wish to add other SVG options to Protovis, or just draw some dashed lines :-)

Dude, where’s my 10.7 Lion FileMerge.app!?

Recently I wanted to merge two files, and had been using git on OSX 10.6 Snowleopard to do all my merging commits etc. 

I tried to fire up the FileMerge.app that is included with the Developer Tools in 10.6, only to find it’s nowhere to be found in 10.7 Lion. Some rummaging found it, hiding inside Xcode 4, that I downloaded from the app store.

It can be found in /Applications/Xcode.app/Contents/Applications along with Application Loader.app, Icon Composer.app, Instruments.app and OpenGL ES Performance Detective.app if you’re looking for those too!

(Note I’m running Xcode 4.3.2 (4E2002) from the App Store on Lion 10.7.3 , YMMV.

EuroSys 2012

I submitted a paper to the MPM workshop at Eurosys this year, and it was accepted! I’m off to Berne, Switzerland tomorrow to present the paper, and attend the rest of the conference. It’ll be my first proper conference, so I’m looking forward to it, and the first time Ive been to Switzerland, apart from a quick drive through on a holiday when I was about 14!  

EuroSys 2012

Hugin iPhone4 Camera Lens HFOV Data

I love making panoramas, a lot of photos really benefit from a wide view, and they can come out looking pretty good.

I damaged my 18-55 Kit lens that came with my Canon 450D a while back and now the auto focus isn’t so hot, so I’ve been using my nifty fifty (50mm f/1.8 mkII) loads, and using my panorama tool of choice, Hugin, to stich snaps together when I can’t get far away enough to get it all in one frame.

I recently tried to use Hugin with my iPhone4, which works well apart from where the 450D records focal and lens information in the EXIF data for each photo, which hugin then uses to work out how to stitch the photos together, the iPhone does not. Therefore when you come to add your photos, Hugin will ask you to manually enter the info. Whilst it’s found on the web, it isn’t the easiest thing to find, so I thought I would reproduce it here for good measure (Note this is for panoramas shot with the phone in portrait):

Apple iPhone 4 Hugin Camera settings:

iPhone 4 Camera Focal Length: 3.85

Lens Horizontal Field Of View (HFOV) 47.5

I also create a lens file which you can use to apply these measurements to your images, it can be found here. Just save somewhere with extension .ini, and apply it by selecting your pictures in the “Camera and Lens” tab, and clicking load lens on the right.

Phocus Night shoot

I joined the University Photography Society this year, and last week was our first shooting event - a night shoot around Cambridge. Some of my shots aren’t too awful I think!

Full set here.

Remote Frame / WebDACP

WebDACP is a web front end to an iTunes remote control using the DACP protocol.

I had a houseparty coming up, and I had started work on such a remote control site but it had fallen by the whey side. I thought displaying the current playing song, some album art, info on the band etc could be fun, a nice display to have during the party.

The code is based on DACPy, by Logaritmisk on GitHub which I forked and fixed up into a working state. I then created some HTML templates and used Web.py to serve these up to the local network, as well as some endpoints to present the iTunes current info requested over DACP to the templates as JSON, and then use a bit of jQuery to change the webapp in real time. The server also pulls a brief artist Bio from Last.fm!

The result is in my Github as RemoteFrame.