27 November, 2007

Starting your own init script in Ericsson W25

Update: In the SW version 1.3 you can simply put your init scripts to /rw/etc/init.d/rc.local and do not need this complicated method.


If we want our extra changes remain after restarting the Ericsson W25 we need to reapply them after restarting the router again. Normally this is done by a custom init script which makes the necessary changes for us.

In the W25 we need to do some special tricks to be able to start our own script as most of the /etc directory and the complete /etc/init.d is in a read only filesystem. However we are clever guys and we notice that the /etc/ppp/peers directory is in the rw filesystem and we know that for the pppd we can give a dialer program as a parameter. Let's use this for starting our own init script, when the unit first tries to connect to the 3G network.

We have to change the following line in /etc/ppp/peers/3g:

connect "/usr/sbin/chat -V -f /etc/ppp/chat/3g-connect"

to the following:

connect "/root/lchat -V -f /etc/ppp/chat/3g-connect"

This will call /root/lchat (our secret agent) instead of the standard chat program. After this we have to create the /root/lchat script, which is actually a wrapper for /usr/sbin/chat, but on the first run, it starts the /root/custominit script as well.

/root/lchat should look like this:

#!/bin/sh
if [ ! -e /var/tmp/customboot.tmp ] ; then
touch /var/tmp/customboot.tmp ;
/root/custominit > /dev/null
fi;
/usr/sbin/chat $*

The /var/tmp directory is cleared on every reboot, so this way we can assure that the init script is runing once and only once.

We are done with this, next time we will continue with setting up Dynamic DNS for our box.

17 November, 2007

Software of the Ericsson W25

The Ericsson W25 is running an embebbed linux.

When you power on your device first the bootloader is started. The bootloader is responsible for loading in the complete operating system and start it up. In the Ericsson W25 there is a RedBoot bootloader, which has plenty of features. It is capable of booting from network, from serial devices, it has a telnet interface etc., but in our case it just selects the propper linux kernel and the propper root file system and starts up the linux operating system.

All the software to be loaded is stored in the built in ROM, in 9 partitons:

0x00000000-0x00080000 : "RedBoot"
0x00080000-0x001c0000 : "kernel_A"
0x001c0000-0x007a0000 : "rootfs_A"
0x007a0000-0x008e0000 : "kernel_B"
0x008e0000-0x00ec0000 : "rootfs_B"
0x00ec0000-0x00fa0000 : "rwfs"
0x00fa0000-0x00fe0000 : "test"
0x00fe0000-0x00fff000 : "FIS directory"
0x00fff000-0x01000000 : "RedBoot config"

As you can see the first partitition is the boatloader itself, while the last partition is the configuration for the bootloader. The "FIS directory" is the "Flash Image System directory" which actually holds the addresses of the above listed partitions.

Partition "test" is probably not used.

Partition "rwfs" is the partition which contains the writable parameters of the router. It countains a jffs2 type filesystem.

Partitions 1-4 hold two versions of the kernel and the root file system. This is a good way of making the device more secure, if a firmware update does not sucseed, there is a copy of the earlier version and the device can switch back to the previous version. Probably there are some commands in the device, where you can switch between these partitions, but so far I have not found them.

The used linux is a MontaVista linux, which is a commercial distribution. The main point of using it, that it gives you a complete development environment with support and instead of trying to find the best components to use, you can develop your device very quickly. As in most embebbed linuxes, most of the commands are implemented in Busybox. Busybox is used to reduce the space used by small command files, instead there is one big executable, which is including all the small unix utility commands. The commands can be executed by shortcuts pointing to the busibox executable.

The management of the wireless router is done by Tail-f Systems ConfD product. This utility makes it possible to handle the different configuration interface identically, and it has ready tools to implement a commd line interface, a web interface and SNMP interface. The command line interface is called cf and when called without parameters it gives a help about the available commands.

After booting up, the root file system will be the selected partition from the flash (3 or 5) which has a squashfs filesystem. This contains all the non changing files. The 6 th flash partition is mounted to /rw, here are stored the parameters which are changing, but have to be preserved between the restarts of the router. There is a RAM based filesystem mounted on /var, which is populated during the init procedure from /etc/varfs.tar and it is a tempfs type filesystem.

To be able to use standard tools, the important configuration files from the /etc directory are symlinked to the /rw/etc and when they are changed these chages are kept peristent in the rw filesystem. The advantage of this solution is that it is very simple, but if you want to change a parameter, which it is not prepared for it (e.g. timezone), you can not change it whithout changing the entire read only root filesystem. A better solution would be to use a filesystem like unionfs which can combine a read only and a read write filesystem and store the changes in the writable filesystem.

This is enough from the theory, in the next post I will write about how to make your own init script to start your very own programs after rebooting.