0% found this document useful (0 votes)
372 views15 pages

Booting ARM Linux PDF

This document defines in clear concise terms, with implementation guidance and examples, the requirements and procedures for a bootloader to start an ARM Linux kernel. It should be noted that provided the guidance in this document is followed, there should be no need for an implementor to understand every nuance of the assembler that starts the kernel.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
372 views15 pages

Booting ARM Linux PDF

This document defines in clear concise terms, with implementation guidance and examples, the requirements and procedures for a bootloader to start an ARM Linux kernel. It should be noted that provided the guidance in this document is followed, there should be no need for an implementor to understand every nuance of the assembler that starts the kernel.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

01/02/2016

BootingARMLinux

BootingARMLinux
VincentSanders
<vince@[Link]>

Reviewandadvice,largechunksoftheARMLinuxkernel,allaroundgoodguy:RussellKing
Review,adviceandnumerousclarifications.:NicolasPitre
Reviewandadvice:ErikMouw,ZwaneMwaikambo,JeffSutherland,RalphSiemsen,DanielSilverstone,Martin
Michlmayr,MichaelStevens,LesleyMitchell,MatthewRichardson
Reviewandreferencedinformation(seebibliography):Wookey
Copyright2004VincentSanders
ThisdocumentisreleasedunderaGPLlicence.
Alltrademarksareacknowledged.
Whileeveryprecautionhasbeentakeninthepreparationofthisarticle,thepublisherassumesnoresponsibilityfor
errorsoromissions,orfordamagesresultingfromtheuseoftheinformationcontainedherein.
20040604
RevisionHistory
Revision1.00
InitialRelease.

10thMay2004

VRS

Revision1.10

4thJune2004

VRS

Updateexamplecodetobemorecomplete.
Improvewordinginplaces,changessuggestedbyNicolasPitre.
UpdateSection2,Otherbootloaders.
Updateacknowledgements.

TableofContents
[Link]
[Link]
[Link]
[Link]'smemory
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Bibliography
Abstract
Thisdocumentdefinesinclearconciseterms,withimplementationguidanceandexamples,therequirementsand
proceduresforabootloadertostartanARMLinuxkernel.

[Link]
[Link]

1/15

01/02/2016

BootingARMLinux

Thisdocumentdescribesthe"new"[Link]
"struct"methodmustnotbeused.
Thisdocumentcontainsinformationfromawidevarietyofsources(seetheBibliography)andauthors,youare
encouragedtoconsultthesesourcesformoreinformationbeforeaskingquestionsoftheMaintainers,oronthe
[Link]
ignoredifyouhaven'tdoneatleastbasicresearch.
Additionallyitshouldbenotedthatprovidedtheguidanceinthisdocumentisfollowed,thereshouldbenoneedfor
[Link]
numerousoccasionsthatmostbootingproblemsareunlikelytoberelatedtothiscode,saidcodeisalsoquitetricky
andunlikelytogiveanyinsightintotheproblem.

[Link]
Beforeembarkingonwritinganewbootloaderadevelopershouldconsiderifoneoftheexistingloadersis
[Link],fromsimpleGPLloaderstofullblowncommercial
[Link].
[Link]
Name

URL

Description

Blob
Bootldr
Redboot
UBoot
ABLE

Blobbootloader
Bootldr
Redboot
UBoot
ABLEbootloader

GPLbootloaderforSA11x0(StrongARM)platforms.
BothGPLandnonGPLversionsavailable,mainlyusedforhandhelddevices.
RedhatloaderreleasedundertheireCoslicence.
GPLuniversalbootloader,providessupportforseveralCPUs.
Commercialbootloaderwithcomprehensivefeatureset

[Link]
ARMLinuxcannotbestartedonamachinewithoutasmallamountofmachinespecificcodetoinitialisethe
[Link],althoughseveralbootloadersdoprovide
[Link]:
Configurethememorysystem.
Loadthekernelimageatthecorrectmemoryaddress.
OptionallyloadaninitialRAMdiskatthecorrectmemoryaddress.
Initialisethebootparameterstopasstothekernel.
ObtaintheARMLinuxmachinetype
Enterthekernelwiththeappropriateregistervalues.
Itisusuallyexpectedthatthebootloaderwillinitialiseaserialorvideoconsoleforthekernelinadditiontothese
[Link].
Eachofthesestepswillbeexaminedinthefollowingsections.

[Link]'smemory
ThebootloaderisexpectedtofindandinitialiseallRAMthatthekernelwilluseforvolatiledatastorageinthe
[Link]
sizeallRAM,oritmayuseknowledgeoftheRAMinthemachine,oranyothermethodthebootloaderdesigner
seesfit.
[Link]
[Link]
machine_fixup()[Link]
[Link]

2/15

01/02/2016

BootingARMLinux

betweenthebootloadersresponsibilityandthekernelinthisarea.
ThephysicalmemorylayoutispassedtothekernelusingtheATAG_MEMparameter.Memorydoesnot
necessarilyhavetobecompletelycontiguous,[Link]
ATAG_MEMblocksallowforseveralmemoryregions.Thekernelwillcoalesceblockspassedtoitiftheyare
contiguousphysicalregions.
Thebootloadermayalsomanipulatethememorywiththekernelscommandline,usingthe'mem='parameter,the
optionsforthisparameterarefullydocumentedinlinux/Documentation/[Link]
Thekernelcommandline'mem='hasthesyntaxmem=<size>[KM][,@<phys_offset>]whichallowsthesizeand
[Link]
memoryblocksatdifferingoffsetsbyprovidingthemem=parametermultipletimes.

[Link]
Kernelimagesgeneratedbythekernelbuildprocessareeitheruncompressed"Image"filesorcompressedzImage
files.
TheuncompressedImagefilesaregenerallynotused,astheydonotcontainareadilyidentifiablemagicnumber.
ThecompressedzImageformatisalmostuniversallyusedinpreference.
[Link],thedecompressionoftheimageis
[Link],asanyerrorswillresultin
[Link],whichallowsforbetterresultsthan
agenericexternalcompressionmethod.
ThezImagehasamagicnumberandsomeusefulinformationnearitsbeginning.
[Link]
OffsetintozImage
Value
Description
0x24
0x016F2818 MagicnumberusedtoidentifythisisanARMLinuxzImage
0x28
startaddress TheaddressthezImagestartsat
0x2C
endaddress TheaddressthezImageendsat
Thestartandendoffsetscanbeusedtodeterminethelengthofthecompressedimage(size=endstart).Thisis
[Link]
aninitialRAMdisk(initrd).Thestartaddressisusually0asthezImagecodeispositionindependent.
ThezImagecodeisPositionIndependentCode(PIC)somaybeloadedanywherewithintheavailableaddress
[Link]
initrdifabootpImagetargetwasused.

Note
AlthoughthezImagemaybelocatedanywhere,[Link]
[Link].
[Link]
kerneldetectssuchaconflictitwilluncompresstheimageimmediatelyafterthecompressedzImage
[Link]
regionthezImageisloadedintomusthaveupto4Megabytesofspaceafterit(themaximum
uncompressedkernelsize),i.e.placingthezImageinthesame4MegabytebankasitsZRELADDR
wouldprobablynotworkasexpected.
DespitetheabilitytoplacezImageanywherewithinmemory,conventionhasitthatitisloadedatthebaseof
physicalRAMplusanoffsetof0x8000(32K).Thisleavesspacefortheparameterblockusuallyplacedatoffset
0x100,[Link].
[Link]

3/15

01/02/2016

BootingARMLinux

[Link]
[Link]
[Link]
linux/Documentation/[Link]

[Link]
[Link]
thatitneedsnobootloaderintervention,butrequiresthekernelbuildprocesstohaveknowledgeofthephysical
addresstoplacetheramdisk(usingtheINITRD_PHYSdefinition).Thehardsizelimitfortheuncompressedkernel
[Link].
Thesecondandmuchmorewidelyusedmethodisforthebootloadertoplaceagiveninitialramdiskimage,
obtainedfromwhatevermedia,[Link]
ATAG_INITRD2andATAG_RAMDISK.
[Link]
[Link]
+decompressedzImage+initrd+[Link]
[Link]:
Itmustliecompletelywithinasinglememoryregion(mustnotcrossbetweenareasdefinedbydifferent
ATAG_MEMparameters)
Itmustbealignedtoapageboundary(typically4k)
ItmustnotconflictwiththememorythezImageheadcodeusestodecompressthekerneloritwillbeoverwritten
asnocheckingisperformed.

[Link]
Aconsoleishighlyrecommendedasamethodtoseewhatactionsthekernelisperformingwheninitialisinga
[Link],themostcommoncasesareavideoframebuffer
[Link].
[Link]
managementetc.,[Link]
shoulduseforthekernelconsole(generallyusedfordebuggingpurposes,orcommunicationwiththetarget.)
Asanalternative,thebootloadercanpasstherelevant'console='optiontothekernel,viathecommandline
parameterspecifyingtheport,andserialformatoptionsasdescribedinlinux/Documentation/kernel
[Link]

[Link]
Thebootloadermustpassparameterstothekerneltodescribethesetupithasperformed,thesizeandshapeof
memoryinthesystemand,optionally,numerousothervalues.
Thetaggedlistshouldconformtothefollowingconstraints
ThelistmustbestoredinRAMandplacedinaregionofmemorywhereneitherthekerneldecompressernorinitrd
manipulationwilloverwriteit.Therecommendedplacementisinthefirst16KiBofRAM,usuallythestartof
physicalRAMplus0x100(whichavoidszeropageexceptionvectors).
ThephysicaladdressofthetaggedlistmustbeplacedinR2onentrytothekernel,howeverhistoricallythishasnot
[Link]
relieduponinthefuture.
Thelistmustnotextendpastthe0x4000boundarywherethekernel'[Link]
kernelperformsnoboundscheckingandwilloverwritetheparameterlistifitdoesso.
Thelistmustbealignedtoaword(32bit,4byte)boundary(ifnotusingtherecommendedlocation)
ThelistmustbeginwithanATAG_COREandendwithATAG_NONE
ThelistmustcontainatleastoneATAG_MEM
[Link]

4/15

01/02/2016

BootingARMLinux

Eachtaginthelistconsistsofaheadercontainingtwounsigned32bitvalues,thesizeofthetag(in32bit,4byte
words)andthetagvalue
structatag_header{
u32size;/*legthoftaginwordsincludingthisheader*/
u32tag;/*tagvalue*/
};

Eachtagheaderisfollowedbydataassociatedwiththattag,exceptingATAG_NONEwhichhasnodataand
ATAG_COREwherethedataisoptional.Thesizeofthedataisdeterminedbythesizefieldinheader,the
minimumsizeis2astheheaderssizeisincludedinthisvalue.TheATAG_NONEisuniqueinthatitssizefieldis
settozero.
Atagmaycontainadditionaldataafterthemandatedstructuresprovidedthesizeisadjustedtocovertheextra
information,[Link]
exampleabootloadermayprovideadditionalserialnumberinformationinanATAG_SERIALwhichcouldthembe
interpretedbyamodifiedkernel.
Theorderofthetagsintheparameterlistisunimportant,theymayappearasmanytimesasrequiredalthough
interpretationofduplicatetagsistagdependant.
ThedataforeachindividualtagisdescribedintheAppendixA,TagReferencesection.
[Link]
Tagname
ATAG_NONE

Value
0x00000000 2

Size

ATAG_CORE

0x54410001 5(2ifempty)

Description
Emptytagusedtoendlist
Firsttagusedtostartlist

ATAG_MEM
0x54410002 4
ATAG_VIDEOTEXT 0x54410003 5

Describesaphysicalareaofmemory
DescribesaVGAtextdisplay

ATAG_RAMDISK

0x54410004 5

ATAG_INITRD2

0x54420005 4

Describeshowtheramdiskwillbeusedinkernel
Describeswherethecompressedramdiskimageis
placedinmemory

ATAG_SERIAL
ATAG_REVISION

0x54410006 4
0x54410007 3

ATAG_VIDEOLFB

0x54410008 8
Initialvaluesforvesafbtypeframebuffers
2+((length_of_cmdline
0x54410009
Commandlinetopasstokernel
+3)/4)

ATAG_CMDLINE

64bitboardserialnumber
32bitboardrevisionnumber

Forimplementationpurposesastructurecanbedefinedforatag
structatag{
structatag_headerhdr;
union{
structatag_corecore;
structatag_memmem;
structatag_videotextvideotext;
structatag_ramdiskramdisk;
structatag_initrd2initrd2;
structatag_serialnrserialnr;
structatag_revisionrevision;
structatag_videolfbvideolfb;
structatag_cmdlinecmdline;
}u;
};

Oncethesestructureshavebeendefinedanimplementationneedstocreatethelistthiscanbeimplementedwith
codesimilarto
#definetag_next(t)((structtag*)((u32*)(t)+(t)>[Link]))
[Link]

5/15

01/02/2016

BootingARMLinux

#definetag_size(type)((sizeof(structtag_header)+sizeof(structtype))>>2)
staticstructatag*params;/*usedtopointatthecurrenttag*/
staticvoid
setup_core_tag(void*address,longpagesize)
{
params=(structtag*)address;/*Initialiseparameterstostartatgivenaddress*/
params>[Link]=ATAG_CORE;/*startwiththecoretag*/
params>[Link]=tag_size(atag_core);/*sizethetag*/
params>[Link]=1;/*ensurereadonly*/
params>[Link]=pagesize;/*systemspagesize(4k)*/
params>[Link]=0;/*zerorootdevice(typicalyoveriddenfromcommandline)*/
params=tag_next(params);/*movepointertonexttag*/
}
staticvoid
setup_mem_tag(u32_tstart,u32_tlen)
{
params>[Link]=ATAG_MEM;/*Memorytag*/
params>[Link]=tag_size(atag_mem);/*sizetag*/
params>[Link]=start;/*Startofmemoryarea(physicaladdress)*/
params>[Link]=len;/*Lengthofarea*/
params=tag_next(params);/*movepointertonexttag*/
}
staticvoid
setup_end_tag(void)
{
params>[Link]=ATAG_NONE;/*Emptytagendslist*/
params>[Link]=0;/*zerolength*/
}
staticvoid
setup_tags(void)
{
setup_core_tag(0x100,4096);/*standardcoretag4kpagesize*/
setup_mem_tag(0x10000000,0x400000);/*64Mbat0x10000000*/
setup_mem_tag(0x18000000,0x400000);/*64Mbat0x18000000*/
setup_end_tag(void);/*endoftags*/
}

Whilethiscodefragmentiscompleteitillustratestheabsoluteminimalrequirementsforaparametersetandis
[Link]
additionalvaluesandwouldprobablyprobeforthememoryactuallyinasystemratherthanusingfixedvalues.A
morecompleteexamplecanbefoundinAppendixB,Completeexample

[Link]
Theonlyadditionalinformationthebootloaderneedstoprovideisthemachinetype,thisisasimplenumberunique
foreachARMsystemoftenreferredtoasaMACH_TYPE.
[Link]
obtainedasearlyinaprojectslifeaspossible,ithasanumberoframificationsforthekernelportitself(machine
definitionsetc.)[Link]
representedbyalistofdefineswithinthekernelsource(linux/arch/arm/tools/machtypes)
[Link]
[Link]
scopeofthisdocument.

[Link]
[Link]

6/15

01/02/2016

BootingARMLinux

Oncethebootloaderhasperformedalltheotherstepsitmuststartexecutionofthekernelwiththecorrectvaluesin
theCPUregisters.
Theentryrequirementsare:
TheCPUmustbeinSVC(supervisor)modewithbothIRQandFIQinterruptsdisabled.
TheMMUmustbeoff,[Link].
Datacachemustbeoff
Instructioncachemaybeeitheronoroff
CPUregister0mustbe0
CPUregister1mustbetheARMLinuxmachinetype
CPUregister2mustbethephysicaladdressoftheparameterlist
Thebootloaderisexpectedtocallthekernelimagebyjumpingdirectlytothefirstinstructionofthekernelimage.

[Link]
ATAG_CORE
ATAG_COREStarttagusedtobeginlist

Value
0x54410001

Size
5(2ifnodata)

Structuremembers
structatag_core{
u32flags;/*bit0=readonly*/
u32pagesize;/*systemspagesize(usually4k)*/
u32rootdev;/*rootdevicenumber*/
};

Description
Thistagmustbeusedtostartthelist,itcontainsthebasicinformationanybootloadermustpass,ataglengthof2
indicatesthetaghasnostructureattached.

ATAG_NONE
ATAG_NONEEmptytagusedtoendlist

Value
0x00000000

Size
2
[Link]

7/15

01/02/2016

BootingARMLinux

Structuremembers
None

Description
Thistagisusedtoindicatethelistend.Itisuniqueinthatitssizefieldintheheadershouldbesetto0(not2).

ATAG_MEM
ATAG_MEMTagusedtodescribeaphysicalareaofmemory.

Value
0x54410002

Size
4

Structuremembers
structatag_mem{
u32size;/*sizeofthearea*/
u32start;/*physicalstartaddress*/
};

Description
Describesanareaofphysicalmemorythekernelistouse.

ATAG_VIDEOTEXT
ATAG_VIDEOTEXTTagusedtodescribeVGAtexttypedisplays

Value
0x54410003

Size
5

Structuremembers
structatag_videotext{
u8x;/*widthofdisplay*/
u8y;/*heightofdisplay*/
u16video_page;
u8video_mode;
u8video_cols;
u16video_ega_bx;
u8video_lines;
[Link]

8/15

01/02/2016

BootingARMLinux

u8video_isvga;
u16video_points;
};

Description
ATAG_RAMDISK
ATAG_RAMDISKTagdescribinghowtheramdiskwillbeusedbythekernel

Value
0x54410004

Size
5

Structuremembers
structatag_ramdisk{
u32flags;/*bit0=load,bit1=prompt*/
u32size;/*decompressedramdisksizein_kilo_bytes*/
u32start;/*startingblockoffloppybasedRAMdiskimage*/
};

Description
Describeshowthe(initial)ramdiskwillbeconfiguredbythekernel,specificallythisallowsforthebootloaderto
ensuretheramdiskwillbelargeenoughtotakethedecompressedinitialramdiskimagethebootloaderispassing
usingATAG_INITRD2.

ATAG_INITRD2
ATAG_INITRD2Tagdescribingthephysicallocationofthecompressedramdiskimage

Value
0x54420005

Size
4

Structuremembers
structatag_initrd2{
u32start;/*physicalstartaddress*/
u32size;/*sizeofcompressedramdiskimageinbytes*/
};

Description
[Link]

9/15

01/02/2016

BootingARMLinux

Locationofacompressedramdiskimage,usuallycombinedwithanATAG_RAMDISK.Canbeusedasaninitial
rootfilesystemwiththeadditionofacommandlineparameterof'root=/dev/ram'.Thistagsupersedestheoriginal
ATAG_INITRDwhichusedvirtualaddressing,[Link]
bootloadersshouldusethistaginpreference.

ATAG_SERIAL
ATAG_SERIALTagwith64bitserialnumberoftheboard

Value
0x54410006

Size
4

Structuremembers
structatag_serialnr{
u32low;
u32high;
};

Description
ATAG_REVISION
ATAG_REVISIONTagfortheboardrevision

Value
0x54410007

Size
3

Structuremembers
structatag_revision{
u32rev;
};

Description
ATAG_VIDEOLFB
ATAG_VIDEOLFBTagdescribingparametersforaframebuffertypedisplay

[Link]

10/15

01/02/2016

BootingARMLinux

Value
0x54410008

Size
8

Structuremembers
structatag_videolfb{
u16lfb_width;
u16lfb_height;
u16lfb_depth;
u16lfb_linelength;
u32lfb_base;
u32lfb_size;
u8red_size;
u8red_pos;
u8green_size;
u8green_pos;
u8blue_size;
u8blue_pos;
u8rsvd_size;
u8rsvd_pos;
};

Description
ATAG_CMDLINE
ATAG_CMDLINETagusedtopassthecommandlinetothekernel

Value
0x54410009

Size
2+((length_of_cmdline+3)/4)

Structuremembers
structatag_cmdline{
charcmdline[1];/*thisistheminimumsize*/
};

Description
[Link]
length_of_cmdlinevariableshouldincludetheterminator.

[Link]
Thisisaworkedexampleofasimplebootloaderandshowsalltheinformationexplainedthroughoutthisdocument.
Morecodewouldberequiredforarealbootloaderthisexampleispurelyillustrative.
[Link]

11/15

01/02/2016

BootingARMLinux

ThecodeinthisexampleisdistributedunderaBSDlicence,itmaybefreelycopiedandusedifnecessary.
/*example.c
*exampleARMLinuxbootloadercode
*thisexampleisdistributedundertheBSDlicence
*/
/*listofpossibletags*/
#defineATAG_NONE0x00000000
#defineATAG_CORE0x54410001
#defineATAG_MEM0x54410002
#defineATAG_VIDEOTEXT0x54410003
#defineATAG_RAMDISK0x54410004
#defineATAG_INITRD20x54420005
#defineATAG_SERIAL0x54410006
#defineATAG_REVISION0x54410007
#defineATAG_VIDEOLFB0x54410008
#defineATAG_CMDLINE0x54410009
/*structuresforeachatag*/
structatag_header{
u32size;/*lengthoftaginwordsincludingthisheader*/
u32tag;/*tagtype*/
};
structatag_core{
u32flags;
u32pagesize;
u32rootdev;
};
structatag_mem{
u32size;
u32start;
};
structatag_videotext{
u8x;
u8y;
u16video_page;
u8video_mode;
u8video_cols;
u16video_ega_bx;
u8video_lines;
u8video_isvga;
u16video_points;
};
structatag_ramdisk{
u32flags;
u32size;
u32start;
};
structatag_initrd2{
u32start;
u32size;
};
structatag_serialnr{
u32low;
u32high;
};
structatag_revision{
u32rev;
};
structatag_videolfb{
u16lfb_width;
u16lfb_height;
u16lfb_depth;
u16lfb_linelength;
[Link]

12/15

01/02/2016

BootingARMLinux

u32lfb_base;
u32lfb_size;
u8red_size;
u8red_pos;
u8green_size;
u8green_pos;
u8blue_size;
u8blue_pos;
u8rsvd_size;
u8rsvd_pos;
};
structatag_cmdline{
charcmdline[1];
};
structatag{
structatag_headerhdr;
union{
structatag_corecore;
structatag_memmem;
structatag_videotextvideotext;
structatag_ramdiskramdisk;
structatag_initrd2initrd2;
structatag_serialnrserialnr;
structatag_revisionrevision;
structatag_videolfbvideolfb;
structatag_cmdlinecmdline;
}u;
};
#definetag_next(t)((structtag*)((u32*)(t)+(t)>[Link]))
#definetag_size(type)((sizeof(structtag_header)+sizeof(structtype))>>2)
staticstructatag*params;/*usedtopointatthecurrenttag*/
staticvoid
setup_core_tag(void*address,longpagesize)
{
params=(structtag*)address;/*Initialiseparameterstostartatgivenaddress*/
params>[Link]=ATAG_CORE;/*startwiththecoretag*/
params>[Link]=tag_size(atag_core);/*sizethetag*/
params>[Link]=1;/*ensurereadonly*/
params>[Link]=pagesize;/*systemspagesize(4k)*/
params>[Link]=0;/*zerorootdevice(typicalyoveriddenfromcommandline)*/
params=tag_next(params);/*movepointertonexttag*/
}
staticvoid
setup_ramdisk_tag(u32_tsize)
{
params>[Link]=ATAG_RAMDISK;/*Ramdisktag*/
params>[Link]=tag_size(atag_ramdisk);/*sizetag*/
params>[Link]=0;/*Loadtheramdisk*/
params>[Link]=size;/*Decompressedramdisksize*/
params>[Link]=0;/*Unused*/
params=tag_next(params);/*movepointertonexttag*/
}
staticvoid
setup_initrd2_tag(u32_tstart,u32_tsize)
{
params>[Link]=ATAG_INITRD2;/*Initrd2tag*/
params>[Link]=tag_size(atag_initrd2);/*sizetag*/
params>[Link]=start;/*physicalstart*/
params>[Link]=size;/*compressedramdisksize*/
params=tag_next(params);/*movepointertonexttag*/
[Link]

13/15

01/02/2016

BootingARMLinux

}
staticvoid
setup_mem_tag(u32_tstart,u32_tlen)
{
params>[Link]=ATAG_MEM;/*Memorytag*/
params>[Link]=tag_size(atag_mem);/*sizetag*/
params>[Link]=start;/*Startofmemoryarea(physicaladdress)*/
params>[Link]=len;/*Lengthofarea*/
params=tag_next(params);/*movepointertonexttag*/
}
staticvoid
setup_cmdline_tag(constchar*line)
{
intlinelen=strlen(line);
if(!linelen)
return;/*donotinsertatagforanemptycommandline*/
params>[Link]=ATAG_CMDLINE;/*Commandlinetag*/
params>[Link]=(sizeof(structatag_header)+linelen+1+4)>>2;
strcpy(params>[Link],line);/*placecommandlineintotag*/
params=tag_next(params);/*movepointertonexttag*/
}
staticvoid
setup_end_tag(void)
{
params>[Link]=ATAG_NONE;/*Emptytagendslist*/
params>[Link]=0;/*zerolength*/
}
#defineDRAM_BASE0x10000000
#defineZIMAGE_LOAD_ADDRESSDRAM_BASE+0x8000
#defineINITRD_LOAD_ADDRESSDRAM_BASE+0x800000
staticvoid
setup_tags(parameters)
{
setup_core_tag(parameters,4096);/*standardcoretag4kpagesize*/
setup_mem_tag(DRAM_BASE,0x4000000);/*64Mbat0x10000000*/
setup_mem_tag(DRAM_BASE+0x8000000,0x4000000);/*64Mbat0x18000000*/
setup_ramdisk_tag(4096);/*create4Mbramdisk*/
setup_initrd2_tag(INITRD_LOAD_ADDRESS,0x100000);/*1Mbofcompresseddataplaced8Mbintomemory*/
setup_cmdline_tag("root=/dev/ram0");/*commandlinesettingrootdevice*/
setup_end_tag(void);/*endoftags*/
}
int
start_linux(char*name,char*rdname)
{
void(*theKernel)(intzero,intarch,u32params);
u32exec_at=(u32)1;
u32parm_at=(u32)1;
u32machine_type;
exec_at=ZIMAGE_LOAD_ADDRESS;
parm_at=DRAM_BASE+0x100
load_image(name,exec_at);/*copyimageintoRAM*/
load_image(rdname,INITRD_LOAD_ADDRESS);/*copyinitialramdiskimageintoRAM*/
setup_tags(parm_at);/*setsupparameters*/
machine_type=get_mach_type();/*getmachinetype*/
irq_shutdown();/*stopirq*/
[Link]

14/15

01/02/2016

BootingARMLinux

cpu_op(CPUOP_MMUCHANGE,NULL);/*turnMMUoff*/
theKernel=(void(*)(int,int,u32))exec_at;/*setthekerneladdress*/
theKernel(0,machine_type,parm_at);/*jumptokernelwithregisterset*/
return0;
}

Bibliography
[Link].
LinuxKernelDocumentation/arm/[Link].
SettingR2correctlyforbootingthekernel(explanationofbootingrequirements).RussellMKing.
Wookey'[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].
[Link].

[Link]

15/15

You might also like