Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,13 @@ def __get_bios_version(self):
except Exception as e:
return None

def get_register_value(self, register):
# Retrieves the cpld register value
with open(GETREG_PATH, 'w') as file:
file.write(register + '\n')
with open(GETREG_PATH, 'r') as file:
raw_data = file.readline()
return raw_data.strip()

def __get_cpld_version(self):
# Retrieves the CPLD firmware version
cpld_version = dict()
for cpld_name in CPLD_ADDR_MAPPING:
try:
cpld_addr = CPLD_ADDR_MAPPING[cpld_name]
cpld_version_raw = self.get_register_value(cpld_addr)
cpld_version_raw = self._api_helper.get_cpld_reg_value(GETREG_PATH, cpld_addr)
cpld_version_str = "{}.{}".format(int(cpld_version_raw[2], 16), int(
cpld_version_raw[3], 16)) if cpld_version_raw is not None else 'None'
cpld_version[cpld_name] = cpld_version_str
Expand Down
21 changes: 18 additions & 3 deletions device/celestica/x86_64-cel_seastone-r0/sonic_platform/helper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fcntl
import os
import struct
import subprocess
Expand Down Expand Up @@ -74,9 +75,23 @@ def write_txt_file(self, file_path, value):
return True

def get_cpld_reg_value(self, getreg_path, register):
with open(getreg_path, 'w') as file:
file = open(getreg_path, 'w+')
# Acquire an exclusive lock on the file
fcntl.flock(file, fcntl.LOCK_EX)

try:
file.write(register + '\n')
with open(getreg_path, 'r') as file:
result = file.readline()
file.flush()

# Seek to the beginning of the file
file.seek(0)

# Read the content of the file
result = file.readline().strip()
finally:
# Release the lock and close the file
fcntl.flock(file, fcntl.LOCK_UN)
file.close()

return result