Skip to content

Commit 569a079

Browse files
authored
[decode-syseeprom] When reading from DB, display CRC-32 and all Vendor Extensions (sonic-net#1497)
Changes when reading system EEPROM values from State DB (`decode-syseeprom -d`): - Display CRC-32 - Display all present vendor extensions - Display hex TLV code with lower-case `x` to match the output when reading directly from EEPROM - If a TLV code is not available, omit it from the output rather than displaying 'N/A' for all fields
1 parent 47d1a14 commit 569a079

File tree

2 files changed

+63
-32
lines changed

2 files changed

+63
-32
lines changed

scripts/decode-syseeprom

+28-11
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def print_eeprom_dict(tlv_dict):
6262
tlv_table_header = ['TLV Name', 'Code', 'Len', 'Value']
6363
tlv_table_body = []
6464
for tlv in tlv_dict['tlv_list']:
65-
tlv_table_body.append([tlv['name'], tlv['code'].upper(), tlv['length'], tlv['value']])
65+
tlv_table_body.append([tlv['name'], tlv['code'], tlv['length'], tlv['value']])
6666

6767
print(tabulate(tlv_table_body, tlv_table_header, tablefmt='simple'))
6868

@@ -91,16 +91,33 @@ def read_eeprom_from_db():
9191
tlv_dict['header']['length'] = tlv_header.get('Total Length', 'N/A')
9292

9393
tlv_dict['tlv_list'] = []
94-
for tlv_code in range(TlvInfoDecoder._TLV_CODE_PRODUCT_NAME, TlvInfoDecoder._TLV_CODE_SERVICE_TAG + 1):
95-
tlv_code_string = '0x{:02x}'.format(tlv_code)
96-
tlv_data = db.get_all(db.STATE_DB, '{}|{}'.format(EEPROM_INFO_TABLE, tlv_code_string))
97-
98-
tlv = {}
99-
tlv['code'] = tlv_code_string
100-
tlv['name'] = tlv_data.get('Name', 'N/A')
101-
tlv['length'] = tlv_data.get('Len', 'N/A')
102-
tlv['value'] = tlv_data.get('Value', 'N/A')
103-
tlv_dict['tlv_list'].append(tlv)
94+
concerned_tlvs = []
95+
concerned_tlvs.extend(range(TlvInfoDecoder._TLV_CODE_PRODUCT_NAME, TlvInfoDecoder._TLV_CODE_SERVICE_TAG + 1))
96+
concerned_tlvs.append(TlvInfoDecoder._TLV_CODE_VENDOR_EXT)
97+
concerned_tlvs.append(TlvInfoDecoder._TLV_CODE_CRC_32)
98+
for tlv_code in concerned_tlvs:
99+
tlv_code_string = '0x{:02X}'.format(tlv_code)
100+
101+
tlv_data = db.get_all(db.STATE_DB, '{}|{}'.format(EEPROM_INFO_TABLE, tlv_code_string.lower()))
102+
if not tlv_data:
103+
continue
104+
105+
if tlv_code == TlvInfoDecoder._TLV_CODE_VENDOR_EXT:
106+
num_vendor_ext = int(tlv_data.get('Num_vendor_ext', '0'))
107+
for i in range(num_vendor_ext):
108+
tlv = {}
109+
tlv['code'] = tlv_code_string
110+
tlv['name'] = tlv_data.get('Name_{}'.format(i), 'N/A')
111+
tlv['length'] = tlv_data.get('Len_{}'.format(i), 'N/A')
112+
tlv['value'] = tlv_data.get('Value_{}'.format(i), 'N/A')
113+
tlv_dict['tlv_list'].append(tlv)
114+
else:
115+
tlv = {}
116+
tlv['code'] = tlv_code_string
117+
tlv['name'] = tlv_data.get('Name', 'N/A')
118+
tlv['length'] = tlv_data.get('Len', 'N/A')
119+
tlv['value'] = tlv_data.get('Value', 'N/A')
120+
tlv_dict['tlv_list'].append(tlv)
104121

105122
checksum_valid = db.get(db.STATE_DB, '{}|{}'.format(EEPROM_INFO_TABLE, 'Checksum'), 'Valid')
106123
tlv_dict['checksum_valid'] = (checksum_valid == '1')

tests/decode_syseeprom_test.py

+35-21
Original file line numberDiff line numberDiff line change
@@ -87,40 +87,52 @@
8787
'value': '3.15.1.0'
8888
},
8989
{
90-
'code': '0x2a',
90+
'code': '0x2A',
9191
'name': 'MAC Addresses',
9292
'length': '2',
9393
'value': '384'
9494
},
9595
{
96-
'code': '0x2b',
96+
'code': '0x2B',
9797
'name': 'Manufacturer',
9898
'length': '5',
9999
'value': 'CET00'
100100
},
101101
{
102-
'code': '0x2c',
102+
'code': '0x2C',
103103
'name': 'Manufacture Country',
104104
'length': '2',
105105
'value': 'TH'
106106
},
107107
{
108-
'code': '0x2d',
108+
'code': '0x2D',
109109
'name': 'Vendor Name',
110110
'length': '4',
111111
'value': 'DELL'
112112
},
113113
{
114-
'code': '0x2e',
114+
'code': '0x2E',
115115
'name': 'Diag Version',
116116
'length': '8',
117117
'value': '3.25.4.1'
118118
},
119119
{
120-
'code': '0x2f',
120+
'code': '0x2F',
121121
'name': 'Service Tag',
122122
'length': '7',
123123
'value': 'F3CD9Z2'
124+
},
125+
{
126+
'code': '0xFD',
127+
'name': 'Vendor Extension',
128+
'length': '7',
129+
'value': ''
130+
},
131+
{
132+
'code': '0xFE',
133+
'name': 'CRC-32',
134+
'length': '4',
135+
'value': '0xAC518FB3'
124136
}
125137
],
126138
'checksum_valid': True
@@ -136,21 +148,23 @@ def test_print_eeprom_dict(self, capsys):
136148
Total Length: 170
137149
TLV Name Code Len Value
138150
------------------- ------ ----- --------------------------
139-
Product Name 0X21 8 S6100-ON
140-
Part Number 0X22 6 0F6N2R
141-
Serial Number 0X23 20 TH0F6N2RCET0007600NG
142-
Base MAC Address 0X24 6 0C:29:EF:CF:AC:A0
143-
Manufacture Date 0X25 19 07/07/2020 15:05:34
144-
Device Version 0X26 1 1
145-
Label Revision 0X27 3 A08
146-
Platform Name 0X28 26 x86_64-dell_s6100_c2538-r0
147-
ONIE Version 0X29 8 3.15.1.0
148-
MAC Addresses 0X2A 2 384
149-
Manufacturer 0X2B 5 CET00
150-
Manufacture Country 0X2C 2 TH
151-
Vendor Name 0X2D 4 DELL
152-
Diag Version 0X2E 8 3.25.4.1
153-
Service Tag 0X2F 7 F3CD9Z2
151+
Product Name 0x21 8 S6100-ON
152+
Part Number 0x22 6 0F6N2R
153+
Serial Number 0x23 20 TH0F6N2RCET0007600NG
154+
Base MAC Address 0x24 6 0C:29:EF:CF:AC:A0
155+
Manufacture Date 0x25 19 07/07/2020 15:05:34
156+
Device Version 0x26 1 1
157+
Label Revision 0x27 3 A08
158+
Platform Name 0x28 26 x86_64-dell_s6100_c2538-r0
159+
ONIE Version 0x29 8 3.15.1.0
160+
MAC Addresses 0x2A 2 384
161+
Manufacturer 0x2B 5 CET00
162+
Manufacture Country 0x2C 2 TH
163+
Vendor Name 0x2D 4 DELL
164+
Diag Version 0x2E 8 3.25.4.1
165+
Service Tag 0x2F 7 F3CD9Z2
166+
Vendor Extension 0xFD 7
167+
CRC-32 0xFE 4 0xAC518FB3
154168
155169
(checksum valid)
156170
'''

0 commit comments

Comments
 (0)