Skip to content

Commit

Permalink
Fix the sfputil treats page number as decimal instead of hexadecimal
Browse files Browse the repository at this point in the history
sonic-net#3009 breaks the number
base rule, treats the page number CLI input as decimal rather than hex,
this is used to fix it.

Signed-off-by: Yuanzhe, Liu <[email protected]>
  • Loading branch information
yuazhe committed Feb 1, 2024
1 parent 3d45c0c commit 39da62a
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions sfputil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,14 +703,14 @@ def eeprom_hexdump(port, page):
if port:
if page is None:
page = 0
return_code, output = eeprom_hexdump_single_port(port, page)
return_code, output = eeprom_hexdump_single_port(port, int(str(page), base=16))
click.echo(output)
sys.exit(return_code)
else:
logical_port_list = natsorted(platform_sfputil.logical)
lines = []
for logical_port_name in logical_port_list:
return_code, output = eeprom_hexdump_single_port(logical_port_name, page)
return_code, output = eeprom_hexdump_single_port(logical_port_name, int(str(page), base=16))
if return_code != 0:
lines.append(f'EEPROM hexdump for port {logical_port_name}')
lines.append(f'{EEPROM_DUMP_INDENT}{output}\n')
Expand All @@ -729,7 +729,7 @@ def validate_eeprom_page(page):
int page
"""
try:
page = int(page)
page = int(page, base=16)
except ValueError:
click.echo('Please enter a numeric page number')
sys.exit(ERROR_NOT_IMPLEMENTED)
Expand Down Expand Up @@ -928,28 +928,6 @@ def eeprom_dump_general(physical_port, page, flat_offset, size, page_offset, no_
return 0, ''.join('{:02x}'.format(x) for x in page_dump)



def eeprom_dump_general(physical_port, page, flat_offset, size, page_offset, no_format=False):
"""
Dump module EEPROM for given pages in hex format.
Args:
logical_port_name: logical port name
pages: a list of pages to be dumped. The list always include a default page list and the target_page input by
user
target_page: user input page number, optional. target_page is only for display purpose
Returns:
tuple(0, dump string) if success else tuple(error_code, error_message)
"""
sfp = platform_chassis.get_sfp(physical_port)
page_dump = sfp.read_eeprom(flat_offset, size)
if page_dump is None:
return ERROR_NOT_IMPLEMENTED, f'Error: Failed to read EEPROM for page {page:x}h, flat_offset {flat_offset}, page_offset {page_offset}, size {size}!'
if not no_format:
return 0, hexdump(EEPROM_DUMP_INDENT, page_dump, page_offset, start_newline=False)
else:
return 0, ''.join('{:02x}'.format(x) for x in page_dump)


def convert_byte_to_valid_ascii_char(byte):
if byte < 32 or 126 < byte:
return '.'
Expand Down

0 comments on commit 39da62a

Please sign in to comment.