From ac1859be9668d2075530c92a18bcd4561735bc35 Mon Sep 17 00:00:00 2001 From: Moriya Pilipenko Date: Tue, 5 May 2026 12:32:34 +0300 Subject: [PATCH] [DO NOT MERGE] for debug purposes * in write verify error - print 4 dwords for both expected and actual data * when reading status register, log to screen if we read flash gw cmd --- mflash/mflash.c | 25 +++++++++++++++++++++++++ mflash/mflash_new_gw.c | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/mflash/mflash.c b/mflash/mflash.c index 8614e6842..59937b13c 100644 --- a/mflash/mflash.c +++ b/mflash/mflash.c @@ -410,6 +410,31 @@ int write_chunks(mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) block_data[i + prefix_pad_size], verify_buffer[i])); + // Print 4 dwords (16 bytes) starting from the dword before the error + u_int32_t error_offset = addr + i; + u_int32_t start_dword_offset = (error_offset & ~0x3) - 4; // Align to dword, go back 1 dword + if ((int32_t)start_dword_offset < 0 || start_dword_offset < addr) { + start_dword_offset = addr; + } + + u_int32_t bytes_to_print = 16; // 4 dwords + u_int32_t start_idx = start_dword_offset - addr; + + printf("Address range: 0x%08x - 0x%08x\n", start_dword_offset, start_dword_offset + bytes_to_print - 1); + printf("expected (4 dwords): "); + for (uint32_t j = start_idx; j < start_idx + bytes_to_print && j < data_size; j++) + { + printf("%02x ", block_data[j + prefix_pad_size]); + } + printf("\n"); + printf("actual (4 dwords): "); + for (uint32_t j = start_idx; j < start_idx + bytes_to_print && j < data_size; j++) + { + printf("%02x ", verify_buffer[j]); + } + printf("\n"); + fflush(stdout); + if (retries_counter >= retries_num) { return MFE_VERIFY_ERROR; } else { diff --git a/mflash/mflash_new_gw.c b/mflash/mflash_new_gw.c index 3c1753476..d9e251456 100644 --- a/mflash/mflash_new_gw.c +++ b/mflash/mflash_new_gw.c @@ -308,6 +308,25 @@ int new_gw_int_spi_get_status_data(mflash* mfl, u_int8_t op_type, u_int32_t* sta rc = new_gw_exec_cmd_get(mfl, gw_cmd, &flash_data, 1, (u_int32_t*)NULL, "Read id"); CHECK_RC(rc); DPRINTF(("new_gw_int_spi_get_status_data: op=%02x status=%08x\n", op_type, flash_data)); + + if (op_type == SFC_RDSR) + { + u_int32_t written_flash_cmd_without_busy = gw_cmd; + + // this changes are applied to the flash gw right before writing it, so need to add before comapring. no need to + // set the busy as it will be unset when we read the flash data. + written_flash_cmd_without_busy = MERGE(written_flash_cmd_without_busy, 1, 31, 1); // lock + written_flash_cmd_without_busy = + MERGE(written_flash_cmd_without_busy, (u_int32_t)mfl->curr_bank, mfl->gw_chip_select_bit_offset, 1); + + if (written_flash_cmd_without_busy == flash_data) + { + printf("============================================================================\n"); + printf("new_gw_int_spi_get_status_data: flash_data is the same as flash gw cmd!\n"); + printf("============================================================================\n"); + } + } + *status = (flash_data >> 8 * (4 - bytes_num)); DPRINTF(("new_gw_int_spi_get_status_data: after shift status=%08x\n", *status)); return MFE_OK;