162306a36Sopenharmony_ci=================================
262306a36Sopenharmony_ciBoot image header in RISC-V Linux
362306a36Sopenharmony_ci=================================
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci:Author: Atish Patra <atish.patra@wdc.com>
662306a36Sopenharmony_ci:Date:   20 May 2019
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciThis document only describes the boot image header details for RISC-V Linux.
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciThe following 64-byte header is present in decompressed Linux kernel image::
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci	u32 code0;		  /* Executable code */
1362306a36Sopenharmony_ci	u32 code1;		  /* Executable code */
1462306a36Sopenharmony_ci	u64 text_offset;	  /* Image load offset, little endian */
1562306a36Sopenharmony_ci	u64 image_size;		  /* Effective Image size, little endian */
1662306a36Sopenharmony_ci	u64 flags;		  /* kernel flags, little endian */
1762306a36Sopenharmony_ci	u32 version;		  /* Version of this header */
1862306a36Sopenharmony_ci	u32 res1 = 0;		  /* Reserved */
1962306a36Sopenharmony_ci	u64 res2 = 0;		  /* Reserved */
2062306a36Sopenharmony_ci	u64 magic = 0x5643534952; /* Magic number, little endian, "RISCV" */
2162306a36Sopenharmony_ci	u32 magic2 = 0x05435352;  /* Magic number 2, little endian, "RSC\x05" */
2262306a36Sopenharmony_ci	u32 res3;		  /* Reserved for PE COFF offset */
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciThis header format is compliant with PE/COFF header and largely inspired from
2562306a36Sopenharmony_ciARM64 header. Thus, both ARM64 & RISC-V header can be combined into one common
2662306a36Sopenharmony_ciheader in future.
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ciNotes
2962306a36Sopenharmony_ci=====
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci- This header is also reused to support EFI stub for RISC-V. EFI specification
3262306a36Sopenharmony_ci  needs PE/COFF image header in the beginning of the kernel image in order to
3362306a36Sopenharmony_ci  load it as an EFI application. In order to support EFI stub, code0 is replaced
3462306a36Sopenharmony_ci  with "MZ" magic string and res3(at offset 0x3c) points to the rest of the
3562306a36Sopenharmony_ci  PE/COFF header.
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci- version field indicate header version number
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci	==========  =============
4062306a36Sopenharmony_ci	Bits 0:15   Minor version
4162306a36Sopenharmony_ci	Bits 16:31  Major version
4262306a36Sopenharmony_ci	==========  =============
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci  This preserves compatibility across newer and older version of the header.
4562306a36Sopenharmony_ci  The current version is defined as 0.2.
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci- The "magic" field is deprecated as of version 0.2.  In a future
4862306a36Sopenharmony_ci  release, it may be removed.  This originally should have matched up
4962306a36Sopenharmony_ci  with the ARM64 header "magic" field, but unfortunately does not.
5062306a36Sopenharmony_ci  The "magic2" field replaces it, matching up with the ARM64 header.
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci- In current header, the flags field has only one field.
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci	=====  ====================================
5562306a36Sopenharmony_ci	Bit 0  Kernel endianness. 1 if BE, 0 if LE.
5662306a36Sopenharmony_ci	=====  ====================================
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci- Image size is mandatory for boot loader to load kernel image. Booting will
5962306a36Sopenharmony_ci  fail otherwise.
60