← Documents Documentation/arch/riscv/boot-image-header.rst GitHub 원문 ↗

Linux 6.18.37 · Architecture

Boot image header in RISC-V Linux

64-byte RISC-V kernel image header의 field, EFI stub, version과 endianness flag를 설명합니다.

Source pathDocumentation/arch/riscv/boot-image-header.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약과 해설

boot-image-header.rst:1-59

Boot loader는 little-endian 64-byte header에서 load offset과 필수 image size를 읽습니다. EFI stub은 같은 영역을 PE/COFF 진입부로 재사용하며 `magic2`가 version 0.2의 기준 magic입니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 =================================
2 Boot image header in RISC-V Linux
3 =================================
4
5 :Author: Atish Patra <[email protected]>
6 :Date: 20 May 2019
7
8 This document only describes the boot image header details for RISC-V Linux.
9
10 The following 64-byte header is present in decompressed Linux kernel image::
11
12 u32 code0; /* Executable code */
13 u32 code1; /* Executable code */
14 u64 text_offset; /* Image load offset, little endian */
15 u64 image_size; /* Effective Image size, little endian */
16 u64 flags; /* kernel flags, little endian */
17 u32 version; /* Version of this header */
18 u32 res1 = 0; /* Reserved */
19 u64 res2 = 0; /* Reserved */
20 u64 magic = 0x5643534952; /* Magic number, little endian, "RISCV" */
21 u32 magic2 = 0x05435352; /* Magic number 2, little endian, "RSC\x05" */
22 u32 res3; /* Reserved for PE COFF offset */
23
24 This header format is compliant with PE/COFF header and largely inspired from
25 ARM64 header. Thus, both ARM64 & RISC-V header can be combined into one common
26 header in future.
27
28 Notes
29 =====
30
31 - This header is also reused to support EFI stub for RISC-V. EFI specification
32 needs PE/COFF image header in the beginning of the kernel image in order to
33 load it as an EFI application. In order to support EFI stub, code0 is replaced
34 with "MZ" magic string and res3(at offset 0x3c) points to the rest of the
35 PE/COFF header.
36
37 - version field indicate header version number
38
39 ========== =============
40 Bits 0:15 Minor version
41 Bits 16:31 Major version
42 ========== =============
43
44 This preserves compatibility across newer and older version of the header.
45 The current version is defined as 0.2.
46
47 - The "magic" field is deprecated as of version 0.2. In a future
48 release, it may be removed. This originally should have matched up
49 with the ARM64 header "magic" field, but unfortunately does not.
50 The "magic2" field replaces it, matching up with the ARM64 header.
51
52 - In current header, the flags field has only one field.
53
54 ===== ====================================
55 Bit 0 Kernel endianness. 1 if BE, 0 if LE.
56 ===== ====================================
57
58 - Image size is mandatory for boot loader to load kernel image. Booting will
59 fail otherwise.
60

3. 한국어 전문 번역

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

RISC-V Linux boot image header

1-8

Atish Patra가 2019-05-20 작성한 이 문서는 RISC-V Linux boot image header의 세부 형식만 설명합니다.

64-byte header layout

9-22

압축 해제된 Linux kernel image의 시작에는 다음 64-byte header가 있습니다. Multi-byte field는 little-endian으로 저장됩니다.

u32 code0;                  /* Executable code */
u32 code1;                  /* Executable code */
u64 text_offset;          /* Image load offset, little endian */
u64 image_size;                  /* Effective Image size, little endian */
u64 flags;                  /* kernel flags, little endian */
u32 version;                  /* Version of this header */
u32 res1 = 0;                  /* Reserved */
u64 res2 = 0;                  /* Reserved */
u64 magic = 0x5643534952; /* Magic number, little endian, "RISCV" */
u32 magic2 = 0x05435352;  /* Magic number 2, little endian, "RSC\x05" */
u32 res3;                  /* Reserved for PE COFF offset */
FieldType의미
`code0`, `code1``u32`실행 코드
`text_offset``u64`Little-endian image load offset
`image_size``u64`Little-endian effective image size
`flags``u64`Little-endian kernel flags
`version``u32`Header version
`res1``u32`Reserved, 0
`res2``u64`Reserved, 0
`magic``u64``0x5643534952`, little-endian `RISCV`
`magic2``u32``0x05435352`, little-endian `RSC\x05`
`res3``u32`PE/COFF offset용 reserved field

PE/COFF 호환성

23-26

이 형식은 PE/COFF header와 호환되며 ARM64 header에서 크게 영향을 받았습니다. 따라서 향후 ARM64와 RISC-V header를 하나의 공통 header로 합칠 수 있습니다.

EFI stub 재사용

27-35

이 header는 RISC-V EFI stub 지원에도 재사용됩니다. EFI application으로 kernel을 load하려면 image 시작에 PE/COFF image header가 있어야 합니다.

EFI stub에서는 `code0`가 `MZ` magic string으로 바뀌고 offset `0x3c`의 `res3`가 나머지 PE/COFF header를 가리킵니다.

Header version

36-45

`version` field는 header version number를 나타내며 새 header와 이전 header 사이의 호환성을 유지합니다. 현재 version은 `0.2`입니다.

BitsVersion component
0:15Minor version
16:31Major version

Magic field 변경

46-50

`magic` field는 version `0.2`부터 deprecated이며 향후 제거될 수 있습니다. 원래 ARM64 header의 `magic`과 일치해야 했지만 그렇지 못했으므로, ARM64 header와 일치하는 `magic2`가 이를 대체합니다.

Kernel flags

51-56

현재 header의 `flags` field에는 endianness bit 하나만 있습니다.

Bit의미
0Kernel endianness: `1`은 BE, `0`은 LE

필수 image size

57-59

Boot loader가 kernel image를 load하려면 `image_size`가 반드시 제공되어야 하며, 없으면 boot에 실패합니다.