booting.rst 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. =================
  2. Booting ARM Linux
  3. =================
  4. Author: Russell King
  5. Date : 18 May 2002
  6. The following documentation is relevant to 2.4.18-rmk6 and beyond.
  7. In order to boot ARM Linux, you require a boot loader, which is a small
  8. program that runs before the main kernel. The boot loader is expected
  9. to initialise various devices, and eventually call the Linux kernel,
  10. passing information to the kernel.
  11. Essentially, the boot loader should provide (as a minimum) the
  12. following:
  13. 1. Setup and initialise the RAM.
  14. 2. Initialise one serial port.
  15. 3. Detect the machine type.
  16. 4. Setup the kernel tagged list.
  17. 5. Load initramfs.
  18. 6. Call the kernel image.
  19. 1. Setup and initialise RAM
  20. ---------------------------
  21. Existing boot loaders:
  22. MANDATORY
  23. New boot loaders:
  24. MANDATORY
  25. The boot loader is expected to find and initialise all RAM that the
  26. kernel will use for volatile data storage in the system. It performs
  27. this in a machine dependent manner. (It may use internal algorithms
  28. to automatically locate and size all RAM, or it may use knowledge of
  29. the RAM in the machine, or any other method the boot loader designer
  30. sees fit.)
  31. 2. Initialise one serial port
  32. -----------------------------
  33. Existing boot loaders:
  34. OPTIONAL, RECOMMENDED
  35. New boot loaders:
  36. OPTIONAL, RECOMMENDED
  37. The boot loader should initialise and enable one serial port on the
  38. target. This allows the kernel serial driver to automatically detect
  39. which serial port it should use for the kernel console (generally
  40. used for debugging purposes, or communication with the target.)
  41. As an alternative, the boot loader can pass the relevant 'console='
  42. option to the kernel via the tagged lists specifying the port, and
  43. serial format options as described in
  44. Documentation/admin-guide/kernel-parameters.rst.
  45. 3. Detect the machine type
  46. --------------------------
  47. Existing boot loaders:
  48. OPTIONAL
  49. New boot loaders:
  50. MANDATORY except for DT-only platforms
  51. The boot loader should detect the machine type its running on by some
  52. method. Whether this is a hard coded value or some algorithm that
  53. looks at the connected hardware is beyond the scope of this document.
  54. The boot loader must ultimately be able to provide a MACH_TYPE_xxx
  55. value to the kernel. (see linux/arch/arm/tools/mach-types). This
  56. should be passed to the kernel in register r1.
  57. For DT-only platforms, the machine type will be determined by device
  58. tree. set the machine type to all ones (~0). This is not strictly
  59. necessary, but assures that it will not match any existing types.
  60. 4. Setup boot data
  61. ------------------
  62. Existing boot loaders:
  63. OPTIONAL, HIGHLY RECOMMENDED
  64. New boot loaders:
  65. MANDATORY
  66. The boot loader must provide either a tagged list or a dtb image for
  67. passing configuration data to the kernel. The physical address of the
  68. boot data is passed to the kernel in register r2.
  69. 4a. Setup the kernel tagged list
  70. --------------------------------
  71. The boot loader must create and initialise the kernel tagged list.
  72. A valid tagged list starts with ATAG_CORE and ends with ATAG_NONE.
  73. The ATAG_CORE tag may or may not be empty. An empty ATAG_CORE tag
  74. has the size field set to '2' (0x00000002). The ATAG_NONE must set
  75. the size field to zero.
  76. Any number of tags can be placed in the list. It is undefined
  77. whether a repeated tag appends to the information carried by the
  78. previous tag, or whether it replaces the information in its
  79. entirety; some tags behave as the former, others the latter.
  80. The boot loader must pass at a minimum the size and location of
  81. the system memory, and root filesystem location. Therefore, the
  82. minimum tagged list should look::
  83. +-----------+
  84. base -> | ATAG_CORE | |
  85. +-----------+ |
  86. | ATAG_MEM | | increasing address
  87. +-----------+ |
  88. | ATAG_NONE | |
  89. +-----------+ v
  90. The tagged list should be stored in system RAM.
  91. The tagged list must be placed in a region of memory where neither
  92. the kernel decompressor nor initrd 'bootp' program will overwrite
  93. it. The recommended placement is in the first 16KiB of RAM.
  94. 4b. Setup the device tree
  95. -------------------------
  96. The boot loader must load a device tree image (dtb) into system ram
  97. at a 64bit aligned address and initialize it with the boot data. The
  98. dtb format is documented in Documentation/devicetree/booting-without-of.rst.
  99. The kernel will look for the dtb magic value of 0xd00dfeed at the dtb
  100. physical address to determine if a dtb has been passed instead of a
  101. tagged list.
  102. The boot loader must pass at a minimum the size and location of the
  103. system memory, and the root filesystem location. The dtb must be
  104. placed in a region of memory where the kernel decompressor will not
  105. overwrite it, while remaining within the region which will be covered
  106. by the kernel's low-memory mapping.
  107. A safe location is just above the 128MiB boundary from start of RAM.
  108. 5. Load initramfs.
  109. ------------------
  110. Existing boot loaders:
  111. OPTIONAL
  112. New boot loaders:
  113. OPTIONAL
  114. If an initramfs is in use then, as with the dtb, it must be placed in
  115. a region of memory where the kernel decompressor will not overwrite it
  116. while also with the region which will be covered by the kernel's
  117. low-memory mapping.
  118. A safe location is just above the device tree blob which itself will
  119. be loaded just above the 128MiB boundary from the start of RAM as
  120. recommended above.
  121. 6. Calling the kernel image
  122. ---------------------------
  123. Existing boot loaders:
  124. MANDATORY
  125. New boot loaders:
  126. MANDATORY
  127. There are two options for calling the kernel zImage. If the zImage
  128. is stored in flash, and is linked correctly to be run from flash,
  129. then it is legal for the boot loader to call the zImage in flash
  130. directly.
  131. The zImage may also be placed in system RAM and called there. The
  132. kernel should be placed in the first 128MiB of RAM. It is recommended
  133. that it is loaded above 32MiB in order to avoid the need to relocate
  134. prior to decompression, which will make the boot process slightly
  135. faster.
  136. When booting a raw (non-zImage) kernel the constraints are tighter.
  137. In this case the kernel must be loaded at an offset into system equal
  138. to TEXT_OFFSET - PAGE_OFFSET.
  139. In any case, the following conditions must be met:
  140. - Quiesce all DMA capable devices so that memory does not get
  141. corrupted by bogus network packets or disk data. This will save
  142. you many hours of debug.
  143. - CPU register settings
  144. - r0 = 0,
  145. - r1 = machine type number discovered in (3) above.
  146. - r2 = physical address of tagged list in system RAM, or
  147. physical address of device tree block (dtb) in system RAM
  148. - CPU mode
  149. All forms of interrupts must be disabled (IRQs and FIQs)
  150. For CPUs which do not include the ARM virtualization extensions, the
  151. CPU must be in SVC mode. (A special exception exists for Angel)
  152. CPUs which include support for the virtualization extensions can be
  153. entered in HYP mode in order to enable the kernel to make full use of
  154. these extensions. This is the recommended boot method for such CPUs,
  155. unless the virtualisations are already in use by a pre-installed
  156. hypervisor.
  157. If the kernel is not entered in HYP mode for any reason, it must be
  158. entered in SVC mode.
  159. - Caches, MMUs
  160. The MMU must be off.
  161. Instruction cache may be on or off.
  162. Data cache must be off.
  163. If the kernel is entered in HYP mode, the above requirements apply to
  164. the HYP mode configuration in addition to the ordinary PL1 (privileged
  165. kernel modes) configuration. In addition, all traps into the
  166. hypervisor must be disabled, and PL1 access must be granted for all
  167. peripherals and CPU resources for which this is architecturally
  168. possible. Except for entering in HYP mode, the system configuration
  169. should be such that a kernel which does not include support for the
  170. virtualization extensions can boot correctly without extra help.
  171. - The boot loader is expected to call the kernel image by jumping
  172. directly to the first instruction of the kernel image.
  173. On CPUs supporting the ARM instruction set, the entry must be
  174. made in ARM state, even for a Thumb-2 kernel.
  175. On CPUs supporting only the Thumb instruction set such as
  176. Cortex-M class CPUs, the entry must be made in Thumb state.