Cross-Compiling in the Raspberry Pi

At the recent VistA Expo & Symposium 2012, the always visionary Rob Tweed
showed us his recently acquired Raspberry Pi,
and pointed out how interesting for the Education of the community it would be
if we could run GT.M on it.

RaspberryPi.jpg

The Raspberry Pi was indeed conveived as a device for education. More specifically, for stimulating the teaching of basic Computer Science in Schools. At $35 a piece, one can let the card in the hands of a toddler without the same apprehension that one would have for a shiny new laptop. It is also, by design, an open device that exposes the basic elements of a computer in the same way that the personal computers did for us in the early 80's.

 

Here is how Eben Upton, co-founder of the Raspberry Pi Foundation, put it:

"The lack of programmable hardware for children 
– the sort of hardware we used to have in the 1980s –
is undermining the supply of eighteen year olds who know how to program,
so that's a problem for universities,
and then it's undermining the supply of 21 year olds
who know how to program, and that's causing problems for industry."

 

That said, the Raspberry Pi is far from being a simple toy. It is a fully functional computer. It has an ARM processor, can fit a 4Gb SD memory card, 512Mb RAM, has an HDMI video port, an ethernet wired port and two USB ports. Combined with LEGOs It has been used to build a supercomputer. There is also a whealth of educational resources built around the Raspberry Pi.

 

Making strides towards that goal of running GT.M on the Raspberry Pi (but not there yet...), we have started by creating a cross compilation environment that allows us to use a standard Linux laptop (with an Intel i7 processor) to compile code targeted to be executed in the Raspberry Pi's ARM processor.

 

The first challenge for us was to actually put our hands on a Raspberry Pi. They are back ordered by several months, and some stores only sell them as added bonus after one orders more than $350 of goods. We were lucky to get a tip on where to buy one, from Professor Seth Chaiken at SUNY Albany, who work with several students on projects in these cards.

We got one with a prebuild Debian 6 Linux installation in a SD card. Once unpacked and plugged into the network, we started this exploration by building code natively in the Raspberry Pi, as described in this blog post, and verified that we could build CMake natively in the board.

The disadvantage of such approach is the long time that it takes to build code natively. About two hours for the case of CMake, and more than four days in the case of ITK. We don't have the exact time for ITK, because after waiting four days and fearing for the Raspberry Pi to overheat, we stopped the build, and accepted that cross-compilation was the way to go.

Cross-compilation is the process of building in one platform, object code that is targeted to a different platform. In our case, we want to use a standard Intel-based laptop running Ubuntu Linux to build object code that will run in the Raspberry Pi. To get there, we are taking advantage of the capabilities that CMake offers for doing cross-compilation.

The full details are described in this second blog post.

 

The challenge of porting GT.M to the Raspberry Pi has two major pieces, that have been discussed in the EWD Forum:

1) Compile the C source code of GT.M for ARM

2) Add an ARM code generator to the GT.M compiler

 

We, of course, start with (1), which is a lot easier now that GT.M 6.0-000 is configured with CMake. This is the easy part...

 

Part (2) is more challenging, since it involves adding new functionalities to GT.M, that will generate native code for the ARM processor. Ideally, this should be done by targeting a generic ARM platform, and in this way making GT.M available for the thousands of ARM-based devices that are in the market today. The effectiveness of the M language and the M database to work on limited hardware, makes of this combination a very interesting one indeed.

 

At this point,

Elves are working on part (1) from an undisclosed location...

 

 

like0

Comments

Cross-Compiling in the Raspberry Pi

Sam Habiel's picture

Luis, I spent 3 weeks around last Christmas trying to get GT.M to run on a Mac. I got a lot of the C code to compile. The problem is that there are about 100 assembly programs that need to be re-written for the new architecture (Intel Macs use a different x86 assembly instruction set and different alignments for instructions). That was totally outside my expertise, plus, I couldn't guarantee the results of changing the assembly code without a unit test suite/regression tests. I personally would like to see GT.M on a Mac before I see it on ARM devices. At least a Mac runs on an x86-64 instruction set. My guess is that converting assembly code to a RISC architecture will be harder. Sam

 

like0

The ARM port may lead to a Mac port...

Luis Ibanez's picture

Sam,

 

That's a good point.

 

One of the advantages that we saw in creating the CMake configuration for GT.M
(when creating the Debian package for it) was the potential for building it on:

 

(A)  Windows, using MinGW

(B)  Building it on Mac

 

I agree with you that building GT.M natively on Mac will be of great benefit for the community.

 

At this point it is looking like every port to a new architecture will make easier to do the next port. A lot of the effort, as you pointed out, is to figure out what each one of the assembly files is supposed to do, and there are about one hundred of them.

 

To report some news on the bright side, I just got GT.M to compile in Raspberry Pi, but by creating empty stubs for each one of the assembly files. So, we still have a long way to go to build a fully functional GT.M in ARM.

Curiously, most of the work so far is not quite specific to the ARM processor, so, it will be plausible to have a parallel Git branch that is making the same strides for building in the Mac.

 

The Git branch that compiles in the Raspberry Pi is here:

https://github.com/luisibanez/fis-gtm/tree/RaspberryPi

 

It has also been tagged as  RPi-0.1

https://github.com/luisibanez/fis-gtm/tags

 

like0

ARM: Assembly Language Programming

Chris Uyehara's picture

Found this, read a couple of pages in Chapter 3 and it appears to be a good read.

http://www.eng.auburn.edu/~nelson/courses/elec5260_6260/ARM_AssyLang.pdf

like0

Great book

Luis Ibanez's picture

Chris,

Thanks for sharing,
I was in need of a document like this one.

This is indeed a nice document for learning about ARM.
It is great that it includes so many programming examples.

Also useful are the Reference manuals here:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.subset.architecture.reference/index.html

   Thanks

       Luis

 

like0

And for the complete refresher course

Christopher Edwards's picture

This seems to be a tutorial for basics for those that haven't programmed assembly in a good long while...

(Welcome back to Computer Science Operating Systems Class!)

http://www.cl.cam.ac.uk/freshers/raspberrypi/tutorials/os/ok01.html

like0

Kids learning about databases

Rob Tweed's picture

Some background on why I believe this is an important initiative:

http://robtweed.wordpress.com/2013/03/26/mumps-the-proto-database-or-how-to-build-your-own-nosql-database/

Rob

 

like0