You are on page 1of 25

EmbeddedLinuxTraining

Building
embeddedLinux
systemswith
Buildroot
ThomasPetazzoni

1
Leveragingfreesoftware
Thousandsoffreesoftwarepackagesare
availableandcanbeleveragedtobuild
embeddedsystems
Withfreesoftware
Youhavecontroloverthesource
Bugscanbefixed
Newfeaturescanbeadded
Yoursystemcanbecustomized
Intheory,thesystemdesignersand
developershavealotofflexibilitythanksto
freesoftware
However,leveragingtheexistingfree
softwarepackagesmaynotbeveryeasy.
3
Usingadistribution

Distributionsprovidereadytousebinarypackages
Somedistributions,suchasDebian,areavailablefor
embeddedarchitectures(ARM,MIPS,PowerPC)
Theymakeitrelativelyeasytogetaworkingsystem,but
Themaintainerofeachpackagehasmadeconfiguration
choicesthatdon'tnecessarilymatchyourchoices(softfloat
vs.hardfloat,EABIvsOABI,featureAornotfeatureA)
Youdon'thavealotofcontrolonsystemintegration
(initializationscripts,dependenciesofthecomponents)
Ifyouwanttointegratefixesornewfeatures,youneedto
rebuildthepackages.Whilethismaynotbeverydifficult,
there'susuallynoautomatedinfrastructuretorebuildthe
wholesystem.

4
Manually

Youcanconfigure,compile,installandintegrateallthefree
softwarecomponentsneededtobuildaworkingLinux
systemmanually.
Itgivesyoufullflexibility,but
Youneedtoknowthedependenciesbetweenallthe
components
Crosscompilingisusuallyatediousprocess,sometimes
requiringpackagesourcecodechanges
Youdon'thaveanautomatedproceduretorebuildyour
system,whichmightbeneededifyouwanttointegrateabug
fixoranewfeature

5
Buildsystems
BuildsystemsallowanembeddedLinuxdevelopertogeneratea
workingembeddedLinuxsystemfromscratch.
Theyautomatetheprocessofdownloading,configuring,
compilingandinstallingallthefreesoftwarepackages
Youhaveawellknownprocedureforrebuildingyoursystemfrom
scratch
Youcaneasilyintegratepatches,bugfixesornewupstream
versions
Yourcolleaguescaneasilytakeoveryourwork,asthere'sa
documentedprocedureforsystemgeneration
Thebuildsystemalreadyknowsaboutmostfreesoftware
packages
Dependenciesaremanaged,andcrosscompilingissuesare
alreadysolved.
6
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
EnteringBuildroot

Buildroot<http://www.buildroot.net> isasetof
Makefilesthatautomatestheprocessofbuildingacross
compilingtoolchainandarootfilesystemforanembedded
system.
BuildroothasbeeninitiallydevelopedbyuClibcdevelopers.
Foralongtime,ithadnomaintainerandnoreleaseswere
delivered
SinceJanuary2009,Buildrootnowhasanofficial
maintainer,PeterKorsgaard
InFebruary2009,thefirststablereleasehasbeen
published,Buildroot2009.02.Anewreleasewillbe
publishedevery3months.
AnopportunitytotakeafreshlookatBuildroot!
7
Buildrootusers

TheyarealreadyusingBuildroot
ATMELfortheirAVR32developmentkit
http://www.atmel.no/buildroot/buildrootdoc.html
Gumstix
http://docwiki.gumstix.org/index.php/Buildroot
Armadeus(ARMboardswithFPGA)
http://www.armadeus.com
CalaoSystems
http://www.calaosystems.com/
Andprobablyalotmore!

8
Buildrootconfiguration

Buildrootuses
theKconfig
configuration
system
Offersa
menuconfiglike
interface
Savesthe
configurationina
.configfile

9
Mainconfiguration
Targetarchitecture
arm,armeb,avr32,cris,i386,mips,mipsel,powerpc,superh,
superh64,x86_64
Architecturevariant
ForARM,forexample:Generic,ARM7TDMI,ARM610,ARM710,
ARM720T,ARM920T,Xscale,etc.
ABIselection
ForARM,EABIorOABI
Targetoptions
Buildoptions
Hosttoolstouse,directorydefinition
Installdocumentation?Debuggingsymbols?Strip?Levelofgcc
optimization?
10
Toolchainconfiguration
Buildrootcaneitherbuildatoolchain(limitedto
uClibctoolchains)orreuseanexistingexternal
toolchain(limitedtosysrootabletoolchains)
InthecaseofatoolchainbuiltbyBuildroot,the
configurationallowstoselectthingssuchas
Kernelheadersversion
uClibcversionandconfiguration
GCCversionandoptions(Fortran?C++?
Java?ObjectiveC?)
GDBversionandoptions
(gdbserver,gdbonthetarget,crossgdbonthe
host)
Generaltoolchainoptions(largefilesupport,
RPCsupport,IPv6support,localesupport,etc.)
11
Packageselection(1/3)

Severalhundredsofpackagescanbeselected,withof
courseafocusonpackagesusefulforembeddeddevices
Dependenciesbetweenpackagesarehandled,either
throughdependson relationorselect relation.
Mainpackages:busybox,bash,bzip2,diffutils,flex,native
toolchain,grep,bootutils,cups,at,beecrypt,dash,file,
gamin,less,lsof,ltrace,memstat,moduleinittools,procps,
psmisc,screen,strace,sudo,syslogd,klogd,utillinux,
which,etc.
Corelibraries:libconfig,libconfuse,libdaemon,libelf,
libevent,libgcrypt,libiconv,libidn,liblockfile,liboil,libsysfs,
etc.

12
Packageselection(2/3)

Databases:MySQLclient,sqlite
Texteditors:ed,nano,uemacs,vim
Networking:argus,avahi,axel,boa,bind,bridgeutils,
DHCPsupport,dnsmasq,dropbear,ethtool,haserl,ifplugd,
iperf,iproute2,ipsectools,iptables,kismet,l2tp,lighttpd,
linkns,lrzsz,mDNSresponder,miidiag,mrouted,nbd,ncftp,
netcat,netkitbase,netkittelnet,netplug,netsnmp,nfsutils,
ntp,openntpd,openssh,openssl,openvpn,portmap,pppd,
pppoe,pptplinux,proftpd,quagga,isisd,samba,rsync,
stunnel,tcpdump,tftpd,thttpd,vsftpd,wirelesstools,etc.
Hardware/systemtools:dm,dmraid,e2fsprogs,fis,libfuse,
hal,hdparm,hotplug,i2ctools,inputtools,iostat,libaio,
libraw1394,libusb,lmsensors,lvm2,mdadm,mtdutils,
pciutils,setserial,udev,usbutils,etc.
13
Packageselection(3/3)
Audio/video:aumix,flac,gstreamerwithplugins,libmad,
libmpd,libogg,libtheora,libvorbis,madplay,mpg123,mplayer,
speex,vlc,festival
Graphiclibraries:ncurses,slang,dialog,DirectFB,
imagemagick,jpeg,libpng,libungif,pixman,SDL,QT
Embedded,Gtk(atk,cairo,pango,glib),fontconfig,Freetype,
Matchbox,X.orgKdriveandafewXapplications(window
managers,etc.)
Compressor/decompressors
Packagemanagers:ipkg,portage,rpm
Interpreters,languages:lua,microperl,python,ruby,tcl,php
Misc:XMLlibraries,Java,Games

14
Filesystemandkernelconfiguration

Outputformatselectionfortherootfilesystem
cramfs,cloop,ext2,jffs2,ubifs,squashfs,tar,cpio,initramfs,
romfs.
Ofcourse,therawrootfilesystemisalsoavailable
Bootloaderconfiguration
UBootsupported
Kernelconfiguration
Theversion,configuration,additionalpatchesandthekernel
binaryformat(uImage,zImage,bzImage)canbespecified

15
Demotime!

BuildingasystemwithBusybox,DirectFBand
exampleapplications

16
Directoryhierarchy
Inthesources
docs/ ,documentation
package/ ,theconfigurationitemsandMakefilesforbuildingthe
userspacepackages
project/ ,theconfigurationitemsandMakefilesfortheproject
concept(severalprojectsinthesameBuildroottree)
scripts/ variousutilities
target/linux/ ,buildingtheLinuxkernel
target/<fstype>/ ,generatingtherootfilesystemimage
target/device/ ,readymadeconfigurationforsupportedboards
target/generic/target_skeleton/ ,thedefaultroot
filesystemskeleton
toolchain/ ,buildingacrosscompilingtoolchain
17
UsingBuildrootinanutshell

Downloadthelateststableversion,orgetadevelopment
versionfromtheSVN(bettertoreportissues)
makemenuconfig
make
Getyourrawrootfilesystemin
project_build_ARCH/PROJECT/root/
Getyourrootfilesystemimageandkernelimagein
binaries/PROJECT/
Locationofoutputdirectoriescanbechangedusing
O=/path/to

18
Generateddirectories
build_ARCH
Onedirectoryforeachpackage,whereithasbeenconfigured
andbuilt
staging_dir ,wherethetoolchainandpackagesare
installed,andwherenonstrippedversionsofthe
binaries/librariescanbefound
project_build_ARCH/PROJECT
autotools_stamps ,stampsforhandlingdependencies
betweenbuildsteps
buildrootconfig ,headerfilesrelatedtoBuildroot
configurationmechanism
root ,therootfilesystemforthetarget
toolchain_build_ARCH
Wherethetoolchaincomponentsareconfiguredandbuilt
19
Buildroot:addingnewpackages
Createanewdirectory,forexamplepackage/gqview/
AddaConfig.in fileinthisdirectorytodescribethe
configurationoptions
configBR2_PACKAGE_GQVIEW
bool"gqview"
selectBR2_PACKAGE_PKGCONFIG
help
GQviewisanimageviewerforUnix
operatingsystems

http://prdownloads.sourceforge.net/gqview

InsertthenewConfig.in fileintheconfigurationsystem
byaddingtopackage/Config.in

source"package/gqview/Config.in"
20
Buildroot:addingnewpackages(2)

Createthegqview.mkfiletodescribethebuildsteps.The
followingexampleusestheMakefile.autotools.in
machinery,whichmakesiteasytosupportautotoolsbased
packages
GQVIEW_VERSION=2.1.5
GQVIEW_SOURCE=gqview$(GQVIEW_VERSION).tar.gz
GQVIEW_SITE=http://prdownloads.sourceforge.net/gqview
GQVIEW_AUTORECONF=NO
GQVIEW_INSTALL_STAGING=NO
GQVIEW_INSTALL_TARGET=YES
GQVIEW_DEPENDENCIES=uclibcpkgconfiglibgtk2
$(eval$(callAUTOTARGETS,package,gqview))

Patchescanalsobeaddedinthepackagedirectory,withfilenames
likepkgnameversionfeature.patch .Theywillbe
automaticallyappliedbeforeconfiguringthepackage.
21
Buildroot:addingnewpackages(3)
Packagesnotbasedonautotools,orneedingspecific
configuration,compilationandinstallationstepscanbe
handledmanually.
GZIP_VERSION:=1.3.12
GZIP_SOURCE:=gzip$(GZIP_VERSION).tar.gz
GZIP_SITE:=$(BR2_GNU_MIRROR)/gzip
GZIP_DIR:=$(BUILD_DIR)/gzip$(GZIP_VERSION)
GZIP_CAT:=$(ZCAT)
GZIP_BINARY:=$(GZIP_DIR)/gzip
GZIP_TARGET_BINARY:=$(TARGET_DIR)/bin/zmore

$(DL_DIR)/$(GZIP_SOURCE):
$(callDOWNLOAD,$(GZIP_SITE),$(GZIP_SOURCE))

gzipsource:$(DL_DIR)/$(GZIP_SOURCE)

$(GZIP_DIR)/.unpacked:$(DL_DIR)/$(GZIP_SOURCE)
$(GZIP_CAT)$(DL_DIR)/$(GZIP_SOURCE)|\
tarC$(BUILD_DIR)$(TAR_OPTIONS)
touch$(GZIP_DIR)/.unpacked
22
Buildroot:addingnewpackages(4)

$(GZIP_DIR)/.configured:$(GZIP_DIR)/.unpacked
(cd$(GZIP_DIR);rmrfconfig.cache;\
$(TARGET_CONFIGURE_OPTS)\
$(TARGET_CONFIGURE_ARGS)\
./configure\
target=$(GNU_TARGET_NAME)\
host=$(GNU_TARGET_NAME)\
build=$(GNU_HOST_NAME)\
prefix=/usr\
execprefix=/\
$(DISABLE_NLS)\
$(DISABLE_LARGEFILE)\
)
touch$(GZIP_DIR)/.configured

$(GZIP_BINARY):$(GZIP_DIR)/.configured
$(MAKE)CC=$(TARGET_CC)C$(GZIP_DIR)

23
Buildroot:addingnewpackages(5)

$(GZIP_TARGET_BINARY):$(GZIP_BINARY)
$(MAKE)DESTDIR=$(TARGET_DIR)CC=$(TARGET_CC)\
C$(GZIP_DIR)installstrip
ifneq($(BR2_HAVE_INFOPAGES),y)
rmrf$(TARGET_DIR)/usr/share/info
endif
ifneq($(BR2_HAVE_MANPAGES),y)
rmrf$(TARGET_DIR)/usr/share/man
endif

gzip:uclibc$(GZIP_TARGET_BINARY)
gzipclean:
$(MAKE)DESTDIR=$(TARGET_DIR)CC=$(TARGET_CC)\
C$(GZIP_DIR)uninstall
$(MAKE)C$(GZIP_DIR)clean
gzipdirclean:
rmrf$(GZIP_DIR)

ifeq($(BR2_PACKAGE_GZIP),y)
TARGETS+=gzip
endif
24
Futurework

Cleanup
Theprojecthasbeenunmaintainedforsometime,sosome
cleanupisneeded
Morepackages
Ofcourse!
Bettersupportforexternaltoolchains
Includingglibctoolchains
$YOURIDEA

25
Feedbackandcommunity

Buildrootisorganizedlikeatypicalfreesoftwarecommunity,
itisnottrustedbyanycompany,eventhoughsomeofthe
developersareobviouslyprofessionals
Mailinglist,athttp://lists.busybox.net/mailman/listinfo/buildroot
Veryhelpfulsupport!
Bugtrackerathttps://bugs.uclibc.org/
Subversionrepositoryatsvn://uclibc.org/trunk/buildroot
Documentationathttp://www.buildroot.net/buildroot.html
Feelfreetotest,reportandcontribute!

26

You might also like