From 446fb32e356f540c13ef85919ab05de9670df5e6 Mon Sep 17 00:00:00 2001 From: Piyushagg19 Date: Sun, 30 May 2021 23:56:52 +0530 Subject: [PATCH 1/4] Update eeprom_base.py --- sonic_platform_base/sonic_eeprom/eeprom_base.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sonic_platform_base/sonic_eeprom/eeprom_base.py b/sonic_platform_base/sonic_eeprom/eeprom_base.py index 05d74573c..7e5b0e8a4 100644 --- a/sonic_platform_base/sonic_eeprom/eeprom_base.py +++ b/sonic_platform_base/sonic_eeprom/eeprom_base.py @@ -29,6 +29,7 @@ def __init__(self, path, format, start, status, readonly): self.r = readonly self.cache_name = None self.cache_update_needed = False + self.eeprom_file_handle = None self.lock_file = None def check_status(self): @@ -220,7 +221,8 @@ def open_eeprom(self): except Exception: pass self.cache_update_needed = using_eeprom - return io.open(eeprom_file, "rb") + self.eeprom_file_handle = io.open(eeprom_file, "rb") + return using_eeprom def read_eeprom(self): sizeof_info = 0 @@ -231,8 +233,9 @@ def read_eeprom(self): def read_eeprom_bytes(self, byteCount, offset=0): F = None + eeprom_flag = False try: - F = self.open_eeprom() + F = self.eeprom_file_handle F.seek(self.s + offset) o = F.read(byteCount) @@ -243,9 +246,11 @@ def read_eeprom_bytes(self, byteCount, offset=0): os.remove(self.cache_name) self.cache_update_needed = True F.close() - F = self.open_eeprom() - F.seek(self.s + offset) - o = F.read(byteCount) + eeprom_flag = self.open_eeprom() + if (eeprom_flag == self.cache_update_needed): + F = self.eeprom_file_handle + F.seek(self.s + offset) + o = F.read(byteCount) if len(o) != byteCount: raise RuntimeError("Expected to read %d bytes from %s, " From 110284342d20ab263908c63ac10a6e73f5461fe2 Mon Sep 17 00:00:00 2001 From: Piyushagg19 Date: Tue, 1 Jun 2021 23:44:08 +0530 Subject: [PATCH 2/4] Update eeprom_base.py Updated for incremental approach. --- sonic_platform_base/sonic_eeprom/eeprom_base.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sonic_platform_base/sonic_eeprom/eeprom_base.py b/sonic_platform_base/sonic_eeprom/eeprom_base.py index 7e5b0e8a4..dc035b2b8 100644 --- a/sonic_platform_base/sonic_eeprom/eeprom_base.py +++ b/sonic_platform_base/sonic_eeprom/eeprom_base.py @@ -222,7 +222,7 @@ def open_eeprom(self): pass self.cache_update_needed = using_eeprom self.eeprom_file_handle = io.open(eeprom_file, "rb") - return using_eeprom + return io.open(eeprom_file, "rb") def read_eeprom(self): sizeof_info = 0 @@ -233,7 +233,6 @@ def read_eeprom(self): def read_eeprom_bytes(self, byteCount, offset=0): F = None - eeprom_flag = False try: F = self.eeprom_file_handle F.seek(self.s + offset) @@ -246,11 +245,10 @@ def read_eeprom_bytes(self, byteCount, offset=0): os.remove(self.cache_name) self.cache_update_needed = True F.close() - eeprom_flag = self.open_eeprom() - if (eeprom_flag == self.cache_update_needed): - F = self.eeprom_file_handle - F.seek(self.s + offset) - o = F.read(byteCount) + update_eeprom_file_handle = self.open_eeprom() + F = self.eeprom_file_handle + F.seek(self.s + offset) + o = F.read(byteCount) if len(o) != byteCount: raise RuntimeError("Expected to read %d bytes from %s, " From 2604fb027a108acf9d4a8c617a02872654109989 Mon Sep 17 00:00:00 2001 From: Piyushagg19 Date: Thu, 3 Jun 2021 14:20:24 +0530 Subject: [PATCH 3/4] Update eeprom_base.py --- sonic_platform_base/sonic_eeprom/eeprom_base.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sonic_platform_base/sonic_eeprom/eeprom_base.py b/sonic_platform_base/sonic_eeprom/eeprom_base.py index dc035b2b8..37187bb5a 100644 --- a/sonic_platform_base/sonic_eeprom/eeprom_base.py +++ b/sonic_platform_base/sonic_eeprom/eeprom_base.py @@ -30,6 +30,8 @@ def __init__(self, path, format, start, status, readonly): self.cache_name = None self.cache_update_needed = False self.eeprom_file_handle = None + self.o = None + self.byte_array = None self.lock_file = None def check_status(self): @@ -228,8 +230,8 @@ def read_eeprom(self): sizeof_info = 0 for I in self.f: sizeof_info += I[2] - o = self.read_eeprom_bytes(sizeof_info) - return o + self.o = self.read_eeprom_bytes(sizeof_info) + return self.o def read_eeprom_bytes(self, byteCount, offset=0): F = None @@ -245,7 +247,7 @@ def read_eeprom_bytes(self, byteCount, offset=0): os.remove(self.cache_name) self.cache_update_needed = True F.close() - update_eeprom_file_handle = self.open_eeprom() + F = self.open_eeprom() F = self.eeprom_file_handle F.seek(self.s + offset) o = F.read(byteCount) @@ -259,8 +261,8 @@ def read_eeprom_bytes(self, byteCount, offset=0): finally: if F is not None: F.close() - - return bytearray(o) + self.byte_array = bytearray(o) + return self.byte_array def read_eeprom_db(self): return 0 From 31a4bf870a7732657d78a365f032f5600bd99619 Mon Sep 17 00:00:00 2001 From: Piyushagg19 Date: Mon, 14 Jun 2021 21:24:39 +0530 Subject: [PATCH 4/4] Update eeprom_base.py --- sonic_platform_base/sonic_eeprom/eeprom_base.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sonic_platform_base/sonic_eeprom/eeprom_base.py b/sonic_platform_base/sonic_eeprom/eeprom_base.py index 37187bb5a..9636edcf3 100644 --- a/sonic_platform_base/sonic_eeprom/eeprom_base.py +++ b/sonic_platform_base/sonic_eeprom/eeprom_base.py @@ -30,8 +30,7 @@ def __init__(self, path, format, start, status, readonly): self.cache_name = None self.cache_update_needed = False self.eeprom_file_handle = None - self.o = None - self.byte_array = None + self.eeprom_raw_bytes = None self.lock_file = None def check_status(self): @@ -230,8 +229,8 @@ def read_eeprom(self): sizeof_info = 0 for I in self.f: sizeof_info += I[2] - self.o = self.read_eeprom_bytes(sizeof_info) - return self.o + self.eeprom_raw_bytes = self.read_eeprom_bytes(sizeof_info) + return self.eeprom_raw_bytes def read_eeprom_bytes(self, byteCount, offset=0): F = None @@ -261,8 +260,8 @@ def read_eeprom_bytes(self, byteCount, offset=0): finally: if F is not None: F.close() - self.byte_array = bytearray(o) - return self.byte_array + + return bytearray(o) def read_eeprom_db(self): return 0