You are on page 1of 62

Linux Training

Lab Book
Embedded Linux training
Lab book
Free Electrons
http://free-electrons.com
1 2004-2009, Free Electrons, http!!"ree-electrons#co$, %reati&e %o$$ons License
Linux Training
Lab Book
About this document
This 'ocu$ent can be "oun' on http!!"ree-electrons#co$!'oc!training!e$be''e'-linux
(t is is co$pose' o" se&eral source 'ocu$ents that )e aggregate "or each training session# These
in'i&i'ual source 'ocu$ents can be "oun' on http!!"ree-electrons#co$!'ocs#
*ore 'etails about our training sessions can be "oun' on http!!"ree-electrons#co$!training#
Copying this document
2004-2010, Free Electrons, http!!"ree-electrons#co$#
This 'ocu$ent is release' un'er the ter$s o" the %reati&e %o$$ons +ttribution-
,hare+like -#0 license# This $eans .ou are "ree to 'o)nloa', 'istribute an' e&en $o'i".
it, un'er certain con'itions#
%orrections, suggestions, contributions an' translations are )elco$e/
2 %op.right 2004-2009, Free Electrons, http!!"ree-electrons#co$, %reati&e %o$$ons License
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Ubuntu Linux installation
Installin Lin!" on #o!r $or%station
&!r trainin la's are (one $ith the )'!nt! 10.04 (istri'!tion
*http://$$$.!'!nt!.com/+, one of the most pop!lar ,-)/Lin!"
(istri'!tions. .e are oin the /es%top e(ition.
-ote: if #o! o thro!h these steps 'efore the trainin session, #o!
can et s!pport '# sen(in e-mail to s!pport0free-electrons.com.
Download Ubuntu
,o to the ne"t pararaph if #o! rea( this at the 'einnin of the
co!rse. 1n )'!nt! c(rom $ill 'e iven to #o! '# #o!r instr!ctor.
If #o! $ish to install )'!nt! /es%top 10.04 'efore the trainin
session, et it from http://$$$.!'!nt!.com/(es%top/et-
!'!nt!/(o$nloa( an( choose the 22 'it *i386+ version.
-ote that $e (on3t s!pport the 44 'it *amd64+ version, 'eca!se it
$on3t 'e a'le to r!n some of the rea(#-ma(e 'inaries $e !se
(!rin the practical la's.
Follo$ the instr!ctions on the (o$nloa( pae to '!rn a c(rom or to
install Lin!" thro!h a )56 (is%.
Freeing space on the hard drive
/o some cleanin !p on #o!r har( (rive. In or(er to install )'!nt!
an( (o the la's in oo( con(itions, #o! $ill nee( 10 ,6 of free
space. .e can (o the la's $ith as little as 7 ,6 of free space, '!t
#o! $ill have to clean !p enerate( files after each la'.
Defragmenting Windows partitions
-o$, (eframent #o!r .in(o$s partitions. .hatever installation
option #o! choose, this $ill !sef!l, either to ma%e more space
availa'le for a separate Lin!" partition, or to et 'etter
performance if #o! choose to install Lin!" insi(e .in(o$s.
Different setup options
8here are several set!p options to !se )'!nt! for the trainin la's:
8he 'est option is to install )'!nt! on #o!r har( (rive. It allo$s
the s#stem to 'e fast an( offer all the feat!res of a properl#
installe( s#stem. 8his option is (escri'e( in the section
9Installing Ubuntu
8he secon( option is to install )'!nt! insi(e a file in a .in(o$s
partition, !sin the .!'i installer availa'le in the )'!nt!
c(rom. 1t each 'oot, #o! $ill 'e iven the choice 'et$een
.in(o$s an( Lin!". 8he a(vantae of this approach is that #o!
$on3t have to mo(if# #o!r .in(o$s partition, an( that #o! can
easil# !ninstall Lin!" $hen #o! no loner nee( it. 8he main
(ra$'ac% is that Lin!" files#stem performance ma# 'e
(era(e(, 'eca!se of the .in(o$s files#stem overhea(. 8his
$ill partic!larl# 'e tr!e if #o!r .in(o$s files#stem is still
heavil# framente( or almost f!ll, as this often happens. ,o to
the 9Installin )'!nt! insi(e .in(o$s: section if #o! choose
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
this option.
Important note: in o!r practical la's, $e (on3t s!pport Lin!"
installations ma(e in a virt!al machine *;<$are, ;irt!al6o", etc.+.
It3s 'eca!se $e $ill nee( to access real har($are *serial port, )56,
etc.+, an( this $ill 'e ver# (iffic!lt to (o thro!h a virt!al machine.
Installing Ubuntu in free hard disk space
If #o! are allo$e( to install ,-)/Lin!" on #o!r =C, #o! ma# choose
to install )'!nt! on #o!r har( (is%.
8he stan(ar( $a# to create space is to shrin% a .in(o$s partition.
If #o! are !sin Microsoft Windows Vista, then !se the (is%
manaement tool provi(e( $ith #o!r operatin s#stem to create
eno!h free space for )'!nt!. If #o! are !sin Microsoft Windows
XP, then ma%e s!re if #o! have eno!h free space an( !se the
(eframentation tool provi(e( $ith #o!r operatin s#stem: the
)'!nt! installer $ill allo$ #o! to shrin% #o!r .in(o$s partition.
Running the Ubuntu installation
8he )'!nt! C/->&< provi(es 'oth a LiveC/ mo(e an( an
installation mo(e. Insert the C/ 'efore po$erin !p #o!r comp!ter,
an( ma%e s!re #o!r comp!ter properl# 'oots from the C/. 1fter a
$hile, the raphical environment $ill sho$ !p: the s#stem is
r!nnin in LiveC/ mo(e. In or(er to install )'!nt! on #o!r har(
(rive, clic% on the installation icon availa'le on the (es%top.
Follo$ the installation process steps !ntil the partitionin step. 1t
that step, select the 9<an!al: mo(e $hich $ill allo$ #o! to access
a partition e(itor. )sin the partition e(itor, #o! can resi?e #o!r
.in(o$s partition '# riht-clic%in on the partition an( selectin
9E(it partition:. &nce eno!h free space is create(, #o! $ill have to
create t$o partitions:
1 partition for the s#stem an( !ser (ata themselves, of aro!n(
10 ,6, $ith the ext4 t#pe, an( the mo!nt point set to /
1 partition for the s$ap, of aro!n( the si?e of the s#stem
memor# *>1<+
&nce (one, #o! can procee( to the ne"t step an( finali?e the
installation. 8he installation process installe( a ,r!' men! that
allo$s #o! to select )'!nt! or .in(o$s at 'oot time.
/dev/hda or /(ev/s(a represents the
first I/E master (is% on #o!r =C. 8hen
/dev/hda1 is the first primar#
partition of the first I/E master (is%.
Free
Windows
system partition
Windows
data partition
Used
Before
Windows
system partition
Windows
data partition
After
Linux
partition
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Contin!e $ith the 9Confi!re the net$or% an( repositories:
pararaph.
Install Ubuntu inside Windows
6oot .in(o$s an( insert the )'!nt! c(rom.
&pen the c(rom an( choose Install inside Windows. In the .!'i
installer, choose an installation (rive $ith at least 7 ,6 of free
space *10 ,6 is stronl# recommen(e(, if #o! (on3t $ant to clean
!p enerate( files at the en( of each la'+.
Choose at least a 7 ,6 installation si?e, or 'etter, 10 ,6.
Let the interface !i(e #o! then.
Configure network and Internet access
<a%e s!re #o! can access the net$or% properl#. )'!nt!
a!tomaticall# !ses /@C= to et an I= a((ress from #o!r net$or%,
so it !s!all# A!st $or%s fla$lessl#.
If #o!r compan# reB!ires to o thro!h a pro"# to connect to the
Internet, #o! can confi!re this thro!h the System ! Preferences
men!. 8hen, start the -et$or% =ro"# (ialo an( t#pe in #o!r pro"#
settins.
Configure package repositories
-o$, ma%e s!re the )'!nt! pac%ae repositories are properl#
ena'le(, '# r!nnin "dministration # Syna$tic Pac%age Manager
in the System men!+ an( ma%e s!re that the main, universe,
restricted an( multiverse repositories are all ena'le( in the
Settings &e$ositories men!.
Co! can also ma%e these chanes '# han( '# e(itin the
/etc/apt/sources.list file, an( !ncommentin the correspon(in
lines. For #o!r convenience, #o! sho!l( !nselect the c(rom
pac%ae so!rce.
<ost of the raphical tools in Lin!" are 'ase( on comman(-line
tools, so there3s !s!all# more than one $a# to confi!re somethinD
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Appl package updates
In 5#naptic, hit the &eload '!tton, $hich $ill (o$nloa( the latest
version of the pac%aes lists from the )'!nt! servers. 8his
operation is the same as r!nnin sudo apt-get update on the
comman( line. 8hen, hit Mar% all u$grades an( then "$$ly. 8his
$ill (o the same as sudo apt-get dist-upgrade in the comman(
line.
e/epen(in on #o!r net$or% connection spee(, this co!l( ta%e
from several min!tes to appro"imatel# one ho!r.
&nce this is (one, remove (o$nloa(e( pac%ae !p(ate files:
sudo apt-get clean
=lease re'oot #o!r comp!ter $hen #o! are (one appl#in the
!p(ates.
>e'ootin is nee(e( after appl#in
%ernel !p(ates, if there $ere an#.
Cleanin (o$nloa(e( pac%ae
!p(ate files can save h!n(re(s of
mea'#tes. 8his is !sef!l if free
space is scarce.
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Training setup
Donloa! files an! !irectories "se! in practical la#s
Install lab data
For the !ifferent la#s in the trainin$, %o"r instr"ctor has prepare! a
set of !ata &'ernel ima$es, 'ernel confi$"rations, root files%stems
an! more(. Donloa! the tar#all at
http://free-electrons.com/la#s/em#e!!e!)lin"*.tar.#+2.
,hen, from a terminal, e*tract the tar#all "sin$ the folloin$
comman!:
cd (going to your home directory)
sudo tar jxf embedded_linux.tar.bz2
sudo chown -R <user>.<user> felabs
La# !ata are no availa#le in a felabs !irector% in %o"r home
!irector%. For each la# there is a !irector% containin$ vario"s !ata.
,his !irector% can also #e "se! as a or'in$ space for each la# so
that %o" properl% 'eep the or' on each la# ell-separate!.
E*it -%naptic if it is still open. .f %o" !on/t, %o" on/t #e a#le to r"n
apt-get install comman!s, #eca"se onl% one pac'a$e
mana$ement tool is alloe! at a time.
0o" are no rea!% to start the real practical la#s1
Install extra packages
2#"nt" comes ith a ver% limite! version of the vi e!itor. .nstall
vim, a improve! version of this e!itor.
sudo apt-get install vim
More guidelines
Can #e "sef"l thro"$ho"t an% of the la#s
3ea! instr"ctions an! tips caref"ll%. Lots of people ma'e
mista'es or aste time #eca"se the% misse! an e*planation or a
$"i!eline.
4la%s rea! error messa$es caref"ll%, in partic"lar the first one
hich is iss"e!. -ome people st"m#le on ver% simple errors 5"st
#eca"se the% specifie! a ron$ file path an! !i!n/t pa% eno"$h
attention to the correspon!in$ error messa$e.
6ever sta% st"c' ith a stran$e pro#lem more than 7 min"tes.
-ho %o"r pro#lem to %o"r collea$"es or to the instr"ctor.
0o" sho"l! onl% "se the root "ser for operations that re8"ire
s"per-"ser privile$es, s"ch as: mo"ntin$ a file s%stem, loa!in$ a
'ernel mo!"le, chan$in$ file onership, confi$"rin$ the
netor'. 9ost re$"lar tas's &s"ch as !onloa!in$, e*tractin$
so"rces, compilin$...( can #e !one as a re$"lar "ser.
.f %o" ran comman!s from a root shell #% mista'e, %o"r re$"lar
"ser ma% no lon$er #e a#le to han!le the correspon!in$
$enerate! files. .n this case, "se the chown -R comman! to $ive
#ac' the ne files to %o"r re$"lar "ser.
E*ample: chown -R myuser.myuser linux-2.6.25
.n De#ian, 2#"nt" an! other !erivatives, !on/t #e s"rprise! if
Em#e!!e! Lin"* 'ernel
an! !river !evelopment
,rainin$ la# #oo'
Em#e!!e! Lin"* 'ernel
an! !river !evelopment
,rainin$ la# #oo'
root permissions are re8"ire! to
e*tract the character an! #loc'
!evice files containe! in the la#
str"ct"re.
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
%o" cannot r"n $raphical applications as root. 0o" co"l! set the
DISPLAY varia#le to the same settin$ as for %o"r re$"lar "ser,
#"t a$ain, it/s "nnecessar% an! "nsafe to r"n $raphical
applications as root.
Em#e!!e! Lin"* 'ernel
an! !river !evelopment
,rainin$ la# #oo'
Em#e!!e! Lin"* 'ernel
an! !river !evelopment
,rainin$ la# #oo'
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Sysdev - Building a cross-compiling toolchain
O!ective: Learn ho" to compile #o$r o"n cross-compilin%
toolchain for the $Clic C lirar#.
&fter this la, #o$ "ill e ale to
Confi%$re the crosstool-n% tool
E'ec$te crosstool-n% an( $il( $p #o$r o"n cross-compilin%
toolchain
Setup
)o to the /home/<user>/felabs/sysdev/toolchain (irector#.
*a+e s$re #o$ have at least 2 ), of free (is+ space.
Install needed packages
-nstall the pac+a%es nee(e( for this la:
sudo apt-get install autoconf automake libtool
sudo apt-get install libncurses-dev bison flex patch
sudo apt-get install cvs texinfo build-essential
sudo apt-get clean
Getting Crosstool-ng
)et the latest 1...' release of Crosstool-n% at http://#morin.is-a-
%ee+.or%/(o+$"i+i/pro!ects/crosstool. E'pan( the archive ri%ht in the
c$rrent (irector#, an( enter the Crosstool-n% so$rce (irector#.
Installing Crosstool-ng
/e can either install Crosstool-n% %loall# on the s#stem, or +eep it
locall# in its (o"nloa( (irector#. /e0ll choose the latter sol$tion. &s
(oc$mente( in docs/overview.txt, (o:
./configure --local
make
make install
1hen #o$ can %et Crosstool-n% help # r$nnin%
./ct-ng help
Configure the toolchain to produce
& sin%le installation of Crosstool-n% allo"s to pro($ce as man#
toolchains as #o$ "ant, for (ifferent architect$res, "ith (ifferent C
liraries an( (ifferent versions of the vario$s components.
Crosstool-n% comes "ith a set of rea(#-ma(e confi%$ration files for
vario$s t#pical set$ps: Crosstool-n% calls them 2samples3. 1he# can
e liste( # $sin% ./ct-ng list-samples.
/e "ill $se the arm-unknown-linux-uclibcgnueabi sample. -t can
e loa(e( # iss$in%:
./ct-ng arm-unknown-linux-uclibcgnueabi
1hen, to refine the confi%$ration, let0s r$n the menuconfig interface:
Eme((e( Lin$'
s#stem (evelopment
1rainin% la oo+
Eme((e( Lin$'
s#stem (evelopment
1rainin% la oo+
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
./ct-ng menuconfig
-n 4ath an( misc options:
Chan%e the prefi' (irector# to
/usr/local/xtools/${CT_TARGET}
1his is the place "here the toolchain "ill e installe(.
Chan%e the n$mer of parallel !os to 2 times the n$mer of
C45 cores in #o$r "or+station. ,$il(in% #o$r toolchain "ill
e faster.
-n 1oolchain options:
6et 21$ple0s alias3 to arm-linux. 1his "a#, "e "ill e ale to
$se the compiler as arm-linux-gcc instea( of arm-unknown-
linux-uclibcgnueabi-gcc, "hich is m$ch lon%er.
-n 7e$% facilities:
Enale %(, strace an( ltrace. 8emove the other options
9(malloc an( ($ma:. -n %( options, enale the ;Cross %(<
an( ;,$il( a static %(server< options= the other options are
not nee(e(.
E'plore the (ifferent other availale options # travelin% thro$%h the
men$s an( loo+in% at the help for some of the options. 7on0t hesitate
to as+ #o$r trainer for (etails on the availale options. >o"ever,
rememer that "e teste( the las "ith the confi%$ration (escrie(
aove.
Produce the toolchain
First, create the (irector# /usr/local/xtools/ an( chan%e its
o"ner to #o$r $ser, so that Crosstool-n% can "rite to it.
1hen, create the (irector# $HOME/src in "hich Crosstool-?) "ill
save the taralls it "ill (o"nloa(.
?othin% is simpler:
./ct-ng build
&n( "ait@
Testing the toolchain
Ao$ can no" test #o$r toolchain # a((in% /usr/local/xtools/arm-
unknown-linux-uclibcgnueabi/bin/ to #o$r PATH environment
variale an( compilin% the simple hello.c pro%ram in #o$r main la
(irector# "ith arm-linux-gcc. Ao$ can $se the file comman( on
#o$r inar# to ma+e s$re it has correctl# een compile( for the &8*
architect$re.
Cleaning up
1o save almost 2 ), of stora%e space, remove the targets/
s$(irector# in the Crosstool-n% (irector#.
Eme((e( Lin$'
6#stem (evelopment
1rainin% la oo+
Eme((e( Lin$'
6#stem (evelopment
1rainin% la oo+
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Lab Using U-Boot
O!ective: interact "ith #-$oot on the $ea%le oar&
On the O'()*+*0 platform, it is possile to compile an& install one,s
o"n version of #-oot. -ee http://elin./.or%/$ea%le$oar&0#-$oot for
&etails.
1n o.r case, a "or2in% version of #-$oot has een pre-installe& on
the oar&, so "e "on,t have to "orr3 ao.t compilin% an& installin%
o.r ootloa&er. 4e "ill &irectl3 start interactin% "ith the installe& #-
$oot.
On the "e,
Setup
5o to the /home/<user>/felabs/sysdev/u-boot-omap/ &irector3.
MMC/SD card setup
6ere are special instr.ctions to format an ''C/-7 car& for the
$ea%le. 8his is not man&ator3 here as "e are %oin% to .se #-oot
from 9(97 flash. 6o"ever, the ''C/-7 car& formate& in this "a3
"ill e .sef.l to .nric2 3o.r $ea%le oar& if 3o. erase the first
sectors of 9(97 flash 3 mista2e. 1f this happens, it "ill allo" to
oot 3o.r o"n version of #-oot from 3o.r ''C/-7 car&.
8o e .se& as a oot &evice, an ''C/-7 car& nee& to have a
special %eometr3 an& a F(8 *2 files3stem.
8o otain this, first connect 3o.r car& rea&er to 3o.r "or2station,
"ith the ''C/-7 car& insi&e. 83pe the dmesg comman& to see
"hich &evice is .se& 3 3o.r "or2station. Let,s ass.me that this
&evice is /dev/sdb.
sd 3:0:0:0: [sdb] 3842048 512-byte hardware sectors:
(1.96 GB/1.83 GiB)
83pe the mount comman& to chec2 3o.r c.rrentl3 mo.nte&
partitions. 1f ''C/-7 partitions are mo.nte&, .nmo.nt them.
1n a terminal open the loc2 &evice "ith fdisk :
$ sudo fdisk /dev/sdb
7ispla3 the on-line help 3 pressin% the m 2e3:
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
1
Lin./ 8rainin%
La $oo2
Lin./ 8rainin%
La $oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
)rint the c.rrent partition tale t3pin% p :
Command (m for help): p
Disk /dev/sdb: 1967 MB, 1967128576 bytes
4rite &o"n the total si:e.
Let,s enter the e/pert mo&e for %eometr3 settin%s :
Command (m for help): x
4e m.st set the %eometr3 to 2++ hea&s, ;* sectors an& calc.late
the n.mer of c3lin&ers correspon&in% to 3o.r ''C car&.
Expert command (m for help) : h
Number of heads (1-256, default 4): 255
Expert command (m for help) : s
Number of sectors (1-63, default 62): 63
Warning : setting sector offset for DOS compatibility
9o" for the n.mer of c3lin&ers, "e consi&er the %loal si:e
<1=;>12?+>; 3tes@ then &ivi&e it 3 <2++A;*A+12@ "hich %ives
aro.n& 2*=.1; c3lin&ers. 4e m.st ro.n& it &o"n to 2*=.
Expert command (m for help) : c
Number of cylinders (1-1048576, default 4): 239
(fter these %eometr3 settin%s, e/it e/pert mo&e <,r, comman&@ then
print a%ain the partition tale to chec2 %eometr3:
Command (m for help): p
Disk /dev/sdb: 1967 MB, 1967128576 bytes
1f an3 partition e/ists, &elete it <,&, comman&@.
9o", let,s create the oot partition :
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-239, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-239, default
239): +64M
'ar2 it ootale:
Command (m for help): a
Partition number (1-4): 1
8hen "e chan%e its t3pe to F(8*2
Command (m for help): t
Selected partition 1
2
Lin./ 8rainin%
La oo2
Lin./ 8rainin%
La oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))
9o" "rite 3o.r chan%es an& e/it:
Command (m for help): w
The partition table has been altered!
...
Format this ne" partition:
sudo mkfs.vfat -n beagleboot -F 32 /dev/sdb1
8hen, remove an& insert 3o.r car& a%ain.
Bo.r ''C/-7 car& is rea&3 to .se in case a prolem happens.
Setting up serial communication with the board
8o comm.nicate "ith the oar& thro.%h the serial port, install a
serial comm.nication pro%ram, s.ch as minicom:
apt-get install minicom
C.n minicom -s, to enter 'inicom,s set.p interface. 1n the Serial
port setup s.section, chan%e the serial &evice to /dev/ttyS0 <or
/dev/ttyUSB0 if 3o. are .sin% a serial to #-$ a&apter@, an& ma2e
s.re that har&"are flo" control is &isale&.
Once this is &one, select Exit, to leave the set.p interface an&
access the serial console.
Bo. sho.l& no" see the #-$oot prompt:
OMAP3 beagleboard.org #
Bo. ma3 nee& to reset the oar&, in case it alrea&3 ootin% an
e/istin% Lin./ 2ernel.
Bo. can no" .se #-$oot. C.n the help comman& to see the
availale comman&s.
1f 3o. "ish to access 'inicom,s men., press [Ctrl][a] follo"e& 3
[z]. Bo. can then choose to e/it 3 pressin% the D/E 2e3, for
e/ample.
Bo. can then connect to /dev/ttyUSB0 .sin% 'inicom an& .se #-
$oot.
U-boot recovery
Later &.rin% this co.rse, if 3o. ma2e a mista2e reflashin% 9(97
flash, 3o. ma3 en& .p "ith a oar& that no lon%er oots.
1f this happens, it,s possile to oot the oar& on an ''C/-7 car&
formatte& accor&in% to the instr.ctions &escrie& earlier in this la.
8o &o this, &o"nloa& the MLO an& u-boot.bin files from http://free-
electrons.com/las/ea%le/ , an& cop3 them to the first, F(8
formatte& partition of 3o.r ''C/-7 car&.
Bo. no" nee& to chan%e the oot or&er an& ma2e the oar& i%nore
the 9(97 flash contents. 8o &o it:
6ol& the USER .tton
)ress the RESET .tter an& release it
*
Lin./ 8rainin%
La $oo2
Lin./ 8rainin%
La $oo2
9o" that minicom is confi%.re&, 3o.
"ill !.st have to r.n minicom instea&
of minicom -s, ne/t time 3o. nee& it.
1f 3o. &on,t li2e 'inicom,s interface,
3o. co.l& also tr3 other pro%rams
"ith a %raphical .ser interface:
c.tecom an& %t2term <apt-get
install cutecom gtkterm@. #sers
familiar "ith 63perterminal on
4in&o"s ma3 prefer these pro%rams.
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Celease the RESET .tton
#-oot sho.l& no" start ''C/-7 ootloa&er, allo"in% 3o. to
repair MLO an& u-boot.bin on 9(97 flash:
mmc init
fatload mmc 0:1 80000000 MLO
8his loa&s the file from ''C 0 partition 1 to memor3 at a&&ress
0/?0000000
nandecc hw
8his comman& enales O'() har&"are ECC for "ritin% to 9(97
since the F-Loa&er <'LO@ is loa&e& 3 the CO'CO7E, "hich .ses
it.
nand erase 0 80000
8his comman& erases a 0/?0000 3te lon% space of the 9(97 flash
from offset 0
nand write 80000000 0 80000
8his comman& "rites &ata to the 9(97 flash. 8he so.rce is
0/?0000000 <"here "e,ve loa&e& the file to store in the flash@ an&
the &estination is offset 0 of the 9(97 flash. 8he len%th of the cop3
is 0/?0000 3tes, "hich correspon&s to the space "e,ve !.st erase&
efore. 1t is important to erase the flash space efore tr3in% to
"rite on it, other"ise it "on,t "or2.
Bo. can no" &o the same "ith #-$oot:
mmc init
fatload mmc 0:1 80000000 u-boot.bin
nandecc sw
nand erase 80000 160000
nand write 80000000 80000 160000
(fter flashin% u-boot.bin, 3o. can remove ''C car&, then reset
the $ea%le oar&. Bo.r oar& sho.l& oot a%ain as it &i& in the
past.
Bo. "ill fin& more &etails on this recover3 process on
http://elin./.or%/$ea%le$oar&Cecover3
8hat,s eno.%h for the momentG 4e "ill oot a Lin./ 2ernel in a
later la.
4
Lin./ 8rainin%
La oo2
Lin./ 8rainin%
La oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Kernel - Kernel sources
O!ective: Learn ho" to #et the $ernel so%rces an& patch
them.
'fter this la, (o% "ill e ale to
)et the $ernel so%rces from the official location
'ppl( $ernel patches
Setup
)o to the /home/<user>/felabs/sysdev/kernel &irector(.
Get the sources
)o to the Lin%* $ernel "e site +http://""".$ernel.or#/, an&
i&entif( the latest stale version.
-%st to ma$e s%re (o% $no" ho" to &o it, chec$ the version of the
Lin%* $ernel r%nnin# on (o%r machine.
.e "ill %se linux-2.6.35, "hich this la "as teste& "ith.
/o practice the patch comman& later, &o"nloa& the f%ll 2.6.34
so%rces. 0npac$ the archive, "hich creates a linux-2.6.34
&irector(.
Apply patches
1nstall the patch comman&, either thro%#h the #raphical pac$a#e
mana#er, or %sin# the follo"in# comman& line:
sudo apt-get install patch
2o"nloa& the 2 patch files correspon&in# to the latest 2.6.35
stale release: a first patch to move from 2.6.34 to 2.6.35 an& a
secon& patch to move from 2.6.35 to 2.6.35.x.
.itho%t %ncompressin# them +3,, appl( the 2 patches to the linux-
2.6.34 &irector(.
4ie" one of the 2 patch files "ith vi or gvim +if (o% prefer a
#raphic e&itor,, to %n&erstan& the information carrie& ( s%ch a
file. 5o" are &escrie& a&&e& or remove& files6
7ename the linux-2.6.34 &irector( to linux-2.6.35.<n>.
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
For (o%r convenience, (o% ma( cop(
the so%rce 07L from (o%r "e
ro"ser an& then %se wget to
&o"nloa& the so%rces from the
comman& line:
wget <url>
wget can contin%e interr%pte&
&o"nloa&s
4im s%pports s%pports s(nta*
hi#hli#htin# for patch files
2i& (o% $no" it6 gvim can open
compresse& files on the fl(3
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Kernel Configuration and compiling
O!ective: #et familiar "ith confi#%rin# an& compilin# the
$ernel
'fter this la, (o% "ill e ale to
Confi#%re, compile an& oot (o%r $ernel on a virt%al 8C.
9o%nt an& mo&if( a root files(stem ima#e ( a&&in# entries
to the /dev/ &irector(.
Setup
:ta( in the /home/<user>/felabs/sysdev/kernel &irector( from
the previo%s la.
Objectives
/he #oal of this la is to confi#%re, %il& an& oot a $ernel for a
minimalistic, virt%al 8C, em%late& ( the qemu em%lator
+http://;em%.or#,
Kernel configuration
7%n make xconfig to start the $ernel confi#%ration interface. /he
$ernel confi#%ration interface is provi&e& as so%rce co&e in the
$ernel, make xconfig compiles it a%tomaticall(, %t re;%ires
liraries an& hea&ers. <o% "ill nee& to install the libqt3-mt-dev
pac$a#e, "hich contains the =t &evelopment files, an& the g++
pac$a#e, the C>> compiler.
1n the interface, to##le the Option -> Show Name option. /his is
%sef%l sometimes, "hen the parameter name is more e*plicit than
its &escription, or "hen (o%?re are follo"in# #%i&elines "hich #ive
the parameter name itself.
'lso tr( the Option -> Show All Options an& Option -> Show
Debug Info options. /he( let (o% see all the parameters "hich
"o%l&n?t appear other"ise, eca%se the( &epen& on the val%es of
other parameters. @( clic$in# on the &escription of s%ch a
parameter, (o% "ill see its precon&itions an& %n&erstan& "h( it is
not selectale.
.e recommen& to fol& %p all cate#ories, so that (o% can clearl( see
ho" the &ifferent options are or#aniAe& in a &oAen of top-level
cate#ories.
Confi#%re (o%r $ernel for a minimalistic 8C:
8enti%m-8ro processor +CONFIG_M686,
12E har& &is$. For this, (o% "ill nee& to enale s%pport for
the 8C1 %s +CONFIG_PCI,, s%pport for the 1ntel E:@, 1C5,
811BC an& 811B4 8'/'/:'/' controllers +CONFIG_ATA_PIIX,,
an& finall( s%pport for :C:1 &is$ +CONFIG_BLK_DEV_SD,. /he
$ernel s%pports 12E &is$s thro%#h the :C:1 stac$, than$s to
liata. :o (o%r 12E &is$ "ill act%all( appear as a :C:1 &is$ in
Lin%*.
ext2 files(stem +CONFIG_EXT2_FS,
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
'lso tr( "ith make menuconfig.
/ho%#h it is not #raphical, some
people prefer this interface. 's the
menuconfig interface is ase& on the
Dc%rses lirar(, (o% "ill have to
install the libncurses-dev pac$a#e
to %se it.
.e a&vise (o% to %nselect all options
at once, an& a&& onl( the ones that
(o% nee&. )et ac$ to (o%r sli&es to
fin& ho" to &o this efficientl(3
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
:%pport for elf inaries +CONFIG_BINFMT_ELF,
:pecif( a version s%ffi*, so that (o% can i&entif( (o%r $ernel in
the r%nnin# s(stem ( r%nnin# uname -r
or cat /proc/version.
/a$e (o%r time to have a loo$ at other availale feat%res3
2on?t hesitate to as$ (o%r trainer for more &etails ao%t a #iven
option.
Compile your kernel
-%st r%n:
make
he !emu "C emulator
qemu is a fast tool "hich can em%late several processors +*EF, ppc,
arm, sparc, mips..., or even entire s(stems.
@( %sin# an em%lator, (o% "on?t have to reoot (o%r "or$station
over an& over a#ain to test (o%r ne" $ernel.
/o install qemu on (o%r s(stem, simpl( install the qemu pac$a#e.
#ooting your kernel
<o% are no" rea&( to +tr( to, oot (o%r ne" $ernel. .e "ill %se the
data/linux_i386.img file as root files(stem.
@ac$ to the main la &irector(, r%n the run_qemu script +!%st a&!%st
the path to the Lin%* $ernel ima#e,:
qemu -m 32 -kernel linux-<ver>/arch/x86/boot/bzImage \
-append "root=/dev/sda rw" \
-hda data/linux_i386.img
1f the $ernel &oesn?t mana#e to oot, an& if the error messa#e is
e*plicit eno%#h, tr( to #%ess "hat is missin# in (o%r $ernel
confi#%ration, an& re%il& (o%r $ernel.
2on?t hesitate to sho" (o%r iss%e to (o%r trainer.
1f (o% are reall( st%c$, (o% can tr( "ith the resc%e confi# file in the
data/ &irector(, "hich (o%r instr%ctor is s%ppose& to have
chec$e&.
1f ever(thin# #oes ri#ht, (o% sho%l& reach the messa#e :
Freeing unused kernel memory: XXXk freed.
'n& nothin# after. /his happens eca%se no console &evice file is
availale in the root files(stem. .itho%t s%ch a file, the shell has no
"a( to interact "ith the har&"are: rea&in# "hat (o% t(pe on the
$e(oar&, an& &ispla(in# the o%tp%t of comman&s on the screen.
1n o%r case, the &evice file the shell is tr(in# to %se is
/dev/console. 'll (o% nee& is to create it3
/(pe [Ctrl] C in the terminal r%nnin# qemu to stop the em%lation
or close the qemu "in&o".
Adding a console device to the root filesystem
0se the follo"in# comman&s in
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
;em% is #oin# to em%late a virt%al 8C
"ith the follo"in# feat%res:
-m: specifies its amo%nt of 7'9.
-hda: specifies the contents +an&
siAe3, of the virt%al har& &is$.
-kernel: $ernel ima#e to oot. ;em%
is here a ootloa&er too. @efore
startin# the em%lation, it copies the
$ernel file to the 7'9 of the virt%al
8C.
-append: options for the $ernel. 1n
partic%lar, root=/dev/sda instr%cts
the $ernel to oot on the first :C:1
har& &is$ of the virt%al 8C.
5ere, "e "on?t nee& to r%n the make
install comman&. 1f "e ran it, the
$ernel "o%l& e installe& for the
"or$station 8C, "hile o%r plans are
to %se an em%late& 8C.
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
/home/<user>/felabs/sysdev/kernel to access the contents of
the files(stem ima#e:
mkdir fs
sudo mount -o loop data/linux_i386.img fs/
Do", create the dev/console &evice that is missin#. <o% can chec$
the /dev/console &evice file on (o%r trainin# "or$station to fin&
o%t the file t(pe as "ell as the ma!or an& minor &evice n%mers.
Once this is &one, %nmo%nt the root files(stem:
sudo umount fs
7er%n (o%r qemu comman&. Do", (o% sho%l& reach a comman& line
shell.
7%n a fe" comman&s in the virt%al 8C shell.
Kernel version
=%er( the version of the r%nnin# $ernel an& ma$e s%re (o% fin& the
version s%ffi* that (o% specifie& at confi#%ration time.
Conclusion
.ell &one3 Do" (o% $no" ho" to confi#%re, compile an& oot a
$ernel on a minimalistic 8C.
Going further
1f (o% complete& (o%r la efore the others...
'&& frame%ffer console s%pport to (o%r $ernel, an& choose
the 4)' 1F color frame%ffer &river. /hen, a&& oot lo#o
s%pport. <o% sho%l& no" see a pen#%in lo#o "hen (o%r virt%al
8C oots.
'&& :98 +:(mmetric 9%lti 8rocessin#, s%pport to (o%r
$ernel. 0sin# the -smp option of qemu, sim%late a 8C "ith 4
processors. <o% sho%l& no" see 4 pen#%ins on the
frame%ffer console, in&icatin# the n%mer of C80s fo%n& on
(o%r s(stem3
'&& frame%ffer console rotation s%pport to (o%r $ernel, an&
mo&if( the $ernel comman& line +-append parameter a#ain, to
oot (o%r $ernel "ith a G0 &e#ree anticloc$"ise rotation.
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
root permissions are re;%ire& to
create an entr( in /mnt/, as "ell as
to r%n the mount comman&
.hatever the architect%re Lin%* r%ns
on, ma!or an& minor &evice n%mers
are al"a(s the same.
/o %nmo%nt a files(stem, rememer
that (o% m%st e outside of the
&irector( "here the files(stem is
mo%nte&. Other"ise umount "ill fail
"ith Device or resource busy.
1f (o% &on?t %mo%nt a files(stem or
&o not %se special mo%nt options, (o%
can?t e s%re that (o%r chan#es have
alrea&( een committe& on the
ph(sical me&ia +the .img file in this
case,.
2on?t e s%rprise& if the "hole
$ernel so%rces are recompile& after
enalin# :98 s%pport. /his chan#es
man( &ata str%ct%res thro%#ho%t the
$ernel so%rces.
<o% "ill fin& &etails ao%t ho" to %se
console rotation in the
2oc%mentation/f/fcon.t*t file.
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
Eme&&e& Lin%*
$ernel %sa#e
/rainin# la oo$
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Kernel Cross-compiling
O!ective: Learn ho" to cross-compile a #ernel for an O$%&
tar'et platform.
%fter this la, (o) "ill e ale to
*et )p a cross-compilin' environment
Confi')re the #ernel Makefile accor+in'l(
Cross compile the #ernel for the ,ea'le arm oar+
-se --,oot to +o"nloa+ the #ernel
Chec# that the #ernel (o) compile+ can oot the s(stem
Setup
.o to the /home/<user>/felabs/sysdev/xkernel +irector(.
/f (o) haven0t +one the previo)s las, install the follo"in'
pac#a'es: libqt3-mt-dev, g++
%lso install uboot-mkimage.
Target system
1e are 'oin' to cross-compile an+ oot a Lin)2 #ernel for the 3/
O$%& ,ea'le oar+.
Getting the sources
1e are 'oin' to )se the Lin)2 2.4.56 so)rces for this la. 3his time,
"e "ill )se ketchup to fetch these so)rces.
First, create an empt( linux-2.6.35 +irector( an+ 'o into it. 7o",
r)n:
ketchup -G 2.6.35
Cross-compiling environment setup
3o cross-compile Lin)2, (o) nee+ to install the cross-compilin'
toolchain. 1e "ill )se the cross-compilin' toolchain that "e
previo)sl( pro+)ce+, so "e !)st nee+ to ma#e it availale in the
&%38:
export PATH=/usr/local/xtools/arm-unknown-linux-
uclibcgnueabi/bin:$PATH
Makefile setup
$o+if( the toplevel $a#efile file to cross-compile for the arm
platform )sin' the aove toolchain.
Linux kernel configuration
,( r)nnin' ma#e help, fin+ the proper $a#efile tar'et to confi')re
the #ernel for the O$%& ,ea'le oar+. Once fo)n+, )se this tar'et
to confi')re the #ernel "ith the rea+(-ma+e confi')ration.
9on0t hesitate to vis)ali:e the ne" settin's ( r)nnin' make
xconfig after"ar+s;
1
Lin)2 3rainin'
La ,oo#
Lin)2 3rainin'
La ,oo#
<etch)p "o)l+ ref)se to r)n in a
non-empt( +irector( "hich +oesn0t
contain Lin)2 so)rces.
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Integrating the root filesystem
=o) nee+ a root files(stem to oot from. Confi')re (o)r #ernel to
)se root files(stem in data/rootfs/ as an initramfs.
,efore compilin' (o)r #ernel, replace ttyS0 ( ttyS2 in
data/rootfs/etc/inittab if nee+e+. 3hat0s nee+e+ eca)se
O$%&5 )ses ttyS2 as serial console +evice.
Cross compiling
=o)0re no" rea+( to cross-compile (o)r #ernel. *impl( r)n:
make
an+ "ait a "hile for the #ernel to compile.
Loo# at the en+ of the #ernel )il+ o)tp)t to see "hich file contains
the #ernel ima'e.
8o"ever, the +efa)lt ima'e pro+)ce+ ( the #ernel )il+ process is
not s)itale to e oote+ from --,oot. % post-processin' operation
m)st e performe+ )sin' the mkimage tool provi+e+ ( --,oot
+evelopers. 3his tool has alrea+( een installe+ in (o)r s(stem as
part of the uboot-mkimage pac#a'e. 3o r)n the post-processin'
operation on the #ernel ima'e, simpl( r)n:
make uImage.
Setting up serial communication ith the !oar"
&l)' the ,ea'le oar+ on (o)r comp)ter. *tart $inicom on
/dev/ttyS0, or on /dev/ttyUSB0 if (o) are )sin' a serial to -*,
a+apter.
=o) sho)l+ no" see the --,oot prompt:
OMAP3 beagleboard.org #
Loa" an" !oot the kernel using #-$oot
Cop( the 'enerate+ uImage file to the $$C car+. 3hen oot the
ea'leoar+ an+ hoo# in --,oot. 3hen +o the follo"in' :
/nitiali:e the mmc s)s(stem:
mmc init
Loa+ uImage from first partition of the $$C into >%$ at
a++ress 0x80000000:
fatload mmc 0 80000000 uImage
,oot the #ernel:
bootm 0x80000000.
=o) sho)l+ see Lin)2 oot an+ reach a shell comman+ line.
Con'rat)lations;
=o) can a)tomate all this ever( time the oar+ is oote+ or reset.
3o +o it, r)n the reboot comman+ in Lin)2 to 'et ac# to --oot,
an+ r)n:
setenv bootcmd 'mmc init;fatload mmc 0 80000000
uImage;bootm 80000000'
saveenv
2
Lin)2 3rainin'
La oo#
Lin)2 3rainin'
La oo#
*ee ho" simple this is compare+ to
havin' to create (o)r o"n files(stem;
*ee ho" simple this is compare+ to
havin' to create (o)r o"n files(stem;
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Flashing the kernel in NAND flash
/n or+er to let the #ernel oot on the oar+ a)tonomo)sl(, "e can
flash it in the 7%79 flash availale on the ,ea'le oar+. 3he 7%79
flash can e manip)late+ in --,oot )sin' the nand comman+, "hich
feat)res several s)comman+s. >)n help nand to see the availale
s)comman+s an+ their options.
3he 7%79 flash is lo'icall( split in three partitions ( the Lin)2
#ernel, as +efine+ in the omap3beagle_nand_partitions +efinition
in the oar+-specific file arch/arm/mach-omap2/board-
omap3beagle.c. 3he first 5 partitions are +e+icate+ to ?-loa+er, to
--oot an+ to its environment variales. 3he 4th partition, "hich is
4 $, i', from 7%79 a++ress 022@0000 to 024@0000, is reserve+
for the #ernel.
*o, let0s start ( erasin' the correspon+in' 4$, of 7%79 flash:
nandecc sw
nand erase 0x280000 0x400000
A7%79 a++rB Asi:eB
3hen, cop( the #ernel from the $$C/*9 car+ into memor(, )sin'
the same a++ress as efore.
3hen, flash the #ernel ima'e:
nand write 0x80000000 0x280000 0x400000
A>%$ a++rB A7%79 a++rB Asi:eB
3hen, "e sho)l+ e ale to oot the #ernel from the 7%79 )sin':
nboot 0x80000000 0 0x280000
A>%$ a++rB A+ev nB A7%79 a++rB
bootm 0x80000000
nboot rea+s the uImage hea+er in flash, an+ onl( copies the ri'ht
amo)nt of +ata to >%$.
7o", (o) can ma#e the oar+ oot on 7%79 flash ( +efa)lt:
setenv bootcmd 'nboot 0x80000000 0 0x280000; bootm
0x80000000'
saveenv
7o", po"er off the oar+, remove the $$C/*9 car+, an+ po"er it
on a'ain to chec# that it oots fine from 7%79 flash. Chec# that
this is reall( (o)r o"n version of the #ernel that0s r)nnin'.
5
Lin)2 3rainin'
La ,oo#
Lin)2 3rainin'
La ,oo#
3he easiest "a( to comp)te these
start an+ en+ a++resses is to rea+
them in the #ernel oot)p messa'es;
8ere, the si:e of the cop( to 7%79 is
a it too pessimistic, )t "e #no" for
s)re that the #ernel si:e "on0t
e2cee+ 4 $, A02400000B.
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Sysdev A tiny embedded system
O!ective: ma"in# a tin$ $et f%ll feat%re& eme&&e& s$stem.
'fter this la, $o% (ill
e ale to confi#%re an& %il& a Lin%) "ernel that oots on a
&irector$ on $o%r (or"station, share& thro%#h the net(or" $
*F+.
e ale to create an& confi#%re a minimalistic root files$stem
from scratch ,e) nihilo, o%t of nothin#, entirel$ han& ma&e...-
for the .ea#le oar&
%n&erstan& ho( small an& simple an eme&&e& Lin%) s$stem
can e.
e ale to install .%s$.o) on this files$stem.
e ale to create a simple start%p script ase& on /sbin/init.
e ale to set %p a simple (e interface for the tar#et.
have an i&ea of ho( m%ch /'0 a Lin%) "ernel smaller than 1
0. nee&s.
Lab implementation
1hile ,s-he &evelops a root files$stem for a &evice, a &eveloper
nee&s to ma"e fre2%ent chan#es to the files$stem contents, li"e
mo&if$in# scripts or a&&in# ne(l$ compile& pro#rams.
3t isn4t practical at all to reflash the root files$stem on the tar#et
ever$ time a chan#e is ma&e. Fort%natel$, it is possile to set %p
net(or"in# et(een the &evelopment (or"station an& the tar#et.
5hen, (or"station files can e accesse& $ the tar#et thro%#h the
net(or", %sin# *F+.
6nless $o% test a oot se2%ence, $o% no lon#er nee& to reoot the
tar#et to test the impact of script or application %p&ates.
1
Lin%) 5rainin#
La .oo"
Lin%) 5rainin#
La .oo"
Development PC
Target (Beagle)
/root directory
nfsroot/root directory
Network
NFS export
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Setup
7o to the /home/<user>/felabs/sysdev/tinysystem/ &irector$.
/e%se the latest 2.8.9: release from the previo%s la $ cop$in#
them to the c%rrent &irector$.
Kernel configuration
'ppl$ the &efa%lt confi#%ration settin#s for the oar&.
Chec" that it has the confi#%ration options that enale ootin# on a
root files$stem sittin# on an *F+ remote &irector$.
1e (ill &o net(or"in# %sin# an 6+. to Ethernet a&apter. 5o %se
this &evice, a&& the elo( confi#%ration settin#s to $o%r "ernel:
0%lti-p%rpose 6+. *et(or"in# Frame(or"
,CONFIG_USB_USBNET=y-
3nventra ;</C 6+. =eripheral ,53, '<3, ...-
,CONFIG_USB_NET_AX8817X=y-
Compile $o%r "ernel an& #enerate the uImage "ernel ima#e s%itale
for 6-.oot. Cop$ this ima#e to the 00C/+< car&.
Root filesystem with Busybox
Create an nfsroot/ &irector$ that (ill contain the root files$stem
for the tar#et.
<o(nloa& the latest .%s$.o) 1.1>.) release an& confi#%re it (ith
the confi#%ration file provi&e& in the data/ &irector$.
't least, ma"e s%re $o% %il& .%s$.o) staticall$?
.%il& .%s$.o) %sin# the toolchain that $o% %se& to %il& the "ernel.
3nstall .%s$.o) in the root files$stem $ r%nnin# make install.
Setting up the NS server
3nstall the *F+ server $ installin# the nfs-kernel-server
pac"a#e if $o% &on4t have it $et. Once installe&, e&it the
/etc/exports file as root to a&& the follo(in# lines, ass%min# that
the 3= a&&ress of $o%r oar& (ill e 192.168.0.100:
/home/<user>/felabs/sysdev/tinysystem/nfsroot
192.168.0.100(rw,no_root_squash,no_subtree_check)
5he path an& the options m%st e on the same line?
5hen, restart the *F+ server:
sudo /etc/init.d/nfs-kernel-server restart
!onfigure host"side networ#ing
3nsert the 6+.-Ethernet &on#le in the 6+. host connector of $o%r
.ea#le. 1ith an Ethernet cale, connect this &on#le to $o%r =C
,possil$ %sin# another 6+.-Ethernet &on#le if $o% alrea&$ %se the
Ethernet connector of $o%r (or"station for 3nternet access-.
5o confi#%re the Ethernet interface on $o%r (or"station, ri#ht-clic"
on the *et(or" 0ana#er tas"let on $o%r &es"top, an& select Edit
Connections. +elect the (ire& net(or" connection, an& in the IPv4
2
Lin%) 5rainin#
La oo"
Lin%) 5rainin#
La oo"
Compilin# .%s$o) staticall$ in the
first place ma"es it eas$ to set %p the
s$stem, eca%se there are no
&epen&encies on liraries. Later on,
(e (ill set %p share& liraries an&
recompile .%s$o).
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Settings ta, ma"e the interface %se a static 3= a&&ress, li"e
192.168.0.1 ,a&& a 2::.2::.2::.0 netmas" an& leave the #ate(a$
fiel& empt$-. Of co%rse, ma"e s%re that this a&&ress elon#s to a
separate net(or" se#ment from the one of the main compan$
net(or".
Booting the system
3nsert the 00C/+< car& in the oar& an& oot the latter to the 6-
.oot prompt ,stop the a%tomatic co%nt &o(n-.
.efore ootin# the "ernel, (e nee& to tell it that the root files$stem
sho%l& e mo%nte& over *F+, $ settin# some "ernel parameters.
6se the follo(in# 6-.oot comman& to &o so ,in !%st 1 line-:
setenv bootargs root=/dev/nfs console=ttyS2,115200n8 ip=192.168.0.100
nfsroot=192.168.0.1:/home/<user>/felabs/sysdev/tinysystem/nfsroot
'lso ma"e the oar& oot a%tomaticall$ on the "ernel on the
00C/+< car&:
setenv bootcmd 'mmc init;fatload mmc 0 80000000 uImage;bootm 80000000'
+ave $o%r ne( settin#s to ma"e them permanent:
saveenv
5r$ to oot $o%r ne( s$stem on the oar&. 3f ever$thin# #oes ri#ht,
the "ernel sho%l& confirm that it mana#e& to mo%nt the *F+ root
files$stem. 5hen, $o% sho%l& #et errors ao%t missin# /dev/ttyX
files. Create them (ith the mknod comman& ,%sin# the same ma!or
an& minor n%mer as in $o%r 7*6/Lin%) (or"station-. 5r$ a#ain.
't the en&, $o% (ill access a console an& (ill e ale to iss%e
comman&s thro%#h the &efa%lt shell.
Virtual filesystems
/%n the ps comman&. @o% can see that it complains that the /proc
&irector$ &oes not e)ist. 5he ps comman& an& other process-
relate& comman&s %se the proc virt%al files$stem to #et their
information from the "ernel.
From the Lin%) comman& line in the tar#et, create the proc, sys
an& etc &irectories in $o%r root files$stem.
*o( mo%nt the proc virt%al files$stem.
9
Lin%) 5rainin#
La .oo"
Lin%) 5rainin#
La .oo"
@o% can %n&erstan& o%r approach to
%il& files$stems from scratch. 1e4re
(aitin# for pro#rams to complain
efore a&&in# &evice or
confi#%ration files. 5his is a (a$ of
ma"in# s%re that ever$ file in the
files$stem is %se&.
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
*o( that /proc is availale, test a#ain the ps comman&.
*ote that $o% can also halt $o%r tar#et in a clean (a$ (ith the halt
comman&, than"s to proc ein# mo%nte&.
System configuration and startup
5he first %serspace that #ets e)ec%te& $ the "ernel is /sbin/init
an& its confi#%ration file is /etc/inittab.
5he docs/BusyBox.txt, #enerate& &%rin# the .%s$.o) compilation
process, contains the &oc%mentation of .%s$.o). 6nfort%natel$,
&%e to the recent s(itch to an a%tomaticall$ #enerate&
&oc%mentation, some informations are missin#. 3n partic%lar, the
information ao%t the /etc/inittab file are onl$ visile in the
include/usage.h file.
Create a /etc/inittab file an& a /etc/init.d/rcS start%p script
&efine& in /etc/inittab. 3n this start%p script, mo%nt the /proc
an& /sys files$stems.
'n$ iss%e after &oin# thisA
Switching to shared libraries
5a"e the hello.c pro#ram s%pplie& in the data &irector$. Cross-
compile it for '/0, &$namicall$-lin"e& (ith the liraries, an& r%n it
on the tar#et.
@o% (ill first enco%nter a not found error ca%se& $ the asence of
the ld-uClibc.so.0 e)ec%tale, (hich is the &$namic lin"er
re2%ire& to e)ec%te an$ pro#ram compile& (ith share& liraries.
6sin# the find comman& ,see e)amples in $o%r comman& memento
sheet-, loo" for this file in the toolchain install &irector$, an& cop$ it
to the lib/ &irector$ on the tar#et.
5hen, r%nnin# the e)ec%tale a#ain an& see that the loa&er
e)ec%tes an& fin&s o%t (hich share& liraries are missin#.
+imilarl$, fin& these liraries in the toolchain an& cop$ them to
lib/ on the tar#et.
Once the small test pro#ram (or"s, recompile .%s$o) (itho%t the
static compilation option, so that .%s$o) ta"es a&vanta#es of the
share& liraries that are no( present on the tar#et.
$mplement a web interface for your device
/eplicate data/www/ to the /www &irector$ in $o%r tar#et root
files$stem.
*o(, r%n the .%s$.o) http server from the comman& line:
/usr/sbin/httpd -h /www/ &
3f $o% %se a pro)$, confi#%re $o%r host ro(ser so that it &oesn4t #o
thro%#h the pro)$ to connect to the tar#et 3= a&&ress, or simpl$
&isale pro)$ %sa#e. *o(, test that $o%r (e interface (or"s (ell
$ openin# http://192.168.0.100:80 on the host.
+ee ho( the &$namic pa#es are implemente&. Ber$ simple, isn4t itA
4
Lin%) 5rainin#
La oo"
Lin%) 5rainin#
La oo"
docs/BusyBox.txt onl$ e)ists if $o%
ran the make comman&. 3t (on4t e)ist
if $o% &irectl$ r%n make install.
'ct%all$, $o% (ill proal$ have
several instr%ctive s%rprises (hen
tr$in# to implement this. <on4t
hesitate to share $o%r 2%estions (ith
$o%r instr%ctor?
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
%ow much RA& does your system need'
Chec" the /proc/meminfo file an& see ho( m%ch /'0 is %se& $
$o%r s$stem.
@o% can tr$ to oot $o%r s$stem (ith less memor$, an& see (hether
it still (or"s properl$ or not. For e)ample, to test (hether 8 0.
are eno%#h, oot the "ernel (ith the mem=6M parameter. Lin%) (ill
then %se !%st 8 0. of /'0, an& i#nore the rest.
:
Lin%) 5rainin#
La .oo"
Lin%) 5rainin#
La .oo"
2004-2009 Free Electrons, http://free-electrons.com Creative Commons License 2004-2009 Free Electrons, http://free-electrons.com Creative Commons License
Filesystems Block file systems
O!ective: confi"#re an$ oot an eme$$e$ Lin#% s&stem
rel&in" on loc' stora"e.
(fter this la, &o# )ill e ale to
*ana"e partitions on loc' stora"e.
+ro$#ce file s&stem ima"es.
Confi"#re the 'ernel to #se these file s&stems
,se the tmpfs file s&stem to store temporar& files
Goals
(fter $oin" the -( tin& eme$$e$ s&stem. la, )e are "oin" to cop&
the files&stem contents to the **C flash $rive. /he files&stem )ill
e split into several partitions, an$ &o#r 0ea"le oar$ )ill e
oote$ )ith this **C car$, )itho#t #sin" 1F2 an& more.
Setup
3o to /home/<user>/felabs/sysdev/fs.
4e#se the 'ernel that &o# #se$ in
/home/<user>/felabs/sysdev/tinysystem.
4ecompile it )ith s#pport for SquashFS an$ ext3.
0oot &o#r oar$ )ith this ne) 'ernel an$ on the 1F2 files&stem
&o# #se$ in this previo#s la.
MMC/SD disk partitioning
,sin" fdisk on your workstation,)e are "oin" to a$$ 2 ne)
partitions to the **C/25 car$ #se$ in the previo#s las.
fdisk allo)s to partition loc' $evices s#ch as har$ $rives or ,20
flash $rives. +artitionin" consists of creatin" a $escriptor tale
containin" information on the $ifferent partitions on the $evice.
/he first one )ill e #se$ to store the root file s&stem an$ $oes not
re6#ire more than 7*0. /he secon$ partition )ill han$le the tar"et
local stora"e an$ )ill the #se all the remainin" space on the
**C/25 car$.
First create a primar& partition to hol$ the root files&stem.
8n fdisk, t&pe:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (35-239, default 35): 35
Last cylinder, +cylinders or +size{K,M,G} (35-239,
default 239): +1M
7
Lin#% /rainin"
La 0oo'
Lin#% /rainin"
La 0oo'
8f &o# $i$n9t $o or complete the
tinysystem la, &o# can #se the
data/rootfs $irector& instea$.
(ccept the $efa#lt val#e for the first
c&lin$er. /hat9s the first availale
sector.
2004-2009 Free Electrons, http://free-electrons.com Creative Commons License 2004-2009 Free Electrons, http://free-electrons.com Creative Commons License
1o), create another primar& partition to hol$ the "eneral p#rpose
files&stem storin" #ser an$ application $ata. 8ts si:e can fill the
remainin" space on the car$ ;accept the last c&lin$er propose$ &
$efa#lt<:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (36-239, default 36): 36
Last cylinder, +cylinders or +size{K,M,G} (36-239,
default 239): 239
,se 'w' to )rite &o#r chan"es. /o reloa$ the ne) partition tale,
remove the **C car$ an$ pl#" it in a"ain.
Data partition on the MMC disk
,sin" the mkfs.ext3 create a !o#rnale$ file s&stem on the thir$
partition of the **C $is'. *ove the contents of the
www/upload/files $irector& ;in &o#r tar"et root files&stem< into
this ne) partition.
Connect the **C $is' to &o#r oar$ )hile it9s r#nnin" Lin#%.
,sin" the dmesg comman$, or havin" a loo' at the console, see ho)
the 'ernel $etects the partitions an$ )hich $evice names it "ives to
them.
*o$if& the set#p scripts in &o#r root files&stem to mo#nt the thir$
$is' partition on /www/upload/files.
4eoot &o#r tar"et s&stem an$ )ith the mount comman$, chec' that
/www/upload/files is no) a mo#nt point for the thir$ **C $is'
partition. (lso ma'e s#re that &o# can still #ploa$ ne) ima"es, an$
that these ima"es are liste$ in the )e interface.
Adding a tmpfs partition for log files
For the moment, the #ploa$ script )as storin" its lo" file in
/www/upload/files/upload.log. /o avoi$ seein" this lo" file in
the $irector& containin" #ploa$e$ files, let9s store it in /var/log
instea$.
($$ the /var/log/ $irector& to &o#r root files&stem an$ mo$if& the
start#p scripts to mo#nt a tmpfs files&stem on this $irector&.
*o$if& the www/cgi-bin/upload.cfg confi"#ration file to store the
lo" file in /var/log/upload.log. =o# )ill loose &o#r lo" file each
time &o# reoot &o#r s&stem, #t that9s O> in o#r s&stem. /hat9s
)hat tmpfs is for: temporar& $ata that &o# $on9t nee$ to 'eep
across s&stem reoots.
4eoot &o#r s&stem an$ chec' that it )or's as e%pecte$.
Making a SquashFS image
?e are "oin" to store the root files&stem in a 26#ashF2 files&stem
in the secon$ partition of the **C $is'.
8n or$er to create 26#ashF2 ima"es on &o#r host, &o# nee$ to
install the squashfs-tools pac'a"e. 1o) create a 26#ashF2 ima"e
2
Lin#% /rainin"
La oo'
Lin#% /rainin"
La oo'
0efore chan"in" &o#r start#p scripts,
&o# ma& also tr& &o#r mo#nt
comman$ in the r#nnin" s&stem, to
ma'e s#re that it )or's as e%pecte$.
2004-2009 Free Electrons, http://free-electrons.com Creative Commons License 2004-2009 Free Electrons, http://free-electrons.com Creative Commons License
of &o#r 1F2 root $irector&.
Finall&, #sin" the dd comman$, cop& the file s&stem ima"e to the
secon$ partition of the **C $is'.
Booting on the SquashFS partition
8n the ,-oot shell, confi"#re the 'ernel comman$ line to #se the
secon$ partition of the **C $is' as the root file s&stem. (lso a$$
the rootwait oot ar"#ment, to )ait for the **C $is' to e
properl& initiali:e$ efore tr&in" to mo#nt the root files&stem.
Chec' that &o#r s&stem still )or's. Con"rat#lations if it $oes@
A
Lin#% /rainin"
La 0oo'
Lin#% /rainin"
La 0oo'
Caution: rea$ this caref#ll& efore procee$in". =o# co#l$ $estro& e%istin" partitions on &o#r +C@
5o not ma'e the conf#sion et)een the $evice that is #se$ & &o#r oar$ to represent &o#r **C $is'
;proal& /dev/sda1<, an$ the $evice that &o#r )or'station #ses ;proal& /dev/sdb1<.
2o, $on9t #se the /dev/sda1 $evice to reflash &o#r **C $is' from &o#r )or'station. +eople have alrea$&
$estro&e$ their ?in$o)s partition & ma'in" this mista'e.
8f &o# $on9t $o this, &o# )ill "et a
'ernel panic, eca#se of a fail#re to
mo#nt the root files&stem, ein" not
rea$& &et.
Caution: rea$ this caref#ll& efore procee$in". =o# co#l$ $estro& e%istin" partitions on &o#r +C@
5o not ma'e the conf#sion et)een the $evice that is #se$ & &o#r oar$ to represent &o#r ,20-$is'
;proal& /dev/sda1<, an$ the $evice that &o#r )or'station #ses ;proal& /dev/sdb1<.
2o, $on9t #se the /dev/sda1 $evice to reflash &o#r ,20 $rive from &o#r )or'station. +eople have alrea$&
$estro&e$ their main ?in$o)s or Lin#% partition & ma'in" this mista'e.
2004-2009 Free Electrons, http://free-electrons.com Creative Commons License 2004-2009 Free Electrons, http://free-electrons.com Creative Commons License
4
Lin#% /rainin"
La oo'
Lin#% /rainin"
La oo'
2004-2009 Free Electrons, http://free-electrons.com Creative Commons License 2004-2009 Free Electrons, http://free-electrons.com Creative Commons License
Filesystems Flash file systems
O!ective: ,n$erstan$ flash file s&stems #sa"e an$ their
inte"ration on the tar"et.
(fter this la, &o# )ill e ale to
+repare files&stem ima"es an$ flash them.
5efine partitions in eme$$e$ flash stora"e.
Setup
2ta& in /home/<user>/felabs/sysdev/fs.
8nstall the mtd-utils pac'a"e, )hich )ill e #sef#l to create BFF22
files&stem ima"es.
Goals
8nstea$ of #sin" an e%ternal **C car$ as in the previo#s la, )e
)ill ma'e o#r s&stem #se its internal flash stora"e.
/he root files&stem )ill still e in a 26#ashF2 files&stem, #t this
time p#t on an */5 partition. 4ea$/)rite $ata )ill e store$ in a
BFF22 files&stem in another */5 partition.
Filesystem image preparation
+repare a BFF22 files&stem ima"e from the /www/uploads/files
$irector& from the previo#s la, specif&in" an erase loc' si:e of
72C>i0. ?rite $o)n the si:e of the ima"e file, an$ chec' that it is a
m#ltiple of the erase loc' si:e.
*o$if& the root files&stem to mo#nt a BFF22 files&stem on the thir$
flash partition, instea$ of an e%tA files&stem on the thir$ **C $is'
partition. ,p$ate &o#r 26#ashF2 ima"e.
na!ling "A"D flash and filesystems
4ecompile &o#r 'ernel )ith s#pport for JFFS2 an$ for s#pport for
*/5 partitions specifie$ in the 'ernel comman$ line
;CONFIG_MTD_CMDLINE_PARTS<.
(lso enale s#pport for the flash chips on the oar$
;MTD_NAND_OMAP2<, #t ma'e s#re that MTD_NAND_OMAP_PREFETCH is
$eselecte$ ;incompatile )ith 26#ashF2 at the moment<
,p$ate &o#r 'ernel ima"e on flash.
M#D partitioning and flashing
*emor& la&o#t an$ partitionin" can e $efine$ insi$e 'ernel so#rces,
nat#rall& in the arch/<arch>/<march>/<board>.c since it is oar$
$epen$ent. 1evertheless, $#rin" $evice $evelopment, it can e
#sef#l to $efine partitions at oot time, on the 'ernel comman$ line.
Chec' the si:e of the 26#ashF2 ima"e of the root files&stem.
Enter the ,-0oot shell an$ erase 1(15 flash, from offset
0%00DC0000, #p to the en$ of the 1(15 flash ;Erase si:e :
0%0f9C0000 &tes<
E
Lin#% /rainin"
La 0oo'
Lin#% /rainin"
La 0oo'
2004-2009 Free Electrons, http://free-electrons.com Creative Commons License 2004-2009 Free Electrons, http://free-electrons.com Creative Commons License
,sin" the fatload comman$, $o)nloa$ an$ flash the 26#ashF2
ima"e at the e"innin" of the erase$ flash area.
,sin" the fatload comman$, $o)nloa$ an$ flash the BFF22 ima"e
at the first *i0 o#n$ar& follo)in" the en$ of the 26#ashF2 ima"e
in flash.
Loo' at the )a& */5 partitions are $efine$ in the 'ernel so#rces
;arch/arm/mach-omap2/oar$-omapAea"le.c<
2et the bootargs variale so that &o# $efine A */5 partitions
One that overla&s the slots for the F-loa$er, ,-0oot, ,-0oot
environment variales an$ the Lin#% 'ernel.
One for the root files&stem ;26#ashF2<
One for the $ata files&stem ;!ffs2<
5on9t for"et to ma'e the root parameter point to the root
files&stem in flash.
0oot the tar"et, chec' that */5 partitions are )ell confi"#re$, an$
that &o#r s&stem still )or's as e%pecte$.
D
Lin#% /rainin"
La oo'
Lin#% /rainin"
La oo'
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Third party libraries and applications
O!ective: Learn ho" to levera#e e$istin# liraries an%
applications: ho" to confi#&re, compile an% install them.
'o ill&strate ho" to &se e$istin# liraries an% applications, "e "ill
e$ten% the small root files(stem &ilt in the )* tin( eme%%e%
s(stem+ la to a%% the ,irectF- #raphic lirar( an% sample
applications &sin# this lirar(. -eca&se man( oar%s %o not have a
%ispla(, "e "ill test the res&lt of this la "ith .em&.
/e0ll see that man&all( re-&sin# e$istin# liraries is 1&ite te%io&s, so
that more a&tomate% proce%&res are necessar( to ma2e it easier.
3o"ever, learnin# ho" to perform these operations man&all( "ill
si#nificantl( help (o& "hen (o&0ll face iss&es "ith more a&tomate%
tools.
Figuring out library dependencies
*s most liraries, ,irectF- %epen%s on other liraries, an% these
%epen%encies are %ifferent %epen%in# on the confi#&ration chosen
for ,irectF-. 4n o&r case, "e "ill enale s&pport for:
567 ima#e loa%in#8
95E7 ima#e loa%in#8
Font ren%erin# &sin# a font en#ine.
'he 567 ima#e loa%in# feat&re "ill e provi%e% ( the libpng
lirar(, the 95E7 ima#e loa%in# feat&re ( the jpeg lirar( an% the
font en#ine "ill e implemente% ( the FreeType lirar(. 'he libpng
lirar( itself %epen%s on the zlib compression/%ecompression
lirar(. :o, "e en% &p "ith the follo"in# %epen%enc( tree:
Of co&rse, all these liraries rel( on the C lirar(, "hich is not
mentione% here, eca&se it is alrea%( part of the root files(stem &ilt
in the )* tin( eme%%e% s(stem+ la. ;o& mi#ht "on%er ho" to
fi#&re o&t this %epen%enc( tree ( (o&rself. -asicall(, there are
several "a(s, that can e comine%:
<ea% the lirar( %oc&mentation, "hich often mentions the
%epen%encies8
<ea% the help messa#e of the configure script
=( r&nnin# ./configure --help>.
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
,irectF-
application
,irectF-
lipn#
!pe# freet(pe
?li
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
-( r&nnin# the confi#&re script, compilin# an% loo2in# at the
errors.
'o confi#&re, compile an% install all the components of o&r s(stem,
"e0re #oin# to start from the ottom of the tree "ith ?li, then
contin&e "ith lipn#, !pe# an% Free'(pe, to finall( compile ,irectF-
an% the ,irectF- sample applications.
Preparation
For o&r cross-compilation "or2, "e "ill nee% to separate spaces:
* @sta#in#A space in "hich "e "ill %irectl( install all the
pac2a#es: non-strippe% versions of the liraries, hea%ers,
%oc&mentation an% other files nee%e% for the compilation.
'his @sta#in#A space can e 1&ite i#, &t "ill not e &se% on
o&r tar#et, onl( for compilin# liraries or applications8
* @tar#etA space, in "hich "e "ill cop( onl( the re1&ire% files
from the @sta#in#A space: inaries an% liraries, after
strippin#, confi#&ration files nee%e% at r&ntime, etc. 'his
tar#et space "ill ta2e a lot less space than the @sta#in#A
space, an% it "ill contain onl( the files that are reall( nee%e%
to ma2e the s(stem "or2 on the tar#et.
'o s&m &p, the @sta#in#A space "ill contain ever(thin# that0s nee%e%
for compilation, "hile the @tar#etA space "ill contain onl( "hat0s
nee%e% for e$ec&tion.
:o, in /home/<user>/felabs/sysdev/thirdparty, create t"o
%irectories: staging an% target.
For the tar#et, "e nee% a asic s(stem "ith -&s(-o$, %evice no%es
an% initiali?ation scripts. /e "ill re-&se the s(stem &ilt in the )*
tin( eme%%e% s(stem+ la, so cop( this s(stem in the tar#et
%irector(:
sudo cp -a /home/<user>/felabs/sysdev/tinysystem/nfsroot/*
target/
'he cop( m&st e %one as root, eca&se the root files(stem of the )*
tin( eme%%e% s(stem+ la contains a fe" %evice no%es.
Testing
Ba2e s&re the target/ %irector( is e$porte% ( (o&r 6F: server (
a%%in# the follo"in# line to /etc/exports:
/home/<user>/felabs/sysdev/thirdparty/target 172.20.0.2(rw
,no_root_squash,no_subtree_check)
*n% restart (o&r 6F: server.
4nstall the .em& em&lator for non-$CD architect&res ( installin# the
qemu-kvm-extras pac2a#e.
Bo%if( the /etc/qemu-ifup script so that it !&st contains 1 line:
/sbin/ifconfig $1 172.20.0.1
'hen, r&n .em& "ith the provi%e% script:
./run_qemu
'he s(stem sho&l% oot an% #ive (o& a prompt.
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
-( %efa&lt, .em& confi#&res ri%#e%
net"or2in#, &t "e "ill &se a ro&te%
net"or2 instea%.
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
zlib
Eli is a compression/%ecompression lirar( availale at
http://""".?li.net/. ,o"nloa% version 1.2.F, an% e$tract it in
/home/<user>/felabs/sysdev/thirdparty/.
-( loo2in# at the confi#&re script, "e see that this confi#&re script
has not een #enerate% ( autoconf =other"ise it "o&l% contain a
sentence li2e Generated by GNU Autoconf 2.62 >. Boreover,
the pro!ect %oesn0t &se automake since there are no Makefile.am
files. :o ?li &ses a c&stom &il% s(stem, not a &il% s(stem ase% on
the classical a&totools.
Let0s tr( to confi#&re an% &il% ?li:
./configure
make
;o& can see that the files are #ettin# compile% "ith #cc, "hich
#enerates co%e for $CD an% not for the tar#et platform. 'his is
ovio&sl( not "hat "e "ant, so "e tell the confi#&re script to &se the
*<B cross-compiler:
CC=arm-linux-gcc ./configure
Of co&rse, the arm-linux-gcc cross-compiler m&st e in (o&r PATH
prior to r&nnin# the confi#&re script. 'he CC environment variale is
the classical name for specif(in# the compiler to &se. Boreover, the
e#innin# of the confi#&re script tells &s ao&t this:
# To impose specific compiler or flags or
# install directory, use for example:
# prefix=$HOME CC=cc CFLAGS="-O4" ./configure
6o" "hen (o& compile "ith make, the cross-compiler is &se%. Loo2
at the res&lt of compilin#: a set of o!ect files, a file libz.a an% set
of li?.soG files.
'he libz.a file is the static version of the lirar(. 4t has een
#enerate% &sin# the follo"in# comman% :
ar rc libz.a adler32.o compress.o crc32.o gzio.o uncompr.o
deflate.o trees.o zutil.o inflate.o infback.o inftrees.o
inffast.o
4t can e &se% to compile applications lin2e% staticall( "ith the ?li
lirar(, as sho"n ( the compilation of the e$ample pro#ram:
arm-linux-gcc -O3 -DUSE_MMAP -o example example.o -L.
libz.a
4n a%%ition to this static lirar(, there is also a %(namic version of
the lirar(, the libz.so* files. 'he share% lirar( itself is
libz.so.1.2.5, it has een #enerate% ( the follo"in# comman%
line :
arm-linux-gcc -shared -Wl,-soname,libz.so.1 -o
libz.so.1.2.5 adler32.o compress.o crc32.o gzio.o
uncompr.o deflate.o trees.o zutil.o inflate.o infback.o
inftrees.o inffast.o
*n% creates s(molic lin2s libz.so an% libz.so.1:
ln -s libz.so.1.2.3 libz.so
ln -s libz.so.1.2.3 libz.so.1
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
'hese s(mlin2s are nee%e% for t"o %ifferent reasons:
libz.so is &se% at compile time "hen (o& "ant to compile an
application that is %(namicall( lin2e% a#ainst the lirar(. 'o
%o so, (o& pass the -lLIBNAME option to the compiler, "hich
"ill loo2 for a file name% lib<LIBNAME>.so. 4n o&r case, the
compilation option is -l? an% the name of the lirar( file is
libz.so. :o, the libz.so s(mlin2 is nee%e% at compile time8
libz.so.1 is nee%e% eca&se it is the :O6*BE of the lirar(.
:O6*BE stan%s for Shared Object Name . 4t is the name
of the lirar( as it "ill e store% in applications lin2e% a#ainst
this lirar(. 4t means that at r&ntime, the %(namic loa%er "ill
loo2 for e$actl( this name "hen loo2in# for the share% lirar(.
:o this s(molic lin2 is nee%e% at r&ntime.
'o 2no" "hat0s the :O6*BE of a lirar(, (o& can &se:
arm-linux-readelf -d libz.so.1.2.5
an% loo2 at the =:O6*BE> line. ;o&0ll also see that this
lirar( nee%s the C lirar(, eca&se of the =6EE,E,> line on
libc.so.0.
'he mechanism of :O6*BE allo"s to chan#e the lirar(
"itho&t recompilin# the applications lin2e% "ith this lirar(.
Let0s sa( that a sec&rit( prolem is fo&n% in ?li 1.2.F, an%
fi$e% in the ne$t release 1.2.D. ;o& can recompile the lirar(,
install it on (o&r tar#et s(stem, chan#e the lin2 libz.so.1 so
that it points to libz.so.1.2.6 an% restart (o&r applications.
*n% it "ill "or2, eca&se (o&r applications %on0t loo2
specificall( for libz.so.1.2.5 &t for the :O6*BE
libz.so.1. 3o"ever, it also means that as a lirar(
%eveloper, if (o& rea2 the *-4 of the lirar(, (o& m&st
chan#e the :O6*BE: chan#e from libz.so.1 to libz.so.2.
Finall(, the last step is to tell the confi#&re script "here the lirar(
is #oin# to e installe%. Bost confi#&re scripts consi%er that the
installation prefi$ is /usr/local/ =so that the lirar( is installe% in
/usr/local/lib, the hea%ers in /usr/local/include, etc.>. -&t in
o&r s(stem, "e simpl( "ant the liraries to e installe% in the /&sr
prefi$, so let0s tell the confi#&re script ao&t this:
CC=arm-linux-gcc ./configure --prefix=/usr
make
For the ?li lirar(, this option ma( not chan#e an(thin# to the
res&ltin# inaries, &t for safet(, it is al"a(s recommen%e% to ma2e
s&re that the prefi$ matches "here (o&r lirar( "ill e r&nnin# on
the tar#et s(stem.
,o not conf&se the prefi$ ="here the application or lirar( "ill e
r&nnin# on the tar#et s(stem> from the location "here the
application or lirar( "ill e installe% on (o&r host "hile &il%in# the
root files(stem. For e$ample, ?li "ill e installe% in
/home/<user>/felabs/sysdev/thirdparty/target/usr/lib/
eca&se this is the %irector( "here "e are &il%in# the root
files(stem, &t once o&r tar#et s(stem "ill e r&nnin#, it "ill see ?li
in /usr/lib. 'he prefi$ correspon%s to the path in the tar#et s(stem
an% never on the host. :o, one sho&l% never pass a prefi$ li2e
/home/<user>/felabs/sysdev/thirdparty/target/usr, other"ise
at r&ntime, the application or lirar( ma( loo2 for files insi%e this
%irector( on the tar#et s(stem, "hich ovio&sl( %oesn0t e$istH -(
%efa&lt, most &il% s(stems "ill install the application or lirar( in
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
the #iven prefi$ =/&sr or /&sr/local>, &t "ith most &il% s(stems
=incl&%in# a&totools>, the installation prefi$ can e overri%en, an% e
%ifferent from the confi#&ration prefi$.
First, let0s ma2e the installation in the @sta#in#A space:
make DESTDIR=../staging install
6o" loo2 at "hat has een installe% ( ?li :
* manpa#e in /usr/share/man
* p2#confi# file in /usr/lib/pkgconfig. /e0ll come ac2 to
these later
'he share% an% static versions of the lirar( in /usr/lib
'he hea%ers in /usr/include
Finall(, let0s install the lirar( in the @tar#etA space:
1. Create the target/usr/lib %irector(, it "ill contain the
strippe% version of the lirar(
2. Cop( the %(namic version of the lirar(. Onl( libz.so.1 an%
libz.so.1.2.5 are nee%e%, since libz.so.1 is the :O6*BE
of the lirar( an% libz.so.1.2.5 is the real inar(:
cp -a libz.so.1* ../target/usr/lib
I. :trip the lirar(:
arm-linux-strip ../target/usr/lib/libz.so.1.2.5
O2, "e0re %one "ith ?liH
Libpng
,o"nloa% lipn# from its official "esite at
http://""".lipn#.or#/p&/pn#/lipn#.html. /e teste% the la "ith
version 1.4.I
Once &ncompresse%, "e 1&ic2l( %iscover that the lipn# &il%
s(stem is ase% on the a&totools, so "e "ill "or2 "ith a re#&lar
confi#&re script.
*s "e0ve seen previo&sl(, if "e !&st r&n ./confi#&re, the &il% s(stem
"ill &se the native compiler to &il% the lirar(, "hich is not "hat "e
"ant. :o let0s tell the &il% s(stem to &se the cross-compiler:
CC=arm-linux-gcc ./configure
.&ic2l(, (o& sho&l% #et an error sa(in#:
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.
4f (o& loo2 at confi#.lo#, (o& 1&ic2l( &n%erstan% "hat0s #oin# on:
configure:2942: checking for C compiler default output file name
configure:2964: arm-linux-gcc conftest.c >&5
configure:2968: $? = 0
configure:3006: result: a.out
configure:3023: checking whether the C compiler works
configure:3033: ./a.out
./configure: line 3035: ./a.out: cannot execute binary file
'he confi#&re script compiles a inar( "ith the cross-compiler an%
then tries to r&n it on the %evelopment "or2station. Ovio&sl(, it
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
cannot "or2, an% the s(stem sa(s that it @cannot e$ec&te inar(
fileA. 'he !o of the confi#&re script is to test the confi#&ration of the
s(stem. 'o %o so, it tries to compile an% r&n a fe" sample
applications to test if this lirar( is availale, if this compiler option
is s&pporte%, etc. -&t in o&r case, r&nnin# the test e$amples is
%efinitel( not possile. /e nee% to tell the confi#&re script that "e
are cross-compilin#, an% this can e %one &sin# the --&il% an% --host
options, as %escrie% in the help of the confi#&re script:
System types:
--build=BUILD configure for building on BUILD
[guessed]
--host=HOST cross-compile to build programs to run
on HOST [BUILD]
'he --&il% option allo"s to specif( on "hich s(stem the pac2a#e is
&ilt, "hile the --host option allo"s to specif( on "hich s(stem the
pac2a#e "ill r&n. -( %efa&lt, the val&e of the --build option is
#&esse% an% the val&e of --host is the same as the val&e of the
--&il% option. 'he val&e is #&esse% &sin# the ./config.guess
script, "hich on (o&r s(stem sho&l% ret&rn i686-pc-linux-gnu. :ee
http://""".#n&.or#/soft"are/a&toconf/man&al/htmlJno%e/:pecif(in#-
6ames.html for more %etails on these options.
:o, let0s overri%e the val&e of the --host option:
CC=arm-linux-gcc ./configure --host=arm-linux
6o", "e #o a little it f&rther in the e$ec&tion of the confi#&re
script, &ntil "e reach:
checking for zlibVersion in -lz... no
configure: error: zlib not installed
*#ain, "e can chec2 in confi#.lo# "hat the confi#&re script is tr(in#
to %o:
configure:12452: checking for zlibVersion in -lz
configure:12487: arm-linux-gcc -o conftest -g -O2
conftest.c -lz -lm >&5
/usr/local/xtools/arm-unknown-linux-uclibcgnueabi/arm-
unknown-linux-uclibcgnueabi/sys-
root/usr/bin/../lib/gcc/arm-linux-
uclibcgnueabi/4.3.3/../../../../arm-linux-
uclibcgnueabi/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
'he confi#&re script tries to compile an application a#ainst ?li =as
can e seen from the -lz option> : lipn# &ses the ?li lirar(, so the
confi#&re script "ants to ma2e s&re this lirar( is alrea%( installe%.
Knfort&natel(, the ld lin2er %oesn0t fin% this lirar(. :o, let0s tell the
lin2er "here to loo2 for liraries &sin# the -L option follo"e% ( the
%irector( "here o&r liraries are =in staging/usr/lib>. 'his -L
option can e passe% to the lin2er ( &sin# the LDFLAGS at confi#&re
time, as tol% ( the help te$t of the confi#&re script:
LDFLAGS linker flags, e.g. -L<lib dir> if you have
libraries in a nonstandard directory <lib dir>
Let0s &se this L,FL*7: variale:
LDFLAGS=-
L/home/<user>/felabs/sysdev/thirdparty/staging/usr/lib \
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
CC=arm-linux-gcc ./configure --host=arm-linux
Let0s also specif( the prefi$, so that the lirar( is compile% to e
installe% in /usr an% not /usr/local:
LDFLAGS=-
L/home/<user>/felabs/sysdev/thirdparty/staging/usr/lib \
CC=arm-linux-gcc ./configure --host=arm-linux \
--prefix=/usr
Then, run the compilation &sin# ma2e. .&ic2l(, (o& sho&l% #et a
pile of error messa#es, startin# "ith:
In file included from png.c:13:
png.h:470:18: error: zlib.h: No such file or directory
Of co&rse, since lipn# &ses the ?li lirar(, it incl&%es its hea%er
fileH :o "e nee% to tell the C compiler "here the hea%ers can e
fo&n%: there are not in the %efa&lt %irector( /usr/include/, &t in
the /usr/include %irector( of o&r @sta#in#A space. 'he help te$t of
the confi#&re script sa(s:
CPPFLAGS C/C++/Objective C preprocessor flags,
e.g. -I<include dir> if you have headers
in a nonstandard directory <include dir>
Let0s &se it:
LDFLAGS=-
L/home/<user>/felabs/sysdev/thirdparty/staging/usr/lib \
CPPFLAGS=-
I/home/<user>/felabs/sysdev/thirdparty/staging/usr/include \
CC=arm-linux-gcc ./configure --host=arm-linux \
--prefix=/usr
'hen, r&n the compilation "ith ma2e. 3opef&ll(, it "or2sH
Let0s no" e#in the installation process. -efore reall( installin# in
the sta#in# %irector(, let0s install in a %&mm( %irector(, to see "hat0s
#oin# to e installe% =this %&mm( %irector( "ill not e &se%
after"ar%s, it is onl( to verif( "hat "ill e installe% efore poll&tin#
the sta#in# space>:
make DESTDIR=/tmp/libpng/ install
'he DESTDIR variale can e &se% "ith all Ba2efiles ase% on
a&toma2e. 4t allo"s to overri%e the installation %irector(: instea% of
ein# installe% in the configuration-prefix, the files "ill e
installe% in DESTDIR/configuration-prefix.
6o", let0s see "hat has een installe% in /tmp/libpng/:
./usr/lib/libpng.la libpng12.la
./usr/lib/libpng14.a
./usr/lib/libpng14.la
./usr/lib/libpng14.so libpng14.so.14.3.0
./usr/lib/libpng14.so.14 libpng12.so.14.3.0
./usr/lib/libpng14.so.14.3.0
./usr/lib/libpng.a libpng14.a
./usr/lib/libpng.la libpng14.la
./usr/lib/libpng.so libpng14.so
./usr/lib/pkgconfig/libpng.pc libpng14.pc
./usr/lib/pkgconfig/libpng14.pc
./usr/share/man/man5/png.5
./usr/share/man/man3/libpngpf.3
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
./usr/share/man/man3/libpng.3
./usr/include/pngconf.h libpng14/pngconf.h
./usr/include/png.h libpng14/png.h
./usr/include/libpng14/pngconf.h
./usr/include/libpng14/png.h
./usr/bin/libpng-config libpng14-config
./usr/bin/libpng14-config
:o, "e have:
'he lirar(, "ith man( s(molic lin2s
lipn#14.so.14.I.0, the inar( of the c&rrent version of
lirar(
lipn#14.so.14, a s(molic lin2 to lipn#14.so.14.I.0, so
that applications &sin# lipn#14.so.14 as the :O6*BE of
the lirar( "ill fin% nit an% &se the c&rrent version
lipn#14.so is a s(molic lin2 to lipn#14.so.14.I.0. :o it
points to the c&rrent version of the lirar(, so that ne"
applications lin2e% "ith -lpn#14 "ill &se the c&rrent
version of the lirar(
lipn#.so is a s(molic lin2 to lipn#14.so. :o applications
lin2e% "ith -lpn# "ill e lin2e% "ith the c&rrent version of
the lirar( =an% not the osolete one since "e %on0t "ant
an(more to lin2 applications a#ainst the osolete versionH>
lipn#14.a is a static version of the lirar(
lipn#.a is a s(molic lin2 to lipn#14.a, so that
applications staticall( lin2e% "ith lipn#.a "ill in fact &se
the c&rrent version of the lirar(
lipn#14.la is a confi#&ration file #enerate% ( litool
"hich #ives confi#&ration %etails for the lirar(. 4t "ill e
&se% to compile applications an% liraries that rel( on
lipn#.
lipn#.la is a s(molic lin2 to lipn#14.la: "e "ant to &se
the c&rrent version for ne" applications, once a#ain.
'he pkg-config files, in /usr/lib/pkgconfig/. 'hese
confi#&ration files are &se% ( the pkg-config tool that "e
"ill cover later. 'he( %escrie ho" to lin2 ne" applications
a#ainst the lirar(.
'he man&al pa#es in /usr/share/man/, e$plainin# ho" to &se
the lirar(.
'he hea%er files, in /usr/include/, nee%e% to compile ne"
applications or liraries a#ainst lipn#. 'he( %efine the
interface to lipn#. 'here are s(molic lin2s so that one can
choose et"een the follo"in# sol&tions:
Kse Lincl&%e Mpn#.hN in the so&rce co%e an% compile
"ith the %efa&lt compiler fla#s
Kse Lincl&%e Mpn#.hN in the so&rce co%e an% compile
"ith -4/&sr/incl&%e/lipn#14
Kse Lincl&%e Mlipn#14/pn#.hN in the so&rce an% compile
"ith the %efa&lt compiler fla#s
'he /&sr/in/lipn#14-confi# tool an% its s(molic lin2
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
/&sr/in/lipn#-confi#. 'his tool is a small shell script that
#ives confi#&ration informations ao&t the liraries, nee%e%
to 2no" ho" to compile applications/liraries a#ainst lipn#.
'his mechanism ase% on shell scripts is no" ein#
s&perse%e% ( p2#-confi#, &t as ol% applications or liraries
ma( rel( on it, it is 2ept for compatiilit(.
6o", let0s ma2e the installation in the @sta#in#A space:
make
DESTDIR=/home/<user>/felabs/sysdev/thirdparty/staging/ install
'hen, let0s install onl( the necessar( files in the @tar#etA space,
man&all(:
cp -a staging/usr/lib/libpng14.so.0* target/usr/lib
arm-linux-strip target/usr/lib/libpng14.so.14.3.0
*n% "e0re finall( %one "ith lipn#H
libjpeg
6o", let0s "or2 on li!pe#. ,o"nloa% it from
http://""".i!#.or#/files/!pe#src.vC.tar.#? an% e$tract it.
Confi#&rin# li!pe# is ver( similar to the confi#&ration of the
previo&s liraries :
CC=arm-linux-gcc ./configure --host=arm-linux \
--prefix=/usr
Of co&rse, compile the lirar(:
make
4nstallation to the @sta#in#A space can e %one &sin# the classical
DESTDIR mechanism, than2s to the patch applie% previo&sl(:
make
DESTDIR=/home/<user>/felabs/sysdev/thirdparty/staging/ install
*n% finall(, install man&all( the onl( nee%e% files at r&ntime in the
@tar#etA space:
cp -a staging/usr/lib/libjpeg.so.8* target/usr/lib/
arm-linux-strip target/usr/lib/libjpeg.so.8.0.0
,one "ith li!pe#H
FreeType
'he Free'(pe lirar( is the ne$t step. 7ra the tarall from
http://""".freet(pe.or#. /e teste% the la "ith version 2.4.2 &t
more other versions ma( also "or2. Kncompress the tarall.
'he Free'(pe &il% s(stem is a nice e$ample of "hat can e %one
"ith a #oo% &sa#e of the a&totools. Cross-compilin# Free'(pe is ver(
eas(. First, the confi#&re step:
CC=arm-linux-gcc ./configure --host=arm-linux \
--prefix=/usr
'hen, compile the lirar(:
make
4nstall it in the @sta#in#A space:
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
make
DESTDIR=/home/<user>/felabs/sysdev/thirdparty/staging/ install
*n% install onl( the re1&ire% files in the @tar#etA space:
cp -a staging/usr/lib/libfreetype.so.6* target/usr/lib/
arm-linux-strip target/usr/lib/libfreetype.so.6.6.0
,one "ith Free'(peH
DirectFB
Finall(, "ith ?li, lipn#, !pe# an% Free'(pe, all the %epen%encies of
,irectF- are rea%(. /e can no" &il% the ,irectF- lirar( itself.
,o"nloa% it from the official "esite, at http://""".%irectf.or#/. /e
teste% version 1.4.F of the lirar(. *s &s&al, e$tract the tarall.
-efore confi#&rin# ,irectF-, let0s have a loo2 at the availale
options ( r&nnin# ./configure --help. * lot of options are
availale. /e see that:
:&pport for F%ev =the Lin&$ frame&ffer> is a&tomaticall(
%etecte%, so that0s fine8
:&pport for 567, 95E7 an% Free'(pe is enale% ( %efa&lt, so
that0s fine8
/e sho&l% specif( a val&e for --with-gfxdrivers. 'he
har%"are em&late% ( .em& %oesn0t have an( accelerate%
%river in ,irectF-, so "e0ll pass --with-gfxdrivers=none8
/e sho&l% specif( a val&e for --with-inputdrivers. /e0ll
nee% keyboard =for the 2e(oar%> an% linuxinput to s&pport
the Lin&$ 4np&t s&s(stem. :o "e0ll pass --with-
inputdrivers=keyboard,linuxinput
:o, let0s e#in "ith a confi#&re line li2e:
CC=arm-linux-gcc ./configure --host=arm-linux \
--prefix=/usr --with-gfxdrivers=none \
--with-inputdrivers=keyboard,linuxinput
4n the o&tp&t, "e see:
*** JPEG library not found. JPEG image provider will not be
built.
:o let0s loo2 in confi#.lo# for the 95E7 iss&e. -( search for @!pe#A,
(o& can fin%:
configure:24701: arm-linux-gcc -o conftest -O3 -ffast-math -pipe
-D_REENTRANT conftest.c -ljpeg -ldl -lpthread >&5
/usr/local/xtools/arm-unknown-linux-uclibcgnueabi/arm-unknown-
linux-uclibcgnueabi/sys-root/usr/bin/../lib/gcc/arm-linux-
uclibcgnueabi/4.3.3/../../../../arm-linux-uclibcgnueabi/bin/ld:
cannot find -ljpeg
Of co&rse, it cannot fin% the !pe# lirar(, since "e %i%n0t pass the
proper LDFLAGS an% CFLAGS tellin# "here o&r liraries are. :o let0s
confi#&re a#ain "ith:
LDFLAGS=-
L/home/<user>/felabs/sysdev/thirdparty/staging/usr/lib \
CPPFLAGS=-
I/home/<user>/felabs/sysdev/thirdparty/staging/usr/include \
CC=arm-linux-gcc ./configure --host=arm-linux \
--prefix=/usr --with-gfxdrivers=none \
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
--with-inputdrivers=keyboard,linuxinput
O2, no" at the en% of the confi#&re, "e #et:
JPEG yes -ljpeg
PNG yes
-I/usr/include/libpng12 -lpng12
[]
FreeType2 yes -
I/usr/include/freetyp2 -lfreetype
4t fo&n% the 95E7 lirar( properl(, &t for lipn# an% freet(pe, it has
a%%e% -I options that points to the lipn# an% freet(pe liraries
installe% on o&r host =$CD> an% not the one of the tar#et. 'his is not
correctH
4n fact, the ,irectF- confi#&re script &ses the pkg-config s(stem to
#et the confi#&ration parameters to lin2 the lirar( a#ainst lipn#
an% Free'(pe. -( %efa&lt, pkg-config loo2s in
/usr/lib/pkgconfig/ for .pc files, an% eca&se the libfreetype6-
dev an% libpng12-dev pac2a#es are alrea%( installe% in (o&r s(stem
=it "as installe% in a previo&s la as a %epen%enc( of another
pac2a#e>, then the confi#&re script of ,irectF- fo&n% the lipn# an%
Free'(pe liraries of (o&r hostH
'his is one of the i##est iss&e "ith cross-compilation : mi$in# host
an% tar#et liraries, eca&se &il% s(stems have a ten%enc( to loo2
for liraries in the %efa&lt paths. 4n o&r case, if libfreetype6-dev
"as not installe%, then the /usr/lib/pkgconfig/freetype2.pc file
"o&l%n0t e$ist, an% the confi#&re script of ,irectF- "o&l% have sai%
somethin# li2e @:orr(, can0t fin% Free'(peA.
:o, no", "e m&st tell pkg-config to loo2 insi%e the
/usr/lib/pkgconfig/ %irector( of o&r @sta#in#A space. 'his is %one
thro&#h the PKG_CONFIG_PATH environment variale, as e$plaine% in
the man&al pa#e of pkg-config.
Boreover, the .pc files contain references to paths. For e$ample, in
/home/<user>/felabs/sysdev/thirdparty/staging/usr/lib/pkgc
onfig/freetype2.pc, "e can see:
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
[...]
Libs: -L${libdir} -lfreetype
Cflags: -I${includedir}/freetype2 -I${includedir}
:o "e m&st tell p2#-confi# that these paths are not asol&te, &t
relative to o&r @sta#in#A space. 'his can e %one &sin# the
PKG_CONFIG_SYSROOT_DIR environment variale.
Knfort&natel(, 'his is onl( possile "ith pkg-config NO 0.2I, "hich
is not (et availale in the K&nt& %istri&tion. :o start ( installin#
the pkg-config K&nt& pac2a#e availale in the data/ %irector( of
the la:
sudo dpkg -i data/pkg-config_0.23-1_i386.deb
'hen, let0s r&n the confi#&ration of ,irectF- a#ain, passin# the
PKG_CONFIG_PATH an% PKG_CONFIG_SYSROOT_DIR environment
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
variales:
LDFLAGS=-L/home/<user>/felabs/sysdev/thirdparty/staging/usr/lib \
CPPFLAGS=-
I/home/<user>/felabs/sysdev/thirdparty/staging/usr/include \
PKG_CONFIG_PATH=/home/<user>/felabs/sysdev/thirdparty/staging/us
r/lib/pkgconfig/ \
PKG_CONFIG_SYSROOT_DIR=/home/<user>/felabs/sysdev/thirdparty/sta
ging/ \
CC=arm-linux-gcc ./configure --host=arm-linux \
--prefix=/usr --with-gfxdrivers=none \
--with-inputdrivers=keyboard,linuxinput
O2, no", the lines relate% to Lipn# an% Free'(pe 2 loo2s m&ch
etter:
PNG yes
-I/home/<user>/felabs/sysdev/thirdparty/staging/usr/include/libpng14
-lpng14
FreeType2 yes
-I/home/<user>/felabs/sysdev/thirdparty/staging/usr/include/freetype2
-lfreetype
Let0s &il% ,irectF- "ith make. *fter a "hile, it fails, complainin#
that X11/Xlib.h an% other relate% hea%er files cannot e fo&n%. 4n
fact, if (o& loo2 ac2 the the ./configure script o&tp&t, (o& can see:
X11 support yes -lX11 -lXext
-eca&se P11 "as installe% on o&r host, ,irectF- ./configure script
tho&#ht that it sho&l% enale s&pport for it. -&t "e "on0t have P11
on o&r s(stem, so "e have to %isale it e$plicitl(. 4n the ./configure
--help o&tp&t, one can see :
--enable-x11 build with X11 support [default=auto]
:o "e have to r&n the confi#&ration a#ain "ith the same ar#&ments,
an% a%% --disable-x11 to them.
'he &il% no" #oes f&rther, &t still fails "ith another error :
/usr/lib/libfreetype.so: could not read symbols: File in
wrong format
*s (o& can rea% from the aove comman% line, the Ba2efile is tr(in#
to fee% an $CD inar( =/usr/lib/libfreetype.so> to (o&r *<B
toolchain. 4nstea%, it sho&l% have een &sin#
usr/lib/libfreetype.so fo&n% in (o&r sta#in# environment.
'his happens eca&se the litool .la files in (o&r sta#in# area nee%
to e fi$e% to %escrie the ri#ht paths in this sta#in# area. :o, in the
.la files, replace libdir='/usr/lib' (
libdir='/home/<user>/felabs/sysdev/thirdparty/staging/usr/
lib'. <estart the &il% a#ain, preferal( from scratch =make clean
then make> to e s&re ever(thin# is fine.
Finall(, it &il%s H
6o", install ,irectF- to the @sta#in#A space &sin#:
make
DESTDIR=/home/<user>/felabs/sysdev/thirdparty/staging/ install
*n% so the installation in the @tar#etA space:
First, the liraries:
cp -a staging/usr/lib/libdirect-1.4.so.5*
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
target/usr/lib
cp -a staging/usr/lib/libdirectfb-1.4.so.5*
target/usr/lib
cp -a staging/usr/lib/libfusion-1.4.so.5*
target/usr/lib
arm-linux-strip target/usr/lib/libdirect-
1.4.so.5.0.0
arm-linux-strip target/usr/lib/libdirectfb-
1.4.so.5.0.0
arm-linux-strip target/usr/lib/libfusion-
1.4.so.5.0.0
'hen, the pl&#ins that are %(namicall( loa%e% ( ,irectF-.
/e first cop( the "hole /usr/lib/directfb-1.4-5/
%irector(, then remove the &seless files =.la> an% finall( strip
the .so files:
cp -a staging/usr/lib/directfb-1.4-5/ target/usr/lib
find target/usr/lib/directfb-1.4-5/ -name '*.la'
-exec rm {} \;
find target/usr/lib/directfb-1.4-5/ -name '*.so'
-exec arm-linux-strip {} \;
DirectFB examples
'o test that o&r ,irectF- installation "or2s, "e "ill &se the e$ample
applications provi%e% ( the ,irectF- pro!ect. :tart ( %o"nloa%in#
the tarall at http://""".%irectf.or#/%o"nloa%s/E$tras/,irectF--
e$amples-1.2.0.tar.#? an% e$tract it.
'hen, "e confi#&re it !&st as "e confi#&re% ,irectF-:
LDFLAGS=-
L/home/<user>/felabs/sysdev/thirdparty/staging/usr/lib \
CPPFLAGS=-
I/home/<user>/felabs/sysdev/thirdparty/staging/usr/include \
PKG_CONFIG_PATH=/home/<user>/felabs/sysdev/thirdparty/staging/us
r/lib/pkgconfig/ \
PKG_CONFIG_SYSROOT_DIR=/home/<user>/felabs/sysdev/thirdparty/sta
ging/ \
CC=arm-linux-gcc ./configure --host=arm-linux \
--prefix=/usr
'hen, compile it "ith ma2e. :oon a compilation error "ill occ&r
eca&se )bzero+ is not %efine%. 'he )bzero+ f&nction is a %eprecate%
-:, f&nction, an% memset sho&l% e &se% instea%. 'he 76K C
lirar( still %efines )bzero+, &t ( %efa&lt, the &Clic lirar( %oesn0t
provi%e )bzero+ =to save space>. :o, let0s mo%if( the so&rce co%e in
src/df_knuckles/matrix.c to chan#e the line:
#define M_CLEAR(m) bzero(m, MATRIX_SIZE)
to
#define M_CLEAR(m) memset(m, 0, MATRIX_SIZE)
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
<&n the compilation a#ain, it sho&l% s&ccee%.
For the installation, as ,irectF- e$amples are onl( applications an%
not liraries, "e %on0t reall( nee% them in the @sta#in#A space, &t
onl( in the @tar#etA space. :o "e0ll %irectl( install in the @tar#etA
space &sin# the install-strip ma2e tar#et. 'his ma2e tar#et is
&s&all( availale "ith a&totools ase% &il% s(stems. 4n a%%ition to
the %estination %irector( =DESTDIR variale>, "e m&st also tell "hich
strip pro#ram sho&l% e &se%, since strippin# is an architect&re-
%epen%ent operation =STRIP variale>:
make STRIP=arm-linux-strip \
DESTDIR=/home/<user>/felabs/sysdev/thirdparty/target/
install-strip
Final setup
:tart the s(stem in .em& &sin# the run_qemu script, an% tr( to r&n
the df_andi pro#ram, "hich is one of the ,irectF- e$amples.
'he application "ill fail to r&n, eca&se the pthrea% lirar( ="hich is
a component of the C lirar(> is missin#. 'his lirar( is availale
insi%e the toolchain. :o let0s a%% it to the tar#et:
cp -a /usr/local/xtools/arm-unknown-linux-
uclibcgnueabi/arm-unknown-linux-uclibcgnueabi/sys-
root/lib/libpthread* target/lib/
'hen, tr( to r&n df_andi a#ain. 4t "ill complain ao&t libdl, "hich
is &se% to %(namicall( loa% liraries %&rin# application e$ec&tion. :o
let0s a%% this lirar( to the tar#et:
cp -a /usr/local/xtools/arm-unknown-linux-
uclibcgnueabi/arm-unknown-linux-uclibcgnueabi/sys-
root/lib/libdl* \
target/lib
/hen r&nnin# %fJan%i a#ain, it "ill complain ao&t li#ccJs, so let0s
cop( this lirar( to the tar#et:
cp -a /usr/local/xtools/arm-unknown-linux-
uclibcgnueabi/arm-unknown-linux-uclibcgnueabi/sys-
root/lib/libgcc_s* target/lib
6o", the application sho&l% no lon#er complain ao&t missin#
lirar(. -&t "hen starte%, sho&l% complain ao&t ine$istin# /dev/fb0
%evice file. :o let0s create this %evice file:
sudo mknod target/dev/fb0 c 29 0
6e$t e$ec&tion of the application "ill complain ao&t missin#
/dev/tty0 %evice file, so let0s create it:
sudo mknod target/dev/tty0 c 4 0
Finall(, "hen r&nnin# %fJan%i, another error messa#e sho"s &p:
Unable to dlopen '/usr/lib/directfb-1.2-
0/interfaces/IDirectFBImageProvider/libidirectfbimageprovi
der_png.so' !
File not found
,irectF- is tr(in# to loa% the 567 pl&#in &sin# the dlopen()
f&nction, "hich is part of the libdl lirar( "e a%%e% to the tar#et
s(stem efore. Knfort&natel(, loa%in# the pl&#in fails "ith the @File
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
:(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
not fo&n%A error. 3o"ever, the pl&#in is properl( present, so the
prolem is not the pl&#in itself. /hat happens is that the pl&#in
%epen%s on the libpng lirar(, "hich itself %epen%s on the
mathematic lirar(. *n% the mathematic lirar( libm =part of the C
lirar(> has not (et een a%%e% to o&r s(stem. :o let0s %o it:
cp -a /usr/local/xtools/arm-unknown-linux-
uclibcgnueabi/arm-unknown-linux-uclibcgnueabi/sys-root/lib/libm*
target/lib
6o", (o& can tr( an% r&n the df_andi applicationH
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
Eme%%e% Lin&$
s(stem %evelopment
'rainin# la oo2
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
cd
Using a build system, example with Buildroot
!"#ectives: discover ho$ a "%ild s&stem is %sed and ho$ it
$or's, $ith the e(ample of the )%ildroot "%ild s&stem. )%ild a
Lin%( s&stem $ith li"raries and ma'e it $or' inside *em%.
Setup
+o into the /home/<user>/felabs/sysdev/buildroot/ director&,
$hich alread& contains some data needed for this la", incl%din, a
'ernel ima,e.
Get Buildroot and explore the source code
-he official )%ildroot $e"site is availa"le at
http://$$$."%ildroot.net. o$nload the sta"le 2010.0. version
$hich $e have tested for this la". /ncompress the tar"all and ,o
inside the buildroot director&.
0everal s%"directories or files are visi"le, the most important ones
are:
boot contains the 1a'efiles and confi,%ration items related
to the compilation of common "ootloaders 2+r%", /-)oot,
)are"o(, etc.3
configs contains a set of predefined confi,%rations, similar
to the concept of defconfi, in the 'ernel.
docs contains the doc%mentation for )%ildroot. 4o% can start
readin, buildroot.html $hich is the main )%ildroot
doc%mentation5
linux contains the 1a'efile and confi,%ration items related
to the compilation of the Lin%( 'ernel
Makefile is the main 1a'efile that $e $ill %se to %se
)%ildroot: ever&thin, $or's thro%,h 1a'efiles in )%ildroot5
package is a director& that contains all the 1a'efiles, patches
and confi,%ration items to compile the %serspace applications
and li"raries of &o%r em"edded Lin%( s&stem. 6ave a loo' at
vario%s s%"directories and see $hat the& contain5
target contains patches and other items specific to partic%lar
hard$are platforms
toolchain contains the 1a'efiles, patches and confi,%ration
items to ,enerate the cross-compilin, toolchain.
Configure Buildroot
7n o%r case, $e $o%ld li'e to:
+enerate an em"edded Lin%( s&stem for 8915
/se an alread& e(istin, e(ternal toolchain instead of havin,
)%ildroot ,eneratin, one for %s5
7nte,rate )%s&"o(, irectF) and irectF) sample
applications in o%r em"edded Lin%( s&stem5
7nte,rate the tar,et files&stem into "oth an e(t2 files&stem
Em"edded Lin%(
s&stem development
-rainin, la" "oo'
Em"edded Lin%(
s&stem development
-rainin, la" "oo'
2004-200: Free Electrons, http://free-electrons.com Creative Commons License 2004-200: Free Electrons, http://free-electrons.com Creative Commons License
ima,e and a tar"all
-o r%n the confi,%ration %tilit& of )%ildroot, simpl& r%n:
make menuconfig
0et the follo$in, options:
-ar,et 8rchitect%re: 891
-ar,et 8rchitect%re ;ariant: arm926t.
-ar,et 8)7: EABI
)%ild options
<%m"er of #o"s to r%n sim%ltaneo%sl&: choose 2 or 4, for
e(ample, to speed %p compilin,, especiall& if &o% have a
d%al-core s&stem.
-oolchain
Toolchain type: External toolchain
External toolchain C library: uClibc
=e m%st tell )%ildroot a"o%t o%r toolchain confi,%ration,
so: ena"le Lar,e File 0%pport, 9>C. )%ildroot $ill chec'
these parameters an&$a&.
External toolchain path: %se the toolchain &o% "%ilt:
/usr/local/xtools/arm-unknown-linux-uclibcgnueabi
>ac'a,e selection for the tar,et
?eep )%s&"o( 2defa%lt version3 and 'eep the )%s&"o(
confi,%ration proposed "& )%ildroot5
7n +raphics li"raries and applications
0elect irectF). )%ildroot $ill a%tomaticall& select the
necessar& dependencies.
9emove to%chscreen s%pport from irectF)
0elect irectF) e(amples
0elect all the irectF) e(amples
-ar,et files&stem options
0elect ext2 root filesystem
0elect tar root filesystem
E(it the menuconfig interface. 4o%r confi,%ration has no$ "een
saved to the .config file.
Generate the embedded Linux system
@%st r%n
make
7t fails A%ic'l& "eca%se $e lac' the gettext and subversion
pac'a,es, so install them. )%ildroot $ill first create a small
environment $ith the e(ternal toolchain, then do$nload, e(tract,
confi,%re, compile and install each component of the em"edded
s&stem.
8ll the compilation has ta'en place in the output/ director&. LetBs
Em"edded Lin%(
0&stem development
-rainin, la" "oo'
Em"edded Lin%(
0&stem development
-rainin, la" "oo'
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
cd
e(plore its contents :
build, is the director& in $hich each component "%ilt "&
)%ildroot is e(tract, and $here the "%ild act%all& ta'es place
host, is the director& $here )%ildroot installs some
components for the host. 8s )%ildroot donBt $ant to depend
on too man& thin,s installed in the developer machines, it
installs some tools needed to compile the pac'a,es for the
tar,et. 7n o%r case it installed pkg-config 2since the version
of the most ma& "e ancient3 and tools to ,enerate the root
files&stem ima,e 2genext2fs, makedevs, fakeroot3
images, $hich contains the final ima,es prod%ced "&
)%ildroot. 7n o%r case itBs #%st an e(t2 files&stem ima,e and a
tar"all of the files&stem, "%t dependin, on the )%ildroot
confi,%ration, there co%ld also "e a 'ernel ima,e or a
"ootloader ima,e. -his is $here $e find rootfs.tar and
rootfs.ext2, $hich are respectivel& the tar"all and an e(t2
ima,e of the ,enerated root files&stem.
staging, $hich contains the C"%ildD space of the tar,et
s&stem. 8ll the tar,et li"raries, $ith headers, doc%mentation.
7t also contains the s&stem headers and the C li"rar&, $hich
in o%r case have "een copied from the cross-compilin,
toolchain.
target, is the tar,et root files&stem. 8ll applications and
li"raries, %s%all& stripped, are installed in this director&.
6o$ever, it cannot "e %sed directl& as the root files&stem, as
all the device files are missin,: it is not possi"le to create
them $itho%t "ein, root, and )%ildroot has a polic& of not
r%nnin, an&thin, as root.
toolchain, is the location $here the toolchain is "%ilt.
6o$ever, in o%r confi,%ration, $e re-%sed an e(istin,
toolchain, so this director& contains almost nothin,.
Run the generated system
=e $ill %se the 'ernel ima,e in data/ and the files&stem ima,e
,enerated "& )%ildroot in the e(t2 format to "oot the ,enerated
s&stem in *em%. =e start "& %sin, a *em%-em%lated 891 "oard
$ith displa& s%pport, allo$in, to test ,raphical applications rel&in,
on the irectF) li"rar&. Later, $e $ill "e a"le move to a real "oard if
&o%r hard$are also has a ,raphical displa&.
-he run_qemu script contains $hatBs needed to "oot the s&stem in
*em%.
Lo, in 2root acco%nt, no pass$ord3, r%n demo pro,rams:
df_andi
df_dok
df_fire
...
Going further
8dd dropbear 2006 server and client3 to the list of pac'a,es
"%ilt "& )%ildroot, add the net$or' em%lation in *em%, and
lo, to &o%r tar,et s&stem in *em% %sin, a ssh client on &o%r
Em"edded Lin%(
s&stem development
-rainin, la" "oo'
Em"edded Lin%(
s&stem development
-rainin, la" "oo'
2004-200: Free Electrons, http://free-electrons.com Creative Commons License 2004-200: Free Electrons, http://free-electrons.com Creative Commons License
development $or'station. 6int: &o% $ill have to set a non-
empt& pass$ord for the root acco%nt on &o%r tar,et for this to
$or'.
8dd a ne$ pac'a,e in )%ildroot for the +</ +t&pist ,ame.
9ead the )%ildroot doc%mentation to see ho$ to add a ne$
pac'a,e. Finall&, add this pac'a,e to &o%r tar,et s&stem,
compile it and r%n it in *em%.
Tests on real hardware
7f &o% have real 891 hard$are $ith ,raphical o%tp%t capa"ilit&, test
&o%r root files&stem on it. 4o% can:
Either cop& the e(t2 ima,e to a "loc' device that can "e
accessed "& &o%r hard$are 2flash card reader, /0) drive...3
!r mo%nt the e(t2 ima,e and cop& its contents to a flash
partition on &o%r "oard.
7f &o% $ant to lo, in on the serial console, %ncomment the ttyS0 line
in /etc/inittab. 7f &o%r s&stem %ses a different device file for the
serial console, modif& this line accordin,l&.
!f co%rse, &o% $ill also have to %se a 'ernel compiled for &o%r "oard.
Special instructions for the Beagle board
7f &o% are %sin, the )ea,le "oard,
Connect &o%r "oard to an ;7- or 617 displa&
Edit etc/inittab, %ncomment the line $ith ttyS0 and replace
all the occ%rrences of ttyS0 "& ttyS2
9e"%ild &o%r Lin%( 'ernel $ith the follo$in, settin,s:
CONFIG_OMAP2_DSS=y
FB_OMAP2=y
CONFIG_PANEL_GENERIC=y
LOGO=y 2optional3
8dd the follo$in, settin,s to the "oot ar,%ments:
console=tty0
2allo$s &o% to have "oth a frame"%ffer and serial console3
vram=12M 2video 9813
omapfb.mode=dvi:640x480MR-16@60 2e(ample for the >ico
>ro#ector. 4o% ma& first tr& to do $itho%t this parameter, and
then specif& a mode that &o%r monitor s%pports.
omapdss.def_disp=dvi 2defa%lt o%tp%t for the !map
ispla& 0%"0&stem driver3
Em"edded Lin%(
0&stem development
-rainin, la" "oo'
Em"edded Lin%(
0&stem development
-rainin, la" "oo'
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Sysdev - Application development and remote
debugging
O!ective:
Compile an" r#n $o#r o%n &irectF' application on
the tar(et.
)se strace an" ltrace to "ia(nose pro(ram iss#es.
)se ("server an" a cross-"e#((er to remotel$
"e#( an eme""e" application
Setup
*o to the /home/<user>/felabs/sysdev/appdev "irector$.
Compile your own application
+n this part, %e %ill re-#se the s$stem #ilt "#rin( the ,'#il"root
la- an" a"" to it o#r o%n application.
First, instea" of #sin( an e.t2 ima(e, %e %ill mo#nt the root
files$stem over /F0 to ma1e it easier to test o#r application. 0o,
create a qemu-rootfs/ "irector$, an" insi"e this "irector$,
#ncompress the tarall (enerate" $ '#il"root in the previo#s la 2in
the output/images/ "irector$3. &on4t for(et to e.tract the archive as
root since the archive contains "evice files.
5hen, a"apt the r#n67em# script to $o#r confi(#ration, an" verif$
that the s$stem %or1s as e.pecte".
/o%, o#r application. +n the la "irector$ the file data/app.c
contains a ver$ simple &irectF' application that "ispla$s the
data/background.png ima(e for five secon"s. 8e %ill compile an"
inte(rate this simple application to o#r Lin#. s$stem.
Let4s tr$ to compile the application:
arm-linux-gcc -o app app.c
+t complains that it cannot fin" the directfb.h hea"er. 5his is
normal, since %e "i"n4t tell the compiler %here to fin" it. 0o let4s #se
p1(-confi( to 7#er$ the p1(-confi( "ataase ao#t the location of the
hea"er files an" the list of liraries nee"e" to #il" an application
a(ainst &irectF':
export
PKG_CONFIG_PATH=/home/<user>/felabs/sysdev/buildroot/outpu
t/staging/usr/lib/pkgconfig
export
PKG_CONFIG_SYSROOT_DIR=/home/<user>/felabs/sysdev/buildroo
t/output/staging/
arm-linux-gcc -o app app.c $
(/home/<user>/felabs/sysdev/buildroot/output/host/usr/bin/
pkg-config --libs --cflags directfb)
Compilin( fails a(ain, eca#se the compiler co#l" not fin" the
lirar$. 5he simplest sol#tion to fi. this iss#e is to #se the s$sroot
feat#re of the cross-compilin( toolchain: %e can tell the toolchain
a(ainst %hich "irector$ the paths li1e /usr/lib, /lib or
/usr/include sho#l" e interprete".
Eme""e" Lin#.
s$stem "evelopment
5rainin( la oo1
Eme""e" Lin#.
s$stem "evelopment
5rainin( la oo1
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
arm-linux-gcc --sysroot
/home/<user>/felabs/sysdev/buildroot/output/staging/ -o
app app.c $
(/home/<user>/felabs/sysdev/buildroot/output/host/usr/bin/
pkg-config --libs --cflags directfb)
O#r application is no% compile"9 Cop$ the (enerate" inar$ an" the
background.png ima(e to the /F0 root files$stem 2in the root/
"irector$ for e.ample3, start $o#r s$stem, an" r#n $o#r application 9
Debugging setup
For the "e#((in( part %e "on4t nee" an em#late" LC& an$more, so
%e %ill move ac1 to $o#r :;< oar". 'oot $o#r :;< oar" over
/F0 on the files$stem pro"#ce" in the ,5in$ eme""e" s$stem- la,
%ith the same 1ernel.
Setting up gdbserver, strace and ltrace
gdbserver, strace an" ltrace have alrea"$ een compile" for $o#r
tar(et architect#re as part of the cross-compilin( toolchain. Fin"
them in the installation "irector$ of $o#r toolchain. Cop$ these
inaries to the /usr/bin/ "irector$ in the root files$stem of $o#r
tar(et s$stem.
Enabling job control
+n this la, %e are (oin( to r#n a #(($ pro(ram that 1eeps han(in(
an" crashin(. 'eca#se of this, %e are (oin( to nee" !o control, in
partic#lar [Ctrl] [C] allo%in( to interr#pt a r#nnin( pro(ram.
:t oot time, $o# proal$ notice" that %arnin( that !o control %as
t#rne" off:
/bin/sh: can't access tty; job control turned off
5his happens %hen the shell is starte" in the console. 5he s$stem
console cannot e #se" as a controllin( terminal.
: %or1 aro#n" is to start this shell in ttyS0 2the first serial port3 $
mo"if$in( the /etc/inittab file:
;eplace
::askfirst:/bin/sh 2impl$in( /dev/console3
$
ttyS0::askfirst:/bin/sh 2#sin( /dev/ttyS03
:lso create /dev/ttyS0 an" reoot. =o# sho#l" no lon(er see the
>?o control t#rne" off@ %arnin(, an" sho#l" e ale to #se [Ctrl]
[C].
Using strace
strace allo%s to trace all the s$stem calls ma"e $ a process:
openin(, rea"in( an" %ritin( files, startin( other processes,
accessin( time, etc. 8hen somethin( (oes %ron( in $o#r application,
strace is an inval#ale tool to see %hat it act#all$ "oes, even %hen
$o# "on4t have the so#rce co"e.
8ith $o#r cross-compilin( toolchain, compile the data/vista-
emulator.c pro(ram, an" cop$ the res#ltin( inar$ to the /root
"irector$ of the root files$stem 2$o# mi(ht nee" to create this
Eme""e" Lin#.
0$stem "evelopment
5rainin( la oo1
Eme""e" Lin#.
0$stem "evelopment
5rainin( la oo1
Ca#tion: if $o#r oar" #ses a serial
port "evice "ifferent from /dev/ttyS0,
"on4t for(et to #se the correct name
instea" of ttyS0 2e.ample: ttyS2 on
the 'ea(le oar"3.
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
"irector$ if it "oesn4t e.ist $et3.
arm-linux-gcc -o vista-emulator data/vista-emulator.c
cp vista-emulator path/to/root/filesystem/root
'ac1 to tar(et s$stem, tr$ to r#n the /root/vista-emulator
pro(ram. +t sho#l" han( in"efinitel$9
+nterr#pt this pro(ram $ hittin( [Ctrl] [C].
/o%, r#nnin( this pro(ram a(ain thro#(h the strace comman" an"
#n"erstan" %h$ it han(s. =o# can (#ess it %itho#t rea"in( the
so#rce co"e9
/o% a"" %hat the pro(ram %as %aitin( for, an" no% see $o#r
pro(ram procee" to another #(, failin( %ith a se(mentation fa#lt.
Using ltrace
5r$ to r#n the pro(ram thro#(h ltrace. =o# %ill see that another
lirar$ is re7#ire" to r#n this #tilit$. Fin" this lirar$ in the toolchain
an" a"" it to $o#r root files$stem a(ain.
/o%, ltrace sho#l" r#n fine an" $o# sho#l" see %hat the pro(ram
"oes: it tries to cons#me as m#ch s$stem memor$ as it can9
Using gdbserver
8e are no% (oin( to #se gdbserver to #n"erstan" %h$ the pro(ram
se(fa#lts.
Compile vista-emulator.c a(ain %ith the -g option to incl#"e
"e#((in( s$mols. Aeep this inar$ on $o#r %or1station, an" ma1e
a cop$ in the /root "irector$ of the tar(et root files$stem. 5hen,
strip the inar$ on the tar(et to remove the "e#((in( s$mols. 5he$
are onl$ nee"e" on $o#r host, %here the cross-"e#((er %ill r#n:
arm-linux-strip path/to/root/filesystem/root/vista-emulator
5hen, on the tar(et si"e, r#n vista-emulator #n"er gdbserver.
gdbserver %ill listen on a 5CB port for a connection from *&', an"
%ill control the e.ec#tion of vista-em#lator accor"in( to the *&'
comman"s:
gdbserver localhost:2345 vista-emulator
On the host si"e, r#n arm-linux-gdb 2also fo#n" in $o#r toolchain3:
arm-linux-gdb vista-emulator
=o# can also start the "e#((er thro#(h the ddd interface:
ddd --debugger arm-linux-gdb vista-emulator
*&' starts an" loa"s the "e#((in( information from the vista-
emulator inar$ that has een compile" %ith -g.
5hen, %e nee" to tell %here to fin" o#r liraries, since the$ are not
present in the "efa#lt /lib an" /usr/lib "irectories on $o#r
%or1station. 5his is "one $ settin( *&' sysroot variale:
(gdb) set sysroot /usr/local/xtools/arm-unknown-linux-
uclibcgnueabi/arm-unknown-linux-uclibcgnueabi/sys-root/
:n" tell gdb to connect to the remote s$stem:
(gdb) target remote <target-ip-address>:2345
Eme""e" Lin#.
s$stem "evelopment
5rainin( la oo1
Eme""e" Lin#.
s$stem "evelopment
5rainin( la oo1
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
5hen, #se gdb as #s#al to set rea1points, loo1 at the so#rce co"e,
r#n the application step $ step, etc. *raphical versions of gdb, s#ch
as ddd can also e #se" in the same %a$. +n o#r case, %e4ll !#st start
the pro(ram an" %ait for it to hit the se(mentation fa#lt:
(gdb) continue
=o# co#l" then as1 for a ac1trace to see %here this happene":
(gdb) backtrace
5his %ill tell $o# that the se(mentation fa#lt occ#rre" in a f#nction of
the C lirar$, calle" $ o#r pro(ram. 5his sho#l" help $o# in fin"in(
the #( in o#r application.
What to remember
&#rin( this la, %e learne" that...
Compilin( an application for the tar(et s$stem is ver$ similar
to compilin( an application for the host, e.cept that the cross-
compilation intro"#ces a fe% comple.ities %hen liraries are
#se".
+t4s eas$ to st#"$ the ehavior of pro(rams an" "ia(nose
iss#es %itho#t even havin( the so#rce co"e, than1s to strace
an" ltrace.
=o# can leave a small gdbserver pro(ram 2C00 A'3 on $o#r
tar(et that allo%s to "e#( tar(et applications, #sin( a
stan"ar" *&' "e#((er on the "evelopment host.
+t is fine to strip applications an" inaries on the tar(et
machine, as lon( as the pro(rams an" liraries %ith
"e#((in( s$mols are availale on the "evelopment host.
Eme""e" Lin#.
0$stem "evelopment
5rainin( la oo1
Eme""e" Lin#.
0$stem "evelopment
5rainin( la oo1
2007-2010 Free Electrons, http://free-electrons.com Creative Commons License 2007-2010 Free Electrons, http://free-electrons.com Creative Commons License
Real-time - Timers and scheduling latency
O!ective: Learn ho" to meas#re time an$ #se hi%h resol#tion
timers. &eas#re sche$#lin% latenc'.
(fter this la, 'o# "ill
)e ale to meas#re time an$ create 'o#r o"n hi%h resol#tion
timers.
)e ale to start processes "ith real-time priorit'.
*ave compare$ sche$#lin% latenc' on 'o#r s'stem, et"een a
stan$ar$ +ernel an$ a +ernel "ith real-time preempt patches.
Setup
,o to the /home/<user>/felabs/realtime/rttest $irector'.
On 'o#r $evelopment "or+station, install the manpages-posix,
manpages-posix-dev, the' contain the -O./0 (-/ $oc#mentation
that mi%ht e #sef#l "hen $oin% real-time pro%rammin%.
1e are %oin% to #se the 2.2.33.7 +ernel so#rces, "hich "ere #se$ to
test this la.
-lease sta' "ith a 2.2.33.4 version, as this is the most recent version
"ith PREEMPT_RT s#pport.
-atch the +ernel "ith ipconfigdelay.patch locate$ in rttest/data
$irector'.
/nstall netcat on 'o#r host, ' r#nnin%:
apt-get install netcat
5o"nloa$ Co$e.o#rcer'6s 2009q1 toolchain at:
http://""".co$eso#rcer'.com/s%pp/lite/arm/portal/release787
Choose 9/(32 ,:;/Lin#4 <(=>
;ntar it.
($$ /home/<user>/felabs/realtime/rttest/arm-2009q1/bin to
'o#r PATH.
/n /home/<user>/felabs/realtime/rttest/nfsroot/inittab
replace ttyS0 ' ttyS2.
Kernel configuration
Confi%#re this +ernel "ith the config-beagle-v2.6.33
confi%#ration file availale on rttest/data $irector'.
1e #se a net"or+ connection over ;.) an$ "ith this +ernel version
the $evice ma' not e availale "hen IP-Config tr' to confi%#re
net"or+s. <hat6s "h' "e applie$ a patch. <his patch a$$ a +ernel
parameter "hich mimics the ?root$ela'? option efore mo#ntin% the
root file s'stem. ($$ the follo"in% comman$ to 'o#r +ernels
parameters:
ipconfdelay=2
)oot the )ea%le oar$ ' mo#ntin% the root files'stem availale at
/home/<user>/felabs/realtime/rttest/nfsroot/ "ith :F..
1
=eal <ime in
eme$$e$ Lin#4 s'stems
<rainin% la oo+
=eal <ime in
eme$$e$ Lin#4 s'stems
<rainin% la oo+
1e are #sin% a %lic toolchain eca#se
%lic has etter s#pport for the -O./0
=< (-/ than #Clic. /n o#r case, "hen
"e create$ this la, #Clic $i$n6t
s#pport the clock_nanosleep f#nction
#se$ in o#r rttest.c pro%ram.
2007-2010 Free Electrons, http://free-electrons.com Creative Commons License 2007-2010 Free Electrons, http://free-electrons.com Creative Commons License
Using high-resolution timers
*ave a loo+ at the rttest.c so#rce file availale in root/ in the
nfsroot/ $irector'. .ee ho" it sho"s the resol#tion of the
CLOCK_MONOTONIC cloc+.
:o" compile this pro%ram:
arm-none-linux-gnueabi-gcc -o rttest rttest.c -lrt
E4ec#te the pro%ram on the oar$. /s the cloc+ resol#tion %oo$ or
a$@ Compare it to the timer tic+ of 'o#r s'stem, as $efine$ '
CONFIG_HZ.
Ovio#sl', this resol#tion "ill not provi$e acc#rate sleep times, an$
this is eca#se o#r +ernel $oesn6t #se hi%h-resol#tion timers. .o let6s
enale the follo"in% options in the +ernel confi%#ration:
CONFIG_HIGH_RES_TIMERS
=ecompile 'o#r +ernel, oot 'o#r )ea%le oar$ "ith the ne" version,
an$ chec+ the ne" resol#tion. )etter, isn6t it @
Testing the non-preemptible kernel
:o", $o the follo"in% tests:
<est the pro%ram "ith nothin% special an$ "rite $o"n the
res#lts.
<est 'o#r pro%ram an$ at the same time, a$$ some "or+loa$
to the oar$, ' r#nnin% doload 300 on the oar$, an$ #sin%
netcat 192.168.0.100 5566 on 'o#r "or+station "hen 'o#
see the messa%e 9Listening on any address 5566> in or$er
to floo$ the net"or+ interface of the )ea%le oar$ A"here
192.168.0.100 is the /- a$$ress of the )ea%le oar$B
<est 'o#r pro%ram a%ain "ith the "or+loa$, #t ' r#nnin%
the pro%ram in the SCHED_FIFO sche$#lin% class at priorit'
CC, #sin% the chrt comman$.
Testing the preemptible kernel
=ecompile 'o#r +ernel "ith CONFIG_PREEMPT enale$, "hich enales
+ernel preemption Ae4cept for critical sections protecte$ '
spinloc+sB.
=e-$o the simple tests "ith this ne" preemptile +ernel an$ compare
the res#lts.
Testing the real-time patch
,et the PREEMPT_RT patch correspon$in% to 'o#r +ernel version from
http://www.kernel.org/pub/linux/kernel/projects/rt/, an$ appl' it
to the +ernel so#rce co$e. Confi%#re the +ernel "ith
CONFIG_PREEMPT_RT an$ recompile it. <he +ernel sho#l$ no" e f#ll'
preemptile, incl#$in% in critical sections, an$ tas+s can have hi%her
priorities than interr#pts.
=e-$o the simple tests "ith this real-time preemptile +ernel an$
compare the res#lts.
2
=eal <ime in
eme$$e$ Lin#4 s'stems
<rainin% la oo+
=eal <ime in
eme$$e$ Lin#4 s'stems
<rainin% la oo+
2007-2010 Free Electrons, http://free-electrons.com Creative Commons License 2007-2010 Free Electrons, http://free-electrons.com Creative Commons License
Using mdev
O!ective: "racticin# $ith %&s'%o( m)ev
*fter this la, 'o& $ill e ale to
+se mdev to pop&late the /dev )irector' $ith )evice files
correspon)in# to )evices present on the s'stem.
+se mdev to a&tomo&nt e(ternal )is, partitions.
Root filesystem
-e $ill re&se the root files'stem from the ./in' s'stem0 la.
Kernel settings
1e&se the Lin&( ,ernel from the ./in' s'stem0 la. 2f 'o& prefer to
start from fresh so&rces, &se the confi#&ration s&pplie) in the data
)irector'.
3o$ a)) or mo)if' the elo$ settin#s to 'o&r ,ernel:
Enale loa)ale mo)&le s&pport: CO3F2456O7+LE89'
6o)&le &nloa)in#: CO3F2456O7+LE5+3LO*79'
8&pport for :ost-si)e +8%: CO3F245+8%9m
6a,e s&re this is set as a mo)&le;
O:C2 :C7 s&pport: CO3F245+8%5O:C25:C79m
+8% 6ass 8tora#e s&pport: CO3F245+8%58/O1*4E9m
*n) an' other feat&re that co&l) e nee)e) on 'o&r har)$are
to access 'o&r hot-pl&##ale )evice.
Compile 'o&r ,ernel. 2nstall the mo)&les in 'o&r root files'stem
&sin#:
make INSTALL_MOD_PATH=<root-dir-path> modules_install
Booting the system
%oot 'o&r s'stem thro&#h 3F8 $ith the #iven root files'stem.
/o ma,e s&re that mo)&le loa)in# $or,s, tr' to loa) the usb-
storage mo)&le:
modprobe usb-storage
First mdev tests
-e are first #oin# to &se mdev to pop&late the /dev )irector' $ith all
)evices present at oot time.
6o)if' the /etc/init.d/rcS script to mo&nt a tmpfs files'stem on
/dev/, an) r&n mdev -s to pop&late this )irector' $ith all minim&m
)evice files. <er' nice, isn=t it>
Using mdev as a hotplug agent
+sin# the #&i)elines in the lect&res, an) %&s'%o( )oc&mentation,
&se mdev to a&tomaticall' create all the /dev/sd[a-z][1-9]* )evice
files $hen a +8% )is, is inserte), correspon)in# to the )is, itself
Eme))e) Lin&(
8'stem 7evelopment
/rainin# la oo,
Eme))e) Lin&(
8'stem 7evelopment
/rainin# la oo,
200?-2010 Free Electrons, http://free-electrons.com Creative Commons License 200?-2010 Free Electrons, http://free-electrons.com Creative Commons License
an) its partitions.
*lso ma,e s&re these )evice files are also remove) a&tomaticall'
$hen the flash )rive is remove).
Automatic mounting
1efine 'o&r confi#&ration to also mo&nt each partition a&tomaticall'
$hen a +8% )is, is inserte), an) to )o the opposite after the )is, is
remove).
Eme))e) Lin&(
s'stem )evelopment
/rainin# la oo,
Eme))e) Lin&(
s'stem )evelopment
/rainin# la oo,
@o& co&l) &se /media/<devname> as
mo&nt point for each partition.
2004-2010 Free Electrons, http://free-electrons.com Creative Commons License 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
Backing up your lab files
O!ective: clean "p an# ma$e an archive of %o"r la #irector%
End of the training session
Con&rat"lations. 'o" reache# the en# of the trainin& session. 'o"
no( have plent% of (or$in& e)amples %o" create# % %o"rself, an#
%o" can "il# "pon them to create more elaorate thin&s.
*n this last la, (e (ill create an archive of all the thin&s %o"
create#. +e (on,t $eep ever%thin& tho"&h, as there are lots of
thin&s %o" can easil% retrieve a&ain.
Create a lab archive
-o to the #irector% containin& %o"r felabs #irector%:
cd $HOME
.o(, r"n a comman# that (ill #o some clean "p an# then create an
archive (ith the most important files:
/ernel confi&"ration files
Other so"rce confi&"ration files 01"s%1o), Crosstool-n&...2
/ernel ima&es
3oolchain
Other c"stom files
4ere is the comman#:
./felabs/archive-labs
5t en# en#, %o" sho"l# have a felabs-<user>.tar.lzma archive
that %o" can cop% to a 671 flash #rive, for e)ample. 3his file sho"l#
onl% e a fe( h"n#re#s of 81 i&.
Lin") 3rainin&
La 1oo$
Lin") 3rainin&
La 1oo$

You might also like