Skip to content

Commit f9d66ea

Browse files
committed
Fix the sfputil treats page number as decimal instead of hexadecimal
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]>
1 parent 3d45c0c commit f9d66ea

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

sfputil/main.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ def validate_eeprom_page(page):
729729
int page
730730
"""
731731
try:
732-
page = int(page)
732+
page = int(page, base=16)
733733
except ValueError:
734734
click.echo('Please enter a numeric page number')
735735
sys.exit(ERROR_NOT_IMPLEMENTED)
@@ -848,8 +848,8 @@ def eeprom_hexdump_pages_general(logical_port_name, pages, target_page):
848848
return return_code, output
849849
lines.append(output)
850850
else:
851-
lines.append(f'\n{EEPROM_DUMP_INDENT}Upper page {page:x}h')
852-
return_code, output = eeprom_dump_general(physical_port, page, page * PAGE_SIZE + PAGE_OFFSET, PAGE_SIZE, PAGE_OFFSET)
851+
lines.append(f'\n{EEPROM_DUMP_INDENT}Upper page {int(str(page), base=16):x}h')
852+
return_code, output = eeprom_dump_general(physical_port, page, int(str(page), base=16) * PAGE_SIZE + PAGE_OFFSET, PAGE_SIZE, PAGE_OFFSET)
853853
if return_code != 0:
854854
return return_code, output
855855
lines.append(output)
@@ -895,7 +895,7 @@ def eeprom_hexdump_pages_sff8472(logical_port_name, pages, target_page):
895895
lines.append(output)
896896
else:
897897
lines.append(f'\n{EEPROM_DUMP_INDENT}A2h dump (upper 128 bytes) page {page - 2:x}h')
898-
return_code, output = eeprom_dump_general(physical_port, page, SFF8472_A0_SIZE + PAGE_OFFSET + page * PAGE_SIZE, PAGE_SIZE, PAGE_SIZE)
898+
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)
899899
if return_code != 0:
900900
return ERROR_NOT_IMPLEMENTED, 'Error: Failed to read EEPROM for A2h upper page!'
901901
lines.append(output)
@@ -928,28 +928,6 @@ def eeprom_dump_general(physical_port, page, flat_offset, size, page_offset, no_
928928
return 0, ''.join('{:02x}'.format(x) for x in page_dump)
929929

930930

931-
932-
def eeprom_dump_general(physical_port, page, flat_offset, size, page_offset, no_format=False):
933-
"""
934-
Dump module EEPROM for given pages in hex format.
935-
Args:
936-
logical_port_name: logical port name
937-
pages: a list of pages to be dumped. The list always include a default page list and the target_page input by
938-
user
939-
target_page: user input page number, optional. target_page is only for display purpose
940-
Returns:
941-
tuple(0, dump string) if success else tuple(error_code, error_message)
942-
"""
943-
sfp = platform_chassis.get_sfp(physical_port)
944-
page_dump = sfp.read_eeprom(flat_offset, size)
945-
if page_dump is None:
946-
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}!'
947-
if not no_format:
948-
return 0, hexdump(EEPROM_DUMP_INDENT, page_dump, page_offset, start_newline=False)
949-
else:
950-
return 0, ''.join('{:02x}'.format(x) for x in page_dump)
951-
952-
953931
def convert_byte_to_valid_ascii_char(byte):
954932
if byte < 32 or 126 < byte:
955933
return '.'

0 commit comments

Comments
 (0)