ARM Linux Kernel Booting 에 대한 이해

아래 내용은 Linux Kernel 3.14.2 의 Document/arm/Booting 을 번역해 본 것임.
중간 중간 약간 이해가 안되는 부분이 있고 현재 kernel 버전과 안맞는 부분이 있는 것 같긴 하지만 흐름은 읽을 수 있음.

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.

-> ARM Linux 를 부팅하기 위해서는 boot loader 가 있어야 한다.
     boot loader 는 main kernel 이전에 동작하는 프로그램이다.
     boot loader 는 다양한 device 들을 초기화하고, 마지막으로 linux kernel 을
    호출하면서 정보를 kernel 에게 전달한다.

Essentially, the boot loader should provide (as a minimum) thefollowing:

-> boot loader 는 필수적으로 최소한 다음 사항을 제공해야 한다.

1. Setup and initialise the RAM.  -> RAM 을 setup 하고 초기화
2. Initialise one serial port.         -> 하나의 serial 포트를 초기화
3. Detect the machine type.        -> machine type 을 감지
4. Setup the kernel tagged list.   -> kernel tagged list 를 setup (atag)
5. Load initramfs.                     -> 램디스크 로딩
6. Call the kernel image.           -> 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.)

-> boot loader 는 kernel 이 임시 data 저장 용도로 사용할 모든 RAM 을 찾아서
   초기화한다. boot loader 는 이 작업을 machine 에 따라 다른 방법으로 수행한다.
   (boot loader 는 모든 RAM 을 자동으로 배치하고 사이징하는 내부 알고리즘을
    이용할 것이다. 또는 boot loader 설계자가 괜찮다고 생각하는 다른 방법을 이용할
    수도 있다.)

 

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.)

-> boot loader 는 target 에 있는 하나의 serial 포트를 초기화하고 enable 해야 한다.
   그러면, kernel serial 드라이버가 자동으로 kernel console 을 위해 어떤 serial 포트를
   사용해야 하는지 자동으로 감지할 수 있다.
   (일반적으로 debugging 이나 taget 과의 통신에 사용된다.)

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

-> boot loader 는 'console=' 옵션을 통해 포트를 지정하여 kernel 에 tagged list 형태로
    전달할 수 있다. serial 에 대한 포맷 옵션을 아래 파일에 기술했다.

Documentation/kernel-parameters.txt.

 

3. Detect the machine type
--------------------------

Existing boot loaders:          OPTIONAL
New boot loaders:               MANDATORY

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).

-> boot loader 는 자신이 동작하고 있는 machine thpe 을 감지해야 한다.
    이러한 감지 방법이 하드코딩되어 있건, 아니면 어떤 알고리즘으로 되어 있건 간에
    이는 이 문서 범위를 넘어가므로 다루지 않는다.
    boot loader 는 최종적으로는 kernel 에게 MACH_TYPE_xxx 값을 제공해야 한다.
    (linux/arch/arm/tools/mach-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.

-> boot loader 는 kernel 에게 설정데이터를 넘기기 위해 tagged list 또는
    dtb 이미지를 전달해야 한다.
    이러한 boot 데이터의 물리주소는 r2 레지스터에 담겨서 kernel 에 전달된다.

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.

-> boot loader 는 kernel tagged list 를 생성하고 초기화해야 한다.
    tagged list 는 ATAG_CORE 로 시작하고 ATAG_NONE 으로 끝나야 한다.
    ATAG_CORE tag 는 공란으로 두어도 상관없다.
    공란의 ATAG_CORE tag 는 size 필드가 2 로 설정된다.
    ATAG_NONE tag 는 size 필드를 0 으로 설정해야 한다.

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.

-> tagged list 에는 제한없이 많은 수의 tag 들을 설정할 수 있다.
    중복된 tag 의 경우 이전의 tag 정보에 덧붙여지는지, 아니면 완전히 교체되는지
    정의되지는 않았다.
    일부 tag 는 덧붙여지는 형태로, 일부 tag 는 교체되는 형태로 동작한다.

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:

-> boot loader 는 최소한 시스템 메모리의 크기와 위치, root 파일시스템 위치는 
    전달해주어야 한다. 따라서, 최소의 tagged list 는 다음과 같은 형태여야 한다.

+-------------+
base -> | ATAG_CORE |  |
+-------------+  |
| ATAG_MEM  |  | increasing address
+-------------+  |
| ATAG_NONE |  |
+-------------+  v

The tagged list should be stored in system RAM.

-> tagged list 는 시스템 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 16KB of RAM.

-> tagged list 는 kernel 의 압축해제나 initrd 'bootp' 프로그램이 덮어쓰지
   않을 메모리 영역에 위치시켜야 한다. RAM 의 첫 16 KB 이내에 저장해두는 것을 권장한다.

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 in Documentation/devicetree/booting-without-of.txt.
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.

-> boot loader 는 시스템 RAM 에 64 bit align 을 맞추어서 dtb 를 로드해야 한다.
   그리고, 이를 boot data 로 초기화해야 한다.
   dtb 포맷은 Documentation/devicetree/booting-without-of.txt 파일을 참고하라.
   kernel 은 tagged list 대신 dtb 가 전달되었는지를 확인하기 위해
   dtb 물리 주소에서 magic 넘버값이 0xd00dfeed 인지를 확인한다.

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, whilst remaining within the region which will be covered
by the kernel's low-memory mapping.

-> boot loader 는 최소한 시스템 메모리의 크기와 위치, root 파일시스템 위치는
    전달해주어야 한다. 그리고, kernel 압축해제 시 덮어써지지 않을 위치에 저장해두어야 한다.

A safe location is just above the 128MiB boundary from start of RAM.

-> RAM 의 128 MB 를 초과하는 곳이 안전하다.

 

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.

-> kernel zImage 를 호출하는 방법은 2 가지가 있다. zImage 가
    flash 에 저장되어 있고 flash 가 잘 연결이 되어 있으면 boot loader 가
    직접 flash 의 zImage 를 호출할 수 있다.

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.

-> 또한 zImage 를 RAM 에 위치시키고 이를 호출할 수도 있다.
    kernel 은 RAM 의 처음 128 MB 위치 내에 저장해야 한다.
    boot 과정을 좀더 빠르게 수행하기 위해 kernel 합축해제 방법을 사용하는데, 
    이러한 압축해제 수행 전에 재배치를 할 필요가 없도록 zImage 는 32 MB 를 넘는 곳에
    로딩하는 것을 권장한다.

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.

-> 압축된 zImage 가 아닌 row kernel 로 부팅할 경우에는 제약사항이 더욱 tight 하다.
    이 경우는 kernel 은 TEXT_OFFSET - PAGE_OFFSET 의 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.

  -> memory 가 잘못된 network 패킷이나 disk 데이터에 의해 손상되지 않도록
      모든 DMA device 들을 정지시켜라. 그러면, debugging 시간을 절약할 수 있다.

- 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)

-> 모든 interrupt 들은 disable 상태여야 한다. (IRQ 와 FIQ 모두)

For CPUs which do not include the ARM virtualization extensions, the
CPU must be in SVC mode.  (A special exception exists for Angel)

-> ARM 가상화 확장기능을 포함하지 않는 CPU 들의 경우 SVC(Supervisor) 모드여야 한다.
     (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.

  -> 가상화 확장기능을 지원하는 CPU 들은 HYP 모드로 진입할 수 있는데,
      이는 kernel 로 하여금 그런 확장기능들을 완전히 이용할 수 있도록 하기 위함이다.

If the kernel is not entered in HYP mode for any reason, it must be entered in SVC mode.

  -> 어떤 이유로 kernel 이 HYP 모드로 들어가지 못하면 SVC 모드로 들어가야 한다.
      (HYP 모드는 SVC 모드보다 더 특권이 강화된 모드임)

- Caches, MMUs

The MMU must be off.

  -> MMU 는 off 되어야 한다.

Instruction cache may be on or off.

  -> 명령어 Cache 는 on 또는 off 일 수 있다.

Data cache must be off.

  -> 데이터 Cache 는 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.

  -> kernel 이 HYP 모드로 들어가면 일반적인 kernel 특권모드 설정에다가
      위의 조건들이 추가로 HYP 모드 설정에 추가로 적용된다. ...

- The boot loader is expected to call the kernel image by jumping
directly to the first instruction of the kernel image.

  -> boot loader 는 kernel image 의 첫번째 instruction 으로 직접
      jump 함으로써 kernel image 를 호출한다.

 

On CPUs supporting the ARM instruction set, the entry must be
made in ARM state, even for a Thumb-2 kernel.

  -> CPU 가 ARM 명령어셋을 지원할 경우에는 kernel 로의 진입 시
      ARM 상태여야 한다. (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.

  -> Cortex-M class 의 CPU 들처럼 CPU 가 Thumb 명령어 셋만을 지원할 경우
      kernel 진입 시에는 Thumb 상태이어야 한다.

 

booting 관련 참고  : http://blog.dasomoli.org/318

 

You may also like...

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x