Historical EuphoriaAndRaspberryPi, Revision 9

The following is an introduction to building Euphoria (and other software) for your Raspberry Pi. The steps used here should work for other ARM devices as well, including the Nokia N900, B&N Nook Color, etc. This wiki page will not detail how to get started using your Pi, since there are already some excellent tutorials out there. Check out the official Raspberry Pi wiki at http://elinux.org/RPi_Hub and also the forums at http://www.raspberrypi.org/phpBB3/index.php for some good guides. I will try to give explicit details and examples for all aspects concerning Euphoria.


Thanks,
Ira

Getting Started


To get started, we first need to choose a specific distribution to use on the Pi since they have some key differences. This tutorial is based on the Raspbian distribution, since it is currently the officially recommended distribution. Other options include Debian Wheezy, Arch Linux, Fedora, QTonPi, and several more; a complete list is given here. Whichever your preference, it is important to note if the distribution uses the hard-float (-mfloat-abi=hard) or soft (-mfloat-abi=soft) ABI (Application Binary Interface). The hard-float distributions take advantage of the FPU hardware on the Pi for floating point calculations, making software that use extensive floating point calculations significantly faster. Soft float distributions perform these calculations in software, as the name implies. There is also the soft-fp (-mfloat-abi=softfp) convention, which uses FPU hardware but remains compatible with the soft ABI. A decent explanation is given here and here.

Now the easiest way to get Euphoria is to take pre-built binaries which are targeted for your distribution choice, either hard or soft. The link to these binaries are given at the top of page. It is recommended to not mix the binaries (things will usually just break), but the exception is that some soft-float binaries may work fine on a hard-float distribution if the binaries are self-contained and do not depend on any external libraries. The current soft-float binaries do not always work correctly on Raspbian.

To get started, boot up your PI and login. You can either work in the initial terminal presented or start a graphical sessison (type 'startx') and pull up LXTerminal inside LXDE (your desktop environment).

-- Download ARM eubins - This link is for the soft-float version! 
pi@raspberrypi ~/tutorial $ wget http://openeuphoria.org/eubins/linux/4.1.0/arm-32-bit/eubin-arm-cortex-a8-2012-01-13-ee49c6b8a340.tar.gz 
 
-- Unzip 
pi@raspberrypi ~/tutorial $ gunzip eubin-arm-cortex-a8-2012-01-13-ee49c6b8a340.tar.gz  
pi@raspberrypi ~/tutorial $ tar -xvf eubin-arm-cortex-a8-2012-01-13-ee49c6b8a340.tar 
 
-- Make a new euphoria directory 
pi@raspberrypi ~/tutorial $ sudo mkdir -p /usr/share/euphoria/bin 
 
-- Change ownership of the euphoria directory to normal users 
pi@raspberrypi ~/tutorial $ sudo chown -R pi.users /usr/share/euphoria/ 
 
-- Copy binary files into euphoria 
pi@raspberrypi ~/tutorial $ mv *.tar ../. 
pi@raspberrypi ~/tutorial $ cp * /usr/share/euphoria/bin/. 
 
-- Check current path and add the euphoria bin directory 
pi@raspberrypi ~/tutorial $ echo $PATH 
-> /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games 
 
pi@raspberrypi ~/tutorial $ nano ~/.bashrc 
-- Add these lines to the end of .bashrc 
PATH=$PATH:/usr/share/euphoria/bin 
export PATH 
-- End of lines to add to .bashrc 
 
-- Update your path so you can use it now 
pi@raspberrypi ~/tutorial $ source ~/.bashrc  
pi@raspberrypi ~/tutorial $ echo $PATH 
-> /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/share/euphoria/bin 
 
-- Check that Euphoria is working 
pi@raspberrypi ~/tutorial $ eui -v 
->   Euphoria Interpreter v4.1.0 development 
->   32-bit Linux, Using System Memory 
->   Revision Date: 2012-01-07 12:54:32, Id: 5455:ee49c6b8a340 
 
-- Now lets get the source files so we have includes,demos,tests,etc.. 
pi@raspberrypi ~/tutorial $ mkdir src 
pi@raspberrypi ~/tutorial $ cd src/ 
pi@raspberrypi ~/tutorial/src $ wget http://sourceforge.net/projects/rapideuphoria/files/Euphoria/4.0.5/euphoria-LINUX-4.0.5-src.tar.gz 
pi@raspberrypi ~/tutorial/src $ cp -r euphoria-LINUX-4.0.5/* /usr/share/euphoria/. 
 

So remember that on Raspbian, the soft-float euphoria binaries will not work correctly when floating points are involved. First, lets show that the binary we have is indeed soft-float and then do an example of why it doesn't work! Code compiled with hard-float will always have the following line in the 'readelf -A' output: "Tag_ABI_VFP_args: VFP registers"

-- Check eui 
pi@raspberrypi ~/tutorial $ readelf -A /usr/share/euphoria/bin/eui 
Attribute Section: aeabi 
File Attributes 
  Tag_CPU_name: "6" 
  Tag_CPU_arch: v6 
  Tag_ARM_ISA_use: Yes 
  Tag_THUMB_ISA_use: Thumb-1 
  Tag_FP_arch: VFPv2 
  Tag_ABI_PCS_wchar_t: 4 
  Tag_ABI_FP_denormal: Needed 
  Tag_ABI_FP_exceptions: Needed 
  Tag_ABI_FP_number_model: IEEE 754 
  Tag_ABI_align_needed: 8-byte 
  Tag_ABI_enum_size: int 
  Tag_ABI_HardFP_use: SP and DP 
 
-- Check a random binary on your system which is hard float 
pi@raspberrypi ~/tutorial $ readelf -A /usr/bin/curl 
Attribute Section: aeabi 
File Attributes 
  Tag_CPU_name: "6" 
  Tag_CPU_arch: v6 
  Tag_ARM_ISA_use: Yes 
  Tag_THUMB_ISA_use: Thumb-1 
  Tag_FP_arch: VFPv2 
  Tag_ABI_PCS_wchar_t: 4 
  Tag_ABI_FP_denormal: Needed 
  Tag_ABI_FP_exceptions: Needed 
  Tag_ABI_FP_number_model: IEEE 754 
  Tag_ABI_align_needed: 8-byte 
  Tag_ABI_align_preserved: 8-byte, except leaf SP 
  Tag_ABI_enum_size: int 
  Tag_ABI_HardFP_use: SP and DP 
  Tag_ABI_VFP_args: VFP registers 
  Tag_DIV_use: Not allowed 

Ok, so lets prove to ourselves that this soft-float eui does not always work correctly when dealing with atoms!

pi@raspberrypi ~/tutorial $ touch cos.ex 
pi@raspberrypi ~/tutorial $ nano cos.ex 
 
-- Lines to add 
include std/io.e 
include std/math.e 
include std/convert.e 
atom angle, degreesToRadians = 3.14159/180.0 
sequence params = command_line() 
if length(params) = 3 then 
        angle = to_number(params[3]) 
else 
        abort(0) 
end if 
printf(1,"The cos of %0.2f degrees is %0.6f \n",{angle,cos(angle*degreesToRadians)}) 
-- End of lines to add 
 
pi@raspberrypi ~/tutorial $ eui cos.ex 45 
The cos of 45.00 degrees is 6.864136  
-- The answer should be: The cos of 45.00 degrees is "0.707107" 


Cross-compiling Euphoria


First, cross-compiling is the process of compiling software for another architecture on your host system. For example on my Ubuntu Linux desktop, I can compile software for my Windoze 7 laptop or my Armv7 Nokia phone. This tutorial will walk through the steps necessary to cross-compile Euphoria for your Raspberry Pi but will also work for compiling any software to another architecture. I prefer using Scratchbox 2; a cross-compiliation engine which neatly handles the cross-compiling process and is very flexible. More info about the project here. I performed these steps on Ubuntu 12.04 but they should work on most major linux distributions by using your distribution's package manager (apt-get, pacman, yum, etc..). Please note there are easier methods for cross-compiling (such as finding a cross-compiler in the Ubuntu repository and using environment variables), but Scratchbox 2 is still my preferred method.

The key idea behind Scratchbox 2 is that we need a basic root file system (rootfs) of our target architecture and a cross-compiler. The rootfs is available from the Raspberry Pi downloads page. The cross-compiler we are going to use as freely available from the Raspberry Pi github page.

-- Install scratchbox2 and qemu. Replace apt-get with your package manager! 
[ira ~/Code/sbox2] $ sudo apt-get install scratchbox2 qemu-user qemu-system 
 
-- Setup a directory to work in. I use "image"  for downloaded images, "rootfs" to hold the root file system for the Raspberry Pi, 
-- and compilers for my cross-compilers 
[ira ~/Code/sbox2] $ mkdir images  
[ira ~/Code/sbox2] $ mkdir -p  rootfs/raspbian 
[ira ~/Code/sbox2] $ mkdir compilers 
 
-- We also need a place to mount our images to 
[ira ~/Code/sbox2] $ sudo mkdir -p  /mnt/img 
 
-- Download the latest Raspbian image. Check the [[http://www.raspberrypi.org/downloads | downloads page]] to select another image! 
[ira ~/Code/sbox2/images] $ wget http://files.velocix.com/c1410/images/raspbian/2012-12-16-wheezy-raspbian/2012-12-16-wheezy-raspbian.zip 
 
-- To be safe, check the sha1sum to ensure the download is correct 
[ira ~/Code/sbox2/images] $ sha1sum 2012-12-16-wheezy-raspbian.zip 
514974a5fcbbbea02151d79a715741c2159d4b0a  2012-12-16-wheezy-raspbian.zip 
 
-- Unzip the image so we can work with it 
[ira ~/Code/sbox2/images] $ unzip 2012-12-16-wheezy-raspbian.zip 
Archive:  2012-12-16-wheezy-raspbian.zip 
 inflating: 2012-12-16-wheezy-raspbian.img 
[ira ~/Code/sbox2/images]$ ls 
2012-12-16-wheezy-raspbian.zip  2012-12-16-wheezy-raspbian.img 
 
-- In order to look at only the root file system of the image, we need to find the start of the appropriate sector. 
-- I've made a simple script for showing this information called: getImgOffset 
[ira ~/Code/sbox2/images]$ ./getImgOffset 2012-12-16-wheezy-raspbian.img 
Disk 2012-12-16-wheezy-raspbian.img: 1939 MB, 1939865600 bytes 
255 heads, 63 sectors/track, 235 cylinders, total 3788800 sectors 
Units = sectors of 1 * 512 = 512 bytes 
Sector size (logical/physical): 512 bytes / 512 bytes 
I/O size (minimum/optimal): 512 bytes / 512 bytes 
Disk identifier: 0x00017b69 
 
                        Device Boot      Start         End      Blocks   Id  System 
2012-12-16-wheezy-raspbian.img1            8192      122879       57344    c  W95 FAT32 (LBA) 
2012-12-16-wheezy-raspbian.img2          122880     3788799     1832960   83  Linux 
 
-- We can now mount the section of the image that we are interested in 
[ira ~/Code/sbox2/images]$ ../mountImg 2012-12-16-wheezy-raspbian.img 122880 
 
-- Take a look at the newly mounted system 
[ira ~/Code/sbox2/images]$ ls /mnt/img/ 
bin   dev  home  lost+found  mnt  proc  run   selinux  sys  usr 
boot  etc  lib   media       opt  root  sbin  srv      tmp  var 
 
-- Lets copy the contents of the rootfs to our rootfs/raspbian folder 
[ira ~/Code/sbox2/images]$ sudo cp -r /mnt/img ../rootfs/raspbian/. 
 
-- Lets change the ownership of our new folder to a normal user. Use your username instead of 'ira' here! 
[ira ~/Code/sbox2/images]$ cd ../rootfs 
[ira ~/Code/sbox2/rootfs]$ sudo chown -R ira.users raspbian 
 
-- So now that we have the rootfs, lets get a cross-compiler! 
-- We will be using the official compiler supplied from the Raspberry Pi website 
[ira ~/Code/sbox2/images]$ cd ../compilers 
 
-- If you do not have git installed, do so now. Git is a revision control software for managing software projects; other populuar choices are  
-- svn and mercurial (mercurial is what Open Euphoria now uses) 
[ira ~/Code/sbox2/compilers]$  sudo apt-get install git 
 
-- Get the latest compiler 
[ira ~/Code/sbox2/compilers ]$ git clone git://github.com/raspberrypi/tools 
Cloning into tools... 
remote: Counting objects: 11148, done. 
remote: Compressing objects: 100% (5753/5753), done. 
remote: Total 11148 (delta 6433), reused 9627 (delta 4912) 
Receiving objects: 100% (11148/11148), 219.74 MiB | 2.41 MiB/s, done. 
Resolving deltas: 100% (6433/6433), done. 
 
-- Take a look inside the git repository at the available compilers 
[ira ~/Code/sbox2/compilers ]$  cd tools/arm-bcm2708/ 
 
-- The compiler we want is the "gcc-linaro-arm-linux-gnueabihf-raspbian" 
[ira ~/Code/sbox2/compilers ]$ ls 
arm-bcm2708hardfp-linux-gnueabi  gcc-linaro-arm-linux-gnueabihf-raspbian arm-bcm2708-linux-gnueabi 


Ok, so now we have all the pieces we need to setup Scratchbox 2! We have the root file system from the Raspbian image from the Raspberry Pi website and also a cross-compiler that can compile binaries that run our Raspberry Pi. We now just need Scratchbox to glue it all together for us.

-- We need sb2-init to create a new scratchbox environment using the Raspbian img and compiler 
[ira ~/Code/sbox2/images/rootfs/raspbian ]$ sb2-init -c /usr/bin/qemu-arm raspbianhf /home/ira/Code/sbox/compilers/raspberry-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc 
 
-- Lets check the version of gcc on the host computer 
[ira ~/Code/sbox2/compilers ]$  gcc --version 
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 
Copyright (C) 2011 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions.  There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 
-- Now lets do the same thing but run our commands through Scratchbox. You simply need to append 'sb2' before your command 
-- to have it run through the Scratchbox environemnt 
-- First, lets see what environments we have to work with! 
[ira ~/Code/sbox2/compilers ]$  sb2-config -l 
n900 
raspbianhf 
raspbianSoft 
squeeze 
windoze 
 
-- Set the default target to our raspbian hard float target 
[ira ~/Code/sbox2/compilers ]$ sb2-config -d raspbianhf 
 
-- Check that it was set correctly 
[ira ~/Code/sbox2/compilers ]$ sb2-config showtarget 
raspbianhf 
 
-- Check the version of gcc again but this time use 'sb2' to run it through Scratchbox 
[ira ~/Code/sbox2/compilers ]$  sb2 gcc --version 
arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1+bzr2458 - Linaro GCC 2012.08) 4.7.2 20120731 (prerelease) 
Copyright (C) 2012 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions.  There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 
-- Check to see what specs were used to build this cross-compiler 
[ira ~/Code/sbox2/compilers ]$  sb2 gcc --version 
Target: arm-linux-gnueabihf 
Configured with: /cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/src/gcc-linaro-4.7-2012.08/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-linux-gnueabihf --prefix=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install --with-sysroot=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-languages=c,c++,fortran --disable-multilib --with-arch=armv6 --with-tune=arm1176jz-s --with-fpu=vfp --with-float=hard --with-pkgversion='crosstool-NG linaro-1.13.1+bzr2458 - Linaro GCC 2012.08' --with-bugurl=https://bugs.launchpad.net/gcc-linaro --enable-__cxa_atexit --enable-libmudflap --enable-libgomp --enable-libssp --with-gmp=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpfr=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpc=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-ppl=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-cloog=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-libelf=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-host-libstdcxx='-L/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static/lib -lpwl' --enable-threads=posix --disable-libstdcxx-pch --enable-linker-build-id --enable-plugin --enable-gold --with-local-prefix=/cbuild/slaves/oort61/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-c99 --enable-long-long 
Thread model: posix 
gcc version 4.7.2 20120731 (prerelease) (crosstool-NG linaro-1.13.1+bzr2458 - Linaro GCC 2012.08)  


So finally, we can build Euphoria (or any other software)

-- Grab the latest copy of Euphoria from the mercurial repository 
[ira ~/Code/sbox2] $ hg clone http://scm.openeuphoria.org/hg/euphoria euphoria 
 
-- Setup Euphoria for Arm on the Raspberry Pi 
[ira ~/Code/sbox2] $ cd euphoria/source 
[ira ~/Code/sbox2/euphoria/source] $   ./configure arch=ARM 
 
-- Compile Euphoria but send it through Scratchbox to generate Armv6 hard float binaries 
[ira ~/Code/sbox2/euphoria/source] $ sb2 make  

Search



Quick Links

User menu

Not signed in.

Misc Menu