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