2010年5月16日 星期日

Running a Buildroot System

Buildroot System for Mini2440

Startup Requirement

In my earlier write up i've showed how to Build a Root File System manually from the ground up base on the FHS, in fact there are a few system tools available to automate this building process systematically, one of this package is Buildroot.

Buildroot come with a set of Makefiles and patches to generate a cross-compilation toolchain and root filesystem using uclibc library mainly for embedded Linux system, targeted processor range from ARM, Power PC, MIPS and x86 and etc. It also help to generate system libraries and application packages simply by selecting the menu option similar to the kernel menuconfig compilation.

Here i will use Buildroot to create a basic rootfile system for mini2440, test run on it and further generate a simple madplay program to play MP3 music without worrying anything about autoconfig and compile process.

This build process require an internet access, a NFS setup environment and assume you have kernel compiled and a bootloader updated in mini2440.



Buldroot Menu Configuration

download a copy from Buildroot and open up the zip file into your home directory, a good thing about Buildroot is it doesn't need root permission to cross compile.

Create a top directory (eg. /arm/sys) where all the system output will be generated.

mkdir /arm/sys
bzip2 -dc buildroot-2010.05-rc2 | tar xvf -


or you may use git to get a download copy.

git clone //git.buildroot.net/buildroot


Change to top directory and start up the menu configuration.

cd buildroot
make menuconfig




You will see a main menu with a highlighting option display, here i will just change a few important settings below.

1) Go to 'Target Architecture' --> select arm

2) Go to 'Target Architecture Variant' --> select arm920t

3) Go to 'Target option' --> select 'System hostname' and change to mini2440, move to 'System banner' and change to Welcome to mini2440, move to 'Generic serial port config' and press space-bar to enable it.

go into 'Generic serial port config' --> select 'Serial port to run a getty on' and select ttySAC0

press 'Exit' to go back to the main menu.

4) Go to 'Toolchain' --> look for 'Enable RPC' option and enable it, move to 'Enable toolchain locale/i18n support' and enable it, move to 'Purge unwanted locales' and enable it, move to 'Locales to keep' and change to C en_US zh_TW.

press 'Exit' to go back to the main menu.

5) Go to 'Target filesystem options' --> select 'ext2 root filesystem' and disable it, move to 'jffs2 root filesystem' and enable it.

go into 'Flash Type' --> select 'NAND flash with 2kB Page and 128 kB erasesize.

press 'Exit' to go back to the main menu.

6) press 'Exit' and 'Yes' to save the configuration settings.

Note, i omit the 'Package Selection for the target' configuration until there is a working copy, i also skip many options like the uclibc C library, Binutils, gcc compiler, Busybox and etc, which Buildroot set by default which you can change to experiment as require.

At last, run the building process.

make


This will take a long time to complete, you can take a break now.

If all goes well, a directory output will be created in the top directory which contain all of the output files, a directory dl is also created consist all of the downloaded source files.

CHANGES    configs  dl    fs        output   scripts  TODO
Config.in COPYING docs Makefile package target toolchain


In the output directory, there are a few more directories.

build  host  images  staging  stamps  target  toolchain

The important one is the staging/usr/bin directory consist of the uclibc version of gcc compiler, set this entry into the search path so that future source compilation can be reference.

export PATH=/arm/sys/buildroot/output/staging/usr/bin:$PATH
arm-linux-gcc -v

使用內建 specs。
目的:arm-unknown-linux-uclibcgnueabi
配置為:/arm/sys/buildroot/output/toolchain/gcc-4.3.4/configure --prefix=/usr --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-unknown-linux-uclibcgnueabi --enable-languages=c --with-sysroot=/arm/sys/buildroot/output/staging --with-build-time-tools=/arm/sys/buildroot/output/staging/usr/arm-unknown-linux-uclibcgnueabi/bin --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-libssp --enable-tls --enable-shared --with-gmp=/arm/sys/buildroot/output/toolchain/gmp --with-mpfr=/arm/sys/buildroot/output/toolchain/mpfr --enable-threads --disable-multilib --disable-decimal-float --with-float=soft --with-abi=aapcs-linux --with-arch=armv4t --with-tune=arm920t --disable-largefile --with-pkgversion='Buildroot 2010.05-rc2' --with-bugurl=http://bugs.buildroot.net/
執行緒模型:posix
gcc version 4.3.4 (Buildroot 2010.05-rc2)

Note also, the target directory you will find the hierarchy root filesystem is created here and the image directory with a copy of jffs2 image of the root filesystem.



Extract JFFS2 image filesystem

In this stage i extract the JFFS2 image and dump it into a NFS directory so that i can make any changes whenever it is require.

I will use RAM disk module to open the image, in case there is a problem check whether kernel RAM disk is supported in your environment.

First, use root permission to load the modules and verify it is available.

modprobe mtdblock
modprobe mtdram total_size=32768 erase_size=256
modprobe jffs2
lsmod | grep mtd

mtdram                  2680  0
mtdblock 4132 0
mtd_blkdevs 6124 1 mtdblock
mtd 15948 5 jffs2,mtdram,mtd_blkdevs

Check also the device file is ready.

ls /dev/mtd*

/dev/mtd0  /dev/mtd0ro  /dev/mtdblock0

Once checked, dump the image into the block device and mount it into a new directory.

dd if=/arm/sys/buildroot/output/images/rootfs.jffs2 of=/dev/mtdblock0
mkdir /arm/fs/rootfs
mount -t jffs2 /dev/mtdblock0 /arm/fs/rootfs


If everything works fine, you will find the hierarchy root filesystem in the new directory.

bin  etc   lib      mnt  proc  sbin  tmp  var
dev home linuxrc opt root sys usr


Make a backup of the directory.

cd /arm/fs
tar jcvf rootfs.bz2 rootfs/


Dismount the block device and release the RAM and modules.

umount -t jffs2 /dev/mtdblock0
modprobe -r mtdblock
modprobe -r mtdram
modprobe -r jffs2


Restore the backup file into the new directory.

cd /arm/fs
bzip2 -dc rootfs.bz | tar xvf -


Setup the NFS for the new directory

cp /etc/exports /etc/exports.bak
echo /arm/fs/rootfs *(rw,sync,no_root_squash)>>/etc/exports


Change the bootargs to look at the new directory

setenv bootargs console=ttySAC0 noinitrd init=/sbin/init mini2440=0tb root=/dev/nfs nfsroot=$(serverip):/arm/fs/rootfs ip=$(ipaddr)::$(gateway):$(netmask):mini2440:eth0:off
saveenv


Reboot the device, if its working a final prompt message will show up, this is the result of a basic copy of root filesystem from Builroot, study the etc/inittab, etc/init.d, etc/network, etc/profile and understand the start up process.



Once tested, you can flash the image.



Build additional package from Buildroot

In this section i will include additional library and program to show that it is easy to build a package if you know the name of the library/software, the objective function and its require dependency modules.

Below i add in a zlib library, a tslib touch screen module and include a command-line MP3 player program into our target image.

Start up the menu configuration and make the following changes.

1) Go to 'Package Selection for the target' --> look for 'Libraries' --> select 'Compression and Decompression' --> move to 'zlib' and enable it.

press 'Exit' to go back to the 'Libraries' menu.

2) Go to 'Hardware Handling' --> select 'libts - The Touchscreen tslib library' and enable it.

press 'Exit' to go back to the 'Package Selection for the target' menu.

3) Go to 'Audio and Video libraries and applications --> select 'madplay' and enable it, notice the 'libmad' and 'libid3tag' option is also being set as its dependency modules.

if you want video playback, move to 'mplayer' and its dependant module 'libdvdread' and enable it.

press 'Exit' to go back to the main menu.

4) Go to 'Toolchain' --> select 'Enable large file'

5) press 'Exit' and 'Yes' to save the configuration settings.


Finally, run the building process.

If all goes well, go to the output/target/usr/lib directory, you will find all the libraries is being generated here.

libid3tag.so        libmad.so        libts-0.0.so.0      libz.so        ts
libid3tag.so.0 libmad.so.0 libts-0.0.so.0.1.1 libz.so.1
libid3tag.so.0.3.0 libmad.so.0.2.1 libts.so libz.so.1.2.3


In the output/target/usr/bin directory, you will see the madplay and ts programs.

[         cut         fuser     logger    realpath     test          unzip
[[ dc head logname renice tftp uptime
abxtest deallocvt hexdump lzmacat reset time uudecode
ar diff hostid madplay resize top uuencode
arping dirname iconv md5sum seq tr vlock
awk dos2unix id mesg setkeycodes traceroute wc
basename du install mkfifo setsid ts_calibrate wget
bunzip2 eject ipcrm nohup sha1sum ts_harvest which
bzcat env ipcs nslookup sha256sum ts_print who
chrt ether-wake killall od sha512sum ts_print_raw whoami
chvt expr killall5 openvt sort ts_test xargs
cksum fdformat last passwd strings tty yes
clear find ldd patch tail uniq
cmp fold length printf tee unix2dos
crontab free less readlink telnet unlzma


Now, before we extract the jffs2 image into the new directory there are a few changes to make below.

Edit the ts.conf in buildroot/package/tslib and uncomment the 'module raw input'.

Modify the profile in buildroot/target/generic/target_skeleton/etc to append code below.

for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done


Create a new directory name 'profile.d' to keep our system profile startup script, this will be the tslib.sh to setup the touchscreen environment's setting.

export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_PLUGINDIR=/usr/lib/ts
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_CONSOLEDEVICE=none


Setup the network ip address require in the etc/network/interface file.

# static ip
auto eth0
iface eth0 inet static
address 192.168.1.190
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1


or setup as a dhcp (handy for me as internet connection when flash the image).

# The primary network interface - use DHCP to find our address
auto eth0
iface eth0 inet dhcp


add a new script resolv.sh in profile.d to setup the DNS and domain name for the resolv.conf in order to access to the internet.

echo search domain.com.tw >/tmp/resolv.conf
echo nameserver 168.95.1.1 >>/tmp/resolv.conf


to restart network service, use the init.d script below.

/etc/init.d/S40network restart


Next, modify the device_table.txt in buildroot/target/generic to uncomment the /dev/dsp sound device file require by our madplay program.

Finally, regenerate the image file for the above changes and extract the jffs2 into the new directory again.

make



Once finish copy a few mp3/mpeg files into 'var' directory and reset the device,
log in as root and test the touchscreen library and madplay/mplayer.

ts_calibrate
ts_test




madplay music.mp3

MPEG Audio Decoder 0.15.2 (beta) - Copyright (C) 2000-2004 Robert Leslie et al.
usb 1-1: USB disconnect, address 2
gspca: disconnect complete
6268 frames decoded (0:02:43.7), +0.6 dB peak amplitude, 106 clipped samples

mplayer video.mpeg

MPlayer 1.0rc2.atmel.1-4.3.4 (C) 2000-2007 MPlayer Team
CPU: ARM

Playing video.mpeg.
MPEG-PS file format detected.
VIDEO: MPEG1 320x240 (aspect 1) 30.000 fps 512.0 kbps (64.0 kbyte/s)
==========================================================================
Opening video decoder: [mpegpes] MPEG 1/2 Video passthrough
Read DOCS/HTML/en/video.html for tuning/speedup tips.
If none of this helps you, read DOCS/HTML/en/bugreports.html.

A: 86.3 V: 86.2 A-V: 0.173 ct: 1.346 2585/2585 29% 23% 49.8% 2128 0

Exiting... (End of file)

2010年3月14日 星期日

Madplay Music Player

Madplay Music Player

The madplay is a mp3 player, it is a command line music player without any fancy user front-end, but serve the purpose if we want an easy way to install and test our machine to listen on music.

First download a copy of libmad and libid3tag which is a dependant libraries for mpeg decoding and song's idtag access require by madplay.

unzip the file and configure the libmad, then install it into a temporary install directory.

./configure --host=arm-linux --prefix=/usr --sysconfdir=/etc --libdir=/lib --datadir=/usr/share LDFLAGS="-L/rootfs/lib" CPPFLAGS="-I/rootfs/usr/include"
make
make install DESTDIR=/install/libmad



Note, if there's a -fforce-mem compile error, just remove the CFLAGS option from the Makefile.

Two directories are created lib and usr, copy all the files from the lib directory and usr include header files to our corresponding root filesystem layout.

Now, configure and compile the libid3tag.

./configure --host=arm-linux --prefix=/usr --sysconfdir=/etc --libdir=/lib --datadir=/usr/share LDFLAGS="-L/rootfs/lib" CPPFLAGS="-I/rootfs/usr/include"
make
make install DESTDIR=/install/libid3tag



Two directories also created lib and usr.

Similarly, copy all the files from the lib directory and usr include header files to our corresponding root filesystem layout.

Configure and compile madplay.

./configure --host=arm-linux --prefix=/usr --sysconfdir=/etc --libdir=/lib --datadir=/usr/share LDFLAGS="-L/rootfs/lib" CPPFLAGS="-I/rootfs/usr/include"
make
make install DESTDIR=/install/madplay


Only usr directory is created, copy the 'madplay' bin file in usr/bin directory to our root filesystem bin directory.

Also copy a mp3 music files over.

Restart the board to test the program.

madplay music.mp3

For the Mini2440 i need a audio jack and a speaker to plug into the device in order to listen to the music.

Note, if no music coming out from the player then the kernel may not configure with the correct sound module properly.

Go to the kernel directory and start the menuconfig screen.

ARCH=arm make menuconfig

Need to configure the UDA1341 chipset which Mini2440 is equip with to enable the sound support.

Go to Device Drivers --> Sound card support --> Advance Linux Sound Architecture --> ALSO for SoC Audio support --> Select the UDA134X audio support.


--- ALSA for SoC audio support
<*> SoC Audio for the Samsung S3CXXXX chips
< > SoC AC97 Audio support for LN2440SBC - ALC650
<*> SoC I2S Audio support UDA134X wired to a S3C24XX
< > SoC I2S Audio support for TLV320AIC23 on Simtec boards
< > SoC I2S Audio support for Simtec Hermes board
< > Build all ASoC CODEC drivers


Once finished, compile the kernel and there should be a dsp and mixer device files create in the dev directory.

2010年3月11日 星期四

SDL Multimedia Library

SDL Multimedia Library

SDL is a cross platform multimedia library provide access to low level system hardware and many applications use to operate on MPEG playback.

Since it is a low level software it is usually require as a dependency library to build on other multimedia applications on our device, such as webcam and etc.

Download a copy from SDL and unzip file.

Configure the package and then compile it.

./configure --host=arm-linux --prefix=/usr --sysconfdir=/etc --libdir=/lib --datadir=/usr/share --disable-video-x11 --disable-alsatest --disable-esdtest --disable-arts LDFLAGS="-L/rootfs/lib" CPPFLAGS="-I/rootfs/usr/include"
make



Install into a temporary directory.

make install DESTDIR=/install/SDL-1.2.14


There are 2 directories lib and usr created.

Copy the libraries and header files to our root filesystem.

cp /install/SDL-1.2.14/lib/libSDL* .
cp /install/SDL-1.2.14/lib/pkgconfig/sdl.pc ./pkgconfig
cp /install/SDL-1.2.14/usr/bin/sdl-config /usr/local/arm/4.4.1/bin
cd ../usr/include
cp -r /install/SDL-1.2.14/usr/include/* .



Note, the sdl-config is a shell script which move to our cross-compiler bin directory because it is related to our target-compiled environment.

Modify the /rootfs/lib/libSDL.la libtool library file to point to our root directory.

libdir='/rootfs/lib'



Modify the library reference of sdl.pc in /rootfs/lib/pkgconfig directory as shown below.

prefix=/rootfs
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/usr/include


Modify the sdl-config script as below.
- change /usr to /rootfs
- change ${prefix}/include to ${prefix}/usr/include
- change /lib to ${prefix}/lib


Now, compile the testing program.

Go to test directory in /opt/SDK-1.2.14/test and configure the package.

./configure --host=arm-linux --prefix=/usr --sysconfdir=/etc --libdir=/lib --datadir=/usr/share LDFLAGS="-L/rootfs/lib" CPPFLAGS="-I/rootfs/usr/include"


Modify the Makefile.
- change the include path to start with our root directory eg. /rootfs
- change the lib path to start with -L/rootfs/lib and append -L/rootfs/lib -Wl,-rpath-link,/rootfs/lib


Compile it.

make

Finally, copy the test program to the board for testing (refer to the test/README for a list of the test program description)

I will test the testalpha program.

cd /opt/SDL-1.2.14/test
cp testalpha /rootfs/usr/local/bin
cp icon.bmp /rootfs/usr/local/bin



Restart the board to test the program.

cd /usr/local/bin
testalpha -width 240 -height 320


The above will show a smiley face and you can move it with the pen around the screen.

motion Webcam

motion Webcam on Mini2440

This is an interesting webcam library that will detect movement object on camera and start capturing the motion picture on mpeg format, there are other feature that allow capture video record into a database and also enable remote control of the webcam through xml-rpc.

The library dependencies is on SDL, ffmpeg, SDL is require because ffplay needs it and ffmpeg also require libz library to build it.

Download a copy from motion and ffmpeg.

Install the ffmpeg first which motion rely on its library.

Configure the package.

./configure --prefix=/usr --libdir=/lib --datadir=/usr/share --enable-shared --enable-cross-compile --arch=arm --cc=arm-linux-gcc --host-ldflags="-L/rootfs/lib" --host-cflags="-I/rootfs/usr/include"


then modify the config.mak in the Makefile to replace gcc, ar, ranlib to prefix it with 'arm-linux-'

Compile and install it to a temporary directory.

make
make install DESTDIR=/install/ffmpeg



There are 2 main directories lib and usr are created.

Copy all the files require to our root filesystem.


cd /install/ffmpeg/usr
cp -ar lib/* /rootfs/lib
cp -ar include/* /rootfs/usr/include
cp bin/* /rootfs/usr/local/bin
cd ../lib
cp pkgconfig/* /rootfs/lib/pkgconfig


Change all the libac* package configure files in /rootfs/lib/pkgconfig as shown below.

prefix=/usr
exec_prefix=${prefix}
libdir=/lib
includedir=${prefix}/include


Now, install the motion webcam library.

Configure the package.

./configure --host=arm-linux --prefix=/usr --sysconfdir=/etc --libdir=/lib -datadir=/usr/share --with-ffmpeg=/rootfs LDFLAGS="-L/rootfs/lib" CPPFLAGS="-I/roofs/usr/include"


Change Makefile to add CPPFLAGS = -I/rootfs/usr/include and insert the flags to all the $(CC) compile line.

Compile and install it.

make
make install DESTDIR=/install/motion



There are 2 directories etc and usr are create.

Copy all the files require to our root filesystem.

cd /install/motion/usr
cp bin/* /rootfs/usr/local/bin
cd ../etc
cp motion-dist.conf /rootfs/etc/motion.conf



Change the motion configuration file below.


ffmpeg_cap_motion off
ffmpeg_timelapse 1
target_dir /tmp/cam1


Restart the board to test the library.

First, check our usb camera is connect and recognize in our board (my is a microdia chip from GDMALL)

dmesg|grep usb

usb 1-1: new full speed USB device using s3c2410-ohci and address 2            
usb 1-1: New USB device found, idVendor=0c45, idProduct=60fc
usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
usb 1-1: Product: USB camera
usb 1-1: configuration #1 chosen from 1 choice


Note, the vendor and product id is shown above, if you don't see the message it means the kernel is not configure properly.

Start the motion webcam, it will generate a timelapse mpg output file in the /tmp/cam1 directory.


motion


Go to the output directory to convert it to avi format from the mpeg file to a suitable frame size.

ffmpeg -i 20090103-timelapse.mpg -s 240x320 foo.avi


Finally, view it on device screen.

ffplay -s 240x320 foo.avi


It can be automated to run a serial of commands above to make it as a live video.

For the server process, we can stream over the network and use the browser in our host computer to view it.

First, configure the ffserver.conf to accept flash stream format which i will view it on my pc, below is the important setting.

Fromat swf
VideoBitRate 300
VideoFrameRate 10
VideoSize 320x240
NoAudio


While the motion is still running, i will start up the stream server and use ffmpeg to redirect the motion mpg files into swf and stream it over the network.

ffserver
ffmpeg -i 20090105-timelapse.mpg -vcodec flv -s 320x240 -b
300k -r 10 http://192.168.114.190:8090/feed1.ffm


FFmpeg version 0.5.1, Copyright (c) 2000-2009 Fabrice Bellard, et al.           
configuration: --prefix=/usr --libdir=/lib --datadir=/usr/share --enable-share
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 1 / 52.20. 1
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
built on Mar 11 2010 16:08:38, gcc: 4.4.1
Input #0, mpegvideo, from '20090105-timelapse.mpg':
Duration: 00:00:00.15, bitrate: 104857 kb/s
Stream #0.0: Video: mpeg1video, yuv420p, 320x240 [PAR 1:1 DAR 4:3], 104857 c
Mon Jan 5 06:36:25 2009 192.168.114.190 - - [GET] "/feed1.ffm HTTP/1.1" 200 825
Output #0, ffm, to 'http://192.168.114.190:8090/feed1.ffm':
Stream #0.0: Video: flv, yuv420p, 320x240, q=3-31, 300 kb/s, 1000k tbn, 10 c
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding


Note, the above message show that our input is from the motion mpeg and the output it to flv flash format.

Now, go to the pc and type http://192.168.114.190:8090/test1.swf in the browser, you will see the flash movie which is capture earlier in our motion webcam.




2010年3月7日 星期日

tslib Touch Screen

tslib Touch Screen

This is a very popular library, almost every small device test board use it to navigating on a touch screen with an GUI applications.

It can be download in tslib.

As usual, unzip the file and configure it first.

autogen.sh
echo ac_cv_func_malloc_0_nonnull=yes >config.cache
./configure --host=arm-linux --prefix=/usr --sysconfdir=/etc --libdir=/lib --datadir=/usr/share



Compile the source and install package to a temporary directory, this is to avoid overwrite any files and examine what files are install.

make
mkdir /install
make install DESTDIR=/install/tslib-1.0



Three main directories etc, lib and usr are created.

Copy all the files to our root filesystem.

cd /rootfs/lib
cp /install/tslib-1.0/lib/* .
cd ../usr
cp -a /install/tslib-1.0/usr/include .
mkdir -p local/bin
cp /install/tslib-1.0/usr/bin/* ./local/bin
cd ../etc
cp /install/tslib-1.0/etc/ts.conf .



Modify the ts.conf configuration file, to uncommend the 'module_raw input' line, the contents show as below.

module_raw input
module pthres pmin=1
module variance delta=30
module dejitter delta=100
module linear

Next, create a directory /etc/profile.d and make a shell script tslib.sh to setup the tslib environment variable settings.

export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_PLUGINDIR=/lib/ts
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_CONSOLEDEVICE=none


Add job process to the system profile so that it will automatically export the settings while start up the system.

Edit the /etc/profile to append instructions below to look at the profile.d directory and run the script.

# auto shell script startup process
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done
unset i


Also, make sure to append the new /usr/local/bin directory to the search system PATH.

PATH=$PATH:/usr/local/bin


At last, change the libtool library file and pkgconfig file.

Go to /rootfs/lib change the tslib.la libdir option to '/rootfs/lib' becuase the actual location of this library is in our root filesystem.

Same goes to directory /rootfs/lib/ts for all the '.la' files (input.la is important)

One more, the tslib-0.0.pc pkgconfig file in /rootfs/pkgconfig, change the include and library reference directory show as below.

prefix=/rootfs
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/usr/include

Name: tslib
Description: Touchscreen Access Library
Version: 0.0.2
Libs: -L${libdir} -lts
Cflags: -I${includedir}


Restart the board to test the setup library.

First, use the calibrate utility to initialize and adjust the drawing boundary, it will show a crosshair on screen, touch it with a pen to finish the procedure.

ts_calibrate


Start the test program, touch on the 'Draw' box and drawing on screen is now enable.

ts_test


thttpd Web Server

thttpd Web Server

This is a open source light weight web server to implement HTTP/1.1, easy to setup with minimum effort to get it running.

Download a copy of thttpd to unzip.

Configure and compile it.

./configure --host=arm-linux
make



Note, if there is a conflicting getline error in extras/htpasswd.c change all the getline function to some other name eg. getlines to make it unique.

Copy the thttpd executable file to /rootfs/usr/sbin (this is assume the root filesystem is created in /rootfs directory).


cp thttpd /rootfs/usr/sbin


Create a thttpd.config file in the /rootfs/etc directory for its configuration settings.


dir=/www
user=root
cgipat=/cgi-bin/*
logfile=/tmp/thttpd.log
pidfile=/var/thttpd.pid


Add the command line to the rcS script to start up the http server.

# start HTTP server
thttpd -C /etc/thttpd.config


Create a directory for the web page.


mkdir -p /rootfs/www/cgi-bin


Create a simple index.html program in the www directory.


<html>
<head>
<title>Welcome html</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>


Restart the board, go to the host computer web browser and enter the url of the device ip address eg. http://192.168.114.190/index.html

Note, the board must be configured with network address over the NFS service.



However, to make our target board as a client we have to configure our host as a router which allow network traffic to be redirected to access the internet gateway, this set up assume the target and host is connected via a hub with NFS service.

First create a virtual network interface, this interface is use as a bridge to our target as a logical subnet.

ifconfig eth0:1 192.168.114.254 netmask 255.255.255.0 up

then, configure the interface routing and enable IP Forward function below.

iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface eth0 -j ACCEPT
echo "1">/proc/sys/net/ipv4/ip_forward


next, in the target bootloader environment, change serverip and gateway reference to eth0:1 IP address (eg. as above 192.168.114.254) and update the bootargs.

That's it, reboot target and it should be able to access to the internet.

2010年3月4日 星期四

Build initrd Image

Build initrd Image on Mini2440

Startup Requirement

You need to build a root filesystem.

This build will create an initial RAM disk as a permanent root filesystem in NAND.

On kernel startup, the bootloader pass the load address of initrd image to the kernel to uncompress and copy the contents of the image into RAM, then frees the memory used and mount it as the initial root file system.

In addition jffs2 and cramfs is can also be used to write to the root filesystem.



System Configuration

For the kernel to support the initial RAM disk, the kernel must be compiled with this.

Change the kernel configuration setting below.

ARCH=arm make menuconfig

Go to 'Device Drivers' --> 'Block devices' --> Select RAM disk support

<*> RAM block device support
(16) Default number of RAM disks
(8192) Default RAM disk size (kbytes)


Go to 'Device Drivers' --> 'Memory Technology Devices (MTD) support' --> Select MTD partitioning support, Command line partition table parsing, Direct char and Cahching block device

<*> MTD concatenating support
[*] MTD partitioning support
< > RedBoot partition table parsing
[*] Command line partition table parsing
< > ARM Firmware Suite partition parsing
< > TI AR7 partitioning support
*** User Modules And Translation Layers ***
<*> Direct char device access to MTD devices
-*- Common interface to block layer for MTD 'translation layers
<*> Caching block device access to MTD devices


Go to 'File systems' --> Select Extended fs support

<*> Second extended fs support
[*] Ext2 extended attributes
[*] Ext2 POSIX Access Control Lists
[*] Ext2 Security Labels
[ ] Ext2 execute in place support


Go to 'File systems' --> 'Miscellaneous filesystems' --> Select Journalling Flash File system and Compressed ROM file system support

<*> Journalling Flash File System v2 (JFFS2) support
(0) JFFS2 debugging verbosity (0 = quiet, 2 = noisy)
[*] JFFS2 write-buffering support
[ ] Verify JFFS2 write-buffer reads
<*> Compressed ROM file system support (cramfs)





Create initrd Image

First, check the size of the root file system.

du -sh /rootfs

4.0K /rootfs/var
4.0K /rootfs/mnt
4.0K /rootfs/sys
624K /rootfs/bin
4.0K /rootfs/usr/bin
4.0K /rootfs/usr/sbin
12K /rootfs/usr
4.0K /rootfs/proc
3.9M /rootfs/lib
4.0K /rootfs/sbin
4.0K /rootfs/dev
8.0K /rootfs/etc/init.d
36K /rootfs/etc
4.0K /rootfs/tmp
4.6M /rootfs

prepare a temporary storage for the RAM disk.

cd /var/lib/tftpboot
dd if=/dev/zero of=/var/lib/tftpboot/initrd.tmp bs=1k count=8192


Note, the above created a 8 megabytes empty storage which is more than sufficient to save the image.

Create a ext2 filesystem format.

mkfs.ext2 initrd.tmp 8192

mke2fs 1.41.9 (22-Aug-2009)
initrd.tmp is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
2048 inodes, 8192 blocks
409 blocks (4.99%) reserved for the super user
First data block=1
Maximum filesystem blocks=8388608
1 block group
8192 blocks per group, 8192 fragments per group
2048 inodes per group

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Mount the filesystem to a directory.

mkdir /mnt/initrd
mount -o loop initrd.tmp /mnt/initrd


Copy the root filesystem into the directory and change the contents to 'root' ownership.

cp -a /rootfs/* /mnt/initrd
chown -R root.root /mnt/initrd


Dismount the filesystem.


umount /mnt/initrd


Compress the filesystem.


gzip -c -9 initrd.tmp>initrd.gz
ls -l initrd.*


-rw-r--r-- 1 root root 2164377 2010-03-05 16:06 initrd.gz
-rw-r--r-- 1 root root 8388608 2010-03-05 15:47 initrd.tmp


Note, the final RAM disk is only one quarter of the original file size.



Refresh the initrd Image

Power on the board into the bootloader command prompt.

Verify the table information, we need the size and offset of the root partition.

MINI2440 # mtdparts

device nand0 , # parts = 4             
#: name size offset mask_flags
0: u-boot 0x00040000 0x00000000 0
1: env 0x00020000 0x00040000 0
2: kernel 0x00500000 0x00060000 0
3: root 0x07aa0000 0x00560000 0

active partition: nand0,0 - (u-boot) 0x00040000 @ 0x00000000

defaults:
mtdids : nand0=mini2440-nand
mtdparts:

The output shows that root is at the last block and start at 0x00560000 offset address with size of 7aa0000 (about 122 megabytes).

Clean up the root partition.

MINI2440 # nand erase 560000 7aa0000

NAND erase: device 0 offset 0x560000, size 0x7aa0000            
Skipping bad block at 0x06b40000
Skipping bad block at 0x07f80000
Skipping bad block at 0x07fa0000
Skipping bad block at 0x07fc0000
Skipping bad block at 0x07fe0000

OK

Download image into the specify location, make sure you have start up the tftp server.


MINI2440 # tftp 32000000 initrd.gz

dm9000 i/o: 0x20000300, id: 0x90000a46                          
DM9000: running in 16 bit mode
MAC: 08:00:2f:00:00:02
TFTP from server 192.168.114.181; our IP address is 192.168.114.190
Filename 'initrd.gz'.
Load address: 0x32000000
Loading: T T T #################################################################
#################################################################
##################
done
Bytes transferred = 2164377 (210699 hex)

Write image to the root partition, if there is a write problem you may have to refresh the NAND from scratch.

MINI2440 # nand write.e 32000000 560000 ${filesize}

NAND write: device 0 offset 0x560000, size 0x210699             

Writing data at 0x770000 -- 100% complete.
2164377 bytes written: OK

Save the file size, it is use later to setup the boot argument.

MINI2440 # setenv initrd_size $(filesize)
MINI2440 # saveenv


Saving Environment to NAND...                                   
Erasing Nand...Writing to Nand... done


Finally, Set the boot argument to load from the initrd and save all the settings.

MINI2440 # setenv 'bootcmd nand read 32000000 60000 200000;nand read 30800000 560000 ${initrd_size};bootm'
MINI2440 # setenv bootargs initrd=0x30800000,0x${initrd_size} init=/linuxrc root=/dev/ram0 rw console=ttySAC0 mini2440=0tb
MINI2440 # saveenv


Reboot the device to run the new update version.

MINI2440 # reset

U-Boot 1.3.2-mini2440 (Feb 26 2010 - 17:34:45)                            

I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: Bad block table not found for chip 0
Bad block table not found for chip 0
128 MiB
Found Environment offset in OOB..
USB: S3C2410 USB Deviced
In: serial
Out: serial
Err: serial
MAC: 08:00:2f:00:00:02
Hit any key to stop autoboot: 0

NAND read: device 0 offset 0x60000, size 0x200000
2097152 bytes read: OK

NAND read: device 0 offset 0x560000, size 0x2106d4
2164436 bytes read: OK
## Booting kernel from Legacy Image at 32000000 ...
Image Name:
Created: 2010-03-02 14:51:28 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2053096 Bytes = 2 MB
Load Address: 30008000
Entry Point: 30008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux.............................................................
Linux version 2.6.32.7 (root@gmax.localdomain) (gcc version 4.4.1 (Sourcery G++0
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: initrd=0x30800000,0x2106D4 init=/linuxrc root=/dev/ram0 rwb
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 58468KB available (3620K code, 420K data, 128K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
MINI2440: Option string mini2440=0tb
MINI2440: LCD [0:240x320] 1:800x480 2:1024x768 3:240x320 4:640x480
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
S3C24XX CPU Frequency driver, s3c244x cpu support
bio: create slab at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
Trying to unpack rootfs image as initramfs...
rootfs image is not initramfs (no cpio magic); looks like an initrd
Freeing initrd memory: 2112K
squashfs: version 4.0 (2009/01/31) Phillip Lougher
JFFS2 version 2.2. (NAND) �© 2001-2006 Red Hat, Inc.
msgmni has been set to 118
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: ttySAC0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: ttySAC1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: ttySAC2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
at24 0-0050: 1024 byte 24c08 EEPROM (writable)
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=1, 9ns Twrph0=3 29ns, Twrph1=2 19ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-b)
Creating 4 MTD partitions on "NAND 128MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "u-boot"
0x000000040000-0x000000060000 : "u-boot-env"
0x000000060000-0x000000560000 : "kernel"
0x000000560000-0x000008000000 : "root"
dm9000 Ethernet Driver, V1.31
eth0: dm9000e at c486e300,c4872304 IRQ 51 MAC: 08:00:2f:00:00:02 (chip)
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
mice: PS/2 mouse device common for all mice
input: gpio-keys as /devices/platform/gpio-keys/input/input0
s3c2440-ts s3c2440-ts: Starting
Created group ts filter len 12 depth 2 close 10 thresh 6
Created Median ts filter len 20 depth 2 dec 24
Created Mean ts filter len 4 depth 2 thresh 65535
Created Linear ts filter depth 2
s3c2440-ts s3c2440-ts: 4 filter(s) initialized
s3c2440-ts s3c2440-ts: successfully loaded
input: s3c2410 TouchScreen as /devices/virtual/input/input1
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c2410-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c2410-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
s3c-sdi s3c2440-sdi: powered down.
s3c-sdi s3c2440-sdi: mmc0 - using pio, sw SDIO IRQ
Registered led device: led1
Registered led device: led2
Registered led device: led3
Registered led device: led4
Registered led device: backlight
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI UDA134X
No device for DAI s3c24xx-i2s
S3C24XX_UDA134X SoC Audio driver
UDA134X SoC Audio Codec
asoc: UDA134X <-> s3c24xx-i2s mapping ok
ALSA device list:
#0: S3C24XX_UDA134X (UDA134X)
TCP cubic registered
NET: Registered protocol family 17
s3c2410-rtc s3c2410-rtc: setting system clock to 2008-12-29 06:17:58 UTC (12305)
RAMDISK: gzip image found at block 0
VFS: Mounted root (ext2 filesystem) on device 1:0.

Freeing init memory: 128K

Please press Enter to activate this console.
[root@(none) /]#



Create JFFS2 and CRAMFS Image

Alternately, JFFS2 can be used to create a root filesystem.

mkfs.jffs2 -r /rootfs -o rootfs.jffs2 -e 0x20000 -n

Or in CRAMFS format.

mkcramfs /rootfs rootfs.cramfs


Reboot the device into bootloader command prompt.

Download image into the specify location.

MINI2440 # tftp 32000000 rootfs.jffs2


Clean up the root partition.

MINI2440 # nand erase root


Write image to the root partition.

MINI2440 # nand write.e 32000000 root ${filesize}


Set the boot argument to load from the initrd and save all the settings.

MINI2440 # setenv bootcmd 'nboot.e kernel;bootm'
MINI2440 # setenv bootargs noinitrd init=/linuxrc root=/dev/mtdblock3
rootfstype=jffs2 console=ttySAC0 mini2440=0tb
MINI2440 # saveenv


Reboot the device to run the new update version.

MINI2440 # reset

U-Boot 1.3.2-mini2440 (Feb 26 2010 - 17:34:45)                              

I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: Bad block table not found for chip 0
Bad block table not found for chip 0
128 MiB
Found Environment offset in OOB..
USB: S3C2410 USB Deviced
In: serial
Out: serial
Err: serial
MAC: 08:00:2f:00:00:02
Hit any key to stop autoboot: 0

Loading from NAND 128MiB 3,3V 8-bit, offset 0x60000
Image Name:
Created: 2010-03-02 14:51:28 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2053096 Bytes = 2 MB
Load Address: 30008000
Entry Point: 30008000
## Booting kernel from Legacy Image at 32000000 ...
Image Name:
Created: 2010-03-02 14:51:28 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2053096 Bytes = 2 MB
Load Address: 30008000
Entry Point: 30008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux.............................................................
Linux version 2.6.32.7 (root@gmax.localdomain) (gcc version 4.4.1 (Sourcery G++0
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: noinitrd init=/linuxrc root=/dev/mtdblock3 console=ttySAC02
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60584KB available (3620K code, 420K data, 128K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
MINI2440: Option string mini2440=0tb
MINI2440: LCD [0:240x320] 1:800x480 2:1024x768 3:240x320 4:640x480
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
S3C24XX CPU Frequency driver, s3c244x cpu support
bio: create slab at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
squashfs: version 4.0 (2009/01/31) Phillip Lougher
JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
msgmni has been set to 118
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: ttySAC0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: ttySAC1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: ttySAC2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
at24 0-0050: 1024 byte 24c08 EEPROM (writable)
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=1, 9ns Twrph0=3 29ns, Twrph1=2 19ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-b)
Creating 4 MTD partitions on "NAND 128MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "u-boot"
0x000000040000-0x000000060000 : "u-boot-env"
0x000000060000-0x000000560000 : "kernel"
0x000000560000-0x000008000000 : "root"
dm9000 Ethernet Driver, V1.31
eth0: dm9000e at c486e300,c4872304 IRQ 51 MAC: 08:00:2f:00:00:02 (chip)
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
mice: PS/2 mouse device common for all mice
input: gpio-keys as /devices/platform/gpio-keys/input/input0
s3c2440-ts s3c2440-ts: Starting
Created group ts filter len 12 depth 2 close 10 thresh 6
Created Median ts filter len 20 depth 2 dec 24
Created Mean ts filter len 4 depth 2 thresh 65535
Created Linear ts filter depth 2
s3c2440-ts s3c2440-ts: 4 filter(s) initialized
s3c2440-ts s3c2440-ts: successfully loaded
input: s3c2410 TouchScreen as /devices/virtual/input/input1
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c2410-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c2410-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
s3c-sdi s3c2440-sdi: powered down.
s3c-sdi s3c2440-sdi: mmc0 - using pio, sw SDIO IRQ
Registered led device: led1
Registered led device: led2
Registered led device: led3
Registered led device: led4
Registered led device: backlight
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI UDA134X
No device for DAI s3c24xx-i2s
S3C24XX_UDA134X SoC Audio driver
UDA134X SoC Audio Codec
asoc: UDA134X <-> s3c24xx-i2s mapping ok
ALSA device list:
#0: S3C24XX_UDA134X (UDA134X)
TCP cubic registered
NET: Registered protocol family 17
s3c2410-rtc s3c2410-rtc: setting system clock to 2008-12-29 07:08:31 UTC (12305)
VFS: Mounted root (jffs2 filesystem) on device 31:3.
Freeing init memory: 128K

Please press Enter to activate this console.
[root@(none) /]#

2010年3月3日 星期三

Build Root File System

Build Root File System on Mini2440

Startup Requirement

You need to have a compiled busybox and the kernel configure with Virtual File memory, NFS client support and the kernel level autoconfiguration function.

This build will create a new Root File System using the NFS service in the host computer to expose the contents to the target system, there is other method which is build a initrd image and booting with an initial RAM disk.

This is by no means a full system setup but a simple process to boot up a Linux system on Mini2440 as a start, alternatively there are tools that will automate the cross compiling process to generate the filesystem and software packages easily - such as Buildroot, OpenEmbedded and etc. which is another stages of learning process.



Filesystem Hierarchy Standard

In order to build a Root File System i will follow the FHS rules to define the main directories and their layout content as below.
rootfs (/)
|--bin
|--dev
|--etc
| |--init.d
|--lib
|--mnt
|--proc
|--sys
|--sbin
|--tmp
|--usr
| |--bin
| |--sbin
|--var

This RFS is mount as a root directory (/).

Note, there are two components to run a Linux system: the kernel and the RFS.

In this example, busybox is use as a base to construct the minimum set of files to support the system.



Create Root Filesystem Strcuture

First, create a new root directory for our RFS, this directory is export as a NFS shared directory.

mkdir /rootfs

Copy the busybox system files into the root directory.

cd /rootfs
cp -a /usr/src/toolchain/busybox-1.16.0/_install/* .


Create the remaining FHS directories as require.

mkdir dev
mkdir -p etc/init.d
mkdir lib
mkdir mnt
mkdir proc
mkdir sys
mkdir -m 777 tmp
mkdir var


Copy the runtime libraries from the compiler system.

cd /rootfs/lib
cp -a /usr/local/arm/4.4.1/arm-none-linux-gnueabi/libc/armv4t/lib/* .


Make a serial console device as our system standard output.

cd /rootfs/dev
mknod -m 622 console c 5 1


When the kernel is running the last initialization action is to start the init program in charge of finalizing system startup by spawning various applications and running some key software components.

The operation of the init program is define in the inittab file, busybox init has the following default behaviour.

::sysinit:/etc/init.d/rcS
::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a
::restart:/sbin/init

Add a getty on the serial console to the above inittab, depending on the environment variable set in the bootargs (eg. console=ttySAC0) the same device to be set similarly.

::respawn:/sbin/getty -L 115200 /dev/ttySAC0 vt100


Create a rcS job file in the /rootfs/etc/init.d directory to initialize the target system.

#! /bin/sh

# Setup the bin file location and export to system PATH
PATH=/sbin:/bin:/usr/sbin:/usr/bin
umask 022
export PATH

# mount the filesystem directories
mount -a
mkdir /dev/pts
mount -t devpts devpts /dev/pts -o mode=0622

# create device nodes and directories
echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev -s
mkdir /var/lock

# start logging utility services
klogd
syslogd

# set system clock from RTC
hwclock -s

# set host and config loopback interface
ifconfig lo 127.0.0.1

Create a mdev.conf file in the /rootfs/etc directory for the mdev process to do an initial update of the device files dynamically.

# system all-writable devices
full 0:0 0666
null 0:0 0666
ptmx 0:0 0666
random 0:0 0666
tty 0:0 0666
zero 0:0 0666

# console devices
tty[0-9]* 0:5 0660
vc/[0-9]* 0:5 0660

# serial port devices
s3c2410_serial0 0:5 0666 =ttySAC0
s3c2410_serial1 0:5 0666 =ttySAC1
s3c2410_serial2 0:5 0666 =ttySAC2
s3c2410_serial3 0:5 0666 =ttySAC3

# loop devices
loop[0-9]* 0:0 0660 =loop/

# i2c devices
i2c-0 0:0 0666 =i2c/0
i2c-1 0:0 0666 =i2c/1

# frame buffer devices
fb[0-9] 0:0 0666

# input devices
mice 0:0 0660 =input/
mouse.* 0:0 0660 =input/
event.* 0:0 0660 =input/
ts.* 0:0 0660 =input/

# rtc devices
rtc0 0:0 0644 >rtc
rtc[1-9] 0:0 0644

# misc devices
mmcblk0p1 0:0 0600 =sdcard */bin/hotplug
sda1 0:0 0600 =udisk * /bin/hotplug

Create a fstab filesystem table in the /rootfs/etc directory to mount the system directories.
# device mount-point type options dump fsck order
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
var /var tmpfs defaults 0 0

Create a group file in /rootfs/etc directory.

grep root /etc/group>group

Create a password file in /rootfs/etc directory.

grep root /etc/passwd>passwd

Create a system wide 'profile' in /rootfs/etc directory.

USER="`id -un`"                                                 
LOGNAME=$USER
PS1='[\u@\h \W]\# '
PATH=$PATH
HOSTNAME=`/bin/hostname`
export USER LOGNAME PS1 PATH HOSTNAME

Create a /rootfs/etc/issue to add a welcome prompt to the console login.

Welcome to Mini2440
Kernel \r on an \m (\l)



Finally, create a resolv.conf file in /rootfs/etc directory to configure the DNS address to access the internet with your service provider network domain and ip address.

search internet.com.tw
nameserver 192.168.55.244
nameserver 168.95.1.1



Start up the NFS Server

Edit /etc/exports to configure the RFS as a shared directory.

/rootfs *(rw,sync,no_root_squash)

Start up the server.

service nfs restart

Verify the NFS server is running.

showmount -e 192.168.114.181

Export list for 192.168.114.181:
/rootfs *

Reboot the device to run the system.

Restarting system�

U-Boot 1.3.2-mini2440 (Feb 26 2010 - 17:34:45)

I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: 128 MiB
Found Environment offset in OOB..
USB: S3C2410 USB Deviced
In: serial
Out: serial
Err: serial
MAC: 08:00:2f:00:00:02
Hit any key to stop autoboot: 0

Loading from NAND 128MiB 3,3V 8-bit, offset 0x60000
Image Name:
Created: 2010-03-02 14:51:28 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2053096 Bytes = 2 MB
Load Address: 30008000
Entry Point: 30008000
## Booting kernel from Legacy Image at 32000000 ...
Image Name:
Created: 2010-03-02 14:51:28 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2053096 Bytes = 2 MB
Load Address: 30008000
Entry Point: 30008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux.............................................................
Linux version 2.6.32.7 (root@gmax.localdomain) (gcc version 4.4.1 (Sourcery G++0
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: console=ttySAC0 noinitrd init=/sbin/init mini2440=0tb rootf
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60664KB available (3572K code, 388K data, 128K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
NET: Registered protocol family 16
MINI2440: Option string mini2440=0tb
MINI2440: LCD [0:240x320] 1:800x480 2:1024x768 3:240x320 4:640x480
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
S3C244X: Clock Support, DVS off
S3C24XX CPU Frequency driver, s3c244x cpu support
bio: create slab at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
NET: Registered protocol family 1
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
squashfs: version 4.0 (2009/01/31) Phillip Lougher
JFFS2 version 2.2. (NAND) �© 2001-2006 Red Hat, Inc.
msgmni has been set to 118
alg: No test for stdrng (krng)
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler deadline registered
io scheduler cfq registered
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
s3c2440-uart.0: ttySAC0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: ttySAC1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: ttySAC2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
at24 0-0050: 1024 byte 24c08 EEPROM (writable)
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=1, 9ns Twrph0=3 29ns, Twrph1=2 19ns
s3c24xx-nand s3c2440-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xf1 (Samsung NAND 128MiB 3,3V 8-b)
Creating 4 MTD partitions on "NAND 128MiB 3,3V 8-bit":
0x000000000000-0x000000040000 : "u-boot"
0x000000040000-0x000000060000 : "u-boot-env"
0x000000060000-0x000000560000 : "kernel"
0x000000560000-0x000008000000 : "root"
dm9000 Ethernet Driver, V1.31
eth0: dm9000e at c4860300,c4864304 IRQ 51 MAC: 08:00:2f:00:00:02 (chip)
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohci s3c2410-ohci: S3C24XX OHCI
s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1
s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
mice: PS/2 mouse device common for all mice
input: gpio-keys as /devices/platform/gpio-keys/input/input0
s3c2440-ts s3c2440-ts: Starting
Created group ts filter len 12 depth 2 close 10 thresh 6
Created Median ts filter len 20 depth 2 dec 24
Created Mean ts filter len 4 depth 2 thresh 65535
Created Linear ts filter depth 2
s3c2440-ts s3c2440-ts: 4 filter(s) initialized
s3c2440-ts s3c2440-ts: successfully loaded
input: s3c2410 TouchScreen as /devices/virtual/input/input1
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
s3c2410-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c2410-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
i2c /dev entries driver
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
cpuidle: using governor ladder
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
s3c-sdi s3c2440-sdi: powered down.
s3c-sdi s3c2440-sdi: mmc0 - using pio, sw SDIO IRQ
Registered led device: led1
Registered led device: led2
Registered led device: led3
Registered led device: led4
Registered led device: backlight
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
usbhid: v2.6:USB HID core driver
Advanced Linux Sound Architecture Driver Version 1.0.21.
No device for DAI UDA134X
No device for DAI s3c24xx-i2s
S3C24XX_UDA134X SoC Audio driver
UDA134X SoC Audio Codec
asoc: UDA134X <-> s3c24xx-i2s mapping ok
ALSA device list:
#0: S3C24XX_UDA134X (UDA134X)
TCP cubic registered
NET: Registered protocol family 17
s3c2410-rtc s3c2410-rtc: setting system clock to 2008-12-27 10:22:30 UTC (12303)
eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
IP-Config: Complete:
device=eth0, addr=192.168.114.190, mask=255.255.255.0, gw=192.168.114.1,
host=mini2440, domain=, nis-domain=(none),
bootserver=255.255.255.255, rootserver=192.168.114.181, rootpath=
Looking up port of RPC 100003/2 on 192.168.114.181
Looking up port of RPC 100005/1 on 192.168.114.181
VFS: Mounted root (nfs filesystem) on device 0:13.
Freeing init memory: 128K

Please press Enter to activate this console.
[root@mini2440 /]#