238 lines · plain
1=================2Booting ARM Linux3=================4 5Author: Russell King6 7Date : 18 May 20028 9The following documentation is relevant to 2.4.18-rmk6 and beyond.10 11In order to boot ARM Linux, you require a boot loader, which is a small12program that runs before the main kernel. The boot loader is expected13to initialise various devices, and eventually call the Linux kernel,14passing information to the kernel.15 16Essentially, the boot loader should provide (as a minimum) the17following:18 191. Setup and initialise the RAM.202. Initialise one serial port.213. Detect the machine type.224. Setup the kernel tagged list.235. Load initramfs.246. Call the kernel image.25 26 271. Setup and initialise RAM28---------------------------29 30Existing boot loaders:31 MANDATORY32New boot loaders:33 MANDATORY34 35The boot loader is expected to find and initialise all RAM that the36kernel will use for volatile data storage in the system. It performs37this in a machine dependent manner. (It may use internal algorithms38to automatically locate and size all RAM, or it may use knowledge of39the RAM in the machine, or any other method the boot loader designer40sees fit.)41 42 432. Initialise one serial port44-----------------------------45 46Existing boot loaders:47 OPTIONAL, RECOMMENDED48New boot loaders:49 OPTIONAL, RECOMMENDED50 51The boot loader should initialise and enable one serial port on the52target. This allows the kernel serial driver to automatically detect53which serial port it should use for the kernel console (generally54used for debugging purposes, or communication with the target.)55 56As an alternative, the boot loader can pass the relevant 'console='57option to the kernel via the tagged lists specifying the port, and58serial format options as described in59 60 Documentation/admin-guide/kernel-parameters.rst.61 62 633. Detect the machine type64--------------------------65 66Existing boot loaders:67 OPTIONAL68New boot loaders:69 MANDATORY except for DT-only platforms70 71The boot loader should detect the machine type its running on by some72method. Whether this is a hard coded value or some algorithm that73looks at the connected hardware is beyond the scope of this document.74The boot loader must ultimately be able to provide a MACH_TYPE_xxx75value to the kernel. (see linux/arch/arm/tools/mach-types). This76should be passed to the kernel in register r1.77 78For DT-only platforms, the machine type will be determined by device79tree. set the machine type to all ones (~0). This is not strictly80necessary, but assures that it will not match any existing types.81 824. Setup boot data83------------------84 85Existing boot loaders:86 OPTIONAL, HIGHLY RECOMMENDED87New boot loaders:88 MANDATORY89 90The boot loader must provide either a tagged list or a dtb image for91passing configuration data to the kernel. The physical address of the92boot data is passed to the kernel in register r2.93 944a. Setup the kernel tagged list95--------------------------------96 97The boot loader must create and initialise the kernel tagged list.98A valid tagged list starts with ATAG_CORE and ends with ATAG_NONE.99The ATAG_CORE tag may or may not be empty. An empty ATAG_CORE tag100has the size field set to '2' (0x00000002). The ATAG_NONE must set101the size field to zero.102 103Any number of tags can be placed in the list. It is undefined104whether a repeated tag appends to the information carried by the105previous tag, or whether it replaces the information in its106entirety; some tags behave as the former, others the latter.107 108The boot loader must pass at a minimum the size and location of109the system memory, and root filesystem location. Therefore, the110minimum tagged list should look::111 112 +-----------+113 base -> | ATAG_CORE | |114 +-----------+ |115 | ATAG_MEM | | increasing address116 +-----------+ |117 | ATAG_NONE | |118 +-----------+ v119 120The tagged list should be stored in system RAM.121 122The tagged list must be placed in a region of memory where neither123the kernel decompressor nor initrd 'bootp' program will overwrite124it. The recommended placement is in the first 16KiB of RAM.125 1264b. Setup the device tree127-------------------------128 129The boot loader must load a device tree image (dtb) into system ram130at a 64bit aligned address and initialize it with the boot data. The131dtb format is documented at https://www.devicetree.org/specifications/.132The kernel will look for the dtb magic value of 0xd00dfeed at the dtb133physical address to determine if a dtb has been passed instead of a134tagged list.135 136The boot loader must pass at a minimum the size and location of the137system memory, and the root filesystem location. The dtb must be138placed in a region of memory where the kernel decompressor will not139overwrite it, while remaining within the region which will be covered140by the kernel's low-memory mapping.141 142A safe location is just above the 128MiB boundary from start of RAM.143 1445. Load initramfs.145------------------146 147Existing boot loaders:148 OPTIONAL149New boot loaders:150 OPTIONAL151 152If an initramfs is in use then, as with the dtb, it must be placed in153a region of memory where the kernel decompressor will not overwrite it154while also with the region which will be covered by the kernel's155low-memory mapping.156 157A safe location is just above the device tree blob which itself will158be loaded just above the 128MiB boundary from the start of RAM as159recommended above.160 1616. Calling the kernel image162---------------------------163 164Existing boot loaders:165 MANDATORY166New boot loaders:167 MANDATORY168 169There are two options for calling the kernel zImage. If the zImage170is stored in flash, and is linked correctly to be run from flash,171then it is legal for the boot loader to call the zImage in flash172directly.173 174The zImage may also be placed in system RAM and called there. The175kernel should be placed in the first 128MiB of RAM. It is recommended176that it is loaded above 32MiB in order to avoid the need to relocate177prior to decompression, which will make the boot process slightly178faster.179 180When booting a raw (non-zImage) kernel the constraints are tighter.181In this case the kernel must be loaded at an offset into system equal182to TEXT_OFFSET - PAGE_OFFSET.183 184In any case, the following conditions must be met:185 186- Quiesce all DMA capable devices so that memory does not get187 corrupted by bogus network packets or disk data. This will save188 you many hours of debug.189 190- CPU register settings191 192 - r0 = 0,193 - r1 = machine type number discovered in (3) above.194 - r2 = physical address of tagged list in system RAM, or195 physical address of device tree block (dtb) in system RAM196 197- CPU mode198 199 All forms of interrupts must be disabled (IRQs and FIQs)200 201 For CPUs which do not include the ARM virtualization extensions, the202 CPU must be in SVC mode. (A special exception exists for Angel)203 204 CPUs which include support for the virtualization extensions can be205 entered in HYP mode in order to enable the kernel to make full use of206 these extensions. This is the recommended boot method for such CPUs,207 unless the virtualisations are already in use by a pre-installed208 hypervisor.209 210 If the kernel is not entered in HYP mode for any reason, it must be211 entered in SVC mode.212 213- Caches, MMUs214 215 The MMU must be off.216 217 Instruction cache may be on or off.218 219 Data cache must be off.220 221 If the kernel is entered in HYP mode, the above requirements apply to222 the HYP mode configuration in addition to the ordinary PL1 (privileged223 kernel modes) configuration. In addition, all traps into the224 hypervisor must be disabled, and PL1 access must be granted for all225 peripherals and CPU resources for which this is architecturally226 possible. Except for entering in HYP mode, the system configuration227 should be such that a kernel which does not include support for the228 virtualization extensions can boot correctly without extra help.229 230- The boot loader is expected to call the kernel image by jumping231 directly to the first instruction of the kernel image.232 233 On CPUs supporting the ARM instruction set, the entry must be234 made in ARM state, even for a Thumb-2 kernel.235 236 On CPUs supporting only the Thumb instruction set such as237 Cortex-M class CPUs, the entry must be made in Thumb state.238