← Documents Documentation/arch/arm/booting.rst GitHub 원문 ↗

Linux 6.18.37 · Architecture

Booting ARM Linux

ARM boot loader가 준비해야 할 RAM·serial·machine ID·ATAG/DTB·initramfs와 kernel 진입 register·CPU 상태를 규정합니다.

Source pathDocumentation/arch/arm/booting.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

booting.rst:1-237

ARM boot protocol의 핵심은 boot data의 정확한 physical address와 kernel 진입 직전 hardware 상태입니다. `r1`은 machine type, `r2`는 ATAG 또는 DTB를 가리키며 MMU와 data cache는 꺼져 있어야 합니다.

권장 RAM 배치
영역권장 위치핵심 제약
ATAG listRAM의 첫 16KiBdecompressor와 initrd가 덮어쓰지 않음
kernel zImage첫 128MiB, 가능하면 32MiB 위relocation 비용 회피
DTBRAM 시작 + 128MiB 바로 위64bit alignment와 low-memory mapping
initramfsDTB 바로 위decompressor overwrite 회피

decompressor overwrite를 피하면서 low-memory mapping 안에 유지하는 보수적 배치입니다.

boot loader에서 kernel까지
RAM 초기화serial 초기화machine typeATAG 또는 DTBinitramfsDMA quiesceregister·CPU mode 설정kernel entry

최소 초기화와 정보 전달을 마친 뒤 image의 첫 instruction으로 직접 진입합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Booting ARM Linux

1-26

저자는 Russell King이고 문서 날짜는 2002년 5월 18일입니다. 내용은 2.4.18-rmk6 이후에 적용됩니다.

ARM Linux를 부팅하려면 main kernel보다 먼저 실행되는 작은 프로그램인 boot loader가 필요합니다. boot loader는 여러 device를 초기화하고 kernel에 정보를 전달하면서 최종적으로 Linux kernel을 호출합니다.

boot loader가 최소한 제공해야 하는 단계는 다음과 같습니다.

순서작업
1RAM 설정과 초기화
2serial port 하나 초기화
3machine type 감지
4kernel tagged list 또는 device tree 설정
5initramfs load
6kernel image 호출

1. Setup and initialise RAM

27-42
boot loader요구 수준
기존MANDATORY
신규MANDATORY

boot loader는 system에서 kernel이 volatile data 저장에 사용할 모든 RAM을 찾아 초기화해야 합니다. 이 과정은 machine에 따라 달라집니다. 모든 RAM의 위치와 크기를 자동으로 찾는 내부 algorithm, machine의 고정 RAM 정보 또는 boot loader 설계자가 적절하다고 판단한 다른 방법을 사용할 수 있습니다.

2. Initialise one serial port

43-62
boot loader요구 수준
기존OPTIONAL, RECOMMENDED
신규OPTIONAL, RECOMMENDED

boot loader는 target의 serial port 하나를 초기화하고 활성화하는 것이 좋습니다. 그러면 kernel serial driver가 kernel console로 사용할 port를 자동 감지할 수 있습니다. 이 console은 보통 debugging 또는 target과의 통신에 사용합니다.

대신 tagged list를 통해 관련 `console=` kernel option을 전달해 port와 serial format을 지정할 수 있습니다. option 형식은 `Documentation/admin-guide/kernel-parameters.rst`를 참고합니다.

3. Detect the machine type

63-81
boot loader요구 수준
기존OPTIONAL
신규DT-only platform을 제외하고 MANDATORY

boot loader는 실행 중인 machine type을 감지해야 합니다. hard-coded value를 쓰든 연결된 hardware를 조사하는 algorithm을 쓰든 구체적인 방법은 이 문서의 범위를 벗어납니다.

최종적으로 boot loader는 kernel에 `MACH_TYPE_xxx` 값을 제공할 수 있어야 합니다. 값 목록은 `linux/arch/arm/tools/mach-types`를 참고하며, 이 값은 register `r1`로 전달합니다.

DT-only platform은 device tree로 machine type을 결정합니다. 이때 machine type을 모든 bit가 1인 `~0`으로 설정합니다. 엄격한 필수 조건은 아니지만 기존 type과 일치하지 않음을 보장합니다.

4. Setup boot data

82-93
boot loader요구 수준
기존OPTIONAL, HIGHLY RECOMMENDED
신규MANDATORY

boot loader는 configuration data를 kernel에 넘기기 위해 tagged list 또는 DTB image 중 하나를 제공해야 합니다. boot data의 physical address는 register `r2`로 전달합니다.

4a. Setup the kernel tagged list

94-125

boot loader는 kernel tagged list를 만들고 초기화해야 합니다. 유효한 list는 `ATAG_CORE`로 시작해 `ATAG_NONE`으로 끝납니다. `ATAG_CORE`는 비어 있어도 되며, 비어 있으면 size field가 `2`, 즉 `0x00000002`입니다. `ATAG_NONE`의 size field는 0이어야 합니다.

list에는 tag를 원하는 수만큼 넣을 수 있습니다. 같은 tag를 반복했을 때 앞 tag의 정보를 덧붙이는지 전체를 교체하는지는 일반적으로 정의되어 있지 않으며, tag 종류마다 동작이 다릅니다.

최소한 system memory의 크기와 위치, root filesystem 위치를 전달해야 합니다. 따라서 최소 tagged list는 address가 증가하는 방향으로 `ATAG_CORE`, `ATAG_MEM`, `ATAG_NONE` 순서입니다.

              +-----------+
base ->        | ATAG_CORE |  |
              +-----------+  |
              | ATAG_MEM  |  | increasing address
              +-----------+  |
              | ATAG_NONE |  |
              +-----------+  v
최소 ATAG list
base: ATAG_COREATAG_MEMATAG_NONE: size 0

base에서 높은 address 방향으로 세 tag를 연속 배치합니다.

tagged list는 system RAM에 저장합니다. kernel decompressor나 initrd `bootp` program이 덮어쓰지 않는 영역이어야 하며, 권장 위치는 RAM의 첫 16KiB 안입니다.

4b. Setup the device tree

126-143

boot loader는 device tree image(DTB)를 64bit aligned physical address의 system RAM에 load하고 boot data로 초기화해야 합니다. DTB 형식은 `https://www.devicetree.org/specifications/`에 정의되어 있습니다.

kernel은 DTB physical address에서 magic value `0xd00dfeed`를 찾아 tagged list 대신 DTB가 전달되었는지 판별합니다.

DTB는 최소한 system memory의 크기와 위치, root filesystem 위치를 전달해야 합니다. kernel decompressor가 덮어쓰지 않으면서 kernel low-memory mapping이 덮는 영역 안에 두어야 합니다. 안전한 위치는 RAM 시작점에서 128MiB 경계를 막 지난 곳입니다.

5. Load initramfs.

144-160
boot loader요구 수준
기존OPTIONAL
신규OPTIONAL

initramfs를 사용한다면 DTB와 마찬가지로 kernel decompressor가 덮어쓰지 않고 kernel low-memory mapping 안에 포함되는 RAM 영역에 두어야 합니다.

권장 배치에서는 RAM 시작점 기준 128MiB 경계 바로 위에 DTB를 놓고, initramfs는 그 DTB 바로 위에 놓습니다.

6. Calling the kernel image

161-183
boot loader요구 수준
기존MANDATORY
신규MANDATORY

kernel `zImage`를 호출하는 방법은 두 가지입니다. flash에서 실행하도록 올바르게 link된 `zImage`가 flash에 있다면 boot loader가 그 image를 직접 호출해도 됩니다.

`zImage`를 system RAM에 놓고 그 위치에서 호출할 수도 있습니다. kernel은 RAM의 첫 128MiB 안에 두어야 하며, 압축 해제 전에 relocate하지 않아도 되도록 32MiB 위에 load하는 것을 권장합니다. 이렇게 하면 부팅이 조금 빨라집니다.

raw, 즉 non-zImage kernel은 제약이 더 엄격합니다. system 안에서 `TEXT_OFFSET - PAGE_OFFSET`과 같은 offset 위치에 kernel을 load해야 합니다.

Kernel entry conditions

184-237

어떤 image 형식이든 kernel에 진입하기 전에 모든 DMA-capable device를 quiesce해야 합니다. 그렇지 않으면 잘못된 network packet이나 disk data가 memory를 손상시켜 debugging 시간을 크게 늘릴 수 있습니다.

registerkernel 진입 값
`r0``0`
`r1`앞 단계에서 감지한 machine type number
`r2`system RAM의 tagged list 또는 device tree block(DTB)의 physical address

IRQ와 FIQ를 포함한 모든 interrupt를 비활성화해야 합니다. ARM virtualization extension이 없는 CPU는 SVC mode여야 하며 Angel에는 특별한 예외가 있습니다.

virtualization extension을 지원하는 CPU는 kernel이 기능을 완전히 활용하도록 HYP mode로 진입할 수 있고 이것이 권장 방식입니다. 다만 이미 설치된 hypervisor가 virtualization을 사용 중이면 예외입니다. 어떤 이유로든 HYP mode로 진입하지 않는다면 SVC mode로 진입해야 합니다.

구성 요소필수 상태
MMUoff
instruction cacheon 또는 off
data cacheoff

HYP mode로 진입할 때 위 요구는 일반 PL1 privileged kernel mode뿐 아니라 HYP mode 구성에도 적용됩니다. hypervisor로 향하는 모든 trap을 끄고, architecture가 허용하는 모든 peripheral과 CPU resource에 PL1 access를 부여해야 합니다. HYP mode 진입 자체를 제외하면 virtualization extension을 지원하지 않는 kernel도 별도 도움 없이 부팅할 수 있는 system 구성이어야 합니다.

boot loader는 kernel image의 첫 instruction으로 직접 jump해 image를 호출해야 합니다. ARM instruction set을 지원하는 CPU에서는 Thumb-2 kernel이라도 ARM state로 진입합니다. Cortex-M처럼 Thumb instruction set만 지원하는 CPU는 Thumb state로 진입해야 합니다.