Back to home page

OSCL-LXR

 
 

    


0001 =================
0002 Booting ARM Linux
0003 =================
0004 
0005 Author: Russell King
0006 
0007 Date  : 18 May 2002
0008 
0009 The following documentation is relevant to 2.4.18-rmk6 and beyond.
0010 
0011 In order to boot ARM Linux, you require a boot loader, which is a small
0012 program that runs before the main kernel.  The boot loader is expected
0013 to initialise various devices, and eventually call the Linux kernel,
0014 passing information to the kernel.
0015 
0016 Essentially, the boot loader should provide (as a minimum) the
0017 following:
0018 
0019 1. Setup and initialise the RAM.
0020 2. Initialise one serial port.
0021 3. Detect the machine type.
0022 4. Setup the kernel tagged list.
0023 5. Load initramfs.
0024 6. Call the kernel image.
0025 
0026 
0027 1. Setup and initialise RAM
0028 ---------------------------
0029 
0030 Existing boot loaders:
0031         MANDATORY
0032 New boot loaders:
0033         MANDATORY
0034 
0035 The boot loader is expected to find and initialise all RAM that the
0036 kernel will use for volatile data storage in the system.  It performs
0037 this in a machine dependent manner.  (It may use internal algorithms
0038 to automatically locate and size all RAM, or it may use knowledge of
0039 the RAM in the machine, or any other method the boot loader designer
0040 sees fit.)
0041 
0042 
0043 2. Initialise one serial port
0044 -----------------------------
0045 
0046 Existing boot loaders:
0047         OPTIONAL, RECOMMENDED
0048 New boot loaders:
0049         OPTIONAL, RECOMMENDED
0050 
0051 The boot loader should initialise and enable one serial port on the
0052 target.  This allows the kernel serial driver to automatically detect
0053 which serial port it should use for the kernel console (generally
0054 used for debugging purposes, or communication with the target.)
0055 
0056 As an alternative, the boot loader can pass the relevant 'console='
0057 option to the kernel via the tagged lists specifying the port, and
0058 serial format options as described in
0059 
0060        Documentation/admin-guide/kernel-parameters.rst.
0061 
0062 
0063 3. Detect the machine type
0064 --------------------------
0065 
0066 Existing boot loaders:
0067         OPTIONAL
0068 New boot loaders:
0069         MANDATORY except for DT-only platforms
0070 
0071 The boot loader should detect the machine type its running on by some
0072 method.  Whether this is a hard coded value or some algorithm that
0073 looks at the connected hardware is beyond the scope of this document.
0074 The boot loader must ultimately be able to provide a MACH_TYPE_xxx
0075 value to the kernel. (see linux/arch/arm/tools/mach-types).  This
0076 should be passed to the kernel in register r1.
0077 
0078 For DT-only platforms, the machine type will be determined by device
0079 tree.  set the machine type to all ones (~0).  This is not strictly
0080 necessary, but assures that it will not match any existing types.
0081 
0082 4. Setup boot data
0083 ------------------
0084 
0085 Existing boot loaders:
0086         OPTIONAL, HIGHLY RECOMMENDED
0087 New boot loaders:
0088         MANDATORY
0089 
0090 The boot loader must provide either a tagged list or a dtb image for
0091 passing configuration data to the kernel.  The physical address of the
0092 boot data is passed to the kernel in register r2.
0093 
0094 4a. Setup the kernel tagged list
0095 --------------------------------
0096 
0097 The boot loader must create and initialise the kernel tagged list.
0098 A valid tagged list starts with ATAG_CORE and ends with ATAG_NONE.
0099 The ATAG_CORE tag may or may not be empty.  An empty ATAG_CORE tag
0100 has the size field set to '2' (0x00000002).  The ATAG_NONE must set
0101 the size field to zero.
0102 
0103 Any number of tags can be placed in the list.  It is undefined
0104 whether a repeated tag appends to the information carried by the
0105 previous tag, or whether it replaces the information in its
0106 entirety; some tags behave as the former, others the latter.
0107 
0108 The boot loader must pass at a minimum the size and location of
0109 the system memory, and root filesystem location.  Therefore, the
0110 minimum tagged list should look::
0111 
0112                 +-----------+
0113   base ->       | ATAG_CORE |  |
0114                 +-----------+  |
0115                 | ATAG_MEM  |  | increasing address
0116                 +-----------+  |
0117                 | ATAG_NONE |  |
0118                 +-----------+  v
0119 
0120 The tagged list should be stored in system RAM.
0121 
0122 The tagged list must be placed in a region of memory where neither
0123 the kernel decompressor nor initrd 'bootp' program will overwrite
0124 it.  The recommended placement is in the first 16KiB of RAM.
0125 
0126 4b. Setup the device tree
0127 -------------------------
0128 
0129 The boot loader must load a device tree image (dtb) into system ram
0130 at a 64bit aligned address and initialize it with the boot data.  The
0131 dtb format is documented at https://www.devicetree.org/specifications/.
0132 The kernel will look for the dtb magic value of 0xd00dfeed at the dtb
0133 physical address to determine if a dtb has been passed instead of a
0134 tagged list.
0135 
0136 The boot loader must pass at a minimum the size and location of the
0137 system memory, and the root filesystem location.  The dtb must be
0138 placed in a region of memory where the kernel decompressor will not
0139 overwrite it, while remaining within the region which will be covered
0140 by the kernel's low-memory mapping.
0141 
0142 A safe location is just above the 128MiB boundary from start of RAM.
0143 
0144 5. Load initramfs.
0145 ------------------
0146 
0147 Existing boot loaders:
0148         OPTIONAL
0149 New boot loaders:
0150         OPTIONAL
0151 
0152 If an initramfs is in use then, as with the dtb, it must be placed in
0153 a region of memory where the kernel decompressor will not overwrite it
0154 while also with the region which will be covered by the kernel's
0155 low-memory mapping.
0156 
0157 A safe location is just above the device tree blob which itself will
0158 be loaded just above the 128MiB boundary from the start of RAM as
0159 recommended above.
0160 
0161 6. Calling the kernel image
0162 ---------------------------
0163 
0164 Existing boot loaders:
0165         MANDATORY
0166 New boot loaders:
0167         MANDATORY
0168 
0169 There are two options for calling the kernel zImage.  If the zImage
0170 is stored in flash, and is linked correctly to be run from flash,
0171 then it is legal for the boot loader to call the zImage in flash
0172 directly.
0173 
0174 The zImage may also be placed in system RAM and called there.  The
0175 kernel should be placed in the first 128MiB of RAM.  It is recommended
0176 that it is loaded above 32MiB in order to avoid the need to relocate
0177 prior to decompression, which will make the boot process slightly
0178 faster.
0179 
0180 When booting a raw (non-zImage) kernel the constraints are tighter.
0181 In this case the kernel must be loaded at an offset into system equal
0182 to TEXT_OFFSET - PAGE_OFFSET.
0183 
0184 In any case, the following conditions must be met:
0185 
0186 - Quiesce all DMA capable devices so that memory does not get
0187   corrupted by bogus network packets or disk data. This will save
0188   you many hours of debug.
0189 
0190 - CPU register settings
0191 
0192   - r0 = 0,
0193   - r1 = machine type number discovered in (3) above.
0194   - r2 = physical address of tagged list in system RAM, or
0195     physical address of device tree block (dtb) in system RAM
0196 
0197 - CPU mode
0198 
0199   All forms of interrupts must be disabled (IRQs and FIQs)
0200 
0201   For CPUs which do not include the ARM virtualization extensions, the
0202   CPU must be in SVC mode.  (A special exception exists for Angel)
0203 
0204   CPUs which include support for the virtualization extensions can be
0205   entered in HYP mode in order to enable the kernel to make full use of
0206   these extensions.  This is the recommended boot method for such CPUs,
0207   unless the virtualisations are already in use by a pre-installed
0208   hypervisor.
0209 
0210   If the kernel is not entered in HYP mode for any reason, it must be
0211   entered in SVC mode.
0212 
0213 - Caches, MMUs
0214 
0215   The MMU must be off.
0216 
0217   Instruction cache may be on or off.
0218 
0219   Data cache must be off.
0220 
0221   If the kernel is entered in HYP mode, the above requirements apply to
0222   the HYP mode configuration in addition to the ordinary PL1 (privileged
0223   kernel modes) configuration.  In addition, all traps into the
0224   hypervisor must be disabled, and PL1 access must be granted for all
0225   peripherals and CPU resources for which this is architecturally
0226   possible.  Except for entering in HYP mode, the system configuration
0227   should be such that a kernel which does not include support for the
0228   virtualization extensions can boot correctly without extra help.
0229 
0230 - The boot loader is expected to call the kernel image by jumping
0231   directly to the first instruction of the kernel image.
0232 
0233   On CPUs supporting the ARM instruction set, the entry must be
0234   made in ARM state, even for a Thumb-2 kernel.
0235 
0236   On CPUs supporting only the Thumb instruction set such as
0237   Cortex-M class CPUs, the entry must be made in Thumb state.