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 <yualiu@nvidia.com>
  • Loading branch information
yuazhe committed Feb 1, 2024
1 parent 3d45c0c commit f9d66ea
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions sfputil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -848,8 +848,8 @@ def eeprom_hexdump_pages_general(logical_port_name, pages, target_page):
return return_code, output
lines.append(output)
else:
lines.append(f'\n{EEPROM_DUMP_INDENT}Upper page {page:x}h')
return_code, output = eeprom_dump_general(physical_port, page, page * PAGE_SIZE + PAGE_OFFSET, PAGE_SIZE, PAGE_OFFSET)
lines.append(f'\n{EEPROM_DUMP_INDENT}Upper page {int(str(page), base=16):x}h')
return_code, output = eeprom_dump_general(physical_port, page, int(str(page), base=16) * PAGE_SIZE + PAGE_OFFSET, PAGE_SIZE, PAGE_OFFSET)
if return_code != 0:
return return_code, output
lines.append(output)
Expand Down Expand Up @@ -895,7 +895,7 @@ def eeprom_hexdump_pages_sff8472(logical_port_name, pages, target_page):
lines.append(output)
else:
lines.append(f'\n{EEPROM_DUMP_INDENT}A2h dump (upper 128 bytes) page {page - 2:x}h')
return_code, output = eeprom_dump_general(physical_port, page, SFF8472_A0_SIZE + PAGE_OFFSET + page * PAGE_SIZE, PAGE_SIZE, PAGE_SIZE)
return_code, output = eeprom_dump_general(physical_port, page, SFF8472_A0_SIZE + PAGE_OFFSET + int(str(page), base=16) * PAGE_SIZE, PAGE_SIZE, PAGE_SIZE)
if return_code != 0:
return ERROR_NOT_IMPLEMENTED, 'Error: Failed to read EEPROM for A2h upper page!'
lines.append(output)
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 f9d66ea

Please sign in to comment.