Performing tasks at startup on the iMote2


When you finish your final application, you'll likely want it to start up when you turn on your iMote2 and automatically load any needed kernel modules. This page describes how to install kernel modules so they will be automatically loaded, how to automatically make devices in /dev, and how to automatically start programs when the iMote2 boots up.

Running programs and scripts at startup

When Linux starts up, it runs a series of scripts which start up various parts of the system. First, it executes all of the scripts in /etc/rcS.d. Each of these scripts starts with a capital S and a number indicating in what sequence the scripts should be run. Scripts that start with an underscore are disabled and will not be executed.

After rc has finished executing all of the scripts in rcS.d, it will execute the scripts in rc2.d. You should put scripts that you'd consider part of the bootup process in rcS.d, and scripts that you want to run after the system has more or less finished starting up, such as your main application, into rc2.d.

Loading kernel modules

Linux on the iMote2 looks for kernel modules in /lib/modules/2.6.14_r1.0/kernel/drivers/. First, it's possible that the module you need is already there; the superbird drivers are in the superbird directory. If the module you need isn't there, put it into this directory.

If you had to add a module that wasn't already there, you'll also have to edit the /lib/modules/2.6.14_r1.0/modules.dep file. Each line in this file has the full path to a kernel module, followed by a colon, and then a list of full paths to all of the module's dependencies (i.e. other modules that must be loaded first).

Now, you should be able to load your module by typing modprobe lcd-fb (replace lcd-fb with the name of the module you want to load). This will first load the dependencies, and then the module you specified. (You may get error messages that some of the dependencies were already loaded and can't be loaded again; it's safe to ignore these).

Finally, you can control which modules in the modules.dep file are loaded automatically at startup by editing /etc/modules. Specify one module per line. You don't need to include the .ko in the names of the modules.

Automatically making devices in /dev

Most of the devices in /dev are created from the /etc/device_table file at startup. However, this approach expects the devices to have fixed major and minor numbers, so this approach won't work for the drivers you've written since they dynamically choose device numbers. Linux normally uses udev to handle such dynamic devices, but it adds a lot of overhead and is disabled by default on the iMote2

You can, however, write a startup script that does essentially the same thing that you do manually when you want to add a device: look at /proc/devices, find the major device number, and execute mknod. The following sequence of commands, for example, will create a device called /dev/superbird for the superbird device:

	sbnum=`cat /proc/devices | grep -E "superbird$" | awk '{print $1}'`
	mknod /dev/superbird c $sbnum 0

The first line looks in /proc/devices for a line ending with the string "superbird". It then takes the first item on the line, which is the major device number, and sticks it in a variable called $sbnum. The second line then executes mknod, creating /dev/superbird as a character device, with the major device number stored in $sbnum and a minor device number of 0.

If you do this in a script that's in rcS.d, the device will be automatically created at startup. You can find the lines that automatically create the sound, lcd, and superbird devices in S11superbird.