summaryrefslogtreecommitdiffstats
path: root/woferclock/update_poundw_buckets
blob: de5667c4b6d3f56594f3812790ca334a6ddd39a7 (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
#!/usr/bin/python
#
# Copyright (c) 2018 Raptor Engineering, LLC
# Released under the terms of the AGPL v3
#
# NOTE:
# #V bucket layout documented in p9_pm_get_poundw_bucket.H,
# type vdmData_t

import sys
import binascii

def show_poundw_bucket_mode_data(mode_data, friendly_name):
    print "\t" + friendly_name + ":"
    sys.stdout.write("\t\t")
    count = 0
    for data in mode_data:
        sys.stdout.write(data + ", ")
        count = count + 1
        if (count > 20):
            print ""
            sys.stdout.write("\t\t")
            count = 0
    print ""

def parse_poundw_bucket(bucket_data):
    id = bucket_data[2:]
    data = map(''.join, zip(*[iter(bucket_data[2:])]*2))

    return id, data

def assemble_poundw_bucket(id, data):
    new_bucket_data = id + "".join(data)
    return new_bucket_data

source_bucket = int(sys.argv[1]) - 1
destination_bucket = int(sys.argv[2]) - 1
raw_data = sys.argv[3]

if (source_bucket < 0) or (source_bucket > 5):
    print "[ERROR] Invalid source bucket specified"
    sys.exit(1)

if (destination_bucket < 0) or (destination_bucket > 5):
    print "[ERROR] Invalid destination bucket specified"
    sys.exit(1)

if source_bucket == destination_bucket:
    print "[ERROR] Cannot copy to same destination bucket as origin bucket"
    sys.exit(1)

# #W buckets start at offset 4, and run for 60 bytes each
# 6 buckets are defined
bucket = ["", "", "", "", "", ""]
header = raw_data[:2]
version = header[:2]
bucket[0] = raw_data[2:124]
bucket[1] = raw_data[124:246]
bucket[2] = raw_data[246:368]
bucket[3] = raw_data[368:490]
bucket[4] = raw_data[490:612]
bucket[5] = raw_data[612:734]

print "#W data block update"
print "=========================================="
print "Header:\t\t" + header
print "Version:\t" + str(int(version, 16))
print ""
for index in range (0, 6):
    if bucket[index][2:].startswith("0000"):
        continue

    print "Bucket " + str(index + 1) + ":\t" + bucket[index]

    id, data = parse_poundw_bucket(bucket[index])
    show_poundw_bucket_mode_data(data, "VDM data")

    print ""

print "Copying and adjusting data from bucket " + str(source_bucket + 1) + " to bucket " + str(destination_bucket + 1)
if bucket[source_bucket][2:].startswith("0000"):
    print "[ERROR] Source bucket data not valid"
    sys.exit(1)

id, data = parse_poundw_bucket(bucket[source_bucket])
new_id = format(destination_bucket + 1, '02x')
bucket[destination_bucket] = assemble_poundw_bucket(new_id, data)

print "\tModified bucket:\t" + bucket[destination_bucket]
show_poundw_bucket_mode_data(data, "VDM data")

new_bucket_data = header + "".join(bucket)

search_binstring = binascii.unhexlify(raw_data)
replace_binstring = binascii.unhexlify(new_bucket_data)

with open("search.bin", 'wb') as f:
    f.write(search_binstring)
with open("replace.bin", 'wb') as f:
    f.write(replace_binstring)

print ""
OpenPOWER on IntegriCloud