-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_eeprom.py
143 lines (135 loc) · 5.7 KB
/
test_eeprom.py
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
# EEPROM initial test procedure
#
# - show beginning of test message on screen
# - if ic2bus is working
# # now let's see if eeprom has been flashed before by ubo
# # proceed to read the content of eeprom
# (1) First approach (requires reboot happened before)
# -> ls /proc/device-tree/hat/
# -> custom_0 custom_1 name product product_id product_ver uuid vendor
# - read content of these files; if they don't exist, then eeprom has not been setup yet
# (2) Second approach (no previos reboot required)
# sudo ./eepflash.sh -r -f=eeprom_readback.eep -t=24c32
# #convert eep file to text
# ./eepdump eeprom_readback.eep eeprom_setting_readback.txt
# # parse text file extract key values
# - check if it contains a valid serial number
# - extract serial number, uuid, etc
# - show in screen
# - return result = true
# - else:
# - generate a serial number to write to eeprom
# - control GPIO to allow write to EEPROM
# - write EEPRPM info and serial_number in test_report json file
# - validate write (read back and compare binary files hashes??)
# - show success with serial number on screen
# - return result = true
# - else:
# - show EEPROM error message
# - write EEPRPM into test_report json file
#
# "eeprom": {
# "model": "CAT24C32",
# "bus_address": "0x51",
# "test_result": true
# }
import time
import os
import sys
up_dir = os.path.dirname(os.path.abspath(__file__))+'/../../'
print(up_dir)
sys.path.append(up_dir)
from eeprom import *
def main():
""" Script to self test EEPROM"""
test_result = False
info = {}
print("starting eeprom test...")
e2p = EEPROM()
if e2p.bus_address:
# check if eeprom ic2bus is working
e2p.test_result = True
else:
e2p.test_result = False
print("no eeprom IC detected!")
time.sleep(1)
# abort test here...
return
try:
e2p.read_eeprom()
print("eeprom content read successfully! now parsing...")
info = e2p.parse_eeprom()
print("printing parsed readback eeprom info")
print("eeprom info: ", str(info))
if (info.get("product_uuid") is None):
# eeprom is blank
refresh_eeprom(e2p)
if (info.get("product_uuid") is not None):
# eeprom does not have product uuid OR has product uuid but it is all zeros
if (info.get("product_uuid") != '00000000-0000-0000-0000-000000000000'):
# epprom has non-zero product uuid
if info.get("custom_data"):
# it has some custom data in eeprom
cdata = info.get("custom_data")
if type(cdata) is dict:
serial_number = cdata.get("serial_number")
if serial_number:
# if eeprom custom data is not blank, then read the content
# and check if it contains a valid serial number
# show serial number on screem
print("Already has serial number: " + serial_number)
# save custom data content into serial_number.json file
cdata['eeprom'] = {'model': '24c32', 'bus_address': "0x50", 'test_result': e2p.test_result }
e2p.update_json(summary=cdata, f_json=serial_number+".json")
print("update json summary suceeded!")
time.sleep(2)
else:
print("Corrupt EEPROM content!")
time.sleep(1)
# TODO: ask user before erasing
refresh_eeprom(e2p)
else:
print("######eeprom has non-zero uuid but no custom data#####")
#generate a serial number
summary = e2p.gen_summary()
serial_number = summary["serial_number"]
# display serial on screen
print("Generated new serial number: ", serial_number)
#update eeprom with custom data that contains serial number
print("creating a new serial_number.json file for summary")
e2p.update_json(summary, f_json=serial_number+".json")
print("#### updating eeprom with summary only, preserving existing product data #####")
e2p.update_eeprom(f_json=serial_number + ".json")
except Exception as e:
print("Execption caught!")
print(e)
e2p.test_result = False
# display serial number on screen
if e2p.test_result:
# Display Test Result on LCD
print("EEPROM test passed!")
sys.exit(0)
else:
# Display Test Result on LCD
print("EEPROM test failed!")
sys.exit(1)
def refresh_eeprom(e2p):
print("Erasing EEPROM content...")
e2p.reset_eeprom()
summary = e2p.gen_summary()
serial_number = summary["serial_number"]
print("Generating serial number: ", serial_number)
#update eeprom with custom data that contains serial number
print("creating a new serial_number.json file for summary")
e2p.update_json(summary, f_json=serial_number+".json")
print("#### updating eeprom with summary only, preserving existing product data #####")
e2p.update_eeprom(f_json=serial_number + ".json", f_setting="eeprom_settings.txt")
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print('Interrupted')
try:
sys.exit(0)
except SystemExit:
os._exit(0)