요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
=================
Booting ARM Linux
=================
Author: Russell King
Date : 18 May 2002
The following documentation is relevant to 2.4.18-rmk6 and beyond.
In order to boot ARM Linux, you require a boot loader, which is a small
program that runs before the main kernel. The boot loader is expected
to initialise various devices, and eventually call the Linux kernel,
passing information to the kernel.
Essentially, the boot loader should provide (as a minimum) the
following:
1. Setup and initialise the RAM.
2. Initialise one serial port.
3. Detect the machine type.
4. Setup the kernel tagged list.
5. Load initramfs.
6. Call the kernel image.
1. Setup and initialise RAM
---------------------------
Existing boot loaders:
MANDATORY
New boot loaders:
MANDATORY
The boot loader is expected to find and initialise all RAM that the
kernel will use for volatile data storage in the system. It performs
this in a machine dependent manner. (It may use internal algorithms
to automatically locate and size all RAM, or it may use knowledge of
the RAM in the machine, or any other method the boot loader designer
sees fit.)
2. Initialise one serial port
-----------------------------
Existing boot loaders:
OPTIONAL, RECOMMENDED
New boot loaders:
OPTIONAL, RECOMMENDED
The boot loader should initialise and enable one serial port on the
target. This allows the kernel serial driver to automatically detect
which serial port it should use for the kernel console (generally
used for debugging purposes, or communication with the target.)
As an alternative, the boot loader can pass the relevant 'console='
option to the kernel via the tagged lists specifying the port, and
serial format options as described in
Documentation/admin-guide/kernel-parameters.rst.
3. Detect the machine type
--------------------------
Existing boot loaders:
OPTIONAL
New boot loaders:
MANDATORY except for DT-only platforms
The boot loader should detect the machine type its running on by some
method. Whether this is a hard coded value or some algorithm that
looks at the connected hardware is beyond the scope of this document.
The boot loader must ultimately be able to provide a MACH_TYPE_xxx
value to the kernel. (see linux/arch/arm/tools/mach-types). This
should be passed to the kernel in register r1.
For DT-only platforms, the machine type will be determined by device
tree. set the machine type to all ones (~0). This is not strictly
necessary, but assures that it will not match any existing types.
4. Setup boot data
------------------
Existing boot loaders:
OPTIONAL, HIGHLY RECOMMENDED
New boot loaders:
MANDATORY
The boot loader must provide either a tagged list or a dtb image for
passing configuration data to the kernel. The physical address of the
boot data is passed to the kernel in register r2.
4a. Setup the kernel tagged list
--------------------------------
The boot loader must create and initialise the kernel tagged list.
A valid tagged list starts with ATAG_CORE and ends with ATAG_NONE.
The ATAG_CORE tag may or may not be empty. An empty ATAG_CORE tag
has the size field set to '2' (0x00000002). The ATAG_NONE must set
the size field to zero.
Any number of tags can be placed in the list. It is undefined
whether a repeated tag appends to the information carried by the
previous tag, or whether it replaces the information in its
entirety; some tags behave as the former, others the latter.
The boot loader must pass at a minimum the size and location of
the system memory, and root filesystem location. Therefore, the
minimum tagged list should look::
+-----------+
base -> | ATAG_CORE | |
+-----------+ |
| ATAG_MEM | | increasing address
+-----------+ |
| ATAG_NONE | |
+-----------+ v
The tagged list should be stored in system RAM.
The tagged list must be placed in a region of memory where neither
the kernel decompressor nor initrd 'bootp' program will overwrite
it. The recommended placement is in the first 16KiB of RAM.
4b. Setup the device tree
-------------------------
The boot loader must load a device tree image (dtb) into system ram
at a 64bit aligned address and initialize it with the boot data. The
dtb format is documented at https://www.devicetree.org/specifications/.
The kernel will look for the dtb magic value of 0xd00dfeed at the dtb
physical address to determine if a dtb has been passed instead of a
tagged list.
The boot loader must pass at a minimum the size and location of the
system memory, and the root filesystem location. The dtb must be
placed in a region of memory where the kernel decompressor will not
overwrite it, while remaining within the region which will be covered
by the kernel's low-memory mapping.
A safe location is just above the 128MiB boundary from start of RAM.
5. Load initramfs.
------------------
Existing boot loaders:
OPTIONAL
New boot loaders:
OPTIONAL
If an initramfs is in use then, as with the dtb, it must be placed in
a region of memory where the kernel decompressor will not overwrite it
while also with the region which will be covered by the kernel's
low-memory mapping.
A safe location is just above the device tree blob which itself will
be loaded just above the 128MiB boundary from the start of RAM as
recommended above.
6. Calling the kernel image
---------------------------
Existing boot loaders:
MANDATORY
New boot loaders:
MANDATORY
There are two options for calling the kernel zImage. If the zImage
is stored in flash, and is linked correctly to be run from flash,
then it is legal for the boot loader to call the zImage in flash
directly.
The zImage may also be placed in system RAM and called there. The
kernel should be placed in the first 128MiB of RAM. It is recommended
that it is loaded above 32MiB in order to avoid the need to relocate
prior to decompression, which will make the boot process slightly
faster.
When booting a raw (non-zImage) kernel the constraints are tighter.
In this case the kernel must be loaded at an offset into system equal
to TEXT_OFFSET - PAGE_OFFSET.
In any case, the following conditions must be met:
- Quiesce all DMA capable devices so that memory does not get
corrupted by bogus network packets or disk data. This will save
you many hours of debug.
- CPU register settings
- r0 = 0,
- r1 = machine type number discovered in (3) above.
- r2 = physical address of tagged list in system RAM, or
physical address of device tree block (dtb) in system RAM
- CPU mode
All forms of interrupts must be disabled (IRQs and FIQs)
For CPUs which do not include the ARM virtualization extensions, the
CPU must be in SVC mode. (A special exception exists for Angel)
CPUs which include support for the virtualization extensions can be
entered in HYP mode in order to enable the kernel to make full use of
these extensions. This is the recommended boot method for such CPUs,
unless the virtualisations are already in use by a pre-installed
hypervisor.
If the kernel is not entered in HYP mode for any reason, it must be
entered in SVC mode.
- Caches, MMUs
The MMU must be off.
Instruction cache may be on or off.
Data cache must be off.
If the kernel is entered in HYP mode, the above requirements apply to
the HYP mode configuration in addition to the ordinary PL1 (privileged
kernel modes) configuration. In addition, all traps into the
hypervisor must be disabled, and PL1 access must be granted for all
peripherals and CPU resources for which this is architecturally
possible. Except for entering in HYP mode, the system configuration
should be such that a kernel which does not include support for the
virtualization extensions can boot correctly without extra help.
- The boot loader is expected to call the kernel image by jumping
directly to the first instruction of the kernel image.
On CPUs supporting the ARM instruction set, the entry must be
made in ARM state, even for a Thumb-2 kernel.
On CPUs supporting only the Thumb instruction set such as
Cortex-M class CPUs, the entry must be made in Thumb state.
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가 최소한 제공해야 하는 단계는 다음과 같습니다.
| 순서 | 작업 |
|---|---|
| 1 | RAM 설정과 초기화 |
| 2 | serial port 하나 초기화 |
| 3 | machine type 감지 |
| 4 | kernel tagged list 또는 device tree 설정 |
| 5 | initramfs load |
| 6 | kernel 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-125boot 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
base에서 높은 address 방향으로 세 tag를 연속 배치합니다.
tagged list는 system RAM에 저장합니다. kernel decompressor나 initrd `bootp` program이 덮어쓰지 않는 영역이어야 하며, 권장 위치는 RAM의 첫 16KiB 안입니다.
4b. Setup the device tree
126-143boot 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 시간을 크게 늘릴 수 있습니다.
| register | kernel 진입 값 |
|---|---|
| `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로 진입해야 합니다.
| 구성 요소 | 필수 상태 |
|---|---|
| MMU | off |
| instruction cache | on 또는 off |
| data cache | off |
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로 진입해야 합니다.
요약과 해설
booting.rst:1-237ARM boot protocol의 핵심은 boot data의 정확한 physical address와 kernel 진입 직전 hardware 상태입니다. `r1`은 machine type, `r2`는 ATAG 또는 DTB를 가리키며 MMU와 data cache는 꺼져 있어야 합니다.
decompressor overwrite를 피하면서 low-memory mapping 안에 유지하는 보수적 배치입니다.
최소 초기화와 정보 전달을 마친 뒤 image의 첫 instruction으로 직접 진입합니다.