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