-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jostar Yang
committed
Aug 3, 2021
1 parent
4fce601
commit d23d3d7
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
platform/broadcom/sonic-platform-modules-accton/as5835-54t/sonic_platform/component.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
############################################################################# | ||
# | ||
# Component contains an implementation of SONiC Platform Base API and | ||
# provides the components firmware management function | ||
# | ||
############################################################################# | ||
|
||
try: | ||
import subprocess | ||
import logging | ||
from sonic_platform_base.component_base import ComponentBase | ||
except ImportError as e: | ||
raise ImportError(str(e) + "- required module not found") | ||
|
||
CPLD_ADDR_MAPPING = { | ||
"CPLD1": ['3', '0x60'], | ||
"CPLD2": ['3', '0x61'], | ||
"CPLD3": ['3', '0x62'] | ||
} | ||
SYSFS_PATH = "/sys/bus/i2c/devices/" | ||
BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" | ||
COMPONENT_LIST= [ | ||
("CPLD1", "CPLD 1"), | ||
("CPLD2", "CPLD 2"), | ||
("CPLD3", "CPLD 3"), | ||
("BIOS", "Basic Input/Output System") | ||
|
||
] | ||
|
||
class Component(ComponentBase): | ||
"""Platform-specific Component class""" | ||
|
||
DEVICE_TYPE = "component" | ||
|
||
def __init__(self, component_index=0): | ||
self.index = component_index | ||
self.name = self.get_name() | ||
|
||
def __run_command(self, command): | ||
# Run bash command and print output to stdout | ||
try: | ||
process = subprocess.Popen( | ||
shlex.split(command), stdout=subprocess.PIPE) | ||
while True: | ||
output = process.stdout.readline() | ||
if output == '' and process.poll() is not None: | ||
break | ||
rc = process.poll() | ||
if rc != 0: | ||
return False | ||
except Exception: | ||
return False | ||
return True | ||
|
||
def __get_bios_version(self): | ||
# Retrieves the BIOS firmware version | ||
try: | ||
with open(BIOS_VERSION_PATH, 'r') as fd: | ||
bios_version = fd.read() | ||
return bios_version.strip() | ||
except Exception as e: | ||
return None | ||
|
||
def __get_cpld_version(self): | ||
# Retrieves the CPLD firmware version | ||
cpld_version = dict() | ||
for cpld_name in CPLD_ADDR_MAPPING: | ||
cmd = "i2cget -f -y {0} {1} 0x1".format(CPLD_ADDR_MAPPING[cpld_name][0], CPLD_ADDR_MAPPING[cpld_name][1]) | ||
status, value = subprocess.getstatusoutput(cmd) | ||
if not status: | ||
cpld_version_raw = value.rstrip() | ||
cpld_version[cpld_name] = "{}".format(int(cpld_version_raw,16)) | ||
|
||
return cpld_version | ||
|
||
def get_name(self): | ||
""" | ||
Retrieves the name of the component | ||
Returns: | ||
A string containing the name of the component | ||
""" | ||
return COMPONENT_LIST[self.index][0] | ||
|
||
def get_description(self): | ||
""" | ||
Retrieves the description of the component | ||
Returns: | ||
A string containing the description of the component | ||
""" | ||
return COMPONENT_LIST[self.index][1] | ||
|
||
def get_firmware_version(self): | ||
""" | ||
Retrieves the firmware version of module | ||
Returns: | ||
string: The firmware versions of the module | ||
""" | ||
fw_version = None | ||
|
||
if self.name == "BIOS": | ||
fw_version = self.__get_bios_version() | ||
elif "CPLD" in self.name: | ||
cpld_version = self.__get_cpld_version() | ||
fw_version = cpld_version.get(self.name) | ||
|
||
return fw_version | ||
|
||
def install_firmware(self, image_path): | ||
""" | ||
Install firmware to module | ||
Args: | ||
image_path: A string, path to firmware image | ||
Returns: | ||
A boolean, True if install successfully, False if not | ||
""" | ||
raise NotImplementedError |