bigbigmdm / IMSProg

IMSProg - software for CH341A-based programmers to work with I2C, SPI and MicroWire EEPROM/Flash chips
https://antenna-dvb-t2.ru/IMSProg.php
GNU General Public License v3.0
215 stars 38 forks source link

Fix #28 for I2C EEPROM #29

Closed mrv96 closed 8 months ago

mrv96 commented 8 months ago

Fix https://github.com/bigbigmdm/IMSProg/issues/28 for I2C EEPROM

VittorioBurani commented 8 months ago

@mrv96 solution fixes the Program function instead and i think this is the preferred fix for this issue. I tested it on my system, now it works as expected.

bigbigmdm commented 8 months ago

You have done a great and good job. But, unfortunately, this problem affects all types of chips and it is much more rational to solve it when loading a file. Please test my changes:

    // if ChipSze = 0 IMSProg using at hexeditor only. chipsize -> hexedit.data
    // if ChipSize < FileSize - showing error message
    // if Filesize <= ChipSize - filling fileArray to hexedit.Data, the end of the array chipData remains filled 0xff
    QFile file(fileName);
    if ((info.size() > currentChipSize) && (currentChipSize != 0))
    {
      QMessageBox::about(this, tr("Error"), tr("The file size exceeds the chip size. Please select another chip or file or use block operations to split the file."));
      return;
    }
    if (!file.open(QIODevice::ReadOnly))
    {

        return;
    }
    buf.resize(info.size());
    buf = file.readAll();
    if (currentChipSize == 0)
    {
        chipData.resize(info.size());
    }

    for (uint32_t i=0; i < info.size(); i++)
    {
        chipData[i] = buf[i];
    }
    hexEdit->setData(chipData);

    file.close();
mrv96 commented 7 months ago

I just tested your solution; generally speaking it works, but I found a case where it doesn't.

Suppose to have a memory of 4 bytes where the value of last byte is 0xAA. You want to write a file containing three byte (e.g. 0x11 0x22 0x33) performing the following steps:

  1. open IMSProg
  2. load the file
  3. write the memory

The expected memory content is: 0x11 0x22 0x33 0xAA, but it actually contains: 0x11 0x22 0x33 0xFF

bigbigmdm commented 7 months ago

That's normal. If you want to load a file and leave the rest of the buffer contents - use the Load Part command. (Puzzle with red arrow). This is a special command for assembling multiple files into a buffer.