From 5c7aa50463512e16fefe564c80eb8838a49a3ee2 Mon Sep 17 00:00:00 2001 From: Arun Saravanan Balachandran <52521751+ArunSaravananBalachandran@users.noreply.github.com> Date: Thu, 17 Mar 2022 02:46:26 +0530 Subject: [PATCH] DellEMC: Z9332f - Component API Fixes (#10187) --- .../common/ipmihelper.py | 5 ++- .../common/onie_stage_fwpkg | 2 +- .../common/sonic_platform/hwaccess.py | 5 ++- .../z9332f/sonic_platform/component.py | 38 +++++++++++++++---- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-dell/common/ipmihelper.py b/platform/broadcom/sonic-platform-modules-dell/common/ipmihelper.py index d95329c40de2..3908f90bdad4 100644 --- a/platform/broadcom/sonic-platform-modules-dell/common/ipmihelper.py +++ b/platform/broadcom/sonic-platform-modules-dell/common/ipmihelper.py @@ -90,7 +90,10 @@ def get_twos_complement(val, bits): R_exp = get_twos_complement((factors[6] & 0xF0) >> 4, 4) B_exp = get_twos_complement(factors[6] & 0x0F, 4) - converted_reading = ((M * raw_value) + (B * 10**B_exp)) * 10**R_exp + if R_exp < 0: + converted_reading = ((M * raw_value) + (B * 10**B_exp)) / 10**(-R_exp) + else: + converted_reading = ((M * raw_value) + (B * 10**B_exp)) * 10**R_exp return True, converted_reading diff --git a/platform/broadcom/sonic-platform-modules-dell/common/onie_stage_fwpkg b/platform/broadcom/sonic-platform-modules-dell/common/onie_stage_fwpkg index 1ceaf32fe8c1..dcc74a09a91e 100755 --- a/platform/broadcom/sonic-platform-modules-dell/common/onie_stage_fwpkg +++ b/platform/broadcom/sonic-platform-modules-dell/common/onie_stage_fwpkg @@ -45,7 +45,7 @@ function show_help_and_exit() echo " " echo " Available options:" echo " -h, -? : getting this help" - echo " -o [fwpkg] : stages the firmware update package" + echo " -a [fwpkg] : stages the firmware update package" exit 0 } diff --git a/platform/broadcom/sonic-platform-modules-dell/common/sonic_platform/hwaccess.py b/platform/broadcom/sonic-platform-modules-dell/common/sonic_platform/hwaccess.py index 373f71bdd5bf..642a6ddc6fc8 100644 --- a/platform/broadcom/sonic-platform-modules-dell/common/sonic_platform/hwaccess.py +++ b/platform/broadcom/sonic-platform-modules-dell/common/sonic_platform/hwaccess.py @@ -39,7 +39,10 @@ def pci_set_value(resource, val, offset): # Read I2C device def i2c_get(bus, i2caddr, ofs): - return int(subprocess.check_output(['/usr/sbin/i2cget', '-y', str(bus), str(i2caddr), str(ofs)]), 16) + try: + return int(subprocess.check_output(['/usr/sbin/i2cget', '-y', str(bus), str(i2caddr), str(ofs)]), 16) + except (FileNotFoundError, subprocess.CalledProcessError): + return -1 def io_reg_read(io_resource, offset): fd = os.open(io_resource, os.O_RDONLY) diff --git a/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/component.py b/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/component.py index f652c2eccf85..214467f8c35d 100644 --- a/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/component.py +++ b/platform/broadcom/sonic-platform-modules-dell/z9332f/sonic_platform/component.py @@ -23,20 +23,36 @@ def get_bios_version(): - return subprocess.check_output( - ['dmidecode', '-s', 'bios-version']).decode('utf-8').strip() + try: + return subprocess.check_output(['dmidecode', '-s', 'bios-version'], + text=True).strip() + except (FileNotFoundError, subprocess.CalledProcessError): + return 'NA' def get_fpga_version(): val = hwaccess.pci_get_value('/sys/bus/pci/devices/0000:09:00.0/resource0', 0) return '{}.{}'.format((val >> 16) & 0xffff, val & 0xffff) def get_bmc_version(): - return subprocess.check_output( - ['cat', '/sys/class/ipmi/ipmi0/device/bmc/firmware_revision'] - ).decode('utf-8').strip() + val = 'NA' + try: + bmc_ver = subprocess.check_output(['ipmitool', 'mc', 'info'], + stderr=subprocess.STDOUT, text=True) + except (FileNotFoundError, subprocess.CalledProcessError): + pass + else: + version = re.search(r'Firmware Revision\s*:\s(.*)', bmc_ver) + if version: + val = version.group(1).strip() + + return val def get_cpld_version(bus, i2caddr): - return '{}'.format(hwaccess.i2c_get(bus, i2caddr, 0)) + val = hwaccess.i2c_get(bus, i2caddr, 0) + if val != -1: + return '{:x}.{:x}'.format((val >> 4) & 0xf, val & 0xf) + else: + return 'NA' def get_cpld0_version(): return get_cpld_version(5, 0x0d) @@ -69,7 +85,7 @@ def get_pciephy_version(): except (FileNotFoundError, subprocess.CalledProcessError): pass else: - version = re.search(r'PCIe FW loader version:\s(.*)', pcie_ver) + version = re.search(r'PCIe FW version:\s(.*)', pcie_ver) if version: val = version.group(1).strip() @@ -158,6 +174,14 @@ def _get_available_firmware_version(image_path): ver_info = ver_info.get("x86_64-dellemc_z9332f_d1508-r0") if ver_info: + components = list(ver_info.keys()) + for component in components: + if "CPLD" in component and ver_info[component].get('version'): + val = ver_info.pop(component) + ver = int(val['version'], 16) + val['version'] = "{:x}.{:x}".format((ver >> 4) & 0xf, ver & 0xf) + ver_info[component.replace("-", " ")] = val + return True, ver_info else: return False, "ERROR: Version info not available"