Skip to content

Commit b03c036

Browse files
committed
Merge tag 'riscv/for-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fix from Paul Walmsley: "Last week, Palmer and I learned that there was an error in the RISC-V kernel image header format that could make it less compatible with the ARM64 kernel image header format. I had missed this error during my original reviews of the patch. The kernel image header format is an interface that impacts bootloaders, QEMU, and other user tools. Those packages must be updated to align with whatever is merged in the kernel. We would like to avoid proliferating these image formats by keeping the RISC-V header as close as possible to the existing ARM64 header. Since the arch/riscv patch that adds support for the image header was merged with our v5.3-rc1 pull request as commit 0f327f2 ("RISC-V: Add an Image header that boot loader can parse."), we think it wise to try to fix this error before v5.3 is released. The fix itself should be backwards-compatible with any project that has already merged support for premature versions of this interface. It primarily involves ensuring that the RISC-V image header has something useful in the same field as the ARM64 image header" * tag 'riscv/for-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: modify the Image header to improve compatibility with the ARM64 header
2 parents 36024fc + 474efec commit b03c036

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

Documentation/riscv/boot-image-header.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The following 64-byte header is present in decompressed Linux kernel image.
1818
u32 res1 = 0; /* Reserved */
1919
u64 res2 = 0; /* Reserved */
2020
u64 magic = 0x5643534952; /* Magic number, little endian, "RISCV" */
21-
u32 res3; /* Reserved for additional RISC-V specific header */
21+
u32 magic2 = 0x56534905; /* Magic number 2, little endian, "RSC\x05" */
2222
u32 res4; /* Reserved for PE COFF offset */
2323

2424
This header format is compliant with PE/COFF header and largely inspired from
@@ -37,13 +37,14 @@ Notes:
3737
Bits 16:31 - Major version
3838

3939
This preserves compatibility across newer and older version of the header.
40-
The current version is defined as 0.1.
40+
The current version is defined as 0.2.
4141

42-
- res3 is reserved for offset to any other additional fields. This makes the
43-
header extendible in future. One example would be to accommodate ISA
44-
extension for RISC-V in future. For current version, it is set to be zero.
42+
- The "magic" field is deprecated as of version 0.2. In a future
43+
release, it may be removed. This originally should have matched up
44+
with the ARM64 header "magic" field, but unfortunately does not.
45+
The "magic2" field replaces it, matching up with the ARM64 header.
4546

46-
- In current header, the flag field has only one field.
47+
- In current header, the flags field has only one field.
4748
Bit 0: Kernel endianness. 1 if BE, 0 if LE.
4849

4950
- Image size is mandatory for boot loader to load kernel image. Booting will

arch/riscv/include/asm/image.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#ifndef __ASM_IMAGE_H
44
#define __ASM_IMAGE_H
55

6-
#define RISCV_IMAGE_MAGIC "RISCV"
6+
#define RISCV_IMAGE_MAGIC "RISCV\0\0\0"
7+
#define RISCV_IMAGE_MAGIC2 "RSC\x05"
78

89
#define RISCV_IMAGE_FLAG_BE_SHIFT 0
910
#define RISCV_IMAGE_FLAG_BE_MASK 0x1
@@ -23,7 +24,7 @@
2324
#define __HEAD_FLAGS (__HEAD_FLAG(BE))
2425

2526
#define RISCV_HEADER_VERSION_MAJOR 0
26-
#define RISCV_HEADER_VERSION_MINOR 1
27+
#define RISCV_HEADER_VERSION_MINOR 2
2728

2829
#define RISCV_HEADER_VERSION (RISCV_HEADER_VERSION_MAJOR << 16 | \
2930
RISCV_HEADER_VERSION_MINOR)
@@ -39,9 +40,8 @@
3940
* @version: version
4041
* @res1: reserved
4142
* @res2: reserved
42-
* @magic: Magic number
43-
* @res3: reserved (will be used for additional RISC-V specific
44-
* header)
43+
* @magic: Magic number (RISC-V specific; deprecated)
44+
* @magic2: Magic number 2 (to match the ARM64 'magic' field pos)
4545
* @res4: reserved (will be used for PE COFF offset)
4646
*
4747
* The intention is for this header format to be shared between multiple
@@ -58,7 +58,7 @@ struct riscv_image_header {
5858
u32 res1;
5959
u64 res2;
6060
u64 magic;
61-
u32 res3;
61+
u32 magic2;
6262
u32 res4;
6363
};
6464
#endif /* __ASSEMBLY__ */

arch/riscv/kernel/head.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ ENTRY(_start)
3939
.word RISCV_HEADER_VERSION
4040
.word 0
4141
.dword 0
42-
.asciz RISCV_IMAGE_MAGIC
43-
.word 0
42+
.ascii RISCV_IMAGE_MAGIC
4443
.balign 4
44+
.ascii RISCV_IMAGE_MAGIC2
4545
.word 0
4646

4747
.global _start_kernel

0 commit comments

Comments
 (0)