gonium.net » smartgrid http://gonium.net/md so much time, so little to do. Sat, 11 Sep 2010 16:42:09 +0000 en hourly 1 http://wordpress.org/?v=3.0.1 Contiki and Mac OS http://gonium.net/md/2010/07/30/contiki-and-mac-os/ http://gonium.net/md/2010/07/30/contiki-and-mac-os/#comments Fri, 30 Jul 2010 09:52:42 +0000 md http://gonium.net/md/?p=271 At the moment I am building a small demo based on the AVR Raven and Contiki. I was running into some trouble with building the Firmwares on my Mac – this is the documentation of the workarounds.

The Contiki build system depends on some GNU utilities that are not installed. Using the following steps I was able to compile for the “native” (i.a. Mac OS) target:

  1. Install GNU binutils using MacPorts.
  2. Edit “cpu/native/Makefile.native” and adjust the “Compiler Definitions” section like this:

    ### Compiler definitions
    CC = gcc
    LD = gcc
    AS = as
    NM = nm
    # Use GNU ar instead of /usr/bin/ar
    AR = gar
    OBJCOPY = objcopy
    STRIP = strip
    ifdef WERROR
    CFLAGSWERROR=-Werror -pedantic -std=c99 -Werror
    endif
    CFLAGSNO = -Wall -g -I/usr/local/include $(CFLAGSWERROR)
    CFLAGS += $(CFLAGSNO) -D_XOPEN_SOURCE=500 -O
    # Simplify ld arguments
    #LDFLAGS = -Wl,-Map=contiki-$(TARGET).map,-export-dynamic
    LDFLAGS = -Wl

Another issue is the ELF binaries for the AVR Raven boards. These files contain all components of the programs: flash and eeprom
images as well as fuse settings. Unfortunately, avrdude cannot read the ELF format. So you have to extract the flash manually:


$ avr-objcopy -R .eeprom -R .fuse -R .signature -O ihex $NAME.elf $NAME.hex

It works similar for the EEPROM section (where the IP data is stored):

$ avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex webserver6.elf webserver6.eep

You can also check which fuse settings are used:

$ avr-objdump -d -S -j .fuse webserver6.elf
webserver6.elf: file format elf32-avr
Disassembly of section .fuse:
00820000 <__fuse>:
820000: e2 99 ff

The directory structure of Contiki is somewhat overwhelming. I am currently working in these directories:

  1. contiki-2.4/platform/avr-ravenlcd: This is where the code for the ATMega3290p lives. Run make here and upload.
  2. contiki-2.4/platform/avr-raven: The ATMega1284p code lives here, this is where most patches are. Don’t run make here!
  3. contiki-2.4/examples/webserver-ipv6-raven: Run make here for the ATMega1284p code. This builds the webserver code and includes the platform/avr-raven dir.

In addition, I have a serial terminal for debugging output:
screen -U /dev/cu.SLAB_USBtoUART 57600

]]>
http://gonium.net/md/2010/07/30/contiki-and-mac-os/feed/ 1
Ruby for Chumby: HowTo http://gonium.net/md/2010/06/02/ruby-for-chumby-howto/ http://gonium.net/md/2010/06/02/ruby-for-chumby-howto/#comments Wed, 02 Jun 2010 15:06:09 +0000 md http://gonium.net/md/?p=261

It took me a while to figure this out, so here are my notes:

  1. Install Scratchbox as described here. This greatly simplifies cross-compiling things. It also provides you a way to run the compiled ruby interpreter on a bigger host machine using QEMU. This is essential because I rely on rubygems, and the Chumby is too small to execute the gem install commands. Besides, at least for the sqlite3-ruby and mongrel gems, I need to compile native code.
  2. Install dependencies. I found the following libraries necessary:
    • OpenSSL 0.9.8n – avoid the 1.0.0 version, it causes problems with the Ruby interpreter.
    • Zlib 1.5.3 – same as installed on the Chumby.
    • Readline 6.1
    • A recent version of sqlite, since I need it for my gems later on.

    Compile the libraries and install them into /mnt/storage (use –prefix where necessary).

  3. Adjust the environment to use the new libraries:
    BASEDIR=/mnt/storage/usr
    export PATH=$PATH:$BASEDIR/bin
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$BASEDIR/lib
  4. Install Ruby and rubygems. I was not able to compile Ruby 1.8.7, but Ruby 1.8.6-p399 works nice. To configure everything, I use the following commands:
    export ac_cv_func_getpgrp_void=yes
    export ac_cv_func_setpgrp_void=yes
    ./configure --target=arm-linux --host=arm-linux --disable-pthread --enable-wide-getaddrinfo --enable-zlib --with-zlib-dir=/mnt/storage/usr --enable-readline --with-readline-dir=/mnt/storage/usr --prefix=/mnt/storage/usr --with-openssl-dir=/mnt/storage/usr && make && make install
  5. Install rubygems:

    /mnt/storage/usr/bin/ruby setup.rb --prefix=/mnt/storage/usr
    mkdir -p /mnt/storage/usr/lib/ruby/gems/1.8
  6. Afterwards, the necessary gems can be installed using the gem command. It might be necessary to provide additonal path information to the gems that compile native extensions, for example
    gem install sqlite3-ruby -- --with-sqlite3-dir=/mnt/storage/usr

The result is an image with Ruby installed, and all necessary gems for my project. The tarball can be downloaded here. To install, scp it to the Chumby and log in:

scp *tarball* root@*chumby-ip*:/mnt/storage
ssh -l root *chumby-ip*
cd /mnt/storage
tar xvzf *tarball*

Now you have a directory /mnt/storage/usr with all tools permanently installed on your Chumby. In order to use it, please adjust your PATH and LD_LIBRARY_PATH appropriately:

export BASEDIR=/mnt/storage/usr
export PATH=$PATH:$BASEDIR/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$BASEDIR/lib

/me mumbles more automation needed. But not today.

]]>
http://gonium.net/md/2010/06/02/ruby-for-chumby-howto/feed/ 0