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 ChehabThe following 64-byte header is present in decompressed Linux kernel image::
11638b642fSMauro Carvalho Chehab
12638b642fSMauro Carvalho Chehab	u32 code0;		  /* Executable code */
13638b642fSMauro Carvalho Chehab	u32 code1;		  /* Executable code */
14638b642fSMauro Carvalho Chehab	u64 text_offset;	  /* Image load offset, little endian */
15638b642fSMauro Carvalho Chehab	u64 image_size;		  /* Effective Image size, little endian */
16638b642fSMauro Carvalho Chehab	u64 flags;		  /* kernel flags, little endian */
17638b642fSMauro Carvalho Chehab	u32 version;		  /* Version of this header */
18638b642fSMauro Carvalho Chehab	u32 res1 = 0;		  /* Reserved */
19638b642fSMauro Carvalho Chehab	u64 res2 = 0;		  /* Reserved */
20638b642fSMauro Carvalho Chehab	u64 magic = 0x5643534952; /* Magic number, little endian, "RISCV" */
21185271a1SChester Lin	u32 magic2 = 0x05435352;  /* Magic number 2, little endian, "RSC\x05" */
221d5c17e4SAtish Patra	u32 res3;		  /* Reserved for PE COFF offset */
23638b642fSMauro Carvalho Chehab
24638b642fSMauro Carvalho ChehabThis header format is compliant with PE/COFF header and largely inspired from
25638b642fSMauro Carvalho ChehabARM64 header. Thus, both ARM64 & RISC-V header can be combined into one common
26638b642fSMauro Carvalho Chehabheader in future.
27638b642fSMauro Carvalho Chehab
28638b642fSMauro Carvalho ChehabNotes
29638b642fSMauro Carvalho Chehab=====
30638b642fSMauro Carvalho Chehab
31*180bb41dSAlexandre Ghiti- This header is also reused to support EFI stub for RISC-V. EFI specification
32*180bb41dSAlexandre Ghiti  needs PE/COFF image header in the beginning of the kernel image in order to
33*180bb41dSAlexandre Ghiti  load it as an EFI application. In order to support EFI stub, code0 is replaced
34*180bb41dSAlexandre Ghiti  with "MZ" magic string and res3(at offset 0x3c) points to the rest of the
35*180bb41dSAlexandre Ghiti  PE/COFF header.
36638b642fSMauro Carvalho Chehab
37638b642fSMauro Carvalho Chehab- version field indicate header version number
38638b642fSMauro Carvalho Chehab
39638b642fSMauro Carvalho Chehab	==========  =============
40638b642fSMauro Carvalho Chehab	Bits 0:15   Minor version
41638b642fSMauro Carvalho Chehab	Bits 16:31  Major version
42638b642fSMauro Carvalho Chehab	==========  =============
43638b642fSMauro Carvalho Chehab
44638b642fSMauro Carvalho Chehab  This preserves compatibility across newer and older version of the header.
457c672abcSLinus Torvalds  The current version is defined as 0.2.
46638b642fSMauro Carvalho Chehab
477c672abcSLinus Torvalds- The "magic" field is deprecated as of version 0.2.  In a future
487c672abcSLinus Torvalds  release, it may be removed.  This originally should have matched up
497c672abcSLinus Torvalds  with the ARM64 header "magic" field, but unfortunately does not.
507c672abcSLinus Torvalds  The "magic2" field replaces it, matching up with the ARM64 header.
51638b642fSMauro Carvalho Chehab
527c672abcSLinus Torvalds- In current header, the flags field has only one field.
53638b642fSMauro Carvalho Chehab
54638b642fSMauro Carvalho Chehab	=====  ====================================
55638b642fSMauro Carvalho Chehab	Bit 0  Kernel endianness. 1 if BE, 0 if LE.
56638b642fSMauro Carvalho Chehab	=====  ====================================
57638b642fSMauro Carvalho Chehab
58638b642fSMauro Carvalho Chehab- Image size is mandatory for boot loader to load kernel image. Booting will
59638b642fSMauro Carvalho Chehab  fail otherwise.
60