diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py index 633af66dbaa8..291ece986222 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py @@ -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" @@ -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() @@ -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 @@ -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" diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py index b80deabb178d..ad6810b14c38 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/component.py @@ -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") @@ -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 @@ -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 @@ -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: @@ -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) diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py index b6881620612d..20f3db111f66 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/eeprom.py @@ -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): diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py index 7e597b7d08e7..768a15ce22ef 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py @@ -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" @@ -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() @@ -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 @@ -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 @@ -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" diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py index d78adf738920..67c7a9c46341 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/component.py @@ -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") @@ -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 @@ -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 @@ -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: @@ -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) diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py index 1e10848ca439..dffda1a3c050 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/eeprom.py @@ -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): diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.install b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.install index 8570fa1eae84..2ab53302a9bf 100644 --- a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.install +++ b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.install @@ -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 diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.install b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.install index df78b7a34ea4..d50306304cd5 100644 --- a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.install +++ b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.install @@ -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 diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/afulnx_64 b/platform/broadcom/sonic-platform-modules-cel/tools/afulnx_64 new file mode 100755 index 000000000000..c32823393c08 Binary files /dev/null and b/platform/broadcom/sonic-platform-modules-cel/tools/afulnx_64 differ