Anda di halaman 1dari 54

IntroductiontouClinux

VM
IntroductiontouClinux
MichaelOpdenacker
FreeElectrons
http://freeelectrons.com

CreatedwithOpenOffice.org2.x
ThankstoNicolasRougier(Copyright2003,http://webloria.loria.fr/~rougier/)fortheTuximage

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

Rightstocopy

AttributionShareAlike2.5
Youarefree
tocopy,distribute,display,andperformthework
tomakederivativeworks
tomakecommercialuseofthework
Underthefollowingconditions
Attribution.Youmustgivetheoriginalauthorcredit.
ShareAlike.Ifyoualter,transform,orbuilduponthiswork,
youmaydistributetheresultingworkonlyunderalicense
identicaltothisone.
Foranyreuseordistribution,youmustmakecleartoothersthe
licensetermsofthiswork.
Anyoftheseconditionscanbewaivedifyougetpermissionfrom
thecopyrightholder.
Yourfairuseandotherrightsareinnowayaffectedbytheabove.
Licensetext:http://creativecommons.org/licenses/bysa/2.5/legalcode

Copyright20042008
FreeElectrons
feedback@freeelectrons.com
Documentsources,updatesandtranslations:
http://freeelectrons.com/articles/uclinux
Corrections,suggestions,contributionsand
translationsarewelcome!

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

Bestviewedwith...
ThisdocumentisbestviewedwitharecentPDFreader
orwithOpenOffice.orgitself!
Takeadvantageofinternalorexternalhyperlinks.
So,donthesitatetoclickonthem!
Findpagesquicklythankstoautomaticsearch.
Usethumbnailstonavigateinthedocumentinaquickway.
IfyourereadingapaperorHTMLcopy,youshouldgetyourcopy
inPDForOpenOffice.orgformaton
http://freeelectrons.com/articles/uclinux!

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

Contents
uClinuxprojectoverview
uClinuximplementationdetails
UsinguClinux

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

Acronyms
MMU:MemoryManagementUnit
MPU:MemoryProtectionUnit
Onlyimplementsmemoryprotection,notvirtualmemory.
GOT:GlobalOffsetTableUsedinexecutableformats.
ELF:ExecutableandLinkableFormat
Afileformatdescribingexecutables,objectcode,sharedlibrariesand
coredumps.TheOSusesittoknowhowtoloadexecutablesandshared
libraries.
PIC:PositionIndependentCode
Objectcodewithoutabsoluteaddresses,whichcanexecuteatdifferent
locationsinmemory.
Seehttp://en.wikipedia.org/wiki/Position_independent_code
IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

TheMMUjob
MMUsincludedinmanygeneralpurposeprocessorsavailabletoday
Virtualtophysicaladdresstranslation.
Allowsprocessestorunintheirownvirtualcontiguousaddressspace.Noneed
forrelocatingprocessaddresses.Possibletoexpandtheaddressspaceofa
runningprocess.
TheMMUraisesanexceptionwhennophysicaladdressisavailable,makingit
possibletoimplementswappingtodisk.
Addressprotection
ActuallydonebytheMPUavailableinmostMMUs.
Preventsprocessesfromaccessingunauthorizedmemoryaddresses.
Thisisalsousedtoimplementdemandpaging(usingpagefaultstoloadin
RAMonlytheaddressesactuallyaccessed)andswapping.
NotethatsomesystemsjusthaveanMPU,butnoMMU.
IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

IntroductiontouClinux

uClinuxprojectoverview

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

TheuClinuxproject
http://www.uclinux.org/Linuxformicrocontrollers
Deliveries:
LinuxkernelsupportingMMUlessprocessors
(atleast32bit)Supportedinmainstreamsources
orthroughpatches.
Softwaredistribution(sourceonly):
http://www.uclinux.org/pub/uClinux/dist/
uClibc:alightweightthoughhighlycompatibleClibrary.
Nowanindependentproject.UsedbyLinuxtoo!
Crosscompilingtoolchains.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

uClinuxdevices

Justafewexamples!
Sendusmore!
uClinuxisoftensodeeplyembedded
thatit'sdifficulttoidentify

Multimedia

TinySingleBoard
Computers

CDataSolutions
CFcomputer

Networkdevices

SnapGearLITE2VPN/Router

SimtecSBCs

Industrial
AppleiPod(notshippedwithuClinux)

SigmaDesignsEM8500basedDVDplayers

picotuxRJ45size
computer

IntelliComremotecontrolsystem

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

StarDotNetCam

Aplio/PROIPPhone

uClinuxhistory
Firstreleasein1998(Linux2.0),
fortheMotorola68000processor.
DemonstratedonPalmPilotIII.
1999:MotorolaColdFiresupport
2001:Linux2.4support.ARM7support
2004:Linux2.6supportforARM
2008:You'rereadingthisdocument

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

10

ReasonsforusinguClinux(1)
Linux
BuiltinIPconnectivity,
reliability,portability,filesystems,
freesoftware...
Lightweight
FullLinux2.6kernelunder300K,
binariesmuchsmallerwith
uClibc.
XIP(ExecuteInPlace)
Don'thavetoloadexecutablesin
RAM.Mayrunslowerthough.

Cheaper
MMUlessarmcoresaresmaller.
Sufficient
Alargenumberofembedded
systemsapplicationscando
withoutanMMU.
Faster
Fastercontextswitches:nocache
flushes.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

11

ReasonsforusinguClinux(2)
Useraccesstothehardware
Userapplicationscanaccessthe
wholesystem,includingdevice
registers.
FullLinuxAPI
CanusemostLinuxsystemcalls
withminorexceptions.Ported
applicationsdistributedwith
uClinux.

Fullmultitasking
Justminorlimitations
Supportedonmanyprocessors,
whichwouldn'tbesupportedby
Linuxotherwise.
Seehttp://www.uclinux.org/ports/
EvenrunningonDSPprocessors
(ADIBlackfin,TIDM64x)!

FullLinux2.6kernelfeatures
stability,preemptiblekernel,
drivers...

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

12

uClinuxweaknesses
LessmomentumthanLinux.
Muchsmallercommunity.
Muchlessonlinedocumentation
andresourcesavailable
Lackofupdatesonpagesanddeliverablesonhttp://uclinux.org.Lotsof
linksandresourcesolderthan2002.
LotsofprojectsstillusingLinux2.4.
HoweveruClinuxdevelopmentisstillactive:kernelanddistribution.
uClinuxreleasesavailableforeachLinux2.6.xversion,
releasedjustafewweeksafter.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

13

uClibc
http://www.uclibc.org/forCodePoetConsulting
LightweightClibraryforsmallembeddedsystems,withmost
featuresthough.
OriginallydevelopedforuClinux.Nowanindependentproject.
ThewholeDebianWoody(thousandsofprograms)wasrecently
portedtoit...Youcanassumeitsatisfiedmostneeds!
Examplesize(ARM):approx.400K(vs.1700Kforglibc)
uClibcvs.glibcsizecomparison(busyboxexample,staticbuild):
311Kvs.843K!

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

14

uClinuxlimitations
Inanutshell
Virtualmemory=physicalmemory
Fixedmemoryforprocesses,can'tfragmentthememory:
morememoryconsumption
Nomemoryprotection.Nodistinctionbetweenusermode
andkernelmode.Anyprogramcancorruptkernelmemory
andevencauseasystemcrash.
Veryusefuldetails(byDavidMcCullough):
http://www.linuxjournal.com/article/7221

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

15

IntroductiontouClinux

uClinuximplementationdetails

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

16

Nomemorymanagement
Novirtualmemory
Programsaddressesneedtobepreprocessed(relocated)before
runningtoobtainuniqueaddressspaces.
Noondemandpaging
NeedtoloadwholeprogramcodeinRAM
(insteadofjustloadingpageswhentheyareeffectivelyaccessed).
Nomemoryprotection
Anyprogramcancrashanotherprogramorthekernel.Corruption
cangounnoticedandsurfacelater...difficulttotrackdown!
Designyourcodecarefully.Becarefulofdatafromtheoutside!
Noswapping
Notreallyanissueonthetinyembeddeddevices
IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

17

Betterperformance
uClinuxcanbesignificantlyfasterthanLinuxonthesameprocessor!
MMUoperationcanrepresentasignificanttimeoverheard.Evenwhen
anMMUisavailable,itisoftenturnedoffinsystemswithrealtime
constraints.
ContextswitchingcanbemuchfasteronuClinux.OnARM9,for
example,theVMbasedcachehastobeflushedateachcontextswitch.
Nosuchneedwhenalltheprocessessharethesameaddressspace.
SeeaninterestingbenchmarkfromH.S.ChoiandH.C.Yun:
http://opensrc.sec.samsung.com/document/uclinux04_sait.pdf

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

18

Differentexecutableformat
Standardformats(suchasELF)relyonVMtocreatethe
addressspaceofaprocess.
flatformat:condensedexecutableformatstoringonly
executablecodeanddata,plustherelocationsneededtoload
theexecutableintoanylocationinmemory.
uClinuxspecifictoolchainsareneededtocreateexecutables
inthisformat.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

19

Differentmmapimplementation
Unlessthefileisstoredsequentiallyandcontiguously,mmap
needstoallocatememory!Onlyromfscanguaranteethis.
Anotherconditionisthatthestoragecandirectlybeaccessed
intheCPUphysicaladdressspace.Canworkwithflashor
ROM,butnotwithdiskstorage.
Onlyreadonlymappingscanbeshared(nocopyonwrite)
withoutallocatingmemory.
Inanutshell,themmapsystemcallisavailable,but
applicationdevelopersshouldbeawarethatithas
performanceissuesinthecasesmentionedabove.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

20

Otherkerneldifferences
Notmpfs
CannotusethetmpfsfilesystemrelyingonVM.
Needtousefixedsizeramdisks.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

21

Nodynamicstack(1)

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

original
stack

MMU

extra
stack

Wheneveranapplicationtriestowrite
beyondthetopofitsstack,theMMU
raisesanexception.Thiscausessome
newmemorytobeallocatedandmapped
inatthetopofthestack.

extra
stack

WithVM,cangrowthestackofa
runningprocesswheneverneeded.

Physical
memory

CPU
Virtual
memory

original
stack

Linux

22

Nodynamicstack(2)
uClinux
Stacksizemustbeallocatedatcompiletime:4KBbydefault.
Noexceptionraisedwhenaprocesswritesbeyondthetopofitsstack!
Theconsequencesofthiscouldsurfacemuchlater.
Ifstrangecrasheshappen,trytoincreasethestacksizeofprograms:
Eitherrecompile:
runexportFLTFLAGS=s<stacksize>beforerecompiling.
Orrunflthdrs<stacksize><executable>

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

23

Memoryallocation
StandardLinuxallocator:allocatesblocksof2nsize.
If65KBarerequested,128KBwillbereserved,andthe
remaining63KBwon'tbereusableinLinux.
uClinux2.4memoryallocator:kmalloc2(akapage_alloc2)
Allocatesblocksof2nsizeuntil4KB
Uses4KBpagesforgreaterrequests
Storesamountsnotgreaterthan8KB
onthestartofthememory,andlarger
onesattheend.Reducesfragmentation.
NotavailableyetforLinux2.6!

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

Biggerblocks

<8KBblocks

24

Nodynamicprocesssize(1)
Linux
WithVM,canincreaseordecrease
theprocesssizewiththebrk()andsbrk()systemcalls.
malloc()implementationbasedonbrk()andsbrk().

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

25

Nodynamicprocesssize(1)
uCLinux
Memoryhastobeallocatedfromaglobal,sharedmemorypool
Differentmalloc()implementation(mallocsimple()),accessing
memoryinthispool,managedbythekernelallocator.
Fragmentation:canbeunabletoallocateenoughcontiguousmemory
Suchsituationscanbedetectedthrough/proc/mem_map(kmalloc2)
Seehttp://www.cyberguard.info/snapgear/tb20020530.htmlfordetailsabout
allocatingmemoryinuClinux.

Can'tallocatememoryforthisextrablock,
whileit'slessthanhalfthefreememory!
IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

26

Tipsforreducingmemoryfragmentation
Haveyourprogramsallocatesmallerchunksofmemory,
ratherthatallocatingbigonesatonce.
Ifpossible,stopandrestartapplicationswhenmemoryistoo
fragmented.Designyourapplicationssothattheycanbeshut
downandrestarted.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

27

Tipsforavoidingmemoryissues
MemoryissuescanbeverydifficulttotrackinuClinux.
Fortunately,theyshouldonlyhappenwithyourown
applications,notwithwidelytestedtoolsfromyouruClinux
distribution.
Designwithcareandwithalowmemorybudgetinmind.
Idea:firstdevelopandprofileyourapplicationonLinux
(typicallyonyouri386desktop).Thereareseveralutilitiesto
detectmemoryissues:Valgrind,memcheck,ElectricFence.
Seehttp://freeelectrons.com/articles/swdevfordetails.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

28

Nofork()
Linuxfork()
Thechildprocessisacloneoftheparent,usingthesamevirtual
memoryspace.Newmemoryallocationhappensforthechildonly
whenitmodifiesapage(copyonwrite).

uClinuxonlyimplementsvfork()
Theparentexecutionisstoppedandnewmemoryiscreatedbefore
thechildprocessisexecuted.Consumesmorememory!
Needtoreplaceallfork()callsbyvfork()
Nosignificantimpactonmultitaskingthough.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

29

ExecuteInPlace(XIP)
AllowstostartanapplicationwithoutloadingitinRAM.
Appliesalsotomultipleinstancesofthesameprogram.
SavesalotofRAM!
Onlysupportedbyromfs
(needcontinuous,noncompressedstorage).
OnlysupportedbythePositionIndependentCode(PIC)flavorof
theflatformat(mustbesupportedbythecompiler).
Caution:XIPmaybemuchslowerifstorageaccesstimeishigh.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

30

Sharedlibraries
PrettydifferentunderuClinux.
Differentcompilingoptions...
Makingyourownwon'tbefamiliar.
MustbecompiledforXIP.WithoutXIP,sharedlibrariesresultina
fullcopyofthelibraryforeachapplicationusingit,whichisworse
thanstaticallylinkingyourapplications.
Seehttp://elinux.org/UClinux_Shared_Library
forimplementationdetails.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

31

uClinuxandLinux2.6
MostofuClinuxcodenowmergedwithmainstreamLinux.
ArchitecturessupportsinmainstreamLinux:
MMUlessm68kandarm,Hitachi'sH8/300series,NEC
v850processor,ADIBlackfin
Linux2.6canbebuiltwithnovirtualmemorysystem
inafewplatforms(notsupportedonx86,forexample).

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

32

IntroductiontouClinux

UsinguClinux

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

33

uClinuxonm68knommuplatforms
http://uclinux.org/ports/coldfire/
KernelsourceswiththestandardLinuxkernel
(arch/m68knommu/)
Supportedprocessors:prettylonglist!
(seearch/m68knommu/Kconfig)
Binaryfilesystemimagesalsoavailable
onhttp://uclinux.org/ports/coldfire/binary.html

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

34

uClinuxonARMMMUlessplatforms
NowsupportedinmainstreamLinux
Usedtobeavailableasseparatepatchesuntilversion2.6.20
(approximately)
Noseparatearmnommuarchitecture
Supportedprocessors:
Lookfor!MMUinarch/arm/mm/Kconfig

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

35

uClinuxonADIBlackfin
http://blackfin.uclinux.org/
SupportedinmainstreamLinuxsince2.6.22
Anicesiteandanactivedevelopercommunity
Shipsbinarybootloader,kernelanddistributionimages.
PeoplefromotheruClinuxportscanlearn
fromtheirresourcesandexperience.
Actually,BlackfinhasnoVM,butsomememoryprotection.
SeeanicearticleonBlackfinspecifics:
http://docs.blackfin.uclinux.org/doku.php?id=operating_systems#introduction_to_uclinux

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

36

uClinuxonotherarchitectures
uClinuxontheMicroBlazeFPGAprocessor
http://www.itee.uq.edu.au/~jwilliams/mblazeuclinux/
Niceandactivecommunity.Commercialsupportalsoavailable.
Moreresourcesavailableonhttp://uclinux.org/ports/
(Caution:lotsofbrokenhyperlinks!)

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

37

DisablingtheMMUonCPUswithMMU
Kernelconfigurationoption
AllowstodisabletheMMU
onsomeprocessorswith
anMMU
(example:Samsungones)
Notsupportedonx86
Checkbyyourselfonyour
ownplatform!

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

38

TheuClinuxdistdistribution
Notabinarydistribution,butatoolandsourcestobuildarootfilesystem.
Containsapplicationsources,patchedforcompliancewithuClinux.270
applicationsinuser/(includingBusyBox)and48librariesinlib/,plus
theuClibcsourcecode.
Alsoincludeskernelsourcesforasupported2.2,2.4and2.6kernel
versions(2.6.25uc0inuClinuxdist20080808).Thisincludes
codeforarchitecturesnotsupportedinthemainlinekernel
(example:nios2nommu).
Examplesize(uClinuxdist20080808):
Compressedarchive(.tar.bz2):281MB!
Expandedarchive:1.5GB!

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

39

uClinuxdistdownloads
uClinux.orgdistribution
http://uclinux.org/pub/uClinux/dist/
Forfasterdownloadtime,canalsouse
http://sourceforge.net/projects/uclinux/download
BestplacestofindapplicationsourcesforusewithuClinux,
evenifyoudon'tusethedistributions.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

40

uClinuxtoolchains
NeedtogetuClinuxspecifictoolchains
Toolchainlocationsaregivenon
http://uclinux.org/pub/uClinux/dist/
Regulartoolchain(compiledtosupportPICandXIP),
plusflatformatutilities:elf2fltandflthdr.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

41

Toolchaininstallationexample
Armexample
Downloadthearmtoolchainfrom
http://ftp.snapgear.org/pub/snapgear/tools/armlinux/
Extractthearchive
cd/
sudotarzxfarmlinuxtools20070808.tar.gz
Caution:thisoneinstallsbinaries
directlyin/usr/local/bin!
Caution:oldgcc3.xtoolchainsarenotrelocatable!
Theycannotbemovedtoanotherlocation
(unlessyoucreatelinksinthedefaultlocation)

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

42

CompilingtheuClinuxdistribution(1)
AddyouruClinuxcrosscompilingtoolchaintoyourPATH:
exportPATH=path/bin:$PATH
(notneededwithourtoolchainin/usr/local)
Installthegenromfstoolifyoudon'thaveit:
aptgetinstallgenromfs(Debian/Ubuntu)
InthetopleveluClinuxdistdirectory:
makexconfig
ormakemenuconfig

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

43

CompilingtheuClinuxdistribution(2)
Chooseyour
platform(vendorand
product).
Chooseyourkernel
andClibrary
version.
Customizeornot
kernelandtool
settings.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

44

CompilingtheuClinuxdistribution(3)
Otherinterfacespopsup
Configureyourkernel
(ifyouchosethisoption)
Configuretheuser
tools(ifyouchosethisoption)
Compile:
make
Thisgeneratesbinary
imagesforyourtarget
intheimages/directory.
IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

45

Addingyourcustomapplication(1)
TheeasiestwayistoaddyourapplicationtouClinuxdist
Helloworldexample:
Createauser/hellodirectoryinuClinuxdist
Createauser/hello/hello.cfile:
#include<stdio.h>
intmain(){
printf("Hello,world\n");
return0;
}

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

46

Addingyourownapplication(2)
Createuser/hello/Makefile:
EXEC=hello
#Stacksize(bytes)
FLTFLAGS+=s64
all:$(EXEC)
romfs:
$(ROMFSINST)/bin/$(EXEC)
clean:
rmf$(EXEC)*.elf*.gdb*.o

SeeotherMakefileexamplesintheuser/directory.
IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

47

Addingyourcustomapplication(3)
Declareyourapplicationsomewhereinuser/Kconfig:
(forexampleinMiscellaneousConfiguration)
configUSER_HELLO
bool"Helloworldprogram"
help
AsampleCprogram
Addthebelowlinetouser/hello/Makefile:
dir_$(CONFIG_USER_HELLO)+=hello
Runmakemenuconfigormakexconfigandenableyour
newapplication.
Runmaketocompileyourapplication
andaddittoyourfilesystemimage.
IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

48

Summary
WorthytouseuClinux(ratherthanaproprietaryRTOS)
onprocessorswithoutanMMU.Surprisingly,withuClinux,
thereareonlyminordifferenceswithwhatyoucandowithafull
Linuxkernel.
Insomecases,worthytouseuClinuxratherthanLinuxon
processorswithanMMU,forperformancereasons.
Thoughalotofworkhasalreadybeendoneandmost
applicationshavealreadybeenported,someuClinuxexperience
orlearningisdefinitelyneededwhenyoustartanewproject.

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

49

Resources
uClinux,StateOfTheNation,byGregUngerer(Apr.2007)
http://www.linuxdevices.com/files/article078/uclinuxsotn.pdf
uClinuxdevelopmentmailinglist
https://mailman.uclinux.org/mailman/listinfo/uclinuxdev
Archives:http://mailman.uclinux.org/pipermail/uclinuxdev/
http://ucdot.org/
Awealthofresources,FAQs,forumsforuClinuxdevelopers!
Don'tmisstheverycompleteFAQ:
http://www.ucdot.org/faq.pl

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

50

FreealternativestouClinux
eCos:http://en.wikipedia.org/wiki/ECos
Lightweightrealtimeembeddedsystem,
originallycontributedbyRedHat/Cygnussolutions.
FreeRTOS:http://en.wikipedia.org/wiki/FreeRTOS
AnotherfreeRTOS,gainingpopularityovereCos
inthelastyears.Apparently,eCosCentricseems
toputmorefocusontheirproprietaryextensions.
Bothalsosupport16bitprocessors
(notsupportedbyuClinuxandLinux)

IntroductiontouClinux
Copyright20042008,FreeElectrons
CreativeCommonsAttributionShareAlike2.5license
http://freeelectrons.com
Sep15,2009

51

Relateddocuments

Allourtechnicalpresentations
onhttp://freeelectrons.com/docs
Linuxkernel
Devicedrivers
Architecturespecifics
EmbeddedLinuxsystemdevelopment
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Howtohelp
Youcanhelpustoimproveandmaintainthisdocument...
Bysendingcorrections,suggestions,contributionsand
translations
Byaskingyourorganizationtoorderdevelopment,consulting
andtrainingservicesperformedbytheauthorsofthese
documents(seehttp://freeelectrons.com/).
Bysharingthisdocumentwithyourfriends,colleagues
andwiththelocalFreeSoftwarecommunity.
Byaddinglinksonyourwebsitetoouronlinematerials,
toincreasetheirvisibilityinsearchengineresults.

FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Linuxkernel
Linuxdevicedrivers
Boardsupportcode
Mainstreamingkernelcode
Kerneldebugging
EmbeddedLinuxTraining
Allmaterialsreleasedwithafreelicense!
UnixandGNU/Linuxbasics
Linuxkernelanddriversdevelopment
RealtimeLinux,uClinux
Developmentandprofilingtools
Lightweighttoolsforembeddedsystems
Rootfilesystemcreation
Audioandmultimedia
Systemoptimization

FreeElectrons
Ourservices
CustomDevelopment
Systemintegration
EmbeddedLinuxdemosandprototypes
Systemoptimization
Applicationandinterfacedevelopment
Consultingandtechnicalsupport
Helpindecisionmaking
Systemarchitecture
Systemdesignandperformancereview
Developmenttoolandapplicationsupport
Investigatingissuesandfixingtoolbugs

Anda mungkin juga menyukai