xref: /OK3568_Linux_fs/kernel/Documentation/arm/booting.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun=================
2*4882a593SmuzhiyunBooting ARM Linux
3*4882a593Smuzhiyun=================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunAuthor:	Russell King
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunDate  : 18 May 2002
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunThe following documentation is relevant to 2.4.18-rmk6 and beyond.
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunIn order to boot ARM Linux, you require a boot loader, which is a small
12*4882a593Smuzhiyunprogram that runs before the main kernel.  The boot loader is expected
13*4882a593Smuzhiyunto initialise various devices, and eventually call the Linux kernel,
14*4882a593Smuzhiyunpassing information to the kernel.
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunEssentially, the boot loader should provide (as a minimum) the
17*4882a593Smuzhiyunfollowing:
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun1. Setup and initialise the RAM.
20*4882a593Smuzhiyun2. Initialise one serial port.
21*4882a593Smuzhiyun3. Detect the machine type.
22*4882a593Smuzhiyun4. Setup the kernel tagged list.
23*4882a593Smuzhiyun5. Load initramfs.
24*4882a593Smuzhiyun6. Call the kernel image.
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun1. Setup and initialise RAM
28*4882a593Smuzhiyun---------------------------
29*4882a593Smuzhiyun
30*4882a593SmuzhiyunExisting boot loaders:
31*4882a593Smuzhiyun	MANDATORY
32*4882a593SmuzhiyunNew boot loaders:
33*4882a593Smuzhiyun	MANDATORY
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunThe boot loader is expected to find and initialise all RAM that the
36*4882a593Smuzhiyunkernel will use for volatile data storage in the system.  It performs
37*4882a593Smuzhiyunthis in a machine dependent manner.  (It may use internal algorithms
38*4882a593Smuzhiyunto automatically locate and size all RAM, or it may use knowledge of
39*4882a593Smuzhiyunthe RAM in the machine, or any other method the boot loader designer
40*4882a593Smuzhiyunsees fit.)
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun2. Initialise one serial port
44*4882a593Smuzhiyun-----------------------------
45*4882a593Smuzhiyun
46*4882a593SmuzhiyunExisting boot loaders:
47*4882a593Smuzhiyun	OPTIONAL, RECOMMENDED
48*4882a593SmuzhiyunNew boot loaders:
49*4882a593Smuzhiyun	OPTIONAL, RECOMMENDED
50*4882a593Smuzhiyun
51*4882a593SmuzhiyunThe boot loader should initialise and enable one serial port on the
52*4882a593Smuzhiyuntarget.  This allows the kernel serial driver to automatically detect
53*4882a593Smuzhiyunwhich serial port it should use for the kernel console (generally
54*4882a593Smuzhiyunused for debugging purposes, or communication with the target.)
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunAs an alternative, the boot loader can pass the relevant 'console='
57*4882a593Smuzhiyunoption to the kernel via the tagged lists specifying the port, and
58*4882a593Smuzhiyunserial format options as described in
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun       Documentation/admin-guide/kernel-parameters.rst.
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun3. Detect the machine type
64*4882a593Smuzhiyun--------------------------
65*4882a593Smuzhiyun
66*4882a593SmuzhiyunExisting boot loaders:
67*4882a593Smuzhiyun	OPTIONAL
68*4882a593SmuzhiyunNew boot loaders:
69*4882a593Smuzhiyun	MANDATORY except for DT-only platforms
70*4882a593Smuzhiyun
71*4882a593SmuzhiyunThe boot loader should detect the machine type its running on by some
72*4882a593Smuzhiyunmethod.  Whether this is a hard coded value or some algorithm that
73*4882a593Smuzhiyunlooks at the connected hardware is beyond the scope of this document.
74*4882a593SmuzhiyunThe boot loader must ultimately be able to provide a MACH_TYPE_xxx
75*4882a593Smuzhiyunvalue to the kernel. (see linux/arch/arm/tools/mach-types).  This
76*4882a593Smuzhiyunshould be passed to the kernel in register r1.
77*4882a593Smuzhiyun
78*4882a593SmuzhiyunFor DT-only platforms, the machine type will be determined by device
79*4882a593Smuzhiyuntree.  set the machine type to all ones (~0).  This is not strictly
80*4882a593Smuzhiyunnecessary, but assures that it will not match any existing types.
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun4. Setup boot data
83*4882a593Smuzhiyun------------------
84*4882a593Smuzhiyun
85*4882a593SmuzhiyunExisting boot loaders:
86*4882a593Smuzhiyun	OPTIONAL, HIGHLY RECOMMENDED
87*4882a593SmuzhiyunNew boot loaders:
88*4882a593Smuzhiyun	MANDATORY
89*4882a593Smuzhiyun
90*4882a593SmuzhiyunThe boot loader must provide either a tagged list or a dtb image for
91*4882a593Smuzhiyunpassing configuration data to the kernel.  The physical address of the
92*4882a593Smuzhiyunboot data is passed to the kernel in register r2.
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun4a. Setup the kernel tagged list
95*4882a593Smuzhiyun--------------------------------
96*4882a593Smuzhiyun
97*4882a593SmuzhiyunThe boot loader must create and initialise the kernel tagged list.
98*4882a593SmuzhiyunA valid tagged list starts with ATAG_CORE and ends with ATAG_NONE.
99*4882a593SmuzhiyunThe ATAG_CORE tag may or may not be empty.  An empty ATAG_CORE tag
100*4882a593Smuzhiyunhas the size field set to '2' (0x00000002).  The ATAG_NONE must set
101*4882a593Smuzhiyunthe size field to zero.
102*4882a593Smuzhiyun
103*4882a593SmuzhiyunAny number of tags can be placed in the list.  It is undefined
104*4882a593Smuzhiyunwhether a repeated tag appends to the information carried by the
105*4882a593Smuzhiyunprevious tag, or whether it replaces the information in its
106*4882a593Smuzhiyunentirety; some tags behave as the former, others the latter.
107*4882a593Smuzhiyun
108*4882a593SmuzhiyunThe boot loader must pass at a minimum the size and location of
109*4882a593Smuzhiyunthe system memory, and root filesystem location.  Therefore, the
110*4882a593Smuzhiyunminimum tagged list should look::
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun		+-----------+
113*4882a593Smuzhiyun  base ->	| ATAG_CORE |  |
114*4882a593Smuzhiyun		+-----------+  |
115*4882a593Smuzhiyun		| ATAG_MEM  |  | increasing address
116*4882a593Smuzhiyun		+-----------+  |
117*4882a593Smuzhiyun		| ATAG_NONE |  |
118*4882a593Smuzhiyun		+-----------+  v
119*4882a593Smuzhiyun
120*4882a593SmuzhiyunThe tagged list should be stored in system RAM.
121*4882a593Smuzhiyun
122*4882a593SmuzhiyunThe tagged list must be placed in a region of memory where neither
123*4882a593Smuzhiyunthe kernel decompressor nor initrd 'bootp' program will overwrite
124*4882a593Smuzhiyunit.  The recommended placement is in the first 16KiB of RAM.
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun4b. Setup the device tree
127*4882a593Smuzhiyun-------------------------
128*4882a593Smuzhiyun
129*4882a593SmuzhiyunThe boot loader must load a device tree image (dtb) into system ram
130*4882a593Smuzhiyunat a 64bit aligned address and initialize it with the boot data.  The
131*4882a593Smuzhiyundtb format is documented in Documentation/devicetree/booting-without-of.rst.
132*4882a593SmuzhiyunThe kernel will look for the dtb magic value of 0xd00dfeed at the dtb
133*4882a593Smuzhiyunphysical address to determine if a dtb has been passed instead of a
134*4882a593Smuzhiyuntagged list.
135*4882a593Smuzhiyun
136*4882a593SmuzhiyunThe boot loader must pass at a minimum the size and location of the
137*4882a593Smuzhiyunsystem memory, and the root filesystem location.  The dtb must be
138*4882a593Smuzhiyunplaced in a region of memory where the kernel decompressor will not
139*4882a593Smuzhiyunoverwrite it, while remaining within the region which will be covered
140*4882a593Smuzhiyunby the kernel's low-memory mapping.
141*4882a593Smuzhiyun
142*4882a593SmuzhiyunA safe location is just above the 128MiB boundary from start of RAM.
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun5. Load initramfs.
145*4882a593Smuzhiyun------------------
146*4882a593Smuzhiyun
147*4882a593SmuzhiyunExisting boot loaders:
148*4882a593Smuzhiyun	OPTIONAL
149*4882a593SmuzhiyunNew boot loaders:
150*4882a593Smuzhiyun	OPTIONAL
151*4882a593Smuzhiyun
152*4882a593SmuzhiyunIf an initramfs is in use then, as with the dtb, it must be placed in
153*4882a593Smuzhiyuna region of memory where the kernel decompressor will not overwrite it
154*4882a593Smuzhiyunwhile also with the region which will be covered by the kernel's
155*4882a593Smuzhiyunlow-memory mapping.
156*4882a593Smuzhiyun
157*4882a593SmuzhiyunA safe location is just above the device tree blob which itself will
158*4882a593Smuzhiyunbe loaded just above the 128MiB boundary from the start of RAM as
159*4882a593Smuzhiyunrecommended above.
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun6. Calling the kernel image
162*4882a593Smuzhiyun---------------------------
163*4882a593Smuzhiyun
164*4882a593SmuzhiyunExisting boot loaders:
165*4882a593Smuzhiyun	MANDATORY
166*4882a593SmuzhiyunNew boot loaders:
167*4882a593Smuzhiyun	MANDATORY
168*4882a593Smuzhiyun
169*4882a593SmuzhiyunThere are two options for calling the kernel zImage.  If the zImage
170*4882a593Smuzhiyunis stored in flash, and is linked correctly to be run from flash,
171*4882a593Smuzhiyunthen it is legal for the boot loader to call the zImage in flash
172*4882a593Smuzhiyundirectly.
173*4882a593Smuzhiyun
174*4882a593SmuzhiyunThe zImage may also be placed in system RAM and called there.  The
175*4882a593Smuzhiyunkernel should be placed in the first 128MiB of RAM.  It is recommended
176*4882a593Smuzhiyunthat it is loaded above 32MiB in order to avoid the need to relocate
177*4882a593Smuzhiyunprior to decompression, which will make the boot process slightly
178*4882a593Smuzhiyunfaster.
179*4882a593Smuzhiyun
180*4882a593SmuzhiyunWhen booting a raw (non-zImage) kernel the constraints are tighter.
181*4882a593SmuzhiyunIn this case the kernel must be loaded at an offset into system equal
182*4882a593Smuzhiyunto TEXT_OFFSET - PAGE_OFFSET.
183*4882a593Smuzhiyun
184*4882a593SmuzhiyunIn any case, the following conditions must be met:
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun- Quiesce all DMA capable devices so that memory does not get
187*4882a593Smuzhiyun  corrupted by bogus network packets or disk data. This will save
188*4882a593Smuzhiyun  you many hours of debug.
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun- CPU register settings
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun  - r0 = 0,
193*4882a593Smuzhiyun  - r1 = machine type number discovered in (3) above.
194*4882a593Smuzhiyun  - r2 = physical address of tagged list in system RAM, or
195*4882a593Smuzhiyun    physical address of device tree block (dtb) in system RAM
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun- CPU mode
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun  All forms of interrupts must be disabled (IRQs and FIQs)
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun  For CPUs which do not include the ARM virtualization extensions, the
202*4882a593Smuzhiyun  CPU must be in SVC mode.  (A special exception exists for Angel)
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun  CPUs which include support for the virtualization extensions can be
205*4882a593Smuzhiyun  entered in HYP mode in order to enable the kernel to make full use of
206*4882a593Smuzhiyun  these extensions.  This is the recommended boot method for such CPUs,
207*4882a593Smuzhiyun  unless the virtualisations are already in use by a pre-installed
208*4882a593Smuzhiyun  hypervisor.
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun  If the kernel is not entered in HYP mode for any reason, it must be
211*4882a593Smuzhiyun  entered in SVC mode.
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun- Caches, MMUs
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun  The MMU must be off.
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun  Instruction cache may be on or off.
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun  Data cache must be off.
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun  If the kernel is entered in HYP mode, the above requirements apply to
222*4882a593Smuzhiyun  the HYP mode configuration in addition to the ordinary PL1 (privileged
223*4882a593Smuzhiyun  kernel modes) configuration.  In addition, all traps into the
224*4882a593Smuzhiyun  hypervisor must be disabled, and PL1 access must be granted for all
225*4882a593Smuzhiyun  peripherals and CPU resources for which this is architecturally
226*4882a593Smuzhiyun  possible.  Except for entering in HYP mode, the system configuration
227*4882a593Smuzhiyun  should be such that a kernel which does not include support for the
228*4882a593Smuzhiyun  virtualization extensions can boot correctly without extra help.
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun- The boot loader is expected to call the kernel image by jumping
231*4882a593Smuzhiyun  directly to the first instruction of the kernel image.
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun  On CPUs supporting the ARM instruction set, the entry must be
234*4882a593Smuzhiyun  made in ARM state, even for a Thumb-2 kernel.
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun  On CPUs supporting only the Thumb instruction set such as
237*4882a593Smuzhiyun  Cortex-M class CPUs, the entry must be made in Thumb state.
238