Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messed up hardware version in dataflash #24

Open
ksf opened this issue Oct 6, 2016 · 4 comments
Open

Messed up hardware version in dataflash #24

ksf opened this issue Oct 6, 2016 · 4 comments

Comments

@ksf
Copy link

ksf commented Oct 6, 2016

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
Copy link
Author

ksf commented Oct 6, 2016

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.

@ReservedField
Copy link
Contributor

ReservedField commented Oct 11, 2016

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.

@ksf
Copy link
Author

ksf commented Oct 12, 2016

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.

@nyov
Copy link

nyov commented Aug 5, 2018

...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)
 
 
+@usb.command('upload-dataflash')
+@click.argument('inputfile', type=click.File('rb'))
+@click.option('--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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants