Skip to content

Commit

Permalink
Support CPLD update for SN2201
Browse files Browse the repository at this point in the history
A new class is introduced, deriving from ComponentCPLD and overloading _install_firmware
Change _install_firmware from private (starting with __) to protected, making it overloadable

Signed-off-by: Stephen Sun <stephens@nvidia.com>
  • Loading branch information
stephenxs authored and keboliu committed Jun 6, 2022
1 parent 5c82369 commit f454691
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions platform/mellanox/mlnx-platform-api/sonic_platform/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ def __get_mst_device(self):

return mst_dev_list[0]

def __install_firmware(self, image_path):
def _install_firmware(self, image_path):
if not self._check_file_validity(image_path):
return False

Expand Down Expand Up @@ -875,9 +875,9 @@ def install_firmware(self, image_path):
burn_firmware = mpfa.get_metadata().get('firmware', 'burn')

print("INFO: Processing {} burn file: firmware install".format(self.name))
return self.__install_firmware(os.path.join(mpfa.get_path(), burn_firmware))
return self._install_firmware(os.path.join(mpfa.get_path(), burn_firmware))
else:
return self.__install_firmware(image_path)
return self._install_firmware(image_path)

def update_firmware(self, image_path):
with MPFAManager(image_path) as mpfa:
Expand All @@ -890,11 +890,11 @@ def update_firmware(self, image_path):
refresh_firmware = mpfa.get_metadata().get('firmware', 'refresh')

print("INFO: Processing {} burn file: firmware install".format(self.name))
if not self.__install_firmware(os.path.join(mpfa.get_path(), burn_firmware)):
if not self._install_firmware(os.path.join(mpfa.get_path(), burn_firmware)):
return

print("INFO: Processing {} refresh file: firmware update".format(self.name))
self.__install_firmware(os.path.join(mpfa.get_path(), refresh_firmware))
self._install_firmware(os.path.join(mpfa.get_path(), refresh_firmware))

@classmethod
def get_component_list(cls):
Expand All @@ -907,3 +907,19 @@ def get_component_list(cls):
component_list.append(cls(cpld_idx))

return component_list


class ComponentCPLDSN2201(ComponentCPLD):
CPLD_FIRMWARE_UPDATE_COMMAND = 'cpldupdate --gpio {} --uncustomized --print-progress'

def _install_firmware(self, image_path):
cmd = self.CPLD_FIRMWARE_UPDATE_COMMAND.format(image_path)

try:
print("INFO: Installing {} firmware update: path={}".format(self.name, image_path))
subprocess.check_call(cmd.split(), universal_newlines=True)
except subprocess.CalledProcessError as e:
print("ERROR: Failed to update {} firmware: {}".format(self.name, str(e)))
return False

return True

0 comments on commit f454691

Please sign in to comment.