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
|
#!/usr/bin/env python3
import sys
import argparse
ramconfigs = {
'mba42': (
'2b_hynix',
None,
'4g_hynix',
None,
'2g_samsung',
None,
'4g_samsung',
None,
'2g_micron',
None,
None,
None,
None,
None,
'4g_elpida',
),
'mba52': (
'4g_hynix',
None,
'8g_hynix',
None,
'4g_samsung',
None,
'8g_samsung',
None,
None,
None,
None,
None,
'4g_elpida',
None,
'8g_elpida',
),
'mbp101': (
'4g_hynix_1600s',
'1g_samsung_1600',
'4g_samsung_1600s',
'1g_hynix_1600',
'4g_elpida_1600s',
'2g_samsung_1600',
'2g_samsung_1333',
'2g_hynix_1600',
'4g_samsung_1600',
'4g_hynix_1600',
'2g_elpida_1600s',
'2g_elpida_1600',
'4g_elpida_1600',
'2g_samsung_1600s',
'2g_hynix_1600s'
)
}
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-m', '--model',
choices=list(ramconfigs.keys()),
help='MacBook model',
required=True)
args = parser.parse_args()
configs = ramconfigs[args.model]
reg = None
for line in sys.stdin:
line = line.strip()
if not line.endswith('(GPIO_LVL3)'):
continue
reg = int(line.split(' ')[1], 16)
break
if reg is None:
raise Exceptions("failed to parse gpio registers")
# GPIO68..GPIO71
ramcfg = (reg >> 4) & 0xf
# reverse bit order
ramcfg = int('{:04b}'.format(ramcfg)[::-1], 2)
if ramcfg >= len(configs) or configs[ramcfg] is None:
print("unsupported memory configuration %d" % ramcfg)
else:
print("%s (RAMCFG=%01x)" % (configs[ramcfg], ramcfg))
if __name__ == '__main__':
main()
|