18c2ecf20Sopenharmony_ci================================= 28c2ecf20Sopenharmony_ciBoot image header in RISC-V Linux 38c2ecf20Sopenharmony_ci================================= 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci:Author: Atish Patra <atish.patra@wdc.com> 68c2ecf20Sopenharmony_ci:Date: 20 May 2019 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciThis document only describes the boot image header details for RISC-V Linux. 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciTODO: 118c2ecf20Sopenharmony_ci Write a complete booting guide. 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciThe following 64-byte header is present in decompressed Linux kernel image:: 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci u32 code0; /* Executable code */ 168c2ecf20Sopenharmony_ci u32 code1; /* Executable code */ 178c2ecf20Sopenharmony_ci u64 text_offset; /* Image load offset, little endian */ 188c2ecf20Sopenharmony_ci u64 image_size; /* Effective Image size, little endian */ 198c2ecf20Sopenharmony_ci u64 flags; /* kernel flags, little endian */ 208c2ecf20Sopenharmony_ci u32 version; /* Version of this header */ 218c2ecf20Sopenharmony_ci u32 res1 = 0; /* Reserved */ 228c2ecf20Sopenharmony_ci u64 res2 = 0; /* Reserved */ 238c2ecf20Sopenharmony_ci u64 magic = 0x5643534952; /* Magic number, little endian, "RISCV" */ 248c2ecf20Sopenharmony_ci u32 magic2 = 0x05435352; /* Magic number 2, little endian, "RSC\x05" */ 258c2ecf20Sopenharmony_ci u32 res3; /* Reserved for PE COFF offset */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciThis header format is compliant with PE/COFF header and largely inspired from 288c2ecf20Sopenharmony_ciARM64 header. Thus, both ARM64 & RISC-V header can be combined into one common 298c2ecf20Sopenharmony_ciheader in future. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciNotes 328c2ecf20Sopenharmony_ci===== 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci- This header can also be reused to support EFI stub for RISC-V in future. EFI 358c2ecf20Sopenharmony_ci specification needs PE/COFF image header in the beginning of the kernel image 368c2ecf20Sopenharmony_ci in order to load it as an EFI application. In order to support EFI stub, 378c2ecf20Sopenharmony_ci code0 should be replaced with "MZ" magic string and res3(at offset 0x3c) should 388c2ecf20Sopenharmony_ci point to the rest of the PE/COFF header. 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci- version field indicate header version number 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci ========== ============= 438c2ecf20Sopenharmony_ci Bits 0:15 Minor version 448c2ecf20Sopenharmony_ci Bits 16:31 Major version 458c2ecf20Sopenharmony_ci ========== ============= 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci This preserves compatibility across newer and older version of the header. 488c2ecf20Sopenharmony_ci The current version is defined as 0.2. 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci- The "magic" field is deprecated as of version 0.2. In a future 518c2ecf20Sopenharmony_ci release, it may be removed. This originally should have matched up 528c2ecf20Sopenharmony_ci with the ARM64 header "magic" field, but unfortunately does not. 538c2ecf20Sopenharmony_ci The "magic2" field replaces it, matching up with the ARM64 header. 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci- In current header, the flags field has only one field. 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci ===== ==================================== 588c2ecf20Sopenharmony_ci Bit 0 Kernel endianness. 1 if BE, 0 if LE. 598c2ecf20Sopenharmony_ci ===== ==================================== 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci- Image size is mandatory for boot loader to load kernel image. Booting will 628c2ecf20Sopenharmony_ci fail otherwise. 63