Valladolid Code Retreat, May 2011

I have just attended a Code Retreat event in Valladolid, facilitated by Enrique Comba Riepenhausen. This was an excellent opportunity to meet fellow geeks interested in continuous learning, that were willing to spend a whole Saturday doing pair programming, exchanging ideas about processes and agile practices, and above all, having fun!

Learning is about getting out of your comfort zone, which was definitely my case, as I had to follow practices like TDD or pair programming, and I even paired with guys writing groovy, although the most popular languages were java and python.

Thanks a lot to Enrique, the sponsors and the organizers!

I can only encourage you to look for Code Retreats in your area, or why not organize one yourself? Really worth it!

C++ for embedded?

Recently I was asked by a client about the advantages of C++ over C for a specific embedded project, and these are the ideas I came with:

C exhibits a narrower relationship between source and machine code, which sometimes makes debugging and code optimization easier. Some architectures also have better compiler support for C, although this applies chiefly to some not very common DSPs. In some cases, C may also provide more efficient usage of memory and a reduced runtime when compared to C++.

On the other hand, C++ provides many facilities through the STL that are not part of the standard C library. C++ facilitates information hiding and object orientation in cases where it might be useful. In addition to this, C++ exceptions simplify error handling without the error checking code frequently spread throughout a C program.

I don´t think other C++ features like templates and RTTI are so useful on embedded systems. If your compiler lets you turn these off completely, I would advise you to do it in order to get significant code size savings. It is always advisable to write a test program to check how well your compiler does with C++ features enabled.

The usage of C++ should be mandated by whether their features make sense in your product and a careful evaluation of the benefits they provide against their performance/size costs.

802.15.4 wireless sensor network prototyping

I have been looking into wireless sensor networks for some time, and I definitely need to jump into the wagon and order some development kits to play/experiment and build some prototypes. 802.15.4 is the radio layer used by Zigbee. I am not constrained to using specifically Zigbee and I prefer open-source stacks, but I would like to stay with 802.15.4 as it is more widespread than other technologies like DASH7. My current hardware options are:

  • Libelium. The Squidbee motes provide a prototyping solution based on Arduino, which is designed for teaching and educational purposes, while Waspmote is their commercial platform. They look very efficient and well built , with good documentation and support.
  • Openpicus. These guys provide an interesting platform for prototyping based on open-source software running FreeRTOS.
  • Some of the platforms based on TI’s CC2420 chip.

Wireless sensor networks need to be programmed in an efficient way due to the limited processing, storage and power resources of a typical sensor node, which is difficult to accomplish using high-level languages. Normally C or a specific dialect like e.g. nesC (used on TinyOS) is needed. The operating systems used on the different wireless sensor platforms can be split between free academic implementations, like TinyOs or Contiki, and proprietary OS layers used on Zigbee stacks, like TI´s Z-Stack, Freescale or Ember´s stack. These proprietary implementations don´t provide an unified C API, the only Zigbee compliance requirement being a correct over-the-air behavior. There have been some attempts at building an open-source Zigbee stack, but I am not aware of a successful one.

An interesting project is zigbee-linux, although it has a misleading name as it only covers 802.15.4. Zigbee itself is not compatible with the GPL, but there are efforts underway to bring to the table alternative protocols which are built on top of 802.15.4 and are GPL compatible, like 6lowpan/ROLL. One good option I have found for running an open wireless sensor network stack is SICSLoWPAN, an open-source IPv6 over 802.15.4 stack.

What do you think? Any platform you can recommend?

Agile methods on embedded software

Lately I keep hearing a lot about software companies moving into agile development processes. Irrespectively of the hype surrounding these news, I think some agile practices are really worth implementing in an embedded software environment: I have had great success e.g. with fast development cycles and continuous integration.

However, we need to be cautious with specific issues surrounding embedded systems, which I think make some of the agile practices less suitable for embedded software development:

  • Pair programming is quite difficult to implement as embedded software is complex, with issues involving hardware interfaces, real-time behavior and multitasking; this complexity means it is not easy to achieve a uniform level of knowledge across different areas for different engineers to contribute effectively through this practice.
  • Continuous customer communication may not be effective as most of the embedded systems software remains hidden from the customer, who usually is not able to grasp the inner workings of complex software.

This is what embedded guru Jack Ganssle thinks about the topic. What do you think? Are agile practices definitely worth using in embedded systems development?

Open source tools in the Spanish embedded systems industry

Although I agree that proprietary software should have their own space within the embedded systems industry, there are some open source tools I consider essential when developing embedded software.

Cenatic is the Spanish national reference center on open source technologies. They have published an interesting report on the usage of open source software on the embedded systems industry in Spain. Especially interesting is the comprehensive list of open source tools covering all phases of the development life-cycle, some of which I intend to incorporate into my toolset.

Mentoring SANS SEC401 in Madrid

I will be mentoring a SANS Security 401 class in Madrid, starting the 6th of October. This class gives an overview of many security topics, and provides a great foundation on which to build your security career. I passed the GSEC certification test last year and preparing for it was quite challenging and interesting, with loads of hands-on exercises and very relevant and up-to-date course material.

Most likely the course will be held at HUB Madrid, hope to see you there!

Setting up a NanoBSD router on a Soekris net5501

NanoBSD is a great set of scripts that facilitate the compilation and installation of a custom full FreeBSD system on embedded devices. It is particularly suited for booting from CF cards, as it creates a read-only root file system, with the read-write partitions mounted on RAM (md) so as to reduce wear on the card.

I have had for some time a Soekris net5501 box gathering dust, which I bought to replace the Linksys router I use on my home lan. It is time to roll up my sleeves and get my hands dirty. The Soekris board will be a perfect gateway with around 5W power consumption and no moving parts that allows loads of flexibility to install lan services that are not available (or not so configurable) in a cheap off-the shelf router, like:

  • pf firewall
  • dhcp
  • ntp
  • dns with bind
  • proxy with squid
  • VPN, network monitoring, etc

I have installed a FreeBSD 8.1 system on vmware, to be used for building the NanoBSD images, which together with a null-modem serial cable  for connecting to the net5501 console, and a 4GB Sandisk CF card (yes, I know it is overkill, but it is just 3 euro more than 2GB, the smallest one I can buy) is all I need to give some new life to my Soekris Net5501 box.

Initially I had to update the FlashDevice.sub file with the parameters corresponding to my Sandisk CF card. The quickest way I found of getting the cylinders/heads/sector information for this specific card was to insert it in the Soekris device and boot it up. The BIOS shows the parameters for the inserted card when booting.

These are the different ways to customize a NanoBSD installation:

  • configuration settings that override the default values set within, as well as the kernel compilation settings that will be passed to the buildworld stage.
  • configuration files or scripts copied to the Files directory. The file system hierarchy created on the Files directory gets overlaid into the target root file system during the build, by setting customize_cmd cust_install_files. I got some interesting scripts from here.
  • packages for the software not included in the base system have to be copied to the Pkg directory. These packages will be installed into the target image by setting customize_cmd cust_pkg.

Any configuration changes on the live system need to be written into /cfg, as /etc is mounted on the md (malloc) disk and changes are lost on reboot. It is recommended to keep these changes synchronized with the configuration files in our main computer.

I built the image with

nanobsd –c

There were some issues with booting the CF card, the most annoying being that the boot menu was missing and always the partition 1 was chosen automatically. This issue seems to be caused by boot/boot0sio, so I went to use boot/boot0 instead:


Thus we get the corresponding boot menu after BIOS initialization:

1 Seconds to automatic boot. Press Ctrl-P for entering Monitor.

F1 FreeBSD

F2 FreeBSD


Boot: F1

Furthermore, the TERM environment variable has to match the setting on the terminal program used to connect to the serial console, otherwise there may be issues when displaying programs that use the whole terminal, like vi or sysinstall. I have used vt100 setting on minicom and putty, after updating /etc/ttys accordingly:

ttyu0 “/usr/libexec/getty std.9600” vt100 on secure

Finally, the NanoBSD images can be updated without removing the CF card from the box. In our setup, we have configured two identical partitions to be used alternatively when upgrading the software. When running from partition 1, /root/updatep2 is able to fetch and install remotely a new image on partition 2. Bear in mind there is currently an issue with boot0cfg in these update scripts.

ssh myhost cat _.disk.image.gz | zcat | sh updatep2

And now it is time to bury my head in the pf configuration book and install a bunch of services this box is screaming for.