Back to home page

OSCL-LXR

 
 

    


0001 =====================
0002 Booting AArch64 Linux
0003 =====================
0004 
0005 Author: Will Deacon <will.deacon@arm.com>
0006 
0007 Date  : 07 September 2012
0008 
0009 This document is based on the ARM booting document by Russell King and
0010 is relevant to all public releases of the AArch64 Linux kernel.
0011 
0012 The AArch64 exception model is made up of a number of exception levels
0013 (EL0 - EL3), with EL0, EL1 and EL2 having a secure and a non-secure
0014 counterpart.  EL2 is the hypervisor level, EL3 is the highest priority
0015 level and exists only in secure mode. Both are architecturally optional.
0016 
0017 For the purposes of this document, we will use the term `boot loader`
0018 simply to define all software that executes on the CPU(s) before control
0019 is passed to the Linux kernel.  This may include secure monitor and
0020 hypervisor code, or it may just be a handful of instructions for
0021 preparing a minimal boot environment.
0022 
0023 Essentially, the boot loader should provide (as a minimum) the
0024 following:
0025 
0026 1. Setup and initialise the RAM
0027 2. Setup the device tree
0028 3. Decompress the kernel image
0029 4. Call the kernel image
0030 
0031 
0032 1. Setup and initialise RAM
0033 ---------------------------
0034 
0035 Requirement: MANDATORY
0036 
0037 The boot loader is expected to find and initialise all RAM that the
0038 kernel will use for volatile data storage in the system.  It performs
0039 this in a machine dependent manner.  (It may use internal algorithms
0040 to automatically locate and size all RAM, or it may use knowledge of
0041 the RAM in the machine, or any other method the boot loader designer
0042 sees fit.)
0043 
0044 
0045 2. Setup the device tree
0046 -------------------------
0047 
0048 Requirement: MANDATORY
0049 
0050 The device tree blob (dtb) must be placed on an 8-byte boundary and must
0051 not exceed 2 megabytes in size. Since the dtb will be mapped cacheable
0052 using blocks of up to 2 megabytes in size, it must not be placed within
0053 any 2M region which must be mapped with any specific attributes.
0054 
0055 NOTE: versions prior to v4.2 also require that the DTB be placed within
0056 the 512 MB region starting at text_offset bytes below the kernel Image.
0057 
0058 3. Decompress the kernel image
0059 ------------------------------
0060 
0061 Requirement: OPTIONAL
0062 
0063 The AArch64 kernel does not currently provide a decompressor and
0064 therefore requires decompression (gzip etc.) to be performed by the boot
0065 loader if a compressed Image target (e.g. Image.gz) is used.  For
0066 bootloaders that do not implement this requirement, the uncompressed
0067 Image target is available instead.
0068 
0069 
0070 4. Call the kernel image
0071 ------------------------
0072 
0073 Requirement: MANDATORY
0074 
0075 The decompressed kernel image contains a 64-byte header as follows::
0076 
0077   u32 code0;                    /* Executable code */
0078   u32 code1;                    /* Executable code */
0079   u64 text_offset;              /* Image load offset, little endian */
0080   u64 image_size;               /* Effective Image size, little endian */
0081   u64 flags;                    /* kernel flags, little endian */
0082   u64 res2      = 0;            /* reserved */
0083   u64 res3      = 0;            /* reserved */
0084   u64 res4      = 0;            /* reserved */
0085   u32 magic     = 0x644d5241;   /* Magic number, little endian, "ARM\x64" */
0086   u32 res5;                     /* reserved (used for PE COFF offset) */
0087 
0088 
0089 Header notes:
0090 
0091 - As of v3.17, all fields are little endian unless stated otherwise.
0092 
0093 - code0/code1 are responsible for branching to stext.
0094 
0095 - when booting through EFI, code0/code1 are initially skipped.
0096   res5 is an offset to the PE header and the PE header has the EFI
0097   entry point (efi_stub_entry).  When the stub has done its work, it
0098   jumps to code0 to resume the normal boot process.
0099 
0100 - Prior to v3.17, the endianness of text_offset was not specified.  In
0101   these cases image_size is zero and text_offset is 0x80000 in the
0102   endianness of the kernel.  Where image_size is non-zero image_size is
0103   little-endian and must be respected.  Where image_size is zero,
0104   text_offset can be assumed to be 0x80000.
0105 
0106 - The flags field (introduced in v3.17) is a little-endian 64-bit field
0107   composed as follows:
0108 
0109   ============= ===============================================================
0110   Bit 0         Kernel endianness.  1 if BE, 0 if LE.
0111   Bit 1-2       Kernel Page size.
0112 
0113                         * 0 - Unspecified.
0114                         * 1 - 4K
0115                         * 2 - 16K
0116                         * 3 - 64K
0117   Bit 3         Kernel physical placement
0118 
0119                         0
0120                           2MB aligned base should be as close as possible
0121                           to the base of DRAM, since memory below it is not
0122                           accessible via the linear mapping
0123                         1
0124                           2MB aligned base may be anywhere in physical
0125                           memory
0126   Bits 4-63     Reserved.
0127   ============= ===============================================================
0128 
0129 - When image_size is zero, a bootloader should attempt to keep as much
0130   memory as possible free for use by the kernel immediately after the
0131   end of the kernel image. The amount of space required will vary
0132   depending on selected features, and is effectively unbound.
0133 
0134 The Image must be placed text_offset bytes from a 2MB aligned base
0135 address anywhere in usable system RAM and called there. The region
0136 between the 2 MB aligned base address and the start of the image has no
0137 special significance to the kernel, and may be used for other purposes.
0138 At least image_size bytes from the start of the image must be free for
0139 use by the kernel.
0140 NOTE: versions prior to v4.6 cannot make use of memory below the
0141 physical offset of the Image so it is recommended that the Image be
0142 placed as close as possible to the start of system RAM.
0143 
0144 If an initrd/initramfs is passed to the kernel at boot, it must reside
0145 entirely within a 1 GB aligned physical memory window of up to 32 GB in
0146 size that fully covers the kernel Image as well.
0147 
0148 Any memory described to the kernel (even that below the start of the
0149 image) which is not marked as reserved from the kernel (e.g., with a
0150 memreserve region in the device tree) will be considered as available to
0151 the kernel.
0152 
0153 Before jumping into the kernel, the following conditions must be met:
0154 
0155 - Quiesce all DMA capable devices so that memory does not get
0156   corrupted by bogus network packets or disk data.  This will save
0157   you many hours of debug.
0158 
0159 - Primary CPU general-purpose register settings:
0160 
0161     - x0 = physical address of device tree blob (dtb) in system RAM.
0162     - x1 = 0 (reserved for future use)
0163     - x2 = 0 (reserved for future use)
0164     - x3 = 0 (reserved for future use)
0165 
0166 - CPU mode
0167 
0168   All forms of interrupts must be masked in PSTATE.DAIF (Debug, SError,
0169   IRQ and FIQ).
0170   The CPU must be in non-secure state, either in EL2 (RECOMMENDED in order
0171   to have access to the virtualisation extensions), or in EL1.
0172 
0173 - Caches, MMUs
0174 
0175   The MMU must be off.
0176 
0177   The instruction cache may be on or off, and must not hold any stale
0178   entries corresponding to the loaded kernel image.
0179 
0180   The address range corresponding to the loaded kernel image must be
0181   cleaned to the PoC. In the presence of a system cache or other
0182   coherent masters with caches enabled, this will typically require
0183   cache maintenance by VA rather than set/way operations.
0184   System caches which respect the architected cache maintenance by VA
0185   operations must be configured and may be enabled.
0186   System caches which do not respect architected cache maintenance by VA
0187   operations (not recommended) must be configured and disabled.
0188 
0189 - Architected timers
0190 
0191   CNTFRQ must be programmed with the timer frequency and CNTVOFF must
0192   be programmed with a consistent value on all CPUs.  If entering the
0193   kernel at EL1, CNTHCTL_EL2 must have EL1PCTEN (bit 0) set where
0194   available.
0195 
0196 - Coherency
0197 
0198   All CPUs to be booted by the kernel must be part of the same coherency
0199   domain on entry to the kernel.  This may require IMPLEMENTATION DEFINED
0200   initialisation to enable the receiving of maintenance operations on
0201   each CPU.
0202 
0203 - System registers
0204 
0205   All writable architected system registers at or below the exception
0206   level where the kernel image will be entered must be initialised by
0207   software at a higher exception level to prevent execution in an UNKNOWN
0208   state.
0209 
0210   For all systems:
0211   - If EL3 is present:
0212 
0213     - SCR_EL3.FIQ must have the same value across all CPUs the kernel is
0214       executing on.
0215     - The value of SCR_EL3.FIQ must be the same as the one present at boot
0216       time whenever the kernel is executing.
0217 
0218   - If EL3 is present and the kernel is entered at EL2:
0219 
0220     - SCR_EL3.HCE (bit 8) must be initialised to 0b1.
0221 
0222   For systems with a GICv3 interrupt controller to be used in v3 mode:
0223   - If EL3 is present:
0224 
0225       - ICC_SRE_EL3.Enable (bit 3) must be initialiased to 0b1.
0226       - ICC_SRE_EL3.SRE (bit 0) must be initialised to 0b1.
0227       - ICC_CTLR_EL3.PMHE (bit 6) must be set to the same value across
0228         all CPUs the kernel is executing on, and must stay constant
0229         for the lifetime of the kernel.
0230 
0231   - If the kernel is entered at EL1:
0232 
0233       - ICC.SRE_EL2.Enable (bit 3) must be initialised to 0b1
0234       - ICC_SRE_EL2.SRE (bit 0) must be initialised to 0b1.
0235 
0236   - The DT or ACPI tables must describe a GICv3 interrupt controller.
0237 
0238   For systems with a GICv3 interrupt controller to be used in
0239   compatibility (v2) mode:
0240 
0241   - If EL3 is present:
0242 
0243       ICC_SRE_EL3.SRE (bit 0) must be initialised to 0b0.
0244 
0245   - If the kernel is entered at EL1:
0246 
0247       ICC_SRE_EL2.SRE (bit 0) must be initialised to 0b0.
0248 
0249   - The DT or ACPI tables must describe a GICv2 interrupt controller.
0250 
0251   For CPUs with pointer authentication functionality:
0252 
0253   - If EL3 is present:
0254 
0255     - SCR_EL3.APK (bit 16) must be initialised to 0b1
0256     - SCR_EL3.API (bit 17) must be initialised to 0b1
0257 
0258   - If the kernel is entered at EL1:
0259 
0260     - HCR_EL2.APK (bit 40) must be initialised to 0b1
0261     - HCR_EL2.API (bit 41) must be initialised to 0b1
0262 
0263   For CPUs with Activity Monitors Unit v1 (AMUv1) extension present:
0264 
0265   - If EL3 is present:
0266 
0267     - CPTR_EL3.TAM (bit 30) must be initialised to 0b0
0268     - CPTR_EL2.TAM (bit 30) must be initialised to 0b0
0269     - AMCNTENSET0_EL0 must be initialised to 0b1111
0270     - AMCNTENSET1_EL0 must be initialised to a platform specific value
0271       having 0b1 set for the corresponding bit for each of the auxiliary
0272       counters present.
0273 
0274   - If the kernel is entered at EL1:
0275 
0276     - AMCNTENSET0_EL0 must be initialised to 0b1111
0277     - AMCNTENSET1_EL0 must be initialised to a platform specific value
0278       having 0b1 set for the corresponding bit for each of the auxiliary
0279       counters present.
0280 
0281   For CPUs with the Fine Grained Traps (FEAT_FGT) extension present:
0282 
0283   - If EL3 is present and the kernel is entered at EL2:
0284 
0285     - SCR_EL3.FGTEn (bit 27) must be initialised to 0b1.
0286 
0287   For CPUs with support for HCRX_EL2 (FEAT_HCX) present:
0288 
0289   - If EL3 is present and the kernel is entered at EL2:
0290 
0291     - SCR_EL3.HXEn (bit 38) must be initialised to 0b1.
0292 
0293   For CPUs with Advanced SIMD and floating point support:
0294 
0295   - If EL3 is present:
0296 
0297     - CPTR_EL3.TFP (bit 10) must be initialised to 0b0.
0298 
0299   - If EL2 is present and the kernel is entered at EL1:
0300 
0301     - CPTR_EL2.TFP (bit 10) must be initialised to 0b0.
0302 
0303   For CPUs with the Scalable Vector Extension (FEAT_SVE) present:
0304 
0305   - if EL3 is present:
0306 
0307     - CPTR_EL3.EZ (bit 8) must be initialised to 0b1.
0308 
0309     - ZCR_EL3.LEN must be initialised to the same value for all CPUs the
0310       kernel is executed on.
0311 
0312   - If the kernel is entered at EL1 and EL2 is present:
0313 
0314     - CPTR_EL2.TZ (bit 8) must be initialised to 0b0.
0315 
0316     - CPTR_EL2.ZEN (bits 17:16) must be initialised to 0b11.
0317 
0318     - ZCR_EL2.LEN must be initialised to the same value for all CPUs the
0319       kernel will execute on.
0320 
0321   For CPUs with the Scalable Matrix Extension (FEAT_SME):
0322 
0323   - If EL3 is present:
0324 
0325     - CPTR_EL3.ESM (bit 12) must be initialised to 0b1.
0326 
0327     - SCR_EL3.EnTP2 (bit 41) must be initialised to 0b1.
0328 
0329     - SMCR_EL3.LEN must be initialised to the same value for all CPUs the
0330       kernel will execute on.
0331 
0332  - If the kernel is entered at EL1 and EL2 is present:
0333 
0334     - CPTR_EL2.TSM (bit 12) must be initialised to 0b0.
0335 
0336     - CPTR_EL2.SMEN (bits 25:24) must be initialised to 0b11.
0337 
0338     - SCTLR_EL2.EnTP2 (bit 60) must be initialised to 0b1.
0339 
0340     - SMCR_EL2.LEN must be initialised to the same value for all CPUs the
0341       kernel will execute on.
0342 
0343   For CPUs with the Scalable Matrix Extension FA64 feature (FEAT_SME_FA64)
0344 
0345   - If EL3 is present:
0346 
0347     - SMCR_EL3.FA64 (bit 31) must be initialised to 0b1.
0348 
0349  - If the kernel is entered at EL1 and EL2 is present:
0350 
0351     - SMCR_EL2.FA64 (bit 31) must be initialised to 0b1.
0352 
0353   For CPUs with the Memory Tagging Extension feature (FEAT_MTE2):
0354 
0355   - If EL3 is present:
0356 
0357     - SCR_EL3.ATA (bit 26) must be initialised to 0b1.
0358 
0359   - If the kernel is entered at EL1 and EL2 is present:
0360 
0361     - HCR_EL2.ATA (bit 56) must be initialised to 0b1.
0362 
0363 The requirements described above for CPU mode, caches, MMUs, architected
0364 timers, coherency and system registers apply to all CPUs.  All CPUs must
0365 enter the kernel in the same exception level.  Where the values documented
0366 disable traps it is permissible for these traps to be enabled so long as
0367 those traps are handled transparently by higher exception levels as though
0368 the values documented were set.
0369 
0370 The boot loader is expected to enter the kernel on each CPU in the
0371 following manner:
0372 
0373 - The primary CPU must jump directly to the first instruction of the
0374   kernel image.  The device tree blob passed by this CPU must contain
0375   an 'enable-method' property for each cpu node.  The supported
0376   enable-methods are described below.
0377 
0378   It is expected that the bootloader will generate these device tree
0379   properties and insert them into the blob prior to kernel entry.
0380 
0381 - CPUs with a "spin-table" enable-method must have a 'cpu-release-addr'
0382   property in their cpu node.  This property identifies a
0383   naturally-aligned 64-bit zero-initalised memory location.
0384 
0385   These CPUs should spin outside of the kernel in a reserved area of
0386   memory (communicated to the kernel by a /memreserve/ region in the
0387   device tree) polling their cpu-release-addr location, which must be
0388   contained in the reserved region.  A wfe instruction may be inserted
0389   to reduce the overhead of the busy-loop and a sev will be issued by
0390   the primary CPU.  When a read of the location pointed to by the
0391   cpu-release-addr returns a non-zero value, the CPU must jump to this
0392   value.  The value will be written as a single 64-bit little-endian
0393   value, so CPUs must convert the read value to their native endianness
0394   before jumping to it.
0395 
0396 - CPUs with a "psci" enable method should remain outside of
0397   the kernel (i.e. outside of the regions of memory described to the
0398   kernel in the memory node, or in a reserved area of memory described
0399   to the kernel by a /memreserve/ region in the device tree).  The
0400   kernel will issue CPU_ON calls as described in ARM document number ARM
0401   DEN 0022A ("Power State Coordination Interface System Software on ARM
0402   processors") to bring CPUs into the kernel.
0403 
0404   The device tree should contain a 'psci' node, as described in
0405   Documentation/devicetree/bindings/arm/psci.yaml.
0406 
0407 - Secondary CPU general-purpose register settings
0408 
0409   - x0 = 0 (reserved for future use)
0410   - x1 = 0 (reserved for future use)
0411   - x2 = 0 (reserved for future use)
0412   - x3 = 0 (reserved for future use)