diff --git a/sonic_platform_base/sonic_eeprom/eeprom_base.py b/sonic_platform_base/sonic_eeprom/eeprom_base.py index 05d74573c..9636edcf3 100644 --- a/sonic_platform_base/sonic_eeprom/eeprom_base.py +++ b/sonic_platform_base/sonic_eeprom/eeprom_base.py @@ -29,6 +29,8 @@ 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.eeprom_raw_bytes = None self.lock_file = None def check_status(self): @@ -220,19 +222,20 @@ def open_eeprom(self): except Exception: pass self.cache_update_needed = using_eeprom + self.eeprom_file_handle = io.open(eeprom_file, "rb") return io.open(eeprom_file, "rb") 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.eeprom_raw_bytes = self.read_eeprom_bytes(sizeof_info) + return self.eeprom_raw_bytes def read_eeprom_bytes(self, byteCount, offset=0): F = None try: - F = self.open_eeprom() + F = self.eeprom_file_handle F.seek(self.s + offset) o = F.read(byteCount) @@ -244,6 +247,7 @@ def read_eeprom_bytes(self, byteCount, offset=0): self.cache_update_needed = True F.close() F = self.open_eeprom() + F = self.eeprom_file_handle F.seek(self.s + offset) o = F.read(byteCount) @@ -256,7 +260,7 @@ def read_eeprom_bytes(self, byteCount, offset=0): finally: if F is not None: F.close() - + return bytearray(o) def read_eeprom_db(self):