Skip to content

Commit

Permalink
[device/celestica]: Update Component APIs (#3510)
Browse files Browse the repository at this point in the history
* [platform/cel]: add bios upgrade tool
* [device/celestica]: update Seastone/E1031 component api to support BIOS upgrade
* [device/celestica]: add error handler for eeprom api
* [device/celestica]: add component description
  • Loading branch information
Wirut Getbamrung authored and jleveque committed Sep 27, 2019
1 parent 59febed commit ecdd866
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 96 deletions.
40 changes: 6 additions & 34 deletions device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
NUM_PSU = 2
NUM_THERMAL = 7
NUM_SFP = 52
NUM_COMPONENT = 3
RESET_REGISTER = "0x112"
HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/previous-reboot-cause.txt"
PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/previous-reboot-cause.txt"
COMPONENT_NAME_LIST = ["SMC_CPLD", "MMC_CPLD", "BIOS"]
HOST_CHK_CMD = "docker > /dev/null 2>&1"


Expand All @@ -56,10 +56,13 @@ def __init__(self):
for index in range(0, NUM_SFP):
sfp = Sfp(index)
self._sfp_list.append(sfp)
for index in range(0, NUM_COMPONENT):
component = Component(index)
self._component_list.append(component)
ChassisBase.__init__(self)
self._reboot_cause_path = HOST_REBOOT_CAUSE_PATH if self.__is_host(
) else PMON_REBOOT_CAUSE_PATH
self._component_name_list = COMPONENT_NAME_LIST

self._watchdog = Watchdog()
self._eeprom = Tlv()

Expand Down Expand Up @@ -102,36 +105,6 @@ def get_system_eeprom_info(self):
"""
return self._eeprom.get_eeprom()

def get_firmware_version(self, component_name):
"""
Retrieves platform-specific hardware/firmware versions for chassis
componenets such as BIOS, CPLD, FPGA, etc.
Args:
type: A string, component name
Returns:
A string containing platform-specific component versions
"""
self.component = Component(component_name)
if component_name not in self._component_name_list:
return None
return self.component.get_firmware_version()

def install_component_firmware(self, component_name, image_path):
"""
Install firmware to module
Args:
type: A string, component name.
image_path: A string, path to firmware image.
Returns:
A boolean, True if install successfully, False if not
"""
self.component = Component(component_name)
if component_name not in self._component_name_list:
return False
return self.component.upgrade_firmware(image_path)

def get_reboot_cause(self):
"""
Retrieves the cause of the previous reboot
Expand All @@ -143,10 +116,9 @@ def get_reboot_cause(self):
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
to pass a description of the reboot cause.
"""
self.component = Component("SMC_CPLD")
description = 'None'
reboot_cause = self.REBOOT_CAUSE_HARDWARE_OTHER
hw_reboot_cause = self.component.get_register_value(RESET_REGISTER)
hw_reboot_cause = self._component_list[0].get_register_value(RESET_REGISTER)
sw_reboot_cause = self.__read_txt_file(
self._reboot_cause_path) or "Unknown"

Expand Down
35 changes: 27 additions & 8 deletions device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import subprocess

try:
from sonic_platform_base.device_base import DeviceBase
from sonic_platform_base.component_base import ComponentBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand All @@ -24,16 +24,20 @@
CONFIG_DB_PATH = "/etc/sonic/config_db.json"
SMC_CPLD_PATH = "/sys/devices/platform/e1031.smc/version"
GETREG_PATH = "/sys/devices/platform/e1031.smc/getreg"
COMPONENT_NAME_LIST = ["SMC_CPLD", "MMC_CPLD", "BIOS"]
COMPONENT_DES_LIST = ["System Management Controller",
"Module Management CPLD", "Basic Input/Output System"]


class Component(DeviceBase):
class Component(ComponentBase):
"""Platform-specific Component class"""

DEVICE_TYPE = "component"

def __init__(self, component_name):
DeviceBase.__init__(self)
self.name = component_name.upper()
def __init__(self, component_index):
ComponentBase.__init__(self)
self.index = component_index
self.name = self.get_name()

def __run_command(self, command):
# Run bash command and print output to stdout
Expand Down Expand Up @@ -86,6 +90,22 @@ def __get_cpld_version(self):
cpld_version["MMC_CPLD"] = mmc_cpld_version
return cpld_version

def get_name(self):
"""
Retrieves the name of the component
Returns:
A string containing the name of the component
"""
return COMPONENT_NAME_LIST[self.index]

def get_description(self):
"""
Retrieves the description of the component
Returns:
A string containing the description of the component
"""
return COMPONENT_DES_LIST[self.index]

def get_firmware_version(self):
"""
Retrieves the firmware version of module
Expand All @@ -102,7 +122,7 @@ def get_firmware_version(self):

return fw_version

def upgrade_firmware(self, image_path):
def install_firmware(self, image_path):
"""
Install firmware to module
Args:
Expand All @@ -121,7 +141,6 @@ def upgrade_firmware(self, image_path):
shutil.copy(image_path, new_image_path)
install_command = "ispvm %s" % new_image_path
elif self.name == "BIOS":
print("Not supported")
return False
install_command = "afulnx_64 %s /p /b /n /x /r" % image_path

return self.__run_command(install_command)
10 changes: 4 additions & 6 deletions device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,15 @@ def __parse_output(self, decode_output):
def _load_eeprom(self):
original_stdout = sys.stdout
sys.stdout = StringIO()
err = self.read_eeprom_db()
if err:
# Failed to read EEPROM information from database. Read from cache file
pass
else:
try:
self.read_eeprom_db()
except:
decode_output = sys.stdout.getvalue()
sys.stdout = original_stdout
return self.__parse_output(decode_output)

status = self.check_status()
if status <> 'ok':
if 'ok' not in status:
return False

if not os.path.exists(CACHE_ROOT):
Expand Down
39 changes: 5 additions & 34 deletions device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
NUM_PSU = 2
NUM_THERMAL = 5
NUM_SFP = 32
NUM_COMPONENT = 5
RESET_REGISTER = "0x103"
HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/"
PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/"
REBOOT_CAUSE_FILE = "reboot-cause.txt"
PREV_REBOOT_CAUSE_FILE = "previous-reboot-cause.txt"
COMPONENT_NAME_LIST = ["CPLD1", "CPLD2", "CPLD3", "CPLD4", "BIOS"]
HOST_CHK_CMD = "docker > /dev/null 2>&1"


Expand All @@ -58,9 +58,11 @@ def __init__(self):
for index in range(0, NUM_SFP):
sfp = Sfp(index)
self._sfp_list.append(sfp)
for index in range(0, NUM_COMPONENT):
component = Component(index)
self._component_list.append(component)
ChassisBase.__init__(self)

self._component_name_list = COMPONENT_NAME_LIST
self._watchdog = Watchdog()
self._eeprom = Tlv()

Expand Down Expand Up @@ -103,36 +105,6 @@ def get_system_eeprom_info(self):
"""
return self._eeprom.get_eeprom()

def get_firmware_version(self, component_name):
"""
Retrieves platform-specific hardware/firmware versions for chassis
componenets such as BIOS, CPLD, FPGA, etc.
Args:
type: A string, component name
Returns:
A string containing platform-specific component versions
"""
self.component = Component(component_name)
if component_name not in self._component_name_list:
return None
return self.component.get_firmware_version()

def install_component_firmware(self, component_name, image_path):
"""
Install firmware to module
Args:
type: A string, component name.
image_path: A string, path to firmware image.
Returns:
A boolean, True if install successfully, False if not
"""
self.component = Component(component_name)
if component_name not in self._component_name_list:
return False
return self.component.upgrade_firmware(image_path)

def get_reboot_cause(self):
"""
Retrieves the cause of the previous reboot
Expand All @@ -144,7 +116,6 @@ def get_reboot_cause(self):
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
to pass a description of the reboot cause.
"""
self.component = Component("CPLD1")
description = 'None'
reboot_cause = self.REBOOT_CAUSE_HARDWARE_OTHER

Expand All @@ -153,7 +124,7 @@ def get_reboot_cause(self):
prev_reboot_cause_path = (HOST_REBOOT_CAUSE_PATH + PREV_REBOOT_CAUSE_FILE) if self.__is_host(
) else PMON_REBOOT_CAUSE_PATH + PREV_REBOOT_CAUSE_FILE

hw_reboot_cause = self.component.get_register_value(RESET_REGISTER)
hw_reboot_cause = self._component_list[0].get_register_value(RESET_REGISTER)

sw_reboot_cause = self.__read_txt_file(
reboot_cause_path) or "Unknown"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import subprocess

try:
from sonic_platform_base.device_base import DeviceBase
from sonic_platform_base.component_base import ComponentBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand All @@ -28,16 +28,19 @@
}
GETREG_PATH = "/sys/devices/platform/dx010_cpld/getreg"
BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version"
COMPONENT_NAME_LIST = ["CPLD1", "CPLD2", "CPLD3", "CPLD4", "BIOS"]
COMPONENT_DES_LIST = ["CPLD1", "CPLD2", "CPLD3", "CPLD4", "Basic Input/Output System"]


class Component(DeviceBase):
class Component(ComponentBase):
"""Platform-specific Component class"""

DEVICE_TYPE = "component"

def __init__(self, component_name):
DeviceBase.__init__(self)
self.name = component_name.upper()
def __init__(self, component_index):
ComponentBase.__init__(self)
self.index = component_index
self.name = self.get_name()

def __run_command(self, command):
# Run bash command and print output to stdout
Expand Down Expand Up @@ -88,6 +91,22 @@ def __get_cpld_version(self):
cpld_version[cpld_name] = 'None'
return cpld_version

def get_name(self):
"""
Retrieves the name of the component
Returns:
A string containing the name of the component
"""
return COMPONENT_NAME_LIST[self.index]

def get_description(self):
"""
Retrieves the description of the component
Returns:
A string containing the description of the component
"""
return COMPONENT_DES_LIST[self.index]

def get_firmware_version(self):
"""
Retrieves the firmware version of module
Expand All @@ -104,7 +123,7 @@ def get_firmware_version(self):

return fw_version

def upgrade_firmware(self, image_path):
def install_firmware(self, image_path):
"""
Install firmware to module
Args:
Expand All @@ -123,7 +142,6 @@ def upgrade_firmware(self, image_path):
shutil.copy(image_path, new_image_path)
install_command = "ispvm %s" % new_image_path
elif self.name == "BIOS":
print("Not supported")
return False
install_command = "afulnx_64 %s /p /b /n /x /r" % image_path

return self.__run_command(install_command)
10 changes: 4 additions & 6 deletions device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,15 @@ def __parse_output(self, decode_output):
def _load_eeprom(self):
original_stdout = sys.stdout
sys.stdout = StringIO()
err = self.read_eeprom_db()
if err:
# Failed to read EEPROM information from database. Read from cache file
pass
else:
try:
self.read_eeprom_db()
except:
decode_output = sys.stdout.getvalue()
sys.stdout = original_stdout
return self.__parse_output(decode_output)

status = self.check_status()
if status <> 'ok':
if 'ok' not in status:
return False

if not os.path.exists(CACHE_ROOT):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dx010/cfg/dx010-modules.conf etc/modules-load.d
dx010/systemd/platform-modules-dx010.service lib/systemd/system
dx010/modules/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-cel_seastone-r0
services/platform_api/platform_api_mgnt.sh usr/local/bin
tools/afulnx_64 usr/local/bin
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ services/fancontrol/fancontrol.service lib/systemd/system
services/fancontrol/fancontrol usr/local/bin
haliburton/modules/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-cel_e1031-r0
services/platform_api/platform_api_mgnt.sh usr/local/bin
tools/afulnx_64 usr/local/bin
Binary file not shown.

0 comments on commit ecdd866

Please sign in to comment.