-
Notifications
You must be signed in to change notification settings - Fork 0
/
components_test.go
147 lines (134 loc) · 4.17 KB
/
components_test.go
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package intelifd
import (
"github.com/stretchr/testify/assert"
"testing"
)
var (
testVTEntries = []VSCCEntry{
{Jid: 0x1840ef, Vscc: 0x20252025},
{Jid: 0x123456, Vscc: 0x42424242},
}
testVTBytes = []byte{
0xef, 0x40, 0x18, 0x00, 0x25, 0x20, 0x25, 0x20,
0x56, 0x34, 0x12, 0x00, 0x42, 0x42, 0x42, 0x42,
}
testFMBytes = []byte{
0x00, 0x0f, 0xa0, 0x00,
0x00, 0x0d, 0x40, 0x00,
0x00, 0x09, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x01, 0x10,
}
testFM = FM{
Raw: struct {
Flmstr1 uint32
Flmstr2 uint32
Flmstr3 uint32
Flmstr4 uint32
Flmstr5 uint32
}{
Flmstr1: 0xa00f00,
Flmstr2: 0x400d00,
Flmstr3: 0x800900,
Flmstr4: 0x000000,
Flmstr5: 0x10010100,
},
Master: MasterSection{
BIOS: MasterSectionEntry{
FlashDescriptorReadAccess: true,
FlashDescriptorWriteAccess: false,
HostCPUBIOSRegionReadAccess: true,
HostCPUBIOSRegionWriteAccess: true,
IntelMERegionReadAccess: true,
IntelMERegionWriteAccess: false,
GbERegionReadAccess: true,
GbERegionWriteAccess: true,
PlatformDataRegionReadAccess: false,
PlatformDataRegionWriteAccess: false,
ECRegionReadAccess: false,
ECRegionWriteAccess: false,
RequesterID: 0xF00,
},
ME: MasterSectionEntry{
FlashDescriptorReadAccess: true,
FlashDescriptorWriteAccess: false,
HostCPUBIOSRegionReadAccess: false,
HostCPUBIOSRegionWriteAccess: false,
IntelMERegionReadAccess: true,
IntelMERegionWriteAccess: true,
GbERegionReadAccess: true,
GbERegionWriteAccess: false,
PlatformDataRegionReadAccess: false,
PlatformDataRegionWriteAccess: false,
ECRegionReadAccess: false,
ECRegionWriteAccess: false,
RequesterID: 0xD00,
},
ETHERNET: MasterSectionEntry{
FlashDescriptorReadAccess: true,
FlashDescriptorWriteAccess: false,
HostCPUBIOSRegionReadAccess: false,
HostCPUBIOSRegionWriteAccess: false,
IntelMERegionReadAccess: false,
IntelMERegionWriteAccess: false,
GbERegionReadAccess: true,
GbERegionWriteAccess: true,
PlatformDataRegionReadAccess: false,
PlatformDataRegionWriteAccess: false,
ECRegionReadAccess: false,
ECRegionWriteAccess: false,
RequesterID: 0x900,
},
RESERVED: MasterSectionEntry{
FlashDescriptorReadAccess: false,
FlashDescriptorWriteAccess: false,
HostCPUBIOSRegionReadAccess: false,
HostCPUBIOSRegionWriteAccess: false,
IntelMERegionReadAccess: false,
IntelMERegionWriteAccess: false,
GbERegionReadAccess: false,
GbERegionWriteAccess: false,
PlatformDataRegionReadAccess: false,
PlatformDataRegionWriteAccess: false,
ECRegionReadAccess: false,
ECRegionWriteAccess: false,
RequesterID: 0,
},
EC: MasterSectionEntry{
FlashDescriptorReadAccess: true,
FlashDescriptorWriteAccess: false,
HostCPUBIOSRegionReadAccess: false,
HostCPUBIOSRegionWriteAccess: false,
IntelMERegionReadAccess: false,
IntelMERegionWriteAccess: false,
GbERegionReadAccess: false,
GbERegionWriteAccess: false,
PlatformDataRegionReadAccess: false,
PlatformDataRegionWriteAccess: false,
ECRegionReadAccess: true,
ECRegionWriteAccess: true,
RequesterID: 0x100,
},
},
}
)
func mockImage() []byte {
firmware := make([]byte, testImage16MB)
copy(firmware[:], testIFDBytes)
copy(firmware[0x10+flumapPosition:], testFlumap1)
copy(firmware[testIFDHeaderMapped.Flumap1.VTBA:], testVTBytes)
copy(firmware[testIFDHeaderMapped.Flmap1.MasterBase:], testFMBytes)
return firmware
}
func TestParseVT(t *testing.T) {
bs := mockImage()
entries, err := parseVT(&testIFDHeaderMapped, bs)
assert.Nil(t, err)
assert.Equal(t, testVTEntries, entries)
}
func TestParseFM(t *testing.T) {
bs := mockImage()
fm, err := parseFM(&testIFDHeaderMapped, bs)
assert.Nil(t, err)
assert.Equal(t, testFM, *fm)
}