]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/FirmwareStorageFormat/SectionHeader.py
ee6a63679d89cec8f8dc7df979d8c4f75f63b374
[mirror_edk2.git] / BaseTools / Source / Python / FirmwareStorageFormat / SectionHeader.py
1 ## @file
2 # This file is used to define the Section Header C Struct.
3 #
4 # Copyright (c) 2021-, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
6 ##
7 from struct import *
8 from ctypes import *
9 from FirmwareStorageFormat.Common import *
10
11 EFI_COMMON_SECTION_HEADER_LEN = 4
12 EFI_COMMON_SECTION_HEADER2_LEN = 8
13
14 class EFI_COMMON_SECTION_HEADER(Structure):
15 _pack_ = 1
16 _fields_ = [
17 ('Size', ARRAY(c_uint8, 3)),
18 ('Type', c_uint8),
19 ]
20
21 @property
22 def SECTION_SIZE(self) -> int:
23 return self.Size[0] | self.Size[1] << 8 | self.Size[2] << 16
24
25 def Common_Header_Size(self) -> int:
26 return 4
27
28 class EFI_COMMON_SECTION_HEADER2(Structure):
29 _pack_ = 1
30 _fields_ = [
31 ('Size', ARRAY(c_uint8, 3)),
32 ('Type', c_uint8),
33 ('ExtendedSize', c_uint32),
34 ]
35
36 @property
37 def SECTION_SIZE(self) -> int:
38 return self.ExtendedSize
39
40 def Common_Header_Size(self) -> int:
41 return 8
42
43 class EFI_COMPRESSION_SECTION(Structure):
44 _pack_ = 1
45 _fields_ = [
46 ('UncompressedLength', c_uint32),
47 ('CompressionType', c_uint8),
48 ]
49
50 def ExtHeaderSize(self) -> int:
51 return 5
52
53 class EFI_FREEFORM_SUBTYPE_GUID_SECTION(Structure):
54 _pack_ = 1
55 _fields_ = [
56 ('SubTypeGuid', GUID),
57 ]
58
59 def ExtHeaderSize(self) -> int:
60 return 16
61
62 class EFI_GUID_DEFINED_SECTION(Structure):
63 _pack_ = 1
64 _fields_ = [
65 ('SectionDefinitionGuid', GUID),
66 ('DataOffset', c_uint16),
67 ('Attributes', c_uint16),
68 ]
69
70 def ExtHeaderSize(self) -> int:
71 return 20
72
73 def Get_USER_INTERFACE_Header(nums: int):
74 class EFI_SECTION_USER_INTERFACE(Structure):
75 _pack_ = 1
76 _fields_ = [
77 ('FileNameString', ARRAY(c_uint16, nums)),
78 ]
79
80 def ExtHeaderSize(self) -> int:
81 return 2 * nums
82
83 def GetUiString(self) -> str:
84 UiString = ''
85 for i in range(nums):
86 if self.FileNameString[i]:
87 UiString += chr(self.FileNameString[i])
88 return UiString
89
90 return EFI_SECTION_USER_INTERFACE
91
92 def Get_VERSION_Header(nums: int):
93 class EFI_SECTION_VERSION(Structure):
94 _pack_ = 1
95 _fields_ = [
96 ('BuildNumber', c_uint16),
97 ('VersionString', ARRAY(c_uint16, nums)),
98 ]
99
100 def ExtHeaderSize(self) -> int:
101 return 2 * (nums+1)
102
103 def GetVersionString(self) -> str:
104 VersionString = ''
105 for i in range(nums):
106 if self.VersionString[i]:
107 VersionString += chr(self.VersionString[i])
108 return VersionString
109
110 return EFI_SECTION_VERSION