2021-10-17 11:03:02 -05:00
|
|
|
#
|
|
|
|
# Copyright (c) 2017-2021 NVIDIA CORPORATION & AFFILIATES.
|
|
|
|
# Apache-2.0
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
2017-02-27 02:13:36 -06:00
|
|
|
#############################################################################
|
|
|
|
# Mellanox
|
|
|
|
#
|
|
|
|
# Platform and model specific eeprom subclass, inherits from the base class,
|
|
|
|
# and provides the followings:
|
|
|
|
# - the eeprom format definition
|
|
|
|
# - specific encoder/decoder if there is special need
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
try:
|
|
|
|
import binascii
|
|
|
|
import time
|
|
|
|
import optparse
|
|
|
|
import warnings
|
|
|
|
import os
|
|
|
|
import sys
|
2018-12-04 09:42:03 -06:00
|
|
|
import syslog
|
2020-11-25 12:28:36 -06:00
|
|
|
|
|
|
|
if sys.version_info.major == 3:
|
|
|
|
from io import StringIO
|
|
|
|
else:
|
|
|
|
from cStringIO import StringIO
|
|
|
|
|
2017-04-13 06:07:44 -05:00
|
|
|
from sonic_eeprom import eeprom_base
|
|
|
|
from sonic_eeprom import eeprom_tlvinfo
|
2020-08-03 13:43:12 -05:00
|
|
|
from sonic_py_common.device_info import get_machine_info
|
2017-02-27 02:13:36 -06:00
|
|
|
import subprocess
|
2020-11-25 12:28:36 -06:00
|
|
|
except ImportError as e:
|
|
|
|
raise ImportError(str(e) + "- required module not found")
|
2017-02-27 02:13:36 -06:00
|
|
|
|
2018-11-29 15:36:13 -06:00
|
|
|
SYSLOG_IDENTIFIER = "eeprom.py"
|
2019-03-06 20:51:46 -06:00
|
|
|
EEPROM_SYMLINK = "/var/run/hw-management/eeprom/vpd_info"
|
2018-11-29 15:36:13 -06:00
|
|
|
CACHE_FILE = "/var/cache/sonic/decode-syseeprom/syseeprom_cache"
|
|
|
|
|
2020-11-25 12:28:36 -06:00
|
|
|
|
2018-11-29 15:36:13 -06:00
|
|
|
def log_error(msg):
|
|
|
|
syslog.openlog(SYSLOG_IDENTIFIER)
|
|
|
|
syslog.syslog(syslog.LOG_ERR, msg)
|
|
|
|
syslog.closelog()
|
|
|
|
|
2020-04-03 14:41:37 -05:00
|
|
|
|
|
|
|
machine_info = get_machine_info()
|
|
|
|
onie_platform = machine_info['onie_platform']
|
|
|
|
if 'simx' in onie_platform:
|
|
|
|
platform_path = os.path.join('/usr/share/sonic/device', onie_platform)
|
|
|
|
subprocess.check_call(['/usr/bin/xxd', '-r', '-p', 'syseeprom.hex', 'syseeprom.bin'], cwd=platform_path)
|
|
|
|
CACHE_FILE = os.path.join(platform_path, 'syseeprom.bin')
|
|
|
|
|
2020-11-25 12:28:36 -06:00
|
|
|
|
2017-02-27 02:13:36 -06:00
|
|
|
class board(eeprom_tlvinfo.TlvInfoDecoder):
|
|
|
|
|
|
|
|
_TLV_INFO_MAX_LEN = 256
|
2018-11-29 15:36:13 -06:00
|
|
|
RETRIES = 5
|
2017-02-27 02:13:36 -06:00
|
|
|
|
|
|
|
def __init__(self, name, path, cpld_root, ro):
|
2018-11-29 15:36:13 -06:00
|
|
|
for attempt in range(self.RETRIES):
|
|
|
|
if not os.path.islink(EEPROM_SYMLINK):
|
|
|
|
time.sleep(1)
|
|
|
|
else:
|
2020-11-25 12:28:36 -06:00
|
|
|
break
|
2020-04-03 14:41:37 -05:00
|
|
|
|
2018-12-04 09:42:03 -06:00
|
|
|
if not (os.path.exists(EEPROM_SYMLINK) or os.path.isfile(CACHE_FILE)):
|
2018-11-29 15:36:13 -06:00
|
|
|
log_error("Nowhere to read syseeprom from! No symlink or cache file found")
|
|
|
|
raise RuntimeError("No syseeprom symlink or cache file found")
|
|
|
|
|
2020-04-03 14:41:37 -05:00
|
|
|
self.eeprom_path = EEPROM_SYMLINK if 'simx' not in onie_platform else CACHE_FILE
|
2017-02-27 02:13:36 -06:00
|
|
|
super(board, self).__init__(self.eeprom_path, 0, '', True)
|
2018-11-20 14:58:50 -06:00
|
|
|
|
|
|
|
def decode_eeprom(self, e):
|
|
|
|
original_stdout = sys.stdout
|
|
|
|
sys.stdout = StringIO()
|
|
|
|
eeprom_tlvinfo.TlvInfoDecoder.decode_eeprom(self, e)
|
|
|
|
decode_output = sys.stdout.getvalue()
|
|
|
|
sys.stdout = original_stdout
|
|
|
|
print(decode_output.replace('\0', ''))
|