python-evic icon indicating copy to clipboard operation
python-evic copied to clipboard

Messed up hardware version in dataflash

Open ksf opened this issue 8 years ago • 4 comments

I get this, don't ask me why it happened (short of that I was uploading self-built stuff, I have no idea):

Verifying data flash...OK
    Device name: eVic-VTC Mini
    Firmware version: 0.00
    Hardware version: 42949672.95

Please set the hardware version.

...indeed, that's exactly what I'd like to do in this situation.

After looking for options to do exactly that and finding none I downloaded the dataflash, changed the ffffffff starting at byte 4 to 63000000 (i.e. hw version 1.04, which is the correct one), uploaded that with extensive --no-verify (why do I also need to upload an aprom with that? no matter)... and it's not changing a thing.

Any hints, pointers, or insights?

ksf avatar Oct 06 '16 21:10 ksf

I just did the whole hex editor shebang under windows and used joyetech's flasher to write the dataflash, from what it's reporting it's working properly (and, btw, it displayed the bonkers version as 2.55, i.e. 8-bit).

So as far as my device is concerned this is fixed, there still seems to be something amiss with python-evic, though.

ksf avatar Oct 06 '16 22:10 ksf

Could you elaborate on how you flashed dataflash with Joyetech's flasher? AFAIK the only way to do that is to create a raw dataflash image (which differs from USB), pad an APROM to 120kB and append DF to it.

ReservedField avatar Oct 11 '16 22:10 ReservedField

I have to correct myself, I used FWUpdater as linked from the myevic readme, which only looks like the official one, short of the additional features.

ksf avatar Oct 12 '16 03:10 ksf

...and it's not changing a thing.

I thought I was having a similar issue: trying to upload an old flash dump to restore (or edit) puffs counter. So I know the aprom write resets this (which comes after the dataflash upload), and wrote a routine that only uploads the dataflash (0x53); but that also can't restore the puffs counter.
Initially I thought it didn't restore any settings, but that was clearly wrong; only the counter values don't seem to be in the flashdump range? Or perhaps are not overwritable through hid transfer? Any idea?

Anyway, perhaps my patched flash upload will be interesting to someone else (who likes switching between setting presets perhaps):

diff --git a/evic/cli.py b/evic/cli.py
index 9d81038..07827f3 100644
--- a/evic/cli.py
+++ b/evic/cli.py
@@ -237,6 +237,71 @@ def upload(inputfile, encrypted, dataflashfile, noverify):
         dev.write_aprom(aprom)
 
 
[email protected]('upload-dataflash')
[email protected]('inputfile', type=click.File('rb'))
[email protected]('--no-verify', 'noverify', is_flag=True,
+              help='Disable data flash verification.')
+def uploaddataflash(inputfile, noverify):
+    """Upload a dataflash dump to the device."""
+
+    dev = evic.HIDTransfer()
+
+    # Connect the device
+    connect(dev)
+
+    # Print the USB info of the device
+    print_usb_info(dev)
+
+    # Read the data flash (from device)
+    dataflash = read_dataflash(dev, not noverify)
+    dataflash_device = copy.deepcopy(dataflash)
+
+    # Get the device info
+    device_info = dev.devices.get(dataflash_device.product_id,
+                                  DeviceInfo("Unknown device", None, None))
+
+    # Print the device information
+    print_device_info(device_info, dataflash_device)
+
+    # Read the data flash file
+    buf = bytearray(inputfile.read())
+    # We used to store the checksum inside the file
+    if len(buf) == 2048:  # same routine as dev.read_dataflash
+        checksum = struct.unpack("=I", bytes(buf[0:4]))[0]
+        dataflash = evic.DataFlash(buf[4:], 0)
+    else:
+        checksum = sum(buf)
+        dataflash = evic.DataFlash(buf, 0)
+    if not noverify:
+        verify_dataflash(dataflash, checksum)
+
+    # Get the device info
+    device_info = dev.devices.get(dataflash.product_id,
+                                  DeviceInfo("Unknown device", None, None))
+    # Print the device information
+    print_device_info(device_info, dataflash)
+
+    # Compare device flash and file upload
+    # Abort if firmware differs
+    if (dataflash.hw_version != dataflash_device.hw_version) or \
+            (dataflash.fw_version != dataflash_device.fw_version) or \
+            (dataflash.product_id != dataflash_device.product_id):
+        error = 'Device upload binary has different version than current firmware, aborting.'
+        click.secho("FAIL", fg='red', bold=True)
+        click.echo(str(error), err=True)
+        sys.exit(1)
+
+    if dataflash.array == dataflash_device.array:
+        click.secho("OK", fg='green', bold=True)
+        return
+
+    # Write data flash to the device
+    with handle_exceptions(IOError):
+        click.echo("Writing data flash...", nl=False)
+        sleep(0.1)
+        dev.write_dataflash(dataflash)
+
+
 @usb.command('upload-logo')
 @click.argument('inputfile', type=click.File('rb'))
 @click.option('--invert', '-i', is_flag=True,

Output

$ evic-usb upload-dataflash Reuleaux_RX23_1.02_4.13.flashdump

Finding device...OK
	Manufacturer: Nuvoton
	Product: HID Transfer
	Serial No: A02014090304

Reading data flash...OK
Verifying data flash...OK
	Device name: Reuleaux RX2/3
	Firmware version: 4.13
	Hardware version: 1.02

Verifying data flash...OK
	Device name: Reuleaux RX2/3
	Firmware version: 4.13
	Hardware version: 1.02

Writing data flash...OK

nyov avatar Aug 05 '18 23:08 nyov