1638b642fSMauro Carvalho Chehab=================================
2638b642fSMauro Carvalho ChehabBoot image header in RISC-V Linux
3638b642fSMauro Carvalho Chehab=================================
4638b642fSMauro Carvalho Chehab
5638b642fSMauro Carvalho Chehab:Author: Atish Patra <atish.patra@wdc.com>
6638b642fSMauro Carvalho Chehab:Date:   20 May 2019
7638b642fSMauro Carvalho Chehab
8638b642fSMauro Carvalho ChehabThis document only describes the boot image header details for RISC-V Linux.
9638b642fSMauro Carvalho Chehab
10638b642fSMauro Carvalho ChehabTODO:
11638b642fSMauro Carvalho Chehab  Write a complete booting guide.
12638b642fSMauro Carvalho Chehab
13638b642fSMauro Carvalho ChehabThe following 64-byte header is present in decompressed Linux kernel image::
14638b642fSMauro Carvalho Chehab
15638b642fSMauro Carvalho Chehab	u32 code0;		  /* Executable code */
16638b642fSMauro Carvalho Chehab	u32 code1;		  /* Executable code */
17638b642fSMauro Carvalho Chehab	u64 text_offset;	  /* Image load offset, little endian */
18638b642fSMauro Carvalho Chehab	u64 image_size;		  /* Effective Image size, little endian */
19638b642fSMauro Carvalho Chehab	u64 flags;		  /* kernel flags, little endian */
20638b642fSMauro Carvalho Chehab	u32 version;		  /* Version of this header */
21638b642fSMauro Carvalho Chehab	u32 res1 = 0;		  /* Reserved */
22638b642fSMauro Carvalho Chehab	u64 res2 = 0;		  /* Reserved */
23638b642fSMauro Carvalho Chehab	u64 magic = 0x5643534952; /* Magic number, little endian, "RISCV" */
24185271a1SChester Lin	u32 magic2 = 0x05435352;  /* Magic number 2, little endian, "RSC\x05" */
25638b642fSMauro Carvalho Chehab	u32 res4;		  /* Reserved for PE COFF offset */
26638b642fSMauro Carvalho Chehab
27638b642fSMauro Carvalho ChehabThis header format is compliant with PE/COFF header and largely inspired from
28638b642fSMauro Carvalho ChehabARM64 header. Thus, both ARM64 & RISC-V header can be combined into one common
29638b642fSMauro Carvalho Chehabheader in future.
30638b642fSMauro Carvalho Chehab
31638b642fSMauro Carvalho ChehabNotes
32638b642fSMauro Carvalho Chehab=====
33638b642fSMauro Carvalho Chehab
34638b642fSMauro Carvalho Chehab- This header can also be reused to support EFI stub for RISC-V in future. EFI
35638b642fSMauro Carvalho Chehab  specification needs PE/COFF image header in the beginning of the kernel image
36638b642fSMauro Carvalho Chehab  in order to load it as an EFI application. In order to support EFI stub,
37638b642fSMauro Carvalho Chehab  code0 should be replaced with "MZ" magic string and res5(at offset 0x3c) should
38638b642fSMauro Carvalho Chehab  point to the rest of the PE/COFF header.
39638b642fSMauro Carvalho Chehab
40638b642fSMauro Carvalho Chehab- version field indicate header version number
41638b642fSMauro Carvalho Chehab
42638b642fSMauro Carvalho Chehab	==========  =============
43638b642fSMauro Carvalho Chehab	Bits 0:15   Minor version
44638b642fSMauro Carvalho Chehab	Bits 16:31  Major version
45638b642fSMauro Carvalho Chehab	==========  =============
46638b642fSMauro Carvalho Chehab
47638b642fSMauro Carvalho Chehab  This preserves compatibility across newer and older version of the header.
487c672abcSLinus Torvalds  The current version is defined as 0.2.
49638b642fSMauro Carvalho Chehab
507c672abcSLinus Torvalds- The "magic" field is deprecated as of version 0.2.  In a future
517c672abcSLinus Torvalds  release, it may be removed.  This originally should have matched up
527c672abcSLinus Torvalds  with the ARM64 header "magic" field, but unfortunately does not.
537c672abcSLinus Torvalds  The "magic2" field replaces it, matching up with the ARM64 header.
54638b642fSMauro Carvalho Chehab
557c672abcSLinus Torvalds- In current header, the flags field has only one field.
56638b642fSMauro Carvalho Chehab
57638b642fSMauro Carvalho Chehab	=====  ====================================
58638b642fSMauro Carvalho Chehab	Bit 0  Kernel endianness. 1 if BE, 0 if LE.
59638b642fSMauro Carvalho Chehab	=====  ====================================
60638b642fSMauro Carvalho Chehab
61638b642fSMauro Carvalho Chehab- Image size is mandatory for boot loader to load kernel image. Booting will
62638b642fSMauro Carvalho Chehab  fail otherwise.
63