From 0b590d012fd2617d4cec9f233ba1c238087813f2 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Thu, 18 Apr 2019 18:16:51 +0800 Subject: [PATCH 1/4] [platform/cel]: Add sysfs to read/write dx010 CPLD register --- .../debian/platform-modules-dx010.init | 58 ++++++++------ .../dx010/modules/dx010_cpld.c | 79 +++++++++++++++++++ 2 files changed, 115 insertions(+), 22 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.init b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.init index 2117ab22b402..aa13d572be78 100644 --- a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.init +++ b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.init @@ -12,7 +12,8 @@ ### END INIT INFO function export_gpio { -label=$2 +label=$3 +gpio_dir=$2 gpio_num=$1 gpio_base=`( cat /sys/class/gpio/gpiochip*/base | head -1 ) 2>/dev/null` gpio_label=`( cat /sys/class/gpio/gpiochip*/label | head -1 ) 2>/dev/null` @@ -27,6 +28,13 @@ if [ $? -ne 0 ]; then echo "Platform driver error: Cannot export gpio$ionum!" exit 1; fi +if [[ "X$gpio_dir" != "X" ]]; then + echo $gpio_dir > /sys/class/gpio/gpio${ionum}/direction + if [ $? -ne 0 ]; then + echo "Platform driver error: Cannot set direction of gpio$ionum!" + exit 1; + fi +fi } case "$1" in @@ -95,27 +103,33 @@ start) sleep 2 # Export platform gpio sysfs - export_gpio 10 # Fan 1 present - export_gpio 11 # Fan 2 present - export_gpio 12 # Fan 3 present - export_gpio 13 # Fan 4 present - export_gpio 14 # Fan 5 present - - export_gpio 22 # PSU L PWOK - export_gpio 25 # PSU R PWOK - export_gpio 27 # PSU L ABS - export_gpio 28 # PSU R ABS - - export_gpio 29 # Fan 1 LED: Red - export_gpio 30 # Fan 1 LED: Yellow - export_gpio 31 # Fan 2 LED: Red - export_gpio 32 # Fan 2 LED: Yellow - export_gpio 33 # Fan 3 LED: Red - export_gpio 34 # Fan 3 LED: Yellow - export_gpio 35 # Fan 4 LED: Red - export_gpio 36 # Fan 4 LED: Yellow - export_gpio 37 # Fan 5 LED: Red - export_gpio 38 # Fan 5 LED: Yellow + export_gpio 10 "in" # Fan 1 present + export_gpio 11 "in" # Fan 2 present + export_gpio 12 "in" # Fan 3 present + export_gpio 13 "in" # Fan 4 present + export_gpio 14 "in" # Fan 5 present + + export_gpio 15 "in" # Fan 1 direction + export_gpio 16 "in" # Fan 2 direction + export_gpio 17 "in" # Fan 3 direction + export_gpio 18 "in" # Fan 4 direction + export_gpio 19 "in" # Fan 5 direction + + export_gpio 22 "in" # PSU L PWOK + export_gpio 25 "in" # PSU R PWOK + export_gpio 27 "in" # PSU L ABS + export_gpio 28 "in" # PSU R ABS + + export_gpio 29 "out" # Fan 1 LED: Red + export_gpio 30 "out" # Fan 1 LED: Yellow + export_gpio 31 "out" # Fan 2 LED: Red + export_gpio 32 "out" # Fan 2 LED: Yellow + export_gpio 33 "out" # Fan 3 LED: Red + export_gpio 34 "out" # Fan 3 LED: Yellow + export_gpio 35 "out" # Fan 4 LED: Red + export_gpio 36 "out" # Fan 4 LED: Yellow + export_gpio 37 "out" # Fan 5 LED: Red + export_gpio 38 "out" # Fan 5 LED: Yellow # Turn off/down lpmod by defult (0 - Normal, 1 - Low Pow) echo 0x00000000 > /sys/devices/platform/dx010_cpld/qsfp_lpmode diff --git a/platform/broadcom/sonic-platform-modules-cel/dx010/modules/dx010_cpld.c b/platform/broadcom/sonic-platform-modules-cel/dx010/modules/dx010_cpld.c index 397361a5edd6..5e55b1190128 100644 --- a/platform/broadcom/sonic-platform-modules-cel/dx010/modules/dx010_cpld.c +++ b/platform/broadcom/sonic-platform-modules-cel/dx010/modules/dx010_cpld.c @@ -30,6 +30,13 @@ #define DRIVER_NAME "dx010_cpld" +#define CPLD1_VERSION_ADDR 0x100 +#define CPLD2_VERSION_ADDR 0x200 +#define CPLD3_VERSION_ADDR 0x280 +#define CPLD4_VERSION_ADDR 0x300 +#define CPLD5_VERSION_ADDR 0x380 + + #define RESET0108 0x250 #define RESET0910 0x251 #define RESET1118 0x2d0 @@ -110,10 +117,36 @@ struct dx010_i2c_data { struct dx010_cpld_data { struct i2c_adapter *i2c_adapter[LENGTH_PORT_CPLD]; struct mutex cpld_lock; + uint16_t read_addr; }; struct dx010_cpld_data *cpld_data; +static ssize_t getreg_store(struct device *dev, struct device_attribute *devattr, + const char *buf, size_t count) +{ + + uint16_t addr; + char *last; + + addr = (uint16_t)strtoul(buf,&last,16); + if(addr == 0 && buf == last){ + return -EINVAL; + } + cpld_data->read_addr = addr; + return count; +} + +static ssize_t getreg_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + + int len = 0; + mutex_lock(&cpld_data->cpld_lock); + len = sprintf(buf, "0x%2.2x\n",inb(cpld_data->read_addr)); + mutex_unlock(&cpld_data->cpld_lock); + return len; +} + static ssize_t get_reset(struct device *dev, struct device_attribute *devattr, char *buf) { @@ -134,6 +167,47 @@ static ssize_t get_reset(struct device *dev, struct device_attribute *devattr, return sprintf(buf,"0x%8.8lx\n", reset & 0xffffffff); } +static ssize_t setreg_store(struct device *dev, struct device_attribute *devattr, + const char *buf, size_t count) +{ + + uint16_t addr; + uint8_t value; + char *tok; + char clone[count]; + char *pclone = clone; + char *last; + + strcpy(clone, buf); + + mutex_lock(&cpld_data->cpld_lock); + tok = strsep((char**)&pclone, " "); + if(tok == NULL){ + mutex_unlock(&cpld_data->cpld_lock); + return -EINVAL; + } + addr = (uint16_t)strtoul(tok,&last,16); + if(addr == 0 && tok == last){ + mutex_unlock(&cpld_data->cpld_lock); + return -EINVAL; + } + + tok = strsep((char**)&pclone, " "); + if(tok == NULL){ + mutex_unlock(&cpld_data->cpld_lock); + return -EINVAL; + } + value = (uint8_t)strtoul(tok,&last,16); + if(value == 0 && tok == last){ + mutex_unlock(&cpld_data->cpld_lock); + return -EINVAL; + } + + outb(value,addr); + mutex_unlock(&cpld_data->cpld_lock); + return count; +} + static ssize_t set_reset(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { @@ -248,12 +322,16 @@ static ssize_t get_modirq(struct device *dev, struct device_attribute *devattr, return sprintf(buf,"0x%8.8lx\n", irq & 0xffffffff); } +static DEVICE_ATTR_RW(getreg); +static DEVICE_ATTR_WO(setreg); static DEVICE_ATTR(qsfp_reset, S_IRUGO | S_IWUSR, get_reset, set_reset); static DEVICE_ATTR(qsfp_lpmode, S_IRUGO | S_IWUSR, get_lpmode, set_lpmode); static DEVICE_ATTR(qsfp_modprs, S_IRUGO, get_modprs, NULL); static DEVICE_ATTR(qsfp_modirq, S_IRUGO, get_modirq, NULL); static struct attribute *dx010_lpc_attrs[] = { + &dev_attr_getreg.attr, + &dev_attr_setreg.attr, &dev_attr_qsfp_reset.attr, &dev_attr_qsfp_lpmode.attr, &dev_attr_qsfp_modprs.attr, @@ -499,6 +577,7 @@ static int cel_dx010_lpc_drv_probe(struct platform_device *pdev) return -ENOMEM; mutex_init(&cpld_data->cpld_lock); + cpld_data->read_addr = CPLD1_VERSION_ADDR; res = platform_get_resource(pdev, IORESOURCE_IO, 0); if (unlikely(!res)) { From d388007a22691417fe6467fb19ebb8af5395ae93 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Thu, 18 Apr 2019 18:19:50 +0800 Subject: [PATCH 2/4] [device/celestica]: Add platform-specific firmware management api --- .../x86_64-cel_e1031-r0/plugins/fwutil.py | 124 +++++++++++++++++ .../x86_64-cel_seastone-r0/plugins/fwutil.py | 131 ++++++++++++++++++ 2 files changed, 255 insertions(+) create mode 100644 device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py create mode 100644 device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py b/device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py new file mode 100644 index 000000000000..bf8438d86bdf --- /dev/null +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python + +import sys +import os.path +import subprocess +import click +import os + + +class FwUtil(): + """Platform-specific FwUtil class""" + + def __init__(self): + self.bios_version_path = "/sys/class/dmi/id/bios_version" + self.smc_cpld_e1031_path = "/sys/devices/platform/e1031.smc/version" + self.mmc_cpld_e1031_path = "/sys/devices/platform/e1031.smc/getreg" + + # Run bash command and print output to stdout + def run_command(self, command): + click.echo(click.style("Command: ", fg='cyan') + + click.style(command, fg='green')) + + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + (out, err) = proc.communicate() + click.echo("") + click.echo(out) + + if proc.returncode != 0: + return False + return True + + # Read register and resurn value + def __get_register_value(self, path, register): + cmd = "echo {1} > {0}; cat {0}".format(path, register) + p = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err is not '': + return None + return raw_data.strip() + + # Get BIOS firmware version + def get_bios_version(self): + try: + with open(self.bios_version_path, 'r') as fd: + bios_version = fd.read() + return bios_version.strip() + except Exception, e: + return None + + # Get CPLD firmware version + def get_cpld_version(self): + try: + with open(self.smc_cpld_e1031_path, 'r') as fd: + smc_cpld_version = fd.read() + + smc_cpld_version = "{}.{}".format(int(smc_cpld_version[2], 16), int( + smc_cpld_version[3], 16)) if smc_cpld_version is not None else smc_cpld_version + + mmc_cpld_version = self.__get_register_value( + self.mmc_cpld_e1031_path, '0x100') + mmc_cpld_version = "{}.{}".format(int(mmc_cpld_version[2], 16), int( + mmc_cpld_version[3], 16)) if mmc_cpld_version is not None else mmc_cpld_version + + cpld_version = dict() + cpld_version["SMC"] = str(smc_cpld_version) + cpld_version["MMC"] = str(mmc_cpld_version) + + return cpld_version + except Exception, e: + return None + + def get_module_list(self): + """ + Retrieves the list of module that available on the device + + :return: A list of module + """ + return ["BIOS", "CPLD"] + + def get_fw_version(self, module_name): + """ + Retrieves the firmware version of module + + :param module_name: A string, module name + :return: Dict, firmware version object + """ + + fw_version = { + "BIOS": self.get_bios_version(), + "CPLD": self.get_cpld_version() + }.get(module_name.upper(), None) + + fw_dict = dict() + fw_dict["module_name"] = module_name + fw_dict["fw_version"] = fw_version + fw_dict["has_submodule"] = True if type(fw_version) is dict else False + + return fw_dict + + def install(self, module_name, image_path): + """ + Install firmware to module + + :param module_name: A string, name of module that need to install new firmware + :param image_path: A string, path to firmware image + :return: Boolean + """ + module_name = module_name.upper() + + if module_name == "CPLD": + img_dir = os.path.dirname(image_path) + img_name = os.path.basename(image_path) + root, ext = os.path.splitext(img_name) + ext = ".vme" if ext == "" else ext + new_image_path = os.path.join(img_dir, (root.lower() + ext)) + os.rename(image_path, new_image_path) + install_command = "ls" + install_command = "ispvm %s" % new_image_path + elif module_name == "BIOS": + click.echo("Not supported") + return False + + return self.run_command(install_command) diff --git a/device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py b/device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py new file mode 100644 index 000000000000..29c8b694debe --- /dev/null +++ b/device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python + +import sys +import os.path +import subprocess +import click +import os + + +class FwUtil(): + """Platform-specific FwUtil class""" + + def __init__(self): + self.cpld_dx010_path = "/sys/devices/platform/dx010_cpld/getreg" + self.bios_version_path = "/sys/class/dmi/id/bios_version" + + # Run bash command and print output to stdout + def run_command(self, command): + click.echo(click.style("Command: ", fg='cyan') + + click.style(command, fg='green')) + + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + (out, err) = proc.communicate() + click.echo("") + click.echo(out) + + if proc.returncode != 0: + return False + return True + + # Read register and resurn value + def __get_register_value(self, path, register): + cmd = "echo {1} > {0}; cat {0}".format(path, register) + p = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err is not '': + return None + return raw_data.strip() + + # Get BIOS firmware version + def get_bios_version(self): + try: + with open(self.bios_version_path, 'r') as fd: + bios_version = fd.read() + return bios_version.strip() + except Exception, e: + return None + + # Get CPLD firmware version + def get_cpld_version(self): + try: + CPLD_1 = self.__get_register_value(self.cpld_dx010_path, '0x100') + CPLD_2 = self.__get_register_value(self.cpld_dx010_path, '0x200') + CPLD_3 = self.__get_register_value(self.cpld_dx010_path, '0x280') + CPLD_4 = self.__get_register_value(self.cpld_dx010_path, '0x300') + CPLD_5 = self.__get_register_value(self.cpld_dx010_path, '0x380') + + CPLD_1 = 'None' if CPLD_1 is 'None' else "{}.{}".format( + int(CPLD_1[2], 16), int(CPLD_1[3], 16)) + CPLD_2 = 'None' if CPLD_2 is 'None' else "{}.{}".format( + int(CPLD_2[2], 16), int(CPLD_2[3], 16)) + CPLD_3 = 'None' if CPLD_3 is 'None' else "{}.{}".format( + int(CPLD_3[2], 16), int(CPLD_3[3], 16)) + CPLD_4 = 'None' if CPLD_4 is 'None' else "{}.{}".format( + int(CPLD_4[2], 16), int(CPLD_4[3], 16)) + CPLD_5 = 'None' if CPLD_5 is 'None' else "{}.{}".format( + int(CPLD_5[2], 16), int(CPLD_5[3], 16)) + + cpld_version = dict() + cpld_version["CPLD1"] = CPLD_1 + cpld_version["CPLD2"] = CPLD_2 + cpld_version["CPLD3"] = CPLD_3 + cpld_version["CPLD4"] = CPLD_4 + cpld_version["CPLD5"] = CPLD_5 + return cpld_version + except Exception, e: + return None + + def get_module_list(self): + """ + Retrieves the list of module that available on the device + + :return: A list of module + """ + return ["BIOS", "CPLD"] + + def get_fw_version(self, module_name): + """ + Retrieves the firmware version of module + + :param module_name: A string, module name + :return: Dict, firmware version object + """ + + fw_version = { + "BIOS": self.get_bios_version(), + "CPLD": self.get_cpld_version() + }.get(module_name.upper(), None) + + fw_dict = dict() + fw_dict["module_name"] = module_name + fw_dict["fw_version"] = fw_version + fw_dict["has_submodule"] = True if type(fw_version) is dict else False + + return fw_dict + + def install(self, module_name, image_path): + """ + Install firmware to module + + :param module_name: A string, name of module that need to install new firmware + :param image_path: A string, path to firmware image + :return: Boolean + """ + module_name = module_name.upper() + + if module_name == "CPLD": + img_dir = os.path.dirname(image_path) + img_name = os.path.basename(image_path) + root, ext = os.path.splitext(img_name) + ext = ".vme" if ext == "" else ext + new_image_path = os.path.join(img_dir, (root.lower() + ext)) + os.rename(image_path, new_image_path) + install_command = "ls" + install_command = "ispvm %s" % new_image_path + elif module_name == "BIOS": + click.echo("Not supported") + return False + + return self.run_command(install_command) From d8d4b2930cc9cf8259f6dd42a581bd4845e2716d Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Fri, 19 Apr 2019 11:59:39 +0700 Subject: [PATCH 3/4] [device/celestica]: Update code format --- .../x86_64-cel_e1031-r0/plugins/fwutil.py | 22 +++---- .../x86_64-cel_seastone-r0/plugins/fwutil.py | 61 ++++++++----------- 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py b/device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py index bf8438d86bdf..69ec4f54815d 100644 --- a/device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import sys import os.path import subprocess import click @@ -10,10 +9,11 @@ class FwUtil(): """Platform-specific FwUtil class""" - def __init__(self): - self.bios_version_path = "/sys/class/dmi/id/bios_version" - self.smc_cpld_e1031_path = "/sys/devices/platform/e1031.smc/version" - self.mmc_cpld_e1031_path = "/sys/devices/platform/e1031.smc/getreg" + SUPPORTED_MODULES = ["BIOS", "CPLD"] + BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" + SMC_CPLD_PATH = "/sys/devices/platform/e1031.smc/version" + MMC_CPLD_PATH = "/sys/devices/platform/e1031.smc/getreg" + MMC_CPLD_ADDR = '0x100' # Run bash command and print output to stdout def run_command(self, command): @@ -29,7 +29,7 @@ def run_command(self, command): return False return True - # Read register and resurn value + # Read register and return value def __get_register_value(self, path, register): cmd = "echo {1} > {0}; cat {0}".format(path, register) p = subprocess.Popen( @@ -42,7 +42,7 @@ def __get_register_value(self, path, register): # Get BIOS firmware version def get_bios_version(self): try: - with open(self.bios_version_path, 'r') as fd: + with open(self.BIOS_VERSION_PATH, 'r') as fd: bios_version = fd.read() return bios_version.strip() except Exception, e: @@ -51,14 +51,14 @@ def get_bios_version(self): # Get CPLD firmware version def get_cpld_version(self): try: - with open(self.smc_cpld_e1031_path, 'r') as fd: + with open(self.SMC_CPLD_PATH, 'r') as fd: smc_cpld_version = fd.read() smc_cpld_version = "{}.{}".format(int(smc_cpld_version[2], 16), int( smc_cpld_version[3], 16)) if smc_cpld_version is not None else smc_cpld_version mmc_cpld_version = self.__get_register_value( - self.mmc_cpld_e1031_path, '0x100') + self.MMC_CPLD_PATH, self.MMC_CPLD_ADDR) mmc_cpld_version = "{}.{}".format(int(mmc_cpld_version[2], 16), int( mmc_cpld_version[3], 16)) if mmc_cpld_version is not None else mmc_cpld_version @@ -74,9 +74,9 @@ def get_module_list(self): """ Retrieves the list of module that available on the device - :return: A list of module + :return: A list of modules """ - return ["BIOS", "CPLD"] + return self.SUPPORTED_MODULES def get_fw_version(self, module_name): """ diff --git a/device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py b/device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py index 29c8b694debe..afbdc4b71012 100644 --- a/device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py +++ b/device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import sys import os.path import subprocess import click @@ -10,9 +9,16 @@ class FwUtil(): """Platform-specific FwUtil class""" - def __init__(self): - self.cpld_dx010_path = "/sys/devices/platform/dx010_cpld/getreg" - self.bios_version_path = "/sys/class/dmi/id/bios_version" + CPLD_ADDR_MAPPING = { + "CPLD1": "0x100", + "CPLD2": "0x200", + "CPLD3": "0x280", + "CPLD4": "0x300", + "CPLD5": "0x380" + } + SUPPORTED_MODULES = ["BIOS", "CPLD"] + GETREG_PATH = "/sys/devices/platform/dx010_cpld/getreg" + BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" # Run bash command and print output to stdout def run_command(self, command): @@ -28,7 +34,7 @@ def run_command(self, command): return False return True - # Read register and resurn value + # Read register and return value def __get_register_value(self, path, register): cmd = "echo {1} > {0}; cat {0}".format(path, register) p = subprocess.Popen( @@ -41,7 +47,7 @@ def __get_register_value(self, path, register): # Get BIOS firmware version def get_bios_version(self): try: - with open(self.bios_version_path, 'r') as fd: + with open(self.BIOS_VERSION_PATH, 'r') as fd: bios_version = fd.read() return bios_version.strip() except Exception, e: @@ -49,41 +55,26 @@ def get_bios_version(self): # Get CPLD firmware version def get_cpld_version(self): - try: - CPLD_1 = self.__get_register_value(self.cpld_dx010_path, '0x100') - CPLD_2 = self.__get_register_value(self.cpld_dx010_path, '0x200') - CPLD_3 = self.__get_register_value(self.cpld_dx010_path, '0x280') - CPLD_4 = self.__get_register_value(self.cpld_dx010_path, '0x300') - CPLD_5 = self.__get_register_value(self.cpld_dx010_path, '0x380') - - CPLD_1 = 'None' if CPLD_1 is 'None' else "{}.{}".format( - int(CPLD_1[2], 16), int(CPLD_1[3], 16)) - CPLD_2 = 'None' if CPLD_2 is 'None' else "{}.{}".format( - int(CPLD_2[2], 16), int(CPLD_2[3], 16)) - CPLD_3 = 'None' if CPLD_3 is 'None' else "{}.{}".format( - int(CPLD_3[2], 16), int(CPLD_3[3], 16)) - CPLD_4 = 'None' if CPLD_4 is 'None' else "{}.{}".format( - int(CPLD_4[2], 16), int(CPLD_4[3], 16)) - CPLD_5 = 'None' if CPLD_5 is 'None' else "{}.{}".format( - int(CPLD_5[2], 16), int(CPLD_5[3], 16)) - - cpld_version = dict() - cpld_version["CPLD1"] = CPLD_1 - cpld_version["CPLD2"] = CPLD_2 - cpld_version["CPLD3"] = CPLD_3 - cpld_version["CPLD4"] = CPLD_4 - cpld_version["CPLD5"] = CPLD_5 - return cpld_version - except Exception, e: - return None + cpld_version = dict() + for cpld_name in self.CPLD_ADDR_MAPPING: + try: + cpld_addr = self.CPLD_ADDR_MAPPING[cpld_name] + cpld_version_raw = self.__get_register_value( + self.GETREG_PATH, cpld_addr) + cpld_version_str = "{}.{}".format(int(cpld_version_raw[2], 16), int( + cpld_version_raw[3], 16)) if cpld_version_raw is not None else 'None' + cpld_version[cpld_name] = cpld_version_str + except Exception, e: + cpld_version[cpld_name] = 'None' + return cpld_version def get_module_list(self): """ Retrieves the list of module that available on the device - :return: A list of module + :return: A list of modules """ - return ["BIOS", "CPLD"] + return self.SUPPORTED_MODULES def get_fw_version(self, module_name): """ From 9cb7b62d16506d8431b2f767270ff18b4245cf20 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Fri, 26 Apr 2019 11:11:33 +0700 Subject: [PATCH 4/4] [device/celestica] - Add fwutil base class --- device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py | 7 ++++++- device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py b/device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py index 69ec4f54815d..5942170e0f7e 100644 --- a/device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py +++ b/device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py @@ -5,8 +5,13 @@ import click import os +try: + from sonic_fw.fw_manage_base import FwBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") -class FwUtil(): + +class FwUtil(FwBase): """Platform-specific FwUtil class""" SUPPORTED_MODULES = ["BIOS", "CPLD"] diff --git a/device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py b/device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py index afbdc4b71012..6e9815de83bf 100644 --- a/device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py +++ b/device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py @@ -5,8 +5,13 @@ import click import os +try: + from sonic_fw.fw_manage_base import FwBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") -class FwUtil(): + +class FwUtil(FwBase): """Platform-specific FwUtil class""" CPLD_ADDR_MAPPING = {