Пример #1
0
 def test_dataflash_from_file(self):
     with open("testdata/test_dataflash.bin", "rb") as dataflashfile:
         dataflash = evic.DataFlash(bytearray(dataflashfile.read()), 0)
         assert dataflash.hw_version == 103
         assert dataflash.bootflag == 0
         assert dataflash.product_id == "E052"
         assert dataflash.fw_version == 300
Пример #2
0
    def test_dataflash_verify(self):
        with open("testdata/test_dataflash.bin", "rb") as dataflashfile:
            dataflash = evic.DataFlash(bytearray(dataflashfile.read()), 0)
            checksum = sum(dataflash.array)

            dataflash.verify(checksum)

            with pytest.raises(evic.DataFlashError):
                dataflash.verify(0)
Пример #3
0
    def test_set_dataflash_attributes(self):
        with open("testdata/test_dataflash.bin", "rb") as dataflashfile:
            dataflash = evic.DataFlash(bytearray(dataflashfile.read()), 0)
            dataflash.bootflag = 1
            dataflash.hw_version = 106

            assert dataflash.bootflag == 1
            assert dataflash.array[9] == 1
            assert dataflash.hw_version == 106
            assert struct.unpack("=I", bytes(dataflash.array[4:8]))[0] == 106
Пример #4
0
def upload(inputfile, encrypted, dataflashfile, noverify):
    """Upload an APROM image 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
    verify = 'dataflash' not in noverify
    dataflash = read_dataflash(dev, verify)
    dataflash_original = copy.deepcopy(dataflash)

    # Print the device information
    print_device_info(dev, dataflash)

    # Read the APROM image
    aprom = evic.APROM(inputfile.read())
    if encrypted:
        aprom = evic.APROM(aprom.convert())

    # Verify the APROM image
    if 'aprom' not in noverify:
        with handle_exceptions(evic.APROMError):
            click.echo("Verifying APROM...", nl=False)
            aprom.verify(dev.supported_product_ids[dataflash.product_id],
                         dataflash.hw_version)

    # Are we using a data flash file?
    if dataflashfile:
        buf = bytearray(dataflashfile.read())
        # We used to store the checksum inside the file
        if len(buf) == 2048:
            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 'dataflash' not in noverify:
            verify_dataflash(dataflash, checksum)

    # We want to boot to LDROM on restart
    if not dev.ldrom:
        dataflash.bootflag = 1

    # Flashing Presa firmware requires HW version <=1.03 on type A devices
    if b'W007' in aprom.data and dataflash.product_id == 'E052' \
            and dataflash.hw_version in [106, 108, 109, 111]:
        click.echo("Changing HW version to 1.03...", nl=False)
        dataflash.hw_version = 103
        click.secho("OK", fg='green', bold=True)

    # Write data flash to the device
    with handle_exceptions(IOError):
        if dataflash.array != dataflash_original.array:
            click.echo("Writing data flash...", nl=False)
            sleep(0.1)
            dev.write_dataflash(dataflash)
            click.secho("OK", fg='green', bold=True)

        # We should only restart if we're not in LDROM
        if not dev.ldrom:
            # Restart
            click.echo("Restarting the device...", nl=False)
            dev.reset()
            sleep(2)
            click.secho("OK", fg='green', nl=False, bold=True)
            # Reconnect
            connect(dev)

        # Write APROM to the device
        click.echo("Writing APROM...", nl=False)
        dev.write_aprom(aprom)