Skip to content

Commit

Permalink
Adding support firmware status
Browse files Browse the repository at this point in the history
  • Loading branch information
lkunjumon committed Jul 7, 2021
1 parent 4623a25 commit f379394
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
########################################################################
#
# Module contains an implementation of SONiC Platform Base API and
# provides the Components' (e.g., BIOS, CPLD, FPGA, etc.) available in
# the platform
#
########################################################################

try:
import os
import sys
import subprocess
import ntpath
from sonic_platform_base.component_base import ComponentBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

smbus_present = 1
try:
import smbus
except ImportError as e:
smbus_present = 0

if sys.version_info[0] < 3:
import commands as cmd
else:
import subprocess as cmd


class Component(ComponentBase):
"""platform-specific Component class"""

CHASSIS_COMPONENTS = [
["U-Boot", "Performs initialization during booting"],
]

def __init__(self, component_index):
self.index = component_index
self.name = self.CHASSIS_COMPONENTS[self.index][0]
self.description = self.CHASSIS_COMPONENTS[self.index][1]

def _get_command_result(self, cmdline):
try:
proc = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
result = stdout.rstrip('\n')
except OSError:
result = None

return result


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

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

def get_firmware_version(self):
"""
Retrieves the firmware version of the component
Returns:
A string containing the firmware version of the component
"""

if self.index == 0:
cmdstatus, uboot_version = cmd.getstatusoutput('grep --null-data U-Boot /dev/mtd0ro|head -2 | cut -d" " -f2')
return uboot_version

def install_firmware(self, image_path):
"""
Installs firmware to the component
Args:
image_path: A string, path to firmware image
Returns:
A boolean, True if install was successful, False if not
"""
return False

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
########################################################################
#
# Module contains an implementation of SONiC Platform Base API and
# provides the Components' (e.g., BIOS, CPLD, FPGA, etc.) available in
# the platform
#
########################################################################

try:
import os
import sys
import subprocess
import ntpath
from sonic_platform_base.component_base import ComponentBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

smbus_present = 1
try:
import smbus
except ImportError as e:
smbus_present = 0

if sys.version_info[0] < 3:
import commands as cmd
else:
import subprocess as cmd


class Component(ComponentBase):
"""platform-specific Component class"""

CHASSIS_COMPONENTS = [
["U-Boot", "Performs initialization during booting"],
]

def __init__(self, component_index):
self.index = component_index
self.name = self.CHASSIS_COMPONENTS[self.index][0]
self.description = self.CHASSIS_COMPONENTS[self.index][1]

def _get_command_result(self, cmdline):
try:
proc = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
result = stdout.rstrip('\n')
except OSError:
result = None

return result


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

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

def get_firmware_version(self):
"""
Retrieves the firmware version of the component
Returns:
A string containing the firmware version of the component
"""

if self.index == 0:
cmdstatus, uboot_version = cmd.getstatusoutput('grep --null-data U-Boot /dev/mtd0ro|head -2 | cut -d" " -f2')
return uboot_version

def install_firmware(self, image_path):
"""
Installs firmware to the component
Args:
image_path: A string, path to firmware image
Returns:
A boolean, True if install was successful, False if not
"""
return False

0 comments on commit f379394

Please sign in to comment.