Welcome, guest ( Login )

WikiHome » Initialization Script

Initialization Script

Version 34, changed by mschnell. 07/23/2008.   Show version history

The init process, that automatically is started by the Kernel, first starts the script file /etc/rc and then uses /etc/inittab to start more processes, if some are defined there.

By default the uCLinux-dist uses an empty inittab thus only /etc/rc is used to bring up the system.

By default the uCLinux-dist uses sash (compiled as the "sh" executable in /bin) as the shell that executes the rc script. This is nice, as sash has a lot of useful "internal" commands and has a very small footprint. OTOH, sash is a very basic shell and can't do things like "if" and does not support pipes from and to files and between the processes it starts. Thus it often is not good enough for more complex shell scripts.

If one day, the uCLinux Tool Chain might support XIP (Execute in place: executables in memory based file systems can be executed without loading [copying] them), it will make more sense to drop sash completely and use msh as the only shell and activate all necessary commands as "external" commands in busybox.

On a  "full" Linux with an MMU-enabled NIOS, supposedly shared libraries can be used, and the concept based on busybox again will need some rethinking.

A way to use more complex shell scripts with sash as the initial shell, is to activate msh and some "external" shell commands (such as "echo" and "cat") in busybox:
... / BusyBox / Coreutils  --->
[*] cat
[*] echo
... / BusyBox / Shells  --->
[*] msh
Now we can just call several shell scripts from rc and have them executed by msh (as usual, this is done by defining the interpreter in the first line of the script:
#!/bin/msh 

and setting the executable flags for the script file.
In rc, the script is now simply called like a normal executable.

Usually the complex script files will be located in /etc. To have them moved there, they are created in vendor/altera/nios2 and the Makefile in that directory is edited to handle them appropriately.

It makes much sense to use one or more simple script files in a Flash file system that are called (i.e. "sourced") by the rc-file(s) and just do some environment settings that are to be acknowledged by the initialization scripts.

These Flash based files can be changed "online" by an appropriate mechanism. Very easy is doing this with FTP (which is enabled in our uCLinux-dist by default). A much more user-friendly way is to do this with a web browser via boa and cgi. Here using a "haserl" script would be most appropriate, but - curiously right now (July 2008) haserl only works on out dist if a syslog() call is added to the source code and the syslog daemon is running (while it works easily on a PC-Linux installation). Any help on this issue is very much appreciated !


Example initialization scripts

You must have "msh" shell and the apps "echo" and "cat" in busybox enabled (see on top)!

An example of cascaded initialization scripts is provided here. These are used in the current version of the binary NEEK distribution that can be found on the TryOutuClinux  page.

/etc/rc is the initial script executed by the init process using /bin/sh (thus sash)

/etc/rc0
is called by rc0 and executed by msh. Here the configuration is read and decisions are made based on the configuration settings. rc0 writes the file /etc/rcc that can be read by any shell using the "source" or "." command to use the preprocessed configuration options.

/etc/rcts does additional system configuration settings

/etc/rca is meant for starting the primary applications (based on configuration settings)

/etc/rcd does the default configuration settings that are used even if the configuration in flash is not (yet) available

/etc/rcc can be read by any shell (sash using the "source", msh using the "." command) to use the preprocessed configuration options. As the environment variables can be e.g. names of additional script files, decisions that are done when rc0 was executed can get effective later.

/mnt/configflash/rc1 is located in the Flash. It does configuration settings and can be edited on the running device.


File /etc/rc (created in vendors/Altera/nios2)

mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t usbfs none /proc/bus/usb
mkdir /var/tmp
mkdir /var/log
mkdir /var/run
mkdir /var/lock
mkdir /var/empty
ifconfig lo 127.0.0.1
route add -net 127.0.0.0 netmask 255.0.0.0 lo
cat /etc/motd

#########################
# FLASH                 #
#########################
mkdir /mnt/configflash
mount -t jffs2 /dev/mtdblock0 /mnt/configflash
#########################
# Read configuration    #
#########################
/etc/rc0
source /etc/rcc

#########################
# APPLICATIONS          #
#########################
/etc/rca

#########################
# AFTER STARTING APPS   #
#########################


File /etc/rc0 (created in vendors/Altera/nios2)

#!/bin/msh
#using the more versatile shell to read the configuration settings
RC=/etc/rcd
if [ -e $RC ]; then
echo reading configuration settings in $RC
. $RC
fi
RC=/mnt/configflash/rc1
if [ -e $RC ]; then
echo reading configuration settings in $RC
. $RC
fi

if [ $NANOX == Y ]; then
RC=/etc/rcts
if [ -e $RC ]; then
echo reading configuration settings in $RC
. $RC
if [ -e $TSLIB_CALIBFILE ]; then
echo touch screen support enabled
export TSLIB_FBDEVICE
export TSLIB_CONSOLEDEVICE
export TSLIB_CALIBFILE
export TSLIB_TSDEVICE
else
export TSLIB_FBDEVICE=none
export TSLIB_CONSOLEDEVICE=none
export TSLIB_CALIBFILE=none
export TSLIB_TSDEVICE=none
fi
fi
fi

RC=/etc/rcc
echo HOSTNAME=$HOSTNAME > $RC
echo DHCP=$DHCP >> $RC
echo IP=$IP >> $RC
echo INETD=$INETD >> $RC
echo BOA=$BOA >> $RC
echo NANOX=$NANOX >> $RC
echo DEMO=$DEMO >> $RC
echo DEMOPIC=$DEMOPIC >> $RC
echo TSLIB_FBDEVICE=$TSLIB_FBDEVICE >> $RC
echo TSLIB_CONSOLEDEVICE=$TSLIB_CONSOLEDEVICE >> $RC
echo TSLIB_CALIBFILE=$TSLIB_CALIBFILE >> $RC
echo TSLIB_TSDEVICE=$TSLIB_TSDEVICE >>$RC
echo =========================
cat $RC
echo =========================

/bin/sh -c hostname $HOSTNAME
if [ $DHCP == Y ]; then
echo starting dhcp client
dhcpcd -p -a -h $HOSTNAME eth0 &
else
echo set IP to $IP
/bin/sh -c ifconfig eth0 $IP
fi

if [ $INETD == Y ]; then
echo starting inetd
inetd &
fi

if [ $BOA == Y ]; then
echo starting boa
boa &
fi

if [ $NANOX == Y ]; then
echo starting nano-X
nano-X &
nanowm &
fi


File /etc/rcts (created in vendors/Altera/nios2)

TSLIB_FBDEVICE=/dev/fb0
TSLIB_CONSOLEDEVICE=none
TSLIB_CALIBFILE=/mnt/configflash/pointercl
TSLIB_TSDEVICE=/dev/input/event0


File /etc/rca (created in vendors/Altera/nios2)

#!/bin/msh
#using the more versatile shell to start application
. /etc/rcc
if [ $DEMO == Y ]; then
echo starting nano-X demo
nxview $DEMOPIC &
fi


File /etc/rcd (created in vendors/Altera/nios2)

# Default configuration
# used if the flash based configuration files are not available
HOSTNAME=uclinux
DHCP=Y
IP=0.0.0.0
INETD=Y
BOA=Y
NANOX=Y
DEMO=Y
DEMOPIC=/etc/p.jpg

File /etc/rcc (created on the fly by rc0)

HOSTNAME=uclinux
DHCP=Y
IP=192.168.37.173
INETD=Y
BOA=Y
NANOX=Y
DEMO=Y
DEMOPIC=/mnt/configflash/demo.jpg
TSLIB_FBDEVICE=/dev/fb0
TSLIB_CONSOLEDEVICE=none
TSLIB_CALIBFILE=/mnt/configflash/pointercl
TSLIB_TSDEVICE=/dev/input/event0

File /mnt/configflash/rc1 (created in the devices flash file system e.g. via FTP)

HOSTNAME=uclinux
DHCP=Y
IP=192.168.37.173
BOA=Y
DEMO=Y
DEMOPIC=/mnt/configflash/demo.jpg


Attachments (0)

  File By Size Attached Ver.