From ec7335d93f4a0ff7c955d2177ee4c193239c66d2 Mon Sep 17 00:00:00 2001 From: qinchuanares <37220227+qinchuanares@users.noreply.github.com> Date: Wed, 24 Nov 2021 05:10:40 -0800 Subject: [PATCH] fix for firmware functions (#243) * fix for firmware functions 1. report updated address, count and remaining bytes info in module_fw_download() 2. remove additional 200 ms wait time in block_write_lpl() and block_write_epl() 3. increase max wait time to 1 min in cdb1_chkstatus() if status is not 1. If status is password error (70) it will break the wait loop. 4. add protection to failed_status_dict * change cdb1_chkstatus(): only wait if status is busy * change cdb1_chkstatus(): only wait if status is busy --- .../sonic_xcvr/api/public/cmis.py | 5 +-- .../sonic_xcvr/api/public/cmisCDB.py | 32 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmis.py b/sonic_platform_base/sonic_xcvr/api/public/cmis.py index 319b787f9fea..c1398bac22de 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -1280,7 +1280,6 @@ def module_fw_download(self, startLPLsize, maxblocksize, lplonly_flag, autopagin else: count = BLOCK_SIZE data = f.read(count) - progress = (imagesize - remaining) * 100.0 / imagesize if lplonly_flag: fw_download_status = self.cdb.block_write_lpl(address, data) else: @@ -1292,9 +1291,11 @@ def module_fw_download(self, startLPLsize, maxblocksize, lplonly_flag, autopagin logger.info(txt) return False, txt elapsedtime = time.time()-starttime - logger.info('Address: {:#08x}; Count: {}; Progress: {:.2f}%; Time: {:.2f}s'.format(address, count, progress, elapsedtime)) address += count remaining -= count + progress = (imagesize - remaining) * 100.0 / imagesize + logger.info('Address: {:#08x}; Count: {}; Remain: {:#08x}; Progress: {:.2f}%; Time: {:.2f}s'.format(address, count, remaining, progress, elapsedtime)) + elapsedtime = time.time()-starttime logger.info('Total module FW download time: %.2f s' %elapsedtime) diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmisCDB.py b/sonic_platform_base/sonic_xcvr/api/public/cmisCDB.py index 215bf8ef0450..fb48e7a81def 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmisCDB.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmisCDB.py @@ -18,7 +18,7 @@ PAGE_LENGTH = 128 INIT_OFFSET = 128 CMDLEN = 2 -MAX_WAIT = 100 +MAX_WAIT = 600 class CmisCdbApi(XcvrApi): @@ -121,12 +121,12 @@ def cdb1_chkstatus(self): 30h-3Fh=Custom ''' status = self.xcvr_eeprom.read(consts.CDB1_STATUS) - is_busy = bool((status >> 7) & 0x1) + is_busy = bool((status >> 7) & 0x1) cnt = 0 while is_busy and cnt < MAX_WAIT: time.sleep(0.1) status = self.xcvr_eeprom.read(consts.CDB1_STATUS) - is_busy = bool((status >> 7) & 0x1) + is_busy = bool((status >> 7) & 0x1) cnt += 1 return status @@ -165,7 +165,7 @@ def query_cdb_status(self): if status > 127: txt = 'Query CDB status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'Query CDB status: Fail- ' + status_txt else: txt = 'Query CDB status: Success' @@ -189,7 +189,7 @@ def module_enter_password(self, psw = 0x00001011): if status > 127: txt = 'Enter password status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'Enter password status: Fail- ' + status_txt else: txt = 'Enter password status: Success' @@ -209,7 +209,7 @@ def get_module_feature(self): if status > 127: txt = 'Get module feature status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'Get module feature status: Fail- ' + status_txt else: txt = 'Get module feature status: Success' @@ -230,7 +230,7 @@ def get_fw_management_features(self): if status > 127: txt = 'Get firmware management feature status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'Get firmware management feature status: Fail- ' + status_txt else: txt = 'Get firmware management feature status: Success' @@ -253,7 +253,7 @@ def get_fw_info(self): if status > 127: txt = 'Get firmware info status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'Get firmware info status: Fail- ' + status_txt else: txt = 'Get firmware info status: Success' @@ -284,7 +284,7 @@ def start_fw_download(self, startLPLsize, header, imagesize): if status > 127: txt = 'Start firmware download status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'Start firmware download status: Fail- ' + status_txt else: txt = 'Start firmware download status: Success' @@ -307,7 +307,7 @@ def abort_fw_download(self): if status > 127: txt = 'Abort firmware download status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'Abort firmware download status: Fail- ' + status_txt else: txt = 'Abort firmware download status: Success' @@ -333,13 +333,12 @@ def block_write_lpl(self, addr, data): cmd += paddedPayload cmd[133-INIT_OFFSET] = self.cdb_chkcode(cmd) self.write_cdb(cmd) - time.sleep(0.2) status = self.cdb1_chkstatus() if (status != 0x1): if status > 127: txt = 'LPL firmware download status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'LPL firmware download status: Fail- ' + status_txt else: txt = 'LPL firmware download status: Success' @@ -386,13 +385,12 @@ def block_write_epl(self, addr, data, autopaging_flag, writelength): cmd += addr_byte cmd[133-INIT_OFFSET] = self.cdb_chkcode(cmd) self.write_cdb(cmd) - time.sleep(0.2) status = self.cdb1_chkstatus() if (status != 0x1): if status > 127: txt = 'EPL firmware download status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'EPL firmware download status: Fail- ' + status_txt else: txt = 'EPL firmware download status: Success' @@ -414,7 +412,7 @@ def validate_fw_image(self): if status > 127: txt = 'Firmware download complete status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'Firmware download complete status: Fail- ' + status_txt else: txt = 'Firmware download complete status: Success' @@ -442,7 +440,7 @@ def run_fw_image(self, mode = 0x01): if status > 127: txt = 'Run firmware status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'Run firmware status: Fail- ' + status_txt else: txt = 'Run firmware status: Success' @@ -472,7 +470,7 @@ def commit_fw_image(self): if status > 127: txt = 'Commit firmware status: Busy' else: - status_txt = self.failed_status_dict[status & 0x3f] + status_txt = self.failed_status_dict.get(status & 0x3f, "Unknown") txt = 'Commit firmware status: Fail- ' + status_txt else: txt = 'Commit firmware status: Success'