Nios Community Wiki > Initialization Script

Initialization Script

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 resume services 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 hush 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 custom writing with sash as the initial shell, is to activate hush and some "external" shell commands (such as "ls" and "cat") in busybox. (echo and test ( aks "[" ) are builtin commands with hush and don't need to be activated (this is why hush is much faster with scripts than msh, which is depreciated due to several bugs, anyway)
... / BusyBox / Coreutils  --->

[*] cat 
[*] ls
... / BusyBox / Shells  --->
[*] hush
[*] Support for if/then/elif/else/fi
[*] Support for while and until loops
[*] Support for case ... esac statement
Now we can just call several shell scripts from rc and have them executed by hush (as usual, this is done by defining the interpreter in the first line of the script:
#!/bin/hush

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 writing services 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 is most appropriate,


Example initialization scripts

You must have "hush" shell and the coreutil "cat" enabled in busybox (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 hush. 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", hush 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/hush
#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 -d &
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/hush
#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 

 

Tag page
Viewing 13 of 13 comments: view all
I'm going to try this out when I get home Terminix
Posted 21:54, 7 Jan 2010
wow, exactly what I was looking for. thank you, Play free fashion games,girly games, girl games, shooting games and many more at myplayyard.com, Fashion games Girly Games Watch free TV
Posted 20:26, 8 Jan 2010
i personally find sash to be too limiting - yes, it is good for simple scripts but i'd just as soon use something else and stick with it throughout and between projects wedding planning
Posted 20:51, 8 Jan 2010
I'm going to try this out when I get home, looks interesting hair games
Posted 06:42, 12 Jan 2010
This is how you are suppose to run a script. I am going to try this out for myself. beaumont mesothelioma attorneys
Posted 19:29, 17 Jan 2010
teeth whitening
Posted 08:23, 18 Jan 2010
Choosing discount eyeglass frames online should not sacrifice a wide selection. It is still a pleasure choice to trust an online store that offers different kinds of discount eyeglass frames. Compared with a site that offers only one or two kinds of discount frames, others providing a larger selection of similar products are more preferable. Online Fire Sciences degree AND Nursing degrees AND Online mechanical engineering degree Civil engineering degree AND Online Counseling Psychology Degree
Posted 11:19, 1 Mar 2010
The louis vuitton logo appeared only briefly in the ad on a basketball, the New York Daily News louis vuitton outlet.The ad, which was aired during Super Bowl XLIV, was a montage that louis vuitton wallet of images comparing a luxury lifestyle to a modest lifestyle. louis vuitton sale included working-class people eating lobster and lv eating caviar.Neither Hyundai nor louis vuitton replied to requests for comments, the News said.
Posted 01:25, 9 Mar 2010
Looking for Cheap and Discount rolex sports watches Brands watches lous vuitton handbags gucci handbags herve leger dressor Wallets?
Posted 05:00, 15 Mar 2010
Ltd is a professional trading company that specializes in wholesale high quality Nike and brand Cheap Shoes.We also are suppliers and manufacturers, so we provide the competitive price for all of our products. Nike shoes jordan child, jodan 2010, Nike soccers, all star shoes,adidas shoes,adicolor,running shoes, authentic Jerseys, converse ,women's Jerseys, guccci , ed hardy ,prada ,lv and other brand shoes.
Posted 05:49, 22 Mar 2010
Nice story about this.
Great Nice Pictures
causes back pain knee high shoes lizlange maternity fishing boats sale flu incubation period remedies sore throat cost breast implants muscle weight gain surgery breast reduction girls party ideas women laptop bags car brake parts continuing nursing education cost breast augmentation protein whey powder baby slings carriers bed bugs pictures bedding duvet covers phone pay as you go outdoor swing sets discount dinnerware sets coffee espresso machines salton yogurt maker hair color pictures pictures of haircuts asvab practice test herpes photos easy cooking recipes toy dog breeds herpes simplex 1 personalized dog tags stress fracture foot occupational therapy schools frontline plus cats fleas on humans physical therapy salary scabies pictures pictures of shingles what is blood pressure ibuprofen side effects pictures of ringworm gendongan bayi kain cukin ring sling pouch sling perlengkapan bayi selendang bayi nursing cover selendang baby perlengkapan bayi baru lahir bayi bayi lucu foto bayi parish vintage ebooks download tv series download manga free download make money online health information cell phone review disorders anxiety psat practice test blood preasure smart water filter filter pur water weight loss effects blood pressure side effects socks over knee socks dress Hot News Today Jual Beli Make Money Celebrity Gossip Kesehatan Alternatif Gosip Selebritis celebrity photos celebrity news hot celebrities celebrity blog kesehatan info kesehatan kesehatan kerja pelayanan kesehatan indonesia artis foto artis gambar artis selebriti iklan iklan gratis jual online handphone daily news breaking news local news online news food dehydrator tray massage chair ijoy homedics massage shiatsu evening gown dress evening wedding dress dry face skin gold toe sock window coverings blinds blinds for windows lip gloss cosmetics folding table chairs women high heels stockings high heels treatment of pain chlorine generation makeup lighted mirror pain management specialist lawn pest control garden pest control joint pain causes
Posted 16:08, 20 Jul 2010
Viewing 13 of 13 comments: view all
You must login to post a comment.
SourceForge.net