Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[device/celestica]: Add fwutil #2824

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions device/celestica/x86_64-cel_e1031-r0/plugins/fwutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/usr/bin/env python

import os.path
import subprocess
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(FwBase):
"""Platform-specific FwUtil class"""

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):
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 return 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_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_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

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 modules
"""
return self.SUPPORTED_MODULES

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)
127 changes: 127 additions & 0 deletions device/celestica/x86_64-cel_seastone-r0/plugins/fwutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env python

import os.path
import subprocess
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(FwBase):
"""Platform-specific FwUtil class"""

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):
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 return 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):
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 modules
"""
return self.SUPPORTED_MODULES

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)
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading