Add module_dump_eeprom_hex() as the shared building block for the per-type EEPROM page hex dump functions added in the next patch. It prints a per-page header followed by a hex dump; the header format is selected by print_i2c / print_bank flags in struct module_eeprom_dump. In JSON context, the flags are ignored and all metadata fields are emitted as one object inside the enclosing "pages" array. Assisted-by: Claude:claude-sonnet-4.6 Reviewed-by: Ido Schimmel Signed-off-by: Danielle Ratson --- module-common.c | 38 ++++++++++++++++++++++++++++++++++++++ module-common.h | 12 ++++++++++++ 2 files changed, 50 insertions(+) diff --git a/module-common.c b/module-common.c index 4e9a0a7..1cfe243 100644 --- a/module-common.c +++ b/module-common.c @@ -656,3 +656,41 @@ void module_show_dom_mod_lvl_monitors(const struct sff_diags *sd) PRINT_VCC_ALL("Module voltage", "module_voltage_measurement", sd->sfp_voltage[MCURR]); } + +/* Print one EEPROM memory block with a descriptive header followed by hex + * dump. The header is selected by the dump->print_i2c and dump->print_bank + * flags: "Page: 0xN" is always printed, an I2C-addressed block prints + * "I2C Address: 0xN" and a banked page prints "Bank: 0xN". + * + * In JSON context, all fields (bank, page, offset, length, i2c_address) are + * emitted unconditionally as a JSON object inside the enclosing "pages" + * array. + */ +void module_dump_eeprom_hex(const struct module_eeprom_dump *dump) +{ + u32 i; + + if (is_json_context()) { + open_json_object(NULL); + print_uint(PRINT_JSON, "bank", "%u", dump->bank); + print_uint(PRINT_JSON, "page", "%u", dump->page); + print_uint(PRINT_JSON, "offset", "%u", dump->offset); + print_uint(PRINT_JSON, "length", "%u", dump->length); + print_uint(PRINT_JSON, "i2c_address", "%u", dump->i2c_address); + open_json_array("data", ""); + for (i = 0; i < dump->length; i++) + print_hex(PRINT_JSON, NULL, "%02x", dump->data[i]); + close_json_array(""); + close_json_object(); + return; + } + + if (dump->print_i2c) + printf("I2C Address: 0x%02x\n", dump->i2c_address); + if (dump->print_bank) + printf("Bank: 0x%x\n", dump->bank); + printf("Page: 0x%x\n\n", dump->page); + + dump_hex(stdout, dump->data, dump->length, dump->offset); + printf("\n"); +} diff --git a/module-common.h b/module-common.h index 985b518..4063448 100644 --- a/module-common.h +++ b/module-common.h @@ -261,6 +261,17 @@ struct module_aw_chan { __u8 adver_value; /* Supported if (offset & value) != 0. */ }; +struct module_eeprom_dump { + u32 offset; + u32 length; + u8 page; + u8 bank; + u8 i2c_address; + bool print_bank; + bool print_i2c; + const u8 *data; +}; + extern const struct module_aw_mod module_aw_mod_flags[]; extern const struct module_aw_chan module_aw_chan_flags[]; @@ -283,5 +294,6 @@ void module_show_identifier(const __u8 *id, int id_offset); void module_show_connector(const __u8 *id, int ctor_offset); void module_show_mit_compliance(u16 value); void module_show_dom_mod_lvl_monitors(const struct sff_diags *sd); +void module_dump_eeprom_hex(const struct module_eeprom_dump *dump); #endif /* MODULE_COMMON_H__ */ -- 2.51.0