Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

TheUbootbootloader

TheUboot bootloader
MichaelOpdenacker ThomasPetazzoni FreeElectrons

Copyright20042009,FreeElectrons. CreativeCommonsBYSA3.0license Latestupdate:Jan19,2011, Documentsources,updatesandtranslations: http://freeelectrons.com/docs/uboot Corrections,suggestions,contributionsandtranslationsarewelcome!

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

UBoot
UBootisatypicalfreesoftwareproject Freelyavailableathttp://www.denx.de/wiki/UBoot Documentationavailableat http://www.denx.de/wiki/UBoot/Documentation ThelatestdevelopmentsourcecodeisavailableinaGit repository: http://git.denx.de/cgibin/gitweb.cgi?p=uboot.git;a=summary Developmentanddiscussionshappenaroundanopenmailing listhttp://lists.denx.de/pipermail/uboot/ Sincetheendof2008,itfollowsafixedintervalreleaseschedule. Everytwomonths,anewversionisreleased.Versionsare namedYYYY.MM.
2
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

CompilingUBoot(1)
Getthesourcecodefromthewebsite,anduncompressit Theinclude/configs/directorycontainsoneconfiguration fileforeachsupportedboard
ItdefinestheCPUtype,theperipheralsandtheirconfiguration,the memorymapping,theUBootfeaturesthatshouldbecompiledin, etc. Itisasimple.hfilethatsetspreprocessorconstants.Seethe READMEfileforthedocumentationoftheseconstants.

AssumingthatyourboardisalreadysupportedbyUBoot,there shouldbeonefilecorrespondingtoyourboard,forexample include/configs/omap2420h4.h.

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

CompilingUBoot(2)

UBootmustbeconfiguredbeforebeingcompiled
makeBOARDNAME_config WhereBOARDNAMEisthenameoftheconfigurationfilein include/configs/,withoutthe.h

MakesurethatthecrosscompilerisavailableinPATH
exportPATH=/usr/local/uclibc0.9.292/arm/bin/:$PATH

CompileUBoot,byspecifyingthecrosscompilerprefix. Example,ifyourcrosscompilerexecutableisarmlinuxgcc: makeCROSS_COMPILE=armlinux

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

InstallingUBoot
UBootmustusuallybeinstalledinflashmemorytobeexecuted bythehardware.Dependingonthehardware,theinstallationof UBootisdoneinadifferentway:
Theboardprovidessomekindofspecificbootmonitor,which allowstoflashthesecondstagebootloader.Inthiscase,referto theboarddocumentationandtools UBootisalreadyinstalled,andcanbeusedtoflashanewversion ofUBoot.However,becareful:ifthenewversionofUBootdoesn't work,theboardisunusable TheboardprovidesaJTAGinterface,whichallowstowritetothe flashmemoryremotely,withoutanysystemrunningontheboard.It alsoallowstorescueaboardifthebootloaderdoesn'twork.

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

Ubootprompt
Connectthetargettothehostthroughaserialconsole Poweruptheboard.Ontheserialconsole,youwillsee somethinglike: UBoot1.1.2(Aug3200417:31:20) RAMConfiguration: Bank#0:000000008MB Flash:2MB In:serial Out:serial Err:serial uboot# TheUBootshelloffersasetofcommands.Wewillstudy themostimportantones,seethedocumentationfora completereferenceorthehelpcommand.
6
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Informationcommands
UBoot>flinfo DataFlash:AT45DB021 Nbpages:1024 PageSize:264 Size=270336bytes Logicaladdress:0xC0000000 Area0:C0000000toC0001FFF(RO)Bootstrap Area1:C0002000toC0003FFFEnvironment Area2:C0004000toC0041FFF(RO)UBoot UBoot>nandinfo Device0:NAND256MiB3,3V8bit,sectorsize128KiB UBoot>version UBoot2009.08(Nov15200914:48:35)

Flash information

NANDflash information UBoot information

Canvaryfromoneboardtotheother (accordingtotheUBootcompileconfiguration)
7
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Environmentvariables(1)
UBootcanbeconfiguredthroughenvironmentvariables,which affectthebehaviorofthedifferentcommands. Seethedocumentationforthecompletelistofenvironment variables. Theprintenvcommandalsotodisplayallvariablesorone:
uboot#printenv baudrate=19200 ethaddr=00:40:95:36:35:33 netmask=255.255.255.0 ipaddr=10.0.0.11 serverip=10.0.0.1 stdin=serial stdout=serial stderr=serial uboot#printenvserverip serverip=10.0.0.2

Networkconfiguration

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

Environmentvariables(2)
Thevalueoftheenvironmentvariablescanbechangedusing thesetenvcommand: uboot#setenvserverip10.0.0.2 Environmentvariablechangescanbestoredtoflashusingthe saveenvcommand.Thelocationinflashisdefinedatcompile timeintheUBootconfigurationfile. Youcanevencreatesmallscriptsstoredinenvironment variables: setenvmmcboot'mmcinit0;iffatloadmmc0 80000000boot.ini;thensource;elseif fatloadmmc080000000uImage;thenrunmmc bootargs;bootm;fi;fi' Youcanthenexecutethescript: runmmcboot
9
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com

Transferringfilestothetarget
UBootismostlyusedtoloadandbootakernelimage,butitalso allowstochangethekernelimageandtherootfilesystemstored inflash. Filesmustbeexchangedbetweenthetargetandthe developmentworkstation.Thisispossible:
ThroughthenetworkifthetargethasanEthernetconnection,and UBootcontainsadriverfortheEthernetchip.Ifso,theTFTP protocolcanbeusedtoexchangefiles ThroughtheseriallineifnoEthernetconnectionisavailable.

Target UBootTFTP client Ethernetconnection

Host TFTP server


10

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

Configuringandtestingtftp
OnGNU/LinuxsystemsbasedonDebian:Ubuntu,Knoppix Installthetftpdhpapackage(tftpserver): aptgetinstalltftpdhpa Copyfilestotherootdirectoryofthetftpserver.Example: cparch/arm/boot/uImage/var/lib/tftpboot Totesttheserver,installatftpclientonyourworkstation: aptgetinstalltftphpa Useittodownloadafile(4toforcetheuseofIPv4) tftp4localhost >getuImage

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

Ubootmkimage
ThekernelimagethatUBootloadsandbootsmustbeprepared, sothatanUBootspecificheaderisaddedinfrontoftheimage ThisisdonewithatoolthatcomesinUBoot,mkimage Debian/Ubuntu:justinstalltheubootmkimagepackage. Or,compileitbyyourself:simplyconfigureUBootforanyboard ofanyarchitectureandcompileit.Theninstallmkimage: cptools/mkimage/usr/local/bin/ ThespecialtargetuImageofthekernelMakefilecanthenbe usedtogenerateakernelimagesuitableforUBoot.

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

Flashingakernelimage
CompileyourkernelandgeneratetheUBootheader runningmakeuImage CopythekernelimagetothedirectoryexportedbytheTFTPserver Ontheboard,inUBoot,downloadthekernelimagetomemory: uboot#tftp8000uImage UnprotectNORflash uboot#protectoff1:04 EraseNORflash uboot#erase1:04 CopytoNORflash(0x01000000:firstsector) uboot#cp.b${fileaddr}1000000${filesize} RestoreNORflashsectorprotection: uboot#protecton1:04 SeeourpracticallabsfordetailshandlingNANDflash.
13

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

bootcommands
Specifykernelbootparameters: uboot#setenvbootargsmem=64M\ console=ttyS0,115200init=/sbin/init\ root=/dev/mtdblock0 Executethekernelfromagivenphysicaladdress (RAMorflash): bootm0x01030000
Continueson thesameline

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

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

You might also like