summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/FirmwareKit/EPM.h
blob: d95ec9032b101752fc87834ab5aef7a5640525c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* -------------------------------------------

	Copyright (C) 2024, t& Corporation, all rights reserved.

------------------------------------------- */

/**
	@brief The Explicit Partition Map scheme.
*/

#ifndef FIRMWAREKIT_EPM_H
#define FIRMWAREKIT_EPM_H

#include <NewKit/Defines.h>

#define kEPMNameLength		 (32)
#define kEPMFilesystemLength (16)
#define kEPMMagicLength		 (5)

/* @brief AMD64 magic for EPM */
#define kEPMMagic86 "EPMAM"

/* @brief RISC-V magic for EPM */
#define kEPMMagicRISCV "EPMRV"

/* @brief ARM magic for EPM */
#define kEPMMagicARM "EPMAR"

/* @brief 64x0 magic for EPM */
#define kEPMMagic64k "EPM64"

/* @brief 32x0 magic for EPM */
#define kEPMMagic32k "EPM32"

/* @brief POWER magic for EPM */
#define kEPMMagicPPC "EPMPC"

/* @brief Invalid magic for EPM */
#define kEPMMagicError "EPM??"

#ifdef __ZKA_AMD64__
#define kEPMMagic kEPMMagic86
#else
#ifdef __ZKA_ARM64__
#define kEPMMagic kEPMMagicARM
#else
#define kEPMMagic kEPMMagicError
#endif
#endif

///! @brief partition must start at this address.
///! Anything below is reserved for Data backup by the Main OS.
#define kEPMPartBlockLba (sizeof(EPM_PART_BLOCK))

///! @brief Current EPM revision.
#define kEPMRevisionBcd (0x0100)

/// !@brief EPM boot block address.
#define kEPMBootBlockLba (0U)

#define kEPMReserveLen (401)

struct EPM_GUID;
struct EPM_PART_BLOCK;

/* The first 0 > 128 addresses of a disk contains these headers. */

/// @brief EPM GUID structure.
typedef struct EPM_GUID
{
	Kernel::UInt32 Data1;
	Kernel::UInt16 Data2;
	Kernel::UInt16 Data3;
	Kernel::UInt8  Data4[8];
} EPM_GUID;

/**
 * @brief The EPM boot block.
 * @note NumBlock and LbaStart are ignored on some platforms.
 */
struct PACKED EPM_PART_BLOCK
{
	Kernel::Char  Magic[kEPMMagicLength];
	Kernel::Char  Name[kEPMNameLength];
	EPM_GUID	  Guid;
	Kernel::Int32 Version;
	Kernel::Int64 NumBlocks;
	Kernel::Int64 SectorSz;
	Kernel::Int64 LbaStart; // base offset
	Kernel::Int64 LbaEnd;	// addition of lba_start to get the end of partition.
	Kernel::Int16 Kind;
	Kernel::Int32 FsVersion;
	Kernel::Char  Fs[kEPMFilesystemLength]; /* NeFS, ffs2... */
	Kernel::Char  Reserved[kEPMReserveLen]; // to fill a full sector.
};

///! @brief Version kind enum.
///! @brief Use in boot block version field.

enum
{
	kEPMInvalid	  = 0x00,
	kEPMGenericOS = 0xcf, // Generic OS
	kEPMLinux	  = 0x8f, // Linux on EPM
	kEPMBSD		  = 0x9f, // Berkeley Soft. Distribution
	kEPMZkaOS	  = 0x1f, // This OS.
	kEPMInvalidOS = 0xff,
};

typedef struct EPM_PART_BLOCK BOOT_BLOCK_STRUCT;

#endif // ifndef FIRMWAREKIT_EPM_H